Spaces:
Running
Running
| <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="#1a0d07"> | |
| <title>Cafe AI — پنل مدیریت</title> | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | |
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | |
| <link href="https://fonts.googleapis.com/css2?family=Lalezar&family=Vazirmatn:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet"> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> | |
| <script> | |
| tailwind.config = { | |
| theme: { | |
| extend: { | |
| fontFamily: { | |
| sans: ['Vazirmatn', 'sans-serif'], | |
| display: ['Lalezar', 'serif'], | |
| }, | |
| colors: { | |
| bazaar: { 950: '#1a0d07', 900: '#2d1810', 800: '#3d2418', 700: '#5c3a2a', 600: '#7a4e3a', 500: '#9c6b4f', 400: '#b8856a', 300: '#d4a88c' }, | |
| azure: { 950: '#051a2e', 900: '#0a2540', 800: '#123a5e', 700: '#1e4976', 600: '#2d6ca8', 500: '#3d8bc4', 400: '#6ba7d4', 300: '#a3c8e4' }, | |
| turk: { DEFAULT: '#0d9488', light: '#2dd4bf', glow: '#5eead4', deep: '#134e4a' }, | |
| rug: { DEFAULT: '#8b1e3f', light: '#c23d5f', dark: '#5a1028', glow: '#e85d7e' }, | |
| ochre: { DEFAULT: '#c9a961', light: '#e4c97a', dark: '#9c7d3a', pale: '#f0dca3' }, | |
| ivory: '#faf3e7', cream: '#f5e6d3', saffron: '#d97706', | |
| emerald: { DEFAULT: '#10b981', light: '#34d399', dark: '#065f46' }, | |
| rose: { DEFAULT: '#e11d48', light: '#fb7185' }, | |
| }, | |
| boxShadow: { | |
| 'carpet': '0 10px 40px -10px rgba(139, 30, 63, 0.35), 0 0 0 1px rgba(201, 169, 97, 0.15)', | |
| 'mosque': '0 10px 40px -10px rgba(13, 148, 136, 0.4), 0 0 0 1px rgba(45, 212, 191, 0.2)', | |
| 'bazaar-glow': '0 0 60px rgba(201, 169, 97, 0.25), inset 0 1px 0 rgba(244, 228, 163, 0.1)', | |
| 'inner-soft': 'inset 0 2px 8px rgba(0,0,0,0.35)', | |
| 'inner-gold': 'inset 0 0 20px rgba(201, 169, 97, 0.15)', | |
| }, | |
| animation: { | |
| 'float': 'float 6s ease-in-out infinite', | |
| 'shimmer': 'shimmer 3s ease-in-out infinite', | |
| 'pulse-glow': 'pulseGlow 2.5s ease-in-out infinite', | |
| }, | |
| keyframes: { | |
| float: { '0%, 100%': { transform: 'translateY(0px)' }, '50%': { transform: 'translateY(-12px)' } }, | |
| shimmer: { '0%, 100%': { opacity: '0.7' }, '50%': { opacity: '1' } }, | |
| pulseGlow: { '0%, 100%': { boxShadow: '0 0 20px rgba(201, 169, 97, 0.3)' }, '50%': { boxShadow: '0 0 40px rgba(201, 169, 97, 0.6)' } }, | |
| }, | |
| } | |
| } | |
| } | |
| </script> | |
| <style> | |
| :root { | |
| --pattern-url: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23c9a961' stroke-width='0.6' opacity='0.08'%3E%3Cpath d='M40 10 L50 20 L60 10 L70 20 L60 30 L70 40 L60 50 L70 60 L60 70 L50 60 L40 70 L30 60 L20 70 L10 60 L20 50 L10 40 L20 30 L10 20 L20 10 L30 20 Z'/%3E%3Ccircle cx='40' cy='40' r='12'/%3E%3Ccircle cx='40' cy='40' r='6'/%3E%3Cpath d='M40 28 L40 52 M28 40 L52 40'/%3E%3C/g%3E%3C/svg%3E"); | |
| --vh: 1vh; | |
| } | |
| * { box-sizing: border-box; } | |
| html, body { | |
| height: 100%; | |
| overflow: hidden; | |
| overscroll-behavior: none; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| @supports (height: 100dvh) { | |
| html, body { height: 100dvh; } | |
| } | |
| body { | |
| background-color: #1a0d07; | |
| color: #f5e6d3; | |
| -webkit-tap-highlight-color: transparent; | |
| font-feature-settings: "ss01", "cv01"; | |
| margin: 0; | |
| padding: 0; | |
| overflow: hidden; | |
| } | |
| .bg-pattern { background-image: var(--pattern-url); background-size: 80px 80px; } | |
| .bg-pattern-fine { | |
| background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23c9a961' stroke-width='0.4' opacity='0.1'%3E%3Cpath d='M20 0 L20 40 M0 20 L40 20'/%3E%3Ccircle cx='20' cy='20' r='3'/%3E%3Ccircle cx='0' cy='0' r='2'/%3E%3Ccircle cx='40' cy='0' r='2'/%3E%3Ccircle cx='0' cy='40' r='2'/%3E%3Ccircle cx='40' cy='40' r='2'/%3E%3C/g%3E%3C/svg%3E"); | |
| } | |
| .bg-arch { | |
| background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cg fill='none' stroke='%230d9488' stroke-width='0.5' opacity='0.06'%3E%3Cpath d='M100 20 Q 40 40, 40 100 Q 40 180, 100 180 Q 160 180, 160 100 Q 160 40, 100 20 Z'/%3E%3Cpath d='M100 50 Q 65 65, 65 100 Q 65 155, 100 155 Q 135 155, 135 100 Q 135 65, 100 50 Z'/%3E%3Cpath d='M100 80 Q 85 90, 85 100 Q 85 130, 100 130 Q 115 130, 115 100 Q 115 90, 100 80 Z'/%3E%3C/g%3E%3C/svg%3E"); | |
| background-size: 200px 200px; | |
| } | |
| ::-webkit-scrollbar { width: 6px; height: 6px; } | |
| ::-webkit-scrollbar-track { background: transparent; } | |
| ::-webkit-scrollbar-thumb { | |
| background: linear-gradient(180deg, #c9a961, #8b1e3f); | |
| border-radius: 4px; | |
| } | |
| ::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #e4c97a, #c23d5f); } | |
| .glass-card { | |
| background: linear-gradient(135deg, rgba(45, 24, 16, 0.82) 0%, rgba(26, 13, 7, 0.78) 100%); | |
| backdrop-filter: blur(20px); | |
| -webkit-backdrop-filter: blur(20px); | |
| border: 1px solid rgba(201, 169, 97, 0.18); | |
| box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(244, 228, 163, 0.08); | |
| transition: all 0.4s ease; | |
| } | |
| .glass-card:hover { border-color: rgba(201, 169, 97, 0.3); } | |
| .glass-card-azure { | |
| background: linear-gradient(135deg, rgba(10, 37, 64, 0.78) 0%, rgba(5, 26, 46, 0.82) 100%); | |
| backdrop-filter: blur(20px); | |
| -webkit-backdrop-filter: blur(20px); | |
| border: 1px solid rgba(45, 212, 191, 0.2); | |
| box-shadow: 0 20px 50px -20px rgba(13, 148, 136, 0.2), inset 0 1px 0 rgba(94, 234, 212, 0.1); | |
| } | |
| .arch-shape { border-radius: 50% 50% 1rem 1rem / 35% 35% 1rem 1rem; } | |
| .chat-markdown { line-height: 1.85; word-wrap: break-word; overflow-wrap: break-word; } | |
| .chat-markdown > * + * { margin-top: 0.6em; } | |
| .chat-markdown h1, .chat-markdown h2, .chat-markdown h3, | |
| .chat-markdown h4, .chat-markdown h5, .chat-markdown h6 { | |
| font-family: 'Lalezar', serif; color: #e4c97a; | |
| margin-top: 1em; margin-bottom: 0.4em; line-height: 1.3; | |
| } | |
| .chat-markdown h1 { font-size: 1.4em; } | |
| .chat-markdown h2 { font-size: 1.25em; } | |
| .chat-markdown h3 { font-size: 1.15em; color: #5eead4; } | |
| .chat-markdown h4, .chat-markdown h5, .chat-markdown h6 { font-size: 1.05em; } | |
| .chat-markdown p { margin-bottom: 0.5em; } | |
| .chat-markdown ul, .chat-markdown ol { padding-right: 1.4em; margin: 0.4em 0; } | |
| .chat-markdown ul { list-style-type: '❋ '; } | |
| .chat-markdown ol { list-style-type: persian; } | |
| .chat-markdown li { margin-bottom: 0.3em; padding-right: 0.2em; } | |
| .chat-markdown li::marker { color: #c9a961; } | |
| .chat-markdown strong { color: #f0dca3; font-weight: 700; text-shadow: 0 0 8px rgba(201, 169, 97, 0.3); } | |
| .chat-markdown em { color: #5eead4; font-style: italic; } | |
| .chat-markdown a { color: #2dd4bf; text-decoration: underline; text-underline-offset: 3px; } | |
| .chat-markdown code { | |
| background: rgba(13, 148, 136, 0.18); color: #5eead4; | |
| padding: 0.15em 0.4em; border-radius: 5px; font-size: 0.88em; | |
| border: 1px solid rgba(45, 212, 191, 0.2); | |
| font-family: 'Courier New', monospace; | |
| direction: ltr; display: inline-block; | |
| } | |
| .chat-markdown pre { | |
| background: rgba(5, 26, 46, 0.7); | |
| border: 1px solid rgba(45, 212, 191, 0.25); | |
| border-right: 3px solid #0d9488; | |
| padding: 0.9em 1em; border-radius: 8px; | |
| overflow-x: auto; margin: 0.6em 0; | |
| direction: ltr; text-align: left; | |
| } | |
| .chat-markdown pre code { background: transparent; border: none; padding: 0; color: #a3c8e4; font-size: 0.85em; } | |
| .chat-markdown blockquote { | |
| border-right: 3px solid #c9a961; | |
| background: linear-gradient(90deg, rgba(201, 169, 97, 0.08), transparent); | |
| padding: 0.5em 1em; margin: 0.6em 0; | |
| color: #f0dca3; font-style: italic; | |
| border-radius: 0 8px 8px 0; | |
| } | |
| .chat-markdown blockquote p { margin: 0; } | |
| .chat-markdown hr { | |
| border: none; height: 1px; | |
| background: linear-gradient(90deg, transparent, rgba(201, 169, 97, 0.5), transparent); | |
| margin: 1em 0; | |
| } | |
| .chat-markdown table { | |
| width: 100%; border-collapse: collapse; margin: 0.6em 0; | |
| font-size: 0.92em; background: rgba(45, 24, 16, 0.5); | |
| border-radius: 8px; overflow: hidden; | |
| border: 1px solid rgba(201, 169, 97, 0.25); | |
| display: block; overflow-x: auto; | |
| } | |
| .chat-markdown thead { background: linear-gradient(90deg, rgba(139, 30, 63, 0.4), rgba(201, 169, 97, 0.2)); } | |
| .chat-markdown th { | |
| padding: 0.55em 0.8em; text-align: right; | |
| color: #e4c97a; font-weight: 700; | |
| border-bottom: 1px solid rgba(201, 169, 97, 0.3); | |
| font-family: 'Lalezar', serif; | |
| } | |
| .chat-markdown td { padding: 0.5em 0.8em; border-bottom: 1px solid rgba(201, 169, 97, 0.1); } | |
| .chat-markdown tr:last-child td { border-bottom: none; } | |
| .chat-markdown img { max-width: 100%; border-radius: 10px; border: 2px solid rgba(201, 169, 97, 0.3); } | |
| .typing-dots span { | |
| display: inline-block; width: 6px; height: 6px; | |
| border-radius: 50%; background: #c9a961; | |
| animation: typing 1.4s infinite; | |
| } | |
| .typing-dots span:nth-child(2) { animation-delay: 0.2s; } | |
| .typing-dots span:nth-child(3) { animation-delay: 0.4s; } | |
| @keyframes typing { | |
| 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } | |
| 30% { transform: translateY(-8px); opacity: 1; } | |
| } | |
| .btn-primary { | |
| background: linear-gradient(135deg, #c9a961 0%, #9c7d3a 100%); | |
| color: #1a0d07; font-weight: 800; | |
| transition: all 0.3s ease; | |
| box-shadow: 0 8px 20px -5px rgba(201, 169, 97, 0.4); | |
| } | |
| .btn-primary:hover { | |
| background: linear-gradient(135deg, #e4c97a 0%, #c9a961 100%); | |
| transform: translateY(-2px); | |
| box-shadow: 0 12px 28px -5px rgba(201, 169, 97, 0.6); | |
| } | |
| .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; } | |
| .btn-ghost { | |
| background: rgba(201, 169, 97, 0.08); | |
| color: #f0dca3; | |
| border: 1px solid rgba(201, 169, 97, 0.2); | |
| transition: all 0.3s ease; | |
| } | |
| .btn-ghost:hover { | |
| background: rgba(201, 169, 97, 0.18); | |
| border-color: rgba(201, 169, 97, 0.45); | |
| } | |
| .btn-turk { | |
| background: linear-gradient(135deg, #0d9488 0%, #134e4a 100%); | |
| color: #f5e6d3; | |
| border: 1px solid rgba(45, 212, 191, 0.3); | |
| transition: all 0.3s ease; | |
| box-shadow: 0 6px 16px -4px rgba(13, 148, 136, 0.4); | |
| } | |
| .btn-turk:hover { | |
| background: linear-gradient(135deg, #2dd4bf 0%, #0d9488 100%); | |
| border-color: rgba(94, 234, 212, 0.6); | |
| transform: translateY(-1px); | |
| } | |
| .drop-zone { | |
| position: relative; | |
| border: 2px dashed rgba(201, 169, 97, 0.3); | |
| transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| .drop-zone:hover, .drop-zone.drag-over { | |
| border-color: rgba(201, 169, 97, 0.7); | |
| background: rgba(201, 169, 97, 0.06); | |
| } | |
| .drop-zone::before { | |
| content: ''; | |
| position: absolute; | |
| inset: 6px; | |
| border: 1px dashed rgba(201, 169, 97, 0.15); | |
| border-radius: inherit; | |
| pointer-events: none; | |
| } | |
| /* کارت سفارش - با افکت ویژه برای سفارشات چندگانه */ | |
| .order-card { | |
| background: linear-gradient(135deg, rgba(45, 24, 16, 0.6), rgba(26, 13, 7, 0.5)); | |
| border: 1px solid rgba(201, 169, 97, 0.2); | |
| transition: all 0.3s ease; | |
| } | |
| .order-card:hover { | |
| border-color: rgba(201, 169, 97, 0.5); | |
| box-shadow: 0 12px 30px -10px rgba(139, 30, 63, 0.3); | |
| transform: translateY(-2px); | |
| } | |
| .order-card.multi-order { | |
| border: 1px solid rgba(194, 61, 95, 0.5); | |
| background: linear-gradient(135deg, rgba(90, 16, 40, 0.25), rgba(26, 13, 7, 0.5)); | |
| } | |
| .order-card.multi-order::before { | |
| content: ''; | |
| position: absolute; | |
| top: -1px; left: -1px; right: -1px; bottom: -1px; | |
| border-radius: inherit; | |
| background: linear-gradient(135deg, rgba(201, 169, 97, 0.3), transparent); | |
| z-index: -1; | |
| pointer-events: none; | |
| } | |
| /* Badge برای تعداد سفارشها */ | |
| .orders-count-badge { | |
| background: linear-gradient(135deg, #8b1e3f, #5a1028); | |
| color: #f5e6d3; | |
| border: 1px solid rgba(201, 169, 97, 0.5); | |
| font-family: 'Lalezar', serif; | |
| animation: pulseGlow 2s ease-in-out infinite; | |
| } | |
| .menu-row { transition: all 0.3s ease; } | |
| .menu-row:hover { background: rgba(201, 169, 97, 0.05); } | |
| input:focus, textarea:focus, select:focus { | |
| outline: none; | |
| border-color: rgba(201, 169, 97, 0.6) ; | |
| box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15); | |
| } | |
| input[type="checkbox"] { | |
| appearance: none; width: 18px; height: 18px; | |
| border: 2px solid rgba(201, 169, 97, 0.4); | |
| border-radius: 4px; | |
| background: rgba(45, 24, 16, 0.5); | |
| cursor: pointer; position: relative; | |
| transition: all 0.2s ease; flex-shrink: 0; | |
| } | |
| input[type="checkbox"]:checked { | |
| background: linear-gradient(135deg, #0d9488, #134e4a); | |
| border-color: #2dd4bf; | |
| } | |
| input[type="checkbox"]:checked::after { | |
| content: '✓'; position: absolute; | |
| top: 50%; left: 50%; | |
| transform: translate(-50%, -50%); | |
| color: #f5e6d3; font-size: 14px; font-weight: bold; | |
| } | |
| .live-dot { | |
| display: inline-block; width: 8px; height: 8px; | |
| border-radius: 50%; background: #10b981; | |
| box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); | |
| animation: live-pulse 2s infinite; | |
| } | |
| @keyframes live-pulse { | |
| 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } | |
| } | |
| .section-title { font-family: 'Lalezar', serif; letter-spacing: 0.02em; } | |
| .badge-live { | |
| background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(6, 95, 70, 0.2)); | |
| border: 1px solid rgba(52, 211, 153, 0.4); | |
| color: #34d399; | |
| } | |
| .badge-table { | |
| background: linear-gradient(135deg, rgba(201, 169, 97, 0.15), rgba(139, 30, 63, 0.15)); | |
| border: 1px solid rgba(201, 169, 97, 0.4); | |
| color: #e4c97a; | |
| } | |
| .admin-table thead { background: linear-gradient(90deg, rgba(139, 30, 63, 0.25), rgba(201, 169, 97, 0.15)); } | |
| .admin-table th { font-family: 'Lalezar', serif; color: #e4c97a; font-size: 11px; } | |
| .admin-table td, .admin-table th { border-bottom: 1px solid rgba(201, 169, 97, 0.1); } | |
| .safe-bottom { padding-bottom: env(safe-area-inset-bottom); } | |
| .safe-top { padding-top: env(safe-area-inset-top); } | |
| .scroll-area { | |
| overflow-y: auto; | |
| overflow-x: hidden; | |
| overscroll-behavior: contain; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| button, .no-select { -webkit-user-select: none; user-select: none; } | |
| .app-wrapper { | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| height: 100dvh; | |
| overflow: hidden; | |
| } | |
| .chat-column { | |
| display: flex; | |
| flex-direction: column; | |
| min-height: 0; | |
| overflow: hidden; | |
| } | |
| .chat-messages-container { | |
| flex: 1; | |
| min-height: 0; | |
| overflow-y: auto; | |
| overflow-x: hidden; | |
| overscroll-behavior: contain; | |
| -webkit-overflow-scrolling: touch; | |
| } | |
| .chat-header-box, | |
| .chat-loader-box, | |
| .chat-input-box { | |
| flex-shrink: 0; | |
| } | |
| @media (min-width: 1024px) { | |
| .main-grid { | |
| overflow: hidden ; | |
| height: 100%; | |
| } | |
| .left-column { | |
| overflow-y: auto; | |
| min-height: 0; | |
| height: 100%; | |
| } | |
| .chat-column { | |
| height: 100%; | |
| max-height: 100%; | |
| } | |
| } | |
| @media (max-width: 1023px) { | |
| .main-grid { | |
| overflow-y: auto; | |
| overflow-x: hidden; | |
| } | |
| .chat-column { | |
| height: 65vh; | |
| height: calc(var(--vh, 1vh) * 65); | |
| min-height: 380px; | |
| max-height: 600px; | |
| flex-shrink: 0; | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| .chat-column { | |
| height: 60vh; | |
| height: calc(var(--vh, 1vh) * 60); | |
| min-height: 340px; | |
| max-height: 500px; | |
| } | |
| } | |
| @media (max-height: 500px) and (orientation: landscape) { | |
| .chat-column { | |
| height: 75vh ; | |
| min-height: 280px ; | |
| } | |
| } | |
| @media (min-width: 768px) and (max-width: 1023px) { | |
| .chat-column { | |
| height: 70vh; | |
| height: calc(var(--vh, 1vh) * 70); | |
| min-height: 420px; | |
| max-height: 650px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body class="font-sans selection:bg-ochre selection:text-bazaar-950 antialiased"> | |
| <!-- Ambient Background --> | |
| <div class="fixed inset-0 overflow-hidden pointer-events-none z-0"> | |
| <div class="absolute inset-0 bg-gradient-to-br from-bazaar-950 via-bazaar-900 to-azure-950"></div> | |
| <div class="absolute inset-0 bg-pattern opacity-40"></div> | |
| <div class="absolute -top-40 -right-40 w-[600px] h-[600px] rounded-full bg-rug/10 blur-[140px] animate-float"></div> | |
| <div class="absolute -bottom-40 -left-40 w-[600px] h-[600px] rounded-full bg-turk/10 blur-[140px] animate-float" style="animation-delay: -3s;"></div> | |
| <div class="absolute top-1/3 left-1/4 w-[400px] h-[400px] rounded-full bg-ochre/8 blur-[120px] animate-shimmer"></div> | |
| </div> | |
| <div class="app-wrapper relative z-10"> | |
| <!-- Header --> | |
| <header class="flex-shrink-0 border-b border-ochre/20 bg-bazaar-900/70 backdrop-blur-2xl z-20 px-3 md:px-6 lg:px-8 py-2.5 md:py-3 shadow-lg safe-top"> | |
| <div class="max-w-7xl mx-auto flex items-center justify-between gap-2 md:gap-4"> | |
| <div class="flex items-center gap-2 md:gap-3 min-w-0"> | |
| <div class="w-9 h-9 md:w-11 md:h-11 arch-shape bg-gradient-to-br from-rug via-rug-dark to-bazaar-900 border-2 border-ochre/50 flex items-center justify-center shadow-carpet flex-shrink-0"> | |
| <svg class="w-5 h-5 md:w-6 md:h-6 text-ochre-light" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"> | |
| <path d="M17 8h1a4 4 0 1 1 0 8h-1" stroke-linecap="round"/> | |
| <path d="M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z" stroke-linecap="round"/> | |
| <line x1="6" y1="2" x2="6" y2="4" stroke-linecap="round"/> | |
| <line x1="10" y1="2" x2="10" y2="4" stroke-linecap="round"/> | |
| <line x1="14" y1="2" x2="14" y2="4" stroke-linecap="round"/> | |
| </svg> | |
| </div> | |
| <div class="min-w-0"> | |
| <h1 class="section-title text-sm md:text-base lg:text-lg text-ochre-light tracking-wide flex items-center gap-1.5 md:gap-2 truncate"> | |
| <span class="text-rug-light flex-shrink-0">Cafe AI</span> | |
| <span class="text-cream/40 flex-shrink-0">|</span> | |
| <span class="text-cream truncate">پنل مدیریت</span> | |
| </h1> | |
| <p class="text-[9px] md:text-[10px] text-turk-light/80 font-medium mt-0.5 truncate hidden sm:block">پایش برخط سفارشات و منوی هوشمند</p> | |
| </div> | |
| </div> | |
| <div class="flex items-center gap-2 flex-shrink-0"> | |
| <span class="badge-live inline-flex items-center gap-1.5 md:gap-2 px-2 md:px-3 py-1.5 rounded-full text-[9px] md:text-[10px] font-bold"> | |
| <span class="live-dot"></span> | |
| <span class="hidden sm:inline">نظارت زنده</span> | |
| <span class="sm:hidden">زنده</span> | |
| </span> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Main grid --> | |
| <main class="main-grid flex-1 min-h-0 w-full mx-auto p-3 md:p-5 lg:p-6 grid grid-cols-1 lg:grid-cols-12 gap-3 md:gap-5 lg:gap-6 z-10 relative max-w-7xl"> | |
| <!-- Right column --> | |
| <section class="left-column lg:col-span-7 flex flex-col gap-3 md:gap-5 lg:gap-6 min-h-0"> | |
| <!-- Live orders --> | |
| <div class="glass-card rounded-2xl md:rounded-3xl p-4 md:p-5 lg:p-6 shadow-xl relative overflow-hidden flex-shrink-0"> | |
| <div class="absolute inset-0 bg-pattern-fine opacity-20 pointer-events-none"></div> | |
| <div class="relative"> | |
| <div class="flex items-center justify-between mb-3 border-b border-ochre/20 pb-2.5"> | |
| <div class="flex items-center gap-2.5 min-w-0"> | |
| <div class="w-8 h-8 md:w-9 md:h-9 rounded-xl bg-rug/20 border border-rug/40 flex items-center justify-center flex-shrink-0"> | |
| <svg class="w-4 h-4 md:w-5 md:h-5 text-rug-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"/> | |
| </svg> | |
| </div> | |
| <div class="min-w-0"> | |
| <h2 class="section-title text-sm md:text-base text-ochre-light flex items-center gap-2 truncate"> | |
| سفارشات جدید آشپزخانه | |
| <span class="w-2 h-2 rounded-full bg-rug-light animate-pulse flex-shrink-0"></span> | |
| </h2> | |
| <p class="text-[9px] md:text-[10px] text-cream/50 mt-0.5 truncate">گروهبندی شده بر اساس میز (ادغام خودکار)</p> | |
| </div> | |
| </div> | |
| <button onclick="fetchActiveOrders()" class="btn-ghost text-[9px] md:text-[10px] flex items-center gap-1 px-2 md:px-3 py-1.5 rounded-lg md:rounded-xl flex-shrink-0"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 1121.21 15H15"/> | |
| </svg> | |
| <span class="hidden sm:inline">بروزرسانی</span> | |
| </button> | |
| </div> | |
| <div id="ordersContainer" class="space-y-2 md:space-y-2.5 max-h-[260px] md:max-h-[320px] scroll-area pr-1"> | |
| <div class="text-center py-8 text-[11px] text-ochre/60">در حال بارگذاری...</div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Current Menu --> | |
| <div class="glass-card rounded-2xl md:rounded-3xl p-4 md:p-5 lg:p-6 space-y-3 shadow-xl relative overflow-hidden flex-shrink-0"> | |
| <div class="absolute inset-0 bg-arch opacity-15 pointer-events-none"></div> | |
| <div class="relative"> | |
| <div class="flex items-center justify-between border-b border-ochre/20 pb-2.5 mb-2.5 flex-wrap gap-2"> | |
| <div class="flex items-center gap-2.5 min-w-0"> | |
| <div class="w-8 h-8 md:w-9 md:h-9 rounded-xl bg-ochre/20 border border-ochre/40 flex items-center justify-center flex-shrink-0"> | |
| <svg class="w-4 h-4 md:w-5 md:h-5 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4"/> | |
| </svg> | |
| </div> | |
| <div class="min-w-0"> | |
| <h2 class="section-title text-sm md:text-base text-ochre-light truncate">مدیریت منوی فعال</h2> | |
| <p class="text-[9px] md:text-[10px] text-cream/50 mt-0.5 truncate">کنترل و ویرایش اقلام قابل سفارش</p> | |
| </div> | |
| </div> | |
| <div class="flex gap-1.5 md:gap-2 flex-shrink-0"> | |
| <button onclick="fetchCurrentMenu()" class="btn-ghost text-[9px] md:text-[10px] flex items-center gap-1 px-2 md:px-3 py-1.5 rounded-lg md:rounded-xl"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 1121.21 15H15"/> | |
| </svg> | |
| <span class="hidden sm:inline">بازنشانی</span> | |
| </button> | |
| <button onclick="addMenuItemRow()" class="btn-turk px-2.5 md:px-4 py-1.5 rounded-lg md:rounded-xl text-[9px] md:text-[10px] font-extrabold flex items-center gap-1"> | |
| <span>+ افزودن</span> | |
| </button> | |
| </div> | |
| </div> | |
| <p class="text-[10px] md:text-[11px] text-cream/70 leading-relaxed mb-3"> | |
| لیست اقلام منو. تغییرات بلافاصله روی سامانه مشتریان اعمال میشود. | |
| </p> | |
| <div class="overflow-x-auto max-h-[280px] md:max-h-[380px] border border-ochre/20 rounded-xl md:rounded-2xl bg-bazaar-950/50 scroll-area"> | |
| <table class="min-w-full admin-table text-[10px] md:text-[11px]" id="currentMenuTable"> | |
| <thead class="sticky top-0"> | |
| <tr> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right">نام محصول</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right hidden md:table-cell">توضیحات</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right w-16 md:w-20">قیمت</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-center w-12 md:w-16">موجود</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-center w-20 md:w-24">عملیات</th> | |
| </tr> | |
| </thead> | |
| <tbody id="menuTableBody" class="divide-y divide-ochre/10"></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Menu extraction & upload --> | |
| <div class="glass-card rounded-2xl md:rounded-3xl p-4 md:p-5 lg:p-6 space-y-3 shadow-xl relative overflow-hidden flex-shrink-0"> | |
| <div class="absolute inset-0 bg-pattern-fine opacity-20 pointer-events-none"></div> | |
| <div class="relative"> | |
| <div class="flex items-center gap-2.5 border-b border-ochre/20 pb-2.5 mb-2.5"> | |
| <div class="w-8 h-8 md:w-9 md:h-9 rounded-xl bg-turk/20 border border-turk/40 flex items-center justify-center flex-shrink-0"> | |
| <svg class="w-4 h-4 md:w-5 md:h-5 text-turk-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/> | |
| </svg> | |
| </div> | |
| <div class="min-w-0"> | |
| <h2 class="section-title text-sm md:text-base text-ochre-light truncate">استخراج خودکار منو</h2> | |
| <p class="text-[9px] md:text-[10px] text-cream/50 mt-0.5 truncate">بارگذاری تصویر یا فایل PDF</p> | |
| </div> | |
| </div> | |
| <p class="text-[10px] md:text-[11px] text-cream/70 leading-relaxed mb-3"> | |
| تصویر منو را بارگذاری کنید. هوش مصنوعی نیلا متون و قیمتها را استخراج میکند. | |
| </p> | |
| <div id="dropZone" | |
| class="drop-zone rounded-xl md:rounded-2xl p-5 md:p-8 text-center cursor-pointer" | |
| onclick="document.getElementById('menuFileInput').click()" | |
| ondragover="handleDragOver(event)" | |
| ondragleave="handleDragLeave(event)" | |
| ondrop="handleDrop(event)"> | |
| <input type="file" id="menuFileInput" class="hidden" accept="image/*,application/pdf" onchange="uploadMenuFile(event)"> | |
| <div class="flex flex-col items-center gap-2 md:gap-3"> | |
| <div class="w-12 h-12 md:w-16 md:h-16 rounded-xl md:rounded-2xl bg-gradient-to-br from-ochre/20 to-rug/15 border border-ochre/30 flex items-center justify-center"> | |
| <svg id="uploadIcon" class="w-6 h-6 md:w-8 md:h-8 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/> | |
| </svg> | |
| </div> | |
| <span class="text-xs md:text-sm text-cream font-medium">فایل منو را بکشید یا انتخاب کنید</span> | |
| <span class="text-[9px] md:text-[10px] text-ochre/60 uppercase tracking-widest">فرمتهای تصویری یا PDF</span> | |
| </div> | |
| </div> | |
| <div id="uploadLoader" class="hidden text-center py-5 bg-bazaar-950/70 rounded-xl md:rounded-2xl border border-turk/30 mt-3"> | |
| <div class="inline-block animate-spin rounded-full h-7 w-7 md:h-8 md:w-8 border-t-2 border-b-2 border-ochre mb-2"></div> | |
| <p class="text-[9px] md:text-[10px] text-ochre-light font-extrabold">نیلا در حال آنالیز منو...</p> | |
| </div> | |
| <div id="menuEditorContainer" class="hidden space-y-3 border-t border-ochre/15 pt-3 mt-3"> | |
| <h3 class="text-[11px] md:text-xs font-bold text-ochre-light flex items-center gap-1.5 section-title"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/> | |
| </svg> | |
| بازبینی اقلام منو پیش از انتشار | |
| </h3> | |
| <div class="overflow-x-auto max-h-[220px] md:max-h-[250px] border border-ochre/20 rounded-xl md:rounded-2xl bg-bazaar-950/50 scroll-area"> | |
| <table class="min-w-full admin-table text-[10px] md:text-[11px]"> | |
| <thead> | |
| <tr> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right">عنوان محصول</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right">توضیحات</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-right w-20 md:w-24">قیمت</th> | |
| <th class="px-2 md:px-3 py-2 md:py-2.5 text-center w-14 md:w-16">عملیات</th> | |
| </tr> | |
| </thead> | |
| <tbody id="menuEditorTableBody" class="divide-y divide-ochre/10"></tbody> | |
| </table> | |
| </div> | |
| <div class="flex justify-end gap-2 flex-wrap"> | |
| <button onclick="addEmptyMenuRow()" class="btn-ghost px-3 md:px-4 py-1.5 md:py-2 rounded-lg md:rounded-xl text-[9px] md:text-[10px]"> | |
| + افزودن محصول | |
| </button> | |
| <button onclick="saveAndPublishMenu()" class="btn-turk px-4 md:px-5 py-1.5 md:py-2.5 rounded-lg md:rounded-xl text-[10px] md:text-[11px] font-extrabold flex items-center gap-2"> | |
| ثبت و همگامسازی زنده | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <!-- Left column: Admin chat --> | |
| <section class="lg:col-span-5 flex flex-col min-h-0"> | |
| <div class="chat-column glass-card-azure rounded-2xl md:rounded-3xl shadow-xl relative"> | |
| <div class="absolute inset-0 bg-arch opacity-15 pointer-events-none"></div> | |
| <div class="chat-header-box relative px-3.5 md:px-5 py-2.5 md:py-3 border-b border-turk/25 flex items-center gap-2.5 bg-gradient-to-l from-azure-950/60 to-azure-900/40"> | |
| <div class="w-9 h-9 md:w-10 md:h-10 rounded-xl bg-gradient-to-br from-turk/30 to-azure-700/30 border border-turk/40 flex items-center justify-center shadow-mosque flex-shrink-0"> | |
| <svg class="w-5 h-5 md:w-6 md:h-6 text-turk-glow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"> | |
| <path d="M12 2a10 10 0 0 1 10 10c0 5.523-4.477 10-10 10S2 17.523 2 12A10 10 0 0 1 12 2z"/> | |
| <path d="M12 8v4l3 3" stroke-linecap="round"/> | |
| </svg> | |
| </div> | |
| <div class="min-w-0 flex-1"> | |
| <h3 class="section-title text-xs md:text-sm text-ochre-light tracking-wide truncate">دستیار هوشمند ادمین</h3> | |
| <p class="text-[9px] md:text-[10px] text-turk-light/80 font-medium flex items-center gap-1.5 truncate"> | |
| <span class="w-1.5 h-1.5 rounded-full bg-turk-light animate-pulse flex-shrink-0"></span> | |
| <span class="truncate">کنترل همگام موجودی و منو</span> | |
| </p> | |
| </div> | |
| </div> | |
| <div id="chatMessages" class="chat-messages-container p-3 md:p-4 space-y-3 relative"> | |
| <div class="flex gap-2 md:gap-2.5 max-w-[88%]"> | |
| <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-turk/20 to-azure-700/20 border border-turk/30 flex items-center justify-center flex-shrink-0"> | |
| <span class="text-ochre-light font-display text-[10px] md:text-[11px]">ن</span> | |
| </div> | |
| <div class="bg-bazaar-950/70 border border-ochre/20 text-cream text-xs md:text-sm rounded-2xl rounded-tr-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft chat-markdown break-words" style="flex: 1; max-width: calc(100% - 2.5rem);"> | |
| سلام همکار گرامی! من <strong>نیلا</strong> هستم، دستیار مدیریت منوی <em>Cafe AI</em>. شما میتوانید از همینجا اقلام منو را با گفتگوی ساده کنترل کنید؛ برای مثال بنویسید: «کروسان ساده تمام شد» یا «چای ماسالا را موجود کن» تا سریعاً تغییرات روی سیستم مشتریان نیز اعمال گردد. | |
| </div> | |
| </div> | |
| </div> | |
| <div id="chatLoader" class="chat-loader-box hidden relative px-3 py-2 md:px-4 md:py-2.5 flex items-center justify-between bg-azure-950/70 text-[9px] md:text-[10px] text-turk-light font-semibold border-t border-turk/20"> | |
| <div class="flex items-center gap-2"> | |
| <div class="typing-dots flex gap-1"> | |
| <span></span><span></span><span></span> | |
| </div> | |
| <span>در حال پردازش...</span> | |
| </div> | |
| <button onclick="stopAdminChat()" class="px-2.5 py-1 md:px-3 md:py-1.5 bg-rug-dark/40 border border-rug/40 hover:bg-rug/40 rounded-lg text-[9px] md:text-[10px] text-rug-light font-bold transition-all"> | |
| توقف | |
| </button> | |
| </div> | |
| <form id="chatForm" onsubmit="sendAdminMessage(event)" class="chat-input-box relative p-2 md:p-3 border-t border-turk/20 bg-bazaar-950/60 flex gap-2 safe-bottom"> | |
| <input type="text" id="chatInput" placeholder="تغییر وضعیت یا ویرایش منو..." autocomplete="off" | |
| class="flex-1 min-w-0 bg-azure-950/60 border border-azure-700/40 text-xs md:text-sm text-cream placeholder-ochre/40 rounded-lg md:rounded-xl px-3 md:px-4 py-2 md:py-3 focus:outline-none focus:border-ochre/60 transition-all duration-300"> | |
| <button type="submit" id="sendBtn" class="btn-primary px-3 md:px-4 py-2 md:py-3 rounded-lg md:rounded-xl text-xs flex items-center justify-center flex-shrink-0"> | |
| <svg class="w-4 h-4 md:w-5 md:h-5 rotate-180" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M14 5l7 7m0 0l-7 7m7-7H3"/> | |
| </svg> | |
| </button> | |
| </form> | |
| </div> | |
| </section> | |
| </main> | |
| <footer class="flex-shrink-0 border-t border-ochre/15 py-2.5 md:py-3 text-center text-[9px] md:text-[10px] text-cream/40 bg-bazaar-950/60 backdrop-blur safe-bottom"> | |
| طراحی و توسعه توسط الگوریتم داده نسترن | با الهام از فرهنگ تبریز © ۲۰۲۶ | |
| </footer> | |
| </div> | |
| <script> | |
| // ============ VIEWPORT HEIGHT FIX ============ | |
| function setVh() { | |
| const vh = window.innerHeight * 0.01; | |
| document.documentElement.style.setProperty('--vh', `${vh}px`); | |
| } | |
| setVh(); | |
| window.addEventListener('resize', setVh); | |
| window.addEventListener('orientationchange', () => setTimeout(setVh, 100)); | |
| function scrollChatToBottom(smooth = true) { | |
| const chatScroll = document.getElementById('chatMessages'); | |
| if (chatScroll) { | |
| if (smooth) { | |
| chatScroll.scrollTo({ top: chatScroll.scrollHeight, behavior: 'smooth' }); | |
| } else { | |
| chatScroll.scrollTop = chatScroll.scrollHeight; | |
| } | |
| } | |
| } | |
| window.addEventListener('resize', () => { | |
| setVh(); | |
| setTimeout(scrollChatToBottom, 150); | |
| }); | |
| marked.setOptions({ sanitize: true, breaks: true }); | |
| let chatHistory = [ | |
| { role: 'model', content: 'سلام همکار گرامی! من نیلا هستم، دستیار مدیریت منوی Cafe AI. شما میتوانید از همینجا اقلام منو را با گفتگوی ساده کنترل کنید؛ برای مثال بنویسید: «کروسان ساده تمام شد» یا «چای ماسالا را موجود کن» تا سریعاً تغییرات روی سیستم مشتریان نیز اعمال گردد.' } | |
| ]; | |
| let abortController = null; | |
| let isGenerating = false; | |
| window.addEventListener('DOMContentLoaded', () => { | |
| fetchActiveOrders(); | |
| fetchCurrentMenu(); | |
| setInterval(fetchActiveOrders, 10000); | |
| setTimeout(scrollChatToBottom, 100); | |
| }); | |
| const chatInput = document.getElementById('chatInput'); | |
| if (chatInput) { | |
| chatInput.addEventListener('focus', () => { | |
| setTimeout(scrollChatToBottom, 300); | |
| setTimeout(scrollChatToBottom, 600); | |
| }); | |
| } | |
| // ============ ORDER FUNCTIONS - با ادغام سفارشات هر میز ============ | |
| async function fetchActiveOrders() { | |
| const container = document.getElementById('ordersContainer'); | |
| try { | |
| const response = await fetch('/api/admin/orders'); | |
| const orders = await response.json(); | |
| if (response.ok) { | |
| if (orders.length === 0) { | |
| container.innerHTML = ` | |
| <div class="text-center py-8 md:py-12 text-ochre/60 border-2 border-dashed border-ochre/25 rounded-xl md:rounded-2xl bg-bazaar-950/30"> | |
| <svg class="w-8 h-8 md:w-10 md:h-10 text-ochre/40 mx-auto mb-2 md:mb-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/> | |
| </svg> | |
| <p class="text-xs md:text-sm font-medium">سفارش معلقی در صف نیست</p> | |
| <p class="text-[9px] md:text-[10px] text-cream/40 mt-1">بهروزرسانی خودکار فعال</p> | |
| </div> | |
| `; | |
| return; | |
| } | |
| // ✅ گروهبندی سفارشات بر اساس میز | |
| const tableGroups = {}; | |
| orders.forEach(order => { | |
| const tableKey = String(order.table); | |
| if (!tableGroups[tableKey]) { | |
| tableGroups[tableKey] = { | |
| table: order.table, | |
| orderIds: [], | |
| items: {}, // name -> {name, quantity} | |
| timestamps: [], | |
| totalItemCount: 0 | |
| }; | |
| } | |
| const group = tableGroups[tableKey]; | |
| group.orderIds.push(order.id); | |
| group.timestamps.push(order.timestamp); | |
| group.totalItemCount += order.items.reduce((sum, it) => sum + it.quantity, 0); | |
| // ✅ ادغام آیتمهای تکراری با جمع تعداد | |
| order.items.forEach(item => { | |
| if (group.items[item.name]) { | |
| group.items[item.name].quantity += item.quantity; | |
| } else { | |
| group.items[item.name] = { name: item.name, quantity: item.quantity }; | |
| } | |
| }); | |
| }); | |
| container.innerHTML = ''; | |
| // مرتبسازی بر اساس جدیدترین timestamp هر گروه | |
| const sortedGroups = Object.values(tableGroups).sort((a, b) => { | |
| const aMax = Math.max(...a.timestamps); | |
| const bMax = Math.max(...b.timestamps); | |
| return bMax - aMax; | |
| }); | |
| sortedGroups.forEach(group => { | |
| const itemsArray = Object.values(group.items); | |
| let itemsHtml = ''; | |
| itemsArray.forEach(item => { | |
| itemsHtml += ` | |
| <div class="flex items-center justify-between text-[10px] md:text-[11px] bg-bazaar-950/60 px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg border border-ochre/20"> | |
| <span class="text-cream font-bold flex items-center gap-2 min-w-0"> | |
| <span class="w-1 h-4 md:h-5 bg-gradient-to-b from-rug to-ochre rounded-full flex-shrink-0"></span> | |
| <span class="truncate">${escapeHtml(item.name)}</span> | |
| </span> | |
| <span class="text-ochre-light bg-ochre/10 px-2 py-0.5 rounded-md font-display text-[9px] md:text-[10px] border border-ochre/25 flex-shrink-0 mr-2">×${item.quantity}</span> | |
| </div> | |
| `; | |
| }); | |
| // محاسبه زمانها | |
| const firstTime = new Date(Math.min(...group.timestamps) * 1000).toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }); | |
| const lastTime = new Date(Math.max(...group.timestamps) * 1000).toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' }); | |
| const orderCount = group.orderIds.length; | |
| const isMulti = orderCount > 1; | |
| // نمایش زمان | |
| let timeDisplay = ''; | |
| if (isMulti) { | |
| timeDisplay = `<span class="text-[9px] md:text-[10px] text-turk-light/70 font-medium flex items-center gap-1 flex-shrink-0"> | |
| <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/> | |
| </svg> | |
| ${firstTime} → ${lastTime} | |
| </span>`; | |
| } else { | |
| timeDisplay = `<span class="text-[9px] md:text-[10px] text-turk-light/70 font-medium flex items-center gap-1 flex-shrink-0"> | |
| <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/> | |
| </svg> | |
| ${lastTime} | |
| </span>`; | |
| } | |
| // Badge برای سفارشات چندگانه | |
| const multiBadge = isMulti ? ` | |
| <span class="orders-count-badge text-[10px] md:text-[11px] px-2 py-0.5 rounded-md flex items-center gap-1 flex-shrink-0"> | |
| <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4"/> | |
| </svg> | |
| ${orderCount} سفارش | |
| </span> | |
| ` : ''; | |
| const orderIdsJson = JSON.stringify(group.orderIds).replace(/"/g, '"'); | |
| const cardHtml = ` | |
| <div class="order-card ${isMulti ? 'multi-order' : ''} relative rounded-xl md:rounded-2xl p-3 md:p-4 flex flex-col md:flex-row justify-between items-start md:items-center gap-2.5 md:gap-3"> | |
| <div class="flex-1 space-y-2 w-full min-w-0"> | |
| <div class="flex items-center justify-between md:justify-start gap-2 md:gap-3 w-full flex-wrap"> | |
| <span class="badge-table text-[10px] md:text-xs font-bold px-2.5 md:px-3 py-1 rounded-lg flex items-center gap-1.5 flex-shrink-0"> | |
| <svg class="w-3 h-3 md:w-3.5 md:h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/> | |
| </svg> | |
| میز ${group.table} | |
| </span> | |
| ${multiBadge} | |
| ${timeDisplay} | |
| </div> | |
| <div class="grid grid-cols-1 sm:grid-cols-2 gap-1 md:gap-1.5 mt-1.5 md:mt-2"> | |
| ${itemsHtml} | |
| </div> | |
| </div> | |
| <button onclick='completeOrdersForTable(${orderIdsJson})' class="w-full md:w-auto btn-ghost hover:bg-emerald-dark/40 hover:border-emerald-light/50 hover:text-emerald-light px-3 md:px-4 py-2 md:py-2.5 rounded-lg md:rounded-xl text-[9px] md:text-[10px] font-bold flex items-center justify-center gap-1.5 flex-shrink-0 group"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4 transition-transform group-hover:scale-110" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/> | |
| </svg> | |
| تحویل نهایی ${isMulti ? `(${orderCount} سفارش)` : 'شد'} | |
| </button> | |
| </div> | |
| `; | |
| container.insertAdjacentHTML('beforeend', cardHtml); | |
| }); | |
| } else { | |
| container.innerHTML = `<div class="text-center py-6 text-rug-light text-xs">خطا در دریافت سفارشات.</div>`; | |
| } | |
| } catch (err) { | |
| container.innerHTML = `<div class="text-center py-6 text-rug-light text-xs">عدم ارتباط با سرور: ${escapeHtml(err.message)}</div>`; | |
| } | |
| } | |
| // ✅ تکمیل همه سفارشهای یک میز (چندگانه) | |
| async function completeOrdersForTable(orderIds) { | |
| if (!Array.isArray(orderIds) || orderIds.length === 0) return; | |
| try { | |
| // انجام sequential همه درخواستها | |
| let successCount = 0; | |
| let failCount = 0; | |
| for (const orderId of orderIds) { | |
| try { | |
| const response = await fetch('/api/admin/complete_order', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ order_id: orderId }) | |
| }); | |
| const result = await response.json(); | |
| if (response.ok && result.success) { | |
| successCount++; | |
| } else { | |
| failCount++; | |
| } | |
| } catch (e) { | |
| failCount++; | |
| } | |
| } | |
| if (failCount === 0) { | |
| fetchActiveOrders(); | |
| } else { | |
| alert(`${successCount} سفارش تکمیل شد. ${failCount} خطا رخ داد.`); | |
| fetchActiveOrders(); | |
| } | |
| } catch (err) { | |
| alert("خطای شبکه: " + err.message); | |
| } | |
| } | |
| // ============ MENU CRUD ============ | |
| async function fetchCurrentMenu() { | |
| const tbody = document.getElementById('menuTableBody'); | |
| tbody.innerHTML = '<tr><td colspan="5" class="text-center py-6 text-ochre/60 text-xs">در حال بارگذاری...</td></tr>'; | |
| try { | |
| const res = await fetch('/api/admin/menu'); | |
| const menu = await res.json(); | |
| if (res.ok && Array.isArray(menu)) { | |
| renderMenuTable(menu); | |
| } else { | |
| tbody.innerHTML = '<tr><td colspan="5" class="text-center py-6 text-rug-light text-xs">خطا</td></tr>'; | |
| } | |
| } catch (e) { | |
| tbody.innerHTML = '<tr><td colspan="5" class="text-center py-6 text-rug-light text-xs">عدم اتصال</td></tr>'; | |
| } | |
| } | |
| function renderMenuTable(menu) { | |
| const tbody = document.getElementById('menuTableBody'); | |
| tbody.innerHTML = ''; | |
| if (menu.length === 0) { | |
| tbody.innerHTML = '<tr><td colspan="5" class="text-center py-6 text-ochre/60 text-xs">منو خالی است.</td></tr>'; | |
| return; | |
| } | |
| menu.forEach(item => { | |
| const row = document.createElement('tr'); | |
| row.className = 'menu-row'; | |
| row.dataset.id = item.id; | |
| row.innerHTML = ` | |
| <td class="px-2 py-1.5 md:py-2"> | |
| <span class="view-mode font-bold text-cream">${escapeHtml(item.name)}</span> | |
| <input type="text" class="edit-mode hidden w-full bg-azure-950/60 border border-azure-700/40 rounded px-2 py-1 text-cream text-[10px] md:text-[11px]" value="${escapeHtml(item.name)}" data-field="name"> | |
| </td> | |
| <td class="px-2 py-1.5 md:py-2 hidden md:table-cell"> | |
| <span class="view-mode text-cream/60 text-[10px]">${escapeHtml(item.description || '-')}</span> | |
| <input type="text" class="edit-mode hidden w-full bg-azure-950/60 border border-azure-700/40 rounded px-2 py-1 text-cream text-[11px]" value="${escapeHtml(item.description || '')}" data-field="description"> | |
| </td> | |
| <td class="px-2 py-1.5 md:py-2"> | |
| <span class="view-mode text-ochre-light font-medium">${escapeHtml(item.price || '-')}</span> | |
| <input type="text" class="edit-mode hidden w-full bg-azure-950/60 border border-azure-700/40 rounded px-2 py-1 text-cream text-[11px]" value="${escapeHtml(item.price || '')}" data-field="price"> | |
| </td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"> | |
| <span class="view-mode text-[9px] md:text-[10px] ${item.available ? 'text-emerald-light' : 'text-rug-light'} font-bold">${item.available ? '✓' : '✗'}</span> | |
| <div class="edit-mode hidden flex items-center justify-center"> | |
| <input type="checkbox" data-field="available" ${item.available ? 'checked' : ''}> | |
| </div> | |
| </td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"> | |
| <div class="view-mode flex gap-1 justify-center"> | |
| <button onclick="editMenuItem(this)" class="p-1 md:p-1.5 text-turk/70 hover:text-ochre-light transition-colors rounded-lg hover:bg-bazaar-800/50" title="ویرایش"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/> | |
| </svg> | |
| </button> | |
| <button onclick="deleteMenuItem(${item.id})" class="p-1 md:p-1.5 text-cream/30 hover:text-rug-light transition-colors rounded-lg hover:bg-bazaar-800/50" title="حذف"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="edit-mode hidden flex gap-1 justify-center"> | |
| <button onclick="saveMenuItem(this, ${item.id})" class="px-2 md:px-2.5 py-1 bg-emerald-dark/40 border border-emerald-light/40 text-emerald-light rounded-md text-[9px] md:text-[10px] font-bold">ذخیره</button> | |
| <button onclick="cancelEdit(this)" class="px-2 md:px-2.5 py-1 bg-bazaar-800 border border-ochre/20 text-cream/60 rounded-md text-[9px] md:text-[10px]">لغو</button> | |
| </div> | |
| </td> | |
| `; | |
| tbody.appendChild(row); | |
| }); | |
| } | |
| function escapeHtml(text) { | |
| return String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, '''); | |
| } | |
| function toggleRowEdit(row, editing) { | |
| row.querySelectorAll('.view-mode').forEach(el => el.classList.toggle('hidden', editing)); | |
| row.querySelectorAll('.edit-mode').forEach(el => el.classList.toggle('hidden', !editing)); | |
| } | |
| function editMenuItem(btn) { toggleRowEdit(btn.closest('tr'), true); } | |
| function cancelEdit(btn) { fetchCurrentMenu(); } | |
| async function saveMenuItem(btn, id) { | |
| const row = btn.closest('tr'); | |
| const data = { | |
| name: row.querySelector('[data-field="name"]').value.trim(), | |
| description: row.querySelector('[data-field="description"]').value.trim(), | |
| price: row.querySelector('[data-field="price"]').value.trim(), | |
| available: row.querySelector('[data-field="available"]').checked | |
| }; | |
| if (!data.name) { alert('نام آیتم نمیتواند خالی باشد.'); return; } | |
| try { | |
| const res = await fetch(`/api/admin/menu/item/${id}`, { | |
| method: 'PUT', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(data) | |
| }); | |
| const result = await res.json(); | |
| if (res.ok && result.success) fetchCurrentMenu(); | |
| else alert(result.error || 'خطا در بروزرسانی'); | |
| } catch (e) { alert('خطای شبکه: ' + e.message); } | |
| } | |
| async function deleteMenuItem(id) { | |
| if (!confirm('آیا از حذف این آیتم اطمینان دارید؟')) return; | |
| try { | |
| const res = await fetch(`/api/admin/menu/item/${id}`, { method: 'DELETE' }); | |
| const result = await res.json(); | |
| if (res.ok && result.success) fetchCurrentMenu(); | |
| else alert(result.error || 'خطا در حذف'); | |
| } catch (e) { alert('خطای شبکه: ' + e.message); } | |
| } | |
| function addMenuItemRow() { | |
| const tbody = document.getElementById('menuTableBody'); | |
| const row = document.createElement('tr'); | |
| row.className = 'menu-row bg-bazaar-800/40'; | |
| row.innerHTML = ` | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="w-full bg-azure-950/60 border border-turk/40 rounded px-2 py-1 text-cream text-[10px] md:text-[11px]" placeholder="نام" data-field="name"></td> | |
| <td class="px-2 py-1.5 md:py-2 hidden md:table-cell"><input type="text" class="w-full bg-azure-950/60 border border-azure-700/40 rounded px-2 py-1 text-cream text-[11px]" placeholder="توضیحات" data-field="description"></td> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="w-full bg-azure-950/60 border border-azure-700/40 rounded px-2 py-1 text-cream text-[11px]" placeholder="قیمت" data-field="price"></td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"><input type="checkbox" data-field="available" checked></td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"><button onclick="saveNewItem(this)" class="btn-turk px-2.5 md:px-3 py-1 rounded-md text-[9px] md:text-[10px]">افزودن</button></td> | |
| `; | |
| tbody.appendChild(row); | |
| } | |
| async function saveNewItem(btn) { | |
| const row = btn.closest('tr'); | |
| const name = row.querySelector('[data-field="name"]').value.trim(); | |
| const desc = row.querySelector('[data-field="description"]').value.trim(); | |
| const price = row.querySelector('[data-field="price"]').value.trim(); | |
| const avail = row.querySelector('[data-field="available"]').checked; | |
| if (!name) { alert('نام الزامی است.'); return; } | |
| try { | |
| const res = await fetch('/api/admin/menu/item', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ name, description: desc, price, available: avail }) | |
| }); | |
| const result = await res.json(); | |
| if (res.ok && result.success) fetchCurrentMenu(); | |
| else alert(result.error || 'خطا در افزودن'); | |
| } catch (e) { alert('خطای شبکه: ' + e.message); } | |
| } | |
| // ============ MENU EXTRACTION ============ | |
| function handleDragOver(e) { e.preventDefault(); document.getElementById('dropZone').classList.add('drag-over'); } | |
| function handleDragLeave(e) { e.preventDefault(); document.getElementById('dropZone').classList.remove('drag-over'); } | |
| function handleDrop(e) { | |
| e.preventDefault(); | |
| handleDragLeave(e); | |
| const files = e.dataTransfer.files; | |
| if (files.length > 0) { | |
| document.getElementById('menuFileInput').files = files; | |
| uploadMenuFile({ target: { files: files } }); | |
| } | |
| } | |
| async function uploadMenuFile(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const loader = document.getElementById('uploadLoader'); | |
| const editor = document.getElementById('menuEditorContainer'); | |
| loader.classList.remove('hidden'); | |
| editor.classList.add('hidden'); | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| try { | |
| const response = await fetch('/api/admin/extract_menu', { method: 'POST', body: formData }); | |
| const data = await response.json(); | |
| loader.classList.add('hidden'); | |
| if (response.ok && data.success) { | |
| renderMenuEditor(data.extracted_menu); | |
| editor.classList.remove('hidden'); | |
| } else { | |
| alert(data.error || 'خطا در آنالیز فایل.'); | |
| } | |
| } catch (err) { | |
| loader.classList.add('hidden'); | |
| alert('خطا: ' + err.message); | |
| } | |
| } | |
| function renderMenuEditor(menuItems) { | |
| const tbody = document.getElementById('menuEditorTableBody'); | |
| tbody.innerHTML = ''; | |
| menuItems.forEach(item => { | |
| const row = ` | |
| <tr class="menu-row"> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-name w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream focus:border-ochre/50 text-[10px] md:text-[11px]" value="${escapeHtml(item.name || '')}"></td> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-desc w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream focus:border-ochre/50 text-[10px] md:text-[11px]" value="${escapeHtml(item.description || '')}"></td> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-price w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream focus:border-ochre/50 text-[10px] md:text-[11px]" value="${escapeHtml(item.price || '')}"></td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"> | |
| <button onclick="removeMenuRow(this)" class="p-1 md:p-1.5 text-cream/30 hover:text-rug-light transition-colors rounded-lg hover:bg-bazaar-800/50"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/> | |
| </svg> | |
| </button> | |
| </td> | |
| </tr> | |
| `; | |
| tbody.insertAdjacentHTML('beforeend', row); | |
| }); | |
| } | |
| function addEmptyMenuRow() { | |
| const tbody = document.getElementById('menuEditorTableBody'); | |
| const row = ` | |
| <tr class="menu-row"> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-name w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream text-[10px] md:text-[11px]" placeholder="مثال: لاته"></td> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-desc w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream text-[10px] md:text-[11px]" placeholder="توضیحات"></td> | |
| <td class="px-2 py-1.5 md:py-2"><input type="text" class="menu-price w-full bg-azure-950/60 border border-azure-700/40 rounded-lg px-2.5 py-1.5 text-cream text-[10px] md:text-[11px]" placeholder="۸۵,۰۰۰"></td> | |
| <td class="px-2 py-1.5 md:py-2 text-center"> | |
| <button onclick="removeMenuRow(this)" class="p-1 md:p-1.5 text-cream/30 hover:text-rug-light transition-colors rounded-lg hover:bg-bazaar-800/50"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/> | |
| </svg> | |
| </button> | |
| </td> | |
| </tr> | |
| `; | |
| tbody.insertAdjacentHTML('beforeend', row); | |
| } | |
| function removeMenuRow(btn) { btn.closest('tr').remove(); } | |
| async function saveAndPublishMenu() { | |
| const tbody = document.getElementById('menuEditorTableBody'); | |
| const rows = tbody.querySelectorAll('tr'); | |
| const menuData = []; | |
| rows.forEach(row => { | |
| const name = row.querySelector('.menu-name').value.trim(); | |
| const description = row.querySelector('.menu-desc').value.trim(); | |
| const price = row.querySelector('.menu-price').value.trim(); | |
| if (name) menuData.push({ name, description, price, available: true }); | |
| }); | |
| if (menuData.length === 0) { alert("لیست فاقد محصول است."); return; } | |
| try { | |
| const response = await fetch('/api/admin/save_menu', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ menu: menuData }) | |
| }); | |
| const data = await response.json(); | |
| if (response.ok && data.success) { | |
| alert("✅ منوی جدید با موفقیت ثبت و همگامسازی شد!"); | |
| document.getElementById('menuEditorContainer').classList.add('hidden'); | |
| fetchCurrentMenu(); | |
| appendChatMessage('model', '✅ **منوی زنده همگامسازی شد.** سیستم سفارشگیری مشتریان اکنون بر مبنای آخرین لیست ویرایششده کالیبره شده است.'); | |
| } else { | |
| alert(data.error || 'خطا در همگامسازی.'); | |
| } | |
| } catch (err) { alert('خطا: ' + err.message); } | |
| } | |
| // ============ ADMIN CHAT ============ | |
| async function sendAdminMessage(e) { | |
| e.preventDefault(); | |
| if (isGenerating) return; | |
| const input = document.getElementById('chatInput'); | |
| const text = input.value.trim(); | |
| if (!text) return; | |
| appendChatMessage('user', text); | |
| input.value = ''; | |
| chatHistory.push({ role: 'user', content: text }); | |
| isGenerating = true; | |
| toggleChatLoading(true); | |
| abortController = new AbortController(); | |
| try { | |
| const response = await fetch('/api/admin/chat', { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ messages: chatHistory }), | |
| signal: abortController.signal | |
| }); | |
| const data = await response.json(); | |
| toggleChatLoading(false); | |
| isGenerating = false; | |
| if (response.ok && data.success) { | |
| const botBubbleId = appendChatMessage('model', ''); | |
| const botBubble = document.getElementById(botBubbleId); | |
| const textResponse = data.response; | |
| let i = 0; | |
| function typeText() { | |
| if (i < textResponse.length && !abortController.signal.aborted) { | |
| botBubble.textContent += textResponse.charAt(i); | |
| i++; | |
| scrollChatToBottom(false); | |
| setTimeout(typeText, 6); | |
| } else { | |
| botBubble.textContent = ''; | |
| botBubble.innerHTML = marked.parse(textResponse); | |
| chatHistory.push({ role: 'model', content: textResponse }); | |
| scrollChatToBottom(true); | |
| fetchCurrentMenu(); | |
| } | |
| } | |
| typeText(); | |
| } else { | |
| appendChatMessage('model', data.error || 'خطا در پاسخگویی.'); | |
| } | |
| } catch (err) { | |
| toggleChatLoading(false); | |
| isGenerating = false; | |
| if (err.name !== 'AbortError') { | |
| appendChatMessage('model', '❌ خطا: ' + escapeHtml(err.message)); | |
| } | |
| } | |
| } | |
| function stopAdminChat() { | |
| if (abortController) abortController.abort(); | |
| toggleChatLoading(false); | |
| isGenerating = false; | |
| } | |
| function toggleChatLoading(loading) { | |
| const loader = document.getElementById('chatLoader'); | |
| const sendBtn = document.getElementById('sendBtn'); | |
| const input = document.getElementById('chatInput'); | |
| if (loading) { | |
| loader.classList.remove('hidden'); | |
| sendBtn.disabled = true; | |
| input.disabled = true; | |
| } else { | |
| loader.classList.add('hidden'); | |
| sendBtn.disabled = false; | |
| input.disabled = false; | |
| } | |
| } | |
| function appendChatMessage(role, content) { | |
| const container = document.getElementById('chatMessages'); | |
| const bubbleId = 'bubble-admin-' + Date.now() + '-' + Math.random().toString(36).substr(2, 5); | |
| let html = ''; | |
| if (role === 'user') { | |
| html = ` | |
| <div class="flex justify-end gap-2 md:gap-2.5 max-w-[88%] mr-auto"> | |
| <div class="bg-gradient-to-br from-rug/20 to-rug-dark/30 border border-rug/30 text-cream text-xs md:text-sm rounded-2xl rounded-tl-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft break-words" style="flex: 1; max-width: calc(100% - 2.5rem);"> | |
| ${escapeHtml(content)} | |
| </div> | |
| <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-ochre/30 to-rug/20 border border-ochre/40 flex items-center justify-center flex-shrink-0"> | |
| <svg class="w-3.5 h-3.5 md:w-4 md:h-4 text-ochre-light" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"> | |
| <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/> | |
| </svg> | |
| </div> | |
| </div> | |
| `; | |
| } else { | |
| html = ` | |
| <div class="flex gap-2 md:gap-2.5 max-w-[88%]"> | |
| <div class="w-7 h-7 md:w-8 md:h-8 rounded-xl bg-gradient-to-br from-turk/20 to-azure-700/20 border border-turk/30 flex items-center justify-center flex-shrink-0"> | |
| <span class="text-ochre-light font-display text-[10px] md:text-[11px]">ن</span> | |
| </div> | |
| <div id="${bubbleId}" class="bg-bazaar-950/70 border border-ochre/20 text-cream text-xs md:text-sm rounded-2xl rounded-tr-none px-3 py-2 md:px-3.5 md:py-2.5 leading-relaxed shadow-inner-soft chat-markdown min-w-0 break-words" style="flex: 1; max-width: calc(100% - 2.5rem);"> | |
| ${content ? marked.parse(content) : ''} | |
| </div> | |
| </div> | |
| `; | |
| } | |
| container.insertAdjacentHTML('beforeend', html); | |
| scrollChatToBottom(true); | |
| return bubbleId; | |
| } | |
| </script> | |
| </body> | |
| </html> |