'use client'; import { useState, useEffect, useCallback } from 'react'; import { Store, Globe, Image as ImageIcon, Phone, Mail, MapPin, Link, Settings, Menu, SlidersHorizontal, ShieldCheck, RefreshCw, Save, Plus, Trash2, ChevronDown, CreditCard, Star, MessageSquare, Upload, } from 'lucide-react'; import { toast } from 'sonner'; import { adminService } from '@/services/api/adminService'; // ───────────────────────────────────────────────────────────────────────────── // Tabs // ───────────────────────────────────────────────────────────────────────────── type Tab = 'branding' | 'footer' | 'megamenu' | 'filters'; const TABS: { id: Tab; label: string; icon: React.ReactNode }[] = [ { id: 'branding', label: 'Branding & Settings', icon: }, { id: 'footer', label: 'Footer', icon: }, { id: 'megamenu', label: 'Mega Menu', icon: }, { id: 'filters', label: 'Catalog Filters', icon: }, ]; // ───────────────────────────────────────────────────────────────────────────── // Branding Tab // ───────────────────────────────────────────────────────────────────────────── function BrandingTab() { const [form, setForm] = useState>({ store_name: '', logo_url: '', primary_wordmark_url: '', secondary_wordmark_url: '', favicon_url: '', support_phone: '', currency_code: 'INR', advance_percent: 20, theme_color: '#6D28D9', }); const [sizeChart, setSizeChart] = useState<{ size: string; width: string; height: string; depth: string }[]>([]); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { adminService.getCmsSettings().then((data: Record) => { const { size_chart, ...rest } = data; setForm((prev) => ({ ...prev, ...rest })); if (Array.isArray(size_chart)) setSizeChart(size_chart); setLoading(false); }).catch(() => { setLoading(false); toast.error('Failed to load settings'); }); }, []); const set = (k: string, v: string | number) => setForm((p) => ({ ...p, [k]: v })); const addSizeRow = () => setSizeChart((rows) => [...rows, { size: '', width: '', height: '', depth: '' }]); const updateSizeRow = (i: number, field: string, v: string) => setSizeChart((rows) => rows.map((r, j) => j === i ? { ...r, [field]: v } : r)); const deleteSizeRow = (i: number) => setSizeChart((rows) => rows.filter((_, j) => j !== i)); const save = async () => { setSaving(true); try { await adminService.updateCmsSettings({ ...form, size_chart: sizeChart } as Record); toast.success('Store settings saved'); } catch { toast.error('Failed to save'); } finally { setSaving(false); } }; if (loading) return ; return (
}>
set('store_name', v)} /> set('support_phone', v)} icon={} /> set('currency_code', v)} />
set('advance_percent', Number(e.target.value))} className="w-24 h-9 px-3 crm-radius-control border border-border bg-card text-[13px] text-foreground focus:outline-none focus:border-primary" /> % of order total collected as deposit
set('theme_color', v)} />
{/* ── Size Chart ── */} }>

Configure the global size chart shown on every product detail page under the "Size Chart" tab.

{/* Header */} {sizeChart.length > 0 && (
{['Size', 'Width', 'Height', 'Depth', ''].map((h) => ( {h} ))}
)} {/* Rows */} {sizeChart.map((row, i) => (
updateSizeRow(i, 'size', v)} placeholder="e.g. S / M / L" /> updateSizeRow(i, 'width', v)} placeholder="e.g. 70 mm" /> updateSizeRow(i, 'height', v)} placeholder="e.g. 140 mm" /> updateSizeRow(i, 'depth', v)} placeholder="e.g. 20 mm" />
))} {sizeChart.length === 0 && (

No size chart rows yet. Add a row to get started.

)}
); } // ───────────────────────────────────────────────────────────────────────────── // Footer Tab // ───────────────────────────────────────────────────────────────────────────── interface SocialLink { platform: string; url: string; icon: string; } interface NavLink { label: string; href: string; } interface FooterColumn { title: string; links: NavLink[]; } interface PaymentMethod { name: string; icon_url: string; } function FooterTab() { const [phone, setPhone] = useState(''); const [email, setEmail] = useState(''); const [address, setAddress] = useState(''); const [copyright, setCopyright] = useState(''); const [socials, setSocials] = useState([]); const [columns, setColumns] = useState([]); const [payments, setPayments] = useState([]); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { adminService.getCmsFooterInfo().then((d: any) => { setPhone(d.phone || ''); setEmail(d.email || ''); setAddress(d.address || ''); setCopyright(d.copyright || ''); setSocials(d.social_links || []); setColumns(d.columns || []); setPayments(d.payment_methods || []); setLoading(false); }).catch(() => { setLoading(false); toast.error('Failed to load footer info'); }); }, []); const save = async () => { setSaving(true); try { await adminService.updateCmsFooterInfo({ phone, email, address, copyright, social_links: socials, columns, payment_methods: payments }); toast.success('Footer info saved'); } catch { toast.error('Failed to save'); } finally { setSaving(false); } }; if (loading) return ; return (
}>
} /> } />