Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML
<h1<link stylehref="text-align:center; font-family:Vazir, Tahoma; color:#333;font-weight:600;">
  📚 کتابخانه
</h1>

<!-- نوار ابزار / جستجو -->
<div id="book-toolbar" style="max-width:900px; margin:0 auto 10px; padding:0 20px; display:flex; justify-content:flex-start; align-items:center; gap:10px; direction:rtl;">
  <input id="book-search" type="text"
         placeholder="جستجو در عنوان، حیطه، نویسنده یا سال..."
         style="flex:1; padding:8px 12px; border-radius:999px; border:1px solid #ddd; font-family:Vazir, Tahoma; font-size:13px; outline:none;">
</div>

<div id="book-grid" style="display:grid; grid-template-columns:repeat(3, 1fr); gap:20px; padding:10px 40px 60px; direction:rtl;"></div>

<style>

@font-face {
  font-family: "IRANSans";
  src: url("/download/attachments/85045416/IRANSansXVF.woff2") format("woff2");
}

@font-face {
  font-family: "Vazir";
  src: url("/download/attachments/85045416/Vazir-Regular.woff2") format("woff2");
}


/* =========================
   تنظیمات کلی
========================= */

#book-grid,
#book-toolbar,
#book-grid * ,
#book-toolbar * {
  box-sizing: border-box;
}

#book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  padding: 10px 40px 60px;
  direction: rtl;
  width: 100%;
  font-family: Vazir, Tahoma, sans-serif;
}


/* https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font@v30.1.0/dist/font-face.css" rel="stylesheet" type="text/css" />

<style>

@font-face {
  font-family: "IRANSans";
  src: url("/download/attachments/85045416/IRANSansXVF.woff2") format("woff2");
}

@font-face {
  font-family: "Vazir";
  src: url("/download/attachments/85045416/Vazir-Regular.woff2") format("woff2");
}


/* ============================================
   پس‌زمینه‌ی اصلی صفحه
============================================ */

body {
  background: 
    radial-gradient(circle at 20% 10%, rgba(139, 92, 246, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 80% 60%, rgba(236, 72, 153, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 50% 100%, rgba(59, 130, 246, 0.05) 0%, transparent 50%),
    #fafbff;
  min-height: 100vh;
  background-attachment: fixed;
}


/* ============================================
   هدر زیبا با گرادیانت
============================================ */

.library-hero {
  max-width: 1100px;
  margin: 0 auto 25px;
  padding: 0 20px;
}

.hero-inner {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 35%, #ec4899 75%, #f43f5e 100%);
  border-radius: 28px;
  padding: 50px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 25px 50px -12px rgba(99, 102, 241, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.hero-inner::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 70%);
  border-radius: 50%;
  animation: float 8s ease-in-out infinite;
}

.hero-inner::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  border-radius: 50%;
  animation: float 10s ease-in-out infinite reverse;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-20px, 20px) scale(1.05); }
}

.hero-content {
  position: relative;
  z-index: 2;
}

.hero-title {
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 38px;
  font-weight: 800;
  color: #fff;
  margin: 0;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.hero-title-icon {
  font-size: 42px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.2));
  animation: bounce 2s ease-in-out infinite;
  display: inline-block;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.hero-subtitle {
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.95);
  margin: 14px 0 0;
  font-weight: 400;
  letter-spacing: 0.3px;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.hero-stat {
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 8px 20px;
  border-radius: 999px;
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 13px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}


/* ============================================
   نوار جستجوی پیشرفته
============================================ */

#book-toolbar {
  width: 100%;
  max-width: 700px;
  margin: 0 auto 30px;
  padding: 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  direction: rtl;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

