1import{r as o,s as y,j as e,ch as se,a2 as we,bm as H,n as G,d as U,aq as B,ax as je,Y as k,m as Z,aK as W,ao as Se,v as V,aM as _e,bs as oe,a4 as te,z as M,l as D,e as I,ci as Ce,au as ke,aC as ce,cg as Ae,X as K,aU as ze,aY as re,ar as Re,cj as ye,f as Ne,a3 as Ee,L as Y,av as ae,a8 as Le,b_ as q,an as Te,N as Fe,aH as $e,A as De,ck as xe,$ as me,cl as Oe,R as Pe,F as ue}from"./index-D6t_VXza.js";import{P as Me}from"./percent-pOYTZfaN.js";const Be={"BEL-HQ":"from-[#800020] to-[#5C0017]","REN-01":"from-[#800020] to-[#6B001A]","SEA-01":"from-[#800020] to-[#5C0017]"},Q={"BEL-HQ":{bg:"bg-blue-500",text:"text-blue-700",ring:"ring-blue-200",light:"bg-blue-50"},"REN-01":{bg:"bg-emerald-500",text:"text-emerald-700",ring:"ring-emerald-200",light:"bg-emerald-50"},"SEA-01":{bg:"bg-purple-500",text:"text-purple-700",ring:"ring-purple-200",light:"bg-purple-50"}},ge=()=>{const[u,S]=o.useState([]),[p,g]=o.useState([]),[z,h]=o.useState(!0),[i,N]=o.useState([]);o.useEffect(()=>{v()},[]);const v=async()=>{h(!0);const{data:s}=await y.from("z_franchise_tenants").select("*").eq("is_active",!0).order("is_hq",{ascending:!1});s&&S(s);const{data:n}=await y.from("z_franchise_royalties").select("*").order("period_start",{ascending:!1}).limit(10);n&&N(n);const f=(s||[]).map(x=>({code:x.code,name:x.name,city:x.city,manager:x.manager_name,isHQ:x.is_hq,students:x.is_hq?{active:42,graduated:156,total:198}:x.code==="REN-01"?{active:28,graduated:67,total:95}:{active:35,graduated:89,total:124},revenue:x.is_hq?{tuition:485e3,service:78e3,retail:42e3,total:605e3}:x.code==="REN-01"?{tuition:285e3,service:35e3,retail:2e4,total:34e4}:{tuition:342e3,service:45e3,retail:25e3,total:412e3},compliance:x.is_hq?{score:98,status:"excellent"}:x.code==="REN-01"?{score:94,status:"good"}:{score:96,status:"good"},inventory:x.is_hq?125e3:x.code==="REN-01"?68e3:82e3,posTransactions:x.is_hq?342:x.code==="REN-01"?187:256}));g(f),h(!1)},a=p.reduce((s,n)=>s+n.revenue.total,0),b=p.reduce((s,n)=>s+n.students.total,0),A=p.reduce((s,n)=>s+n.students.active,0),w=p.reduce((s,n)=>s+n.students.graduated,0),_=p.length>0?Math.round(p.reduce((s,n)=>s+n.compliance.score,0)/p.length):0,R=p.reduce((s,n)=>s+n.inventory,0),L=i.filter(s=>s.status==="invoiced").reduce((s,n)=>s+n.total_due,0),l=i.filter(s=>s.status==="paid"||s.status==="submitted_to_cpa").reduce((s,n)=>s+n.total_due,0);return z?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-3 border-gold border-t-transparent rounded-full"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gradient-to-r from-slate-900 via-slate-800 to-slate-900 rounded-2xl p-6 lg:p-8 text-white relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 right-0 w-96 h-96 bg-gold/5 rounded-full -translate-y-1/2 translate-x-1/3"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-64 h-64 bg-burgundy/10 rounded-full translate-y-1/2 -translate-x-1/4"}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(se,{size:16,className:"text-gold"}),e.jsx("span",{className:"text-xs font-bold text-gold uppercase tracking-widest",children:"CEO Global Command Center"})]}),e.jsx("h2",{className:"font-display text-2xl lg:text-3xl font-bold",children:"Consolidated Enterprise View"}),e.jsxs("p",{className:"text-white/60 text-sm mt-1",children:["Real-time intelligence across ",u.length," campuses â Bellingham, Renton & Seattle"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex -space-x-2",children:["BEL-HQ","REN-01","SEA-01"].map(s=>{var n;return e.jsx("div",{className:`w-10 h-10 rounded-full ${((n=Q[s])==null?void 0:n.bg)||"bg-gray-500"} flex items-center justify-center text-white text-xs font-bold ring-2 ring-slate-800`,children:s.split("-")[0]},s)})}),e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 bg-emerald-500/20 border border-emerald-400/30 rounded-full",children:[e.jsx(we,{size:12,className:"text-emerald-400"}),e.jsx("span",{className:"text-xs font-semibold text-emerald-300",children:"All Systems Live"})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-6 gap-3 mt-6",children:[{label:"Total Revenue",value:`$${(a/100).toLocaleStr
1ing(void 0,{maximumFractionDigits:0})}`,sub:"All locations YTD",icon:H,color:"text-gold"},{label:"Active Students",value:A.toString(),sub:`${w} graduated`,icon:G,color:"text-emerald-400"},{label:"Compliance Score",value:`${_}%`,sub:"NACCAS average",icon:U,color:"text-blue-400"},{label:"Inventory Value",value:`$${R.toLocaleString()}`,sub:"Across all locations",icon:B,color:"text-purple-400"},{label:"Royalties Due",value:`$${(L/100).toLocaleString(void 0,{maximumFractionDigits:0})}`,sub:"Outstanding invoices",icon:je,color:"text-amber-400"},{label:"Royalties Collected",value:`$${(l/100).toLocaleString(void 0,{maximumFractionDigits:0})}`,sub:"Paid + filed",icon:k,color:"text-emerald-400"}].map(s=>e.jsxs("div",{className:"bg-white/5 backdrop-blur-sm border border-white/10 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(s.icon,{size:13,className:s.color}),e.jsx("span",{className:"text-[10px] text-white/50 uppercase tracking-wider",children:s.label})]}),e.jsx("p",{className:"font-mono text-lg font-bold text-white",children:s.value}),e.jsx("p",{className:"text-[10px] text-white/40 mt-0.5",children:s.sub})]},s.label))})]})]}),e.jsx("div",{className:"grid lg:grid-cols-3 gap-5",children:p.map(s=>{const n=Q[s.code]||Q["BEL-HQ"],f=Be[s.code]||"from-gray-600 to-gray-700",x=a>0?(s.revenue.total/a*100).toFixed(1):"0",C=b>0?(s.students.total/b*100).toFixed(1):"0";return e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 overflow-hidden hover:shadow-xl transition-all duration-300 group",children:[e.jsxs("div",{className:`bg-gradient-to-r ${f} p-5 text-white relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-white/5 rounded-full -translate-y-1/2 translate-x-1/2"}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[s.isHQ&&e.jsx(se,{size:14,className:"text-gold"}),e.jsx("span",{className:"text-xs font-bold text-white/70 uppercase tracking-wider",children:s.isHQ?"Headquarters":"Branch Campus"})]}),e.jsx("span",{className:"text-xs font-mono bg-white/20 px-2 py-0.5 rounded-full",children:s.code})]}),e.jsx("h3",{className:"font-display text-xl font-bold",children:s.city}),e.jsxs("p",{className:"text-white/60 text-xs mt-1 flex items-center gap-1",children:[e.jsx(Z,{size:10})," Managed by ",s.manager]})]})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider",children:"Revenue"}),e.jsxs("span",{className:"text-xs font-mono text-gray-400",children:[x,"% of total"]})]}),e.jsxs("p",{className:"font-mono text-2xl font-bold text-gray-900",children:["$",s.revenue.total.toLocaleString()]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-2",children:[e.jsxs("div",{className:"text-center p-1.5 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-[10px] text-gray-400",children:"Tuition"}),e.jsxs("p",{className:"font-mono text-xs font-bold",children:["$",(s.revenue.tuition/1e3).toFixed(0),"k"]})]}),e.jsxs("div",{className:"text-center p-1.5 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-[10px] text-gray-400",children:"Services"}),e.jsxs("p",{className:"font-mono text-xs font-bold",children:["$",(s.revenue.service/1e3).toFixed(0),"k"]})]}),e.jsxs("div",{className:"text-center p-1.5 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-[10px] text-gray-400",children:"Retail"}),e.jsxs("p",{className:"font-mono text-xs font-bold",children:["$",(s.revenue.retail/1e3).toFixed(0),"k"]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-gray-100",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Enrollment"}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"font-mono text-lg font-bold text-gray-900",children:s.students.active}),e.jsx("span",{className:"text-xs text-gray-400",children:"active"}),e.jsx("span",{className:"text-gray-300",children:"|"}),e.jsx("span",{className:"font-mono text-sm font-semibold text-emerald-600",children:s.students.graduated}),e.jsx("span",{className:"text-xs text-gray-400",children:"grad"})]})]}),e.jsxs("div",{className:`px-2.5 py-1 rounded-full text-xs font-bold ${n.light} ${n.text}`,children:[C,"%"]})]}),e.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{size:16,className:s.compliance.score>=95?"text-emerald-500":s.compliance.score>=90?"text-amber-500":"text-red-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-400",children:"NACCAS Compliance"}),e.jsxs("p",{className:"font-mono text-sm font-bold",children:[s.compliance.score,"%"]})]})]}),e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold ${s.compliance.score>=95?"bg-emerald-50 text-emerald-700 border border-emerald-200":s.compliance.score>=90?"bg-amber-50 text-amber-700 border border-amber-200":"bg-red-50 text-red-700 border border-red-200"}`,children:s.compliance.status})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-2 border-t border-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-gray-50 rounded-lg",children:[e.jsx(B,{size:12,className:"text-gray-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-gray-400",children:"Inventory"}),e.jsxs("p",{className:"font-mono text-xs font-bold",children:["$",s.inventory.toLocaleStr
1ing()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-gray-50 rounded-lg",children:[e.jsx(W,{size:12,className:"text-gray-400"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-gray-400",children:"POS Txns"}),e.jsx("p",{className:"font-mono text-xs font-bold",children:s.posTransactions})]})]})]})]})]},s.code)})}),e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 p-6",children:[e.jsxs("h3",{className:"font-display text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(W,{size:20,className:"text-gold-dark"})," Revenue Distribution by Location"]}),e.jsx("div",{className:"space-y-4",children:p.map(s=>{const n=a>0?s.revenue.total/a*100:0,f=Q[s.code]||Q["BEL-HQ"];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full ${f.bg}`}),e.jsx("span",{className:"text-sm font-semibold text-gray-700",children:s.city}),s.isHQ&&e.jsx("span",{className:"text-[9px] font-bold text-gold-dark bg-gold/10 px-1.5 py-0.5 rounded-full",children:"HQ"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"font-mono text-sm font-bold text-gray-900",children:["$",s.revenue.total.toLocaleString()]}),e.jsxs("span",{className:"font-mono text-xs text-gray-400 w-12 text-right",children:[n.toFixed(1),"%"]})]})]}),e.jsx("div",{className:"w-full h-3 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${f.bg} rounded-full transition-all duration-700`,style:{width:`${Math.max(n,2)}%`}})})]},s.code)})})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-5",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 p-6",children:[e.jsxs("h3",{className:"font-display text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(U,{size:20,className:"text-emerald-600"})," Compliance Scorecard"]}),e.jsx("div",{className:"space-y-3",children:[{label:"NACCAS Accreditation",status:"current",expires:"Dec 2028",all:!0},{label:"WA State DOL License",status:"current",expires:"Jun 2027",all:!0},{label:"Title IV Financial Aid",status:"current",expires:"Sep 2027",all:!1},{label:"FERPA Compliance",status:"current",expires:"Annual Review",all:!0},{label:"ADA/WCAG 2.1 AA",status:"current",expires:"Apr 2026 Deadline Met",all:!0},{label:"HIPAA (Med Spa)",status:"current",expires:"Annual Review",all:!1}].map(s=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{size:16,className:"text-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:s.label}),e.jsx("p",{className:"text-[10px] text-gray-400",children:s.expires})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.all?e.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 px-2 py-0.5 rounded-full border border-blue-200",children:"All Locations"}):e.jsx("span",{className:"text-[10px] font-bold text-purple-600 bg-purple-50 px-2 py-0.5 rounded-full border border-purple-200",children:"HQ Only"}),e.jsx("span",{className:"text-[10px] font-bold text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded-full border border-emerald-200",children:"Active"})]})]},s.label))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 p-6",children:[e.jsxs("h3",{className:"font-display text-lg font-bold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(Se,{size:20,className:"text-amber-500"})," Quick Actions"]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{label:"Run Compliance Audit",desc:"All locations",icon:U,color:"bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100"},{label:"Calculate Royalties",desc:"Current quarter",icon:H,color:"bg-gold/10 text-gold-dark border-gold/20 hover:bg-gold/20"},{label:"Sync Curriculum",desc:"Push to branches",icon:V,color:"bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100"},{label:"Generate Reports",desc:"Consolidated P&L",icon:W,color:"bg-purple-50 text-purple-700 border-purple-200 hover:bg-purple-100"},{label:"View Audit Trail",desc:"Data silo logs",icon:_e,color:"bg-orange-50 text-orange-700 border-orange-200 hover:bg-orange-100"},{label:"Kit Order Status",desc:"Branch orders",icon:B,color:"bg-teal-50 text-teal-700 border-teal-200 hover:bg-teal-100"}].map(s=>e.jsxs("button",{className:`flex items-start gap-3 p-3 rounded-xl border transition-all text-left ${s.color}`,children:[e.jsx(s.icon,{size:18,className:"flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:s.label}),e.jsx("p",{className:"text-[10px] opacity-70",children:s.desc})]})]},s.label))})]})]})]})},pe={"BEL-HQ":{name:"Bellingham HQ",city:"Bellingham",gradient:"from-[#800020] to-[#5C0017]",manager:"Frida Karlsson",phone:"(360) 392-8243",address:"410 West Bakerview Rd, Suite 112, Bellingham, WA 98226"},"REN-01":{name:"Renton Campus (Coming August 2026)",city:"Renton",gradient:"from-[#800020] to-[#6B001A]",manager:"Maya Chen",phone:"(360) 392-8243",address:"Renton, WA â Coming August 2026"},"SEA-01":{name:"Seattle Campus (Coming 2027)",city:"Seattle",gradient:"from-[#800020] to-[#5C0017]",manager:"Jordan Rivera",phone:"(360) 392-8243",address:"Seattle, WA â Coming 2027"}},he={"BEL-HQ":{students:[{id:"STU-BEL-001",name:"Emma Thompson",program:"Cosmetology 1600h",hours:1240,status:"active"},{id:"STU-BEL-002",name:"Sophia Martinez",program:"Esthetics 750h",hours:580,status:"active"},{id:"STU-BEL-003",name:"Olivia Johnson",program:"Master Esthetics 450h",hours:320,status:"active"},{id:"STU-BEL-004",name:"Ava Williams",program:"Cosmetology 1600h",hours:1600,status:"graduated"},{id:"STU-BEL-005",name:"Isabella Brown",program:"Instructor 600h",hours:450,status:"active"}
1],staff:[{name:"Frida Karlsson",role:"CEO / Super Admin",status:"active"},{name:"Dr. Sarah Kim",role:"MD Partner",status:"active"},{name:"Lisa Park",role:"Lead Instructor",status:"active"},{name:"Tom Anderson",role:"Financial Aid Director",status:"active"},{name:"Rachel Green",role:"Registrar",status:"active"}],revenue:{tuition:485e3,service:78e3,retail:42e3,total:605e3},activeStudents:42,graduated:156},"REN-01":{students:[{id:"STU-REN-001",name:"Lily Zhang",program:"Cosmetology 1600h",hours:890,status:"active"},{id:"STU-REN-002",name:"Mia Nguyen",program:"Esthetics 750h",hours:420,status:"active"},{id:"STU-REN-003",name:"Chloe Davis",program:"Cosmetology 1600h",hours:1100,status:"active"},{id:"STU-REN-004",name:"Zoe Wilson",program:"Esthetics 750h",hours:750,status:"graduated"}],staff:[{name:"Maya Chen",role:"Location Manager",status:"active"},{name:"Amy Foster",role:"Instructor",status:"active"},{name:"Kevin Park",role:"Front Desk",status:"active"}],revenue:{tuition:285e3,service:35e3,retail:2e4,total:34e4},activeStudents:28,graduated:67},"SEA-01":{students:[{id:"STU-SEA-001",name:"Harper Lee",program:"Cosmetology 1600h",hours:1350,status:"active"},{id:"STU-SEA-002",name:"Ella Garcia",program:"Esthetics 750h",hours:600,status:"active"},{id:"STU-SEA-003",name:"Aria Patel",program:"Master Esthetics 450h",hours:200,status:"active"},{id:"STU-SEA-004",name:"Luna Kim",program:"Cosmetology 1600h",hours:980,status:"active"},{id:"STU-SEA-005",name:"Nora Adams",program:"Esthetics 750h",hours:750,status:"graduated"}],staff:[{name:"Jordan Rivera",role:"Location Manager",status:"active"},{name:"Diana Cruz",role:"Lead Instructor",status:"active"},{name:"Mark Johnson",role:"Instructor",status:"active"},{name:"Sarah White",role:"Front Desk / Admin",status:"active"}],revenue:{tuition:342e3,service:45e3,retail:25e3,total:412e3},activeStudents:35,graduated:89}},X=({tenantCode:u})=>{const[S,p]=o.useState([]),[g,z]=o.useState("overview"),h=pe[u]||pe["BEL-HQ"],i=he[u]||he["BEL-HQ"];o.useEffect(()=>{N()},[u]);const N=async()=>{const{data:a}=await y.from("z_franchise_data_silo_log").select("*").eq("tenant_code",u).order("created_at",{ascending:!1}).limit(20);a&&p(a)},v=[{id:"overview",label:"Overview",icon:I},{id:"students",label:"Students",icon:G},{id:"staff",label:"Staff",icon:Z},{id:"financial",label:"Financials",icon:H},{id:"silo-log",label:"Data Silo Log",icon:M}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:`bg-gradient-to-r ${h.gradient} rounded-2xl p-6 text-white relative overflow-hidden`,children:[e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-white/5 rounded-full -translate-y-1/2 translate-x-1/3"}),e.jsxs("div",{className:"relative z-10 flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(oe,{size:14,className:"text-white/60"}),e.jsxs("span",{className:"text-xs font-bold text-white/60 uppercase tracking-widest",children:["Tenant: ",u]})]}),e.jsx("h2",{className:"font-display text-2xl font-bold",children:h.name}),e.jsxs("p",{className:"text-white/60 text-sm mt-1 flex items-center gap-1",children:[e.jsx(te,{size:12})," ",h.address]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-white/10 rounded-lg border border-white/20",children:[e.jsx(M,{size:14}),e.jsx("span",{className:"text-xs font-semibold",children:"Data Silo: Active"})]}),e.jsxs("p",{className:"text-white/50 text-xs",children:["Manager: ",h.manager," | ",h.phone]})]})]})]}),e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(D,{size:18,className:"text-amber-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900",children:"Tenant Data Isolation Active"}),e.jsxs("p",{className:"text-xs text-amber-700 mt-0.5",children:["All data below is strictly isolated to ",e.jsx("strong",{children:h.name}),". Student records, Z-Bank accounts, and staff lists from other locations are not accessible. Cross-tenant access attempts are logged and denied."]})]})]}),e.jsx("div",{className:"flex items-center gap-1 bg-gray-100 rounded-xl p-1 overflow-x-auto",children:v.map(a=>e.jsxs("button",{onClick:()=>z(a.id),className:`flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-semibold transition-all whitespace-nowrap ${g===a.id?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:[e.jsx(a.icon,{size:15}),a.label]},a.id))}),g==="overview"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-blue-50 flex items-center justify-center",children:e.jsx(G,{size:18,className:"text-blue-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Active Students"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-gray-900",children:i.activeStudents})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(k,{size:18,className:"text-emerald-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Graduated"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-emerald-600",children:i.graduated})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-gold/10 flex items-center justify-center",children:e.jsx(H,{size:18,className:"text-gold-dark"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Revenue"})]}),e.jsxs("p",{className:"font-mono text-2xl font-bold text-gray-900",children:["$",i.revenue.total.toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple-50 flex items-center justify-center",children:e.jsx(Z,{size:18,className:"text-purple-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Staff"})]}),e.jsx("p",{className:"font-mono text-2xl font-bold text-purple-600",children:i.staff.length})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4",children:"Revenue Breakdown"}),e.jsx("div",{className:"space-y-3",children:[{label:"Tuition & Fees",value:i.revenue.tuition,color:"bg-gold"},{label:"Clinic Services",value:i.revenue.service,color:"bg-purple-500"},{label:"Retail Sales",value:i.revenue.retail,color:"bg-emerald-500"}].map(a=>{const b=i.revenue.total>0?a.value/i.revenue.total*100:0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-gray-600",children:a.label}),e.jsxs("span",{className:"font-mono font-bold",children:["$",a.value.toLocaleString()]})]}),e.jsx("div",{className:"w-full h-2.5 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${a.color} rounded-full`,style:{width:`${Math.max(b,3)}%`}})})]},a.label)})})]})]}),g==="students"&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(G,{size:16,className:"text-blue-600"}),"Student Records â ",h.name," Only"]}),e.jsxs("span",{className:"flex items-center gap-1 px-2 py-1 bg-amber-50 text-amber-700 text-[10px] font-bold rounded-full border border-amber-200",children:[e.jsx(D,{size:10})," FERPA Protected"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50",children:[e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Student ID"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Name"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Program"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Hours"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:i.students.map(a=>e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs text-gray-500",children:a.id}),e.jsx("td",{className:"px-4 py-3 text-sm font-semibold text-gray-900",children:a.name}),e.jsx("td",{className:"px-4 py-3 text-sm text-gray-600",children:a.program}),e.jsx("td",{className:"px-4 py-3 font-mono text-sm font-bold",children:a.hours}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold ${a.status==="active"?"bg-emerald-50 text-emerald-700 border border-emerald-200":"bg-blue-50 text-blue-700 border border-blue-200"}`,children:a.status})})]},a.id))})]})})]}),g==="staff"&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-gray-100",children:e.jsxs("h4",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(Z,{size:16,className:"text-purple-600"}),"Staff Directory â ",h.name," Only"]})}),e.jsx("div",{className:"divide-y divide-gray-50",children:i.staff.map((a,b)=>e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 hover:bg-gray-50/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-gray-200 to-gray-300 flex items-center justify-center",children:e.jsx("span",{className:"text-gray-600 text-xs font-bold",children:a.name.split(" ").map(A=>A[0]).join("")})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:a.name}),e.jsx("p",{className:"text-xs text-gray-400",children:a.role})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200",children:a.status})]},b))})]}),g==="financial"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(Ce,{size:16,className:"text-gold-dark"}),"Z-Bank Account â ",h.name]}),e.jsxs("span",{className:"flex items-center gap-1 px-2 py-1 bg-red-50 text-red-700 text-[10px] font-bold rounded-full border border-red-200",children:[e.jsx(D,{size:10})," Isolated Account"]})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Operating Balance"}),e.jsxs("p",{className:"font-mono text-xl font-bold text-gray-900",children:["$",(i.revenue.total*.3).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Tuition Receivable"}),e.jsxs("p",{className:"font-mono text-xl font-bold text-blue-600",children:["$",(i.revenue.tuition*.15).toLocaleString()]})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Monthly Expenses"}),e.jsxs("p",{className:"font-mono text-xl font-bold text-red-600",children:["$",(i.revenue.total*.08).toLocaleString()]})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Net Margin"}),e.jsxs("p",{className:"font-mono text-xl font-bold text-emerald-600",children:[(i.revenue.total*.22/i.revenue.total*100).toFixed(1),"%"]})]})]})]}),e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(M,{size:18,className:"text-red-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-red-900",children:"Financial Data Silo Enforced"}),e.jsxs("p",{className:"text-xs text-red-700 mt-0.5",children:["This Z-Bank account is strictly isolated to ",h.name,". Other locations cannot view or access these financial records. All access attempts are logged for NACCAS/DOL audit compliance."]})]})]})]}),g==="silo-log"&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(M,{size:16,className:"text-red-600"}),"Data Silo Access Log"]}),e.jsxs("span",{className:"text-xs text-gray-400",children:[S.length," entries"]})]}),e.jsx("div",{className:"divide-y divide-gray-50 max-h-[500px] overflow-y-auto",children:S.length===0?e.jsxs("div",{className:"p-8 text-center text-gray-400",children:[e.jsx(oe,{size:32,className:"mx-auto mb-2 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No access log entries found"})]}):S.map(a=>e.jsxs("div",{className:`px-5 py-3 flex items-start gap-3 ${a.access_granted?"":"bg-red-50/50"}`,children:[a.access_granted?e.jsx(k,{size:16,className:"text-emerald-500 flex-shrink-0 mt-0.5"}):e.jsx(ke,{size:16,className:"text-red-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-900",children:a.user_name}),e.jsx("span",{className:"text-[10px] font-mono bg-gray-100 px-1.5 py-0.5 rounded",children:a.user_role}),e.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded ${a.action==="VIEW"?"bg-blue-50 text-blue-700":a.action==="EXPORT"?"bg-purple-50 text-purple-700":a.action==="UPDATE"?"bg-amber-50 text-amber-700":"bg-gray-50 text-gray-600"}`,children:a.action}),e.jsx("span",{className:"text-xs text-gray-400",children:a.resource_type})]}),a.denial_reason&&e.jsx("p",{className:"text-xs text-red-600 mt-1 font-medium",children:a.denial_reason}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:new Date(a.created_at).toLocaleString()})]}),e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold flex-shrink-0 ${a.access_granted?"bg-emerald-50 text-emerald-700 border border-emerald-200":"bg-red-50 text-red-700 border border-red-200"}`,children:a.access_granted?"Granted":"Denied"})]},a.id))})]})]})},ee=[{sku:"SK-EST-100",name:"Student Esthetics Kit",description:"Complete 750h esthetics student kit with Zorganics products",price:18500,category:"Student Kits",image:"EST"},{sku:"SK-COS-200",name:"Student Cosmetology Kit",description:"Complete 1600h cosmetology student kit",price:24500,category:"Student Kits",image:"COS"},{sku:"SK-MAS-300",name:"Master Esthetics Kit",description:"Advanced 450h bridge program kit",price:32e3,category:"Student Kits",image:"MAS"},{sku:"CMH-PRO-01",name:"Changeable Mannequin Head",description:"Professional training mannequin with interchangeable features",price:8900,category:"Training Equipment",image:"CMH"},{sku:"CMH-ADV-02",name:"Advanced Mannequin Head Set",description:"Set of 3 with different skin tones and features",price:24500,category:"Training Equipment",image:"ADV"}
1,{sku:"ZFK-ORG-01",name:"Zorganics Facial Kit",description:"Organic facial treatment product set",price:4500,category:"Zorganics Products",image:"ZFK"},{sku:"LED-PRO-02",name:"LED Light Therapy Device",description:"Professional-grade LED panel for treatments",price:32e3,category:"Equipment",image:"LED"},{sku:"MTB-SET-01",name:"Milady Textbook Set",description:"Complete Milady textbook + workbook bundle",price:12e3,category:"Textbooks",image:"MTB"},{sku:"WAX-BDL-01",name:"Waxing Supplies Bundle",description:"Professional waxing kit with warmers and supplies",price:6500,category:"Supplies",image:"WAX"},{sku:"MIC-PRO-01",name:"Microdermabrasion Unit",description:"Diamond-tip microdermabrasion system",price:45e3,category:"Equipment",image:"MIC"}],be={pending:{color:"bg-amber-50 text-amber-700 border-amber-200",icon:Ne,label:"Pending Review"},approved:{color:"bg-blue-50 text-blue-700 border-blue-200",icon:k,label:"Approved"},processing:{color:"bg-purple-50 text-purple-700 border-purple-200",icon:B,label:"Processing"},shipped:{color:"bg-indigo-50 text-indigo-700 border-indigo-200",icon:ye,label:"Shipped"},delivered:{color:"bg-emerald-50 text-emerald-700 border-emerald-200",icon:k,label:"Delivered"},cancelled:{color:"bg-red-50 text-red-700 border-red-200",icon:K,label:"Cancelled"}},He=()=>
1{const[u,S]=o.useState([]),[p,g]=o.useState(!0),[z,h]=o.useState(!1),[i,N]=o.useState(null),[v,a]=o.useState({}),[b,A]=o.useState("REN-01"),[w,_]=o.useState(""),[R,L]=o.useState("all"),[l,s]=o.useState("");o.useEffect(()=>{n()},[]);const n=async()=>{g(!1);const{data:r}=await y.from("z_franchise_kit_orders").select("*").order("created_at",{ascending:!1});r&&S(r),g(!1)},f=r=>{a(c=>({...c,[r]:(c[r]||0)+1}))},x=r=>{a(c=>{const j={...c};return j[r]>1?j[r]--:delete j[r],j})},C=Object.entries(v).map(([r,c])=>{const j=ee.find(P=>P.sku===r);return{...j,qty:c,total:j.price*c}}),m=C.reduce((r,c)=>r+c.total,0),t=15,d=Math.round(m*(t/100)),T=m>5e4?0:4500,O=m-d+T,F=async()=>{const r=b==="REN-01"?"Renton Campus":"Seattle Campus",c=b==="REN-01"?"Maya Chen":"Jordan Rivera",j=`FKO-${new Date().getFullYear()}-${String(u.length+5).padStart(3,"0")}`,P=C.map($=>({name:$.name,sku:$.sku,qty:$.qty,unit_price:$.price,total:$.total}));await y.from("z_franchise_kit_orders").insert({order_number:j,tenant_code:b,tenant_name:r,ordered_by:c,status:"pending",items:P,subtotal:m,shipping:T,franchise_discount:t,discount_amount:d,total:O,notes:w}),a({}),_(""),h(!1),n()},le=async r=>{await y.from("z_franchise_kit_orders").update({status:"approved",approved_by:"Frida Karlsson",approved_at:new Date().toISOString()}).eq("id",r),n(),N(null)},E=u.filter(r=>!(R!=="all"&&r.status!==R||l&&!r.order_number.toLowerCase().includes(l.toLowerCase())&&!r.tenant_name.toLowerCase().includes(l.toLowerCase()))),J=[...new Set(ee.map(r=>r.category))];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-display text-xl font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(B,{size:22,className:"text-gold-dark"})," Franchise Kit Ordering"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Branch locations order kits & supplies through the Bellingham Wholesale Portal"})]}),e.jsxs("button",{onClick:()=>h(!0),className:"flex items-center gap-2 px-4 py-2.5 bg-gradient-to-r from-gold-dark to-gold text-white rounded-xl text-sm font-semibold shadow-md hover:shadow-lg transition-all",children:[e.jsx(ce,{size:16})," New Kit Order"]})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(I,{size:18,className:"text-blue-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-blue-900",children:"Internal Wholesale System"}),e.jsxs("p",{className:"text-xs text-blue-700 mt-0.5",children:["Renton and Seattle campuses must order all student kits, Changeable Mannequin Heads, and Zorganics products through the Bellingham HQ wholesale portal. Branch locations receive a ",e.jsx("strong",{children:"15% franchise discount"})," on all orders. Free shipping on orders over $500."]})]})]}),z&&e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-200 shadow-lg overflow-hidden",children:[e.jsxs("div",{className:"p-5 border-b border-gray-100 flex items-center justify-between bg-gradient-to-r from-gray-50 to-white",children:[e.jsxs("h4",{className:"font-display text-lg font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(Ae,{size:18,className:"text-gold-dark"})," New Internal Kit Order"]}),e.jsx("button",{onClick:()=>{h(!1),a({})},className:"p-2 hover:bg-gray-100 rounded-lg",children:e.jsx(K,{size:18,className:"text-gray-400"})})]}),e.jsxs("div",{className:"p-5 grid lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:b,onChange:r=>A(r.target.value),className:"px-3 py-2 border border-gray-200 rounded-lg text-sm font-medium focus:outline-none focus:ring-2 focus:ring-gold/30",children:[e.jsx("option",{value:"REN-01",children:"Renton Campus"}),e.jsx("option",{value:"SEA-01",children:"Seattle Campus"})]}),e.jsx("span",{className:"text-xs text-gray-400",children:"Ordering from Bellingham HQ Wholesale"})]}),J.map(r=>e.jsxs("div",{children:[e.jsx("h5",{className:"text-xs font-bold text-gray-400 uppercase tracking-wider mb-2",children:r}),e.jsx("div",{className:"grid md:grid-cols-2 gap-3",children:ee.filter(c=>c.category===r).map(c=>{const j=v[c.sku]||0;return e.jsxs("div",{className:`p-3 rounded-xl border transition-all ${j>0?"border-gold bg-gold/5":"border-gray-100 bg-white hover:border-gray-200"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-gray-100 to-gray-200 flex items-center justify-center flex-shrink-0",children:e.jsx("span",{className:"text-[8px] font-bold text-gray-500",children:c.image})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 truncate",children:c.name}),e.jsx("p",{className:"text-[10px] text-gray-400 font-mono",children:c.sku})]})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 line-clamp-1",children:c.description})]}),e.jsxs("p",{className:"font-mono text-sm font-bold text-gray-900 whitespace-nowrap",children:["$",(c.price/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsx("span",{className:"text-[10px] text-emerald-600 font-semibold",children:"15% franchise discount"}),j>0?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>x(c.sku),className:"w-7 h-7 rounded-lg bg-gray-100 hover:bg-gray-200 flex items-center justify-center transition-colors",children:e.jsx(ze,{size:12})}),e.jsx("span",{className:"font-mono text-sm font-bold w-6 text-center",children:j}),e.jsx("button",{onClick:()=>f(c.sku),className:"w-7 h-7 rounded-lg bg-gold/20 hover:bg-gold/30 text-gold-dark flex items-center justify-center transition-colors",children:e.jsx(ce,{size:12})})]}):e.jsx("button",{onClick:()=>f(c.sku),className:"px-3 py-1.5 bg-gray-100 hover:bg-gold/10 text-gray-600 hover:text-gold-dark rounded-lg text-xs font-semibold transition-all",children:"Add"})]})]},c.sku)})})]},r))]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-gray-50 rounded-xl p-4 sticky top-4",children:[e.jsx("h5",{className:"font-semibold text-gray-900 mb-3",children:"Order Summary"}),C.length===0?e.jsx("p",{className:"text-sm text-gray-400 text-center py-4",children:"No items added yet"}):e.jsx("div",{className:"space-y-2 mb-4",children:C.map(r=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-gray-600 truncate max-w-[180px]",children:[r.name," x",r.qty]}),e.jsxs("span",{className:"font-mono font-semibold",children:["$",(r.total/100).toFixed(2)]})]},r.sku))}),e.jsxs("div",{className:"border-t border-gray-200 pt-3 space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Subtotal"}),e.jsxs("span",{className:"font-mono",children:["$",(m/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-sm text-emerald-600",children:[e.jsxs("span",{children:["Franchise Discount (",t,"%)"]}),e.jsxs("span",{className:"font-mono",children:["-$",(d/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Shipping"}),e.jsx("span",{className:"font-mono",children:T===0?"FREE":`$${(T/100).toFixed(2)}`})]}),e.jsxs("div",{className:"flex justify-between text-base font-bold border-t border-gray-200 pt-2",children:[e.jsx("span",{children:"Total"}),e.jsxs("span",{className:"font-mono",children:["$",(O/100).toFixed(2)]})]})]}),e.jsx("textarea",{value:w,onChange:r=>_(r.target.value),placeholder:"Order notes (optional)...",className:"w-full mt-3 p-2 border border-gray-200 rounded-lg text-sm resize-none h-16 focus:outline-none focus:ring-2 focus:ring-gold/30"}),e.jsxs("button",{onClick:F,disabled:C.length===0,className:"w-full mt-3 flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-gold-dark to-gold text-white rounded-xl text-sm font-semibold shadow-md hover:shadow-lg transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(re,{size:16})," Submit Order to HQ"]}
1)]})})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100 flex flex-col lg:flex-row lg:items-center justify-between gap-3",children:[e.jsx("h4",{className:"font-semibold text-gray-900",children:"Order History"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Re,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx("input",{value:l,onChange:r=>s(r.target.value),placeholder:"Search orders...",className:"pl-9 pr-3 py-2 border border-gray-200 rounded-lg text-sm w-48 focus:outline-none focus:ring-2 focus:ring-gold/30"})]}),e.jsxs("select",{value:R,onChange:r=>L(r.target.value),className:"px-3 py-2 border border-gray-200 rounded-lg text-sm",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"approved",children:"Approved"}),e.jsx("option",{value:"shipped",children:"Shipped"}),e.jsx("option",{value:"delivered",children:"Delivered"})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50",children:[e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Order #"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Campus"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Items"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Total"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Date"}),e.jsx("th",{className:"text-right px-4 py-3 text-xs font-semibold text-gray-500 uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:E.map(r=>{const c=be[r.status]||be.pending,j=c.icon;return e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-4 py-3 font-mono text-sm font-semibold text-gray-900",children:r.order_number}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${r.tenant_code==="REN-01"?"bg-emerald-500":"bg-purple-500"}`}),e.jsx("span",{className:"text-sm text-gray-600",children:r.tenant_name})]})}),e.jsxs("td",{className:"px-4 py-3 text-sm text-gray-600",children:[(r.items||[]).length," items"]}),e.jsxs("td",{className:"px-4 py-3 font-mono text-sm font-bold text-gray-900",children:["$",(r.total/100).toFixed(2)]}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold border ${c.color}`,children:[e.jsx(j,{size:10})," ",c.label]})}),e.jsx("td",{className:"px-4 py-3 text-xs text-gray-400",children:new Date(r.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>N(r),className:"p-1.5 hover:bg-gray-100 rounded-lg",title:"View Details",children:e.jsx(Ee,{size:14,className:"text-gray-400"})}),r.status==="pending"&&e.jsx("button",{onClick:()=>le(r.id),className:"px-2 py-1 bg-emerald-50 text-emerald-700 rounded-lg text-[10px] font-bold hover:bg-emerald-100 border border-emerald-200",children:"Approve"})]})})]},r.id)})})]})})]}),i&&e.jsx("div",{className:"fixed inset-0 bg-black/40 backdrop-blur-sm z-50 flex items-center justify-center p-4",onClick:()=>N(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl max-w-lg w-full max-h-[80vh] overflow-y-auto",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"p-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-display text-lg font-bold text-gray-900",children:i.order_number}),e.jsxs("p",{className:"text-xs text-gray-400",children:[i.tenant_name," â ",i.ordered_by]})]}),e.jsx("button",{onClick:()=>N(null),className:"p-2 hover:bg-gray-100 rounded-lg",children:e.jsx(K,{size:18})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsx("div",{className:"space-y-2",children:(i.items||[]).map((r,c)=>e.jsxs("div",{className:"flex justify-between items-center p-2 bg-gray-50 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:r.name}),e.jsxs("p",{className:"text-[10px] text-gray-400 font-mono",children:[r.sku," x ",r.qty]})]}),e.jsxs("span",{className:"font-mono text-sm font-bold",children:["$",(r.total/100).toFixed(2)]})]},c))}),e.jsxs("div",{className:"border-t border-gray-100 pt-3 space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Subtotal"}),e.jsxs("span",{className:"font-mono",children:["$",(i.subtotal/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-sm text-emerald-600",children:[e.jsxs("span",{children:["Discount (",i.franchise_discount,"%)"]}),e.jsxs("span",{className:"font-mono",children:["-$",(i.discount_amount/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"Shipping"}),e.jsxs("span",{className:"font-mono",children:["$",(i.shipping/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-base font-bold border-t border-gray-100 pt-2",children:[e.jsx("span",{children:"Total"}),e.jsxs("span",{className:"font-mono",children:["$",(i.total/100).toFixed(2)]})]})]}),i.tracking_number&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-blue-50 rounded-lg border border-blue-200",children:[e.jsx(ye,{size:16,className:"text-blue-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-blue-600",children:"Tracking Number"}),e.jsx("p",{className:"font-mono text-sm font-bold text-blue-900",children:i.tracking_number})]})]}),i.notes&&e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-1",children:"Notes"}),e.jsx("p",{className:"text-sm text-gray-700",children:i.notes})]})]})]})})]})},Ie=[{code:"REN-01",name:"Renton",synced:!0,lastSync:"2026-04-02T18:30:00Z",manager:"Maya Chen"},{code:"SEA-01",name:"Seattle",synced:!0,lastSync:"2026-04-02T18:30:00Z",manager:"Jordan Rivera"}],qe=()=>
1{const[u,S]=o.useState([]),[p,g]=o.useState(!0),[z,h]=o.useState(null),[i,N]=o.useState(!1),[v,a]=o.useState(null),[b,A]=o.useState(null);o.useEffect(()=>{w()},[]);const w=async()=>{g(!0);const{data:l}=await y.from("z_franchise_curriculum_sync").select("*").order("program_code");l&&S(l),g(!1)},_=(l,s)=>{A({type:l,message:s}),setTimeout(()=>A(null),5e3)},R=async l=>{N(!0),a(l),await new Promise(x=>setTimeout(x,2e3));const s=new Date().toISOString(),n=u.find(x=>x.id===l),f=[...(n==null?void 0:n.sync_log)||[],{action:"push_all",timestamp:s,by:"Bellingham HQ",targets:["REN-01","SEA-01"],version:n==null?void 0:n.version}];await y.from("z_franchise_curriculum_sync").update({sync_log:f,last_updated_at:s}).eq("id",l),_("success",`${n==null?void 0:n.program_name} curriculum pushed to all branch locations.`),N(!1),a(null),w()},L=async(l,s)=>{const n=u.find(x=>x.id===l);if(!n)return;const f=!n[s];await y.from("z_franchise_curriculum_sync").update({[s]:f}).eq("id",l),_("success",`${s==="quiz_keys_locked"?"Quiz Keys":"PowerPoints"} ${f?"locked":"unlocked"} for ${n.program_name}.`),w()};return p?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Y,{size:32,className:"text-blue-500 animate-spin"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(V,{size:18,className:"text-blue-600"}),e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:"Curriculum Synchronization"}),e.jsx("span",{className:"px-2 py-0.5 bg-blue-100 text-blue-700 text-[10px] font-bold rounded-full",children:"MOTHER SHIP CONTROL"})]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Only Bellingham HQ can update Milady PowerPoints and Quiz Keys. Branches receive read-only copies."})]})}),b&&e.jsxs("div",{className:`p-3 rounded-xl border flex items-center gap-3 ${b.type==="success"?"bg-emerald-50 border-emerald-200":"bg-red-50 border-red-200"}`,children:[b.type==="success"?e.jsx(k,{size:16,className:"text-emerald-600"}):e.jsx(ae,{size:16,className:"text-red-600"}),e.jsx("p",{className:`text-sm font-medium ${b.type==="success"?"text-emerald-800":"text-red-800"}`,children:b.message}),e.jsx("button",{onClick:()=>A(null),className:"ml-auto",children:e.jsx(K,{size:14,className:"text-gray-400"})})]}),e.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200 rounded-2xl p-5",children:[e.jsxs("h4",{className:"text-sm font-bold text-blue-900 mb-3 flex items-center gap-2",children:[e.jsx(Le,{size:16,className:"text-blue-600"})," Branch Sync Status"]}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-blue-200 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-500 flex items-center justify-center",children:e.jsx(I,{size:14,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900",children:"Bellingham HQ"}),e.jsx("p",{className:"text-[10px] text-blue-600 font-semibold",children:"MASTER SOURCE"})]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[e.jsx(q,{size:12,className:"text-emerald-500"}),e.jsx("span",{className:"text-[10px] text-emerald-700 font-semibold",children:"Full Edit Access"})]})]}),Ie.map(l=>e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg ${l.code==="REN-01"?"bg-emerald-500":"bg-purple-500"} flex items-center justify-center`,children:e.jsx(I,{size:14,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900",children:l.name}),e.jsx("p",{className:"text-[10px] text-gray-400",children:l.manager})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(D,{size:12,className:"text-amber-500"}),e.jsx("span",{className:"text-[10px] text-amber-700 font-semibold",children:"Read-Only"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l.synced?e.jsx(k,{size:12,className:"text-emerald-500"}):e.jsx(ae,{size:12,className:"text-red-500"}),e.jsx("span",{className:"text-[10px] text-gray-400",children:new Date(l.lastSync).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]})]})]},l.code))]})]}),e.jsx("div",{className:"space-y-4",children:u.map(l=>{const s=z===l.id,n=(l.modules||[]).reduce((m,t)=>m+(t.chapters||0),0),f=(l.modules||[]).filter(m=>m.synced).length,x=(l.modules||[]).length,C=i&&v===l.id;return e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"p-5 flex items-center justify-between cursor-pointer hover:bg-gray-50/50 transition-colors",onClick:()=>h(s?null:l.id),children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 roun
1ded-xl bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center text-white",children:e.jsx(V,{size:24})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900",children:l.program_name}),e.jsx("span",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 text-[10px] font-mono font-bold rounded-full",children:l.program_code}),e.jsx("span",{className:"px-2 py-0.5 bg-blue-50 text-blue-700 text-[10px] font-bold rounded-full border border-blue-200",children:l.version})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-gray-400",children:[e.jsxs("span",{className:"font-mono font-bold text-gray-600",children:[l.total_hours,"h"]}),e.jsxs("span",{children:[x," modules"]}),e.jsxs("span",{children:[n," chapters"]}),e.jsxs("span",{children:[f,"/",x," synced"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:`flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-bold ${l.quiz_keys_locked?"bg-red-50 text-red-700 border border-red-200":"bg-emerald-50 text-emerald-700 border border-emerald-200"}`,children:[l.quiz_keys_locked?e.jsx(D,{size:10}):e.jsx(q,{size:10}),"Quiz Keys"]}),e.jsxs("div",{className:`flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-bold ${l.powerpoints_locked?"bg-red-50 text-red-700 border border-red-200":"bg-emerald-50 text-emerald-700 border border-emerald-200"}`,children:[l.powerpoints_locked?e.jsx(D,{size:10}):e.jsx(q,{size:10}),"PowerPoints"]})]}),s?e.jsx(Te,{size:18,className:"text-gray-400"}):e.jsx(Fe,{size:18,className:"text-gray-400"})]})]}),s&&e.jsxs("div",{className:"border-t border-gray-100",children:[e.jsxs("div",{className:"p-5",children:[e.jsx("h5",{className:"text-xs font-bold text-gray-400 uppercase tracking-wider mb-3",children:"Curriculum Modules"}),e.jsx("div",{className:"grid gap-2",children:(l.modules||[]).map((m,t)=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-xl",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-white border border-gray-200 flex items-center justify-center text-xs font-bold text-gray-500",children:t+1}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-gray-400",children:[e.jsxs("span",{className:"font-mono font-bold",children:[m.hours,"h"]}),m.chapters>0&&e.jsxs("span",{children:[m.chapters," chapters"]})]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:m.synced?e.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-emerald-50 text-emerald-700 text-[10px] font-bold rounded-full border border-emerald-200",children:[e.jsx(k,{size:10})," Synced"]}):e.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-amber-50 text-amber-700 text-[10px] font-bold rounded-full border border-amber-200",children:[e.jsx(Ne,{size:10})," Pending"]})})]},t))})]}),e.jsxs("div",{className:"px-5 pb-5 flex flex-wrap items-center gap-3",children:[e.jsx("button",{onClick:m=>{m.stopPropagation(),R(l.id)},disabled:C,className:"flex items-center gap-2 px-4 py-2.5 bg-gradient-to-r from-blue-600 to-indigo-600 text-white rounded-xl text-sm font-semibold hover:shadow-lg transition-all disabled:opacity-50",children:C?e.jsxs(e.Fragment,{children:[e.jsx(Y,{size:14,className:"animate-spin"})," Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{size:14})," Push to All Branches"]})}),e.jsxs("button",{onClick:m=>{m.stopPropagation(),L(l.id,"quiz_keys_locked")},className:"flex items-center gap-2 px-3 py-2 border border-gray-200 rounded-xl text-sm font-medium hover:bg-gray-50 transition-colors",children:[l.quiz_keys_locked?e.jsx(q,{size:14}):e.jsx(D,{size:14}),l.quiz_keys_locked?"Unlock":"Lock"," Quiz Keys"]}),e.jsxs("button",{onClick:m=>{m.stopPropagation(),L(l.id,"powerpoints_locked")},className:"flex items-center gap-2 px-3 py-2 border border-gray-200 rounded-xl text-sm font-medium hover:bg-gray-50 transition-colors",children:[l.powerpoints_locked?e.jsx(q,{size:14}):e.jsx(D,{size:14}),l.powerpoints_locked?"Unlock":"Lock"," PowerPoints"]})]}),(l.sync_log||[]).length>0&&e.jsxs("div",{className:"px-5 pb-5",children:[e.jsx("h5",{className:"text-xs font-bold text-gray-400 uppercase tracking-wider mb-2",children:"Sync History"}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:(l.sync_log||[]).slice(-5).reverse().map((m,t)=>
1e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 p-2 bg-gray-50 rounded-lg",children:[e.jsx($e,{size:10,className:"text-blue-500"}),e.jsx("span",{className:"font-semibold",children:m.by}),e.jsx(De,{size:10}),e.jsx("span",{children:(m.targets||[]).join(", ")}),e.jsx("span",{className:"text-gray-300",children:"|"}),e.jsx("span",{className:"font-mono",children:m.version}),e.jsx("span",{className:"ml-auto text-gray-400",children:new Date(m.timestamp).toLocaleString()})]},t))})]}),e.jsx("div",{className:"px-5 pb-5",children:e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-3 flex items-start gap-3",children:[e.jsx(M,{size:16,className:"text-amber-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-amber-900",children:"Branch Access: Read-Only"}),e.jsx("p",{className:"text-[10px] text-amber-700 mt-0.5",children:"Renton and Seattle campuses receive this curriculum as read-only. They cannot modify Milady PowerPoints, Quiz Keys, or module structure. All updates must originate from Bellingham HQ."})]})]})})]})]},l.id)})})]})},Qe=[{id:"global",label:"CEO Global Dashboard",shortLabel:"Global",icon:e.jsx(se,{size:16}),color:"text-gold-dark"},{id:"bellingham",label:"Bellingham HQ",shortLabel:"BEL",icon:e.jsx(I,{size:16}),color:"text-blue-600"},{id:"renton",label:"Renton Campus (Coming August 2026)",shortLabel:"REN",icon:e.jsx(te,{size:16}),color:"text-emerald-600"},{id:"seattle",label:"Seattle Campus",shortLabel:"SEA",icon:e.jsx(te,{size:16}),color:"text-purple-600"},{id:"kit-ordering",label:"Kit Ordering",shortLabel:"Kits",icon:e.jsx(B,{size:16}),color:"text-amber-600"},{id:"curriculum",label:"Curriculum Sync",shortLabel:"Curriculum",icon:e.jsx(V,{size:16}),color:"text-indigo-600"},{id:"royalties",label:"Royalty & Fees",shortLabel:"Royalties",icon:e.jsx(H,{size:16}),color:"text-burgundy"}],fe={draft:{bg:"bg-gray-50",text:"text-gray-700",border:"border-gray-200",label:"Draft"},calculated:{bg:"bg-blue-50",text:"text-blue-700",border:"border-blue-200",label:"Calculated"},invoiced:{bg:"bg-amber-50",text:"text-amber-700",border:"border-amber-200",label:"Invoiced"},paid:{bg:"bg-emerald-50",text:"text-emerald-700",border:"border-emerald-200",label:"Paid"},submitted_to_cpa:{bg:"bg-purple-50",text:"text-purple-700",border:"border-purple-200",label:"Filed to CPA"},overdue:{bg:"bg-red-50",text:"text-red-700",border:"border-red-200",label:"Overdue"}},Ke=()=>
1{const[u,S]=o.useState([]),[p,g]=o.useState([]),[z,h]=o.useState(!0),[i,N]=o.useState(!1),[v,a]=o.useState(null),[b,A]=o.useState("all");o.useEffect(()=>{w()},[]);const w=async()=>{h(!0);try{const[t,d]=await Promise.allSettled([me(y.from("z_franchise_royalties").select("*").order("period_start",{ascending:!1}),12e3,"z_franchise_royalties"),me(y.from("z_franchise_tenants").select("*").eq("is_active",!0).eq("is_hq",!1),12e3,"z_franchise_tenants")]);t.status==="fulfilled"&&t.value.data&&S(t.value.data),d.status==="fulfilled"&&d.value.data&&g(d.value.data)}catch(t){console.error("[FranchiseHub/RoyaltyAutomator] fetchData fatal error:",t)}finally{h(!1)}},_=(t,d)=>{a({type:t,message:d}),setTimeout(()=>a(null),5e3)},R=async()=>{N(!0);const t=new Date,d=new Date(t.getFullYear(),Math.floor(t.getMonth()/3)*3,1),T=new Date(t.getFullYear(),Math.floor(t.getMonth()/3)*3+3,0),O=`Q${Math.floor(t.getMonth()/3)+1} ${t.getFullYear()}`;for(const F of p){if(u.find(de=>de.tenant_code===F.code&&de.period_label===O))continue;const E=F.code==="REN-01"?305e5:372e5,J=Math.round(E*.72),r=Math.round(E*.14),c=Math.round(E*.08),j=Math.round(E*.06),P=Number(F.royalty_rate)||6,$=Math.round(E*(P/100)),ne=(F.franchise_fee_monthly||2500)*3*100,ie=Math.round(E*.01),ve=$+ne+ie;await y.from("z_franchise_royalties").insert({tenant_code:F.code,tenant_name:F.name.replace("Zorganics Institute â ","")+" Campus",period_start:d.toISOString().split("T")[0],period_end:T.toISOString().split("T")[0],period_label:O,gross_revenue:E,tuition_revenue:J,service_revenue:r,retail_revenue:c,pos_revenue:j,royalty_rate:P,royalty_amount:$,franchise_fee:ne,marketing_fund:ie,total_due:ve,status:"calculated"})}_("success",`Royalties calculated for ${O} across ${p.length} branch locations.`),N(!1),w()},L=async t=>{await y.from("z_franchise_royalties").update({status:"paid",paid_at:new Date().toISOString()}).eq("id",t),_("success","Royalty marked as paid."),w()},l=async t=>{const d=u.find(T=>T.id===t);d&&(await y.from("z_cpa_entries").insert({category:"franchise_royalty",description:`Franchise Royalty â ${d.tenant_name} â ${d.period_label}`,amount:d.total_due,type:"income",date:new Date().toISOString().split("T")[0],status:"pending_review",metadata:{royalty_id:t,tenant_code:d.tenant_code,period:d.period_label}}),await y.from("z_franchise_royalties").update({status:"submitted_to_cpa"}).eq("id",t),_("success",`Royalty for ${d.tenant_name} â ${d.period_label} submitted to Z-CPA Corporate Ledger.`),w())},s=async t=>{await y.from("z_franchise_royalties").update({status:"invoiced"}).eq("id",t),_("success","Invoice sent to branch location."),w()},n=b==="all"?u:u.filter(t=>t.tenant_code===b),f=u.filter(t=>t.status==="invoiced"||t.status==="calculated").reduce((t,d)=>t+d.total_due,0),x=u.filter(t=>t.status==="paid"||t.status==="submitted_to_cpa").reduce((t,d)=>t+d.total_due,0),C=u.filter(t=>t.status==="submitted_to_cpa").reduce((t,d)=>t+d.total_due,0),m=u.reduce((t,d)=>t+d.gross_revenue,0);return z?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(Y,{size:32,className:"text-gold animate-spin"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(H,{size:18,className:"text-burgundy"}),e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:"Royalty & Fee Automator"}),e.jsx("span",{className:"px-2 py-0.5 bg-burgundy/10 text-burgundy text-[10px] font-bold rounded-full",children:"Z-CPA INTEGRATED"})]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Auto-calculate franchise fees and royalties from branch revenue. Report to Z-CPA Corporate Ledger."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:b,onChange:t=>A(t.target.value),className:"px-3 py-2.5 border border-gray-200 rounded-xl text-sm bg-white",children:[e.jsx("option",{value:"all",children:"All Branches"}),p.map(t=>e.jsx("option",{value:t.code,children:t.name.replace("Zorganics Institute â ","")},t.code))]}),e.jsx("button",{onClick:R,disabled:i,className:"flex items-center gap-2 px-5 py-2.5 bg-gradient-to-r from-burgundy to-burgundy-dark text-white rounded-xl text-sm font-semibold hover:shadow-lg transition-all disabled:opacity-50",children:i?e.jsxs(e.Fragment,{children:[e.jsx(Y,{size:14,className:"animate-spin"})," Calculating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Oe,{size:14})," Calculate Current Quarter"]})})]})]}),v&&e.jsxs("div",{className:`p-3 rounded-xl border flex items-center gap-3 ${v.type==="success"?"bg-emerald-50 border-emerald-200":"bg-red-50 border-red-200"}`,children:[v.type==="success"?e.jsx(k,{size:16,className:"text-emerald-600"}):e.jsx(ae,{size:16,className:"text-red-600"}),e.jsx("p",{className:`text-sm font-medium ${v.type==="success"?"text-emerald-800":"text-red-800"}`,children:v.message}),e.jsx("button",{onClick:()=>a(null),className:"ml-auto",children:e.jsx(K,{size:14,className:"text-gray-400"})})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-gold/10 flex items-center justify-center",children:e.jsx(je,{size:16,className:"text-gold-dark"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Gross Revenue"})]}),e.jsxs("p",{className:"font-mono text-xl font-bold text-gray-900",children:["$",(m/100).toLocaleStr
1ing(void 0,{maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"All periods combined"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-amber-50 flex items-center justify-center",children:e.jsx(Pe,{size:16,className:"text-amber-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Outstanding"})]}),e.jsxs("p",{className:"font-mono text-xl font-bold text-amber-700",children:["$",(f/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Invoiced + calculated"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(k,{size:16,className:"text-emerald-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Collected"})]}),e.jsxs("p",{className:"font-mono text-xl font-bold text-emerald-700",children:["$",(x/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Paid + filed"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-100 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-purple-50 flex items-center justify-center",children:e.jsx(ue,{size:16,className:"text-purple-600"})}),e.jsx("span",{className:"text-xs text-gray-400",children:"Filed to CPA"})]}),e.jsxs("p",{className:"font-mono text-xl font-bold text-purple-700",children:["$",(C/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Submitted to Z-CPA"})]})]}),e.jsxs("div",{className:"bg-gradient-to-r from-burgundy/5 to-gold/5 border border-burgundy/10 rounded-2xl p-5",children:[e.jsxs("h4",{className:"text-sm font-bold text-burgundy mb-3 flex items-center gap-2",children:[e.jsx(Me,{size:16})," Franchise Fee Structure"]}),e.jsx("div",{className:"grid md:grid-cols-3 gap-4",children:p.map(t=>e.jsxs("div",{className:"bg-white rounded-xl p-4 border border-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg ${t.code==="REN-01"?"bg-emerald-500":"bg-purple-500"} flex items-center justify-center`,children:e.jsx(I,{size:14,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900",children:t.name.replace("Zorganics Institute â ","")}),e.jsx("p",{className:"text-[10px] text-gray-400 font-mono",children:t.code})]})]}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Royalty Rate"}),e.jsxs("span",{className:"font-bold text-burgundy",children:[t.royalty_rate,"%"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Monthly Franchise Fee"}),e.jsxs("span",{className:"font-bold",children:["$",(t.franchise_fee_monthly||0).toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Marketing Fund"}),e.jsx("span",{className:"font-bold",children:"1% of revenue"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Max Students"}),e.jsx("span",{className:"font-bold",children:t.max_students})]})]})]},t.code))})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100 flex items-center justify-between bg-gradient-to-r from-gray-50 to-white",children:[e.jsxs("h4",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(W,{size:16,className:"text-gold-dark"})," Royalty Ledger"]}),e.jsxs("span",{className:"text-xs text-gray-400",children:[n.length," records"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-gray-50",children:[e.jsx("th",{className:"text-left px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Period"}),e.jsx("th",{className:"text-left px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Branch"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Gross Revenue"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Royalty (6%)"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Franchise Fee"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Marketing"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Total Due"}),e.jsx("th",{className:"text-center px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-3 text-[10px] font-bold text-gray-500 uppercase",children:"Actions"})]})}),e.jsxs("tbody",{className:"divide-y divide-gray-50",children:[n.map(t=>{const d=fe[t.status]||fe.draft;return e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("p",{className:"text-sm font-bold text-gray-900",children:t.period_label}),e.jsxs("p",{className:"text-[10px] text-gray-400",children:[new Date(t.period_start).toLocaleDateString()," â ",new Date(t.period_end).toLocaleDateString()]})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${t.tenant_code==="REN-01"?"bg-emerald-500":"bg-purple-500"}`}),e.jsx("span",{className:"text-sm text-gray-700",children:t.tenant_name})]})}),e.jsxs("td",{className:"px-4 py-3 text-right font-mono text-sm font-bold text-gray-900",children:["$",(t.gross_revenue/100).toLocaleStr
1ing(void 0,{maximumFractionDigits:0})]}),e.jsxs("td",{className:"px-4 py-3 text-right font-mono text-sm text-burgundy font-bold",children:["$",(t.royalty_amount/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsxs("td",{className:"px-4 py-3 text-right font-mono text-sm text-gray-600",children:["$",(t.franchise_fee/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsxs("td",{className:"px-4 py-3 text-right font-mono text-sm text-gray-600",children:["$",(t.marketing_fund/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsxs("td",{className:"px-4 py-3 text-right font-mono text-sm font-bold text-gray-900",children:["$",(t.total_due/100).toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold border ${d.bg} ${d.text} ${d.border}`,children:d.label})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[(t.status==="calculated"||t.status==="draft")&&e.jsx("button",{onClick:()=>s(t.id),className:"px-2 py-1 bg-amber-50 text-amber-700 rounded-lg text-[10px] font-bold hover:bg-amber-100 border border-amber-200",title:"Send Invoice",children:e.jsx(re,{size:10})}),t.status==="invoiced"&&e.jsx("button",{onClick:()=>L(t.id),className:"px-2 py-1 bg-emerald-50 text-emerald-700 rounded-lg text-[10px] font-bold hover:bg-emerald-100 border border-emerald-200",title:"Mark Paid",children:e.jsx(k,{size:10})}),t.status==="paid"&&e.jsx("button",{onClick:()=>l(t.id),className:"px-2 py-1 bg-purple-50 text-purple-700 rounded-lg text-[10px] font-bold hover:bg-purple-100 border border-purple-200",title:"Submit to CPA",children:e.jsx(ue,{size:10})})]})})]},t.id)}),n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"px-4 py-8 text-center text-gray-400 text-sm",children:'No royalty records found. Click "Calculate Current Quarter" to generate.'})})]})]})}),e.jsxs("div",{className:"px-4 py-3 bg-gray-50 border-t border-gray-100 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Royalties auto-calculated from branch revenue data"}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-400",children:[e.jsx(M,{size:12}),e.jsx("span",{children:"All fees reported to Z-CPA Corporate Ledger"})]})]})]})]})},Ze=()=>{const[u,S]=o.useState("global"),p=()=>{switch(u){case"global":return e.jsx(xe,{redirectTo:"/admin-login",children:e.jsx(ge,{})});case"bellingham":return e.jsx(X,{tenantCode:"BEL-HQ"});case"renton":return e.jsx(X,{tenantCode:"REN-01"});case"seattle":return e.jsx(X,{tenantCode:"SEA-01"});case"kit-ordering":return e.jsx(He,{});case"curriculum":return e.jsx(qe,{});case"royalties":return e.jsx(Ke,{});default:return e.jsx(xe,{redirectTo:"/admin-login",children:e.jsx(ge,{})})}};return e.jsxs("section",{className:"py-8 lg:py-12",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-end justify-between gap-4 mb-6",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("div",{className:"w-1 h-6 bg-gradient-to-b from-gold to-burgundy rounded-full"}),e.jsx("span",{className:"text-xs font-semibold text-burgundy uppercase tracking-wider",children:"Global Franchise & Multi-Location · Operator Console"})]}),e.jsx("h2",{className:"font-display text-3xl lg:text-4xl font-bold text-gray-900",children:"Franchise Command Center"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"Multi-tenant operator console with data silos, curriculum control, and royalty automation across the active footprint â Bellingham HQ, Renton (Coming August 2026) & Seattle. Internal B2B tooling, separate from the public Institute storefront."})]})}),e.jsx("div",{className:"flex items-center gap-1 bg-gray-100 rounded-xl p-1 mb-6 overflow-x-auto",children:Qe.map(g=>e.jsxs("button",{onClick:()=>S(g.id),className:`flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-semibold transition-all whitespace-nowrap ${u===g.id?"bg-white text-gray-900 shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:[e.jsx("span",{className:u===g.id?g.color:"text-gray-400",children:g.icon}),e.jsx("span",{className:"hidden lg:inline",children:g.label}),e.jsx("span",{className:"lg:hidden",children:g.shortLabel})]},g.id))}),p()]})};export{Ze as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.