elahe-dashboards/dashboards/ops/shomal.html

1659 lines
92 KiB
HTML
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<meta name="theme-color" content="#090d16" />
<title>اکسپدیشن شمال و رشت ۱۴۰۵ | داشبورد مدیریت سفر</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Phosphor Icons -->
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<!-- Vazirmatn Font -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css">
<!-- jsPDF & html2canvas for PDF Export -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: {
sans: ['Vazirmatn', 'sans-serif'],
},
colors: {
brand: {
400: '#34d399',
500: '#10b981',
600: '#059669',
},
dark: {
bg: '#090d16',
surface: '#101726',
card: '#162033',
border: '#202d44',
muted: '#94a3b8'
}
}
}
}
}
</script>
<style>
* {
font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
-webkit-tap-highlight-color: transparent;
box-sizing: border-box;
font-feature-settings: "tnum";
}
html, body {
background-color: #090d16;
color: #f1f5f9;
margin: 0;
padding: 0;
width: 100%;
overflow-x: hidden;
min-height: 100vh;
}
.glass-card {
background: rgba(22, 32, 51, 0.9);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.hide-scrollbar::-webkit-scrollbar {
display: none;
}
.hide-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
animation: tabFadeIn 0.22s ease-out;
}
@keyframes tabFadeIn {
from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); }
}
button, a, input, select, textarea {
touch-action: manipulation;
}
@media print {
body {
background: #fff !important;
color: #000 !important;
}
.no-print {
display: none !important;
}
.print-only {
display: block !important;
}
.glass-card {
background: #fff !important;
border: 1px solid #ccc !important;
color: #000 !important;
box-shadow: none !important;
}
}
</style>
</head>
<body class="selection:bg-emerald-500 selection:text-black">
<!-- ============================================================== -->
<!-- TOP STICKY APP BAR -->
<!-- ============================================================== -->
<header class="sticky top-0 z-40 bg-dark-bg/95 backdrop-blur-md border-b border-dark-border px-3.5 py-2.5 no-print">
<div class="max-w-4xl mx-auto flex items-center justify-between">
<div class="flex items-center gap-2.5">
<div class="w-10 h-10 rounded-xl bg-gradient-to-tr from-emerald-600 to-teal-400 flex items-center justify-center text-white shadow-md shadow-emerald-950/50">
<i class="ph-bold ph-compass text-2xl"></i>
</div>
<div>
<div class="flex items-center gap-1.5">
<h1 class="text-sm sm:text-base font-black tracking-tight text-white">اکسپدیشن شمال و رشت ۱۴۰۵</h1>
<span class="text-[10px] bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 px-1.5 py-0.5 rounded-md font-bold">۷ تا ۱۲ مهر</span>
</div>
<p class="text-[11px] text-slate-400">چمستان امیرآباد & رشت | ۷ همسفر</p>
</div>
</div>
<!-- User Profile Picker & Actions -->
<div class="flex items-center gap-2">
<button onclick="openProfileModal()" class="flex items-center gap-1.5 bg-dark-card border border-emerald-500/40 hover:border-emerald-400 px-2.5 py-1.5 rounded-xl text-xs text-white active:scale-95 transition" title="تغییر پروفایل من">
<span id="header-user-avatar" class="text-base">👩‍💼</span>
<span id="header-user-name" class="font-bold text-emerald-400">محدثه</span>
<i class="ph-bold ph-caret-down text-slate-400 text-xs"></i>
</button>
<div id="sync-status" class="hidden sm:flex items-center gap-1 text-[11px] bg-dark-card border border-dark-border px-2 py-1.5 rounded-xl text-slate-300" title="وضعیت سرور">
<span class="w-2 h-2 rounded-full bg-emerald-400"></span>
<span>همگام</span>
</div>
<button onclick="copyTripBrief()" class="w-9 h-9 rounded-xl bg-dark-card border border-dark-border flex items-center justify-center text-slate-300 hover:text-white active:scale-95 transition" title="کپی خلاصه سفر">
<i class="ph-bold ph-share-network text-lg"></i>
</button>
</div>
</div>
</header>
<!-- Floating Toast Snackbar -->
<div id="toast" class="fixed bottom-20 left-1/2 -translate-x-1/2 z-50 pointer-events-none transition-all duration-300 opacity-0 translate-y-3 max-w-[90vw]">
<div id="toast-body" class="bg-emerald-500 text-black text-xs font-bold px-4 py-2.5 rounded-xl shadow-2xl flex items-center gap-2 border border-emerald-400/50">
<i class="ph-bold ph-check-circle text-base"></i>
<span id="toast-text">اعلان</span>
</div>
</div>
<main class="max-w-4xl mx-auto px-3.5 pt-3 pb-32 space-y-3.5">
<!-- ============================================================== -->
<!-- HERO SUMMARY CARD -->
<!-- ============================================================== -->
<div class="glass-card rounded-2xl p-3.5 border border-dark-border relative overflow-hidden no-print">
<div class="flex items-center justify-between pb-2.5 border-b border-dark-border/60">
<div class="flex items-center gap-2 text-xs">
<span class="flex h-2 w-2 relative">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-2 w-2 bg-emerald-500"></span>
</span>
<span class="text-slate-300 font-semibold">حرکت گروه ۱: <strong class="text-white">سه‌شنبه ۷ مهر (۲۱:۰۰)</strong></span>
</div>
<button onclick="toggleHeroDetails()" class="text-[11px] text-emerald-400 hover:text-emerald-300 flex items-center gap-1 font-bold">
<span id="hero-toggle-label">جزئیات زمان‌بندی و هوا</span>
<i id="hero-toggle-icon" class="ph-bold ph-caret-down transition-transform"></i>
</button>
</div>
<!-- Quick Summary Bar -->
<div class="grid grid-cols-3 gap-2 pt-2.5 text-center">
<div class="bg-dark-bg/80 border border-dark-border/80 rounded-xl py-1.5 px-1">
<span class="text-[10px] text-slate-400 block">مانده تا حرکت گروه ۱</span>
<span id="cd-compact" class="text-xs sm:text-sm font-black text-emerald-400">در حال محاسبه...</span>
</div>
<div class="bg-dark-bg/80 border border-dark-border/80 rounded-xl py-1.5 px-1">
<span class="text-[10px] text-slate-400 block">هوای چمستان & رشت</span>
<span class="text-xs sm:text-sm font-black text-amber-300">۲۱° پاییزی مه‌آلود</span>
</div>
<div class="bg-dark-bg/80 border border-dark-border/80 rounded-xl py-1.5 px-1">
<span class="text-[10px] text-slate-400 block">تعداد همسفران</span>
<span class="text-xs sm:text-sm font-black text-white">۷ نفر (۴+۳)</span>
</div>
</div>
<!-- Collapsible Detailed Drawer -->
<div id="hero-detailed-drawer" class="hidden mt-3 pt-3 border-t border-dark-border/60 space-y-3">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div class="bg-dark-bg/90 p-2.5 rounded-xl border border-dark-border">
<div class="flex items-center justify-between mb-1.5">
<span class="text-[11px] font-bold text-white flex items-center gap-1">
<i class="ph-bold ph-car text-emerald-400"></i> گروه ۱ (محدثه، محمدرضا، آریا، سینا):
</span>
<span class="text-[10px] text-slate-400">سه‌شنبه ۷ مهر - ۲۱:۰۰</span>
</div>
<div class="grid grid-cols-4 gap-1 text-center font-mono">
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd1-days" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">روز</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd1-hours" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">ساعت</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd1-mins" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">دقیقه</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd1-secs" class="text-sm font-black text-emerald-400">--</span><span class="text-[9px] text-slate-400 block font-sans">ثانیه</span></div>
</div>
</div>
<div class="bg-dark-bg/90 p-2.5 rounded-xl border border-dark-border">
<div class="flex items-center justify-between mb-1.5">
<span class="text-[11px] font-bold text-white flex items-center gap-1">
<i class="ph-bold ph-car text-amber-400"></i> گروه ۲ (امیرحسین، آوا، محمد):
</span>
<span class="text-[10px] text-slate-400">چهارشنبه ۸ مهر - بعد کار</span>
</div>
<div class="grid grid-cols-4 gap-1 text-center font-mono">
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd2-days" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">روز</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd2-hours" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">ساعت</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd2-mins" class="text-sm font-black text-white">--</span><span class="text-[9px] text-slate-400 block font-sans">دقیقه</span></div>
<div class="bg-dark-card p-1 rounded-lg border border-dark-border"><span id="cd2-secs" class="text-sm font-black text-amber-400">--</span><span class="text-[9px] text-slate-400 block font-sans">ثانیه</span></div>
</div>
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- NAVIGATION TABS PILLS -->
<!-- ============================================================== -->
<div class="flex items-center gap-1.5 overflow-x-auto my-2.5 pb-1 hide-scrollbar no-print">
<button onclick="switchTab('itinerary')" id="btn-tab-itinerary" class="tab-btn active shrink-0 px-3.5 py-2 rounded-xl text-xs font-bold transition flex items-center gap-1.5 bg-emerald-500 text-black">
<i class="ph-bold ph-calendar-blank text-sm"></i> برنامه سفر و جابجایی
</button>
<button onclick="switchTab('roster')" id="btn-tab-roster" class="tab-btn shrink-0 px-3.5 py-2 rounded-xl text-xs font-bold transition flex items-center gap-1.5 bg-dark-card text-slate-300 border border-dark-border">
<i class="ph-bold ph-trophy text-sm"></i> لیدربورد، نظرسنجی و کامنت‌ها
</button>
<button onclick="switchTab('shopping')" id="btn-tab-shopping" class="tab-btn shrink-0 px-3.5 py-2 rounded-xl text-xs font-bold transition flex items-center gap-1.5 bg-dark-card text-slate-300 border border-dark-border">
<i class="ph-bold ph-shopping-cart text-sm"></i> لیست خرید و ویرایش قیمت
</button>
<button onclick="switchTab('activities')" id="btn-tab-activities" class="tab-btn shrink-0 px-3.5 py-2 rounded-xl text-xs font-bold transition flex items-center gap-1.5 bg-dark-card text-slate-300 border border-dark-border">
<i class="ph-bold ph-film-strip text-sm"></i> تفریحات & فیلم‌های زرفیلم
</button>
<button onclick="switchTab('routes')" id="btn-tab-routes" class="tab-btn shrink-0 px-3.5 py-2 rounded-xl text-xs font-bold transition flex items-center gap-1.5 bg-dark-card text-slate-300 border border-dark-border">
<i class="ph-bold ph-path text-sm"></i> نقشه لوپ البرز
</button>
</div>
<!-- ============================================================== -->
<!-- TAB 1: ITINERARY (برنامه سفر با مکانیزم جابجایی مطمئن) -->
<!-- ============================================================== -->
<section id="tab-itinerary" class="tab-content active space-y-3">
<!-- Interactive Reorder Banner -->
<div class="bg-gradient-to-l from-emerald-950/60 via-dark-card to-dark-card border-r-4 border-emerald-500 border-t border-b border-l border-dark-border rounded-2xl p-3.5 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3">
<div class="flex items-start gap-2.5">
<div class="w-8 h-8 rounded-lg bg-emerald-500/20 text-emerald-400 flex items-center justify-center shrink-0 mt-0.5">
<i class="ph-bold ph-arrows-left-right text-lg"></i>
</div>
<div>
<strong class="text-white text-xs sm:text-sm font-bold block">مدیریت و جابجایی برنامه‌ها</strong>
<p class="text-[11px] text-slate-300 leading-relaxed">
روی هر برنامه دکمه <span class="text-emerald-400 font-bold">«انتقال به روز دیگر»</span> قرار دارد تا هر آیتم (مانند <strong>اکسپدیشن رشت</strong> یا باربیکیو) را فوراً به هر روز دلخواه منتقل کنید.
</p>
</div>
</div>
<div class="flex items-center gap-2 self-end sm:self-center">
<button onclick="openSwapRashtModal()" class="bg-emerald-500 hover:bg-emerald-400 text-black text-xs font-black px-3 py-1.5 rounded-xl transition flex items-center gap-1 shadow-lg shadow-emerald-950/50">
<i class="ph-bold ph-shuffle text-sm"></i> جابجایی سریع روز رشت
</button>
</div>
</div>
<!-- Days Container -->
<div id="itinerary-container" class="space-y-3.5">
<!-- Rendered by JavaScript -->
</div>
</section>
<!-- ============================================================== -->
<!-- TAB 2: ROSTER & LEADERBOARD & REVIEWS WALL (لیدربورد شیک و نظرات) -->
<!-- ============================================================== -->
<section id="tab-roster" class="tab-content space-y-4">
<!-- Leaderboard Header Card -->
<div class="glass-card rounded-2xl p-4 border border-dark-border">
<div class="flex items-center justify-between pb-3 border-b border-dark-border">
<div class="flex items-center gap-2.5">
<div class="w-10 h-10 rounded-xl bg-amber-500/20 border border-amber-500/30 flex items-center justify-center text-amber-400 text-2xl">
<i class="ph-bold ph-trophy"></i>
</div>
<div>
<h2 class="text-sm sm:text-base font-black text-white">جدول امتیازات و رده‌بندی همسفران</h2>
<p class="text-[11px] text-slate-400">محاسبه زنده بر اساس نظرسنجی‌های شبانه و ارزیابی منصفانه وظایف</p>
</div>
</div>
<button onclick="scrollToNightlyPoll()" class="bg-gradient-to-r from-emerald-500 to-teal-400 text-black text-xs font-black px-3.5 py-2 rounded-xl transition shadow-md shadow-emerald-950/40 flex items-center gap-1.5 active:scale-95">
<i class="ph-bold ph-star text-base"></i> ثبت / ویرایش نظر من
</button>
</div>
<!-- Leaderboard List -->
<div id="leaderboard-list" class="mt-4 grid grid-cols-1 gap-2.5">
<!-- Rendered by JavaScript -->
</div>
</div>
<!-- Companions Status Cards -->
<div class="glass-card rounded-2xl p-4 border border-dark-border">
<h3 class="text-xs sm:text-sm font-black text-white mb-3 flex items-center gap-2">
<i class="ph-bold ph-users-three text-emerald-400 text-base"></i> وضعیت حضور و اطلاعات ۷ همسفر
</h3>
<div id="companions-grid" class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<!-- Rendered by JavaScript -->
</div>
</div>
<!-- NIGHTLY POLL SECTION -->
<div id="nightly-poll-section" class="glass-card rounded-2xl p-4 border-2 border-emerald-500/50 relative overflow-hidden">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-2.5 pb-3 border-b border-dark-border">
<div class="flex items-center gap-2.5">
<div class="w-10 h-10 rounded-xl bg-emerald-500 text-black flex items-center justify-center font-black text-xl shadow-lg">
<i class="ph-bold ph-scales"></i>
</div>
<div>
<h3 class="text-sm sm:text-base font-black text-white flex items-center gap-2">
<span>نظرسنجی و داوری منصفانه شبانه</span>
<span class="text-[10px] bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 px-2 py-0.5 rounded-full font-bold">+۱۰ امتیاز مشارکت</span>
</h3>
<p class="text-[11px] text-slate-300">هر همسفر مالک نظرات خود است و فقط می‌تواند نظر خودش را ویرایش یا حذف کند.</p>
</div>
</div>
<!-- Select Poll Day -->
<div class="flex items-center gap-2">
<label class="text-xs text-slate-300">شب نظرسنجی:</label>
<select id="poll-day-select" onchange="changePollDay(this.value)" class="bg-dark-bg border border-emerald-500/50 text-xs rounded-xl px-3 py-1.5 text-white font-bold focus:outline-none">
<option value="day1_tue">سه‌شنبه ۷ مهر (شب اول)</option>
<option value="day2_wed">چهارشنبه ۸ مهر (شب دوم)</option>
<option value="day3_thu" selected>پنج‌شنبه ۹ مهر (شب سوم)</option>
<option value="day4_fri">جمعه ۱۰ مهر (شب چهارم)</option>
<option value="day5_sat">شنبه ۱۱ مهر (شب پنجم)</option>
<option value="day6_sun">یکشنبه ۱۲ مهر (شب فینال)</option>
</select>
</div>
</div>
<!-- Ownership Status Alert Banner -->
<div id="user-vote-ownership-banner" class="hidden mt-3 p-3 rounded-xl border text-xs flex flex-col sm:flex-row sm:items-center justify-between gap-2 bg-emerald-950/40 border-emerald-500/60 text-emerald-200">
<div class="flex items-center gap-2">
<i class="ph-bold ph-check-circle text-lg text-emerald-400"></i>
<span>شما برای این شب نظر ثبت کرده‌اید. در فرم زیر می‌توانید آن را ویرایش کرده یا کلاً حذف کنید.</span>
</div>
<button onclick="deleteMyVote(currentPollDay, currentUser)" class="bg-rose-500/20 hover:bg-rose-500/30 text-rose-300 border border-rose-500/40 px-2.5 py-1 rounded-lg text-xs font-bold flex items-center gap-1 transition self-end sm:self-auto">
<i class="ph-bold ph-trash"></i> حذف نظر من
</button>
</div>
<!-- Poll Form -->
<div class="mt-4 space-y-4">
<!-- Fair Roles Selection -->
<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-3.5 space-y-3">
<span class="text-xs font-black text-amber-300 block flex items-center gap-1.5">
<i class="ph-bold ph-gavel text-base"></i> داوری وظایف امشب:
</span>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label class="text-[11px] text-slate-300 block mb-1">🧼 کی امشب بیشترین ظرف‌ها رو شست؟ (+۲۰ امتیاز)</label>
<select id="vote-dishwashing" class="w-full bg-dark-card border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500">
<option value="">انتخاب همسفر...</option>
</select>
</div>
<div>
<label class="text-[11px] text-slate-300 block mb-1">👨‍🍳 کی بیشترین زحمت آشپزی و منقل رو کشید؟ (+۲۵ امتیاز)</label>
<select id="vote-cooking" class="w-full bg-dark-card border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500">
<option value="">انتخاب همسفر...</option>
</select>
</div>
<div>
<label class="text-[11px] text-slate-300 block mb-1">🤝 کی بیشترین کمک عمومی و کار تیمی رو داشت؟ (+۱۵ امتیاز)</label>
<select id="vote-helper" class="w-full bg-dark-card border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500">
<option value="">انتخاب همسفر...</option>
</select>
</div>
<div>
<label class="text-[11px] text-rose-300 block mb-1">🛋️ کی امشب بیشترین تنبلی رو کرد؟ (-۱۰ امتیاز)</label>
<select id="vote-lazy" class="w-full bg-dark-card border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-rose-500">
<option value="">انتخاب همسفر...</option>
</select>
</div>
</div>
</div>
<!-- Peer Ratings & Rich Comments Box -->
<div class="space-y-3">
<span class="text-xs font-black text-white block flex items-center gap-1.5">
<i class="ph-bold ph-star-half text-emerald-400 text-base"></i> امتیازدهی و نوشتن کامنت برای هر همسفر:
</span>
<div id="peer-ratings-container" class="space-y-2.5">
<!-- Rendered for each companion except active user -->
</div>
</div>
<!-- Submit Button -->
<div class="pt-2 flex flex-col sm:flex-row sm:items-center justify-between gap-3 bg-dark-bg/60 p-3 rounded-xl border border-dark-border">
<div class="flex items-center gap-2">
<span class="text-xs text-slate-400">پروفایل ثبت‌کننده:</span>
<span id="poll-current-voter" class="text-xs font-black text-emerald-400 bg-dark-card px-2.5 py-1 rounded-lg border border-dark-border">محدثه</span>
</div>
<div class="flex items-center gap-2">
<button id="btn-delete-poll-vote" onclick="deleteMyVote(currentPollDay, currentUser)" class="hidden bg-rose-500/20 hover:bg-rose-500/30 text-rose-300 border border-rose-500/40 text-xs font-bold px-3.5 py-2.5 rounded-xl transition flex items-center gap-1">
<i class="ph-bold ph-trash"></i> حذف نظر من
</button>
<button id="btn-submit-poll-vote" onclick="submitNightlyPoll()" class="bg-gradient-to-r from-emerald-500 to-teal-400 hover:from-emerald-400 hover:to-teal-300 text-black font-black text-xs sm:text-sm px-6 py-2.5 rounded-xl transition flex items-center justify-center gap-2 shadow-lg shadow-emerald-950/60 active:scale-95">
<i class="ph-bold ph-paper-plane-right text-lg"></i> <span id="submit-btn-label">ثبت و ذخیره قطعی نظرسنجی</span>
</button>
</div>
</div>
</div>
<!-- REVIEWS & COMMENTS WALL (بخش بازخوردها و نظرات کامل با قابلیت مدیریت مالکیت) -->
<div class="mt-6 pt-5 border-t border-dark-border">
<div class="flex items-center justify-between mb-3">
<h4 class="text-xs sm:text-sm font-black text-white flex items-center gap-2">
<i class="ph-bold ph-chat-circle-dots text-emerald-400 text-lg"></i> دیوار نظرات و کامنت‌های همسفران
</h4>
<span id="reviews-count-badge" class="text-[10px] bg-dark-bg border border-dark-border text-slate-300 px-2 py-0.5 rounded-full">۰ نظر</span>
</div>
<div id="poll-reviews-feed" class="space-y-2.5 max-h-96 overflow-y-auto pr-1">
<!-- Rendered by JavaScript -->
</div>
</div>
</div>
</section>
<!-- ============================================================== -->
<!-- TAB 3: SHOPPING LIST (ویرایش مستقیم قیمت و اقلام مهر ۱۴۰۵) -->
<!-- ============================================================== -->
<section id="tab-shopping" class="tab-content space-y-4">
<!-- Shopping Summary Card -->
<div class="glass-card rounded-2xl p-4 border border-dark-border">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-3 border-b border-dark-border">
<div>
<h2 class="text-sm sm:text-base font-black text-white flex items-center gap-2">
<i class="ph-bold ph-basket text-emerald-400 text-xl"></i> لیست خرید و مخارج ویلا (دیجی‌کالا جت / مهر ۱۴۰۵)
</h2>
<p class="text-[11px] text-slate-400 mt-0.5">قیمت‌ها به تومان و مستقیماً در جدول <strong>قابل ویرایش</strong> هستند.</p>
</div>
<div class="flex items-center gap-2 flex-wrap no-print">
<button onclick="exportShoppingPDF()" class="bg-emerald-500 hover:bg-emerald-400 text-black text-xs font-black px-3 py-1.5 rounded-xl transition flex items-center gap-1 shadow-md">
<i class="ph-bold ph-file-pdf text-sm"></i> خروجی PDF
</button>
<button onclick="openAddItemModal()" class="bg-dark-card border border-emerald-500/40 hover:border-emerald-400 text-white text-xs font-bold px-3 py-1.5 rounded-xl transition flex items-center gap-1">
<i class="ph-bold ph-plus text-sm text-emerald-400"></i> افزودن آیتم جدید
</button>
<button onclick="copyShoppingListText()" class="bg-dark-card border border-dark-border text-slate-300 hover:text-white text-xs font-bold px-2.5 py-1.5 rounded-xl transition" title="کپی متن لیست">
<i class="ph-bold ph-copy text-sm"></i>
</button>
</div>
</div>
<!-- Budget & Per Person Overview -->
<div class="grid grid-cols-2 sm:grid-cols-4 gap-2.5 pt-3.5 text-center">
<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-2.5">
<span class="text-[10px] text-slate-400 block">کل برآورد خرید</span>
<span id="shop-total-cost" class="text-xs sm:text-sm font-black text-emerald-400">-- تومان</span>
</div>
<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-2.5">
<span class="text-[10px] text-slate-400 block">سهم هر نفر (۷ نفر)</span>
<span id="shop-per-person-7" class="text-xs sm:text-sm font-black text-white">-- تومان</span>
</div>
<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-2.5">
<span class="text-[10px] text-slate-400 block">خریداری شده</span>
<span id="shop-bought-count" class="text-xs sm:text-sm font-black text-teal-300">۰ از ۲۰</span>
</div>
<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-2.5">
<span class="text-[10px] text-slate-400 block">وضعیت بودجه</span>
<span class="text-xs sm:text-sm font-black text-emerald-400">مناسب و کنترل‌شده</span>
</div>
</div>
</div>
<!-- Printable Area & Editable Item Cards -->
<div id="shopping-printable-area" class="space-y-4">
<!-- Rendered by JavaScript -->
</div>
</section>
<!-- ============================================================== -->
<!-- TAB 4: ACTIVITIES & ZARFILM MOVIES -->
<!-- ============================================================== -->
<section id="tab-activities" class="tab-content space-y-4">
<!-- Zarfilm Special Movies Section -->
<div class="glass-card rounded-2xl p-4 border-2 border-amber-500/40">
<div class="flex items-center justify-between pb-3 border-b border-dark-border">
<div class="flex items-center gap-2.5">
<div class="w-10 h-10 rounded-xl bg-amber-500/20 border border-amber-500/30 flex items-center justify-center text-amber-400 text-xl">
<i class="ph-bold ph-film-slate"></i>
</div>
<div>
<h2 class="text-sm sm:text-base font-black text-white flex items-center gap-1.5">
<span>لیست پیشنهادی فیلم‌های زرفیلم (Zarfilm)</span>
<span class="text-[10px] bg-amber-500/20 text-amber-300 border border-amber-500/30 px-1.5 py-0.5 rounded font-bold">مخصوص جمع دوستانه</span>
</h2>
<p class="text-[11px] text-slate-400">فیلم‌های کمدی، معمایی و سرگرم‌کننده مناسب شب‌های ویلای شمال</p>
</div>
</div>
</div>
<div id="movies-container" class="mt-3.5 grid grid-cols-1 sm:grid-cols-2 gap-3">
<!-- Rendered by JavaScript -->
</div>
</div>
<!-- Outdoor & Indoor Activities -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="glass-card rounded-2xl p-4 border border-dark-border space-y-3">
<h3 class="text-xs sm:text-sm font-black text-white flex items-center gap-2 pb-2 border-b border-dark-border">
<i class="ph-bold ph-sun-horizon text-emerald-400 text-lg"></i> تفریحات و گشت‌های بیرونی (Outdoor)
</h3>
<div id="outdoor-activities-list" class="space-y-2.5">
<!-- Rendered by JavaScript -->
</div>
</div>
<div class="glass-card rounded-2xl p-4 border border-dark-border space-y-3">
<h3 class="text-xs sm:text-sm font-black text-white flex items-center gap-2 pb-2 border-b border-dark-border">
<i class="ph-bold ph-house-line text-amber-400 text-lg"></i> تفریحات و سرگرمی‌های داخل ویلا (Indoor)
</h3>
<div id="indoor-activities-list" class="space-y-2.5">
<!-- Rendered by JavaScript -->
</div>
</div>
</div>
</section>
<!-- ============================================================== -->
<!-- TAB 5: ROUTES & NAVIGATION -->
<!-- ============================================================== -->
<section id="tab-routes" class="tab-content space-y-3.5">
<div class="glass-card rounded-2xl p-4 border border-dark-border space-y-3">
<h2 class="text-sm sm:text-base font-black text-white flex items-center gap-2">
<i class="ph-bold ph-map-trifold text-emerald-400 text-xl"></i> نقشه لوپ البرز (Circular Route)
</h2>
<p class="text-xs text-slate-300 leading-relaxed">
مسیر رفت از <strong>جاده هراز</strong> به چمستان امیرآباد، گشت‌های میانی در خط ساحلی خزر به سمت <strong>رشت</strong>، و بازگشت روز یکشنبه از <strong>آزادراه قزوین-رشت</strong> به تهران.
</p>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-2.5 pt-2">
<div class="bg-dark-bg p-3 rounded-xl border border-dark-border space-y-1">
<span class="text-[10px] text-emerald-400 font-bold block">مرحله اول: رفت (سه‌شنبه / چهارشنبه)</span>
<strong class="text-xs text-white block">تهران ➔ رودهن ➔ هراز ➔ آمل ➔ چمستان</strong>
<p class="text-[11px] text-slate-400">مسافت: ۱۸۰ کیلومتر (۳.۵ ساعت)</p>
</div>
<div class="bg-dark-bg p-3 rounded-xl border border-dark-border space-y-1">
<span class="text-[10px] text-amber-400 font-bold block">مرحله دوم: گیلان و رشت (جمعه)</span>
<strong class="text-xs text-white block">چمستان ➔ نور ➔ نوشهر ➔ رامسر ➔ رشت</strong>
<p class="text-[11px] text-slate-400">مسافت: ۱۹۰ کیلومتر خط ساحلی دیدنی</p>
</div>
<div class="bg-dark-bg p-3 rounded-xl border border-dark-border space-y-1">
<span class="text-[10px] text-teal-400 font-bold block">مرحله سوم: بازگشت روان (یکشنبه)</span>
<strong class="text-xs text-white block">رشت ➔ رودبار ➔ قزوین ➔ کرج ➔ تهران</strong>
<p class="text-[11px] text-slate-400">مسافت: ۳۱۰ کیلومتر تماماً آزادراه دوبانده</p>
</div>
</div>
</div>
</section>
</main>
<!-- ============================================================== -->
<!-- MODAL: TRANSFER PLAN TO ANOTHER DAY (مکانیزم انتقال روان) -->
<!-- ============================================================== -->
<div id="modal-transfer-plan" class="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm hidden flex items-center justify-center p-3.5 no-print">
<div class="glass-card w-full max-w-md rounded-2xl p-4 border border-dark-border space-y-3.5">
<div class="flex items-center justify-between pb-2 border-b border-dark-border">
<h3 class="text-sm font-black text-white flex items-center gap-2">
<i class="ph-bold ph-arrows-left-right text-emerald-400 text-lg"></i> انتقال برنامه به روز دیگر
</h3>
<button onclick="closeTransferModal()" class="text-slate-400 hover:text-white"><i class="ph-bold ph-x text-lg"></i></button>
</div>
<div class="space-y-1">
<span class="text-xs text-slate-400">برنامه انتخاب‌شده:</span>
<strong id="transfer-plan-title" class="text-xs sm:text-sm text-emerald-400 block bg-dark-bg p-2 rounded-xl border border-dark-border">عنوان برنامه</strong>
</div>
<div class="space-y-2 pt-1">
<span class="text-xs text-slate-300 block">انتقال به کدام روز انجام شود؟</span>
<div id="transfer-days-list" class="space-y-1.5">
<!-- Rendered by JavaScript -->
</div>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: PROFILE SELECTOR (با قابلیت تعریف رمز ۴ رقمی اختیاری) -->
<!-- ============================================================== -->
<div id="modal-profile" class="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm hidden flex items-center justify-center p-3.5 no-print">
<div class="glass-card w-full max-w-md rounded-2xl p-4 border border-dark-border space-y-3.5">
<div class="flex items-center justify-between pb-2 border-b border-dark-border">
<h3 class="text-sm font-black text-white flex items-center gap-2">
<i class="ph-bold ph-user-circle text-emerald-400 text-lg"></i> انتخاب پروفایل شما
</h3>
<button onclick="closeProfileModal()" class="text-slate-400 hover:text-white"><i class="ph-bold ph-x text-lg"></i></button>
</div>
<p class="text-xs text-slate-300">پروفایل خود را انتخاب کنید تا بتوانید نظرات و امتیازات اختصاصی خود را ثبت یا ویرایش کنید:</p>
<div id="modal-profile-list" class="grid grid-cols-1 gap-2 max-h-80 overflow-y-auto pr-1">
<!-- Rendered by JavaScript -->
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: ADD SHOPPING ITEM -->
<!-- ============================================================== -->
<div id="modal-add-item" class="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm hidden flex items-center justify-center p-3.5 no-print">
<div class="glass-card w-full max-w-md rounded-2xl p-4 border border-dark-border space-y-3.5">
<div class="flex items-center justify-between pb-2 border-b border-dark-border">
<h3 class="text-sm font-black text-white flex items-center gap-2">
<i class="ph-bold ph-plus-circle text-emerald-400 text-lg"></i> افزودن آیتم جدید به لیست خرید
</h3>
<button onclick="closeAddItemModal()" class="text-slate-400 hover:text-white"><i class="ph-bold ph-x text-lg"></i></button>
</div>
<form id="form-add-item" onsubmit="handleSaveItem(event)" class="space-y-3">
<div>
<label class="text-[11px] text-slate-300 block mb-1">دسته‌بندی:</label>
<select id="item-cat-select" class="w-full bg-dark-bg border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500">
<option value="bbq">جوجه‌کباب و باربیکیو شبانه</option>
<option value="breakfast">صبحانه‌ها و عصرانه‌ها</option>
<option value="snacks">تنقلات و نوشیدنی‌ها</option>
<option value="hygiene">ملزومات بهداشتی و نظافت</option>
</select>
</div>
<div>
<label class="text-[11px] text-slate-300 block mb-1">نام محصول (سوپرمارکت / دیجی‌کالا جت):</label>
<input type="text" id="item-name-input" required placeholder="مثال: نوشابه خانواده کوکاکولا" class="w-full bg-dark-bg border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500" />
</div>
<div class="grid grid-cols-2 gap-2">
<div>
<label class="text-[11px] text-slate-300 block mb-1">قیمت واحد (تومان):</label>
<input type="number" id="item-price-input" required placeholder="مثال: 55000" class="w-full bg-dark-bg border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500" />
</div>
<div>
<label class="text-[11px] text-slate-300 block mb-1">خریدار / پرداخت‌کننده:</label>
<input type="text" id="item-payer-input" placeholder="صندوق مشترک" class="w-full bg-dark-bg border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500" />
</div>
</div>
<div>
<label class="text-[11px] text-slate-300 block mb-1">یادداشت:</label>
<input type="text" id="item-notes-input" placeholder="مثال: خرید از چمستان" class="w-full bg-dark-bg border border-dark-border text-xs rounded-xl px-3 py-2 text-white focus:outline-none focus:border-emerald-500" />
</div>
<div class="pt-2 flex items-center justify-end gap-2">
<button type="button" onclick="closeAddItemModal()" class="px-3 py-2 rounded-xl text-xs font-bold text-slate-300 hover:text-white">انصراف</button>
<button type="submit" class="bg-emerald-500 hover:bg-emerald-400 text-black text-xs font-black px-4 py-2 rounded-xl transition">افزودن به لیست</button>
</div>
</form>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: SWAP RASHT DAY -->
<!-- ============================================================== -->
<div id="modal-swap-rasht" class="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm hidden flex items-center justify-center p-3.5 no-print">
<div class="glass-card w-full max-w-md rounded-2xl p-4 border border-dark-border space-y-3.5">
<div class="flex items-center justify-between pb-2 border-b border-dark-border">
<h3 class="text-sm font-black text-white flex items-center gap-2">
<i class="ph-bold ph-shuffle text-emerald-400 text-lg"></i> جابجایی روز سفر به رشت
</h3>
<button onclick="closeSwapRashtModal()" class="text-slate-400 hover:text-white"><i class="ph-bold ph-x text-lg"></i></button>
</div>
<p class="text-xs text-slate-300 leading-relaxed">
برنامه گشت رشت را به کدام روز مایلید جابجا کنید؟
</p>
<div class="space-y-2">
<button onclick="swapRashtWith('day-3')" class="w-full text-right bg-dark-bg hover:bg-dark-border p-3 rounded-xl border border-dark-border text-xs text-white flex items-center justify-between transition">
<span>جابجایی با <strong>پنج‌شنبه ۹ مهر</strong> (روز باربیکیو)</span>
<i class="ph-bold ph-arrow-left text-emerald-400"></i>
</button>
<button onclick="swapRashtWith('day-5')" class="w-full text-right bg-dark-bg hover:bg-dark-border p-3 rounded-xl border border-dark-border text-xs text-white flex items-center justify-between transition">
<span>جابجایی با <strong>شنبه ۱۱ مهر</strong> (روز بدرقه)</span>
<i class="ph-bold ph-arrow-left text-emerald-400"></i>
</button>
</div>
</div>
</div>
<!-- ============================================================== -->
<!-- JAVASCRIPT APPLICATION CORE -->
<!-- ============================================================== -->
<script>
var appState = null;
var currentUser = localStorage.getItem('shomal_active_user') || 'mohadese';
var currentPollDay = 'day3_thu';
var syncInterval = null;
var transferSource = { dayIdx: null, planIdx: null };
// Tab Switcher
function switchTab(tabId) {
var contents = document.querySelectorAll('.tab-content');
for (var i = 0; i < contents.length; i++) {
contents[i].classList.remove('active');
}
var buttons = document.querySelectorAll('.tab-btn');
for (var j = 0; j < buttons.length; j++) {
buttons[j].classList.remove('active', 'bg-emerald-500', 'text-black');
buttons[j].classList.add('bg-dark-card', 'text-slate-300', 'border', 'border-dark-border');
}
var activeContent = document.getElementById('tab-' + tabId);
var activeBtn = document.getElementById('btn-tab-' + tabId);
if (activeContent) activeContent.classList.add('active');
if (activeBtn) {
activeBtn.classList.add('active', 'bg-emerald-500', 'text-black');
activeBtn.classList.remove('bg-dark-card', 'text-slate-300');
}
}
// Default State
var defaultState = {
version: '2.1.0',
members: [
{ id: 'mohadese', name: 'محدثه', group: 1, departure_day: 'سه‌شنبه شب ۷ مهر', return_day: 'یکشنبه ۱۲ مهر', role: 'مدیریت برنامه و هماهنگی سفر', car: 'ماشین ۱', avatar: '👩‍💼', score: 100 },
{ id: 'mohammadreza', name: 'محمدرضا', group: 1, departure_day: 'سه‌شنبه شب ۷ مهر', return_day: 'یکشنبه ۱۲ مهر', role: 'مسئول لجستیک و ناوبری مسیر', car: 'ماشین ۱', avatar: '🧔', score: 100 },
{ id: 'arya', name: 'آریا', group: 1, departure_day: 'سه‌شنبه شب ۷ مهر', return_day: 'یکشنبه ۱۲ مهر', role: 'میزبان ویلا (چمستان امیرآباد)', car: 'ماشین ۱', avatar: '👑', score: 100 },
{ id: 'sina', name: 'سینا', group: 1, departure_day: 'سه‌شنبه شب ۷ مهر', return_day: 'یکشنبه ۱۲ مهر', role: 'مدیر باربیکیو و تفریحات', car: 'ماشین ۱', avatar: '🔥', score: 100 },
{ id: 'amirhossein', name: 'امیرحسین', group: 2, departure_day: 'چهارشنبه شب ۸ مهر (بعد کار)', return_day: 'یکشنبه ۱۲ مهر', role: 'دی‌جی و سیستم صوتی و انرژی', car: 'ماشین ۲', avatar: '🎧', score: 100 },
{ id: 'ava', name: 'آوا', group: 2, departure_day: 'چهارشنبه شب ۸ مهر (بعد کار)', return_day: 'شنبه ۱۱ مهر (بازگشت)', role: 'عکاسی و مستندسازی خاطرات', car: 'ماشین ۲', avatar: '📸', score: 100 },
{ id: 'mohammad', name: 'محمد', group: 2, departure_day: 'چهارشنبه شب ۸ مهر (بعد کار)', return_day: 'شنبه ۱۱ مهر (بازگشت)', role: 'مدیریت بازی‌ها و مافیا', car: 'ماشین ۲', avatar: '🎲', score: 100 }
],
daily_surveys: {
day1_tue: { title: 'سه‌شنبه شب ۷ مهر (حرکت گروه ۱)', is_active: true, votes: [] },
day2_wed: { title: 'چهارشنبه ۸ مهر (ورود گروه ۲ و دورهمی)', is_active: true, votes: [] },
day3_thu: { title: 'پنج‌شنبه ۹ مهر (روز جمعی و باربیکیو)', is_active: true, votes: [] },
day4_fri: { title: 'جمعه ۱۰ مهر (اکسپدیشن و تفریحات)', is_active: true, votes: [] },
day5_sat: { title: 'شنبه ۱۱ مهر (خداحافظی آوا و محمد)', is_active: true, votes: [] },
day6_sun: { title: 'یکشنبه ۱۲ مهر (فینال و بازگشت)', is_active: true, votes: [] }
},
itinerary_days: [],
shopping_categories: [],
movies: [],
activities_list: { outdoor: [], indoor: [] }
};
// App Initialization
async function initApp() {
setupCountdowns();
await fetchState();
renderAll();
startLiveSync();
}
// Backend Fetch
async function fetchState() {
try {
const res = await fetch('/api/shomal/state');
if (res.ok) {
appState = await res.json();
updateSyncIndicator(true);
} else {
appState = defaultState;
}
} catch (err) {
console.warn('Backend fetch error, using local fallback:', err);
if (!appState) appState = defaultState;
}
}
// Backend Save
async function saveState(actionName) {
if (!actionName) actionName = 'ویرایش';
updateSyncIndicator(false);
try {
appState.updated_by = currentUser;
const res = await fetch('/api/shomal/state', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(appState)
});
if (res.ok) {
updateSyncIndicator(true);
showToast('تغییرات (' + actionName + ') برای همه همسفران ذخیره شد.');
} else {
showToast('خطا در ذخیره‌سازی سرور', true);
}
} catch (err) {
console.error('Save error:', err);
showToast('عدم اتصال به سرور جهت ذخیره', true);
}
}
// Auto Polling Live Sync
function startLiveSync() {
if (syncInterval) clearInterval(syncInterval);
syncInterval = setInterval(async function() {
try {
const res = await fetch('/api/shomal/state');
if (res.ok) {
const freshState = await res.json();
if (JSON.stringify(freshState) !== JSON.stringify(appState)) {
appState = freshState;
renderAll();
}
}
} catch (e) {}
}, 6000);
}
function updateSyncIndicator(isSynced) {
const el = document.getElementById('sync-status');
if (!el) return;
if (isSynced) {
el.innerHTML = '<span class="w-2 h-2 rounded-full bg-emerald-400"></span><span>همگام</span>';
} else {
el.innerHTML = '<span class="w-2 h-2 rounded-full bg-amber-400 animate-spin"></span><span>در حال ذخیره...</span>';
}
}
// Master Render
function renderAll() {
if (!appState) return;
updateActiveUserUI();
renderItinerary();
renderLeaderboard();
renderCompanionsGrid();
renderPollForm();
renderShoppingList();
renderActivitiesAndMovies();
}
// User Profile
function updateActiveUserUI() {
const user = appState.members.find(function(m) { return m.id === currentUser; }) || appState.members[0];
document.getElementById('header-user-avatar').textContent = user.avatar;
document.getElementById('header-user-name').textContent = user.name;
const voterEl = document.getElementById('poll-current-voter');
if (voterEl) voterEl.textContent = user.name;
}
function openProfileModal() {
const listEl = document.getElementById('modal-profile-list');
listEl.innerHTML = appState.members.map(function(m) {
var isCurr = (m.id === currentUser);
return '<button onclick="selectUserProfile(\'' + m.id + '\')" class="w-full text-right p-3 rounded-xl border transition flex items-center justify-between ' + (isCurr ? 'bg-emerald-950/60 border-emerald-500' : 'bg-dark-bg border-dark-border hover:border-slate-500') + '">' +
'<div class="flex items-center gap-2.5">' +
'<span class="text-2xl">' + m.avatar + '</span>' +
'<div>' +
'<strong class="text-xs sm:text-sm text-white font-bold block">' + m.name + '</strong>' +
'<span class="text-[11px] text-slate-400">' + m.role + '</span>' +
'</div>' +
'</div>' +
'<span class="text-xs font-bold text-emerald-400">' + m.score + ' امتیاز</span>' +
'</button>';
}).join('');
document.getElementById('modal-profile').classList.remove('hidden');
}
function closeProfileModal() {
document.getElementById('modal-profile').classList.add('hidden');
}
function selectUserProfile(userId) {
currentUser = userId;
localStorage.setItem('shomal_active_user', userId);
closeProfileModal();
renderAll();
var u = appState.members.find(function(m) { return m.id === userId; });
showToast('پروفایل شما به «' + (u ? u.name : userId) + '» تغییر کرد.');
}
// ==============================================================
// ITINERARY RENDERING & ROBUST TRANSFER MECHANISM
// ==============================================================
function renderItinerary() {
const container = document.getElementById('itinerary-container');
if (!container || !appState.itinerary_days) return;
container.innerHTML = appState.itinerary_days.map(function(day, dIdx) {
var upBtn = (dIdx > 0) ? '<button onclick="moveDay(' + dIdx + ', -1)" class="w-7 h-7 rounded-lg bg-dark-bg border border-dark-border flex items-center justify-center text-slate-300 hover:text-white" title="انتقال کل روز به بالا"><i class="ph-bold ph-caret-up"></i></button>' : '';
var downBtn = (dIdx < appState.itinerary_days.length - 1) ? '<button onclick="moveDay(' + dIdx + ', 1)" class="w-7 h-7 rounded-lg bg-dark-bg border border-dark-border flex items-center justify-center text-slate-300 hover:text-white" title="انتقال کل روز به پایین"><i class="ph-bold ph-caret-down"></i></button>' : '';
var plansHtml = day.plans.map(function(p, pIdx) {
var pUp = (pIdx > 0) ? '<button onclick="movePlan(' + dIdx + ', ' + pIdx + ', -1)" class="w-6 h-6 rounded bg-dark-card text-slate-400 hover:text-white flex items-center justify-center text-xs" title="انتقال به بالا"><i class="ph-bold ph-arrow-up"></i></button>' : '';
var pDown = (pIdx < day.plans.length - 1) ? '<button onclick="movePlan(' + dIdx + ', ' + pIdx + ', 1)" class="w-6 h-6 rounded bg-dark-card text-slate-400 hover:text-white flex items-center justify-center text-xs" title="انتقال به پایین"><i class="ph-bold ph-arrow-down"></i></button>' : '';
return '<div class="bg-dark-bg/80 border border-dark-border/70 rounded-xl p-3 flex flex-col sm:flex-row sm:items-start justify-between gap-2.5 hover:border-slate-600 transition">' +
'<div class="flex items-start gap-2.5 flex-1">' +
'<div class="w-8 h-8 rounded-lg bg-dark-card border border-dark-border flex items-center justify-center text-emerald-400 shrink-0 mt-0.5">' +
'<i class="ph-bold ' + (p.icon || 'ph-map-pin') + ' text-base"></i>' +
'</div>' +
'<div class="space-y-1">' +
'<div class="flex items-center gap-2 flex-wrap">' +
'<span class="text-[10px] bg-dark-card text-slate-300 px-1.5 py-0.5 rounded font-mono font-bold">' + p.time + '</span>' +
'<strong class="text-xs sm:text-sm text-white font-bold">' + p.title + '</strong>' +
'</div>' +
'<p class="text-[11px] text-slate-400 leading-relaxed">' + p.desc + '</p>' +
'<div class="flex items-center gap-1 text-[10px] text-emerald-400 font-semibold pt-0.5">' +
'<i class="ph-bold ph-map-pin"></i>' +
'<span>' + p.loc + '</span>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="flex items-center justify-end gap-1.5 shrink-0 pt-1 sm:pt-0 no-print border-t sm:border-t-0 border-dark-border/40">' +
'<button onclick="openTransferPlanModal(' + dIdx + ', ' + pIdx + ')" class="bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-300 border border-emerald-500/40 text-[10px] font-bold px-2 py-1 rounded-lg flex items-center gap-1 transition" title="انتقال این برنامه به روزی دیگر">' +
'<i class="ph-bold ph-arrows-left-right"></i> انتقال به روز دیگر' +
'</button>' +
pUp + pDown +
'</div>' +
'</div>';
}).join('');
return '<div class="glass-card rounded-2xl p-4 border border-dark-border space-y-3 relative overflow-hidden" id="card-' + day.id + '">' +
'<div class="flex items-center justify-between pb-2.5 border-b border-dark-border/70">' +
'<div class="flex items-center gap-2">' +
'<span class="w-7 h-7 rounded-xl bg-emerald-500/20 text-emerald-400 flex items-center justify-center text-xs font-bold font-mono">' + (dIdx + 1) + '</span>' +
'<div>' +
'<h3 class="text-xs sm:text-sm font-black text-white">' + day.day_name + '</h3>' +
'<span class="text-[10px] text-emerald-400 font-bold">' + day.tag + '</span>' +
'</div>' +
'</div>' +
'<div class="flex items-center gap-1.5 no-print">' + upBtn + downBtn + '</div>' +
'</div>' +
'<div class="space-y-2">' + plansHtml + '</div>' +
'</div>';
}).join('');
}
function moveDay(idx, dir) {
const targetIdx = idx + dir;
if (targetIdx < 0 || targetIdx >= appState.itinerary_days.length) return;
const temp = appState.itinerary_days[idx];
appState.itinerary_days[idx] = appState.itinerary_days[targetIdx];
appState.itinerary_days[targetIdx] = temp;
renderItinerary();
saveState('جابجایی روز');
}
function movePlan(dIdx, pIdx, dir) {
const plans = appState.itinerary_days[dIdx].plans;
const targetPIdx = pIdx + dir;
if (targetPIdx < 0 || targetPIdx >= plans.length) return;
const temp = plans[pIdx];
plans[pIdx] = plans[targetPIdx];
plans[targetPIdx] = temp;
renderItinerary();
saveState('تغییر اولویت پلن');
}
function openTransferPlanModal(dIdx, pIdx) {
transferSource = { dayIdx: dIdx, planIdx: pIdx };
const plan = appState.itinerary_days[dIdx].plans[pIdx];
document.getElementById('transfer-plan-title').textContent = plan.title;
const daysListEl = document.getElementById('transfer-days-list');
daysListEl.innerHTML = appState.itinerary_days.map(function(d, idx) {
var isCurrent = (idx === dIdx);
return '<button ' + (isCurrent ? 'disabled' : '') + ' onclick="executeTransferPlan(' + idx + ')" class="w-full text-right p-2.5 rounded-xl border text-xs flex items-center justify-between transition ' + (isCurrent ? 'bg-dark-card border-dark-border opacity-50 cursor-not-allowed' : 'bg-dark-bg border-dark-border hover:border-emerald-500 text-white') + '">' +
'<span>' + d.day_name + ' (' + d.tag + ')</span>' +
(isCurrent ? '<span class="text-[10px] text-slate-500">روز جاری</span>' : '<i class="ph-bold ph-arrow-left text-emerald-400"></i>') +
'</button>';
}).join('');
document.getElementById('modal-transfer-plan').classList.remove('hidden');
}
function closeTransferModal() {
document.getElementById('modal-transfer-plan').classList.add('hidden');
}
function executeTransferPlan(targetDayIdx) {
if (transferSource.dayIdx === null || transferSource.planIdx === null) return;
const planToMove = appState.itinerary_days[transferSource.dayIdx].plans.splice(transferSource.planIdx, 1)[0];
appState.itinerary_days[targetDayIdx].plans.push(planToMove);
closeTransferModal();
renderItinerary();
saveState('انتقال برنامه به روز جدید');
showToast('برنامه با موفقیت به روز مقصد منتقل شد.');
}
function openSwapRashtModal() {
document.getElementById('modal-swap-rasht').classList.remove('hidden');
}
function closeSwapRashtModal() {
document.getElementById('modal-swap-rasht').classList.add('hidden');
}
function swapRashtWith(targetDayId) {
const rashtIdx = appState.itinerary_days.findIndex(function(d) {
return d.id === 'day-4' || d.day_name.indexOf('جمعه') !== -1 || (d.theme && d.theme.indexOf('رشت') !== -1);
});
const targetIdx = appState.itinerary_days.findIndex(function(d) { return d.id === targetDayId; });
if (rashtIdx !== -1 && targetIdx !== -1) {
const temp = appState.itinerary_days[rashtIdx];
appState.itinerary_days[rashtIdx] = appState.itinerary_days[targetIdx];
appState.itinerary_days[targetIdx] = temp;
closeSwapRashtModal();
renderItinerary();
saveState('جابجایی روز رشت');
showToast('روز سفر به رشت جابجا و در سرور ذخیره شد.');
}
}
// ==============================================================
// LEADERBOARD & REVIEWS (بدون لقب + وال کامنت‌ها)
// ==============================================================
function renderLeaderboard() {
const listEl = document.getElementById('leaderboard-list');
if (!listEl || !appState.members) return;
const calculatedScores = {};
appState.members.forEach(function(m) { calculatedScores[m.id] = 100; });
if (appState.daily_surveys) {
Object.values(appState.daily_surveys).forEach(function(day) {
if (!day.votes) return;
day.votes.forEach(function(v) {
if (calculatedScores[v.by_user] !== undefined) calculatedScores[v.by_user] += 10;
if (v.ratings) {
Object.keys(v.ratings).forEach(function(tid) {
var stars = parseInt(v.ratings[tid]) || 3;
if (calculatedScores[tid] !== undefined) calculatedScores[tid] += (stars * 4);
});
}
if (v.dishwashing && calculatedScores[v.dishwashing] !== undefined) calculatedScores[v.dishwashing] += 20;
if (v.cooking && calculatedScores[v.cooking] !== undefined) calculatedScores[v.cooking] += 25;
if (v.helper && calculatedScores[v.helper] !== undefined) calculatedScores[v.helper] += 15;
if (v.lazy && calculatedScores[v.lazy] !== undefined) calculatedScores[v.lazy] -= 10;
});
});
}
const sortedMembers = appState.members.map(function(m) {
return Object.assign({}, m, { score: calculatedScores[m.id] || m.score });
}).sort(function(a, b) { return b.score - a.score; });
const maxScore = Math.max.apply(Math, sortedMembers.map(function(m) { return m.score; })) || 100;
listEl.innerHTML = sortedMembers.map(function(m, rank) {
var medal = '';
var cardStyle = 'bg-dark-bg border-dark-border';
var scoreColor = 'text-emerald-400';
if (rank === 0) {
medal = '🥇';
cardStyle = 'bg-gradient-to-r from-amber-950/50 via-dark-card to-dark-bg border-amber-500/60 shadow-lg shadow-amber-950/30';
scoreColor = 'text-amber-400';
} else if (rank === 1) {
medal = '🥈';
cardStyle = 'bg-gradient-to-r from-slate-800/60 via-dark-card to-dark-bg border-slate-400/50';
scoreColor = 'text-slate-200';
} else if (rank === 2) {
medal = '🥉';
cardStyle = 'bg-gradient-to-r from-orange-950/40 via-dark-card to-dark-bg border-orange-500/50';
scoreColor = 'text-orange-300';
}
var progressPct = Math.round((m.score / (maxScore + 20)) * 100);
return '<div class="p-3.5 rounded-2xl border flex flex-col sm:flex-row sm:items-center justify-between gap-3 transition ' + cardStyle + '">' +
'<div class="flex items-center gap-3.5">' +
'<span class="w-8 text-center font-black text-base font-mono">' + (medal || ('#' + (rank + 1))) + '</span>' +
'<span class="text-3xl">' + m.avatar + '</span>' +
'<div>' +
'<div class="flex items-center gap-2">' +
'<strong class="text-sm sm:text-base font-bold text-white">' + m.name + '</strong>' +
'<span class="text-[10px] text-slate-400 bg-dark-bg px-2 py-0.5 rounded-md border border-dark-border">' + m.car + '</span>' +
'</div>' +
'<span class="text-xs text-slate-400 block mt-0.5">' + m.role + '</span>' +
'</div>' +
'</div>' +
'<div class="flex items-center justify-between sm:justify-end gap-3 sm:min-w-[180px]">' +
'<div class="w-24 bg-dark-bg rounded-full h-2 overflow-hidden border border-dark-border hidden sm:block">' +
'<div class="bg-emerald-400 h-full rounded-full" style="width: ' + progressPct + '%"></div>' +
'</div>' +
'<div class="text-left font-mono">' +
'<span class="text-sm sm:text-base font-black ' + scoreColor + ' block">' + m.score + '</span>' +
'<span class="text-[9px] text-slate-400 font-sans">امتیاز کل</span>' +
'</div>' +
'</div>' +
'</div>';
}).join('');
}
function renderCompanionsGrid() {
const grid = document.getElementById('companions-grid');
if (!grid || !appState.members) return;
grid.innerHTML = appState.members.map(function(m) {
return '<div class="bg-dark-bg/80 border border-dark-border rounded-xl p-3 space-y-2">' +
'<div class="flex items-center justify-between">' +
'<div class="flex items-center gap-2">' +
'<span class="text-2xl">' + m.avatar + '</span>' +
'<div>' +
'<strong class="text-xs sm:text-sm font-bold text-white block">' + m.name + '</strong>' +
'<span class="text-[11px] text-slate-400">' + m.role + '</span>' +
'</div>' +
'</div>' +
'<span class="text-[10px] bg-dark-card px-2 py-0.5 rounded-lg border border-dark-border text-slate-300 font-bold">' + m.car + '</span>' +
'</div>' +
'<div class="text-[11px] text-slate-400 space-y-1 pt-1.5 border-t border-dark-border/60">' +
'<div class="flex justify-between"><span>حرکت:</span><span class="text-slate-200 font-medium">' + m.departure_day + '</span></div>' +
'<div class="flex justify-between"><span>بازگشت:</span><span class="text-slate-200 font-medium">' + m.return_day + '</span></div>' +
'</div>' +
'</div>';
}).join('');
}
// ==============================================================
// POLL FORM & REVIEWS WALL (با مکانیزم بررسی مالکیت و ویرایش/حذف نظر)
// ==============================================================
function renderPollForm() {
const selectDish = document.getElementById('vote-dishwashing');
const selectCook = document.getElementById('vote-cooking');
const selectHelp = document.getElementById('vote-helper');
const selectLazy = document.getElementById('vote-lazy');
const ratingsCont = document.getElementById('peer-ratings-container');
const feedCont = document.getElementById('poll-reviews-feed');
const bannerEl = document.getElementById('user-vote-ownership-banner');
const deleteBtn = document.getElementById('btn-delete-poll-vote');
const submitLabel = document.getElementById('submit-btn-label');
if (!selectDish || !appState.members) return;
const memberOptions = '<option value="">انتخاب همسفر...</option>' + appState.members.map(function(m) {
return '<option value="' + m.id + '">' + m.avatar + ' ' + m.name + '</option>';
}).join('');
selectDish.innerHTML = memberOptions;
selectCook.innerHTML = memberOptions;
selectHelp.innerHTML = memberOptions;
selectLazy.innerHTML = memberOptions;
// Peers for active user
const peers = appState.members.filter(function(m) { return m.id !== currentUser; });
ratingsCont.innerHTML = peers.map(function(p) {
return '<div class="bg-dark-bg/80 border border-dark-border p-3 rounded-xl space-y-2">' +
'<div class="flex items-center justify-between">' +
'<div class="flex items-center gap-2">' +
'<span class="text-2xl">' + p.avatar + '</span>' +
'<strong class="text-xs sm:text-sm font-bold text-white">' + p.name + '</strong>' +
'</div>' +
'<div class="flex items-center gap-1.5 bg-dark-card px-2.5 py-1 rounded-lg border border-dark-border">' +
'<span class="text-[10px] text-slate-400">امتیاز:</span>' +
'<select id="rate-' + p.id + '" class="bg-transparent text-amber-300 font-bold text-xs focus:outline-none">' +
'<option value="5">⭐⭐⭐⭐⭐ (۵ ستاره - عالی)</option>' +
'<option value="4">⭐⭐⭐⭐ (۴ ستاره - خیلی خوب)</option>' +
'<option value="3" selected>⭐⭐⭐ (۳ ستاره - خوب)</option>' +
'<option value="2">⭐⭐ (۲ ستاره - متوسط)</option>' +
'<option value="1">⭐ (۱ ستاره - ضعیف)</option>' +
'</select>' +
'</div>' +
'</div>' +
'<div>' +
'<textarea id="comment-' + p.id + '" rows="2" placeholder="کامنت، خاطره یا بازخورد شما درباره ' + p.name + ' در این روز..." class="w-full bg-dark-card border border-dark-border text-xs rounded-xl p-2.5 text-white placeholder:text-slate-500 focus:outline-none focus:border-emerald-500"></textarea>' +
'</div>' +
'</div>';
}).join('');
// Check if current user already voted for this day
const dayPoll = (appState.daily_surveys && appState.daily_surveys[currentPollDay]) ? appState.daily_surveys[currentPollDay] : { votes: [] };
const votes = dayPoll.votes || [];
const myExistingVote = votes.find(function(v) { return v.by_user === currentUser; });
if (myExistingVote) {
// Pre-fill form
selectDish.value = myExistingVote.dishwashing || '';
selectCook.value = myExistingVote.cooking || '';
selectHelp.value = myExistingVote.helper || '';
selectLazy.value = myExistingVote.lazy || '';
if (myExistingVote.ratings) {
Object.keys(myExistingVote.ratings).forEach(function(pid) {
var rel = document.getElementById('rate-' + pid);
if (rel) rel.value = myExistingVote.ratings[pid];
});
}
if (myExistingVote.comments) {
myExistingVote.comments.forEach(function(c) {
peers.forEach(function(p) {
if (c.indexOf('برای ' + p.name + ':') !== -1) {
var cel = document.getElementById('comment-' + p.id);
if (cel) cel.value = c.replace('برای ' + p.name + ':', '').trim();
}
});
});
}
if (bannerEl) bannerEl.classList.remove('hidden');
if (deleteBtn) deleteBtn.classList.remove('hidden');
if (submitLabel) submitLabel.textContent = 'بروزرسانی و ویرایش نظر من';
} else {
if (bannerEl) bannerEl.classList.add('hidden');
if (deleteBtn) deleteBtn.classList.add('hidden');
if (submitLabel) submitLabel.textContent = 'ثبت و ذخیره قطعی نظرسنجی';
}
// Reviews Feed Wall Rendering with Ownership Actions
const countBadge = document.getElementById('reviews-count-badge');
if (countBadge) countBadge.textContent = votes.length + ' نظر ثبت‌شده';
if (votes.length === 0) {
feedCont.innerHTML = '<div class="text-xs text-slate-400 p-4 text-center bg-dark-bg/60 rounded-xl border border-dark-border">هنوز نظری برای این شب ثبت نشده است. اولین نفری باشید که نظرسنجی را پر می‌کند!</div>';
} else {
feedCont.innerHTML = votes.map(function(v) {
var voter = appState.members.find(function(m) { return m.id === v.by_user; }) || { name: v.by_user, avatar: '👤' };
var dishMember = appState.members.find(function(m) { return m.id === v.dishwashing; });
var cookMember = appState.members.find(function(m) { return m.id === v.cooking; });
var helpMember = appState.members.find(function(m) { return m.id === v.helper; });
var lazyMember = appState.members.find(function(m) { return m.id === v.lazy; });
var isMyReview = (v.by_user === currentUser);
var badges = [];
if (dishMember) badges.push('<span class="bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 px-2 py-0.5 rounded text-[10px]">🧼 ظرفشویی: ' + dishMember.name + '</span>');
if (cookMember) badges.push('<span class="bg-amber-500/10 text-amber-400 border border-amber-500/20 px-2 py-0.5 rounded text-[10px]">👨‍🍳 آشپزی: ' + cookMember.name + '</span>');
if (helpMember) badges.push('<span class="bg-teal-500/10 text-teal-400 border border-teal-500/20 px-2 py-0.5 rounded text-[10px]">🤝 همراهی: ' + helpMember.name + '</span>');
if (lazyMember) badges.push('<span class="bg-rose-500/10 text-rose-400 border border-rose-500/20 px-2 py-0.5 rounded text-[10px]">🛋️ تنبلی: ' + lazyMember.name + '</span>');
var commentsList = (v.comments && v.comments.length) ? ('<div class="space-y-1.5 pt-2 border-t border-dark-border/60">' + v.comments.map(function(c) {
return '<div class="bg-dark-card/90 p-2 rounded-lg text-xs text-slate-200 leading-relaxed border border-dark-border flex items-start gap-1.5"><i class="ph-bold ph-chat text-emerald-400 mt-0.5 shrink-0"></i><span>' + c + '</span></div>';
}).join('') + '</div>') : '';
var ownershipActions = isMyReview
? '<div class="flex items-center gap-1.5">' +
'<span class="text-[9px] bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 px-1.5 py-0.5 rounded font-bold">نظر شما</span>' +
'<button onclick="deleteMyVote(\'' + currentPollDay + '\', \'' + v.by_user + '\')" class="text-slate-400 hover:text-rose-400 p-1 transition" title="حذف این نظر"><i class="ph-bold ph-trash text-sm"></i></button>' +
'</div>'
: '<div class="flex items-center gap-1 text-[10px] text-slate-500"><i class="ph-bold ph-lock-simple"></i><span>ثبت‌شده توسط ' + voter.name + '</span></div>';
return '<div class="bg-dark-bg/90 border ' + (isMyReview ? 'border-emerald-500/50 shadow-md shadow-emerald-950/30' : 'border-dark-border') + ' p-3.5 rounded-xl space-y-2.5">' +
'<div class="flex items-center justify-between">' +
'<div class="flex items-center gap-2">' +
'<span class="text-2xl">' + voter.avatar + '</span>' +
'<div>' +
'<strong class="text-xs sm:text-sm font-bold text-white block">' + voter.name + '</strong>' +
'<span class="text-[10px] text-slate-500 font-mono">' + (v.time || 'امشب') + '</span>' +
'</div>' +
'</div>' +
ownershipActions +
'</div>' +
'<div class="flex items-center gap-1.5 flex-wrap">' + badges.join('') + '</div>' +
commentsList +
'</div>';
}).join('');
}
}
function changePollDay(dayKey) {
currentPollDay = dayKey;
renderPollForm();
}
function scrollToNightlyPoll() {
switchTab('roster');
document.getElementById('nightly-poll-section').scrollIntoView({ behavior: 'smooth' });
}
// Submit Poll with 100% Reliable Persistence & Ownership
async function submitNightlyPoll() {
const dish = document.getElementById('vote-dishwashing').value;
const cook = document.getElementById('vote-cooking').value;
const help = document.getElementById('vote-helper').value;
const lazy = document.getElementById('vote-lazy').value;
const ratings = {};
const comments = [];
const peers = appState.members.filter(function(m) { return m.id !== currentUser; });
peers.forEach(function(p) {
const rateEl = document.getElementById('rate-' + p.id);
const commEl = document.getElementById('comment-' + p.id);
if (rateEl) ratings[p.id] = rateEl.value;
if (commEl && commEl.value.trim()) {
comments.push('برای ' + p.name + ': ' + commEl.value.trim());
}
});
if (!appState.daily_surveys) appState.daily_surveys = {};
if (!appState.daily_surveys[currentPollDay]) {
appState.daily_surveys[currentPollDay] = { title: currentPollDay, is_active: true, votes: [] };
}
if (!appState.daily_surveys[currentPollDay].votes) {
appState.daily_surveys[currentPollDay].votes = [];
}
const voteObj = {
by_user: currentUser,
time: new Date().toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }),
dishwashing: dish,
cooking: cook,
helper: help,
lazy: lazy,
ratings: ratings,
comments: comments
};
// Replace previous vote from this user for this day
appState.daily_surveys[currentPollDay].votes = appState.daily_surveys[currentPollDay].votes.filter(function(v) {
return v.by_user !== currentUser;
});
appState.daily_surveys[currentPollDay].votes.push(voteObj);
renderLeaderboard();
renderPollForm();
await saveState('ثبت / ویرایش نظرسنجی');
showToast('نظر و امتیازات شما با موفقیت ثبت و ذخیره شد! 🌟');
}
// Delete Own Vote
async function deleteMyVote(dayKey, userId) {
if (userId !== currentUser) {
showToast('خطا: شما فقط مجاز به حذف نظرات پروفایل خود هستید.', true);
return;
}
if (!confirm('آیا از حذف کامل نظر و امتیازهای خود برای این شب اطمینان دارید؟')) return;
if (appState.daily_surveys && appState.daily_surveys[dayKey] && appState.daily_surveys[dayKey].votes) {
appState.daily_surveys[dayKey].votes = appState.daily_surveys[dayKey].votes.filter(function(v) {
return v.by_user !== userId;
});
renderLeaderboard();
renderPollForm();
await saveState('حذف نظر شخصی');
showToast('نظر شما با موفقیت حذف شد و امتیازها بازنشانی شدند.');
}
}
// ==============================================================
// SHOPPING LIST (ویرایش مستقیم قیمت‌ها)
// ==============================================================
function renderShoppingList() {
const container = document.getElementById('shopping-printable-area');
if (!container || !appState.shopping_categories) return;
var totalCost = 0;
var totalItems = 0;
var boughtItems = 0;
container.innerHTML = appState.shopping_categories.map(function(cat) {
var catCost = cat.items.reduce(function(s, i) { return s + (parseInt(i.unit_price) || 0) * (i.qty || 1); }, 0);
totalCost += catCost;
totalItems += cat.items.length;
boughtItems += cat.items.filter(function(i) { return i.bought; }).length;
var itemsHtml = cat.items.map(function(item) {
return '<div class="bg-dark-bg/80 border border-dark-border/80 rounded-xl p-2.5 flex flex-col sm:flex-row sm:items-center justify-between gap-2.5 hover:border-slate-600 transition">' +
'<div class="flex items-center gap-2.5 flex-1 min-w-0">' +
'<input type="checkbox" ' + (item.bought ? 'checked' : '') + ' onchange="toggleItemBought(\'' + cat.id + '\', \'' + item.id + '\')" class="w-4 h-4 rounded text-emerald-500 focus:ring-emerald-400 bg-dark-card border-dark-border shrink-0 cursor-pointer" />' +
'<div class="min-w-0">' +
'<span class="text-xs font-bold text-white block truncate ' + (item.bought ? 'line-through text-slate-500' : '') + '">' + item.name + '</span>' +
'<div class="flex items-center gap-2 text-[10px] text-slate-400">' +
'<span>پرداخت‌کننده: <strong class="text-slate-200">' + (item.payer || 'صندوق مشترک') + '</strong></span>' +
(item.notes ? ('<span>• ' + item.notes + '</span>') : '') +
'</div>' +
'</div>' +
'</div>' +
'<div class="flex items-center justify-between sm:justify-end gap-2 shrink-0 pt-1.5 sm:pt-0 border-t sm:border-t-0 border-dark-border/40">' +
'<div class="flex items-center gap-1.5">' +
'<span class="text-[10px] text-slate-400">قیمت (تومان):</span>' +
'<input type="number" value="' + item.unit_price + '" onchange="changeItemPrice(\'' + cat.id + '\', \'' + item.id + '\', this.value)" class="w-24 bg-dark-card border border-dark-border text-xs text-emerald-400 font-mono font-bold rounded-lg px-2 py-1 text-center focus:outline-none focus:border-emerald-500" />' +
'</div>' +
'<button onclick="deleteItem(\'' + cat.id + '\', \'' + item.id + '\')" class="text-slate-500 hover:text-rose-400 p-1 no-print" title="حذف آیتم"><i class="ph-bold ph-trash text-sm"></i></button>' +
'</div>' +
'</div>';
}).join('');
return '<div class="glass-card rounded-2xl p-4 border border-dark-border space-y-3">' +
'<div class="flex items-center justify-between pb-2 border-b border-dark-border">' +
'<h3 class="text-xs sm:text-sm font-black text-white">' + cat.title + '</h3>' +
'<span class="text-xs font-mono font-bold text-emerald-400">' + catCost.toLocaleString('fa-IR') + ' تومان</span>' +
'</div>' +
'<div class="space-y-2">' + itemsHtml + '</div>' +
'</div>';
}).join('');
document.getElementById('shop-total-cost').textContent = totalCost.toLocaleString('fa-IR') + ' تومان';
document.getElementById('shop-per-person-7').textContent = Math.round(totalCost / 7).toLocaleString('fa-IR') + ' تومان';
document.getElementById('shop-bought-count').textContent = boughtItems + ' از ' + totalItems;
}
function changeItemPrice(catId, itemId, newPrice) {
const cat = appState.shopping_categories.find(function(c) { return c.id === catId; });
if (!cat) return;
const item = cat.items.find(function(i) { return i.id === itemId; });
if (!item) return;
item.unit_price = parseInt(newPrice) || 0;
renderShoppingList();
saveState('ویرایش قیمت آیتم');
}
function toggleItemBought(catId, itemId) {
const cat = appState.shopping_categories.find(function(c) { return c.id === catId; });
if (!cat) return;
const item = cat.items.find(function(i) { return i.id === itemId; });
if (!item) return;
item.bought = !item.bought;
renderShoppingList();
saveState('تغییر وضعیت خرید');
}
function deleteItem(catId, itemId) {
const cat = appState.shopping_categories.find(function(c) { return c.id === catId; });
if (!cat) return;
cat.items = cat.items.filter(function(i) { return i.id !== itemId; });
renderShoppingList();
saveState('حذف آیتم خرید');
}
function openAddItemModal() {
document.getElementById('modal-add-item').classList.remove('hidden');
}
function closeAddItemModal() {
document.getElementById('modal-add-item').classList.add('hidden');
}
function handleSaveItem(e) {
e.preventDefault();
const catId = document.getElementById('item-cat-select').value;
const name = document.getElementById('item-name-input').value.trim();
const price = parseInt(document.getElementById('item-price-input').value) || 0;
const payer = document.getElementById('item-payer-input').value.trim() || 'صندوق مشترک';
const notes = document.getElementById('item-notes-input').value.trim();
const cat = appState.shopping_categories.find(function(c) { return c.id === catId; });
if (cat) {
cat.items.push({
id: 'custom-' + Date.now(),
name: name,
unit_price: price,
qty: 1,
payer: payer,
bought: false,
notes: notes
});
closeAddItemModal();
document.getElementById('form-add-item').reset();
renderShoppingList();
saveState('افزودن آیتم جدید به لیست خرید');
}
}
function exportShoppingPDF() {
const element = document.getElementById('shopping-printable-area');
const opt = {
margin: [10, 10, 10, 10],
filename: 'لیست-خرید-سفر-شمال-۱۴۰۵.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
showToast('در حال ایجاد فایل PDF لیست خرید...');
html2pdf().set(opt).from(element).save().then(function() {
showToast('فایل PDF دانلود شد.');
});
}
function copyShoppingListText() {
var lines = ['🛒 لیست خرید خوراکی و اقلام سفر شمال ۱۴۰۵ (دیجی‌کالا جت):', ''];
appState.shopping_categories.forEach(function(c) {
lines.push('🔹 ' + c.title + ':');
c.items.forEach(function(i) {
lines.push('• ' + i.name + ' - ' + (parseInt(i.unit_price) || 0).toLocaleString('fa-IR') + ' ت (' + (i.payer || 'مشترک') + ')');
});
lines.push('');
});
var txt = lines.join('\n');
navigator.clipboard.writeText(txt).then(function() {
showToast('لیست خرید در کلیپ‌بورد کپی شد.');
});
}
// ==============================================================
// ACTIVITIES & ZARFILM MOVIES
// ==============================================================
function renderActivitiesAndMovies() {
const mCont = document.getElementById('movies-container');
if (mCont && appState.movies) {
mCont.innerHTML = appState.movies.map(function(m) {
return '<div class="bg-dark-bg/90 border border-dark-border rounded-xl p-3.5 space-y-2 flex flex-col justify-between hover:border-amber-500/50 transition">' +
'<div class="space-y-1.5">' +
'<div class="flex items-center justify-between">' +
'<span class="text-[10px] bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded font-bold">' + m.badge + '</span>' +
'<span class="text-xs font-mono font-bold text-amber-400 flex items-center gap-1">⭐ ' + m.imdb + '</span>' +
'</div>' +
'<strong class="text-xs sm:text-sm font-bold text-white block">' + m.title_fa + '</strong>' +
'<span class="text-[10px] text-slate-400 block font-mono">' + m.title_en + ' • ' + m.duration + ' • ' + m.genre + '</span>' +
'<p class="text-[11px] text-slate-300 leading-relaxed">' + m.desc + '</p>' +
'</div>' +
'<a href="' + m.zarfilm_url + '" target="_blank" rel="noopener noreferrer" class="self-start inline-flex items-center gap-1 text-[11px] font-bold text-amber-400 hover:text-amber-300 pt-1">' +
'<span>مشاهده در زرفیلم</span>' +
'<i class="ph-bold ph-arrow-square-out"></i>' +
'</a>' +
'</div>';
}).join('');
}
const outCont = document.getElementById('outdoor-activities-list');
if (outCont && appState.activities_list && appState.activities_list.outdoor) {
outCont.innerHTML = appState.activities_list.outdoor.map(function(a) {
return '<div class="bg-dark-bg/80 border border-dark-border rounded-xl p-3 space-y-1">' +
'<div class="flex items-center justify-between">' +
'<strong class="text-xs font-bold text-white flex items-center gap-1.5">' +
'<i class="ph-bold ' + (a.icon || 'ph-compass') + ' text-emerald-400"></i> ' + a.title +
'</strong>' +
'<span class="text-[10px] text-emerald-400 font-bold">' + a.tag + '</span>' +
'</div>' +
'<p class="text-[11px] text-slate-400 leading-relaxed">' + a.desc + '</p>' +
'<div class="flex items-center justify-between text-[10px] text-slate-400 pt-1 border-t border-dark-border/40">' +
'<span>موقعیت: ' + a.loc + '</span>' +
'<span class="text-amber-300">' + a.cost + '</span>' +
'</div>' +
'</div>';
}).join('');
}
const inCont = document.getElementById('indoor-activities-list');
if (inCont && appState.activities_list && appState.activities_list.indoor) {
inCont.innerHTML = appState.activities_list.indoor.map(function(a) {
return '<div class="bg-dark-bg/80 border border-dark-border rounded-xl p-3 space-y-1">' +
'<div class="flex items-center justify-between">' +
'<strong class="text-xs font-bold text-white flex items-center gap-1.5">' +
'<i class="ph-bold ' + (a.icon || 'ph-cards') + ' text-amber-400"></i> ' + a.title +
'</strong>' +
'<span class="text-[10px] text-amber-400 font-bold">' + a.tag + '</span>' +
'</div>' +
'<p class="text-[11px] text-slate-400 leading-relaxed">' + a.desc + '</p>' +
'<div class="text-[10px] text-slate-400 pt-1 border-t border-dark-border/40">' +
'<span>لوکیشن: ' + a.loc + '</span>' +
'</div>' +
'</div>';
}).join('');
}
}
// Countdown Timers
function setupCountdowns() {
var targetG1 = new Date('2026-09-29T21:00:00+03:30').getTime();
var targetG2 = new Date('2026-09-30T19:00:00+03:30').getTime();
function updateTimer() {
var now = new Date().getTime();
var diff1 = targetG1 - now;
if (diff1 > 0) {
var d1 = Math.floor(diff1 / (1000 * 60 * 60 * 24));
var h1 = Math.floor((diff1 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var m1 = Math.floor((diff1 % (1000 * 60 * 60)) / (1000 * 60));
var s1 = Math.floor((diff1 % (1000 * 60)) / 1000);
var cdEl = document.getElementById('cd-compact');
if (cdEl) cdEl.textContent = d1 + ' روز و ' + h1 + ' ساعت';
var cd1d = document.getElementById('cd1-days');
if (cd1d) cd1d.textContent = d1;
var cd1h = document.getElementById('cd1-hours');
if (cd1h) cd1h.textContent = h1;
var cd1m = document.getElementById('cd1-mins');
if (cd1m) cd1m.textContent = m1;
var cd1s = document.getElementById('cd1-secs');
if (cd1s) cd1s.textContent = s1;
}
var diff2 = targetG2 - now;
if (diff2 > 0) {
var d2 = Math.floor(diff2 / (1000 * 60 * 60 * 24));
var h2 = Math.floor((diff2 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var m2 = Math.floor((diff2 % (1000 * 60 * 60)) / (1000 * 60));
var s2 = Math.floor((diff2 % (1000 * 60)) / 1000);
var cd2d = document.getElementById('cd2-days');
if (cd2d) cd2d.textContent = d2;
var cd2h = document.getElementById('cd2-hours');
if (cd2h) cd2h.textContent = h2;
var cd2m = document.getElementById('cd2-mins');
if (cd2m) cd2m.textContent = m2;
var cd2s = document.getElementById('cd2-secs');
if (cd2s) cd2s.textContent = s2;
}
}
updateTimer();
setInterval(updateTimer, 1000);
}
function toggleHeroDetails() {
var drawer = document.getElementById('hero-detailed-drawer');
var icon = document.getElementById('hero-toggle-icon');
var label = document.getElementById('hero-toggle-label');
if (drawer.classList.contains('hidden')) {
drawer.classList.remove('hidden');
icon.classList.add('rotate-180');
label.textContent = 'بستن جزئیات';
} else {
drawer.classList.add('hidden');
icon.classList.remove('rotate-180');
label.textContent = 'جزئیات زمان‌بندی و هوا';
}
}
function copyTripBrief() {
var lines = [
'🏕️ اکسپدیشن شمال و رشت ۱۴۰۵ (۷ تا ۱۲ مهر)',
'📍 اقامت: چمستان امیرآباد (ویلای آریا) & گشت رشت',
'👥 همسفران (۷ نفر):',
'- گروه ۱ (حرکت ۳شنبه ۷ مهر): محدثه، محمدرضا، آریا، سینا',
'- گروه ۲ (حرکت ۴شنبه ۸ مهر بعد کار): امیرحسین، آوا، محمد',
'- بازگشت آوا و محمد: شنبه ۱۱ مهر | بازگشت کل جمع: ۱شنبه ۱۲ مهر',
'🔗 لینک داشبورد تعاملی:',
'https://ops.zebellkhan.com/shomal.html'
];
var txt = lines.join('\n');
navigator.clipboard.writeText(txt).then(function() {
showToast('خلاصه برنامه سفر کپی شد.');
});
}
function showToast(text, isError) {
var toast = document.getElementById('toast');
var body = document.getElementById('toast-body');
var textEl = document.getElementById('toast-text');
if (!toast || !body || !textEl) return;
textEl.textContent = text;
if (isError) {
body.className = 'bg-rose-500 text-white text-xs font-bold px-4 py-2.5 rounded-xl shadow-2xl flex items-center gap-2 border border-rose-400';
} else {
body.className = 'bg-emerald-500 text-black text-xs font-bold px-4 py-2.5 rounded-xl shadow-2xl flex items-center gap-2 border border-emerald-400/50';
}
toast.classList.remove('opacity-0', 'translate-y-3');
toast.classList.add('opacity-100', 'translate-y-0');
setTimeout(function() {
toast.classList.remove('opacity-100', 'translate-y-0');
toast.classList.add('opacity-0', 'translate-y-3');
}, 3500);
}
window.addEventListener('DOMContentLoaded', initApp);
</script>
</body>
</html>