$(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]; let currentBook = null; if (!bookId || isNaN(bookId)) { Utils.showToast("Некорректный ID книги", "error"); return; } Api.get(`/api/books/${bookId}`) .then((book) => { currentBook = book; document.title = `LiB - ${book.title}`; renderBook(book); if (window.canManage()) { $("#edit-book-btn") .attr("href", `/book/${book.id}/edit`) .removeClass("hidden"); } }) .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 || "Описание отсутствует"); renderStatusWidget(book); if (!window.canManage && book.status === "active") { renderReserveButton(); } if (book.genres && book.genres.length > 0) { $("#genres-section").removeClass("hidden"); const $genres = $("#genres-container"); $genres.empty(); 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"); $authors.empty(); book.authors.forEach((a) => { $authors.append(`