#book-search {
  width: 100%;
  height: 54px;
  padding: 0 60px 0 50px;
  border-radius: 999px;
  border: 2px solid transparent;
  background: #fff;
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 14px;
  color: #2d3748;
  outline: none;
  box-shadow:
    0 10px 40px rgba(99, 102, 241, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 0 0 1px rgba(99, 102, 241, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#book-search::placeholder {
  color: #a0aec0;
  font-weight: 400;
}

#book-search:hover {
  box-shadow:
    0 15px 50px rgba(99, 102, 241, 0.18),
    0 4px 12px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(99, 102, 241, 0.12);
}

#book-search:focus {
  border-color: #8b5cf6;
  box-shadow:
    0 20px 60px rgba(139, 92, 246, 0.25),
    0 0 0 4px rgba(139, 92, 246, 0.1);
  transform: translateY(-2px);
}

.search-icon {
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: #8b5cf6;
  pointer-events: none;
  transition: transform 0.3s ease;
}

#book-search:focus + .search-icon {
  transform: translateY(-50%) scale(1.1);
}

.search-clear {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f1f5f9;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 14px;
  transition: all 0.2s ease;
}

.search-clear:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.search-clear.visible {
  display: flex;
}


/* ============================================
   گرید کتاب‌ها
============================================ */

#book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
  padding: 0 40px 60px;
  direction: rtl;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  font-family: Vazir, Tahoma, sans-serif;
}


/* ============================================
   کارت کتاب - طراحی مدرن
============================================ */

.card {
  background: #fff;
  border-radius: 22px;
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.05),
    0 10px 30px -5px rgba(99, 102, 241, 0.08);
  padding: 20px;
  min-height: 220px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-direction: row-reverse;
  font-family: Vazir, Tahoma, sans-serif;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.06);
  animation: cardEnter 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* خط رنگی بالای کارت */
.card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6, #ec4899);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.04) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.card:hover {
  transform: translateY(-8px);
  box-shadow:
    0 20px 40px -10px rgba(99, 102, 241, 0.2),
    0 10px 20px -5px rgba(0, 0, 0, 0.08);
  border-color: rgba(139, 92, 246, 0.2);
}

.card:hover::before {
  opacity: 1;
}

.card:hover::after {
  opacity: 1;
}

.card:hover .card-icon {
  background: linear-gradient(135deg, #ede9fe, #fce7f3);
  transform: rotate(-5deg) scale(1.05);
}

.card:hover .card-icon img {
  transform: scale(1.1);
}

.card:hover .download-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}


/* ============================================
   محتوای کارت
============================================ */

.card-content {
  flex: 1;
  min-width: 0;
  text-align: right;
  padding-right: 15px;
  direction: rtl;
  display: flex;
  flex-direction: column;
}

.card-content h3 {
  margin: 0 0 12px;
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  font-weight: 700;
  color: #1e293b;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 50px;
}

.card-content .dot-line {
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 12.5px;
  line-height: 1.9;
  color: #64748b;
  margin: 2px 0;
  word-break: break-word;
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-content .dot-line::before {
  content: '';
  width: 4px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-meta {
  margin-top: auto;
  padding-top: 10px;
}


/* ============================================
   آیکون / تصویر کتاب
============================================ */

.card-icon {
  flex: 0 0 80px;
  width: 80px;
  height: 96px;
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  border-radius: 16px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.card-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 16px;
  border: 1px solid rgba(99, 102, 241, 0.08);
}

.card-icon img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  display: block;
  transition: transform 0.4s ease;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.08));
}


/* ============================================
   دکمه‌ی دانلود
============================================ */

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #08a9c5, #0891b2);
  color: #fff !important;
  border: none;
  border-radius: 25px;
  padding: 7px 18px;
  font-family: Vazir, Tahoma, sans-serif;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  text-decoration: none !important;
  margin-top: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(8, 169, 197, 0.25);
  align-self: flex-start;
}

.download-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #0891b2, #0e7490) !important;
  box-shadow: 0 8px 20px rgba(8, 169, 197, 0.35);
}

.download-btn:active {
  transform: translateY(0);
}

