import { U as jsxRuntimeExports, r as reactExports } from "./worker-entry-Xz__m-MI.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CUxLKZvE.js";
import { i as useQueryClient, t as toast, s as supabase } from "./router-CHpUX3w1.js";
import { e as blacklistQueryOptions, c as formatDateTime } from "./format-BJ9Pc8X9.js";
import { C as Card } from "./card-Cu-N09iC.js";
import { I as Input } from "./input-79qqvIMV.js";
import { B as Button } from "./button-DpKP5ewx.js";
import { T as Trash2 } from "./trash-2-BYAqX1Cv.js";
import "node:events";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./utils-Bz4m9VPB.js";
import "./createLucideIcon-4cZKQB6y.js";
function BlacklistPage() {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-2xl font-semibold mb-4", children: "ব্ল্যাকলিস্ট" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-muted-foreground", children: "লোড হচ্ছে..." }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(BlacklistContent, {}) })
  ] });
}
function BlacklistContent() {
  const {
    data
  } = useSuspenseQuery(blacklistQueryOptions());
  const qc = useQueryClient();
  const [phone, setPhone] = reactExports.useState("");
  const [reason, setReason] = reactExports.useState("");
  const [adding, setAdding] = reactExports.useState(false);
  const add = async (e) => {
    e.preventDefault();
    if (!/^\+?[0-9]{10,15}$/.test(phone)) {
      toast.error("সঠিক ফোন নাম্বার দিন");
      return;
    }
    setAdding(true);
    const {
      error
    } = await supabase.from("blacklisted_phones").insert({
      phone,
      reason: reason || null
    });
    setAdding(false);
    if (error) {
      toast.error(error.message);
      return;
    }
    setPhone("");
    setReason("");
    toast.success("ব্ল্যাকলিস্টে যোগ হয়েছে");
    qc.invalidateQueries({
      queryKey: ["admin", "blacklist"]
    });
  };
  const remove = async (id) => {
    if (!confirm("ব্ল্যাকলিস্ট থেকে সরাবেন?")) return;
    const {
      error
    } = await supabase.from("blacklisted_phones").delete().eq("id", id);
    if (error) {
      toast.error(error.message);
      return;
    }
    toast.success("সরানো হয়েছে");
    qc.invalidateQueries({
      queryKey: ["admin", "blacklist"]
    });
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Card, { className: "p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: add, className: "flex flex-col sm:flex-row gap-2", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: "ফোন নাম্বার", value: phone, onChange: (e) => setPhone(e.target.value), className: "sm:w-48" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: "কারণ (ঐচ্ছিক)", value: reason, onChange: (e) => setReason(e.target.value), className: "flex-1" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", disabled: adding, children: "যোগ করুন" })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid gap-2", children: [
      data.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Card, { className: "p-6 text-center text-muted-foreground", children: "ব্ল্যাকলিস্ট খালি" }),
      data.map((b) => /* @__PURE__ */ jsxRuntimeExports.jsxs(Card, { className: "p-3 flex items-center gap-3", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono font-medium", children: b.phone }),
          b.reason && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground", children: b.reason }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] text-muted-foreground", children: formatDateTime(b.created_at) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "icon", variant: "ghost", onClick: () => remove(b.id), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, { className: "h-4 w-4 text-destructive" }) })
      ] }, b.id))
    ] })
  ] });
}
export {
  BlacklistPage as component
};
