$(document).ready(() => { const STATUS_CONFIG = { active: { label: "Доступна", bgClass: "bg-green-100", textClass: "text-green-800", icon: ` `, }, borrowed: { label: "Выдана", bgClass: "bg-yellow-100", textClass: "text-yellow-800", icon: ` `, }, reserved: { label: "Забронирована", bgClass: "bg-blue-100", textClass: "text-blue-800", icon: ` `, }, restoration: { label: "На реставрации", bgClass: "bg-orange-100", textClass: "text-orange-800", icon: ` `, }, written_off: { label: "Списана", bgClass: "bg-red-100", textClass: "text-red-800", icon: ` `, }, }; function getStatusConfig(status) { return ( STATUS_CONFIG[status] || { label: status || "Неизвестно", bgClass: "bg-gray-100", textClass: "text-gray-800", icon: "", } ); } const pathParts = window.location.pathname.split("/"); const bookId = pathParts[pathParts.length - 1]; if (!bookId || isNaN(bookId)) { Utils.showToast("Некорректный ID книги", "error"); return; } Api.get(`/api/books/${bookId}`) .then((book) => { document.title = `LiB - ${book.title}`; renderBook(book); }) .catch((error) => { console.error(error); Utils.showToast("Книга не найдена", "error"); $("#book-loader").html( '

Ошибка загрузки

', ); }); function renderBook(book) { $("#book-title").text(book.title); $("#book-id").text(`ID: ${book.id}`); $("#book-authors-text").text( book.authors.map((a) => a.name).join(", ") || "Автор неизвестен", ); $("#book-description").text(book.description || "Описание отсутствует"); const statusConfig = getStatusConfig(book.status); $("#book-status") .html(statusConfig.icon + statusConfig.label) .removeClass() .addClass( `inline-flex items-center px-3 py-1 rounded-full text-sm font-medium ${statusConfig.bgClass} ${statusConfig.textClass}`, ); if (book.genres && book.genres.length > 0) { $("#genres-section").removeClass("hidden"); const $genres = $("#genres-container"); book.genres.forEach((g) => { $genres.append(` ${Utils.escapeHtml(g.name)} `); }); } if (book.authors && book.authors.length > 0) { $("#authors-section").removeClass("hidden"); const $authors = $("#authors-container"); book.authors.forEach((a) => { $authors.append(`
${a.name.charAt(0).toUpperCase()}
${Utils.escapeHtml(a.name)}
`); }); } $("#book-loader").addClass("hidden"); $("#book-content").removeClass("hidden"); } });