1import{j as e}from"./vendor-grid-ClmSNH6q.js";import{ac as ue,h as Ye,aW as Ke,w as X,aO as J,z as me,av as ee,Y as fe,a8 as We,X as le,a4 as pe,R as he,q as te,aQ as ie,o as G,K as Ue,a5 as Xe,b6 as Qe,S as be,B as Ze,U as et,a2 as tt,b as Be,b5 as je,$ as st,bj as qe,aP as He}from"./index-Cab6mplo.js";import{r}from"./vendor-charts-B2bLUVVL.js";import{P as at}from"./PageHeader-yatqFoQp.js";import{b as ge}from"./Card-BUL_z2x0.js";import{U as rt}from"./user-check-BuNHEcu6.js";import{S as Se}from"./scroll-text-DK18zFf2.js";import{F as lt}from"./file-lock-BlWXzQDJ.js";import{K as Je}from"./key-BJ1KLere.js";const Ee=[{limit:"$10,000",monthly_cents:350},{limit:"$15,000",monthly_cents:400},{limit:"$20,000",monthly_cents:445},{limit:"$25,000",monthly_cents:485},{limit:"$50,000",monthly_cents:615},{limit:"$75,000",monthly_cents:685},{limit:"$100,000",monthly_cents:700,recommended:!0},{limit:"$150,000",monthly_cents:850},{limit:"$200,000",monthly_cents:950},{limit:"$250,000",monthly_cents:1025},{limit:"$300,000",monthly_cents:1050},{limit:"$500,000",monthly_cents:1650}],ce={pp:{label:"Personal Property",rates:[{limit:"$5,000",monthly_cents:150,deductible:"$500 / $1,000"},{limit:"$10,000",monthly_cents:300,deductible:"$500 / $1,000"},{limit:"$15,000",monthly_cents:450,deductible:"$500 / $1,000"},{limit:"$20,000",monthly_cents:550,deductible:"$500 / $1,000"},{limit:"$25,000",monthly_cents:625,deductible:"$500 / $1,000"},{limit:"$30,000",monthly_cents:675,deductible:"$500 / $1,000"},{limit:"$50,000",monthly_cents:1e3,deductible:"$500 / $1,000"}]},ale:{label:"Additional Living Expenses",rates:[{limit:"$2,000 / $10,000",monthly_cents:25},{limit:"$5,000 / $25,000",monthly_cents:50}]},lri:{label:"Loss of Landlord's Rental Income",rates:[{limit:"$2,500 / $15,000",monthly_cents:15},{limit:"$5,000 / $25,000",monthly_cents:25},{limit:"$10,000 / $50,000",monthly_cents:35}]},bi:{label:"Bodily Injury Liability",rates:[{limit:"$10,000 / $25,000",monthly_cents:75},{limit:"$25,000 / $50,000",monthly_cents:100},{limit:"$50,000 / $100,000",monthly_cents:175},{limit:"$100,000 / $100,000",monthly_cents:200},{limit:"$300,000 / $300,000",monthly_cents:400}]},pet:{label:"Pet Damage",rates:[{limit:"$1,000",monthly_cents:25,deductible:"$100"},{limit:"$2,500",monthly_cents:35,deductible:"$100"},{limit:"$5,000",monthly_cents:50,deductible:"$100"}]},dog:{label:"Dog Bite / Animal Liability",rates:[{limit:"$10,000 / $25,000",monthly_cents:50},{limit:"$25,000 / $50,000",monthly_cents:75},{limit:"$50,000 / $100,000",monthly_cents:100},{limit:"$100,000 / $100,000",monthly_cents:150}]},bact:{label:"Limited Bacteria / Fungi",rates:[{limit:"$10,000",monthly_cents:25},{limit:"$25,000",monthly_cents:50}]},bb:{label:"Bed Bug Remediation",rates:[{limit:"$500",monthly_cents:15},{limit:"$1,000",monthly_cents:25}]},veh:{label:"Vehicle Liability",rates:[{limit:"$10,000 / $25,000",monthly_cents:50}]}};function nt({onSaveTier:a,platformFeePercent:t=20}){const[k,h]=r.useState(6),[C,S]=r.useState({}),[E,F]=r.useState(""),[j,u]=r.useState(t),s=Ee[k],o=Object.entries(C).reduce((m,[f,g])=>m+ce[f].rates[g].monthly_cents,0),d=s.monthly_cents+o,c=Math.round(d*j/100),x=d-c,A=(m,f)=>{S(g=>{const _={...g};return _[m]===f?delete _[m]:_[m]=f,_})},b=()=>{const m=[`Property Damage Liability: ${s.limit}`];return Object.entries(C).forEach(([f,g])=>{const _=ce[f];m.push(`${_.label}: ${_.rates[g].limit}`)}),m.join(" + ")},I=()=>{if(!E.trim())return;const m=s.limit.replace(/[$,]/g,""),f=parseInt(m)*100;a({tierName:E.trim(),monthlyPremiumCents:d,platformFeeCents:c,coverageAmountCents:f,coverageDescription:b(),msiCoverageCodes:JSON.stringify([{code:1003,limit:0},{code:1005,limit:parseInt(m)}])})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-emerald-900 rounded-lg flex items-center justify-center",children:e.jsx(ue,{className:"w-5 h-5 text-emerald-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"MSI TLL Rate Builder"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Select base coverage + endorsements to build a tier"})]})]}),e.jsxs(ge,{padding:"sm",children:[e.jsxs("div",{className:"px-4 py-2 border-b border-gray-100 dark:border-slate-700",children:[e.jsx("h4",{className:"text-sm font-semibold text-emerald-800 dark:text-emerald-400",children:"Property Damage Liability â Required"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Select one liability limit. No deductible."})]}),e.jsx("div",{className:"divide-y divide-gray-50 dark:divide-slate-700",children:Ee.map((m,f)=>e.jsxs("button",{onClick:()=>h(f),className:`w-full flex items-center justify-between px-4 py-2.5 text-sm transition-colors ${k===f?"bg-emerald-50 dark:bg-emerald-900/20":"hover:bg-gray-50 dark:hover:bg-slate-700/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center ${k===f?"border-emerald-600 bg-emerald-600":"border-gray-300"}`,children:k===f&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-white"})}),e.jsx("span",{className:"font-mono text-gray-800 dark:text-gray-200",children:m.limit}),m.recommended&&e.jsx("span",{className:"px-1.5 py-0.5 text-[9px] font-bold uppercase bg-emerald-100 text-emerald-700 rounded-full",children:"Recommended"})]}),e.jsxs("span",{className:"font-mono text-emerald-700 dark:text-emerald-400 font-medium",children:["$",(m.monthly_cents/100).toFixed(2),"/mo"]})]},f))})]}),Object.entries(ce).map(([m,f])=>e.jsxs(ge,{padding:"sm",children:[e.jsx("div",{className:"px-4 py-2 border-b border-gray-100 dark:border-slate-700",children:e.jsx("h4",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300",children:f.label})}),e.jsx("div",{className:"divide-y divide-gray-50 dark:divide-slate-700",children:f.rates.map((g,_)=>{const R=C[m]===_;return e.jsxs("button",{onClick:()=>A(m,_),className:`w-full flex items-center justify-between px-4 py-2 text-sm transition-colors ${R?"bg-blue-50 dark:bg-blue-900/20":"hover:bg-gray-50 dark:hover:bg-slate-700/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-4 h-4 rounded border-2 flex items-center justify-center text-[10px] ${R?"border-emerald-600 bg-emerald-600 text-white":"border-gray-300"}`,children:R&&e.jsx(Ye,{className:"w-3 h-3"})}),e.jsx("span",{className:"font-mono text-gray-700 dark:text-gray-300",children:g.limit}),g.deductible&&e.jsxs("span",{className:"text-xs text-gray-400",children:["Ded: ",g.deductible]})]}),e.jsxs("span",{className:"font-mono text-gray-600 dark:text-gray-400",children:["$",(g.monthly_cents/100).toFixed(2),"/mo"]})]},_)})})]},m)),e.jsxs(ge,{padding:"md",children:[e.jsxs("div",{className:"bg-emerald-900 text-white rounded-lg p-5 text-center mb-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-emerald-300/60 mb-1",children:"Total Monthly Premium"}),e.jsxs("p",{className:"text-4xl font-mono font-bold text-emerald-400",children:["$",(d/100).toFixed(2)]}),e.jsx("p",{className:"text-xs text-emerald-300/50 mt-1",children:"per unit / per month"}),e.jsxs("p",{className:"text-xs font-mono text-emerald-300/40 mt-0.5",children:["$",(d*12/100).toFixed(2)," / year"]})]}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-gray-600",children:["Property Damage Liability (",s.limit,")"]}),e.jsxs("span",{className:"font-mono font-medium text-gray-800",children:["$",(s.monthly_cents/100).toFixed(2)]})]}),Object.entries(C).map(([m,f])=>{const g=ce[m],_=g.rates[f];return e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-gray-600",children:[g.label," (",_.limit,")"]}),e.jsxs("span",{className:"font-mono font-medium text-gray-800",children:["$",(_.monthly_cents/100).toFixed(2)]})]},m)}),e.jsx("hr",{className:"border-gray-200 dark:border-slate-600"}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-gray-500",children:["Platform fee (",j,"%)"]}),e.jsxs("span",{className:"font-mono text-blue-600",children:["$",(c/100).toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"MSI payout"}),e.jsxs("span",{className:"font-mono text-gray-600",children:["$",(x/100).toFixed(2)]})]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"text-xs text-gray-500 block mb-1",children:["Platform fee: ",j,"%"]}),e.jsx("input",{type:"range",min:0,max:50,value:j,onChange:m=>u(parseInt(m.target.value)),className:"w-full accent-emerald-600"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:E,onChange:m=>F(m.target.value),placeholder:"Tier name (e.g. Standard, Premium)",className:"flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-slate-600 rounded-lg dark:bg-slate-800 dark:text-white"}),e.jsxs(Ke,{variant:"primary",onClick:I,disabled:!E.trim(),children:[e.jsx(X,{className:"w-4 h-4 mr-1"})," Save Tier"]})]})]})]})}const Fe=()=>({"x-api-key":G(),"Content-Type":"application/json"}),Te=()=>({"x-api-key":G()}),it=[{id:"",label:"All"},{id:"unassigned",label:"Unassigned"},{id:"in_review",label:"In Review"},{id:"pending_approval",label:"Pending Approval"},{id:"escalated",label:"Escalated"},{id:"closed",label:"Closed"}],Ae=[{value:"cleared_false_positive",label:"Clear â false positive (not a match, this is a different person)",hint:"Not a real SDN match â the screened entity is not the sanctioned individual. High-confidence hits still need an admin checker."},{value:"confirmed_match",label:"Confirmed match â this person is on the OFAC sanctions list, block them",hint:"A real SDN match. Always requires an admin checker (four-eyes)."},{value:"escalated",label:"Escalate for senior review â need more information to decide",hint:"Needs more documents or senior judgment. Not a terminal decision."}],Re=a=>
1a?new Date(a).toLocaleString():"â",Ne=a=>a==null?"â":`${(a*100).toFixed(0)}%`,Q=a=>a.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase());function Ie(a){const t={unassigned:"bg-gray-100 text-gray-700",in_review:"bg-blue-100 text-blue-700",pending_approval:"bg-amber-100 text-amber-800",escalated:"bg-red-100 text-red-700",closed:"bg-green-100 text-green-700"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:Q(a)})}function Pe(a){const t=a??0,k=t>=.95?"bg-red-100 text-red-700":t>=.9?"bg-amber-100 text-amber-800":"bg-gray-100 text-gray-600";return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-semibold ${k}`,children:Ne(a)})}function ct({isAdmin:a}){var P,Z;const t=J(),k=localStorage.getItem("userId")||"",[h,C]=r.useState([]),[S,E]=r.useState({}),[F,j]=r.useState(!0),[u,s]=r.useState(""),[o,d]=r.useState(null),[c,x]=r.useState(!1),[A,b]=r.useState(!1),[I,m]=r.useState(!1),[f,g]=r.useState("cleared_false_positive"),[_,R]=r.useState(""),[D,M]=r.useState(""),[z,n]=r.useState(!1),[p,N]=r.useState({first_name:"",last_name:"",dob:"",entity_type:"beneficial_owner",entity_id:""}),l=r.useCallback(()=>{j(!0);const y=new URLSearchParams({limit:"100"});u&&y.set("stage",u),fetch(`/api/screening/ofac-cases?${y}`,{headers:Te()}).then(O=>O.json()).then(O=>{C(Array.isArray(O.cases)?O.cases:[]),E(O.counts||{})}).catch(()=>t.error("Failed to load OFAC cases")).finally(()=>j(!1))},[u,t]);r.useEffect(()=>{l()},[l]);const T=r.useCallback(y=>{x(!0),m(!1),R(""),M(""),fetch(`/api/screening/ofac-cases?case_id=${encodeURIComponent(y)}`,{headers:Te()}).then(O=>O.json()).then(O=>{O.case?d(O.case):t.error(O.error||"Case not found")}).catch(()=>t.error("Failed to load case")).finally(()=>x(!1))},[t]),v=async(y,O,q)=>{b(!0);try{const L=await fetch(y,{method:"POST",headers:Fe(),body:JSON.stringify(O)}),W=await L.json();return L.ok?(t.success(W.message||q),o&&T(o.case_id),l(),!0):(t.error(W.error||`Action failed (${L.status})`),!1)}catch{return t.error("Network error"),!1}finally{b(!1)}},B=y=>v(`/api/screening/ofac-cases/${encodeURIComponent(y.case_id)}/assign`,{},"Case assigned to you."),se=async y=>{if(!_.trim()){t.error("A reason is required.");return}await v(`/api/screening/ofac-cases/${encodeURIComponent(y.case_id)}/disposition`,{disposition:f,reason:_.trim()},"Disposition recorded.")&&(m(!1),R(""))},Y=(y,O)=>v(`/api/screening/ofac-cases/${encodeURIComponent(y.case_id)}/approve`,{decision:O,note:D.trim()||void 0},O==="approve"?"Disposition approved.":"Disposition rejected â returned to maker."),w=async()=>{var O;const y=p;if(!y.first_name||!y.last_name||!y.dob||!y.entity_id){t.error("First name, last name, DOB and entity ID are required.");return}b(!0);try{const q=await fetch("/api/screening/ofac-screen",{method:"POST",headers:Fe(),body:JSON.stringify(y)}),L=await q.json();if(!q.ok){t.error(L.error||`Screen failed (${q.status})`);return}L.cleared?t.success(`Cleared â no SDN match (${L.rule_id}).`):t.error(`HIT â ${((O=L.matches)==null?void 0:O.length)||0} match(es). Case ${L.case_id} opened for review.`),n(!1),N({first_name:"",last_name:"",dob:"",entity_type:"beneficial_owner",entity_id:""}),l(),!L.cleared&&L.case_id&&T(L.case_id)}catch{t.error("Network error")}finally{b(!1)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:it.map(y=>e.jsxs("button",{onClick:()=>s(y.id),className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors ${u===y.id?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[y.label,(y.id==="pending_approval"&&S.under_review,"")]},y.id||"all"))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>n(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(me,{className:"w-4 h-4"})," Run a screen"]}),e.jsxs("button",{onClick:l,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors",children:[e.jsx(ee,{className:"w-4 h-4"})," Refresh"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 ga
1p-3",children:[{k:"open",label:"Open",cls:"text-gray-700"},{k:"under_review",label:"Under Review",cls:"text-blue-600"},{k:"escalated",label:"Escalated",cls:"text-red-600"},{k:"confirmed_match",label:"Confirmed Match",cls:"text-red-700"},{k:"cleared_false_positive",label:"Cleared",cls:"text-green-600"}].map(y=>e.jsxs("div",{className:"bg-white rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:y.label}),e.jsx("p",{className:`text-xl font-bold ${y.cls}`,children:S[y.k]||0})]},y.k))}),e.jsx("div",{className:"bg-white rounded-lg border overflow-hidden",children:F?e.jsx("div",{className:"p-8 text-center text-gray-400 text-sm",children:"Loading OFAC casesâ¦"}):h.length===0?e.jsxs("div",{className:"p-8 text-center text-gray-400 text-sm",children:[e.jsx(fe,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),"No OFAC cases",u?` in "${Q(u)}"`:"",". A case opens automatically whenever a screen produces a hit."]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500 text-xs uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Entity"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Matches"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Top Score"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Stage"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Opened"}),e.jsx("th",{className:"px-4 py-2"})]})}),e.jsx("tbody",{className:"divide-y",children:h.map(y=>e.jsxs("tr",{onClick:()=>T(y.case_id),className:"hover:bg-gray-50 cursor-pointer",children:[e.jsxs("td",{className:"px-4 py-2.5",children:[e.jsx("p",{className:"font-medium text-gray-900",children:y.entity_name||y.entity_id}),e.jsx("p",{className:"text-xs text-gray-400",children:y.entity_id})]}),e.jsx("td",{className:"px-4 py-2.5 text-gray-600",children:Q(y.entity_type)}),e.jsx("td",{className:"px-4 py-2.5 text-gray-600",children:y.match_count}),e.jsx("td",{className:"px-4 py-2.5",children:Pe(y.top_match_score)}),e.jsx("td",{className:"px-4 py-2.5",children:Ie(y.review_stage)}),e.jsx("td",{className:"px-4 py-2.5 text-gray-500 text-xs",children:Re(y.created_at)}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:e.jsx(We,{className:"w-4 h-4 text-gray-300 inline"})})]},y.case_id))})]})}),o&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-start justify-center z-50 p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-2xl my-8",children:[e.jsxs("div",{className:"flex items-start justify-between p-5 border-b",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-5 h-5 text-red-500"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:o.entity_name||o.entity_id}),Ie(o.review_stage)]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:[Q(o.entity_type)," · ",o.entity_id," · case ",o.case_id]})]}),e.jsx("button",{onClick:()=>d(null),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[c&&e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}),o.top_match_score!=null&&o.top_match_score>=.8&&o.review_stage!=="closed"&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3 text-sm",children:[e.jsxs("p",{className:"font-medium text-red-800 flex items-center gap-1.5",children:[e.jsx(pe,{className:"w-4 h-4"})," Likely sanctions match"]}),e.jsxs("p",{className:"text-red-700 mt-0.5",children:["This name closely matches someone on the OFAC SDN (Specially Designated Nationals) sanctions list â ",Ne(o.top_match_score)," on the top hit. A reviewer must confirm whether it is the same individual before this entity can be cleared."]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Status"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:Q(o.status)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Matches"}),e.jsx("br",{}),e.jsxs("span",{className:"font-medium",children:[o.match_count," · top ",Ne(o.top_match_score)]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"SDN list version"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:o.sdn_list_publish_date||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Opened"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:Re(o.created_at)})]}),o.assigned_to&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Assigned to"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:o.assigned_to})]}),o.disposed_by&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Maker disposition"}),e.jsx("br",{}),e.jsxs("span",{className:"font-medium",children:[Q(o.proposed_disposition||"")," â ",o.disposed_by]})]}),o.approved_by&&e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-400",children:"Approved by (checker)"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:o.approved_by})]})]}),o.disposition_reason&&e.jsxs("div",{className:"bg-gray-50 border rounded-lg p-3 text-sm",children:[e.jsx("p",{className:"text-xs text-gray-400 mb-1",children:"Disposition rationale"}),e.jsx("p",{className:"text-gray-700",children:o.disposition_reason})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide mb-2",children:["SDN matches (",((P=o.matches)==null?void 0:P.length)||0,")"]}),e.jsx("div",{className:"space-y-1.5 max-h-52 overflow-y-auto",children:(o.matches||[]).map((y,O)=>{var q;return e.jsxs("div",{className:"flex items-center justify-between border rounded-lg px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-800",children:y.name}),e.jsxs("p",{className:"text-xs text-gray-400",children:["SDN ",y.sdn_id,(q=y.programs)!=null&&q.length?` · ${y.programs.join(", ")}`:""]})]}),Pe(y.match_score)]},`${y.sdn_id}-${O}`)})})]}),e.jsx("div",{className:"border-t pt-4 space-y-3",children:o.review_stage==="pending_approval"?a?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-amber-800 flex items-center gap-1.5",children:[e.jsx(he,{className:"w-4 h-4"})," Awaiting checker approval (four-eyes)"]}
1),e.jsxs("p",{className:"text-xs text-gray-500",children:["A reviewer has proposed a decision. As the checker you are approving the",e.jsx("em",{children:" reviewer's decision"}),", not the person. ",e.jsx("strong",{children:"Approve"})," = the reviewer got it right. ",e.jsx("strong",{children:"Reject"})," = the reviewer's decision is wrong â the case goes back to them (this does not clear the person)."]}),e.jsx("textarea",{value:D,onChange:y=>M(y.target.value),placeholder:"Checker note (recommended, especially for a reject)â¦",className:"w-full border rounded-lg px-3 py-2 text-sm",rows:2}),o.disposed_by===k?e.jsx("p",{className:"text-xs text-red-600",children:"You dispositioned this case â a different admin must approve it (four-eyes)."}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{disabled:A,onClick:()=>Y(o,"approve"),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50",children:[e.jsx(te,{className:"w-4 h-4"})," Approve ",Q(o.proposed_disposition||"")]}),e.jsxs("button",{disabled:A,onClick:()=>Y(o,"reject"),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-red-600 text-white rounded-lg hover:bg-red-700 disabled:opacity-50",children:[e.jsx(ie,{className:"w-4 h-4"})," Reject â send back to reviewer"]})]})]}):e.jsxs("p",{className:"text-sm text-amber-800 flex items-center gap-1.5",children:[e.jsx(he,{className:"w-4 h-4"})," Awaiting an admin checker's approval."]}):o.review_stage==="closed"?e.jsxs("p",{className:"text-sm text-green-700 flex items-center gap-1.5",children:[e.jsx(te,{className:"w-4 h-4"})," Case closed â ",Q(o.status),"."]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{disabled:A,onClick:()=>B(o),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 disabled:opacity-50",children:[e.jsx(rt,{className:"w-4 h-4"})," Assign to me"]}),!I&&e.jsxs("button",{disabled:A,onClick:()=>m(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(pe,{className:"w-4 h-4"})," Disposition"]})]}),I&&e.jsxs("div",{className:"border rounded-lg p-3 space-y-2 bg-gray-50",children:[e.jsx("select",{value:f,onChange:y=>g(y.target.value),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white",children:Ae.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))}),e.jsx("p",{className:"text-xs text-gray-500",children:(Z=Ae.find(y=>y.value===f))==null?void 0:Z.hint}),e.jsx("textarea",{value:_,onChange:y=>R(y.target.value),placeholder:"Reason / rationale (required) â this is the audit record.",className:"w-full border rounded-lg px-3 py-2 text-sm",rows:3}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:A,onClick:()=>se(o),className:"px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:"Submit disposition"}),e.jsx("button",{disabled:A,onClick:()=>{m(!1),R("")},className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-200 rounded-lg",children:"Cancel"})]})]})]})})]})]})}),z&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-md",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Run an OFAC screen"}),e.jsx("button",{onClick:()=>n(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{placeholder:"First name",value:p.first_name,onChange:y=>N({...p,first_name:y.target.value}),className:"border rounded-lg px-3 py-2 text-sm"}),e.jsx("input",{placeholder:"Last name",value:p.last_name,onChange:y=>N({...p,last_name:y.target.value}),className:"border rounded-lg px-3 py-2 text-sm"})]}),e.jsx("input",{type:"date",value:p.dob,onChange:y=>N({...p,dob:y.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"}
1),e.jsxs("select",{value:p.entity_type,onChange:y=>N({...p,entity_type:y.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white",children:[e.jsx("option",{value:"beneficial_owner",children:"Beneficial owner"}),e.jsx("option",{value:"landlord",children:"Landlord"}),e.jsx("option",{value:"business",children:"Business"})]}),e.jsx("input",{placeholder:"Entity ID (landlord_id / business_id / owner_id)",value:p.entity_id,onChange:y=>N({...p,entity_id:y.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"}),e.jsx("p",{className:"text-xs text-gray-400",children:"Screens against the locally-mirrored Treasury SDN list. A hit opens a review case automatically."}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{disabled:A,onClick:w,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(me,{className:"w-4 h-4"})," Run screen"]}),e.jsx("button",{onClick:()=>n(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]})]})})]})}const $e=()=>({"x-api-key":G(),"Content-Type":"application/json"}),ot=()=>({"x-api-key":G()}),dt=[{id:"",label:"All"},{id:"EFIN",label:"EFIN"},{id:"PTIN",label:"PTIN"},{id:"ERO",label:"ERO"}],xt=a=>a?new Date(a).toLocaleDateString():"â",mt=a=>a?new Date(a).toLocaleString():"â";function pt(a){const t={active:"bg-green-100 text-green-700",pending:"bg-amber-100 text-amber-800",suspended:"bg-yellow-100 text-yellow-800",expired:"bg-gray-100 text-gray-600",revoked:"bg-red-100 text-red-700"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:a})}function ht(a){const t=a==="EFIN"?"bg-blue-100 text-blue-700":a==="PTIN"?"bg-purple-100 text-purple-700":"bg-indigo-100 text-indigo-700";return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-semibold ${t}`,children:a})}function ut({isAdmin:a}){const t=J(),k=localStorage.getItem("userId")||"",[h,C]=r.useState([]),[S,E]=r.useState(!0),[F,j]=r.useState(""),[u,s]=r.useState(!1),[o,d]=r.useState(!1),[c,x]=r.useState({credential_type:"EFIN",credential_value:"",user_id:"",expires_at:"",reason:""}),A=r.useCallback(()=>{E(!0);const m=new URLSearchParams({limit:"200"});F&&m.set("type",F),fetch(`/api/tax/preparer-credentials?${m}`,{headers:ot()}).then(f=>f.json()).then(f=>C(Array.isArray(f.credentials)?f.credentials:[])).catch(()=>t.error("Failed to load preparer credentials")).finally(()=>E(!1))},[F,t]);r.useEffect(()=>{A()},[A]);const b=async()=>{const m=c.credential_value.trim();if(!m){t.error("credential_value required");return}if(c.credential_type==="PTIN"&&!c.user_id.trim()){t.error("user_id is required for a PTIN credential.");return}s(!0);try{const f={credential_type:c.credential_type,credential_value:m,reason:c.reason.trim()||void 0};c.credential_type==="PTIN"&&(f.user_id=c.user_id.trim()),c.expires_at&&(f.expires_at=new Date(c.expires_at).toISOString());const g=await fetch("/api/tax/preparer-credentials",{method:"POST",headers:$e(),body:JSON.stringify(f)}),_=await g.json();if(!g.ok){t.error(_.error||`Propose failed (${g.status})`);return}t.success("Credential proposed â a different admin must approve it before it goes live (four-eyes)."),d(!1),x({credential_type:"EFIN",credential_value:"",user_id:"",expires_at:"",reason:""}),A()}catch{t.error("Network error")}finally{s(!1)}},I=async(m,f,g)=>{s(!0);try{const _=await fetch(`/api/tax/preparer-credentials/${m.credential_id}/${f}`,{method:"POST",headers:$e(),body:JSON.stringify({reason:(g==null?void 0:g.trim())||void 0})}),R=await _.json();if(!_.ok){t.error(R.error||`${f} failed (${_.status})`);return}const D=f==="approve"?"Credential approved and activated.":f==="reject"?"Proposal rejected; placeholder removed (ledger preserves the audit trail).":"Proposal withdrawn.";t.success(D),A()}catch{t.error("Network error")}finally{s(!1)}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:dt.map(m=>e.jsx("button",{onClick:()=>j(m.id),className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors ${F===m.id?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:m.label},m.id||"all"))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>d(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(X,{className:"w-4 h-4"})," Propose new credential"]}),e.jsxs("button",{onClick:A,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200",children:[e.jsx(ee,{className:"w-4 h-4"})," Refresh"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 ga
1p-3",children:[["active","Active","text-green-600"],["pending","Pending Approval","text-amber-600"],["expired","Expired","text-gray-600"],["suspended","Suspended","text-yellow-600"],["revoked","Revoked","text-red-600"]].map(([m,f,g])=>e.jsxs("div",{className:"bg-white rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:f}),e.jsx("p",{className:`text-xl font-bold ${g}`,children:h.filter(_=>_.status===m).length})]},m))}),e.jsx("div",{className:"bg-white rounded-lg border overflow-hidden",children:S?e.jsx("div",{className:"p-8 text-center text-gray-400 text-sm",children:"Loading credentialsâ¦"}):h.length===0?e.jsxs("div",{className:"p-8 text-center text-gray-400 text-sm",children:[e.jsx(Ue,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),"No credentials",F?` of type ${F}`:""," registered. Click ",e.jsx("strong",{children:"Propose new credential"})," to register an EFIN, PTIN, or ERO.",e.jsx("br",{}),e.jsx("span",{className:"text-xs",children:"EFIN/ERO are org-level; PTIN is per individual preparer. A different admin must approve every proposal before it goes live (four-eyes)."})]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500 text-xs uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Value"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Holder"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Verified"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Expires"}),e.jsx("th",{className:"px-4 py-2 font-medium text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:h.map(m=>{const f=!!m.pending_change_action,g=m.pending_proposed_by===k;return e.jsxs("tr",{className:f?"bg-amber-50/40":"",children:[e.jsx("td",{className:"px-4 py-2.5",children:ht(m.credential_type)}),e.jsxs("td",{className:"px-4 py-2.5 text-gray-800 font-mono text-xs",children:["â¢â¢â¢â¢",m.credential_value_last4]}),e.jsx("td",{className:"px-4 py-2.5 text-gray-600 text-xs",children:m.user_id?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Xe,{className:"w-3 h-3"})," ",m.user_id]}):e.jsx("span",{className:"text-gray-400",children:"org-level"})}),e.jsxs("td",{className:"px-4 py-2.5",children:[pt(m.status),f&&e.jsxs("p",{className:"text-xs text-amber-700 mt-0.5 inline-flex items-center gap-1",children:[e.jsx(he,{className:"w-3 h-3"})," pending ",m.pending_change_action,g?" (yours)":""]})]}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:mt(m.verified_at)}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:xt(m.expires_at)}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:f?e.jsx("div",{className:"flex items-center gap-1 justify-end",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-red-600 mr-1",title:"Four-eyes: you proposed this, so a different admin must approve.",children:[e.jsx(pe,{className:"inline w-3 h-3"})," needs another admin"]}),e.jsxs("button",{disabled:u,onClick:()=>I(m,"withdraw","withdrawn by proposer"),className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-gray-700 bg-gray-100 rounded hover:bg-gray-200 disabled:opacity-50",title:"Withdraw your own proposal",children:[e.jsx(Qe,{className:"w-3 h-3"})," Withdraw"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{disabled:u,onClick:()=>{const _=window.prompt("Approval note (optional):")??void 0;I(m,"approve",_)},className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-white bg-green-600 rounded hover:bg-green-700 disabled:opacity-50",children:[e.jsx(te,{className:"w-3 h-3"})," Approve"]}),e.jsxs("button",{disabled:u,onClick:()=>{const _=window.prompt("Rejection reason:")??"";_.trim()&&I(m,"reject",_)},className:"flex items-center gap-1 px-2 py-1 text-xs font-medium text-white bg-red-600 rounded hover:bg-red-700 disabled:opacity-50",children:[e.jsx(ie,{className:"w-3 h-3"})," Reject"]})]})}):e.jsx("span",{className:"text-xs text-gray-400",children:"â"})})]},m.credential_id)})})]})}),o&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-md",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(be,{className:"w-5 h-5 text-blue-500"}),"Propose a preparer credential"]}),e.jsx("button",{onClick:()=>d(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Type"}
1),e.jsxs("select",{value:c.credential_type,onChange:m=>x({...c,credential_type:m.target.value,user_id:""}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"EFIN",children:"EFIN â firm-level e-file ID (6 digits)"}),e.jsx("option",{value:"PTIN",children:"PTIN â individual preparer ID (P + 8 digits)"}),e.jsx("option",{value:"ERO",children:"ERO â firm e-file provider attestation"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:c.credential_type==="EFIN"?"EFIN (6 digits)":c.credential_type==="PTIN"?"PTIN (e.g. P12345678)":"ERO identifier"}),e.jsx("input",{value:c.credential_value,onChange:m=>x({...c,credential_value:m.target.value}),placeholder:c.credential_type==="EFIN"?"123456":c.credential_type==="PTIN"?"P12345678":"ERO-...",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1 font-mono"})]}),c.credential_type==="PTIN"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Holder user_id"}),e.jsx("input",{value:c.user_id,onChange:m=>x({...c,user_id:m.target.value}),placeholder:"user-...",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1 font-mono"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"PTIN is tied to one preparer. EFIN/ERO are org-level."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Expires (optional â PTINs renew annually)"}),e.jsx("input",{type:"date",value:c.expires_at,onChange:m=>x({...c,expires_at:m.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Reason (optional, recorded in the ledger)"}),e.jsx("textarea",{value:c.reason,onChange:m=>x({...c,reason:m.target.value}),rows:2,placeholder:"e.g. New CPA joining the firm, IRS e-Services confirmed.",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("p",{className:"text-xs text-gray-500 bg-gray-50 border rounded p-2",children:[e.jsx("strong",{children:"Four-eyes:"})," a different admin must approve this proposal before the credential goes live. The IRS has no real-time EFIN-validation API, so approval is a maker-checker attestation."]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{disabled:u,onClick:b,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(X,{className:"w-4 h-4"})," Propose"]}),e.jsx("button",{onClick:()=>d(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]})]})})]}):e.jsx("div",{className:"bg-white rounded-lg border p-6 text-center text-gray-500",children:"Preparer-credential management is admin-only."})}const ne=()=>({"x-api-key":G(),"Content-Type":"application/json"}),Oe=()=>({"x-api-key":G()}),gt=[{id:"",label:"All"},{id:"2553",label:"Form 2553 (S-corp)"},{id:"8832",label:"Form 8832 (Classification)"}],yt=[{v:"FAX_855_887_7734",label:"Fax 855-887-7734 (CT/DE/DC/GA/IL/IN/KY/ME/MD/MA/MI/NH/NJ/NY/NC/OH/PA/RI/SC/TN/VT/VA/WV/WI)"},{v:"FAX_855_214_7520",label:"Fax 855-214-7520 (other states)"}],ft=[{v:"MAIL_OGDEN",label:"Mail to Ogden, UT 84201-0023 (most western states + military)"},{v:"MAIL_KANSAS_CITY",label:"Mail to Kansas City, MO 64999 (eastern + central states)"}],bt=[{v:"CP_261",label:"CP-261 â S-corp acceptance"},{v:"CP_262",label:"CP-262 â S-corp acceptance (variation)"},{v:"CP_277",label:"CP-277 â 8832 acceptance"},{v:"REQUEST_FOR_INFO",label:"Request for more information"},{v:"REJECTION",label:"Rejection"}],re=a=>a?new Date(a).toLocaleDateString():"â",jt=a=>a==null?"â":`${(a/100).toFixed(2)}%`;function De(a){const t={DRAFT:"bg-gray-100 text-gray-700",SIGNED:"bg-blue-100 text-blue-700",FILED:"bg-amber-100 text-amber-800",ACKED:"bg-green-100 text-green-700",ACK_LATE_REJECT:"bg-red-100 text-red-700",REJECTED:"bg-red-100 text-red-700",SUPERSEDED:"bg-gray-100 text-gray-500"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:a})}function Nt({isAdmin:a}){var L,W,ve,we,ke;const t=J(),[k,h]=r.useState([]),[C,S]=r.useState(!0),[E,F]=r.useState(""),[j,u]=r.useState(!1),[s,o]=r.useState(!1),[d,c]=r.useState({form_code:"2553",entity_type:"corporation",entity_id:"",entity_name:"",entity_ein_last4:"",effective_date:"",tax_year_first:new Date().getFullYear(),tax_year_election_cd:"CALENDAR",elected_classification_cd:"ASSOCIATION_TAXABLE_AS_CORPORATION",total_signers_required:1}),[x,A]=r.useState(null),[b,I]=r.useState([]),[m,f]=r.useState(!1),[g,_]=r.useState({signer_name:"",signer_role:"SHAREHOLDER",signer_tin_last4:"",ownership_pct_bps:1e4,shares_owned:0}),[R,D]=r.useState({}),[M,z]=r.useState(!1),[n,p]=r.useState({filing_channel:"",fax_confirmation_id:"",usps_tracking_number:""}),[N,l]=r.useState(!1),[T,v]=r.useState({irs_ack_letter_type:"CP_261",irs_assigned_effective_date:""}),B=r.useCallback(()=>{S(!0);const i=new URLSearchParams({limit:"200"});E&&i.set("form_code",E),fetch(`/api/tax/elections/filing?${i}`,{headers:Oe()}).then($=>$.json()).then($=>h(Array.isArray($.elections)?$.elections:[])).catch(()=>t.error("Failed to load elections")).finally(()=>S(!1))},[E,t]);r.useEffect(()=>{B()},[B]);const se=i=>{A(i),f(!0),fetch(`/api/tax/elections/filing?election_id=${encodeURIComponent(i.election_id)}`,{headers:Oe()}).then($=>$.json()).then($=>{$.election&&A($.election),I(Array.isArray($.signers)?$.signers:[])}).catch(()=>t.error("Failed to load detail")).finally(()=>f(!1))},Y=()=>{x&&se(x)},w=async()=>
1{if(!d.entity_id.trim()||!d.entity_name.trim()||!d.effective_date){t.error("entity_id, entity_name, effective_date all required.");return}u(!0);try{const i={form_code:d.form_code,entity_type:d.entity_type,entity_id:d.entity_id.trim(),entity_name:d.entity_name.trim(),entity_ein_last4:d.entity_ein_last4.trim()||void 0,effective_date:d.effective_date,tax_year_first:d.tax_year_first,total_signers_required:d.total_signers_required};d.form_code==="2553"&&(i.tax_year_election_cd=d.tax_year_election_cd),d.form_code==="8832"&&(i.elected_classification_cd=d.elected_classification_cd);const $=await fetch("/api/tax/elections/filing",{method:"POST",headers:ne(),body:JSON.stringify(i)}),ae=await $.json();if(!$.ok){t.error(ae.error||`Create failed (${$.status})`);return}t.success(`Form ${d.form_code} election created.`),o(!1),c({...d,entity_id:"",entity_name:"",entity_ein_last4:"",effective_date:""}),B()}finally{u(!1)}},P=async()=>{if(x){if(!g.signer_name.trim()){t.error("signer_name required");return}u(!0);try{const i=await fetch("/api/tax/elections/filing?action=add_signer",{method:"POST",headers:ne(),body:JSON.stringify({election_id:x.election_id,signer_name:g.signer_name.trim(),signer_role:g.signer_role,signer_tin_last4:g.signer_tin_last4.trim()||void 0,ownership_pct_bps:Number(g.ownership_pct_bps)||void 0,shares_owned:Number(g.shares_owned)||void 0})}),$=await i.json();if(!i.ok){t.error($.error||"Add signer failed");return}t.success(`Added ${g.signer_name}.`),_({...g,signer_name:"",signer_tin_last4:"",shares_owned:0}),Y()}finally{u(!1)}}},Z=async i=>{if(!x)return;const $=(R[i]??"").trim();if(!/^\d{5}$/.test($)){t.error("PIN must be 5 digits");return}u(!0);try{const ae=await fetch("/api/tax/elections/filing?action=sign_signer",{method:"POST",headers:ne(),body:JSON.stringify({election_id:x.election_id,signer_id:i,consent_pin:$})}),Ce=await ae.json();if(!ae.ok){t.error(Ce.error||"Sign failed");return}t.success(Ce.ec_status==="SIGNED"?"Signed â all signers have consented; election is now SIGNED.":"Signed."),D({...R,[i]:""}),Y(),B()}finally{u(!1)}},y=async()=>{if(x){if(!n.filing_channel){t.error("filing_channel required");return}u(!0);try{const i=await fetch("/api/tax/elections/filing?action=mark_filed",{method:"POST",headers:ne(),body:JSON.stringify({election_id:x.election_id,filing_channel:n.filing_channel,fax_confirmation_id:n.fax_confirmation_id||void 0,usps_tracking_number:n.usps_tracking_number||void 0})}),$=await i.json();if(!i.ok){t.error($.error||"Mark filed failed");return}t.success("Election marked FILED."),z(!1),Y(),B()}finally{u(!1)}}},O=async()=>{if(x){u(!0);try{const i=await fetch("/api/tax/elections/filing?action=mark_acked",{method:"POST",headers:ne(),body:JSON.stringify({election_id:x.election_id,irs_ack_letter_type:T.irs_ack_letter_type,irs_assigned_effective_date:T.irs_assigned_effective_date||void 0})}),$=await i.json();if(!i.ok){t.error($.error||"Mark acked failed");return}const ae=$.status;t.success(ae==="REJECTED"?"Election marked REJECTED.":"Election marked ACKED."),l(!1),Y(),B()}finally{u(!1)}}};if(!a)return e.jsx("div",{className:"bg-white rounded-lg border p-6 text-center text-gray-500",children:"Entity-election management is admin-only."});const q=(x==null?void 0:x.form_code)==="2553"?yt:ft;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:gt.map(i=>e.jsx("button",{onClick:()=>F(i.id),className:`px-3 py-1.5 text-sm font-medium rounded-lg transition-colors ${E===i.id?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:i.label},i.id||"all"))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(X,{className:"w-4 h-4"})," New election"]}),e.jsxs("button",{onClick:B,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200",children:[e.jsx(ee,{className:"w-4 h-4"})," Refresh"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3",children:["DRAFT","SIGNED","FILED","ACKED","REJECTED","SUPERSEDED"].map(i=>e.jsxs("div",{className:"bg-white rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:i.replace(/_/g," ").toLowerCase()}),e.jsx("p",{className:"text-xl font-bold text-gray-800",children:k.filter($=>$.status===i).length})]},i))}),e.jsx("div",{className:"bg-white rounded-lg border overflow-hidden",children:C?e.jsx("div",{className:"p-8 text-center text-gray-400 text-sm",children:"Loading electionsâ¦"}):k.length===0?e.jsxs("div",{className:"p-8 text-center text-gray-400 text-sm",children:[e.jsx(Se,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),"No elections registered. Click ",e.jsx("strong",{children:"New election"})," to file a Form 2553 (S-corp election) or Form 8832 (entity classification).",e.jsx("p",{className:"text-xs mt-1",children:"Both forms are paper / fax f
1ilings per IRS Pub 4163. The platform tracks the lifecycle but the operator does the actual mailing or faxing."})]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500 text-xs uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Form"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Entity"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Effective"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Filed"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"IRS Ack"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:k.map(i=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("span",{className:"font-mono text-xs",children:["Form ",i.form_code]})}),e.jsxs("td",{className:"px-4 py-2.5",children:[e.jsx("p",{className:"font-medium text-gray-900",children:i.entity_name}),e.jsxs("p",{className:"text-xs text-gray-400",children:[i.entity_type," · ",i.entity_id]})]}),e.jsxs("td",{className:"px-4 py-2.5 text-xs text-gray-600",children:[re(i.effective_date),e.jsx("br",{}),e.jsxs("span",{className:"text-gray-400",children:["TY",i.tax_year_first]})]}),e.jsx("td",{className:"px-4 py-2.5",children:De(i.status)}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:i.filing_channel?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-700",children:i.filing_channel.replace(/_/g," ")}),e.jsx("br",{}),e.jsx("span",{className:"text-gray-400",children:re(i.filed_at)})]}):"â"}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:i.irs_ack_letter_type?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-700",children:i.irs_ack_letter_type.replace("_","-")}),e.jsx("br",{}),e.jsx("span",{className:"text-gray-400",children:re(i.irs_ack_received_at)})]}):"â"}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:e.jsx("button",{onClick:()=>se(i),className:"text-blue-600 hover:underline text-xs font-medium",children:"Open â"})})]},i.election_id))})]})}),s&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-lg",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 border-b",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(Ze,{className:"w-5 h-5 text-blue-500"})," New entity election"]}),e.jsx("button",{onClick:()=>o(!1),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Form"}),e.jsxs("select",{value:d.form_code,onChange:i=>c({...d,form_code:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"2553",children:"2553 â S-corp election"}),e.jsx("option",{value:"8832",children:"8832 â Entity classification"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Entity type"}),e.jsxs("select",{value:d.entity_type,onChange:i=>c({...d,entity_type:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"corporation",children:"Corporation"}),e.jsx("option",{value:"partnership",children:"Partnership"}),e.jsx("option",{value:"llc",children:"LLC"}),e.jsx("option",{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Entity ID"}),e.jsx("input",{value:d.entity_id,onChange:i=>c({...d,entity_id:i.target.value}),placeholder:"corp-...",className:"w-full border rounded-lg px-3 py-2 text-sm font-mono mt-1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"EIN last 4 (optional)"}),e.jsx("input",{value:d.entity_ein_last4,onChange:i=>c({...d,entity_ein_last4:i.target.value}),placeholder:"0000",maxLength:4,className:"w-full border rounded-lg px-3 py-2 text-sm font-mono mt-1"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Entity name"}),e.jsx("input",{value:d.entity_name,onChange:i=>c({...d,entity_name:i.target.value}),placeholder:"ACME Holdings Inc",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Effective date"}),e.jsx("input",{type:"date",value:d.effective_date,onChange:i=>c({...d,effective_date:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"First tax year"}),e.jsx("input",{type:"number",value:d.tax_year_first,onChange:i=>c({...d,tax_year_first:Number(i.target.value)}),min:2020,max:2099,className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]})]}),d.form_code==="2553"?e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Tax-year selection (2553 Box F)"}),e.jsxs("select",{value:d.tax_year_election_cd,onChange:i=>c({...d,tax_year_election_cd:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"CALENDAR",children:"Calendar year"}),e.jsx("option",{value:"NATURAL",children:"Natural business year"}),e.jsx("option",{value:"OWNER",children:"Ownership tax year"}),e.jsx("option",{value:"SECTION_444",children:"§444 fiscal year election"})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Elected classification (8832 line 6)"}),e.jsxs("select",{value:d.elected_classification_cd,onChange:i=>c({...d,elected_classification_cd:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"ASSOCIATION_TAXABLE_AS_CORPORATION",children:"Association taxable as corporation"}),e.jsx("option",{value:"PARTNERSHIP",children:"Partnership"}),e.jsx("option",{value:"DISREGARDED_ENTITY",children:"Disregarded entity"}),e.jsx("option",{value:"FOREIGN_ELIGIBLE_ENTITY",children:"Foreign eligible entity"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Number of signers required"}),e.jsx("input",{type:"number",min:1,value:d.total_signers_required,onChange:i=>c({...d,total_signers_required:Math.max(1,Number(i.target.value))}),className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"2553 requires every shareholder; 8832 requires every member or an authorized officer."})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{disabled:j,onClick:w,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:[e.jsx(X,{className:"w-4 h-4"})," Create"]}),e.jsx("button",{onClick:()=>o(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]})]})}),x&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-start justify-center z-50 p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-3xl my-8",children:[e.jsxs("div",{className:"flex items-start justify-between p-5 border-b",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"w-5 h-5 text-blue-500"}),e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Form ",x.form_code," â ",x.entity_name]}),De(x.status)]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:[x.entity_type," · ",x.entity_id," · effective ",re(x.effective_date)," · TY",x.tax_year_first]})]}),e.jsx("button",{onClick:()=>A(null),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[m&&e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide mb-2 flex items-center gap-1.5",children:[e.jsx(et,{className:"w-3.5 h-3.5"})," Signers (",b.length," added · ",b.filter(i=>i.signed_at).length," signed / ",x.total_signers_required??1," required)"]}),b.length>0&&e.jsx("div",{className:"border rounded-lg overflow-x-auto mb-2",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"Name"}),e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"Role"}),e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"Ownership"}),e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"SSN/TIN"}),e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"Signed"}),e.jsx("th",{className:"text-left px-3 py-1.5 font-medium",children:"PIN"})]})}),e.jsx("tbody",{className:"divide-y",children:b.map(i=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-1.5 text-gray-800",children:i.signer_name}),e.jsx("td",{className:"px-3 py-1.5 text-gray-600",children:i.signer_role}),e.jsxs("td",{className:"px-3 py-1.5 text-gray-600",children:[jt(i.ownership_pct_bps),i.shares_owned?` · ${i.shares_owned} sh`:""]}),e.jsx("td",{className:"px-3 py-1.5 text-gray-500 font-mono",children:i.signer_tin_last4?`â¢â¢â¢ ${i.signer_tin_last4}`:"â"}),e.jsx("td",{className:"px-3 py-1.5",children:i.signed_at?e.jsxs("span",{className:"inline-flex items-center gap-1 text-green-700",children:[e.jsx(te,{className:"w-3 h-3"}
1)," ",new Date(i.signed_at).toLocaleString()]}):e.jsx("span",{className:"text-amber-700",children:"unsigned"})}),e.jsx("td",{className:"px-3 py-1.5",children:i.signed_at?e.jsx("span",{className:"text-gray-400",children:"â"}):e.jsxs("div",{className:"flex gap-1",children:[e.jsx("input",{autoComplete:"new-password","data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",type:"password",value:R[i.signer_id]??"",onChange:$=>D({...R,[i.signer_id]:$.target.value}),placeholder:"5-digit PIN",maxLength:5,className:"w-24 border rounded px-2 py-0.5 text-xs font-mono"}),e.jsx("button",{disabled:j,onClick:()=>Z(i.signer_id),className:"px-2 py-0.5 text-xs font-medium bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50",children:"Sign"})]})})]},i.signer_id))})]})}),(x.status==="DRAFT"||x.status==="SIGNED")&&e.jsx("div",{className:"border rounded-lg p-3 bg-gray-50 space-y-2",children:e.jsxs("div",{className:"grid grid-cols-12 gap-2",children:[e.jsx("input",{className:"col-span-3 border rounded px-2 py-1 text-xs",placeholder:"Name",value:g.signer_name,onChange:i=>_({...g,signer_name:i.target.value})}),e.jsxs("select",{className:"col-span-2 border rounded px-2 py-1 text-xs bg-white",value:g.signer_role,onChange:i=>_({...g,signer_role:i.target.value}),children:[e.jsx("option",{value:"SHAREHOLDER",children:"Shareholder"}),e.jsx("option",{value:"MEMBER",children:"Member"}),e.jsx("option",{value:"OFFICER",children:"Officer"}),e.jsx("option",{value:"PARTNER",children:"Partner"}),e.jsx("option",{value:"FIDUCIARY",children:"Fiduciary"})]}),e.jsx("input",{className:"col-span-2 border rounded px-2 py-1 text-xs font-mono",placeholder:"TIN last4",maxLength:4,value:g.signer_tin_last4,onChange:i=>_({...g,signer_tin_last4:i.target.value})}),e.jsx("input",{className:"col-span-2 border rounded px-2 py-1 text-xs",placeholder:"bps (e.g. 6000=60%)",type:"number",value:g.ownership_pct_bps,onChange:i=>_({...g,ownership_pct_bps:Number(i.target.value)})}),e.jsx("input",{className:"col-span-2 border rounded px-2 py-1 text-xs",placeholder:"shares",type:"number",value:g.shares_owned,onChange:i=>_({...g,shares_owned:Number(i.target.value)})}),e.jsx("button",{disabled:j,onClick:P,className:"col-span-1 px-2 py-1 text-xs font-medium bg-gray-700 text-white rounded hover:bg-gray-800 disabled:opacity-50",children:"Add"})]})})]}),e.jsxs("div",{className:"border-t pt-4 space-y-3",children:[x.status==="SIGNED"&&e.jsxs("button",{onClick:()=>z(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-amber-600 text-white rounded-lg hover:bg-amber-700",children:[e.jsx(tt,{className:"w-4 h-4"})," Mark filed (operator must fax or mail)"]}),x.status==="FILED"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm text-amber-800 flex items-center gap-1.5",children:[e.jsx(he,{className:"w-4 h-4"})," Awaiting IRS acknowledgment letter",(L=x.filing_channel)!=null&&L.startsWith("FAX_")?" (typically 60 days for 2553 acceptance â CP-261 / CP-262).":" (typically 60-90 days for 8832 acceptance â CP-277)."]}),e.jsxs("button",{onClick:()=>l(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-green-600 text-white rounded-lg hover:bg-green-700",children:[e.jsx(Be,{className:"w-4 h-4"})," Record IRS letter"]})]}),(x.status==="ACKED"||x.status==="REJECTED")&&e.jsx("p",{className:"text-sm text-gray-600 flex items-center gap-1.5",children:x.status==="ACKED"?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-4 h-4 text-green-600"})," Election complete â ",(W=x.irs_ack_letter_type)==null?void 0:W.replace("_","-")," on ",re(x.irs_ack_received_at),"."]}):e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 text-red-600"})," Election rejected â ",(ve=x.irs_ack_letter_type)==null?void 0:ve.replace("_","-")," on ",re(x.irs_ack_received_at),"."]})})]}),M&&e.jsxs("div",{className:"border rounded-lg p-4 bg-amber-50 space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-amber-900",children:["Mark Form ",x.form_code," filed"]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Filing channel"}),e.jsxs("select",{value:n.filing_channel,onChange:i=>p({...n,filing_channel:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:[e.jsx("option",{value:"",children:"â select â"}),q.map(i=>e.jsx("option",{value:i.v,children:i.label},i.v))]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"2553 must be faxed; 8832 must be mailed. The server enforces this."})]}),((we=n.filing_channel)==null?void 0:we.startsWith("FAX_"))&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Fax confirmation ID (optional)"}),e.jsx("input",{value:n.fax_confirmation_id,onChange:i=>p({...n,fax_confirmation_id:i.target.value}),placeholder:"from the fax-machine receipt",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),((ke=n.filing_channel)==null?void 0:ke.startsWith("MAIL_"))&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"USPS tracking number (optional)"}),e.jsx("input",{value:n.usps_tracking_number,onChange:i=>p({...n,usps_tracking_number:i.target.value}),placeholder:"9400 ...",className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:j,onClick:y,className:"px-3 py-1.5 text-sm font-medium bg-amber-600 text-white rounded-lg hover:bg-amber-700 disabled:opacity-50",children:"Mark filed"}),e.jsx("button",{onClick:()=>z(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]}),N&&e.jsxs("div",{className:"border rounded-lg p-4 bg-green-50 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-green-900",children:"Record IRS letter"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Letter type"}
1),e.jsx("select",{value:T.irs_ack_letter_type,onChange:i=>v({...T,irs_ack_letter_type:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm bg-white mt-1",children:bt.map(i=>e.jsx("option",{value:i.v,children:i.label},i.v))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"IRS-assigned effective date (if different)"}),e.jsx("input",{type:"date",value:T.irs_assigned_effective_date,onChange:i=>v({...T,irs_assigned_effective_date:i.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:j,onClick:O,className:"px-3 py-1.5 text-sm font-medium bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50",children:"Record"}),e.jsx("button",{onClick:()=>l(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]})]})]})})]})}const oe=()=>({"x-api-key":G(),"Content-Type":"application/json"}),Le=()=>({"x-api-key":G()}),_t=[{id:"",label:"All"},{id:"DRAFT",label:"Draft"},{id:"TAXPAYER_SIGNED",label:"Taxpayer signed"},{id:"FULLY_SIGNED",label:"Fully signed"},{id:"ARCHIVED",label:"Archived"},{id:"VOIDED",label:"Voided"}],vt=a=>a==null?"â":`$${(Number(a)/100).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,Me=a=>a?new Date(a).toLocaleDateString():"â",de=a=>a?new Date(a).toLocaleString():"â";function ze(a){const t={DRAFT:"bg-gray-100 text-gray-700",TAXPAYER_SIGNED:"bg-blue-100 text-blue-700",FULLY_SIGNED:"bg-green-100 text-green-700",ARCHIVED:"bg-gray-100 text-gray-500",VOIDED:"bg-red-100 text-red-700"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:a.replace(/_/g," ").toLowerCase()})}function wt(a){switch(a.form_variant){case"8879":return[{label:"AGI (line 1)",value:a.agi_cents},{label:"Total tax (line 2)",value:a.total_tax_cents},{label:"FIT withheld (line 3)",value:a.fit_withheld_cents},{label:"Refund (line 4)",value:a.refund_cents},{label:"Amount owed (line 5)",value:a.amount_owed_cents}];case"8879-F":return[{label:"Total tax",value:a.total_tax_cents}];case"8879-PE":case"8879-S":return[{label:"Gross receipts (line 1)",value:a.gross_receipts_cents},{label:"Ordinary business income (line 3)",value:a.ordinary_business_income_cents}];case"8879-C":return[{label:"Total income (line 1)",value:a.gross_receipts_cents},{label:"Taxable income (line 2)",value:a.taxable_income_cents},{label:"Total tax (line 3)",value:a.total_tax_cents}];case"8879-TE":return[{label:"Total revenue",value:a.total_revenue_cents}];case"8879-EMP":return[{label:"Total taxes (employment)",value:a.total_taxes_employment_cents}];default:return[]}}function kt({isAdmin:a}){var Y;const t=J(),[k,h]=r.useState([]),[C,S]=r.useState(!0),[E,F]=r.useState(""),[j,u]=r.useState(!1),[s,o]=r.useState(null),[d,c]=r.useState(""),[x,A]=r.useState(!1),[b,I]=r.useState(!1),[m,f]=r.useState(""),[g,_]=r.useState(!1),[R,D]=r.useState(null),[M,z]=r.useState(!1),[n,p]=r.useState(""),N=r.useCallback(()=>{S(!0);const w=new URLSearchParams({limit:"200"});E&&w.set("status",E),fetch(`/api/tax/form-8879?${w}`,{headers:Le()}).then(P=>P.json()).then(P=>h(Array.isArray(P.authorizations)?P.authorizations:[])).catch(()=>t.error("Failed to load Form 8879 authorizations")).finally(()=>S(!1))},[E,t]);r.useEffect(()=>{N()},[N]);const l=async()=>{if(!s)return;const P=await(await fetch(`/api/tax/form-8879?authorization_id=${encodeURIComponent(s.authorization_id)}`,{headers:Le()})).json();P.authorization&&o(P.authorization),N()},T=async()=>{if(s){if(!/^\d{5}$/.test(d)){t.error("PIN must be 5 digits.");return}u(!0);try{const w=await fetch("/api/tax/form-8879?action=sign_taxpayer",{method:"POST",headers:oe(),body:JSON.stringify({authorization_id:s.authorization_id,taxpayer_pin:d,taxpayer_dob_match:x})}),P=await w.json();if(!w.ok){t.error(P.error||"Sign failed");return}t.success("Taxpayer signature captured. Awaiting ERO countersignature."),c(""),A(!1),await l()}finally{u(!1)}}},v=async()=>
1{if(s){if(!m){t.error("retained_until required (IRS Pub 1345 = 3 yrs from due/file date)");return}u(!0);try{const w=await fetch("/api/tax/form-8879?action=countersign_ero",{method:"POST",headers:oe(),body:JSON.stringify({authorization_id:s.authorization_id,retained_until:new Date(m).toISOString()})}),P=await w.json();if(!w.ok){t.error(P.error||`Countersign failed (${P.code??w.status})`);return}t.success("ERO countersignature captured. Form 8879 is fully signed."),I(!1),f(""),await l()}finally{u(!1)}}},B=async()=>{var w;if(!s||!R){t.error("Select a PDF file first");return}if(R.size>10*1024*1024){t.error("PDF exceeds 10 MiB");return}u(!0);try{const P=await R.arrayBuffer();let Z="";const y=new Uint8Array(P);for(let W=0;W<y.length;W++)Z+=String.fromCharCode(y[W]);const O=btoa(Z),q=await fetch(`/api/tax/form-8879/${encodeURIComponent(s.authorization_id)}/upload-pdf`,{method:"POST",headers:oe(),body:JSON.stringify({pdf_base64:O})}),L=await q.json();if(!q.ok){t.error(L.error||`Upload failed (${q.status})`);return}t.success(`PDF uploaded â ${L.document_bytes} bytes, sha256 ${(w=L.document_sha256)==null?void 0:w.slice(0,8)}â¦`),_(!1),D(null),await l()}catch(P){t.error("Upload failed: "+((P==null?void 0:P.message)??P))}finally{u(!1)}},se=async()=>{if(!s||!n.trim()){t.error("Reason required");return}u(!0);try{const w=await fetch("/api/tax/form-8879?action=void",{method:"POST",headers:oe(),body:JSON.stringify({authorization_id:s.authorization_id,reason:n.trim()})}),P=await w.json();if(!w.ok){t.error(P.error||"Void failed");return}t.success("Authorization voided."),z(!1),p(""),o(null),N()}finally{u(!1)}};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1",children:_t.map(w=>e.jsx("button",{onClick:()=>F(w.id),className:`px-3 py-1.5 text-sm font-medium rounded-lg ${E===w.id?"bg-blue-600 text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:w.label},w.id||"all"))}),e.jsxs("button",{onClick:N,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200",children:[e.jsx(ee,{className:"w-4 h-4"})," Refresh"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-3",children:["DRAFT","TAXPAYER_SIGNED","FULLY_SIGNED","ARCHIVED","VOIDED"].map(w=>e.jsxs("div",{className:"bg-white rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:w.replace(/_/g," ").toLowerCase()}),e.jsx("p",{className:"text-xl font-bold text-gray-800",children:k.filter(P=>P.status===w).length})]},w))}),e.jsx("div",{className:"bg-white rounded-lg border overflow-hidden",children:C?e.jsx("div",{className:"p-8 text-center text-gray-400 text-sm",children:"Loading authorizationsâ¦"}):k.length===0?e.jsxs("div",{className:"p-8 text-center text-gray-400 text-sm",children:[e.jsx(be,{className:"w-8 h-8 mx-auto mb-2 text-gray-300"}),"No Form 8879 authorizations yet. They're auto-created when a corporate return passes the four-eyes approve_submit transition, and can also be created manually via the API.",e.jsx("p",{className:"text-xs mt-1",children:"IRS Pub 1345 requires the ERO to retain the signed 8879 for 3 years from the later of the due date or filing date."})]}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-500 text-xs uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Variant / Return"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Taxpayer"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Year"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Taxpayer signed"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"ERO signed"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Retained until"}),e.jsx("th",{className:"text-right px-4 py-2 font-medium",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:k.map(w=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsxs("td",{className:"px-4 py-2.5",children:[e.jsx("p",{className:"font-mono text-xs text-blue-700",children:w.form_variant}),e.jsxs("p",{className:"text-xs text-gray-400",children:["Form ",w.return_kind.toUpperCase()]})]}),e.jsxs("td",{className:"px-4 py-2.5",children:[e.jsx("p",{className:"text-gray-800",children:w.taxpayer_name}),e.jsxs("p",{className:"text-xs text-gray-400 font-mono",children:["â¢â¢â¢ ",w.taxpayer_tin_last4,w.taxpayer_title?` · ${w.taxpayer_title}`:""]})]}),e.jsx("td",{className:"px-4 py-2.5 text-gray-600",children:w.tax_year}),e.jsx("td",{className:"px-4 py-2.5",children:ze(w.status)}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:de(w.taxpayer_signed_at)}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:de(w.ero_signed_at)}),e.jsx("td",{className:"px-4 py-2.5 text-xs text-gray-500",children:Me(w.retained_until)}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:e.jsx("button",{onClick:()=>o(w),className:"text-blue-600 hover:underline text-xs font-medium",children:"Open â"})})]},w.authorization_id))})]})}),s&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-start justify-center z-50 p-4 overflow-y-auto",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-2xl my-8",children:[e.jsxs("div",{className:"flex items-start justify-between p-5 border-b",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"w-5 h-5 text-blue-500"}),e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:["Form ",s.form_variant," â ",s.taxpayer_name]}),ze(s.status)]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:["Form ",s.return_kind.toUpperCase()," · TY",s.tax_year," · â¢â¢â¢ ",s.taxpayer_tin_last4,s.taxpayer_title?` · ${s.taxpayer_title}`:""]})]}),e.jsx("button",{onClick:()=>o(null),className:"text-gray-400 hover:text-gray-600",children:e.jsx(le,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 uppercase tracking-wide mb-2",children:"Part II â return totals"}),e.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-1.5 text-sm",children:wt(s).map((w,P)=>e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-400",children:w.label}),e.jsx("p",{className:"font-mono font-medium",children:vt(w.value)})]},P))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm border-t pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Taxpayer / officer"}),e.jsx("p",{children:s.taxpayer_name}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Method: ",s.taxpayer_signature_method.replace(/_/g," ").toLowerCase()]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Signed: ",de(s.taxpayer_signed_at)]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-400",children:"ERO / preparer"}),e.jsx("p",{children:s.ero_signer_name}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Signed: ",de(s.ero_signed_at)]})]})]}),s.document_storage_key?e.jsxs("div",{className:"border rounded-lg p-3 bg-green-50 text-sm",children:[e.jsxs("p",{className:"font-medium text-green-900 flex items-center gap-1.5",children:[e.jsx(lt,{className:"w-4 h-4"})," Signed PDF on file"]}),e.jsxs("p",{className:"text-xs text-gray-600 mt-1",children:["R2 key: ",e.jsx("span",{className:"font-mono",children:s.document_storage_key})]}),e.jsxs("p",{className:"text-xs text-gray-600",children:["SHA-256: ",e.jsxs("span",{className:"font-mono",children:[(Y=s.document_sha256)==null?void 0:Y.slice(0,16),"â¦"]})]}),e.jsxs("p",{className:"text-xs text-gray-600",children:["Size: ",Number(s.document_bytes??0).toLocaleStr
1ing()," bytes · Retained until: ",Me(s.retained_until)]})]}):s.status==="FULLY_SIGNED"?e.jsxs("div",{className:"border rounded-lg p-3 bg-amber-50 text-sm",children:[e.jsx("p",{className:"font-medium text-amber-900",children:"Awaiting PDF upload"}),e.jsx("p",{className:"text-xs text-gray-600",children:'Click "Upload PDF" to retain the signed document for the Pub 1345 3-year clock.'})]}):null,e.jsxs("div",{className:"border-t pt-4 space-y-2",children:[s.status==="DRAFT"&&e.jsxs("div",{className:"border rounded-lg p-3 bg-gray-50 space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-gray-800 flex items-center gap-1.5",children:[e.jsx(je,{className:"w-4 h-4"})," Taxpayer signature (Self-Select or Practitioner PIN)"]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{autoComplete:"new-password","data-lpignore":"true","data-1p-ignore":"true","data-form-type":"other",type:"password",maxLength:5,value:d,onChange:w=>c(w.target.value),placeholder:"5-digit PIN",className:"w-32 border rounded px-3 py-1.5 text-sm font-mono"}),s.taxpayer_signature_method==="SELF_SELECT_PIN"&&e.jsxs("label",{className:"text-xs text-gray-600 flex items-center gap-1",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:w=>A(w.target.checked)}),"AGI + DOB shared-secret matched"]}),e.jsx("button",{disabled:j,onClick:T,className:"px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:"Sign"})]})]}),s.status==="TAXPAYER_SIGNED"&&e.jsx(e.Fragment,{children:b?e.jsxs("div",{className:"border rounded-lg p-3 bg-blue-50 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-blue-900",children:"ERO countersignature"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-gray-600",children:"Retained until (IRS Pub 1345: 3 years from MAX(due date, filing date))"}),e.jsx("input",{type:"date",value:m,onChange:w=>f(w.target.value),className:"w-full border rounded-lg px-3 py-2 text-sm mt-1"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Server enforces variant-specific Part II totals â any missing required value returns 412 MISSING_TOTAL."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:j,onClick:v,className:"px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:"Countersign"}),e.jsx("button",{onClick:()=>I(!1),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]}):e.jsxs("button",{onClick:()=>I(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(je,{className:"w-4 h-4"})," ERO countersign"]})}),s.status==="FULLY_SIGNED"&&!s.document_storage_key&&e.jsx(e.Fragment,{children:g?e.jsxs("div",{className:"border rounded-lg p-3 bg-blue-50 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-blue-900",children:"Upload signed PDF to R2"}),e.jsx("input",{type:"file",accept:"application/pdf",onChange:w=>{var P;return D(((P=w.target.files)==null?void 0:P[0])??null)},className:"w-full text-sm"}),R&&e.jsxs("p",{className:"text-xs text-gray-600",children:[R.name," · ",(R.size/1024).toFixed(1)," KB"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:j||!R,onClick:B,className:"px-3 py-1.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:"Upload"}),e.jsx("button",{onClick:()=>{_(!1),D(null)},className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]}):e.jsxs("button",{onClick:()=>_(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium bg-green-600 text-white rounded-lg hover:bg-green-700",children:[e.jsx(st,{className:"w-4 h-4"})," Upload signed PDF"]})}),s.status!=="VOIDED"&&e.jsx(e.Fragment,{children:M?e.jsxs("div",{className:"border rounded-lg p-3 bg-red-50 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-red-900",children:"Void authorization"}),e.jsx("textarea",{value:n,onChange:w=>p(w.target.value),rows:2,placeholder:"Reason (recorded in audit log)",className:"w-full border rounded-lg px-3 py-2 text-sm"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:j,onClick:se,className:"px-3 py-1.5 text-sm font-medium bg-red-600 text-white rounded-lg hover:bg-red-700 disabled:opacity-50",children:"Void"}),e.jsx("button",{onClick:()=>{z(!1),p("")},className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:bg-gray-100 rounded-lg",children:"Cancel"})]})]}):e.jsxs("button",{onClick:()=>z(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-700 hover:bg-red-50 rounded-lg",children:[e.jsx(ie,{className:"w-3 h-3"})," Void"]})})]}),s.status==="FULLY_SIGNED"&&e.jsxs("p",{className:"text-xs text-gray-500 flex items-center gap-1 border-t pt-3",children:[e.jsx(te,{className:"w-3 h-3 text-green-600"})," Both signatures captured. The return can be e-file-transmitted whenever the operator is ready."]})]})]})})]}):e.jsx("div",{className:"bg-white rounded-lg border p-6 text-center text-gray-500",children:"Form 8879 review is admin-only."})}const xe=()=>({"x-api-key":G(),"Content-Type":"application/json"}),Ct=()=>({"x-api-key":G()}),ye=[{id:"fed_2848",label:"Form 2848 (POA)",desc:"Power of Attorney â full representation rights",needs_rep:!0},{id:"fed_8821",label:"Form 8821 (TIA)",desc:"Tax Information Authorization â read-only",needs_rep:!0},{id:"fed_1310",label:"Form 1310 (Refund)",desc:"Claiming refund for deceased taxpayer",needs_rep:!0},{id:"fed_9000",label:"Form 9000 (Alt Media)",desc:"Alternative media preference (accessibility)",needs_rep:!1}];function St(a){const t={DRAFT:"bg-gray-100 text-gray-700",SIGNED:"bg-cyan-50 text-cyan-700",FILED_WITH_IRS:"bg-blue-50 text-blue-700",ACTIVE:"bg-green-100 text-green-700",REVOKED:"bg-red-100 text-red-700",EXPIRED:"bg-amber-50 text-amber-700",SUPERSEDED:"bg-gray-100 text-gray-500"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]??"bg-gray-100 text-gray-600"}`,children:a})}function Et({isAdmin:a}){const t=J(),[k,h]=r.useState(""),[C,S]=r.useState([]),[E,F]=r.useState(!0),[j,u]=r.useState(!1),[s,o]=r.useState(!1),[d,c]=r.useState({}),[x,A]=r.useState(null),[b,I]=r.useState(""),[m,f]=r.useState(null),[g,_]=r.useState(""),R=r.useCallback(async()=>{F(!0);try{const l=k?`?form_code=${k}`:"",T=await fetch(`/api/tax/authorizations${l}`,{headers:Ct()}),v=await T.json();if(!T.ok)throw new Error(v.error||"Load failed");S(v.authorizations??[])}catch(l){t.error((l==null?void 0:l.message)||"Load failed")}finally{F(!1)}},[k,t]);r.useEffect(()=>{R()},[R]);const D=async()=>{o(!0);try{const l=await fetch("/api/tax/authorizations",{method:"POST",headers:xe(),body:JSON.stringify(d)}),T=await l.json();if(!l.ok){if(T.code==="DUPLICATE_AUTHORIZATION"){t.error(T.error);return}throw new Error(T.error||"Create failed")}t.success("Authorization created."),u(!1),c({}),await R()}catch(l){t.error((l==null?void 0:l.message)||"Create failed")}finally{o(!1)}},M=async l=>{o(!0);try{const T=await fetch("/api/tax/authorizations?action=sign",{method:"POST",headers:xe(),body:JSON.stringify({authorization_id:l})}),v=await T.json();if(!T.ok)throw new Error(v.error||"Sign failed");t.success("Authorization signed."),await R()}catch(T){t.error((T==null?void 0:T.message)||"Sign failed")}finally{o(!1)}},z=async l=>{if(!b.trim()){t.error("CAF letter reference required");return}o(!0);try{const T=await fetch("/api/tax/authorizations?action=record_caf",{method:"POST",headers:xe(),body:JSON.stringify({authorization_id:l,caf_letter_ref:b.trim()})}),v=await T.json();if(!T.ok)throw new Error(v.error||"Record CAF failed");t.success("CAF recorded â authorization ACTIVE."),A(null),I(""),await R()}catch(T){t.error((T==null?void 0:T.message)||"Record CAF failed")}finally{o(!1)}},n=async l=>{if(g.trim().length<5){t.error("Reason required (â¥5 chars)");return}o(!0);try{const T=await fetch("/api/tax/authorizations?action=revoke",{method:"POST",headers:xe(),body:JSON.stringify({authorization_id:l,revoked_reason:g.trim()})}),v=await T.json();if(!T.ok)throw new Error(v.error||"Revoke failed");t.success("Authorization revoked."),f(null),_(""),await R()}catch(T){t.error((T==null?void 0:T.message)||"Revoke failed")}finally{o(!1)}},p=(l,T)=>c({...d,[l]:T}),N=ye.find(l=>l.id===d.form_code);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>h(""),className:`px-3 py-1.5 text-xs rounded-md font-medium ${k===""?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:"All"}),ye.map(l=>e.jsx("button",{onClick:()=>h(l.id),className:`px-3 py-1.5 text-xs rounded-md font-medium ${k===l.id?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:l.label},l.id)),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>{c({form_code:"fed_2848"}),u(!0)},className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded-md bg-blue-600 text-white hover:bg-blue-700",children:[e.jsx(X,{className:"w-3 h-3"})," New authorization"]}),e.jsxs("button",{onClick:R,className:"inline-flex items-center gap-1 px-3 py-1.5 text-xs rounded-md border border-gray-300 hover:bg-gray-50",children:[e.jsx(ee,{className:`w-3 h-3 ${E?"animate-spin":""}`})," Refresh"]})]}),E?e.jsx("p",{className:"text-sm text-gray-500 italic py-12 text-center",children:"Loadingâ¦"}):C.length===0?e.jsx("p",{className:"text-sm text-gray-500 italic py-12 text-center",children:"No authorizations yet."}):e.jsx("div",{className:"border border-gray-200 rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-600 uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-2",children:"Form"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Taxpayer"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Representative"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Years"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Status"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Actions"})]})}),e.jsx("tbody",{children:C.map(l=>e.jsxs("tr",{className:"border-t border-gray-100 hover:bg-gray-50",children:[e.jsx("td",{className:"px-3 py-2 font-mono text-[10px]",children:l.form_code.replace("fed_","")}),e.jsxs("td",{className:"px-3 py-2",children:[l.taxpayer_first_name," ",l.taxpayer_last_name,l.taxpayer_tin_last4&&e.jsxs("span",{className:"text-[10px] text-gray-400",children:[" ···",l.taxpayer_tin_last4]})]}),e.jsxs("td",{className:"px-3 py-2",children:[l.representative_name??"â",l.representative_designation_cd&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:[" (",l.representative_designation_cd,")"]})]}),e.jsx("td",{className:"px-3 py-2 text-[10px]",children:l.tax_years_authorized??"â"}),e.jsx("td",{className:"px-3 py-2",children:St(l.status)}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsxs("div",{className:"inline-flex gap-1",children:[l.status==="DRAFT"&&e.jsx("button",{onClick:()=>M(l.authorization_id),disabled:s,className:"text-[10px] px-2 py-0.5 rounded bg-cyan-600 text-white hover:bg-cyan-700 disabled:opacity-50",children:"Sign"}),(l.status==="SIGNED"||l.status==="FILED_WITH_IRS")&&e.jsx("button",{onClick:()=>{A(l.authorization_id),I("")},disabled:s,className:"text-[10px] px-2 py-0.5 rounded border border-blue-300 text-blue-700 hover:bg-blue-50",children:"Record CAF"}),l.status!=="REVOKED"&&l.status!=="EXPIRED"&&l.status!=="SUPERSEDED"&&e.jsx("button",{onClick:()=>{f(l.authorization_id),_("")},disabled:s,className:"text-[10px] px-2 py-0.5 rounded border border-rose-300 text-rose-700 hover:bg-rose-50",children:"Revoke"})]})})]},l.authorization_id))})]})}),j&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:l=>{l.target===l.currentTarget&&!s&&u(!1)},children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl border border-gray-200 w-full max-w-lg mx-4 max-h-[90vh] overflow-auto",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200",children:[e.jsxs("h2",{className:"text-base font-semibold inline-flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-blue-600"})," New taxpayer authorization"]}),N&&e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:N.desc})]}),e.jsxs("div",{className:"p-4 space-y-3 text-sm",children:[e.jsx(U,{label:"Form *",children:e.jsx("select",{value:d.form_code??"fed_2848",onChange:l=>p("form_code",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:ye.map(l=>
1e.jsxs("option",{value:l.id,children:[l.label," â ",l.desc.slice(0,50),"â¦"]},l.id))})}),e.jsx(U,{label:"Primary landlord ID *",children:e.jsx("input",{type:"text",value:d.primary_landlord_id??"",onChange:l=>p("primary_landlord_id",l.target.value),placeholder:"landlord-...",className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono text-xs"})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 p-3 space-y-2 bg-gray-50/50",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-700",children:"Taxpayer"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(U,{label:"First name",children:e.jsx("input",{type:"text",value:d.taxpayer_first_name??"",onChange:l=>p("taxpayer_first_name",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})}),e.jsx(U,{label:"Last name",children:e.jsx("input",{type:"text",value:d.taxpayer_last_name??"",onChange:l=>p("taxpayer_last_name",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})})]}),e.jsx(U,{label:"Taxpayer TIN last 4",children:e.jsx("input",{type:"text",maxLength:4,value:d.taxpayer_tin_last4??"",onChange:l=>p("taxpayer_tin_last4",l.target.value),className:"w-32 px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono"})})]}),(N==null?void 0:N.needs_rep)&&e.jsxs("div",{className:"rounded-lg border-2 border-blue-200 bg-blue-50/30 p-3 space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-blue-800",children:"Representative / Appointee / Claimant"}),e.jsx(U,{label:"Representative name *",children:e.jsx("input",{type:"text",value:d.representative_name??"",onChange:l=>p("representative_name",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(U,{label:"Designation",children:e.jsxs("select",{value:d.representative_designation_cd??"",onChange:l=>p("representative_designation_cd",l.target.value||void 0),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:[e.jsx("option",{value:"",children:"â"}),e.jsx("option",{value:"ATTORNEY",children:"Attorney"}),e.jsx("option",{value:"CPA",children:"CPA"}),e.jsx("option",{value:"ENROLLED_AGENT",children:"Enrolled Agent"}),e.jsx("option",{value:"OFFICER",children:"Corp Officer"}),e.jsx("option",{value:"PARTNER",children:"Partner"}),e.jsx("option",{value:"OTHER",children:"Other"})]})}),e.jsx(U,{label:"CAF number",children:e.jsx("input",{type:"text",value:d.representative_caf_number??"",onChange:l=>p("representative_caf_number",l.target.value),placeholder:"1234567",className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(U,{label:"State (2-letter)",children:e.jsx("input",{type:"text",maxLength:2,value:d.representative_state??"",onChange:l=>p("representative_state",l.target.value.toUpperCase()),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono uppercase"})}),e.jsx(U,{label:"Phone",children:e.jsx("input",{type:"text",value:d.representative_phone??"",onChange:l=>p("representative_phone",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})})]})]}),e.jsx(U,{label:"Tax matters authorized (form numbers + descriptions)",children:e.jsx("textarea",{value:d.matters_authorized??"",onChange:l=>p("matters_authorized",l.target.value),placeholder:"e.g. Income tax (1040), Estate tax (706)",rows:2,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})}),e.jsx(U,{label:"Tax years (comma-separated)",children:e.jsx("input",{type:"text",value:d.tax_years_authorized??"",onChange:l=>p("tax_years_authorized",l.target.value),placeholder:"2023,2024,2025",className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono text-xs"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(U,{label:"Effective date",children:e.jsx("input",{type:"date",value:d.effective_dt??"",onChange:l=>p("effective_dt",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})}),e.jsx(U,{label:"Expires date",children:e.jsx("input",{type:"date",value:d.expires_dt??"",onChange:l=>p("expires_dt",l.target.value),className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-gray-200",children:[e.jsx("button",{onClick:()=>u(!1),disabled:s,className:"px-3 py-1.5 text-sm rounded-md border border-gray-300 hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:D,disabled:s||!d.form_code||!d.primary_landlord_id||(N==null?void 0:N.needs_rep)&&!d.representative_name,className:"px-4 py-1.5 text-sm rounded-md bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:s?"Creatingâ¦":"Create"})]})]})}),x&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:l=>{l.target===l.currentTarget&&!s&&A(null)},children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl border border-gray-200 w-full max-w-md mx-4",children:[e.jsxs("div",{className:"p-4 border-b border-gray-200",children:[e.jsxs("h2",{className:"text-base font-semibold inline-flex items-center gap-2",children:[e.jsx(qe,{className:"w-4 h-4 text-blue-600"})," Record CAF letter"]}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"After IRS receives the signed Form 2848/8821 and records it in the Centralized Authorization File, enter the CAF letter reference here. Status will transition to ACTIVE."})]}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx(U,{label:"CAF letter reference *",children:e.jsx("input",{type:"text",value:b,onChange:l=>I(l.target.value),placeholder:"e.g. CAF-2026-001234",className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg font-mono"})})}),e.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-gray-200",children:[e.jsx("button",{onClick:()=>A(null),disabled:s,className:"px-3 py-1.5 text-sm rounded-md border border-gray-300 hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:()=>z(x),disabled:s||!b.trim(),className:"px-4 py-1.5 text-sm rounded-md bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:s?"Recordingâ¦":"Record CAF"})]})]})}),m&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:l=>{l.target===l.currentTarget&&!s&&f(null)},children:e.jsxs("div",{className:"bg-white rounded-xl shadow-2xl border border-rose-300 w-full max-w-md mx-4",children:[e.jsxs("div",{className:"p-4 border-b border-rose-200 bg-rose-50/50",children:[e.jsx("h2",{className:"text-base font-semibold text-rose-800",children:"Revoke authorization"}),e.jsx("p",{className:"text-xs text-rose-700 mt-1",children:"Revocation is permanent â to grant access again, create a new authorization."})]}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx(U,{label:"Reason *",children:e.jsx("textarea",{value:g,onChange:l=>_(l.target.value),placeholder:"â¥5 chars, recorded in the ledger",rows:3,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg"})})}),e.jsxs("div",{className:"flex justify-end gap-2 p-4 border-t border-gray-200",children:[e.jsx("button",{onClick:()=>f(null),disabled:s,className:"px-3 py-1.5 text-sm rounded-md border border-gray-300 hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:()=>n(m),disabled:s||g.trim().length<5,className:"px-4 py-1.5 text-sm rounded-md bg-rose-600 text-white hover:bg-rose-700 disabled:opacity-50",children:s?"Revokingâ¦":"Revoke"})]})]})})]})}function U({label:a,children:t}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wide text-gray-600 mb-0.5",children:a}),t]})}const Ve=["move_in","move_out","routine","safety","fire_safety","annual","general"],Ft=["renters","liability","flood","umbrella","property","other"],Tt=["critical","high","medium","low"],At=["property","tenant","lease","vendor","insurance","inspection"],Rt={move_in:{sections:[{name:"Kitchen",items:[{key:"kitchen_appliances",label:"Appliances functional"},{key:"kitchen_counters",label:"Countertops & cabinets"},{key:"kitchen_sink",label:"Sink & faucet"},{key:"kitchen_floor",label:"Flooring condition"}]},{name:"Bathroom",items:[{key:"bath_toilet",label:"Toilet functional"},{key:"bath_shower",label:"Shower/tub & fixtures"},{key:"bath_sink",label:"Sink & vanity"},{key:"bath_ventilation",label:"Ventilation/exhaust fan"}]},{name:"Living Areas",items:[{key:"living_walls",label:"Walls & paint condition"},{key:"living_windows",label:"Windows & blinds"},{key:"living_doors",label:"Doors & locks"},{key:"living_flooring",label:"Flooring condition"},{key:"living_electrical",label:"Outlets & light switches"}]},{name:"Safety",items:[{key:"safety_smoke",label:"Smoke detectors"},{key:"safety_co",label:"CO detectors"},{key:"safety_fire_ext",label:"Fire extinguisher"},{key:"safety_egress",label:"Emergency exits clear"}]},{name:"Exterior",items:[{key:"ext_entry",label:"Entry door & lock"},{key:"ext_mailbox",label:"Mailbox"},{key:"ext_parking",label:"Parking space"},{key:"ext_common",label:"Common areas"}]}]},move_out:{sections:[{name:"Kitchen",items:[{key:"kitchen_appliances",label:"Appliances functional"},{key:"kitchen_counters",label:"Countertops & cabinets"},{key:"kitchen_sink",label:"Sink & faucet"},{key:"kitchen_floor",label:"Flooring condition"}]},{name:"Bathroom",items:[{key:"bath_toilet",label:"Toilet functional"},{key:"bath_shower",label:"Shower/tub & fixtures"},{key:"bath_sink",label:"Sink & vanity"},{key:"bath_ventilation",label:"Ventilation/exhaust fan"}]},{name:"Living Areas",items:[{key:"living_walls",label:"Walls & paint condition"},{key:"living_windows",label:"Windows & blinds"},{key:"living_doors",label:"Doors & locks"},{key:"living_flooring",label:"Flooring condition"},{key:"living_electrical",label:"Outlets & light switches"}]},{name:"Safety",items:[{key:"safety_smoke",label:"Smoke detectors"},{key:"safety_co",label:"CO detectors"},{key:"safety_fire_ext",label:"Fire extinguisher"},{key:"safety_egress",label:"Emergency exits clear"}]},{name:"Exterior",items:[{key:"ext_entry",label:"Entry door & lock"},{key:"ext_mailbox",label:"Mailbox"},{key:"ext_parking",label:"Parking space"},{key:"ext_common",label:"Common areas"}]}]},safety:{sections:[{name:"Fire Safety",items:[{key:"fire_alarms",label:"Fire alarm system tested"},{key:"fire_sprinklers",label:"Sprinkler system operational"},{key:"fire_exits",label:"Emergency exits unobstructed"},{key:"fire_extinguishers",label:"Fire extinguishers inspected"},{key:"fire_signage",label:"Exit signage illuminated"}]},{name:"Electrical",items:[{key:"elec_panels",label:"Electrical panels accessible"},{key:"elec_wiring",label:"No exposed wiring"},{key:"elec_gfci",label:"GFCI outlets functional"}]},{name:"Structural",items:[{key:"struct_foundation",label:"Foundation condition"}
1,{key:"struct_roof",label:"Roof condition"},{key:"struct_stairs",label:"Stairs & railings secure"}]}]},fire_safety:{sections:[{name:"Fire Safety",items:[{key:"fire_alarms",label:"Fire alarm system tested"},{key:"fire_sprinklers",label:"Sprinkler system operational"},{key:"fire_exits",label:"Emergency exits unobstructed"},{key:"fire_extinguishers",label:"Fire extinguishers inspected"},{key:"fire_signage",label:"Exit signage illuminated"}]}]},general:{sections:[]},routine:{sections:[]},annual:{sections:[]}},K=()=>({"x-api-key":G(),"Content-Type":"application/json"}),H=()=>({"x-api-key":G()}),It=a=>(a/100).toLocaleString("en-US",{style:"currency",currency:"USD"}),_e=a=>a?new Date(a).toLocaleDateString():"â",V=a=>a.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase());function Pt(a){const t=new Date(a),k=new Date;return Math.ceil((t.getTime()-k.getTime())/(1e3*60*60*24))}function Ge(a){const t={active:"bg-green-100 text-green-700",expired:"bg-red-100 text-red-700",pending:"bg-gray-100 text-gray-700",lapsed:"bg-red-100 text-red-700"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:V(a)})}function $t(a){const t={critical:"bg-red-100 text-red-700",high:"bg-orange-100 text-orange-700",medium:"bg-yellow-100 text-yellow-700",low:"bg-blue-100 text-blue-700"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:V(a)})}function Ot(a){const t={pass:"bg-green-100 text-green-700",fail:"bg-red-100 text-red-700",needs_attention:"bg-yellow-100 text-yellow-700",pending:"bg-gray-100 text-gray-600"};return e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded text-xs font-medium ${t[a]||"bg-gray-100 text-gray-600"}`,children:V(a)})}function es({onNavigate:a}={}){J(),He();const[t,k]=r.useState("insurance"),[h,C]=r.useState(null),[S,E]=r.useState(!0),F=localStorage.getItem("userRole")||"manager",j=F==="admin"||F==="landlord",u=F==="admin";r.useEffect(()=>{fetch("/api/compliance/summary",{headers:H()}).then(o=>o.json()).then(o=>{o.success&&C(o)}).catch(console.error).finally(()=>E(!1))},[]);const s=[{id:"insurance",label:"Insurance",icon:ue},{id:"inspections",label:"Inspections",icon:qe},{id:"risk-flags",label:"Risk Flags",icon:pe},{id:"ofac",label:"OFAC Screening",icon:fe},...u?[{id:"preparer-credentials",label:"Preparer Credentials",icon:Ue}]:[],...u?[{id:"elections",label:"Elections (2553/8832)",icon:Be}]:[],...u?[{id:"form-8879",label:"Form 8879",icon:je}]:[],...u?[{id:"authorizations",label:"Authorizations (2848/8821/1310/9000)",icon:Je}]:[]];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(at,{title:"Compliance & Risk Management",subtitle:"Insurance tracking, safety inspections, and risk monitoring",onShowGuide:()=>window.dispatchEvent(new CustomEvent("ream-open-guide",{detail:"compliance"})),actions:e.jsx("button",{onClick:()=>a==null?void 0:a("documents"),className:"px-3 py-1.5 text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors",children:"Documents"})}),h&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-white rounded-lg border p-4",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Active Policies"}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:h.insurance.active}),e.jsxs("p",{className:"text-xs text-gray-400",children:[h.insurance.expired," expired"]})]}),e.jsxs("div",{className:"bg-white rounded-lg border p-4",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Expiring (30d)"}),e.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:h.insurance.expiring_30d}),e.jsxs("p",{className:"text-xs text-gray-400",children:[h.insurance.uninsured_tenants," uninsured tenants"]})]}),e.jsxs("div",{className:"bg-white rounded-lg border p-4",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Inspections"}),e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:h.inspections.total}),e.jsxs("p",{className:"text-xs text-gray-400",children:[h.inspections.failed," failed, ",h.inspections.pending," pending"]})]}),e.jsxs("div",{className:"bg-white rounded-lg border p-4",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Open Risk Flags"}),e.jsx("p",{className:"text-2xl font-bold text-red-600",children:h.risk_flags.open}),e.jsxs("p",{className:"text-xs text-gray-400",children:[h.risk_flags.critical," critical, ",h.risk_flags.high," high"]})]})]}),e.jsx("div",{className:"border-b border-gray-200",children:e.jsx("nav",{className:"flex -mb-px space-x-6",children:s.map(o=>{const d=o.icon;return e.jsxs("button",{onClick:()=>k(o.id),className:`flex items-center gap-2 py-3 px-1 border-b-2 text-sm font-medium transition-colors ${t===o.id?"border-blue-600 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[e.jsx(d,{className:"w-4 h-4"})," ",o.label]},o.id)})})}),t==="insurance"&&e.jsx(Dt,{isLandlordOrAbove:j,isAdmin:u,onRefreshSummary:()=>{fetch("/api/compliance/summary",{headers:H()}).then(o=>o.json()).then(o=>{o.success&&C(o)}).catch(console.error)}}),t==="inspections"&&e.jsx(Mt,{onRefreshSummary:()=>{fetch("/api/compliance/summary",{headers:H()}).then(o=>o.json()).then(o=>{o.success&&C(o)}).catch(console.error)}}),t==="risk-flags"&&e.jsx(Ut,{isLandlordOrAbove:j,onRefreshSummary:()=>{fetch("/api/compliance/summary",{headers:H()}).then(o=>o.json()).then(o=>{o.success&&C(o)}).catch(console.error)}}),t==="ofac"&&e.jsx(ct,{isAdmin:u}),t==="preparer-credentials"&&e.jsx(ut,{isAdmin:u}),t==="elections"&&e.jsx(Nt,{isAdmin:u}),t==="form-8879"&&e.jsx(kt,{isAdmin:u}),t==="authorizations"&&e.jsx(Et,{isAdmin:u})]})}function Dt({isLandlordOrAbove:a,isAdmin:t,onRefreshSummary:k}){var z;const h=J();He();const[C,S]=r.useState([]),[E,F]=r.useState(!0),[j,u]=r.useState(!1),[s,o]=r.useState(""),[d,c]=r.useState(null),[x,A]=r.useState([]),[b,I]=r.useState(!1),[m,f]=r.useState(null),g=()=>{F(!0),Promise.all([fetch("/api/compliance/insurance/list",{headers:H()}).then(n=>n.json()),fetch("/api/compliance/insurance/compliance-summary",{headers:H()}).then(n=>n.json()),fetch("/api/compliance/master-liability/config",{headers:H()}).then(n=>n.json())]).then(([n,p,N])=>{n.success&&S(n.policies),p.ok&&c(p),N.ok&&A(N.configs||[])}).catch(console.error).finally(()=>F(!1))};r.useEffect(()=>{g()},[]);const _=async n=>{try{const N=await(await fetch("/api/compliance/insurance/verify",{method:"POST",headers:K(),body:JSON.stringify({policy_id:n})})).json();N.success?(g(),k()):h.error(N.error)}catch(p){h.error(p.message)}},R=async()=>{try{const p=await(await fetch("/api/compliance/insurance/send-expiry-alerts",{method:"POST",headers:K()})).json();p.success?(h.success(`Alerts sent: ${p.alerts_sent} · Policies expired: ${p.policies_expired} · Flags created: ${p.flags_created}`),g(),k()):h.error(p.error)}catch(n){h.error(n.message)}},D=async()=>{try{const p=await(await fetch("/api/compliance/insurance/send-enrollment-reminders",{method:"POST",headers:K()})).json();p.ok?(h.success(`Reminders sent to ${p.sent} of ${p.total_uninsured} uninsured tenants`),g(),k()):h.error(p.error)}catch(n){h.error(n.message)}},M=C.filter(n=>{if(!s)return!0;const p=s.toLowerCase();return(n.tenant_name||"").toLowerCase().includes(p)||(n.carrier||"").toLowerCase().includes(p)||(n.policy_number||"").toLowerCase().includes(p)});return e.jsxs("div",{className:"space-y-4",children:[((z=d==null?void 0:d.properties)==null?void 0:z.length)>0&&e.jsxs("div",{className:"bg-white rounded-lg border overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b bg-gray-50 flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold text-gray-800 flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4 text-blue-600"}),"Insurance Compliance by Property",e.jsxs("span",{className:"text-xs font-normal text-gray-500 ml-2",children:["Overall: ",d.summary.total_insured,"/",d.summary.total_tenants," tenants (",d.summary.overall_compliance_pct,"%)"]})]}),t&&e.jsxs("button",{onClick:()=>I(!b),className:"text-xs px-3 py-1.5 bg-blue-50 text-blue-700 rounded-lg hover:bg-blue-100 border border-blue-200",children:[b?"Hide":"Configure"," Master Liability"]})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-gray-500 text-xs uppercase",children:[e.jsx("th",{className:"px-4 py-2",children:"Property"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Tenants"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Own Insurance"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Master Liability"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Compliance"}),b&&t&&e.jsx("th",{className:"px-4 py-2 text-center",children:"ML Enabled"}),b&&t&&e.jsx("th",{className:"px-4 py-2 text-right",children:"Premium"})]})}),e.jsx("tbody",{className:"divide-y",children:d.properties.map(n=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium",children:n.property_name}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:n.total_tenants}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:n.own_insurance_count}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:n.master_liability_count}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsxs("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${n.compliance_pct>=90?"bg-green-100 text-green-700":n.compliance_pct>=50?"bg-yellow-100 text-yellow-700":"bg-red-100 text-red-700"}`,children:[n.compliance_pct,"%"]})}),b&&t&&e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${n.master_liability_enabled?"bg-green-100 text-green-700":"bg-gray-100 text-gray-500"}`,children:n.master_liability_enabled?"Enabled":"Off"})}),b&&t&&e.jsx("td",{className:"px-4 py-2.5 text-right text-gray-600",children:n.monthly_premium_cents?`$${(n.monthly_premium_cents/100).toFixed(2)}/mo`:"â"})]},n.property_id))})]})]}),b&&t&&e.jsx(Ht,{onSaved:g}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"relative",children:[e.jsx(me,{className:"absolute left-3 top-2.5 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search policies...",className:"pl-9 pr-4 py-2 border rounded-lg text-sm w-64 focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:s,onChange:n=>o(n.target.value)})]}),e.jsxs("div",{className:"flex gap-2",children:[a&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:D,className:"flex items-center gap-1 px-3 py-2 text-sm bg-indigo-50 text-indigo-700 border border-indigo-200 rounded-lg hover:bg-indigo-100",children:[e.jsx(ee,{className:"w-4 h-4"})," Send Enrollment Reminders"]}),e.jsxs("button",{onClick:R,className:"flex items-center gap-1 px-3 py-2 text-sm bg-orange-50 text-orange-700 border border-orange-200 rounded-lg hover:bg-orange-100",children:[e.jsx(ee,{className:"w-4 h-4"})," Send Expiry Alerts"]})]}),t&&e.jsxs("button",{onClick:()=>u(!0),className:"flex items-center gap-1 px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(X,{className:"w-4 h-4"})," Add Policy"]})]})]}),E?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"Loading..."}):M.length===0?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No insurance policies found. Tenants can enroll via the tenant portal."}):e.jsx("div",{className:"bg-white rounded-lg border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Tenant"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Carrier"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Policy #"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium text-gray-600",children:"Coverage"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Expires"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Verified"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Status"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium text-gray-600",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:M.map(n=>{const p=Pt(n.expiration_date),N=p<0?"text-red-600 font-semibold":p<=30?"text-yellow-600 font-semibold":"text-gray-900";return e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:n.tenant_name||"Unknown"}),e.jsx("td",{className:"px-4 py-3",children:V(n.policy_type)}),e.jsx("td",{className:"px-4 py-3",children:n.carrier||"â"}),e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:n.policy_number||"â"}),e.jsx("td",{className:"px-4 py-3 text-right",children:n.coverage_amount_cents?It(n.coverage_amount_cents):"â"}),e.jsxs("td",{className:`px-4 py-3 ${N}`,children:[_e(n.expiration_date),p<=30&&p>=0&&e.jsxs("span",{className:"text-xs ml-1",children:["(",p,"d)"]}),p<0&&e.jsx("span",{className:"text-xs ml-1",children:"(expired)"})]}),e.jsx("td",{className:"px-4 py-3 text-center",children:n.is_verified?e.jsx(te,{className:"w-5 h-5 text-green-500 inline"}):e.jsx(ie,{className:"w-5 h-5 text-gray-300 inline"})}),e.jsx("td",{className:"px-4 py-3 text-center",children:Ge(n.status)}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-2",children:[n.notification_count&&parseInt(n.notification_count)>0&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-700",title:`${n.notification_count} notification(s) sent`,children:n.notification_count}),n.certificate_url&&e.jsx("a",{href:n.certificate_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline text-xs",children:"COI"}),a&&!n.is_verified&&e.jsx("button",{onClick:()=>_(n.policy_id),className:"text-green-600 hover:underline text-xs font-medium",children:"Verify"})]})]},n.policy_id)})})]})}),j&&e.jsx(Lt,{onClose:()=>u(!1),onSaved:()=>{u(!1),g(),k()}})]})}function Lt({onClose:a,onSaved:t}){const k=J(),[h,C]=r.useState({tenant_id:"",policy_type:"renter
1s",carrier:"",policy_number:"",coverage_amount_cents:"",effective_date:new Date().toISOString().split("T")[0],expiration_date:"",certificate_url:""}),[S,E]=r.useState([]),[F,j]=r.useState(!1);r.useEffect(()=>{fetch("/api/tenants/list?limit=200",{headers:H()}).then(s=>s.json()).then(s=>{s.tenants&&E(s.tenants)}).catch(console.error)},[]);const u=async()=>{if(!h.tenant_id||!h.effective_date||!h.expiration_date){k.warning("Tenant, effective date, and expiration date are required");return}j(!0);try{const s={...h,coverage_amount_cents:h.coverage_amount_cents?Math.round(parseFloat(h.coverage_amount_cents)*100):null},d=await(await fetch("/api/compliance/insurance/create",{method:"POST",headers:K(),body:JSON.stringify(s)})).json();d.success?t():k.error(d.error)}catch(s){k.error(s.message)}finally{j(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-lg p-6 space-y-4 max-h-[90vh] overflow-y-auto",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Add Insurance Policy"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Tenant *"}),e.jsxs("select",{value:h.tenant_id,onChange:s=>C({...h,tenant_id:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"Select tenant..."}),S.map(s=>e.jsx("option",{value:s.tenant_id,children:s.full_name||s.tenant_id},s.tenant_id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Policy Type"}),e.jsx("select",{value:h.policy_type,onChange:s=>C({...h,policy_type:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:Ft.map(s=>e.jsx("option",{value:s,children:V(s)},s))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Carrier"}),e.jsx("input",{type:"text",value:h.carrier,onChange:s=>C({...h,carrier:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. State Farm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Policy Number"}),e.jsx("input",{type:"text",value:h.policy_number,onChange:s=>C({...h,policy_number:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Coverage Amount ($)"}),e.jsx("input",{type:"number",step:"0.01",value:h.coverage_amount_cents,onChange:s=>C({...h,coverage_amount_cents:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"100000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Effective Date *"}),e.jsx("input",{type:"date",value:h.effective_date,onChange:s=>C({...h,effective_date:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Expiration Date *"}),e.jsx("input",{type:"date",value:h.expiration_date,onChange:s=>C({...h,expiration_date:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Certificate URL (COI)"}),e.jsx("input",{type:"text",value:h.certificate_url,onChange:s=>C({...h,certificate_url:s.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"https://..."})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm border rounded-lg hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:u,disabled:F,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:F?"Saving...":"Add Policy"})]})]})})}function Mt({onRefreshSummary:a}){J();const[t,k]=r.useState([]),[h,C]=r.useState(!0),[S,E]=r.useState(!1),[F,j]=r.useState(""),[u,s]=r.useState(""),o=()=>{C(!0);const c=new URLSearchParams;u&&c.set("inspection_type",u),fetch(`/api/compliance/inspections/list?${c}`,{headers:H()}).then(x=>x.json()).then(x=>{x.success&&k(x.inspections)}).catch(console.error).finally(()=>C(!1))};r.useEffect(()=>{o()},[u]);const d=t.filter(c=>{if(!F)return!0;const x=F.toLowerCase();return(c.property_name||"").toLowerCase().includes(x)||(c.inspector_name||"").toLowerCase().includes(x)||c.inspection_type.toLowerCase().includes(x)});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(me,{className:"absolute left-3 top-2.5 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search inspections...",className:"pl-9 pr-4 py-2 border rounded-lg text-sm w-64 focus:ring-2 focus:ring-blue-500 focus:border-blue-500",value:F,onChange:c=>j(c.target.value)})]}),e.jsxs("select",{value:u,onChange:c=>s(c.target.value),className:"border rounded-lg px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"All Types"}),Ve.map(c=>e.jsx("option",{value:c,children:V(c)},c))]})]}),e.jsxs("button",{onClick:()=>E(!0),className:"flex items-center gap-1 px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:[e.jsx(X,{className:"w-4 h-4"}
1)," New Inspection"]})]}),h?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"Loading..."}):d.length===0?e.jsx("div",{className:"text-center py-12 text-gray-500",children:'No inspections found. Click "New Inspection" to create one.'}):e.jsx("div",{className:"bg-white rounded-lg border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Property"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Inspector"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Date"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Result"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Photos"})]})}),e.jsx("tbody",{className:"divide-y",children:d.map(c=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:c.property_name||c.property_id}),e.jsx("td",{className:"px-4 py-3",children:V(c.inspection_type)}),e.jsx("td",{className:"px-4 py-3",children:c.inspector_name||"â"}),e.jsx("td",{className:"px-4 py-3",children:_e(c.performed_at)}),e.jsx("td",{className:"px-4 py-3 text-center",children:Ot(c.result)}),e.jsx("td",{className:"px-4 py-3 text-center",children:parseInt(c.attachment_count||"0")>0?e.jsx("span",{className:"text-blue-600 font-medium",children:c.attachment_count}):"â"})]},c.inspection_id))})]})}),S&&e.jsx(zt,{onClose:()=>E(!1),onSaved:()=>{E(!1),o(),a()}})]})}function zt({onClose:a,onSaved:t}){const k=J(),[h,C]=r.useState("setup"),[S,E]=r.useState({property_id:"",unit_id:"",inspection_type:"move_in",inspector_name:"",notes:"",performed_at:new Date().toISOString().split("T")[0]}),[F,j]=r.useState({}),[u,s]=r.useState([]),[o,d]=r.useState(!1);r.useEffect(()=>{fetch("/api/properties/recent?limit=200",{headers:H()}).then(b=>b.json()).then(b=>{b.properties&&s(b.properties)}).catch(console.error)},[]);const c=Rt[S.inspection_type]||{sections:[]},x=()=>{const b={};c.sections.forEach(I=>I.items.forEach(m=>{b[m.key]={result:"pass",notes:""}})),j(b),C("checklist")},A=async()=>{if(!S.property_id||!S.inspection_type){k.warning("Property and inspection type are required");return}d(!0);try{const b={sections:c.sections.map(_=>({name:_.name,items:_.items.map(R=>{var D,M;return{key:R.key,label:R.label,result:((D=F[R.key])==null?void 0:D.result)||"pass",notes:((M=F[R.key])==null?void 0:M.notes)||""}})}))},m=Object.values(F).some(_=>_.result==="fail")?"fail":Object.values(F).some(_=>_.result==="na")?"needs_attention":"pass",g=await(await fetch("/api/compliance/inspections/create",{method:"POST",headers:K(),body:JSON.stringify({...S,checklist_result:b,result:c.sections.length>0?m:"pending"})})).json();g.success?t():k.error(g.error)}catch(b){k.error(b.message)}finally{d(!1)}};return h==="setup"?e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-lg p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"New Inspection"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Property *"}),e.jsxs("select",{value:S.property_id,onChange:b=>E({...S,property_id:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"Select property..."}),u.map(b=>e.jsx("option",{value:b.property_id,children:b.name},b.property_id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Unit ID (optional)"}),e.jsx("input",{type:"text",value:S.unit_id,onChange:b=>E({...S,unit_id:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. unit-123"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Inspection Type *"}
1),e.jsx("select",{value:S.inspection_type,onChange:b=>E({...S,inspection_type:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:Ve.map(b=>e.jsx("option",{value:b,children:V(b)},b))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Inspector Name"}),e.jsx("input",{type:"text",value:S.inspector_name,onChange:b=>E({...S,inspector_name:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date"}),e.jsx("input",{type:"date",value:S.performed_at,onChange:b=>E({...S,performed_at:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Notes"}),e.jsx("textarea",{value:S.notes,onChange:b=>E({...S,notes:b.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",rows:2})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm border rounded-lg hover:bg-gray-50",children:"Cancel"}),c.sections.length>0?e.jsx("button",{onClick:x,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700",children:"Next: Checklist"}):e.jsx("button",{onClick:A,disabled:o,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:o?"Saving...":"Create Inspection"})]})]})}):e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-2xl p-6 space-y-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:[V(S.inspection_type)," Checklist"]}),e.jsx("button",{onClick:()=>C("setup"),className:"text-sm text-blue-600 hover:underline",children:"Back"})]}),c.sections.map(b=>e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-4 py-2 font-medium text-sm",children:b.name}),e.jsx("div",{className:"divide-y",children:b.items.map(I=>{var m;return e.jsxs("div",{className:"px-4 py-3 flex items-center gap-4",children:[e.jsx("span",{className:"flex-1 text-sm",children:I.label}),e.jsx("div",{className:"flex gap-1",children:["pass","fail","na"].map(f=>{var g;return e.jsx("button",{onClick:()=>j(_=>({..._,[I.key]:{..._[I.key],result:f}})),className:`px-2 py-1 text-xs rounded font-medium ${((g=F[I.key])==null?void 0:g.result)===f?f==="pass"?"bg-green-100 text-green-700 ring-2 ring-green-500":f==="fail"?"bg-red-100 text-red-700 ring-2 ring-red-500":"bg-gray-100 text-gray-700 ring-2 ring-gray-500":"bg-gray-50 text-gray-400 hover:bg-gray-100"}`,children:f==="na"?"N/A":V(f)},f)})}),e.jsx("input",{type:"text",placeholder:"Notes...",className:"w-40 border rounded px-2 py-1 text-xs",value:((m=F[I.key])==null?void 0:m.notes)||"",onChange:f=>j(g=>({...g,[I.key]:{...g[I.key],notes:f.target.value}}))})]},I.key)})})]},b.name)),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm border rounded-lg hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:A,disabled:o,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50",children:o?"Saving...":"Submit Inspection"})]})]})})}function Ut({isLandlordOrAbove:a,onRefreshSummary:t}){J();const[k,h]=r.useState([]),[C,S]=r.useState(!0),[E,F]=r.useState(!1),[j,u]=r.useState(null),[s,o]=r.useState("open"),d=()=>{S(!0);const c=new URLSearchParams;s&&c.set("status",s),fetch(`/api/compliance/risk-flags/list?${c}`,{headers:H()}).then(x=>x.json()).then(x=>{x.success&&h(x.risk_flags)}).catch(console.error).finally(()=>S(!1))};return r.useEffect(()=>{d()},[s]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("select",{value:s,onChange:c=>o(c.target.value),className:"border rounded-lg px-3 py-2 text-sm",children:[e.jsx("option",{value:"open",children:"Open"}),e.jsx("option",{value:"resolved",children:"Resolved"}),e.jsx("option",{value:"",children:"All"})]}),e.jsxs("button",{onClick:()=>F(!0),className:"flex items-center gap-1 px-4 py-2 text-sm bg-red-600 text-white rounded-lg hover:bg-red-700",children:[e.jsx(X,{className:"w-4 h-4"})," Add Risk Flag"]})]}),C?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"Loading..."}):k.length===0?e.jsx("div",{className:"text-center py-12 text-gray-500",children:"No risk flags found."}):e.jsx("div",{className:"bg-white rounded-lg border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Severity"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Subject"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Reason"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium text-gray-600",children:"Status"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Created"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium text-gray-600",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:k.map(c=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 text-center",children:$t(c.severity)}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("span",{className:"text-xs bg-gray-100 px-1.5 py-0.5 rounded text-gray-600",children:V(c.subject_type)}),e.jsxs("span",{className:"ml-2 text-xs text-gray-400 font-mono",children:[c.subject_id.substring(0,20),"..."]})]}),e.jsx("td",{className:"px-4 py-3 max-w-xs truncate",children:c.reason}),e.jsx("td",{className:"px-4 py-3 text-center",children:Ge(c.status)}),e.jsx("td",{className:"px-4 py-3 text-gray-500",children:_e(c.created_at)}),e.jsxs("td",{className:"px-4 py-3 text-right",children:[c.status==="open"&&a&&e.jsx("button",{onClick:()=>u(c.risk_flag_id),className:"text-green-600 hover:underline text-xs font-medium",children:"Resolve"}),c.status==="resolved"&&c.resolved_by&&e.jsxs("span",{className:"text-xs text-gray-400",title:c.resolution_notes||"",children:["by ",c.resolved_by]})]})]},c.risk_flag_id))})]})}),E&&e.jsx(Bt,{onClose:()=>F(!1),onSaved:()=>{F(!1),d(),t()}}),j&&e.jsx(qt,{flagId:j,onClose:()=>u(null),onSaved:()=>{u(null),d(),t()}})]})}function Bt({onClose:a,onSaved:t}){const k=J(),[h,C]=r.useState({subject_type:"tenant",subject_id:"",severity:"medium",reason:""}),[S,E]=r.useState(!1),F=async()=>
1{if(!h.subject_id||!h.reason){k.warning("Subject ID and reason are required");return}E(!0);try{const u=await(await fetch("/api/compliance/risk-flags/create",{method:"POST",headers:K(),body:JSON.stringify(h)})).json();u.success?t():k.error(u.error)}catch(j){k.error(j.message)}finally{E(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Add Risk Flag"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Subject Type"}),e.jsx("select",{value:h.subject_type,onChange:j=>C({...h,subject_type:j.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:At.map(j=>e.jsx("option",{value:j,children:V(j)},j))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Subject ID *"}),e.jsx("input",{type:"text",value:h.subject_id,onChange:j=>C({...h,subject_id:j.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",placeholder:"e.g. tenant-abc123"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Severity"}),e.jsx("select",{value:h.severity,onChange:j=>C({...h,severity:j.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",children:Tt.map(j=>e.jsx("option",{value:j,children:V(j)},j))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Reason *"}),e.jsx("textarea",{value:h.reason,onChange:j=>C({...h,reason:j.target.value}),className:"w-full border rounded-lg px-3 py-2 text-sm",rows:3,placeholder:"Describe the risk..."})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:a,className:"px-4 py-2 text-sm border rounded-lg hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:F,disabled:S,className:"px-4 py-2 text-sm bg-red-600 text-white rounded-lg hover:bg-red-700 disabled:opacity-50",children:S?"Saving...":"Create Flag"})]})]})})}function qt({flagId:a,onClose:t,onSaved:k}){const h=J(),[C,S]=r.useState(""),[E,F]=r.useState(!1),j=async()=>{F(!0);try{const s=await(await fetch("/api/compliance/risk-flags/resolve",{method:"POST",headers:K(),body:JSON.stringify({risk_flag_id:a,resolution_notes:C})})).json();s.success?k():h.error(s.error)}catch(u){h.error(u.message)}finally{F(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-xl shadow-xl w-full max-w-md p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Resolve Risk Flag"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Resolution Notes"}),e.jsx("textarea",{value:C,onChange:u=>S(u.target.value),className:"w-full border rounded-lg px-3 py-2 text-sm",rows:4,placeholder:"Describe how this was resolved..."})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:t,className:"px-4 py-2 text-sm border rounded-lg hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:j,disabled:E,className:"px-4 py-2 text-sm bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50",children:E?"Resolving...":"Mark Resolved"})]})]})})}function Ht({onSaved:a}){const t=J(),[k,h]=r.useState([]),[C,S]=r.useState([]),[E,F]=r.useState([]),[j,u]=r.useState(null),[s,o]=r.useState({}),[d,c]=r.useState(null),[x,A]=r.useState({}),[b,I]=r.useState(null),[m,f]=r.useState(null),g=()=>{Promise.all([fetch("/api/properties/list?limit=200",{headers:H()}).then(n=>n.json()),fetch("/api/compliance/master-liability/config",{headers:H()}).then(n=>n.json()),fetch("/api/compliance/insurance/coverage-tiers",{headers:H()}).then(n=>n.json())]).then(([n,p,N])=>{n.properties&&h(n.properties),p.ok&&S(p.configs||[]),N.ok&&F(N.tiers||[])}).catch(console.error)};r.useEffect(()=>{g()},[]);const _=async n=>{u(n);const p=s[n]||{};try{const l=await(await fetch("/api/compliance/master-liability/config",{method:"POST",headers:K(),body:JSON.stringify({property_id:n,is_enabled:p.is_enabled??!1,carrier_name:p.carrier_name||"",master_policy_number:p.master_policy_number||"",monthly_premium_cents:0,platform_fee_cents:0})})).json();l.ok?(g(),a()):t.error(l.error)}catch(N){t.error(N.message)}finally{u(null)}},R=async n=>{u("tier");try{const p=Math.round(parseFloat(x.premium||"0")*100),N=Math.round(parseFloat(x.platform_fee||"0")*100),T=await(await fetch("/api/compliance/insurance/coverage-tiers",{method:"POST",headers:K(),body:JSON.stringify({config_id:n,tier_id:x.tier_id||void 0,tier_name:x.tier_name||"",coverage_amount_cents:Math.round(parseFloat(x.coverage||"0")*100),monthly_premium_cents:p,platform_fee_cents:N,msi_payout_cents:p-N,description:x.description||""})})).json();T.ok?(c(null),A({}),g(),a()):t.error(T.error)}catch(p){t.error(p.message)}finally{u(null)}},D=(n,p,N)=>{o(l=>({...l,[n]:{...l[n]||{},[p]:N}}))},M=n=>C.find(p=>p.property_id===n),z=n=>E.filter(p=>p.config_id===n);return e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 space-y-4",children:[e.jsxs("h4",{className:"font-semibold text-blue-800 flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4"}),"Master Liability Policy Configuration"]}),e.jsx("p",{className:"text-xs text-blue-600",children:"Enable per property, then configure coverage tiers that tenants can choose from. Premium goes to tenant's bill. Platform fee is your revenue. MSI payout = premium - platform fee."}),e.jsx("div",{className:"space-y-2",children:k.map(n=>{const p=s[n.property_id]||{},N=M(n.property_id),l=N?z(N.config_id):[],T=m===n.property_id;return e.jsxs("div",{className:"bg-white rounded-lg border overflow-hidden",children:[e.jsxs("div",{className:"p-3 flex items-center gap-4 flex-wrap",children:[e.jsx("div",{className:"min-w-[180px] font-medium text-sm",children:n.name}),e.jsxs("label",{className:"flex items-center gap-1 text-sm",children:[e.jsx("input",{type:"checkbox",checked:p.is_enabled??(N==null?void 0:N.is_enabled)??!1,onChange:v=>D(n.property_id,"is_enabled",v.target.checked)}),"Enable"]}),e.jsx("input",{type:"text",placeholder:"Carrier (e.g. MSI)",className:"w-40 px-2 py-1 border rounded text-sm",value:p.carrier_name??(N==null?void 0:N.carrier_name)??"",onChange:v=>D(n.property_id,"carrier_name",v.target.value)}),e.jsx("input",{type:"text",placeholder:"Policy #",className:"w-32 px-2 py-1 border rounded text-sm",value:p.master_policy_number??(N==null?void 0:N.master_policy_number)??"",onChange:v=>D(n.property_id,"master_policy_number",v.target.value)}),e.jsx("button",{onClick:()=>_(n.property_id),disabled:j===n.property_id,className:"px-3 py-1 text-xs bg-blue-600 text-white rounded hover:bg-blue-700 disabled:opacity-50",children:j===n.property_id?"Saving...":"Save"}),N&&e.jsx("button",{onClick:()=>f(T?null:n.property_id),className:"px-3 py-1 text-xs bg-indigo-50 text-indigo-700 border border-indigo-200 rounded hover:bg-indigo-100",children:T?"Hide Tiers":`Tiers (${l.length})`})]}),T&&N&&e.jsxs("div",{className:"border-t bg-gray-50 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h5",{className:"text-sm font-semibold text-gray-700",children:"Coverage Tiers"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{I(N.config_id)},className:"text-xs px-2 py-1 bg-emerald-700 text-white rounded hover:bg-emerald-800",children:"MSI Rate Builder"}),e.jsx("button",{onClick:()=>
1{c(N.config_id),A({})},className:"text-xs px-2 py-1 bg-indigo-600 text-white rounded hover:bg-indigo-700",children:"+ Add Tier"})]})]}),l.length===0?e.jsx("p",{className:"text-xs text-gray-400 py-2",children:"No tiers configured. Add tiers so tenants can select coverage levels."}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-gray-500 uppercase",children:[e.jsx("th",{className:"px-2 py-1",children:"Tier"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Premium"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Platform Fee"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"MSI Payout"}),e.jsx("th",{className:"px-2 py-1 text-right",children:"Coverage"}),e.jsx("th",{className:"px-2 py-1",children:"Description"}),e.jsx("th",{className:"px-2 py-1 text-center",children:"Active"}),e.jsx("th",{className:"px-2 py-1",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",children:l.map(v=>e.jsxs("tr",{className:"hover:bg-white",children:[e.jsx("td",{className:"px-2 py-1.5 font-medium",children:v.tier_name}),e.jsxs("td",{className:"px-2 py-1.5 text-right",children:["$",(v.monthly_premium_cents/100).toFixed(2)]}),e.jsxs("td",{className:"px-2 py-1.5 text-right text-emerald-600",children:["$",(v.platform_fee_cents/100).toFixed(2)]}),e.jsxs("td",{className:"px-2 py-1.5 text-right text-blue-600",children:["$",(v.msi_payout_cents/100).toFixed(2)]}),e.jsxs("td",{className:"px-2 py-1.5 text-right",children:["$",(v.coverage_amount_cents/100).toLocaleString()]}),e.jsx("td",{className:"px-2 py-1.5 text-gray-500 max-w-[200px] truncate",children:v.description||"â"}),e.jsx("td",{className:"px-2 py-1.5 text-center",children:e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${v.is_active?"bg-green-100 text-green-700":"bg-gray-100 text-gray-500"}`,children:v.is_active?"Yes":"No"})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("button",{onClick:()=>{c(N.config_id),A({tier_id:v.tier_id,tier_name:v.tier_name,premium:(v.monthly_premium_cents/100).toFixed(2),platform_fee:(v.platform_fee_cents/100).toFixed(2),coverage:(v.coverage_amount_cents/100).toFixed(2),description:v.description||""})},className:"text-xs text-blue-600 hover:underline",children:"Edit"})})]},v.tier_id))})]}),b===N.config_id&&e.jsxs("div",{className:"bg-white border rounded-lg p-4 mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h6",{className:"text-sm font-semibold text-gray-900",children:"Build Coverage Tier from MSI Rates"}),e.jsx("button",{onClick:()=>I(null),className:"text-xs text-gray-400 hover:text-gray-600",children:"Close"})]}),e.jsx(nt,{onSaveTier:async v=>{try{(await fetch("/api/compliance/insurance/coverage-tiers",{method:"POST",headers:K(),body:JSON.stringify({config_id:N.config_id,tier_name:v.tierName,coverage_amount_cents:v.coverageAmountCents,monthly_premium_cents:v.monthlyPremiumCents,platform_fee_cents:v.platformFeeCents,msi_payout_cents:v.monthlyPremiumCents-v.platformFeeCents,description:v.coverageDescription})})).ok&&(I(null),g(),a())}catch(B){console.error("Save tier error:",B)}}})]}),d===N.config_id&&e.jsxs("div",{className:"bg-white border rounded-lg p-3 space-y-2 mt-2",children:[e.jsx("h6",{className:"text-sm font-semibold",children:x.tier_id?"Edit Tier":"Add New Tier"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Tier Name *"}),e.jsx("input",{type:"text",placeholder:"e.g. Premium",className:"w-full px-2 py-1 border rounded text-sm",value:x.tier_name||"",onChange:v=>A({...x,tier_name:v.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Premium $/mo *"}),e.jsx("input",{type:"number",step:"0.01",min:"0",className:"w-full px-2 py-1 border rounded text-sm",value:x.premium||"",placeholder:"25.00",onChange:v=>A({...x,premium:v.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Platform Fee $"}),e.jsx("input",{type:"number",step:"0.01",min:"0",className:"w-full px-2 py-1 border rounded text-sm",value:x.platform_fee||"",placeholder:"5.00",onChange:v=>A({...x,platform_fee:v.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Coverage $"}),e.jsx("input",{type:"number",step:"1",min:"0",className:"w-full px-2 py-1 border rounded text-sm",value:x.coverage||"",placeholder:"100000",onChange:v=>A({...x,coverage:v.target.value})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-gray-500",children:"Description"}),e.jsx("input",{type:"text",className:"w-full px-2 py-1 border rounded text-sm",value:x.description||"",placeholder:"Liability coverage up to $100,000",onChange:v=>A({...x,description:v.target.value})})]}),x.premium&&x.platform_fee&&e.jsxs("p",{className:"text-xs text-gray-500",children:["MSI payout: ",e.jsxs("span",{className:"font-medium text-blue-600",children:["$",(parseFloat(x.premium||"0")-parseFloat(x.platform_fee||"0")).toFixed(2),"/mo"]})," per enrollment"]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{c(null),A({})},className:"px-3 py-1 text-xs text-gray-600 border rounded hover:bg-gray-50",children:"Cancel"}),e.jsx("button",{onClick:()=>R(N.config_id),disabled:j==="tier",className:"px-3 py-1 text-xs bg-indigo-600 text-white rounded hover:bg-indigo-700 disabled:opacity-50",children:j==="tier"?"Saving...":x.tier_id?"Update Tier":"Add Tier"})]})]})]})]},n.property_id)})})]})}export{es 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.