.download-btn::before {
  content: '⬇';
  font-size: 11px;
}


/* ============================================
   حالت‌های خالی / خطا / لودینگ
============================================ */

.state-message {
  grid-column: 1 / -1;
  text-align: center;
  font-family: Vazir, Tahoma, sans-serif !important;
  padding: 60px 30px !important;
  border-radius: 22px !important;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.state-empty {
  background: linear-gradient(135deg, #fafbff, #f5f3ff) !important;
  border: 2px dashed #d8b4fe !important;
  color: #6b7280 !important;
}

.state-empty-icon {
  font-size: 56px;
  margin-bottom: 15px;
  display: block;
  opacity: 0.6;
}

.state-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 6px;
}

.state-empty-sub {
  font-size: 13px;
  color: #9ca3af;
}

.state-error {
  background: linear-gradient(135deg, #fef2f2, #fee2e2) !important;
  border: 2px dashed #fca5a5 !important;
  color: #b91c1c !important;
}

.state-loading {
  background: #fff !important;
  border: 1px solid rgba(99, 102, 241, 0.1) !important;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  margin: 0 auto 15px;
  border: 4px solid #f3f4f6;
  border-top: 4px solid #8b5cf6;
  border-right: 4px solid #ec4899;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ============================================
   نوار جستجو
ریسپانسیو
========================================== */

#book-toolbar====== */

@media (max-width: 1100px) {
  #book-grid {
   width: 100%;
  max-width: 940px grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-left: 25px;
  margin: 0 auto 10pxpadding-right: 25px;
    paddinggap: 0 20px;
  }
  .hero-inner { displaypadding: flex40px 30px; }
  justify-content: center;
  align-items: center;
  direction: rtl;.hero-title { font-size: 32px; }
}

#book-search {
  @media (max-width: 100%;700px) {
  height: 40px;
  #book-toolbar { padding: 8px0 18px15px;

  bordermargin-radiusbottom: 999px20px; }
  border:
 1px solid #dedede;
#book-search {
  background: #fff;

  font-family: Vazir, Tahoma, sans-serif;
 height: 48px;
    font-size: 13px;
    colorpadding: #444;

0 50px outline:0 none45px;

  transition:}
  
  border.search-coloricon 0.2s ease,
    box-shadow 0.2s ease;
}

#book-search::placeholder {
  color: #999;
}

#book-search:focus {
  border-color: #cfcfcf;
  box-shadow: 0 0 0 3px rgba(180, 0, 116, 0.05);
}


/* =========================
   کارت کتاب
========================= */

.card {
  background: #fff;

  border-radius: 18px;

  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.08);

  padding: 16px;

  min-height: 216px;

  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  flex-direction: row-reverse;

  font-family: Vazir, Tahoma, sans-serif;

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}


/* افکت بسیار ملایم هنگام رفتن موس روی کارت */

.card:hover {
  transform: translateY(-2px);

  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.10);
}


/* =========={ right: 18px; width: 18px; height: 18px; }
  
  #book-grid {
    grid-template-columns: 1fr;
    padding: 0 15px 40px;
    gap: 16px;
  }
  
  .card {
    min-height: auto;
    padding: 16px;
  }
  
  .hero-inner { 
    padding: 35px 20px;
    border-radius: 22px;
  }
  
  .hero-title { 
    font-size: 26px;
    gap: 10px;
  }
  
  .hero-title-icon { font-size: 32px; }
  
  .hero-subtitle { font-size: 13px; }
  
  .hero-stats { gap: 10px; }
  
  .hero-stat { font-size: 12px; padding: 6px 14px; }
}

@media (max-width: 400px) {
  .card { padding: 14px; }
  .card-icon { flex: 0 0 70px; width: 70px; height: 84px; }
  .card-icon img { width: 50px; height: 50px; }
  .card-content h3 { font-size: 14px; }
}

</style>


<!-- ===============
   بخش متن کارت
============================= */

