PageSourceSearch

https://taxease360.ai/assets/SuperSubscriptions-DEXBQVZY.js

js taxease360.ai collected 2026-10-05 14:25:37 UTC 30,926 bytes, 1 lines download raw bytes

1import{a4 as G,r as h,j as e,X as le,q as D,z as oe,t as R,p as I,I as b,w as O,ai as de,i as K,B as V,y as ce,ac as ue,a5 as xe,L as W}from"./index-CfXbMZ_V.js";import{S as me}from"./save-DxI-RWzE.js";import{D as te,a as ae,b as se,c as ne,d as re}from"./dialog-D3H816yE.js";import{P as ge}from"./power-4s9LtUWg.js";import{P as pe}from"./pencil-DCKB3rA6.js";const be=[{key:"client_job_management",label:"Client & job management",category:"Core"},{key:"forms_onboarding",label:"Forms & onboarding",category:"Core"},{key:"standard_engagement_letters",label:"Standard engagement letters",category:"Core"},{key:"firm_contact_details",label:"Firm contact details",category:"Core"},{key:"booking_calendar_sync",label:"Booking & calendar sync",category:"Core"},{key:"standard_reports",label:"Standard reports",category:"Core"},{key:"core_finley",label:"Core Finley assistance",category:"Core"},{key:"basic_signatures",label:"Basic digital signatures",category:"Core"},{key:"document_uploads",label:"Document uploads",category:"Core"},{key:"secure_messaging",label:"Secure messaging",category:"Core"},{key:"standard_onboarding",label:"Standard onboarding workflows",category:"Core"},{key:"taxease_email_delivery",label:"TaxEase360 email delivery",category:"Core"},{key:"firm_logo_documents",label:"Firm logo on documents",category:"Branding"},{key:"firm_logo_portal",label:"Firm logo in client portal",category:"Branding"},{key:"custom_brand_colours",label:"Custom brand colours",category:"Branding"},{key:"branded_emails",label:"Branded emails",category:"Branding"},{key:"branded_onboarding",label:"Branded onboarding",category:"Branding"},{key:"branded_letters",label:"Branded engagement letters",category:"Branding"},{key:"branded_pdfs",label:"Branded PDFs",category:"Branding"},{key:"branded_booking",label:"Branded booking confirmations",category:"Branding"},{key:"branded_reminders",label:"Branded appointment reminders",category:"Branding"},{key:"branded_signature_requests",label:"Branded signature requests",category:"Branding"},{key:"remove_taxease_branding",label:"Remove TaxEase360 branding",category:"Branding"},{key:"custom_domain",label:"Custom portal domain",category:"Branding"},{key:"custom_login_page",label:"Custom login page",category:"Branding"},{key:"custom_email_domain",label:"Custom email sending domain",category:"Branding"},{key:"custom_favicon",label:"Custom favicon",category:"Branding"},{key:"advanced_template_builder",label:"Advanced template builder",category:"Productivity"},{key:"advanced_workflows",label:"Advanced workflow automation",category:"Productivity"},{key:"advanced_reporting",label:"Advanced reporting & analytics",category:"Productivity"}
1,{key:"multi_office",label:"Multiple offices",category:"Organisation"},{key:"franchise_management",label:"Franchise management",category:"Organisation"},{key:"api_access",label:"API access",category:"Platform"},{key:"priority_support",label:"Priority support",category:"Platform"},{key:"advanced_finley",label:"Advanced Finley AI add-on",category:"Add-ons",addon:!0},{key:"refund_estimator",label:"Refund estimator add-on",category:"Add-ons",addon:!0},{key:"advanced_signatures",label:"Advanced signatures add-on",category:"Add-ons",addon:!0},{key:"aml_kyc",label:"AML/KYC verification add-on",category:"Add-ons",addon:!0}],Q=["client_job_management","forms_onboarding","standard_engagement_letters","firm_contact_details","booking_calendar_sync","standard_reports","core_finley","basic_signatures","document_uploads","secure_messaging","standard_onboarding","taxease_email_delivery"],ie=[...Q,"firm_logo_documents","firm_logo_portal","custom_brand_colours","branded_emails","branded_onboarding","branded_letters","branded_pdfs","branded_booking","branded_reminders","branded_signature_requests","advanced_template_builder","advanced_workflows","advanced_reporting","multi_office","priority_support","advanced_finley","refund_estimator"],fe=[...ie,"remove_taxease_branding","custom_domain","custom_login_page","custom_email_domain","custom_favicon","franchise_management","api_access","advanced_signatures","aml_kyc"],X={Free:Q,Starter:Q,Basic:Q,Professional:ie,Enterprise:fe};function he(u,g,f,o,m){const i=Date.now(),l=f!=="Inactive",w=g==="trial"&&(!o||new Date(o).getTime()>i),_=l&&(g==="active"||w),x=new Set(X[u]||X.Free),y={};for(const a of be){let n=x.has(a.key),j=n?"plan":null,r=null;const p=m?m[a.key]:null;p&&(p.expires_at&&new Date(p.expires_at).getTime()<i||(p.enabled===!0?(n=!0,j=p.addon?"addon":"override",r=p.expires_at||null):p.enabled===!1&&(n=!1,j="override"))),y[a.key]={enabled:n&&_,locked:!(n&&_),source:j,label:a.label,category:a.category,addon:!!a.addon,expires_at:r}}return y}const ve=["Free","Starter","Professional","Enterprise"],_e=["trial","active","past_due","cancelled","suspended"],ye=["monthly","annual","custom"];function je({organisationId:u,open:g,onClose:f,onSaved:o}){var B,A;const{toast:m}=G(),[i,l]=h.useState(!1),[w,S]=h.useState(!1),[_,x]=h.useState(null),[y,a]=h.useState(null),[n,j]=h.useState({}),[r,p]=h.useState({}),z=async()=>{var t,c,d,v,E,$,F;if(u){l(!0);try{const T=await I.functions.invoke("manageSubscriptions",{action:"get",organisation_id:u}),L=(T==null?void 0:T.data)||T,C=(L==null?void 0:L.organisation)||{};x(C),a((L==null?void 0:L.entitlements)||null),j(((t=C.entitlements)==null?void 0:t.feature_overrides)||{}),p({subscription_plan:C.subscription_plan||"Starter",subscription_status:C.subscription_status||"trial",client_limit:C.client_limit??"",account_limit:C.account_limit??"",status:C.status||"Active",trial_expiry:((d=(c=C.entitlements)==null?void 0:c.trial_expiry)==null?void 0:d.slice(0,10))||"",billing_frequency:((v=C.entitlements)==null?void 0:v.billing_frequency)||"",next_billing_date:(($=(E=C.entitlements)==null?void 0:E.next_billing_date)==null?void 0:$.slice(0,10))||"",notes:((F=C.entitlements)==null?void 0:F.notes)||""})}catch(T){m({title:"Failed to load",description:T.message,variant:"destructive"})}finally{l(!1)}}};if(h.useEffect(()=>{g&&z()},[g,u]),!g)return null;const q=he(r.subscription_plan,r.subscription_status,r.status,r.trial_expiry,n),P={};Object.entries(q).forEach(([t,c])=>{P[c.category]||(P[c.category]=[]),P[c.category].push({key:t,...c})});const U=(t,c)=>{j(d=>{var E;const v={...d};return c==="default"?delete v[t]:v[t]={...v[t]||{},enabled:c==="on",addon:(E=q[t])==null?void 0:E.addon,set_at:new Date().toISOString()},v})},H=(t,c)=>{j(d=>d[t]?{...d,[t]:{...d[t],expires_at:c?new Date(c).toISOString():null}}:d)},s=(t,c)=>{j(d=>d[t]?{...d,[t]:{...d[t],reason:c}}:d)},N=async()=>{var t;S(!0);try{const c={organisation_id:u,subscription_plan:r.subscription_plan,subscription_status:r.subscription_status,client_limit:r.client_limit===""?null:Number(r.client_limit),account_limit:r.account_limit===""?null:Number(r.account_limit),status:r.status,trial_expiry:r.trial_expiry?new Date(r.trial_expiry).toISOString():null,billing_frequency:r.billing_frequency||null,
1next_billing_date:r.next_billing_date?new Date(r.next_billing_date).toISOString():null,notes:r.notes||null,feature_overrides:n,summary:"Subscription & entitlements updated"},d=await I.functions.invoke("manageSubscriptions",{action:"update",...c});if((t=d==null?void 0:d.data)!=null&&t.error)throw new Error(d.data.error);m({title:"Subscription updated"}),o==null||o(),f==null||f()}catch(c){m({title:"Save failed",description:c.message,variant:"destructive"})}finally{S(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 p-0 sm:p-4",onClick:f,children:e.jsxs("div",{className:"bg-card border border-border w-full sm:max-w-2xl sm:rounded-2xl max-h-[92vh] overflow-y-auto",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 bg-card border-b border-border px-4 py-3 flex items-center justify-between z-10",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-foreground",children:(_==null?void 0:_.name)||"Organisation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Subscription & feature controls"})]}),e.jsx("button",{onClick:f,className:"p-1 rounded hover:bg-accent",children:e.jsx(le,{size:18,className:"text-muted-foreground"})})]}),i?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(D,{className:"w-6 h-6 text-violet-500 animate-spin"})}):e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsx(Y,{label:"Plan",value:r.subscription_plan,onChange:t=>p({...r,subscription_plan:t}),options:ve}),e.jsx(Y,{label:"Subscription status",value:r.subscription_status,onChange:t=>p({...r,subscription_status:t}),options:_e}),e.jsx(Y,{label:"Account status",value:r.status,onChange:t=>p({...r,status:t}),options:["Active","Inactive"]}),e.jsx(Y,{label:"Billing frequency",value:r.billing_frequency,onChange:t=>p({...r,billing_frequency:t}),options:["",...ye]}),e.jsx(M,{label:"Trial expiry",type:"date",value:r.trial_expiry,onChange:t=>p({...r,trial_expiry:t})}),e.jsx(M,{label:"Next billing date",type:"date",value:r.next_billing_date,onChange:t=>p({...r,next_billing_date:t})}),e.jsx(M,{label:"Client capacity",type:"number",value:r.client_limit,onChange:t=>p({...r,client_limit:t})}),e.jsx(M,{label:"Staff seats",type:"number",value:r.account_limit,onChange:t=>p({...r,account_limit:t})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:"Internal notes"}),e.jsx("textarea",{value:r.notes,onChange:t=>p({...r,notes:t.target.value}),rows:2,className:"w-full text-sm border border-border bg-background rounded-lg p-2.5 text-foreground"})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Feature entitlements"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-2",children:'Override any feature for this organisation. "Default" follows the plan; "On/Off" forces it (with optional expiry).'}),Object.entries(P).map(([t,c])=>e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mb-1.5",children:t}),e.jsx("div",{className:"space-y-1.5",children:c.map(d=>{var $;const v=n[d.key],E=v?v.enabled?"on":"off":"default";return e.jsxs("div",{className:"bg-background border border-border rounded-lg p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-xs font-medium text-foreground truncate",children:[d.label,d.addon&&e.jsx("span",{className:"ml-1.5 text-[9px] bg-amber-500/15 text-amber-400 px-1.5 py-0.5 rounded-full",children:"Add-on"})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Plan: ",d.source==="plan"?"included":"not included",d.source==="override"&&(v==null?void 0:v.enabled)===!1?" · overridden OFF":""]})]}),e.jsxs("select",{value:E,onChange:F=>U(d.key,F.target.value),className:"h-8 text-[11px] border border-border bg-card text-foreground rounded-md px-2 shrink-0",children:[e.jsx("option",{value:"default",children:"Default"}),e.jsx("option",{value:"on",children:"Force on"}),e.jsx("option",{value:"off",children:"Force off"})]})]}),E!=="default"&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx(oe,{size:11}),e.jsx("input",{type:"date",value:(($=v==null?void 0:v.expires_at)==null?void 0:$.slice(0,10))||"",onChange:F=>H(d.key,F.target.value),className:"h-7 text-[11px] border border-border bg-card text-foreground rounded px-1.5"})]}),e.jsx("input",{value:(v==null?void 0:v.reason)||"",onChange:F=>s(d.key,F.target.value),placeholder:"Reason (optional)",className:"flex-1 min-w-[120px] h-7 text-[11px] border border-border bg-card text-foreground rounded px-2"})]})]},d.key)})})]},t))]}),((A=(B=_==null?void 0:_.entitlements)==null?void 0:B.history)==null?void 0:A.length)>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-foreground mb-1",children:"Change history"}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:_.entitlements.history.slice(-10).reverse().map((t,c)=>e.jsxs("div",{className:"text-[11px] text-muted-foreground bg-background border border-border rounded p-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:t.by})," — ",t.action,e.jsxs("span",{className:"block text-[10px] text-muted-foreground
1/70",children:[new Date(t.at).toLocaleString("en-AU"),t.detail?` · ${t.detail}`:""]})]},c))})]}),e.jsxs("div",{className:"flex gap-2 sticky bottom-0 bg-card py-2 -mx-4 px-4 border-t border-border",children:[e.jsx(R,{variant:"outline",onClick:f,className:"flex-1 border-border",children:"Cancel"}),e.jsxs(R,{onClick:N,disabled:w,className:"flex-1 bg-violet-600 hover:bg-violet-700",children:[w?e.jsx(D,{size:16,className:"animate-spin"}):e.jsx(me,{size:16})," Save changes"]})]})]})]})})}function Y({label:u,value:g,onChange:f,options:o}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:u}),e.jsx("select",{value:g,onChange:m=>f(m.target.value),className:"w-full h-10 text-sm border border-border bg-card text-foreground rounded-lg px-3",children:o.map(m=>e.jsx("option",{value:m,children:m||"—"},m||"none"))})]})}function M({label:u,type:g,value:f,onChange:o}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-medium text-muted-foreground mb-1 block",children:u}),e.jsx(b,{type:g,value:f??"",onChange:m=>o(m.target.value),className:"bg-card border-border text-foreground"})]})}const Ne=["HQ","Main","Branch","Franchise","FRP"];function we({open:u,organisationId:g,organisationName:f,onClose:o,onCreated:m}){const[i,l]=h.useState({office_name:"",brand_name:f||"",office_type:"Branch",address:"",suburb:"",state:"",postcode:"",phone:"",email:""}),[w,S]=h.useState(!1),[_,x]=h.useState(""),y=(n,j)=>l(r=>({...r,[n]:j})),a=async()=>{if(!i.office_name.trim()){x("Office name is required");return}S(!0),x("");try{await I.functions.invoke("manageOffice",{action:"create_office",organisation_id:g,office_name:i.office_name.trim(),brand_name:i.brand_name.trim()||f||"",office_type:i.office_type,address:i.address,suburb:i.suburb,state:i.state,postcode:i.postcode,phone:i.phone,email:i.email}),m==null||m(),o==null||o(),l({office_name:"",brand_name:f||"",office_type:"Branch",address:"",suburb:"",state:"",postcode:"",phone:"",email:""})}catch(n){x((n==null?void 0:n.message)||"Failed to create office")}finally{S(!1)}};return e.jsx(te,{open:!!u,onOpenChange:n=>!n&&(o==null?void 0:o()),children:e.jsxs(ae,{className:"max-w-lg",children:[e.jsx(se,{children:e.jsxs(ne,{children:["Add office",f?` to ${f}`:""]})}),e.jsxs("div",{className:"space-y-3 max-h-[60vh] overflow-y-auto pr-1",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Office name"}),e.jsx(b,{value:i.office_name,onChange:n=>y("office_name",n.target.value),placeholder:"e.g. Ringwood"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Brand name"}),e.jsx(b,{value:i.brand_name,onChange:n=>y("brand_name",n.target.value),placeholder:"e.g. R&K Taxation Experts"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Office type"}),e.jsx("select",{value:i.office_type,onChange:n=>y("office_type",n.target.value),className:"w-full h-9 rounded-md border border-input bg-transparent px-3 text-sm text-foreground",children:Ne.map(n=>e.jsx("option",{value:n,children:n},n))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Street address"}),e.jsx(b,{value:i.address,onChange:n=>y("address",n.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Suburb"}),e.jsx(b,{value:i.suburb,onChange:n=>y("suburb",n.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"State"}),e.jsx(b,{value:i.state,onChange:n=>y("state",n.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Postcode"}),e.jsx(b,{value:i.postcode,onChange:n=>y("postcode",n.target.value)})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Phone"}),e.jsx(b,{value:i.phone,onChange:n=>y("phone",n.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{children:"Email"}),e.jsx(b,{value:i.email,onChange:n=>y("email",n.target.value)})]})]}),_?e.jsx("p",{className:"text-xs text-red-400",children:_}):null]}),e.jsxs(re,{children:[e.jsx(R,{variant:"ghost",onClick:o,disabled:w,children:"Cancel"}),e.jsxs(R,{onClick:a,disabled:w,className:"bg-violet-600 hover:bg-violet-700 text-white",children:[w?e.jsx(D,{className:"w-4 h-4 animate-spin"}):null," Create office"]})]})]})})}function ke({open:u,organisationId:g,organisationName:f,onClose:o,onSaved:m}){const{toast:i}
1=G(),[l,w]=h.useState(null),[S,_]=h.useState(!1);h.useEffect(()=>{!u||!g||I.entities.Company.get(g).then(a=>{w({name:a.name||"",owner_name:a.owner_name||"",email:a.email||"",phone:a.phone||"",address:a.address||"",suburb:a.suburb||"",state:a.state||"",postcode:a.postcode||"",website:a.website||"",abn:a.abn||"",tax_agent_registration_number:a.tax_agent_registration_number||"",principal_accountant_name:a.principal_accountant_name||"",support_email:a.support_email||"",support_phone:a.support_phone||"",primary_color:a.primary_color||"",logo_url:a.logo_url||""})}).catch(()=>w({}))},[u,g]);const x=(a,n)=>w(j=>({...j,[a]:n})),y=async()=>{var a;if(!((a=l.name)!=null&&a.trim())){i({title:"Organisation name is required",variant:"destructive"});return}_(!0);try{await I.functions.invoke("manageOffice",{action:"update_organisation",organisation_id:g,...l}),i({title:"Organisation updated"}),m==null||m(),o==null||o()}catch(n){i({title:"Update failed",description:n==null?void 0:n.message,variant:"destructive"})}finally{_(!1)}};return e.jsx(te,{open:!!u,onOpenChange:a=>!a&&(o==null?void 0:o()),children:e.jsxs(ae,{className:"max-w-lg",children:[e.jsx(se,{children:e.jsxs(ne,{children:["Edit organisation — ",f]})}),l?e.jsxs("div",{className:"space-y-3 max-h-[60vh] overflow-y-auto pr-1",children:[e.jsx(k,{label:"Organisation name",children:e.jsx(b,{value:l.name,onChange:a=>x("name",a.target.value)})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(k,{label:"Owner / principal contact",children:e.jsx(b,{value:l.owner_name,onChange:a=>x("owner_name",a.target.value)})}),e.jsx(k,{label:"Contact email",children:e.jsx(b,{value:l.email,onChange:a=>x("email",a.target.value)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(k,{label:"Phone",children:e.jsx(b,{value:l.phone,onChange:a=>x("phone",a.target.value)})}),e.jsx(k,{label:"Website",children:e.jsx(b,{value:l.website,onChange:a=>x("website",a.target.value)})})]}),e.jsx(k,{label:"Head office address",children:e.jsx(b,{value:l.address,onChange:a=>x("address",a.target.value)})}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(k,{label:"Suburb",children:e.jsx(b,{value:l.suburb,onChange:a=>x("suburb",a.target.value)})}),e.jsx(k,{label:"State",children:e.jsx(b,{value:l.state,onChange:a=>x("state",a.target.value)})}),e.jsx(k,{label:"Postcode",children:e.jsx(b,{value:l.postcode,onChange:a=>x("postcode",a.target.value)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(k,{label:"ABN",children:e.jsx(b,{value:l.abn,onChange:a=>x("abn",a.target.value)})}),e.jsx(k,{label:"Tax agent reg. no.",children:e.jsx(b,{value:l.tax_agent_registration_number,onChange:a=>x("tax_agent_registration_number",a.target.value)})})]}),e.jsx(k,{label:"Principal accountant name",children:e.jsx(b,{value:l.principal_accountant_name,onChange:a=>x("principal_accountant_name",a.target.value)})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(k,{label:"Support email",children:e.jsx(b,{value:l.support_email,onChange:a=>x("support_email",a.target.value)})}),e.jsx(k,{label:"Support phone",children:e.jsx(b,{value:l.support_phone,onChange:a=>x("support_phone",a.target.value)})})]}),e.jsx(k,{label:"Brand colour (hex)",children:e.jsx(b,{value:l.primary_color,onChange:a=>x("primary_color",a.target.value),placeholder:"#1f2937"})})]}):e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(D,{className:"w-5 h-5 animate-spin text-violet-500"})}),e.jsxs(re,{children:[e.jsx(R,{variant:"ghost",onClick:o,disabled:S,children:"Cancel"}),e.jsxs(R,{onClick:y,disabled:S||!l,className:"bg-violet-600 hover:bg-violet-700 text-white",children:[S?e.jsx(D,{className:"w-4 h-4 animate-spin"}):null," Save profile"]})]})]})})}function k({label:u,children:g}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(O,{className:"text-xs text-muted-foreground",children:u}),g]})}const J={Free:"bg-gray-500/15 text-gray-400",Starter:"bg-gray-500/15 text-gray-300",Professional:"bg-blue-500/15 text-blue-400",Enterprise:"bg-violet-500/15 text-violet-300"},Z={trial:"bg-amber-500/15 text-amber-400",active:"bg-emerald-500/15 text-emerald-400",past_due:"bg-orange-500/15 text-orange-400",cancelled:"bg-gray-500/15 text-gray-400",suspended:"bg-red-500/15 text-red-400"},ee={Active:"bg-emerald-500/15 text-emerald-400",Suspended:"bg-red-500/15 text-red-400","Pending Setup":"bg-amber-500/15 text-amber-400",Closed:"bg-gray-500/15 text-gray-400"};
1function Se(u){const g=[u.suburb,u.state,u.postcode].filter(Boolean).join(" ");return[u.address,g].filter(Boolean).join(", ")}function Fe(){var U,H;const[u,g]=h.useState([]),[f,o]=h.useState(!0),[m,i]=h.useState(""),[l,w]=h.useState(null),[S,_]=h.useState(null),[x,y]=h.useState(null),[a,n]=h.useState(null),[j,r]=h.useState(""),p=async()=>{var s;o(!0);try{const N=await I.functions.invoke("manageSubscriptions",{action:"list"});g(((s=N==null?void 0:N.data)==null?void 0:s.organisations)||(N==null?void 0:N.organisations)||[])}catch{g([])}finally{o(!1)}};h.useEffect(()=>{p()},[]);const{toast:z}=G(),q=async(s,N,B)=>{try{await I.functions.invoke("manageSubscriptions",{action:"update",organisation_id:s.id,...N}),z({title:B}),p()}catch(A){z({title:"Action failed",description:A==null?void 0:A.message,variant:"destructive"})}},P=u.filter(s=>[s.name,s.owner_name,s.email,s.plan].some(N=>(N||"").toLowerCase().includes(m.toLowerCase())));return e.jsxs("div",{className:"space-y-4 pb-10",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(de,{size:20,className:"text-violet-500"})," Organisations & Subscriptions"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Control plans, trials, feature entitlements and overrides for every organisation."})]}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx("input",{value:m,onChange:s=>i(s.target.value),placeholder:"Search organisations…",className:"w-full pl-9 pr-3 py-2.5 rounded-lg bg-card border border-border text-foreground placeholder:text-muted-foreground text-sm",style:{minHeight:44}})]}),f?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(D,{className:"w-6 h-6 text-violet-500 animate-spin"})}):P.length===0?e.jsxs("div",{className:"bg-card border border-border rounded-2xl p-8 text-center",children:[e.jsx(V,{size:28,className:"mx-auto text-muted-foreground/60 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No organisations found."})]}):e.jsx("div",{className:"space-y-2",children:P.map(s=>{const N=S===s.id,B=s.office_list||[],A=B.filter(t=>[t.display_name,t.name,t.manager_name,t.status,t.office_type].some(c=>(c||"").toLowerCase().includes(j.toLowerCase())));return e.jsxs("div",{className:"bg-card border border-border rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-stretch",children:[e.jsx("button",{onClick:()=>_(N?null:s.id),className:"flex-1 text-left p-4 hover:bg-accent/30 transition-colors",children:e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(ce,{size:16,className:`text-muted-foreground/60 shrink-0 transition-transform ${N?"rotate-90":""}`}),e.jsx("p",{className:"font-semibold text-foreground truncate",children:s.name}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full ${J[s.plan]||J.Starter}`,children:s.plan}),e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full ${Z[s.status]||Z.trial}`,children:s.status}),s.account_status==="Inactive"&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-red-500/15 text-red-400",children:"Inactive"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 truncate pl-6",children:[s.owner_name?`${s.owner_name} · `:"",s.email]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-0.5 mt-1.5 text-[11px] text-muted-foreground pl-6",children:[e.jsxs("span",{children:[s.active_clients," clients",s.staff_seats?` / ${s.staff_seats} seats`:""]}
1),e.jsxs("span",{children:[s.offices," ",s.offices===1?"office":"offices"]}),s.trial_expiry&&e.jsxs("span",{className:"text-amber-400",children:["Trial ends ",new Date(s.trial_expiry).toLocaleDateString("en-AU")]}),e.jsxs("span",{className:"text-violet-400",children:[s.feature_count," features"]}),s.override_count>0&&e.jsxs("span",{className:"text-amber-400",children:[s.override_count," overrides"]})]})]})})}),e.jsxs("div",{className:"flex items-stretch shrink-0",children:[e.jsxs("button",{onClick:()=>n(s.id),className:"px-3 text-xs font-medium text-foreground hover:bg-accent/40 transition-colors whitespace-nowrap border-l border-border flex items-center gap-1",children:[e.jsx(V,{size:14})," Profile"]}),e.jsxs("button",{onClick:()=>q(s,{subscription_status:s.status==="suspended"?"active":"suspended"},s.status==="suspended"?"Organisation reactivated":"Organisation suspended"),className:"px-3 text-xs font-medium text-amber-300 hover:text-amber-200 hover:bg-amber-500/10 transition-colors whitespace-nowrap border-l border-border flex items-center gap-1",children:[e.jsx(ge,{size:14})," ",s.status==="suspended"?"Reactivate":"Suspend"]}),e.jsxs("button",{onClick:()=>q(s,{status:s.account_status==="Inactive"?"Active":"Inactive"},s.account_status==="Inactive"?"Organisation restored":"Organisation archived"),className:"px-3 text-xs font-medium text-red-300 hover:text-red-200 hover:bg-red-500/10 transition-colors whitespace-nowrap border-l border-border flex items-center gap-1",children:[e.jsx(ue,{size:14})," ",s.account_status==="Inactive"?"Restore":"Archive"]}),e.jsx("button",{onClick:()=>w(s.id),className:"px-4 text-xs font-medium text-violet-300 hover:text-violet-200 hover:bg-violet-500/10 transition-colors whitespace-nowrap border-l border-border",children:"Edit"})]})]}),N&&e.jsxs("div",{className:"border-t border-border bg-muted/30 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 gap-2",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground font-semibold",children:"Offices in this organisation"}),e.jsxs("div",{className:"flex items-center gap-2",children:[B.length>0?e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx("input",{value:j,onChange:t=>r(t.target.value),placeholder:"Search offices…",className:"pl-7 pr-2 py-1.5 rounded-md bg-card border border-border text-xs text-foreground placeholder:text-muted-foreground",style:{minHeight:36}})]}):null,e.jsxs("button",{onClick:()=>y(s.id),className:"text-xs font-medium text-violet-300 hover:text-violet-200 flex items-center gap-1",children:[e.jsx(xe,{size:12})," Add office"]})]})]}),B.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:"No offices yet."}):A.length===0?e.jsxs("p",{className:"text-xs text-muted-foreground py-2",children:["No offices match “",j,"”."]}):e.jsx("div",{className:"overflow-x-auto rounded-lg border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[10px] uppercase tracking-wide text-muted-foreground bg-muted/40",children:[e.jsx("th",{className:"py-2 px-3 font-semibold",children:"Office Name"}),e.jsx("th",{className:"py-2 px-3 font-semibold",children:"Type"}),e.jsx("th",{className:"py-2 px-3 font-semibold",children:"Status"}),e.jsx("th",{className:"py-2 px-3 font-semibold",children:"Manager"}),e.jsx("th",{className:"py-2 px-3 font-semibold text-right",children:"Clients"}),e.jsx("th",{className:"py-2 px-3 font-semibold text-right",children:"Accountants"}),e.jsx("th",{className:"py-2 px-3 font-semibold text-right",children:"Actions"})]})}),e.jsx("tbody",{children:A.map(t=>{const c=Se(t);return e.jsxs("tr",{className:"border-t border-border hover:bg-accent/30 align-top",children:[e.jsxs("td",{className:"py-2 px-3",children:[e.jsx(W,{to:`/super/offices/${t.id}`,className:"text-sm font-medium text-violet-300 hover:text-violet-200 truncate block",children:t.display_name||t.name}),c?e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:c}):null]}),e.jsx("td",{className:"py-2 px-3",children:e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full bg-gray-500/15 text-gray-400",children:t.office_type||"Branch"})}),e.jsx("td",{className:"py-2 px-3",children:e.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full ${ee[t.status]||ee.Active}`,children:t.status||"Active"})}),e.jsx("td",{className:"py-2 px-3 text-xs text-muted-foreground",children:t.manager_name||"—"}),e.jsx("td",{className:"py-2 px-3 text-xs text-right",children:t.client_count}),e.jsx("td",{className:"py-2 px-3 text-xs text-right",children:t.accountant_count}),e.jsx("td",{className:"py-2 px-3 text-right",children:e.jsxs(W,{to:`/super/offices/${t.id}`,className:"inline-flex items-center gap-1 text-xs font-medium text-violet-300 hover:text-violet-200",children:[e.jsx(pe,{size:12})," Edit"]})})]},t.id)})})]})}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2.5",children:"One organisation-wide subscription covers every office above. Office status is operational only (not billing). Click an office to view & edit full details."})]})]},s.id)})}),e.jsx(je,{organisationId:l,open:!!l,onClose:()=>w(null),onSaved:p}),e.jsx(we,{open:!!x,organisationId:x,organisationName:(U=u.find(s=>
1s.id===x))==null?void 0:U.name,onClose:()=>y(null),onCreated:p}),e.jsx(ke,{open:!!a,organisationId:a,organisationName:(H=u.find(s=>s.id===a))==null?void 0:H.name,onClose:()=>n(null),onSaved:p})]})}export{Fe 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.