import{r as l,j as e,R as g,aO as f,aN as u,m as N,X as b,b2 as v}from"./vendor-DyCecx-5.js";import{a as r}from"./admin.service-BOkBJ3gu.js";import{u as y}from"./index-BFnDPF9i.js";const P=()=>{const{showToast:a}=y(),[d,x]=l.useState([]),[i,m]=l.useState([]),[h,o]=l.useState(!0),c=async()=>{o(!0);try{const[s,t]=await Promise.all([r.getPendingFranchises(),r.getAllFranchises()]);s.success&&x(s.data),t.success&&m(t.data)}catch{a("Failed to load franchise data","error")}finally{o(!1)}};l.useEffect(()=>{c()},[]);const p=async s=>{try{const t=await r.approveFranchise(s);t.success?(a("Franchise approved successfully","success"),c()):a(t.message||"Failed to approve","error")}catch{a("Something went wrong","error")}},j=async s=>{const t=prompt("Enter rejection reason:");if(t)try{const n=await r.rejectFranchise(s,t);n.success?(a("Franchise rejected","success"),c()):a(n.message||"Failed to reject","error")}catch{a("Something went wrong","error")}};return h?e.jsx("div",{className:"p-8 text-center text-slate-500",children:"Loading franchise data..."}):e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-black text-slate-900 tracking-tight",children:"Franchise Management"}),e.jsx("p",{className:"text-slate-500 mt-2 font-medium",children:"Approve and manage franchise partners"})]}),d.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500"}),"Pending Approvals"]}),e.jsx("div",{className:"grid grid-cols-1 gap-4",children:d.map(s=>e.jsxs("div",{className:"bg-white p-6 rounded border border-amber-100 shadow-sm flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-3 bg-amber-50 rounded text-amber-600",children:e.jsx(g,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900 text-lg",children:s.name}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-1 text-sm text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(f,{className:"w-4 h-4"})," ",s.email]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(u,{className:"w-4 h-4"})," ",s.phone]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(N,{className:"w-4 h-4"})," ",s.territory]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 w-full md:w-auto",children:[e.jsxs("button",{onClick:()=>j(s.id),className:"flex-1 md:flex-none px-4 py-2 text-rose-600 bg-rose-50 hover:bg-rose-100 rounded font-bold text-sm transition-colors flex items-center justify-center gap-2",children:[e.jsx(b,{className:"w-4 h-4"})," Reject"]}),e.jsxs("button",{onClick:()=>p(s.id),className:"flex-1 md:flex-none px-6 py-2 bg-slate-900 text-white hover:bg-slate-800 rounded font-bold text-sm transition-colors flex items-center justify-center gap-2",children:[e.jsx(v,{className:"w-4 h-4"})," Approve"]})]})]},s.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500"}),"Active Franchises"]}),i.length===0?e.jsx("div",{className:"bg-slate-50 p-8 rounded text-center text-slate-500 border border-dashed border-slate-200",children:"No active franchises found."}):e.jsx("div",{className:"bg-white rounded border border-slate-200 shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-100",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4 font-bold text-slate-700",children:"Name"}),e.jsx("th",{className:"px-6 py-4 font-bold text-slate-700",children:"Contact"}),e.jsx("th",{className:"px-6 py-4 font-bold text-slate-700",children:"Territory"}),e.jsx("th",{className:"px-6 py-4 font-bold text-slate-700",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:i.map(s=>e.jsxs("tr",{className:"hover:bg-slate-50/50",children:[e.jsx("td",{className:"px-6 py-4 font-medium text-slate-900",children:s.name}),e.jsx("td",{className:"px-6 py-4 text-slate-500",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.email}),e.jsx("span",{className:"text-xs text-slate-400",children:s.phone})]})}),e.jsx("td",{className:"px-6 py-4 text-slate-500 max-w-xs truncate",children:s.territory}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${s.status==="APPROVED"?"bg-emerald-100 text-emerald-700":s.status==="REJECTED"?"bg-rose-100 text-rose-700":"bg-amber-100 text-amber-700"}`,children:s.status||"PENDING"})})]},s.id))})]})})]})]})};export{P as default};