.card-content {
  flex: 1;

  min-width: 0;

  text-align: right;

  padding-right: 15px;

  direction: rtl;
}


/* عنوان */

.card-content h3 {
  margin: 0 0 8px;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 14px;

  line-height: 1.65;

  font-weight: 700;

  color: #222;
}


/* خطوط اطلاعات */

.card-content .dot-line {
  font-family: Vazir, Tahoma, sans-serif;

  font-size: 12.5px;

  line-height: 1.8;

  color: #555;

  margin: 1px 0;

  word-break: break-word;
}


/* =========================
   تصویر کتاب
========================= */

.card-icon {
  flex: 0 0 88px;

  width: 88px;
  height: 100px;

  background: #f7f7f7;

  border-radius: 16px;

  padding: 10px;

  display: flex;

  align-items: center;
  justify-content: center;

  margin-top: 0;
}


.card-icon img {
  width: 72px;
  height: 72px;

  object-fit: contain;

  display: block;
}


/* =========================
   دکمه دانلود
========================= */

.download-btn {
  display: inline-block;

  background: #08a9c5;

  color: #fff !important;

  border: none;

  border-radius: 25px;

  padding: 5px 16px;

  min-width: 54px;

  text-align: center;

  font-family: Vazir, Tahoma, sans-serif;

  font-size: 11px;

  line-height: 1.5;

  text-decoration: none !important;

  margin-top: 8px;

  cursor: pointer;

  transition:
    background 0.2s ease,
    transform 0.2s ease;
}


.download-btn:hover {
  background: #0797af;

  transform: translateY(-1px);
}


/* =========================
   پیام‌های خالی / خطا
=
     HTML
============================================ -->

<!-- هدر زیبا -->
<div class="library-hero">
  <div class="hero-inner">
    <div class="hero-content">
      <h1 class="hero-title">
        <span class="hero-title-icon">📚</span>
        <span>کتابخانه</span>
      </h1>
      <p class="hero-subtitle">دروازه‌ای به دنیای دانش و مطالعه</p>
      <div class="hero-stats" id="hero-stats"></div>
    </div>
  </div>
</div>

<!-- نوار جستجو -->
<div id="book-toolbar">
  <div class="search-wrapper">
    <input id="book-search" type="text"
           placeholder="جستجو در عنوان، حیطه، نویسنده یا سال..."
           autocomplete="off">
    <svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
      <circle cx="11" cy="11" r="8"/>
      <line x1="21" y1="21" x2="16.65" y2="16.65"/>
    </svg>
    <button class="search-clear" id="search-clear" type="button" aria-label="پاک کردن جستجو">✕</button>
  </div>
</div>

<div id="book-grid"></div>


<script>
(() => {
  /* ===== تنظیمات ===== */
  const LIB_ID             = "nikan-west-library";
  const FORCED_DATA_PAGE_ID = 85045416;
  const JSON_FILE_NAME     = `library-${LIB_ID}.json`;
  /* =================== */

  function detectBase(){
    try{ if (window.AJS && typeof AJS.contextPath====== */

#book-grid > div[style*="grid-column"] {
  font-family: Vazir, Tahoma, sans-serif !important;

  border-radius: 18px !important;
}


/* =========================
   تبلت
========================= */

@media (max-width: 1100px) {

  #book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));

    padding-left: 25px;
    padding-right: 25px;

    gap: 18px;
  }

}


/* =========================
   موبایل
========================= */

@media (max-width: 700px) {

  #book-toolbar {
    padding: 0 15px;
  }

  #book-grid {
    grid-template-columns: 1fr;

    padding:
      10px 15px 40px;

    gap: 15px"function") return AJS.contextPath(); }catch(e){}
    const meta = document.querySelector('meta[name="ajs-context-path"]')?.content;
    if (meta) return meta;
    const m = location.pathname.match(/^(.*)\/(pages|display|download)\//);
    if (m) return m;
    return '';
  }

  const BASE        = detectBase();
  const DATA_PAGE_ID = FORCED_DATA_PAGE_ID;
  const ENDPOINT_ATTACH_LIST =
    `${BASE}/rest/api/content/${DATA_PAGE_ID}/child/attachment`;

  const grid        = document.getElementById("book-grid");
  const searchInput = document.getElementById("book-search");
  const searchClear = document.getElementById("search-clear");
  const heroStats   = document.getElementById("hero-stats");

  let allBooks = [];

  /* ---------- نمایش لودینگ ---------- */
  function showLoading(){
    grid.innerHTML = `
      <div class="state-message state-loading">
        <div class="loading-spinner"></div>
        <div style="color:#6b7280; font-size:14px;">در حال بارگذاری کتاب‌ها...</div>
      </div>`;
  }

  .card {
    min-height: auto;
  }

}

