import { jsxs, jsx } from "react/jsx-runtime";
import { Link } from "@tanstack/react-router";
import { useState, useEffect } from "react";
import { s as supabase } from "./client-Dz5aErML.js";
import { u as useSiteSettings } from "./useSiteSettings-7O51JHh5.js";
import "@supabase/supabase-js";
function AdminSettings() {
  const {
    settings,
    loading,
    refetch
  } = useSiteSettings();
  const [waNumber, setWaNumber] = useState("");
  const [waNumber2, setWaNumber2] = useState("");
  const [igUrl, setIgUrl] = useState("");
  const [tiktokUrl, setTiktokUrl] = useState("");
  const [waChannelUrl, setWaChannelUrl] = useState("");
  const [saving, setSaving] = useState(false);
  const [msg, setMsg] = useState(null);
  useEffect(() => {
    if (!loading) {
      setWaNumber(settings.whatsappNumber);
      setWaNumber2(settings.whatsappNumber2);
      setIgUrl(settings.instagramUrl);
      setTiktokUrl(settings.tiktokUrl);
      setWaChannelUrl(settings.whatsappChannelUrl);
    }
  }, [loading, settings.whatsappNumber, settings.whatsappNumber2, settings.instagramUrl, settings.tiktokUrl, settings.whatsappChannelUrl]);
  const handleSave = async (e) => {
    e.preventDefault();
    setSaving(true);
    setMsg(null);
    const cleanWa = waNumber.replace(/[^0-9]/g, "");
    const cleanWa2 = waNumber2.replace(/[^0-9]/g, "");
    const {
      error
    } = await supabase.from("site_settings").update({
      whatsapp_number: cleanWa,
      whatsapp_number_2: cleanWa2,
      instagram_url: igUrl.trim(),
      tiktok_url: tiktokUrl.trim(),
      whatsapp_channel_url: waChannelUrl.trim()
    }).eq("id", true);
    setSaving(false);
    if (error) {
      setMsg("Gagal menyimpan: " + error.message);
    } else {
      setMsg("Tersimpan! Perubahan langsung muncul di website.");
      refetch();
    }
  };
  return /* @__PURE__ */ jsxs("div", { className: "max-w-2xl", children: [
    /* @__PURE__ */ jsx(Link, { to: "/adminpergam", className: "text-xs text-muted-foreground hover:text-foreground", children: "← Kembali" }),
    /* @__PURE__ */ jsx("h1", { className: "font-display text-3xl font-bold mt-2 mb-2", children: "Pengaturan Kontak" }),
    /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mb-6", children: "Nomor WhatsApp (Stock & Rental) dan Instagram di sini akan digunakan di seluruh website utama (kecuali kategori Partner Resmi & Paid Promote yang punya nomor sendiri per produk). Perubahan tampil real-time." }),
    /* @__PURE__ */ jsxs("form", { onSubmit: handleSave, className: "card-surface rounded-2xl p-6 space-y-5", children: [
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2", children: "Wa Khusus Stock" }),
        /* @__PURE__ */ jsx("input", { type: "text", value: waNumber, onChange: (e) => setWaNumber(e.target.value.replace(/[^0-9]/g, "")), placeholder: "6282312715218", className: "w-full px-4 py-3 rounded-xl bg-card border border-border focus:border-primary focus:ring-2 focus:ring-primary/40 outline-none transition-all text-sm" }),
        /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-1.5", children: 'Format internasional tanpa "+" atau spasi. Contoh: 6282312715218' })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2", children: "Wa Khusus Rental (Opsional)" }),
        /* @__PURE__ */ jsx("input", { type: "text", value: waNumber2, onChange: (e) => setWaNumber2(e.target.value.replace(/[^0-9]/g, "")), placeholder: "62812xxxxxxx", className: "w-full px-4 py-3 rounded-xl bg-card border border-border focus:border-primary focus:ring-2 focus:ring-primary/40 outline-none transition-all text-sm" }),
        /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-1.5", children: "Digunakan untuk CTA WhatsApp khusus Rental di bagian Kontak. Kosongkan untuk menyembunyikan." })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2", children: "URL Instagram" }),
        /* @__PURE__ */ jsx("input", { type: "url", value: igUrl, onChange: (e) => setIgUrl(e.target.value), placeholder: "https://instagram.com/username", className: "w-full px-4 py-3 rounded-xl bg-card border border-border focus:border-primary focus:ring-2 focus:ring-primary/40 outline-none transition-all text-sm" }),
        /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-1.5", children: "Link lengkap profil Instagram." })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2", children: "URL TikTok (Opsional)" }),
        /* @__PURE__ */ jsx("input", { type: "url", value: tiktokUrl, onChange: (e) => setTiktokUrl(e.target.value), placeholder: "https://tiktok.com/@username", className: "w-full px-4 py-3 rounded-xl bg-card border border-border focus:border-primary focus:ring-2 focus:ring-primary/40 outline-none transition-all text-sm" }),
        /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-1.5", children: "Kosongkan jika tidak ingin menampilkan CTA TikTok." })
      ] }),
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2", children: "URL Saluran WhatsApp (Opsional)" }),
        /* @__PURE__ */ jsx("input", { type: "url", value: waChannelUrl, onChange: (e) => setWaChannelUrl(e.target.value), placeholder: "https://whatsapp.com/channel/...", className: "w-full px-4 py-3 rounded-xl bg-card border border-border focus:border-primary focus:ring-2 focus:ring-primary/40 outline-none transition-all text-sm" }),
        /* @__PURE__ */ jsx("p", { className: "text-[11px] text-muted-foreground mt-1.5", children: "Kosongkan jika tidak ingin menampilkan CTA Saluran WhatsApp." })
      ] }),
      msg && /* @__PURE__ */ jsx("div", { className: "text-xs px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-foreground", children: msg }),
      /* @__PURE__ */ jsx("button", { type: "submit", disabled: saving || loading, className: "px-6 py-3 rounded-full bg-primary text-primary-foreground text-sm font-semibold glow-purple-sm hover:-translate-y-0.5 transition disabled:opacity-50", children: saving ? "Menyimpan..." : "Simpan Perubahan" })
    ] })
  ] });
}
export {
  AdminSettings as component
};
