+ // Safe fallback configurations
+ const displayTitle = bookDetails?.book_name || "Loading Title...";
+ const displayAuthor = bookDetails?.book_author || "Please wait";
+ const displayId = bookDetails?.book_id ? String(bookDetails.book_id).slice(-4).toUpperCase() : "0000";
+ const displayLanguage = bookDetails?.language || "N/A";
+ const displayCategory = bookDetails?.category?.category_name || "Unclassified";
+ const isbn = bookDetails?.isbn || "N/A";
+ const historyLog = bookDetails?.history || [];
+ console.log("history Log ",historyLog)
-
+ const availableCount = bookDetails?.available_copies ?? 0;
+ const totalCount = bookDetails?.total_copies ?? 0;
+ const borrowCount = bookDetails?.lending_count ?? 0;
- {/* Core Info Properties Grid Layout */}
-
-
-
- Language Spec
-
-
- {book.language}
-
-
+ const totalDamagedBooks = historyLog.filter(log => log.condition === "DAMAGED").length;
-
-
- Category Classification
-
-
- {book.categoryName}
-
-
+ const shelfEntryDate = bookDetails?.created_at
+ ? new Date(bookDetails.created_at).toLocaleDateString("en-US", {
+ year: "numeric",
+ month: "long",
+ day: "numeric",
+ })
+ : "Processing...";
-
-
- Shelf Registry Date
-
-
- {shelfEntryDate}
-
-
+ // 🚀 Reusable Date Formatter
+ const formatDate = (dateString: string | null) => {
+ if (!dateString) return "—";
+ return new Date(dateString).toLocaleDateString("en-US", {
+ year: "numeric",
+ month: "long",
+ day: "numeric",
+ });
+ };
+
+ // ==================== PDF REPORT GENERATOR ====================
+ const generateStructuredPDF = () => {
+ if (!bookDetails) return;
+ const doc = new jsPDF({ orientation: "portrait", unit: "mm", format: "a4" });
+
+ // Header Banner Box
+ doc.setFillColor(26, 54, 93);
+ doc.rect(0, 0, 210, 40, "F");
+
+ doc.setTextColor(255, 255, 255);
+ doc.setFont("helvetica", "bold");
+ doc.setFontSize(22);
+ doc.text("LIBRARY MANAGEMENT SYSTEM", 15, 18);
+ doc.setFontSize(11);
+ doc.setFont("helvetica", "normal");
+ doc.text("Official Catalog Book Profile Inventory Ledger Report", 15, 26);
+
+ // Core Metadata Info Row Block
+ doc.setTextColor(45, 55, 72);
+ doc.setFontSize(14);
+ doc.setFont("helvetica", "bold");
+ doc.text("BOOK RECORD METADATA", 15, 52);
+
+ doc.setFontSize(10);
+ doc.setFont("helvetica", "normal");
+ doc.text([
+ `Book Volume Title: ${displayTitle}`,
+ `Author / Creator: ${displayAuthor}`,
+ `ISBN Reference Identifier: ${isbn}`,
+ `Language Classification: ${displayLanguage.toUpperCase()}`,
+ `Assigned Category: ${displayCategory}`,
+ `Shelf Registry Date: ${shelfEntryDate}`
+ ], 15, 60);
+
+ // KPI Summary Widget Box Component Pinned Right
+ doc.setFillColor(247, 250, 252);
+ doc.rect(140, 58, 55, 28, "F");
+ doc.setTextColor(26, 54, 93);
+ doc.setFont("helvetica", "bold");
+ doc.text("INVENTORY STATISTICS", 143, 64);
+ doc.setFont("helvetica", "normal");
+ doc.setFontSize(9);
+ doc.text(`Total Holdings: ${totalCount} Copies`, 143, 71);
+ doc.text(`On-Shelf Copies: ${availableCount} Units`, 143, 77);
+ doc.text(`Damaged Incidents: ${totalDamagedBooks} items`, 143, 83);
+
+ doc.setDrawColor(226, 232, 240);
+ doc.line(15, 93, 195, 93);
+
+ doc.setTextColor(26, 54, 93);
+ doc.setFontSize(12);
+ doc.setFont("helvetica", "bold");
+ doc.text("CIRCULATION TIMELINE & HISTORICAL LOGS", 15, 102);
+
+ // Main History Table
+ autoTable(doc, {
+ startY: 107,
+ margin: { left: 15, right: 15 },
+ head: [["Active Borrower Name", "Email Address", "Issued On Date", "Returned On Date", "Item Condition State", "Damage Reason"]],
+ body: historyLog.map((log) => [
+ log.member_name,
+ log.gmail || "N/A", // 🚀 FIXED: Swapped log.gmail to log.email to match types configuration
+ log.borrow_date ? formatDate(log.borrow_date) : "—",
+ log.return_date ? formatDate(log.return_date) : "Active Loan",
+ log.condition,
+ log.damage_description
+ ]),
+ headStyles: { fillColor: [26, 54, 93], fontStyle: "bold" },
+ styles: { fontSize: 8.5, font: "helvetica" }
+ });
+
+ const clientFileNameSafeText = displayTitle.replace(/\s+/g, "_");
+ doc.save(`${clientFileNameSafeText}_inventory_ledger_report.pdf`);
+ };
+
+ return (
+ <>
+
+
+
+
+ {/* ==================== WORKSPACE HEADER CONTROLS BAR ==================== */}
+
+
+
-
- Lending Metrics (Total / Available / Loans)
-
-
-
- {book.totalCopies} Total
-
-
- {book.availableCopies} On Shelf
-
-
- {book.lendingCount}× Borrowed
+
+
{displayTitle}
+ 0 ? "bg-emerald-50 text-emerald-700 border-emerald-200" : "bg-rose-50 text-rose-700 border-rose-200"
+ }`}>
+ {availableCount > 0 ? "In Stock Available" : "All Copies Loaned"}
+
+ Catalog Inventory Index Code: BOOK-{displayId}
+
- {/* Operations Layout Action Buttons - Matching layout rules and theme */}
-
+
+
+
+
+
+ {/* ==================== CONTENT BODY MATRIX ROW LAYOUT ==================== */}
+
+
+ {/* LEFT SIDE SPECIFICATIONS CARD BAR */}
+
+
+
+
+
+
+
+ {displayTitle}
+
+
by {displayAuthor}
+
+
+ {/* Data specifications list details */}
+
+
+ ISBN Number
+ {isbn}
+
+
+ Language Spec
+ {displayLanguage}
+
+
+ Category Classification
+ {displayCategory}
+
+
+ Shelf Registry Date
+ {shelfEntryDate}
+
+
+
-
+
-
-
-
-
-
- {/* Embedded inline confirmation screen */}
-
setIsDeleteOpen(false)}
- onConfirm={handleConfirmDeletion}
- bookTitle={book.title}
- />
- >
-);}
\ No newline at end of file
+ {/* RIGHT COLUMN AREA PANEL DESK */}
+
+
+ {/* Tab Nav Menu Headers */}
+
+
+
+
+
+
+ {isLoading ? (
+
+ Streaming structural log transactions...
+
+ ) : (
+ <>
+ {/* TAB PANEL A: META OVERVIEW DATA SUMMARY */}
+ {activeTab === "bio" && (
+
+
+
+ Catalog Allocation Profile Status
+
+
+
+
+
+
+
+ Total Fleet
+ {totalCount} Copies
+
+
+ Available
+ {availableCount} On Shelf
+
+
+ Total Borrowed
+ {borrowCount} Times
+
+
+
+ Damaged Returns
+ {totalDamagedBooks} Incidence
+
+
+
+
+
+ {/* Dangerous Operation Triggers Pin Bottom Row */}
+
+
+ )}
+
+ {/* TAB PANEL B: CIRCULATION HISTORIC LEDGER DATA TABLE */}
+ {activeTab === "logs" && (
+
+
+
+
+ | Borrower / Member |
+ Issued Date |
+ Returned Date |
+ Condition Status |
+ Damage Reason |
+
+ {/* 🚀 FIXED: Added missing corresponding closing tag for 'thead' */}
+
+ {historyLog.length === 0 ? (
+
+ |
+ No historic checkout records or active transaction footprints found.
+ |
+
+ ) : (
+ historyLog.map((log, idx) => (
+
+ |
+ {log.member_name}
+ {/* 🚀 FIXED: Changed log.gmail to log.email to match types file parameters */}
+ {log.gmail || "N/A"}
+ |
+
+ {log.borrow_date ? formatDate(log.borrow_date) : "—"}
+ |
+
+ {log.return_date ? (
+ {formatDate(log.return_date)}
+ ) : (
+
+ Not Returned yet
+
+ )}
+ |
+
+
+ {log.condition}
+
+ |
+
+
+ {log.damage_description}
+
+ |
+
+ ))
+ )}
+
+
+
+ )}
+ >
+ )}
+
+
+
+ {/* Content grid container close */}
+