</style>

<script>
(() => {
  /* ===== تنظیمات ===== */
  const LIB_ID      /* ---------- آمار هدر ---------- */
  function updateHeroStats(count){
    if (!heroStats) return;
    heroStats.innerHTML = `
      <div class="hero-stat">📖 ${count} کتاب</div>
      <div class= "nikanhero-west-librarystat";>✨ بروزرسانی شده</div>
   // با`;
 صفحه ثبت یکی باشد }

  const FORCED_DATA_PAGE_ID = 85045416;      /* ---------- ساخت کارت ---------- */
  function createBookCard(book, index){
    //const صفحه‌یauthorsBlock فرم ثبت / ریشه دیتا= (book.authors && book.authors.length)
  const JSON_FILE_NAME   ? book.authors.map(a = `library-${LIB_ID}.json`;
  /* =================== */

  // تشخیص BASE (context path)
  function detectBase(){
    try{ if (window.AJS && typeof AJS.contextPath==="function") return AJS.contextPath(); }catch(e){}
    const meta = document.querySelector('meta[name="ajs-context-path"]')?.content;
    if (meta) return meta;
    const m = location.pathname.match(/^(.*)\/(pages|display|download)\//);
    if (m) return m[1];
    return '';
  }

  const BASE        = detectBase();
  const DATA_PAGE_ID = FORCED_DATA_PAGE_ID;   // چون می‌دانیم دیتا روی صفحه‌ی فرم ثبت است
  const ENDPOINT_ATTACH_LIST =
    `${BASE}/rest/api/content/${DATA_PAGE_ID}/child/attachment`;

  const grid        = document.getElementById("book-grid");
  const searchInput = document.getElementById("book-search");

  let allBooks = [];

  function createBookCard(book){
    const authorsBlock = (book.authors && book.authors.length)
      ? book.authors.map(a=>`<div class="dot-line">• ${a}</div>`).join("")
      : `<div class="dot-line">• بدون نویسنده</div>`;

    const card = document.createElement("div");
    card.className = "card";
    card.innerHTML = `
      <div class="card-content> `<div class="dot-line">${a}</div>`).join("")
      : `<div class="dot-line">بدون نویسنده</div>`;

    const card = document.createElement("div");
    card.className = "card";
    card.style.animationDelay = `${Math.min(index * 0.05, 0.6)}s`;
    card.innerHTML = `
      <div class="card-content">
        <h3>${book.title || "-"}</h3>
        <div class="dot-line">${book.category || "بدون دسته"}</div>
        ${authorsBlock}
        <div class="dot-line">${book.year || "نامشخص"}</div>
        <div class="card-meta">
          ${book.fileUrl ? `<a href="${book.fileUrl}" target="_blank" rel="noopener" class="download-btn">دانلود</a>` : ""}
        </div>
      </div>
      <div class="card-icon">
        <img src="https://kb.h-soft.ir/download/thumbnails/85045416/12%20-%20Copy.png?api=v2&nonce=1787954132399" alt="کتاب" loading="lazy">
      </div>
    `;
    return card;
  }

  /* ---------- رندر لیست ---------- */
  function renderBooks(list){
    grid.innerHTML = "";
    if (!list.length){
      grid.innerHTML = `
        <div class="state-message state-empty">
        <h3>${book.title || "-"}</h3>  <span class="state-empty-icon">📭</span>
          <div class="dotstate-empty-linetitle">•>کتابی حیطه: ${book.category || "-"}<پیدا نشد</div>
        ${authorsBlock}
        <div class="dot-line">• تاریخ انتشار: ${book.year || "-"}</div>
        ${book.fileUrl ? `<a href="${book.fileUrl}" target="_blank" class="download-btn">دانلود</a>` : ""}state-empty-sub">لطفاً عبارت دیگری جستجو کنید یا فیلتر را پاک کنید.</div>
        </div>`;
      </div>return;
    }
   <div class="card-icon">
        <img src="https://kb.h-soft.ir/download/thumbnails/85045416/12%20-%20Copy.png?api=v2&nonce=1787954132399" alt="کتاب">
      </div>
    `;
    return card;
  }

  function renderBooks(list){
    grid.innerHTML = "" list.forEach((b, i) => grid.appendChild(createBookCard(b, i)));
  }

  /* ---------- دریافت JSON ---------- */
  async function getExistingAttachmentMeta() {
    const url = `${ENDPOINT_ATTACH_LIST}?filename=${encodeURIComponent(JSON_FILE_NAME)}&expand=results`;
    const res = await fetch(url, { credentials: "include" });
    if (!listres.length){ok) return null;
    const data grid.innerHTML= = `await res.json();
    if (!data.results ||  <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#777!data.results.length) return null;
    return data.results;
  }

  async function loadJsonFromAttachment() {
    const meta = await getExistingAttachmentMeta();
     background:#fafafa; border:1px dashed #e4e4e4; padding:14px; border-radius:18px;">if (!meta) return { libId: LIB_ID, books: [] };

    const downloadLink = meta._links &&  کتابی با این فیلتر پیدا نشد.
        </div>`;meta._links.download;
    if (!downloadLink) return { libId: LIB_ID, books: [] };

    const res return;
=    }
    list.forEach(b => grid.appendChild(createBookCard(b)))await fetch(BASE + downloadLink, { credentials: "include" });
  }

  async functionif getExistingAttachmentMeta(!res.ok) {
    const url = `${ENDPOINT_ATTACH_LIST}?filename=${encodeURIComponent(JSON_FILE_NAME)}&expand=results`throw new Error("خطا در دانلود JSON: " + res.status);
    const restext = await fetch(url, { credentials: "include" }res.text();
    if (!restext.oktrim()) return null { libId: LIB_ID, books: [] };

    consttry {
 data = await res.json();
  const parsed if= JSON.parse(!data.results || !data.results.length) return null;
    return data.results[0];
  }

  async function loadJsonFromAttachment() {text.replace(/^\uFEFF/, '').trim());
      if (!parsed.books) parsed.books = [];
      if (!parsed.libId) parsed.libId = LIB_ID;
    const meta = await getExistingAttachmentMeta()return parsed;
    if} catch(!metae) return { libId: LIB_ID, books: [] };

    const downloadLink = meta._links && meta._links.download console.error("JSON parse error:", e);
    if (!downloadLink) return { libId: LIB_ID, books: [] };

    const}
 res =}

 await fetch(BASE + downloadLink, { credentials: "include" });
    if (!res.ok) throw new Error("خطا در دانلود JSON: " + res.status);
/* ---------- بارگذاری اولیه ---------- */
  async function loadBooks() {
    showLoading();
    try {
      const textdata = await res.textloadJsonFromAttachment();
    if (!text.trim()) return { libId: LIB_ID, books: [] };

 allBooks = data.books || [];
     try {
      const parsed = JSON.parse(text.replace(/^\uFEFF/, '').trim())   updateHeroStats(allBooks.length);
      
      if (!parsedallBooks.bookslength) parsed.books{
        grid.innerHTML = [];`
      if (!parsed.libId) parsed.libId = LIB_ID;
    <div class="state-message state-empty">
        return parsed;
    } catch(e) {
<span class="state-empty-icon">📚</span>
        console.error("JSON parse error:", e);
 <div class="state-empty-title">کتابخانه خالی است</div>
  return { libId: LIB_ID, books: [] };
    }
  }

  async function loadBooks() {
    try {<div class="state-empty-sub">از طریق فرم ثبت، اولین کتاب را به کتابخانه اضافه کنید.</div>
      const data = await loadJsonFromAttachment() </div>`;
      allBooks = data.books || [] return;
      if (!allBooks.length) {}
      setTimeout(()  grid.innerHTML = `=> renderBooks(allBooks), 250);
    } catch     <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#777(e) {
      console.error(e);
      grid.innerHTML = `
        <div class="state-message state-error">
      background:#fafafa; border:1px dashed #e4e4e4; padding:14px; border-radius:18px;"> <span class="state-empty-icon">⚠️</span>
          <div  هنوز کتابی ثبت نشده است.class="state-empty-title">خطا در بارگذاری کتاب‌ها</div>
          <div class="state-empty-sub">${e.message}</div>`;div>
        return</div>`;
      }
      renderBooks(allBooks);
    } catch (e) {}

  /* ---------- جستجو  console.error(e);
      grid.innerHTML = `---------- */
  function handleSearch(){
    const q =  <div style="grid-column:1/-1; text-align:center; font-family:Vazir, Tahoma; color:#c00;(searchInput.value || "").trim().toLowerCase();
    
    // نمایش/مخفی کردن دکمه‌ی پاک کردن
    if (q) {
      background:#fff5f5; border:1px dashed #f5b5b5; padding:14px; border-radius:18px;">searchClear.classList.add("visible");
    } else {
      searchClear.classList.remove("visible");
    }

 خطا در خواندن کتاب‌ها: ${e.message}if (!q){
      renderBooks(allBooks);
  </div>`;
    }return;
    }

  //  سرچconst رویfiltered آرایه‌ی= allBooks
  function handleSearch(){
.filter(b => {
      const title  q  = (searchInput.valueb.title    || "").trim().toLowerCase();
    if (!q){
 const category = (b.category  renderBooks(allBooks|| "").toLowerCase();
      return;
const year     }

 = (b.year   const filtered = allBooks.filter(b => {
|| "").toLowerCase();
      const authors  const title    == Array.isArray(b.authors) ? b.authors.join(" ") : (b.titleauthors    || "").toLowerCase();
      const categoryauthorsL = (b.category || "")authors.toLowerCase();

      const haystack = `${title} ${category} ${year} ${authorsL}`;
     = return (b.year  haystack.includes(q);
    });

   || "").toLowerCase( renderBooks(filtered);
  }

  /*  const authors  = Array.isArray(b.authors) ? b.authors.join(" ") : (b.authors || ""---------- رویدادها ---------- */
  let searchTimeout;
  searchInput.addEventListener("input", () => {
    clearTimeout(searchTimeout);
    searchTimeout = const authorsL = authors.toLowerCase(setTimeout(handleSearch, 180);
  });

  searchClear.addEventListener("click", () => {
 const haystack = `${title} ${category} ${year} ${authorsL}` searchInput.value = "";
      return haystack.includes(qsearchClear.classList.remove("visible");
    }searchInput.focus();

    renderBooks(filteredallBooks);
  }

  searchInput.addEventListener("input", handleSearch);

  loadBooks();
})();
</script>