import{j as e,r,m as v,t as a,s as x}from"./index-C-9v46qO.js";import{u as N}from"./useSuspenseQuery-BEvSCKBz.js";import{e as y,c as k}from"./format-A5vAYKc-.js";import{C as o}from"./card-Bnq45TwS.js";import{I as f}from"./input-Dr7-mDl9.js";import{B as p}from"./button-B-2orO_-.js";import{T as b}from"./trash-2-C76Z0d0f.js";import"./utils-BQHNewu7.js";import"./createLucideIcon-PnqOq2iY.js";function I(){return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold mb-4",children:"ব্ল্যাকলিস্ট"}),e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"text-muted-foreground",children:"লোড হচ্ছে..."}),children:e.jsx(C,{})})]})}function C(){const{data:i}=N(y()),l=v(),[n,c]=r.useState(""),[m,d]=r.useState(""),[h,u]=r.useState(!1),j=async s=>{if(s.preventDefault(),!/^\+?[0-9]{10,15}$/.test(n)){a.error("সঠিক ফোন নাম্বার দিন");return}u(!0);const{error:t}=await x.from("blacklisted_phones").insert({phone:n,reason:m||null});if(u(!1),t){a.error(t.message);return}c(""),d(""),a.success("ব্ল্যাকলিস্টে যোগ হয়েছে"),l.invalidateQueries({queryKey:["admin","blacklist"]})},g=async s=>{if(!confirm("ব্ল্যাকলিস্ট থেকে সরাবেন?"))return;const{error:t}=await x.from("blacklisted_phones").delete().eq("id",s);if(t){a.error(t.message);return}a.success("সরানো হয়েছে"),l.invalidateQueries({queryKey:["admin","blacklist"]})};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(o,{className:"p-4",children:e.jsxs("form",{onSubmit:j,className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(f,{placeholder:"ফোন নাম্বার",value:n,onChange:s=>c(s.target.value),className:"sm:w-48"}),e.jsx(f,{placeholder:"কারণ (ঐচ্ছিক)",value:m,onChange:s=>d(s.target.value),className:"flex-1"}),e.jsx(p,{type:"submit",disabled:h,children:"যোগ করুন"})]})}),e.jsxs("div",{className:"grid gap-2",children:[i.length===0&&e.jsx(o,{className:"p-6 text-center text-muted-foreground",children:"ব্ল্যাকলিস্ট খালি"}),i.map(s=>e.jsxs(o,{className:"p-3 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-mono font-medium",children:s.phone}),s.reason&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.reason}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:k(s.created_at)})]}),e.jsx(p,{size:"icon",variant:"ghost",onClick:()=>g(s.id),children:e.jsx(b,{className:"h-4 w-4 text-destructive"})})]},s.id))]})]})}export{I as component};
