{"path":"src/app/admin/page.tsx","size":43403,"locked":false,"binary":false,"truncated":false,"content":"\"use client\";\n\nexport const dynamic = \"force-dynamic\";\n\nimport { useState, useEffect } from \"react\";\nimport { createClient } from \"@/lib/supabase/client\";\nimport { Plus, Star, X, Trash2 } from \"lucide-react\";\nimport { brandConfig } from \"@/lib/brand\";\nimport { revalidateHome } from \"@/actions/revalidate\";\nimport { AdminProductCard } from \"@/components/admin/AdminProductCard\"; // NEW\n\nconst supabase = createClient();\n\nexport default function AdminDashboard() {\n  const [activeTab, setActiveTab] = useState(\"products\");\n  const [products, setProducts] = useState<any[]>([]);\n  const [reviews, setReviews] = useState<any[]>([]);\n  const [settings, setSettings] = useState<any>({\n    name: brandConfig.name,\n    tagline: brandConfig.tagline,\n    colors: { ...brandConfig.colors },\n    hero: { ...brandConfig.hero },\n    about: { ...brandConfig.about },\n    contact: { ...brandConfig.contact },\n    footer: {\n      ...brandConfig.footer,\n      socials: {\n        instagram: brandConfig.footer?.socials?.instagram || \"\",\n        facebook: brandConfig.footer?.socials?.facebook || \"\",\n        x: brandConfig.footer?.socials?.x || \"\",\n        youtube: brandConfig.footer?.socials?.youtube || \"\",\n        whatsapp_channel: brandConfig.footer?.socials?.whatsapp_channel || \"\",\n        telegram_channel: brandConfig.footer?.socials?.telegram_channel || \"\",\n        discord_channel: brandConfig.footer?.socials?.discord_channel || \"\",\n        viber_channel: brandConfig.footer?.socials?.viber_channel || \"\",\n      },\n    },\n    nav: [...brandConfig.nav],\n    chat: {\n      whatsapp: brandConfig.chat?.whatsapp || \"\",\n      telegram: brandConfig.chat?.telegram || \"\",\n      discord: brandConfig.chat?.discord || \"\",\n      viber: brandConfig.chat?.viber || \"\",\n    },\n    preferred_chat: brandConfig.preferred_chat || \"whatsapp\",\n  });\n  const [loading, setLoading] = useState(true);\n  const [user, setUser] = useState<any>(null);\n  const [modalOpen, setModalOpen] = useState(false);\n  const [editingProduct, setEditingProduct] = useState<any>(null);\n\n  const [form, setForm] = useState({\n    name: \"\",\n    description: \"\",\n    price: \"\",\n    badge: \"\",\n    icon: \"sparkles\",\n  });\n  const [imageList, setImageList] = useState<string[]>([\"\"]);\n\n  useEffect(() => {\n    if (!supabase) return;\n    supabase.auth.getUser().then(({ data }) => {\n      if (!data.user) {\n        window.location.href = \"/login\";\n      } else {\n        setUser(data.user);\n        fetchData();\n      }\n    });\n  }, []);\n\n  const fetchData = async () => {\n    setLoading(true);\n    try {\n      const [prodRes, revRes, settRes] = await Promise.all([\n        supabase!.from(\"products\").select(\"*\").order(\"created_at\", { ascending: false }),\n        supabase!.from(\"reviews\").select(\"*\").order(\"created_at\", { ascending: false }),\n        supabase!.from(\"site_settings\").select(\"*\").single(),\n      ]);\n      setProducts(prodRes.data || []);\n      setReviews(revRes.data || []);\n      if (settRes.data) {\n        const s = settRes.data;\n        setSettings((prev: any) => ({\n          name: s.name ?? prev.name,\n          tagline: s.tagline ?? prev.tagline,\n          colors: s.colors ?? prev.colors,\n          hero: s.hero ?? prev.hero,\n          about: s.about ?? prev.about,\n          contact: s.contact ?? prev.contact,\n          footer: s.footer ?? prev.footer,\n          nav: s.nav ?? prev.nav,\n          chat: s.chat ?? prev.chat,\n          preferred_chat: s.preferred_chat ?? prev.preferred_chat,\n        }));\n      }\n    } catch (error) {\n      console.error(error);\n    }\n    setLoading(false);\n  };\n\n  const openAddModal = () => {\n    setEditingProduct(null);\n    setForm({ name: \"\", description: \"\", price: \"\", badge: \"\", icon: \"sparkles\" });\n    setImageList([\"\"]);\n    setModalOpen(true);\n  };\n\n  const openEditModal = (product: any) => {\n    setEditingProduct(product);\n    setForm({\n      name: product.name || \"\",\n      description: product.description || \"\",\n      price: product.price?.toString() || \"\",\n      badge: product.badge || \"\",\n      icon: product.icon || \"sparkles\",\n    });\n    const existingImages: string[] = Array.isArray(product.images)\n      ? product.images\n      : product.image\n      ? [product.image]\n      : [\"\"];\n    setImageList(existingImages);\n    setModalOpen(true);\n  };\n\n  const handleImageChange = (index: number, value: string) => {\n    const updated = [...imageList];\n    updated[index] = value;\n    setImageList(updated);\n  };\n\n  const addImageField = () => setImageList([...imageList, \"\"]);\n\n  const removeImageField = (index: number) => {\n    if (imageList.length <= 1) return;\n    const updated = imageList.filter((_, i) => i !== index);\n    setImageList(updated);\n  };\n\n  const handleProductSubmit = async () => {\n    if (!supabase) return;\n    const cleanedImages = imageList.map((url) => url.trim()).filter((url) => url.length > 0);\n    const primaryImage = cleanedImages.length > 0 ? cleanedImages[0] : \"\";\n\n    const payload = {\n      name: form.name,\n      description: form.description,\n      price: parseFloat(form.price) || 0,\n      image: primaryImage,\n      images: cleanedImages,\n      badge: form.badge,\n      icon: form.icon,\n      is_active: true,\n    };\n    if (editingProduct) {\n      await supabase.from(\"products\").update(payload).eq(\"id\", editingProduct.id);\n    } else {\n      await supabase.from(\"products\").insert([payload]);\n    }\n    setModalOpen(false);\n    fetchData();\n  };\n\n  const handleDeleteProduct = async (id: string) => {\n    if (!supabase) return;\n    await supabase.from(\"products\").delete().eq(\"id\", id);\n    fetchData();\n  };\n\n  const toggleReviewApproval = async (review: any) => {\n    if (!supabase) return;\n    await supabase.from(\"reviews\").update({ approved: !review.approved }).eq(\"id\", review.id);\n    fetchData();\n  };\n\n  const handleDeleteReview = async (id: string) => {\n    if (!supabase) return;\n    await supabase.from(\"reviews\").delete().eq(\"id\", id);\n    fetchData();\n  };\n\n  const handleSettingsChange = (section: string, field: string, value: any) => {\n    setSettings((prev: any) => ({\n      ...prev,\n      [section]: { ...prev[section], [field]: value },\n    }));\n  };\n\n  const handleSettingsSave = async () => {\n    if (!supabase) return;\n    const { error } = await supabase.from(\"site_settings\").upsert({ id: 1, ...settings });\n    if (!error) {\n      await revalidateHome();\n      alert(\"Settings saved. The main site will now show your changes.\");\n    } else {\n      alert(`Error: ${error.message} (Code: ${error.code || \"none\"})`);\n    }\n  };\n\n  if (loading) {\n    return (\n      <div className=\"flex h-64 items-center justify-center\">\n        <p className=\"text-sm text-neutral-500\">Loading…</p>\n      </div>\n    );\n  }\n\n  if (!supabase) {\n    return (\n      <div className=\"flex h-64 items-center justify-center\">\n        <p className=\"text-sm text-neutral-500\">Database not connected.</p>\n      </div>\n    );\n  }\n\n  return (\n    <div className=\"space-y-8\">\n      {/* Tab navigation */}\n      <div className=\"border-b border-neutral-200 pb-4\">\n        <div className=\"flex gap-8 text-[11px] uppercase font-medium tracking-[0.2em] text-neutral-400\">\n          <button\n            onClick={() => setActiveTab(\"products\")}\n            className={`${activeTab === \"products\" ? \"text-black border-b border-black pb-1 -mb-1\" : \"hover:text-black\"} transition`}\n          >\n            Products\n          </button>\n          <button\n            onClick={() => setActiveTab(\"reviews\")}\n            className={`${activeTab === \"reviews\" ? \"text-black border-b border-black pb-1 -mb-1\" : \"hover:text-black\"} transition`}\n          >\n            Reviews\n          </button>\n          <button\n            onClick={() => setActiveTab(\"settings\")}\n            className={`${activeTab === \"settings\" ? \"text-black border-b border-black pb-1 -mb-1\" : \"hover:text-black\"} transition`}\n          >\n            Settings\n          </button>\n          <button\n            onClick={() => setActiveTab(\"admins\")}\n            className={`${activeTab === \"admins\" ? \"text-black border-b border-black pb-1 -mb-1\" : \"hover:text-black\"} transition`}\n          >\n            Admins\n          </button>\n        </div>\n      </div>\n\n      {/* Products tab – now uses AdminProductCard with image arrows */}\n      {activeTab === \"products\" && (\n        <div className=\"space-y-8\">\n          <div className=\"flex flex-col sm:flex-row sm:items-center justify-between gap-4\">\n            <h2 className=\"font-serif text-xl font-medium tracking-wide\">Products</h2>\n            <button\n              onClick={openAddModal}\n              className=\"inline-flex items-center gap-2 bg-black text-white text-[11px] uppercase tracking-[0.15em] font-medium px-5 py-3 hover:bg-neutral-800 transition rounded-sm\"\n            >\n              <Plus className=\"w-3.5 h-3.5\" /> Add New Product\n            </button>\n          </div>\n          {products.length === 0 ? (\n            <div className=\"text-center py-20 text-neutral-400 text-sm\">No products yet.</div>\n          ) : (\n            <div className=\"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6\">\n              {products.map((product) => (\n                <AdminProductCard\n                  key={product.id}\n                  product={product}\n                  onEdit={openEditModal}\n                  onDelete={handleDeleteProduct}\n                />\n              ))}\n            </div>\n          )}\n        </div>\n      )}\n\n      {/* Reviews tab */}\n      {activeTab === \"reviews\" && (\n        <div className=\"space-y-8\">\n          <h2 className=\"font-serif text-xl font-medium tracking-wide\">Client Reviews</h2>\n          {reviews.length === 0 ? (\n            <div className=\"text-center py-20 text-neutral-400 text-sm\">No reviews yet.</div>\n          ) : (\n            <div className=\"space-y-4 max-w-4xl\">\n              {reviews.map((review) => (\n                <div key={review.id} className=\"bg-white border border-neutral-100 p-5 rounded-sm flex flex-col md:flex-row md:items-center justify-between gap-4 hover:border-neutral-200 transition\">\n                  <div className=\"space-y-2\">\n                    <div className=\"flex items-center gap-3\">\n                      <span className=\"text-[12px] font-medium text-neutral-900\">{review.author || \"Anonymous\"}</span>\n                      <div className=\"flex text-yellow-500 gap-0.5\">\n                        {Array.from({ length: 5 }, (_, i) => (\n                          <Star key={i} className={`w-3 h-3 ${i < review.rating ? \"fill-current stroke-none\" : \"stroke-[1.5] fill-none\"}`} />\n                        ))}\n                      </div>\n                      <span className=\"text-[10px] text-neutral-400 font-mono\">on {review.product_id || \"product\"}</span>\n                    </div>\n                    <p className=\"text-[12px] text-neutral-600 font-light leading-relaxed\">{review.comment}</p>\n                  </div>\n                  <div className=\"flex items-center gap-4 self-end md:self-center\">\n                    <span className={`text-[10px] uppercase font-medium tracking-widest px-2 py-1 rounded-sm ${review.approved ? \"text-emerald-600 bg-emerald-50\" : \"text-neutral-400 bg-neutral-50\"}`}>\n                      {review.approved ? \"Showing\" : \"Hidden\"}\n                    </span>\n                    <button\n                      onClick={() => toggleReviewApproval(review)}\n                      className={`text-[11px] uppercase tracking-wider font-medium px-3 py-1.5 rounded-sm transition-colors ${review.approved ? \"text-neutral-400 hover:text-black border border-neutral-200 bg-white\" : \"text-white bg-black hover:bg-neutral-800\"}`}\n                    >\n                      {review.approved ? \"Hide\" : \"Show on site\"}\n                    </button>\n                    <button onClick={() => handleDeleteReview(review.id)} className=\"text-neutral-400 hover:text-red-600 transition-colors p-1\" title=\"Delete review\">\n                      <X className=\"w-4 h-4\" />\n                    </button>\n                  </div>\n                </div>\n              ))}\n            </div>\n          )}\n        </div>\n      )}\n\n      {/* Settings tab – Full Customization (unchanged) */}\n      {activeTab === \"settings\" && (\n        <div className=\"space-y-8\">\n          <h2 className=\"font-serif text-xl font-medium tracking-wide\">Site Customization</h2>\n\n          <div className=\"max-w-2xl bg-white border border-neutral-100 p-6 lg:p-8 rounded-sm space-y-8\">\n            {/* Business Identity */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">Business Identity</h3>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Storefront Name</label>\n                <input\n                  type=\"text\"\n                  value={settings.name}\n                  onChange={(e) => setSettings({ ...settings, name: e.target.value })}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Tagline / Motto</label>\n                <textarea\n                  rows={2}\n                  value={settings.tagline}\n                  onChange={(e) => setSettings({ ...settings, tagline: e.target.value })}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light resize-none\"\n                />\n              </div>\n            </div>\n\n            {/* Hero Section */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">Hero Section</h3>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Title</label>\n                <input\n                  type=\"text\"\n                  value={settings.hero?.title || \"\"}\n                  onChange={(e) => handleSettingsChange(\"hero\", \"title\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Subtitle</label>\n                <input\n                  type=\"text\"\n                  value={settings.hero?.subtitle || \"\"}\n                  onChange={(e) => handleSettingsChange(\"hero\", \"subtitle\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"grid grid-cols-2 gap-4\">\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">CTA Text</label>\n                  <input\n                    type=\"text\"\n                    value={settings.hero?.cta || \"\"}\n                    onChange={(e) => handleSettingsChange(\"hero\", \"cta\", e.target.value)}\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">CTA Link</label>\n                  <input\n                    type=\"text\"\n                    value={settings.hero?.ctaLink || \"#products\"}\n                    onChange={(e) => handleSettingsChange(\"hero\", \"ctaLink\", e.target.value)}\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n              </div>\n            </div>\n\n            {/* About Section */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">About Section</h3>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Title</label>\n                <input\n                  type=\"text\"\n                  value={settings.about?.title || \"\"}\n                  onChange={(e) => handleSettingsChange(\"about\", \"title\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Content</label>\n                <textarea\n                  rows={4}\n                  value={settings.about?.content || \"\"}\n                  onChange={(e) => handleSettingsChange(\"about\", \"content\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light resize-none\"\n                />\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Image URL</label>\n                <input\n                  type=\"text\"\n                  value={settings.about?.image || \"\"}\n                  onChange={(e) => handleSettingsChange(\"about\", \"image\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n            </div>\n\n            {/* Contact */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">Contact</h3>\n              <div className=\"grid grid-cols-1 sm:grid-cols-3 gap-4\">\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Email</label>\n                  <input\n                    type=\"email\"\n                    value={settings.contact?.email || \"\"}\n                    onChange={(e) => handleSettingsChange(\"contact\", \"email\", e.target.value)}\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Phone</label>\n                  <input\n                    type=\"text\"\n                    value={settings.contact?.phone || \"\"}\n                    onChange={(e) => handleSettingsChange(\"contact\", \"phone\", e.target.value)}\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Address</label>\n                  <input\n                    type=\"text\"\n                    value={settings.contact?.address || \"\"}\n                    onChange={(e) => handleSettingsChange(\"contact\", \"address\", e.target.value)}\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n              </div>\n            </div>\n\n            {/* Chat Apps (for Book Now) */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">Chat Links (for “Book Now”)</h3>\n              <div className=\"grid grid-cols-1 sm:grid-cols-2 gap-4\">\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">WhatsApp Number</label>\n                  <input\n                    type=\"text\"\n                    value={settings.chat?.whatsapp || \"\"}\n                    onChange={(e) => handleSettingsChange(\"chat\", \"whatsapp\", e.target.value)}\n                    placeholder=\"+15551234567\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Telegram Username</label>\n                  <input\n                    type=\"text\"\n                    value={settings.chat?.telegram || \"\"}\n                    onChange={(e) => handleSettingsChange(\"chat\", \"telegram\", e.target.value)}\n                    placeholder=\"@username\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Discord Server Invite</label>\n                  <input\n                    type=\"text\"\n                    value={settings.chat?.discord || \"\"}\n                    onChange={(e) => handleSettingsChange(\"chat\", \"discord\", e.target.value)}\n                    placeholder=\"https://discord.gg/...\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Viber Number</label>\n                  <input\n                    type=\"text\"\n                    value={settings.chat?.viber || \"\"}\n                    onChange={(e) => handleSettingsChange(\"chat\", \"viber\", e.target.value)}\n                    placeholder=\"+15551234567\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Preferred Chat</label>\n                <select\n                  value={settings.preferred_chat || \"whatsapp\"}\n                  onChange={(e) => setSettings({ ...settings, preferred_chat: e.target.value })}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light appearance-none\"\n                >\n                  <option value=\"whatsapp\">WhatsApp</option>\n                  <option value=\"telegram\">Telegram</option>\n                  <option value=\"discord\">Discord</option>\n                  <option value=\"viber\">Viber</option>\n                </select>\n              </div>\n            </div>\n\n            {/* Footer & Social */}\n            <div className=\"space-y-4\">\n              <h3 className=\"text-sm font-semibold uppercase tracking-widest text-neutral-400\">Footer & Social Links</h3>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Copyright</label>\n                <input\n                  type=\"text\"\n                  value={settings.footer?.copyright || \"\"}\n                  onChange={(e) => handleSettingsChange(\"footer\", \"copyright\", e.target.value)}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"grid grid-cols-2 gap-4\">\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Instagram URL</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.instagram || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, instagram: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Facebook URL</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.facebook || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, facebook: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">X (Twitter) URL</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.x || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, x: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">YouTube URL</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.youtube || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, youtube: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">WhatsApp Channel</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.whatsapp_channel || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, whatsapp_channel: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Telegram Channel</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.telegram_channel || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, telegram_channel: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Discord Channel</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.discord_channel || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, discord_channel: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[11px] uppercase tracking-widest text-neutral-500 font-medium\">Viber Channel</label>\n                  <input\n                    type=\"text\"\n                    value={settings.footer?.socials?.viber_channel || \"\"}\n                    onChange={(e) =>\n                      setSettings((prev: any) => ({\n                        ...prev,\n                        footer: { ...prev.footer, socials: { ...prev.footer?.socials, viber_channel: e.target.value } },\n                      }))\n                    }\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] tracking-wide px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n              </div>\n            </div>\n\n            <div className=\"pt-4 border-t border-neutral-100 flex justify-end\">\n              <button\n                onClick={handleSettingsSave}\n                className=\"bg-black text-white text-[11px] uppercase tracking-[0.15em] font-medium px-6 py-3.5 hover:bg-neutral-800 transition-all rounded-sm\"\n              >\n                Save All Settings\n              </button>\n            </div>\n          </div>\n        </div>\n      )}\n\n      {/* Admins tab */}\n      {activeTab === \"admins\" && (\n        <div className=\"space-y-8\">\n          <h2 className=\"font-serif text-xl font-medium tracking-wide\">Admin Management</h2>\n          <AdminPanel />\n        </div>\n      )}\n\n      {/* Product modal – unchanged */}\n      {modalOpen && (\n        <div className=\"fixed inset-0 z-50 bg-black/40 backdrop-blur-sm flex items-center justify-center p-4\">\n          <div className=\"bg-white max-w-lg w-full rounded-sm border border-neutral-200 shadow-xl\">\n            <div className=\"p-6 border-b border-neutral-100 flex items-center justify-between\">\n              <h3 className=\"font-serif text-[15px] font-medium tracking-wider uppercase\">\n                {editingProduct ? \"Edit Product\" : \"New Product Manifest\"}\n              </h3>\n              <button onClick={() => setModalOpen(false)} className=\"text-neutral-400 hover:text-black\">\n                <X className=\"w-4 h-4\" />\n              </button>\n            </div>\n            <div className=\"p-6 space-y-4 max-h-[70vh] overflow-y-auto\">\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium\">Title</label>\n                <input\n                  type=\"text\"\n                  value={form.name}\n                  onChange={(e) => setForm({ ...form, name: e.target.value })}\n                  placeholder=\"e.g. N°02 Alabaster Candle\"\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n              <div className=\"grid grid-cols-2 gap-4\">\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium\">Price (USD)</label>\n                  <input\n                    type=\"number\"\n                    step=\"0.01\"\n                    value={form.price}\n                    onChange={(e) => setForm({ ...form, price: e.target.value })}\n                    placeholder=\"180\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n                <div className=\"space-y-1.5\">\n                  <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium\">Badge</label>\n                  <input\n                    type=\"text\"\n                    value={form.badge}\n                    onChange={(e) => setForm({ ...form, badge: e.target.value })}\n                    placeholder=\"e.g. Limited\"\n                    className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                  />\n                </div>\n              </div>\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium\">Description</label>\n                <input\n                  type=\"text\"\n                  value={form.description}\n                  onChange={(e) => setForm({ ...form, description: e.target.value })}\n                  placeholder=\"e.g. Soy Wax / 220g\"\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                />\n              </div>\n\n              <div>\n                <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium mb-2 block\">\n                  Images (first is primary)\n                </label>\n                <div className=\"space-y-2\">\n                  {imageList.map((url, idx) => (\n                    <div key={idx} className=\"flex gap-2 items-center\">\n                      <input\n                        type=\"text\"\n                        value={url}\n                        onChange={(e) => handleImageChange(idx, e.target.value)}\n                        placeholder=\"https://...\"\n                        className=\"flex-1 bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light\"\n                      />\n                      {imageList.length > 1 && (\n                        <button\n                          type=\"button\"\n                          onClick={() => removeImageField(idx)}\n                          className=\"text-neutral-400 hover:text-red-500 transition p-1\"\n                        >\n                          <Trash2 className=\"w-4 h-4\" />\n                        </button>\n                      )}\n                    </div>\n                  ))}\n                </div>\n                <button\n                  type=\"button\"\n                  onClick={addImageField}\n                  className=\"mt-2 inline-flex items-center gap-1 text-[10px] uppercase tracking-wider text-neutral-500 hover:text-black transition font-medium\"\n                >\n                  <Plus className=\"w-3.5 h-3.5\" /> Add Image URL\n                </button>\n              </div>\n\n              <div className=\"space-y-1.5\">\n                <label className=\"text-[10px] uppercase tracking-widest text-neutral-400 font-medium\">Icon</label>\n                <select\n                  value={form.icon}\n                  onChange={(e) => setForm({ ...form, icon: e.target.value })}\n                  className=\"w-full bg-[#f4f4f4] border border-transparent text-[12px] px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300 transition-all font-light appearance-none\"\n                >\n                  <option value=\"sparkles\">Sparkles</option>\n                  <option value=\"wallet\">Wallet</option>\n                  <option value=\"glasses\">Glasses</option>\n                  <option value=\"watch\">Watch</option>\n                </select>\n              </div>\n            </div>\n            <div className=\"p-6 bg-[#fafafa] border-t border-neutral-100 flex justify-end gap-3\">\n              <button\n                onClick={() => setModalOpen(false)}\n                className=\"text-[11px] uppercase tracking-wider font-medium text-neutral-500 hover:text-black px-4 py-2.5 transition-colors\"\n              >\n                Cancel\n              </button>\n              <button\n                onClick={handleProductSubmit}\n                className=\"bg-black text-white text-[11px] uppercase tracking-[0.15em] font-medium px-5 py-2.5 hover:bg-neutral-800 transition-all rounded-sm\"\n              >\n                {editingProduct ? \"Update Item\" : \"Add Item\"}\n              </button>\n            </div>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n\n// ------------------- Admin Panel Component (unchanged) -------------------\nfunction AdminPanel() {\n  const [admins, setAdmins] = useState<any[]>([]);\n  const [loading, setLoading] = useState(true);\n  const [email, setEmail] = useState(\"\");\n  const [error, setError] = useState(\"\");\n  const [isFirstAdmin, setIsFirstAdmin] = useState(false);\n  const [currentUserId, setCurrentUserId] = useState<string | null>(null);\n\n  useEffect(() => {\n    if (!supabase) return;\n    fetchAdmins();\n  }, []);\n\n  const fetchAdmins = async () => {\n    try {\n      const res = await fetch(\"/api/admin/admins\");\n      if (!res.ok) throw new Error(\"API failed\");\n\n      const data = await res.json();\n      const adminsArray = Array.isArray(data) ? data : data.admins || [];\n      const currentId = data.currentUserId;\n      const firstAdminFlag = data.isFirstAdmin ?? false;\n\n      setAdmins(adminsArray);\n      setCurrentUserId(currentId);\n      setIsFirstAdmin(firstAdminFlag);\n    } catch (error) {\n      console.error(\"Failed to fetch admins:\", error);\n      setAdmins([]);\n      setCurrentUserId(null);\n      setIsFirstAdmin(false);\n    }\n    setLoading(false);\n  };\n\n  const handlePromote = async (e: React.FormEvent) => {\n    e.preventDefault();\n    setError(\"\");\n    const res = await fetch(\"/api/admin/admins\", {\n      method: \"POST\",\n      headers: { \"Content-Type\": \"application/json\" },\n      body: JSON.stringify({ email }),\n    });\n    if (res.ok) {\n      setEmail(\"\");\n      fetchAdmins();\n    } else {\n      const data = await res.json();\n      setError(data.error || \"Promotion failed\");\n    }\n  };\n\n  const handleDemote = async (userId: string) => {\n    const res = await fetch(`/api/admin/admins/${userId}`, {\n      method: \"DELETE\",\n    });\n    if (res.ok) {\n      fetchAdmins();\n    } else {\n      const data = await res.json();\n      alert(data.error || \"Demotion failed\");\n    }\n  };\n\n  if (loading) return <p className=\"text-sm text-neutral-500\">Loading...</p>;\n\n  return (\n    <div className=\"space-y-6 max-w-2xl\">\n      {isFirstAdmin && (\n        <form onSubmit={handlePromote} className=\"flex gap-4 items-end\">\n          <div className=\"flex-1\">\n            <label className=\"block text-xs uppercase tracking-widest text-neutral-500 mb-1\">\n              Email of user to promote\n            </label>\n            <input\n              type=\"email\"\n              value={email}\n              onChange={(e) => setEmail(e.target.value)}\n              required\n              className=\"w-full bg-[#f4f4f4] border border-transparent text-sm px-4 py-3 rounded-sm focus:outline-none focus:border-neutral-300\"\n              placeholder=\"user@example.com\"\n            />\n          </div>\n          <button\n            type=\"submit\"\n            className=\"bg-black text-white text-xs uppercase tracking-wider px-5 py-3 rounded-sm hover:bg-neutral-800 transition\"\n          >\n            Promote\n          </button>\n        </form>\n      )}\n      {error && <p className=\"text-red-500 text-xs\">{error}</p>}\n\n      <div className=\"bg-white border border-neutral-100 rounded-sm divide-y divide-neutral-100\">\n        {admins.length === 0 && !loading && (\n          <div className=\"p-6 text-center text-sm text-neutral-400\">No admins found.</div>\n        )}\n        {admins.map((admin: any) => (\n          <div key={admin.user_id} className=\"flex items-center justify-between p-4\">\n            <div>\n              <p className=\"text-sm font-medium\">\n                {admin.profiles?.full_name || \"No name\"}\n              </p>\n              <p className=\"text-xs text-neutral-500\">{admin.user_id}</p>\n            </div>\n            {isFirstAdmin && admin.user_id !== currentUserId && (\n              <button\n                onClick={() => handleDemote(admin.user_id)}\n                className=\"text-xs text-red-500 hover:text-red-700\"\n              >\n                Remove\n              </button>\n            )}\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}"}