1import{Q as H,r as n,j as e,a2 as M,c as I,bM as Te,aj as Ae,bg as Y,aJ as Re,be as ee,O as V,o as Oe,bI as Pe,ay as Ie,bJ as ne,Z as te,n as Le,$ as oe,ar as le,aZ as ie,C as ce,cO as De,bu as Be,cP as Fe,a0 as me,U as Me,f as Ge,u as ue,b1 as re,I as U,bA as G,aX as $e,bm as ae,av as se,ci as Ue,bn as de}from"./index-sy1_3QS7.js";import{R as ze}from"./RowActionsMenu-Bu6iQBX3.js";import{B as We}from"./Breadcrumbs-qrbEhwT8.js";import{b as Ye}from"./breadcrumbHelper-iVarpcvw.js";import{M as xe,e as be,m as ge,f as O}from"./currency-BcQnOpyz.js";import{e as pe}from"./apiError-CArl5-g6.js";import{u as Ve}from"./useCloseOnOrgChange-CkQsTSCk.js";import{u as He,E as qe}from"./useExport-C5k4hFAG.js";import{s as Ze,a as Xe}from"./selectStyles-9JiBYRZI.js";import{W as Je}from"./WizardShell-DbLFewBi.js";import{W as he}from"./wallet-DXDn0DFr.js";import{C as Qe}from"./cpu-CjXcgVgR.js";import{C as Ke}from"./credit-card-B5qqfXGY.js";import{D as et}from"./download-9jcSWGu9.js";import"./file-down-B-9xjJQn.js";import"./xlsx-CKN5doRT.js";import"./csv-iccbTvx_.js";import"./blobErrorBody-DeLL2ap3.js";import"./panel-right-open-CnQzaxsD.js";/** 2 * @license lucide-react v0.316.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const tt=H("BadgeDollarSign",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 18V6",key:"zqpxq5"}]]);/** 7 * @license lucide-react v0.316.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const rt=H("Factory",[["path",{d:"M2 20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8l-7 5V8l-7 5V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"159hny"}],["path",{d:"M17 18h1",key:"uldtlt"}],["path",{d:"M12 18h1",key:"s9uhes"}],["path",{d:"M7 18h1",key:"1neino"}]]);/** 12 * @license lucide-react v0.316.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const at=H("HandHeart",[["path",{d:"M11 14h2a2 2 0 1 0 0-4h-3c-.6 0-1.1.2-1.4.6L3 16",key:"1ifwr1"}],["path",{d:"m7 20 1.6-1.4c.3-.4.8-.6 1.4-.6h4c1.1 0 2.1-.4 2.8-1.2l4.6-4.4a2 2 0 0 0-2.75-2.91l-4.2 3.9",key:"17abbs"}],["path",{d:"m2 15 6 6",key:"10dquu"}],["path",{d:"M19.5 8.5c.7-.7 1.5-1.6 1.5-2.7A2.73 2.73 0 0 0 16 4a2.78 2.78 0 0 0-5 1.8c0 1.2.8 2 1.5 2.8L16 12Z",key:"1h3036"}]]);function st({code:t,onClose:r,onSuccess:d}){const[i,s]=n.useState(""),[c,x]=n.useState(""),[u,E]=n.useState("department"),[b,f]=n.useState(""),[v,l]=n.useState(""),[N,h]=n.useState(""),[g,j]=n.useState(!1);n.useEffect(()=>{var p;t&&(s(t.code),x(t.name),E(t.type),f(((p=t.allocation)==null?void 0:p.toString())||""),l(t.description||""))},[t]),n.useEffect(()=>{const p=o=>{o.key==="Escape"&&r()};return document.addEventListener("keydown",p),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",p),document.body.style.overflow="unset"}},[r]);const m=async p=>{var k,S;p.preventDefault(),h("");const o=b?parseFloat(b):null;if(be(o)){h(ge("Allocation"));return}j(!0);try{const w=M();if(!w){h("You must be logged in to update a budget code"),j(!1);return}await I.put(`/budget-codes/${t.id}`,{code:i.trim(),name:c.trim(),type:u,allocation:b?parseFloat(b):null,description:v.trim()||null},{headers:{Authorization:`Bearer ${w}`,"Content-Type":"application/json"}}),d()}catch(w){Te.isAxiosError(w)?((k=w.response)==null?void 0:k.status)===401?h("Session expired. Please log in again."):((S=w.response)==null?void 0:S.status)===404?h("Budget code not found."):h(pe(w,"Failed to update budget code. Please try again.")):h("An unexpected error occurred. Please try again.")}finally{j(!1)}},y=p=>{p.target===p.currentTarget&&r()};return e.jsx("div",{className:"modal-overlay",onClick:y,role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{id:"modal-title",className:"modal-title",children:"Edit Budget Code"}),e.jsx("button",{onClick:r,className:"modal-close-btn","aria-label":"Close modal",disabled:g,children:e.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:m,className:"modal-body",children:[N&&e.jsx("div",{className:"alert-error",children:e.jsx("p",{className:"alert-error-text",children:N})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"budget-code",className:"label-text",children:["Code ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsx("input",{id:"budget-code",type:"text",value:i,onChange:p=>s(p.target.value),required:!0,maxLength:50,className:"input-field",placeholder:"DEPT-IT-001",disabled:g,autoFocus:!0}),e.jsx("p",{className:"label-hint",children:"Must be unique within the organization"})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"budget-name",className:"label-text",children:["Name ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsx("input",{id:"budget-name",type:"text",value:c,onChange:p=>x(p.target.value),required:!0,maxLength:200,className:"input-field",placeholder:"IT Department",disabled:g})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"budget-type",className:"label-text",children:["Type ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsxs("select",{id:"budget-type",value:u,onChange:p=>E(p.target.value),className:"select-field",disabled:g,children:[e.jsx("option",{value:"department",children:"Department"}),e.jsx("option",{value:"grant",children:"Grant"}),e.jsx("option",{value:"program",children:"Program"}),e.jsx("option",{value:"cost_center",children:"Cost Center"}),e.jsx("option",{value:"fund",children:"Fund"}),e.jsx("option",{value:"custom",children:"Custom"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"budget-allocation",className:"label-text",children:"Allocation"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 dark:text-brand-dark-text-secondary",children:"$"}),e.jsx("input",{id:"budget-allocation",type:"number",step:"0.01",min:"0",max:xe,value:b,onChange:p=>f(p.target.value),className:"number-field pl-8",placeholder:"0.00",disabled:g})]}),e.jsx("p",{className:"label-hint",children:"Optional budget allocation amount"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"budget-description",className:"label-text",children:"Description"}
16),e.jsx("textarea",{id:"budget-description",value:v,onChange:p=>l(p.target.value),rows:3,maxLength:500,className:"input-field",placeholder:"Optional description of this budget code...",disabled:g}),e.jsxs("p",{className:"label-hint",children:[v.length,"/500 characters"]})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{type:"button",onClick:r,disabled:g,className:"flex-1 btn-secondary",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:g||!i.trim()||!c.trim(),className:"flex-1 btn-primary",children:g?e.jsxs("span",{className:"flex items-center justify-center",children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Updating..."]}):"Update Budget Code"})]})]})]})})}function dt({isOpen:t,organizationId:r,onClose:d,onUpdate:i,currentLabels:s}){Ve(t,d);const[c,x]=n.useState({custom_type_1_label:s.custom_type_1_label||"Custom 1",custom_type_2_label:s.custom_type_2_label||"Custom 2",custom_type_3_label:s.custom_type_3_label||"Custom 3"}),[u,E]=n.useState(!1),[b,f]=n.useState(""),v=async l=>{l.preventDefault(),E(!0),f("");try{await I.put(`/organizations/${r}`,c),i(),d()}catch(N){f(V(N))}finally{E(!1)}};return e.jsxs(Ae,{isOpen:t,onClose:d,title:"Configure Custom Budget Types",size:"lg",closeDisabled:u,footer:e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(ee,{variant:"secondary",onClick:d,disabled:u,children:"Cancel"}),e.jsx(ee,{type:"submit",form:"custom-types-form",isLoading:u,children:"Save Changes"})]}),children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-brand-dark-text-secondary mb-6",children:"Customize the names of your three custom budget code types. These will appear throughout the system when creating and viewing budget codes."}),e.jsxs("form",{id:"custom-types-form",onSubmit:v,children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(Y,{label:"Custom Type 1",value:c.custom_type_1_label,onChange:l=>x({...c,custom_type_1_label:l}),placeholder:"e.g., Marketing Campaigns",maxLength:100,required:!0,disabled:u}),e.jsx(Y,{label:"Custom Type 2",value:c.custom_type_2_label,onChange:l=>x({...c,custom_type_2_label:l}),placeholder:"e.g., Regional Offices",maxLength:100,required:!0,disabled:u}),e.jsx(Y,{label:"Custom Type 3",value:c.custom_type_3_label,onChange:l=>x({...c,custom_type_3_label:l}),placeholder:"e.g., Special Initiatives",maxLength:100,required:!0,disabled:u})]}),b&&e.jsx("div",{className:"mt-4",children:e.jsx(Re,{message:b,onDismiss:()=>f(""),variant:"banner"})})]})]})}const ke=[{value:"corporate",label:"Corporate/Business",description:"Standard business operations, commercial enterprises",icon:"Building2"},{value:"education",label:"Education",description:"Schools, universities, training institutions",icon:"GraduationCap"},{value:"healthcare",label:"Healthcare",description:"Hospitals, clinics, medical practices",icon:"Heart"},{value:"nonprofit",label:"Nonprofit/NGO",description:"Charities, foundations, non-governmental organizations",icon:"HandHeart"},{value:"government",label:"Government",description:"Public sector, municipal, state, federal agencies",icon:"Landmark"},{value:"technology",label:"Technology",description:"Tech companies, startups, software development",icon:"Cpu"},{value:"manufacturing",label:"Manufacturing",description:"Production, industrial, factory operations",icon:"Factory"},{value:"professional_services",label:"Professional Services",description:"Consulting, legal, accounting, advisory firms",icon:"Briefcase"}],C={SELECT_TYPE:0,CONFIGURE:1,PREVIEW:2,CREATE:3},nt=["Select Type","Configure","Preview","Create"],P={department:{label:"Departments",description:"Organizational units and divisions",icon:"Users",color:"blue"},cost_center:{label:"Cost Centers",description:"Cost allocation categories",icon:"Target",color:"purple"},program:{label:"Programs",description:"Activities and initiatives",icon:"Briefcase",color:"amber"},fund:{label:"Funds",description:"Funding sources and reserves",icon:"Wallet",color:"emerald"},grant:{label:"Grants",description:"External grant funding",icon:"BadgeDollarSign",color:"teal"}};function ot(){return{organizationType:null,includeDepartments:!0,includeCostCenters:!0,includePrograms:!0,includeFunds:!0,customPrefix:""}}
16function ye(){return{currentStep:C.SELECT_TYPE,config:ot(),previewedCodes:null,previewResponse:null,generationProgress:{status:"idle"},createdResult:null,creationProgress:{status:"idle"},isLoading:!1,error:null}}function fe(t){return t?t.filter(r=>r.is_selected).length:0}function lt(t){const r={department:{total:0,selected:0},cost_center:{total:0,selected:0},program:{total:0,selected:0},fund:{total:0,selected:0},grant:{total:0,selected:0}};if(!t)return r;for(const d of t)r[d.type]&&(r[d.type].total++,d.is_selected&&r[d.type].selected++);return r}async function it(t,r){return(await I.post(`/organizations/${t}/budget-codes/autogenerate/preview`,r)).data}async function ct(t,r){return(await I.post(`/organizations/${t}/budget-codes/autogenerate/create`,r)).data}function mt(t,r){switch(r.type){case"SET_STEP":return{...t,currentStep:r.step,error:null};case"SET_ORGANIZATION_TYPE":return{...t,config:{...t.config,organizationType:r.organizationType}};case"SET_INCLUDE_DEPARTMENTS":return{...t,config:{...t.config,includeDepartments:r.include}};case"SET_INCLUDE_COST_CENTERS":return{...t,config:{...t.config,includeCostCenters:r.include}};case"SET_INCLUDE_PROGRAMS":return{...t,config:{...t.config,includePrograms:r.include}};case"SET_INCLUDE_FUNDS":return{...t,config:{...t.config,includeFunds:r.include}};case"SET_CUSTOM_PREFIX":return{...t,config:{...t.config,customPrefix:r.prefix}};case"GENERATION_START":return{...t,isLoading:!0,error:null,generationProgress:{status:"generating"}};case"GENERATION_SUCCESS":return{...t,isLoading:!1,previewedCodes:r.response.suggested_codes,previewResponse:r.response,generationProgress:{status:"complete"},currentStep:C.PREVIEW};case"GENERATION_ERROR":return{...t,isLoading:!1,error:r.error,generationProgress:{status:"error",message:r.error}};case"TOGGLE_CODE_SELECTION":return t.previewedCodes?{...t,previewedCodes:t.previewedCodes.map(d=>d.code===r.code?{...d,is_selected:!d.is_selected}:d)}:t;case"SELECT_ALL_CODES":return t.previewedCodes?{...t,previewedCodes:t.previewedCodes.map(d=>({...d,is_selected:r.selected}))}:t;case"SELECT_ALL_BY_TYPE":return t.previewedCodes?{...t,previewedCodes:t.previewedCodes.map(d=>d.type===r.codeType?{...d,is_selected:r.selected}:d)}:t;case"CREATION_START":return{...t,isLoading:!0,error:null,creationProgress:{status:"creating"}};case"CREATION_SUCCESS":return{...t,isLoading:!1,createdResult:r.result,creationProgress:{status:"complete"},currentStep:C.CREATE};case"CREATION_ERROR":return{...t,isLoading:!1,error:r.error,creationProgress:{status:"error",message:r.error}};case"RESET":return ye();case"SET_ERROR":return{...t,error:r.error};default:return t}}function ut(){const[t,r]=n.useReducer(mt,ye()),d=n.useCallback(o=>{r({type:"SET_STEP",step:o})},[]),i=n.useCallback(()=>{const o=Object.values(C),k=o.indexOf(t.currentStep);k<o.length-1&&r({type:"SET_STEP",step:o[k+1]})},[t.currentStep]),s=n.useCallback(()=>{const o=Object.values(C),k=o.indexOf(t.currentStep);k>0&&r({type:"SET_STEP",step:o[k-1]})},[t.currentStep]),c=n.useCallback(()=>{const o=Object.values(C);return o.indexOf(t.currentStep)>=o.length-1?!1:t.currentStep===C.SELECT_TYPE?t.config.organizationType!==null:t.currentStep===C.CONFIGURE?t.config.includeDepartments||t.config.includeCostCenters||t.config.includePrograms||t.config.includeFunds:t.currentStep===C.PREVIEW?t.previewedCodes!==null&&t.previewedCodes.some(S=>S.is_selected):!0},[t.currentStep,t.config,t.previewedCodes]),x=n.useCallback(()=>t.currentStep>C.SELECT_TYPE,[t.currentStep]),u=n.useCallback(o=>{r({type:"SET_ORGANIZATION_TYPE",organizationType:o})},[]),E=n.useCallback(o=>{r({type:"SET_INCLUDE_DEPARTMENTS",include:o})},[]),b=n.useCallback(o=>{r({type:"SET_INCLUDE_COST_CENTERS",include:o})},[]),f=n.useCallback(o=>{r({type:"SET_INCLUDE_PROGRAMS",include:o})},[]),v=n.useCallback(o=>{r({type:"SET_INCLUDE_FUNDS",include:o})},[]),l=n.useCallback(o=>{r({type:"SET_CUSTOM_PREFIX",prefix:o})},[]),N=n.useCallback(async o=>{if(t.config.organizationType){r({type:"GENERATION_START"});try{const k=await it(o,{organization_type:t.config.organizationType,include_departments:t.config.includeDepartments,include_cost_centers:t.config.includeCostCenters,include_programs:t.config.includePrograms,include_funds:t.config.includeFunds,custom_prefix:t.config.customPrefix||void 0});r({type:"GENERATION_SUCCESS",response:k})}catch(k){const S=V(k);r({type:"GENERATION_ERROR",error:S})}}},[t.config]),h=n.useCallback(o=>{r({type:"TOGGLE_CODE_SELECTION",code:o})},[]),g=n.useCallback(o=>{r({type:"SELECT_ALL_CODES",selected:o})},[]),j=n.useCallback((o,k)=>{r({type:"SELECT_ALL_BY_TYPE",codeType:o,selected:k})},[]),m=n.useCallback(async o=>{if(!t.previewedCodes)return;const k=t.previewedCodes.filter(S=>S.is_selected);if(k.length!==0){r({type:"CREATION_START"});try{const S=await ct(o,{codes:k.map(w=>({code:w.code,name:w.name,type:w.type,description:w.description}))});r({type:"CREATION_SUCCESS",result:S})}catch(S){const w=V(S);r({type:"CREATION_ERROR",error:w})}}},[t.previewedCodes]),y=n.useCallback(()=>{r({type:"RESET"})},[]),p=n.useCallback(()=>{r({type:"SET_ERROR",error:null})},[]);return{state:t,setStep:d,nextStep:i,prevStep:s,canGoNext:c,canGoPrev:x,setOrganizationType:u,setIncludeDepartments:E,setIncludeCostCenters:b,setIncludePrograms:f,setIncludeFunds:v,setCustomPrefix:l,generatePreview:N,toggleCodeSelection:h,selectAllCodes:g,selectAllByType:j,createCodes:m,reset:y,clearError:p}}const xt={Building2:me,GraduationCap:Fe,Heart:Be,HandHeart:at,Landmark:De,Cpu:Qe,Factory:rt,Briefcase:ie,Users:oe,Target:le,Wallet:he,BadgeDollarSign:tt};function bt(t){return xt[t]||me}function gt({selectedType:t,onSelect:r}){return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-brand-text-primary dark:text-brand-dark-text-primary mb-2",children:"Select Your Organization Type"}),e.jsx("p",{className:"text-sm text-brand-text-muted dark:text-brand-dark-text-muted",children:"Choose the type that best describes your organization. This will determine the budget codes generated for you."})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:ke.map(d=>{const i=bt(d.icon),s=t===d.value;return e.jsx("button",{onClick:()=>
16r(d.value),className:`p-4 rounded-lg border-2 text-left transition-all ${s?"border-amber-500 bg-amber-50 dark:bg-amber-900/30 ring-2 ring-amber-500/20":"border-brand-border-subtle dark:border-brand-dark-border hover:border-amber-300 dark:hover:border-amber-600 hover:bg-gray-50 dark:hover:bg-gray-800/50"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${s?"bg-amber-100 dark:bg-amber-800/50 text-amber-600 dark:text-amber-400":"bg-brand-bg-subtle dark:bg-brand-dark-bg-subtle text-brand-text-muted dark:text-brand-dark-text-muted"}`,children:e.jsx(i,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${s?"text-amber-700 dark:text-amber-300":"text-brand-text-primary dark:text-brand-dark-text-primary"}`,children:d.label}),s&&e.jsx(ce,{className:"w-4 h-4 text-amber-500"})]}),e.jsx("p",{className:"text-xs text-brand-text-muted dark:text-brand-dark-text-muted mt-0.5 line-clamp-2",children:d.description})]})]})},d.value)})})]})}function pt({includeDepartments:t,includeCostCenters:r,includePrograms:d,includeFunds:i,customPrefix:s,onSetIncludeDepartments:c,onSetIncludeCostCenters:x,onSetIncludePrograms:u,onSetIncludeFunds:E,onSetCustomPrefix:b,organizationTypeLabel:f}){const v=[{key:"department",label:P.department.label,description:P.department.description,icon:oe,color:"blue",checked:t,onChange:c},{key:"cost_center",label:P.cost_center.label,description:P.cost_center.description,icon:le,color:"purple",checked:r,onChange:x},{key:"program",label:P.program.label,description:P.program.description,icon:ie,color:"amber",checked:d,onChange:u},{key:"fund",label:P.fund.label,description:P.fund.description,icon:he,color:"amber",checked:i,onChange:E}];return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-brand-text-primary dark:text-brand-dark-text-primary mb-2",children:"Configure Budget Codes"}),e.jsxs("p",{className:"text-sm text-brand-text-muted dark:text-brand-dark-text-muted",children:["Select which types of budget codes to generate for your"," ",e.jsx("span",{className:"font-medium text-amber-600 dark:text-amber-400",children:f})," ","organization."]})]}),e.jsx("div",{className:"space-y-3",children:v.map(l=>{const N=l.icon;return e.jsxs("label",{className:`flex items-center gap-4 p-4 rounded-lg border cursor-pointer transition-all ${l.checked?"border-amber-300 dark:border-amber-600 bg-amber-50/50 dark:bg-amber-900/20":"border-brand-border-subtle dark:border-brand-dark-border hover:bg-gray-50 dark:hover:bg-gray-800/50"}`,children:[e.jsx("input",{type:"checkbox",checked:l.checked,onChange:h=>l.onChange(h.target.checked),className:"w-5 h-5 text-amber-600 border-gray-300 rounded focus:ring-focus"}),e.jsx("div",{className:`p-2 rounded-lg ${l.checked?"bg-amber-100 dark:bg-amber-800/50 text-amber-600 dark:text-amber-400":"bg-brand-bg-subtle dark:bg-brand-dark-bg-subtle text-brand-text-muted dark:text-brand-dark-text-muted"}`,children:e.jsx(N,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-brand-text-primary dark:text-brand-dark-text-primary",children:l.label}),e.jsx("div",{className:"text-xs text-brand-text-muted dark:text-brand-dark-text-muted",children:l.description})]})]},l.key)})}),e.jsx("div",{className:"pt-4 border-t border-brand-border-subtle dark:border-brand-dark-border",children:e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-brand-text-secondary dark:text-brand-dark-text-secondary",children:"Custom Prefix (Optional)"}),e.jsx("p",{className:"text-xs text-brand-text-muted dark:text-brand-dark-text-muted mt-1 mb-2",children:'Add a prefix to all generated codes, e.g., "ORG" would create "ORG-DEPT-HR"'}),e.jsx("input",{type:"text",value:s,onChange:l=>b(l.target.value.toUpperCase()),placeholder:"e.g., ORG",maxLength:10,className:"w-full max-w-xs px-3 py-2 border border-brand-border dark:border-brand-dark-border rounded-lg bg-brand-bg-card dark:bg-brand-dark-bg-card text-brand-text-primary dark:text-brand-dark-text-primary placeholder-gray-400 dark:placeholder-gray-500 focus:ring-2 focus:ring-focus focus:border-transparent"})]})})]})}function ht({codes:t,onToggleCode:r,onSelectAll:d,onSelectAllByType:i}){const s=lt(t),c=fe(t),x=c===t.length,u={};for(const b of t)u[b.type]||(u[b.type]=[]),u[b.type].push(b);const E=["department","cost_center","program","fund","grant"];return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-brand-text-primary dark:text-brand-dark-text-primary mb-2",children:"Review Generated Codes"}),e.jsxs("p",{className:"text-sm text-brand-text-muted dark:text-brand-dark-text-muted",children:[t.length," codes generated. Select the ones you want to create."]})]}),e.jsx("button",{onClick:()=>d(!x),className:"text-sm text-amber-600 hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300 font-medium",children:x?"Deselect All":"Select All"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("span",{className:"px-3 py-1 text-sm rounded-full bg-amber-100 dar
16k:bg-amber-900/30 text-amber-700 dark:text-amber-300 font-medium",children:[c," of ",t.length," selected"]})}),e.jsx("div",{className:"space-y-6",children:E.map(b=>{const f=u[b];if(!f||f.length===0)return null;const v=P[b],l=s[b],N=l.selected===l.total;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-sm font-semibold text-brand-text-secondary dark:text-brand-dark-text-secondary flex items-center gap-2",children:[(v==null?void 0:v.label)||b,e.jsxs("span",{className:"text-xs font-normal text-brand-text-muted dark:text-brand-dark-text-muted",children:["(",l.selected,"/",l.total,")"]})]}),e.jsxs("button",{onClick:()=>i(b,!N),className:"text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:[N?"Deselect":"Select"," all"]})]}),e.jsx("div",{className:"space-y-2",children:f.map(h=>e.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ${h.is_selected?"border-amber-300 dark:border-amber-600 bg-amber-50/50 dark:bg-amber-900/20":"border-brand-border-subtle dark:border-brand-dark-border hover:bg-gray-50 dark:hover:bg-gray-800/50"}`,children:[e.jsx("input",{type:"checkbox",checked:h.is_selected,onChange:()=>r(h.code),className:"w-4 h-4 text-amber-600 border-gray-300 rounded focus:ring-focus"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"text-sm font-mono font-medium text-brand-text-primary dark:text-brand-dark-text-primary",children:h.code}),e.jsxs("span",{className:"text-sm text-brand-text-muted dark:text-brand-dark-text-muted",children:["- ",h.name]})]}),e.jsx("p",{className:"text-xs text-brand-text-muted dark:text-brand-dark-text-muted mt-0.5 line-clamp-1",children:h.description})]})]},h.code))})]},b)})})]})}function kt({result:t}){return e.jsxs("div",{className:"p-6 flex flex-col items-center justify-center min-h-[300px] text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center mb-6",children:e.jsx(Le,{className:"w-8 h-8 text-amber-600 dark:text-amber-400"})}),e.jsx("h3",{className:"text-xl font-semibold text-brand-text-primary dark:text-brand-dark-text-primary mb-2",children:"Budget Codes Created!"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-300 mb-6",children:t.summary}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-900/30 rounded-lg p-4 border border-amber-200 dark:border-amber-700",children:[e.jsx("div",{className:"text-3xl font-bold text-amber-600 dark:text-amber-400",children:t.created_count}),e.jsx("div",{className:"text-sm text-amber-700 dark:text-amber-300",children:"codes created"})]})]})}function yt({currentStep:t,steps:r}){return e.jsx("div",{className:"px-6 py-4 bg-gray-50 dark:bg-brand-dark-bg-subtle border-b border-gray-200 dark:border-brand-dark-border",children:e.jsx("div",{className:"flex items-center justify-between max-w-2xl mx-auto",children:r.map((d,i)=>{const s=i===t,c=i<t;return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center font-medium text-sm transition-colors ${c?"bg-amber-500 text-white":s?"bg-amber-500 text-white ring-4 ring-amber-100 dark:ring-amber-900/50":"bg-gray-200 dark:bg-gray-700 text-brand-text-muted dark:text-brand-dark-text-secondary"}`,children:c?e.jsx(ce,{className:"w-4 h-4"}):i+1}),e.jsx("span",{className:`text-xs mt-1.5 font-medium ${s||c?"text-amber-600 dark:text-amber-400":"text-gray-400 dark:text-brand-dark-text-muted"}`,children:d})]}),i<r.length-1&&e.jsx("div",{className:`w-12 sm:w-20 h-0.5 mx-2 ${c?"bg-amber-500":"bg-gray-200 dark:bg-gray-700"}`})]},d)})})})}function ft({isOpen:t,onClose:r,organizationId:d,onComplete:i}){const{state:s,nextStep:c,prevStep:x,canGoNext:u,canGoPrev:E,setOrganizationType:b,setIncludeDepartments:f,setIncludeCostCenters:v,setIncludePrograms:l,setIncludeFunds:N,setCustomPrefix:h,generatePreview:g,toggleCodeSelection:j,selectAllCodes:m,selectAllByType:y,createCodes:p,reset:o}=ut(),k=()=>{o(),r()},S=async()=>
16{s.currentStep===C.CONFIGURE?await g(d):s.currentStep===C.PREVIEW?await p(d):c()},w=()=>{i==null||i(),k()},L=ke.find(z=>z.value===s.config.organizationType);let D=null;switch(s.currentStep){case C.SELECT_TYPE:D=e.jsx(gt,{selectedType:s.config.organizationType,onSelect:b});break;case C.CONFIGURE:D=e.jsx(pt,{includeDepartments:s.config.includeDepartments,includeCostCenters:s.config.includeCostCenters,includePrograms:s.config.includePrograms,includeFunds:s.config.includeFunds,customPrefix:s.config.customPrefix,onSetIncludeDepartments:f,onSetIncludeCostCenters:v,onSetIncludePrograms:l,onSetIncludeFunds:N,onSetCustomPrefix:h,organizationTypeLabel:(L==null?void 0:L.label)||""});break;case C.PREVIEW:s.previewedCodes&&(D=e.jsx(ht,{codes:s.previewedCodes,onToggleCode:j,onSelectAll:m,onSelectAllByType:y}));break;case C.CREATE:s.createdResult&&(D=e.jsx(kt,{result:{created_count:s.createdResult.created_count,summary:s.createdResult.summary}}));break}const B=s.currentStep===C.CREATE,T=s.generationProgress.status==="generating",A=s.creationProgress.status==="creating";return e.jsx(Je,{isOpen:t,onClose:k,title:"Auto-Generate Budget Codes",hasUnsavedChanges:s.currentStep>C.SELECT_TYPE&&s.currentStep<C.CREATE,maxWidth:"3xl",showSidebar:!1,progressBar:e.jsx(yt,{currentStep:s.currentStep,steps:nt}),footer:e.jsxs("div",{className:"px-6 py-4 bg-gray-50 dark:bg-brand-dark-bg-subtle border-t border-gray-200 dark:border-brand-dark-border flex items-center justify-between md:rounded-b-lg",children:[e.jsx("div",{children:s.error&&e.jsxs("div",{className:"flex items-center gap-2 text-red-600 dark:text-red-400 text-sm",children:[e.jsx(Oe,{className:"w-4 h-4"}),s.error]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[!B&&E()&&e.jsxs("button",{onClick:x,disabled:T||A,className:"px-4 py-2 text-sm font-medium text-brand-text-secondary dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover rounded-lg transition-colors disabled:opacity-50",children:[e.jsx(Pe,{className:"w-4 h-4 inline mr-1"}),"Back"]}),B?e.jsx("button",{onClick:w,className:"px-4 py-2 text-sm font-medium text-white bg-amber-700 hover:bg-amber-800 rounded-lg transition-colors",children:"Done"}):e.jsx("button",{onClick:S,disabled:!u()||T||A,className:"px-4 py-2 text-sm font-medium text-white bg-amber-700 hover:bg-amber-800 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:T||A?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4 animate-spin"}),T?"Generating...":"Creating..."]}):s.currentStep===C.CONFIGURE?e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4"}),"Generate Preview"]}):s.currentStep===C.PREVIEW?e.jsxs(e.Fragment,{children:["Create ",fe(s.previewedCodes)," Codes",e.jsx(te,{className:"w-4 h-4"})]}):e.jsxs(e.Fragment,{children:["Next",e.jsx(te,{className:"w-4 h-4"})]})})]})]}),children:D})}function $t({organizationId:t}={}){const r=Me(),d=t||r.organizationId,i=Ge(),{showToast:s}=ue(),c=re(d??null,{feature:"budgets",anyRole:["OWNER","ADMIN"]}),x=c.allowed,[u,E]=n.useState([]),[b,f]=n.useState(!0),[v,l]=n.useState(!1),[N,h]=n.useState(null),[g,j]=n.useState(""),[m,y]=n.useState(null),[p,o]=n.useState(!1),[k,S]=n.useState(!1),[w,L]=n.useState(!1),[D,B]=n.useState(!1),[T,A]=n.useState(null),{isExporting:z,isModalOpen:ve,openExportModal:je,closeExportModal:Ce,handleExport:Ne}=He({entityType:"budget_codes",entityName:"Budget Codes",organizationId:d||""}),$=re(d??null,{feature:"reports",minRole:"MEMBER"}),q=[{key:"code",label:"Code",width:15},{key:"name",label:"Name",width:20},{key:"type",label:"Type",width:12,format:a=>W(a)},{key:"total_allocated",label:"Allocated",width:12,format:a=>O(a)},{key:"total_actual",label:"Actuals",width:12,format:a=>O(a)},{key:"variance",label:"Variance",width:12,format:a=>O(a)},{key:"is_active",label:"Status",width:10,format:a=>a?"Active":"Archived"},{key:"description",label:"Description",width:20}];n.useEffect(()=>{d&&(Z(),F())},[d,g]);const Z=async()=>{if(d)try{const a=M();if(!a)return;const R=await I.get(`/organizations/${d}`,{headers:{Authorization:`Bearer ${a}`}});y(R.data)}catch(a){console.error("Failed to fetch organization:",a)}},F=async()=>{var a,R;try{f(!0);const _=M();if(!_){i("/login");return}const Ee=g?{type:g}:{},Se=await I.get(`/organizations/${d}/budget-codes`,{headers:{Authorization:`Bearer ${_}`},params:Ee});E(Se.data)}catch(_){U(_)?((a=_.response)==null?void 0:a.status)===401?(localStorage.removeItem("access_token"),i("/login")):((R=_.response)==null?void 0:R.status)===403?s({message:"You do not have access to this organization",variant:"error"}):s({message:"Failed to load budget codes",variant:"error"}):s({message:"An unexpected error occurred",variant:"error"})}finally{f(!1)}},X=a=>{h(a)},J=a=>{A({code:a,action:"archive"}),L(!0)},we=async()=>{var a,R;if(T)try{const _=M();if(!_){s({message:"You must be logged in to archive a budget code",variant:"error"}),L(!1),A(null);return}await I.delete(`/budget-codes/${T.code.id}`,{headers:{Authorization:`Bearer ${_}`}}),F()}catch(_){U(_)?s({message:((R=(a=_.response)==null?void 0:a.data)==null?void 0:R.detail)||"Failed to archive budget code",variant:"error"}):s({message:"Failed to archive budget code",variant:"error"})}finally{L(!1),A(null)}},Q=a=>{A({code:a,action:"delete"}),B(!0)},_e=async()=>{var a,R;if(T)try{const _=M();if(!_){s({message:"You must be logged in to delete a budget code",variant:"error"}),B(!1),A(null);return}await I.delete(`/budget-codes/${T.code.id}`,{headers:{Authorization:`Bearer ${_}`},params:{hard_delete:!0}}),F()}catch(_){U(_)?s({message:((R=(a=_.response)==null?void 0:a.data)==null?void 0:R.detail)||"Failed to delete budget code",variant:"error"}):s({message:"Failed to delete budget code",variant:"error"})}finally{B(!1),A(null)}},K=a=>{switch(a){case"department":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"grant":return"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300";case"program":return"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300";
16case"cost_center":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300";case"fund":return"bg-pink-100 text-pink-800 dark:bg-pink-900/30 dark:text-pink-300";case"custom_1":return"bg-gray-100 text-gray-800 dark:bg-brand-dark-input/30 dark:text-brand-dark-text-secondary";case"custom_2":return"bg-gray-100 text-gray-800 dark:bg-brand-dark-input/30 dark:text-brand-dark-text-secondary";case"custom_3":return"bg-gray-100 text-gray-800 dark:bg-brand-dark-input/30 dark:text-brand-dark-text-secondary";default:return"bg-gray-100 text-gray-800 dark:bg-brand-dark-input/30 dark:text-brand-dark-text-secondary"}},W=a=>({department:"Department",grant:"Grant",program:"Program",cost_center:"Cost Center",fund:"Fund",custom_1:(m==null?void 0:m.custom_type_1_label)||"Custom 1",custom_2:(m==null?void 0:m.custom_type_2_label)||"Custom 2",custom_3:(m==null?void 0:m.custom_type_3_label)||"Custom 3"})[a]||a;return b?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-brand-primary mx-auto"}),e.jsx("p",{className:"mt-4 text-gray-600 dark:text-brand-dark-text-secondary",children:"Loading budget codes..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bg-white dark:bg-brand-dark-bg-card border-b border-gray-200 dark:border-brand-dark-border px-6 py-4",children:[e.jsx(We,{items:Ye(d??null,(m==null?void 0:m.name)??null)}),e.jsxs("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ke,{className:"w-8 h-8 text-brand-primary flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-brand-text-primary dark:text-brand-dark-text-primary",children:"Budget Codes"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-brand-dark-text-secondary mt-1 hidden sm:block",children:"Define and manage budget codes for financial tracking and allocation"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(G,{reason:c.reason,disabled:!x,children:e.jsx("button",{onClick:()=>S(!0),disabled:!x,"aria-label":"Auto-generate budget codes",className:"p-2.5 bg-amber-700 dark:bg-ai-accent hover:bg-amber-800 dark:hover:bg-ai-accent-hover text-white dark:text-brand-dark-text-inverse rounded-lg font-medium flex items-center transition disabled:opacity-40 disabled:cursor-not-allowed",title:x?"Auto-generate budget codes based on your organization type":void 0,children:e.jsx(ne,{className:"w-4 h-4"})})}),e.jsxs("button",{onClick:()=>o(!0),className:"px-4 py-2 border border-gray-300 dark:border-brand-dark-border rounded-lg hover:bg-gray-50 dark:hover:bg-brand-dark-bg-hover text-brand-text-primary dark:text-brand-dark-text-primary flex items-center gap-2",children:[e.jsx($e,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Configure Types"})]}),u.length>0&&e.jsx(G,{reason:$.reason,disabled:!$.allowed,children:e.jsx("button",{onClick:je,disabled:!$.allowed,className:"p-2 bg-gray-100 hover:bg-gray-200 dark:bg-brand-dark-bg-subtle dark:hover:bg-brand-dark-border text-gray-700 dark:text-brand-dark-text-primary rounded-lg transition-colors flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed","aria-label":"Export data",title:$.allowed?"Export data":void 0,children:e.jsx(et,{className:"w-5 h-5"})})}),e.jsx(G,{reason:c.reason,disabled:!x,children:e.jsx("button",{onClick:()=>l(!0),disabled:!x,"aria-label":"Add Budget Code",className:"p-2 bg-amber-700 dark:bg-ai-accent hover:bg-amber-800 dark:hover:bg-ai-accent-hover text-white dark:text-brand-dark-text-inverse font-medium rounded-md transition flex items-center justify-center disabled:opacity-40 disabled:cursor-not-allowed",title:x?"Add Budget Code":void 0,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})})})})]})]})]}),e.jsxs("main",{className:"flex-1 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex gap-2 mb-6 flex-wrap",children:[e.jsx("button",{onClick:()=>j(""),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g===""?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"All"}),e.jsx("button",{onClick:()=>j("department"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="department"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"Departments"}),e.jsx("button",{onClick:()=>j("grant"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="grant"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"Grants"}),e.jsx("button",{onClick:()=>j("program"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="program"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"Programs"}),e.jsx("button",{onClick:()=>j("cost_center"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="cost_center"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"Cost Centers"}),e.jsx("button",{onClick:()=>j("fund"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="fund"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:"Funds"}),e.jsx("button",{onClick:()=>j("custom_1"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="custom_1"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:(m==null?void 0:m.custom_type_1_label)||"Custom 1"}),e.jsx("button",{onClick:()=>j("custom_2"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="custom_2"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:(m==null?void 0:m.custom_type_2_label)||"Custom 2"}),e.jsx("button",{onClick:()=>j("custom_3"),className:`px-4 py-2 rounded-lg font-medium transition duration-200 ${g==="custom_3"?"bg-amber-700 dark:bg-ai-accent text-white dark:text-brand-dark-text-inverse":"bg-white dark:bg-brand-dark-bg-card text-gray-700 dark:text-brand-dark-text-secondary hover:bg-gray-100 dark:hover:bg-brand-dark-bg-hover"}`,children:(m==null?void 0:m.custom_type_3_label)||"Custom 3"})]}),e.jsx("div",{className:"bg-white dark:bg-brand-dark-bg-card rounded-lg shadow overflow-hidden",children:u.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 14l6-6m-5.5.5h.01m4.99 5h.01M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16l3.5-2 3.5 2 3.5-2 3.5 2zM10 8.5a.5.5 0 11-1 0 .5.5 0 011 0zm5 5a.5.5 0 11-1 0 .5.5 0 011 0z"})}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-brand-text-primary dark:text-brand-dark-text-primary",children:"No budget codes"}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-brand-dark-text-secondary",children:"Get started by creating a new budget code."}),e.jsx("div",{className:"mt-6",children:e.jsx(G,{reason:c.reason,disabled:!x,children:e.jsx("button",{onClick:()=>l(!0),disabled:!x,className:"bg-amber-700 dark:bg-ai-accent hover:bg-amber-800 dark:hover:bg-ai-accent-hover text-white dark:text-brand-dark-text-inverse px-6 py-2 rounded-lg font-medium transition duration-200 disabled:opacity-40 disabled:cursor-not-allowed",children:"Add Budget Code"})})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"block lg:hidden divide-y divide-brand-border-subtle dark:divide-brand-dark-border",children:u.map(a=>e.jsxs("div",{className:"p-4 bg-white dark:bg-brand-dark-bg-card",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono font-semibold text-sm text-brand-text-primary dark:text-brand-dark-text-primary",children:a.code}),e.jsx("span",{className:`px-2 py-0.5 text-xs font-semibold rounded-full ${K(a.type)}`,children:W(a.type)})]}),e.jsx("div",{className:"text-sm font-medium text-brand-text-primary dark:text-brand-dark-text-primary mt-1",children:a.name}),a.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-brand-dark-text-secondary mt-1 line-clamp-2",children:a.description})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-2",children:[a.is_active?e.jsx("span",{className:"text-green-600 dark:text-green-400 text-xs font-medium",children:"Active"}):e.jsx("span",{className:"text-gray-400 dark:text-brand-dark-text-muted text-xs font-medium",children:"Archived"}),e.jsx(G,{reason:c.reason,disabled:!x,children:e.jsx("button",{onClick:()=>X(a),disabled:!x,"aria-label":"Edit budget code",className:"p-1.5 text-amber-800 hover:text-amber-900 dark:text-brand-primary dark:hover:text-brand-primary-hover hover:bg-orange-50 dark:hover:bg-orange-900/20 rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:x?"Edit budget code":void 0,children:e.jsx(ae,{className:"w-4 h-4"})})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-brand-dark-text-secondary text-xs",children:"Allocated"}
16),e.jsx("div",{className:"font-medium text-blue-600 dark:text-blue-400",children:O(a.total_allocated)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-brand-dark-text-secondary text-xs",children:"Actuals"}),e.jsx("div",{className:`font-medium ${a.total_actual>a.total_allocated?"text-red-600 dark:text-red-400":"text-brand-text-primary dark:text-brand-dark-text-primary"}`,children:O(a.total_actual)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500 dark:text-brand-dark-text-secondary text-xs",children:"Variance"}),e.jsx("div",{className:`font-medium ${a.variance<0?"text-red-600 dark:text-red-400":"text-green-600 dark:text-green-400"}`,children:O(a.variance)})]})]}),a.is_active&&x&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-brand-border-subtle dark:border-brand-dark-border flex gap-4",children:[e.jsx("button",{onClick:()=>J(a),className:"text-sm text-amber-600 hover:text-amber-700 dark:text-amber-500 dark:hover:text-amber-400 font-medium transition",children:"Archive"}),e.jsxs("button",{onClick:()=>Q(a),className:"text-sm text-red-600 hover:text-red-700 dark:text-red-300 dark:hover:text-red-400 font-medium transition flex items-center gap-1",title:"Permanently delete (only works if unused)",children:[e.jsx(se,{className:"w-3.5 h-3.5"}),"Delete"]})]})]},a.id))}),e.jsx("div",{className:"hidden lg:block overflow-x-auto overscroll-x-contain",children:e.jsxs("table",{className:"min-w-full divide-y divide-brand-border-subtle dark:divide-brand-dark-border",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-brand-dark-bg-page",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Code"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Type"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Allocated"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Actuals"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Variance"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-brand-dark-text-secondary uppercase tracking-wider whitespace-nowrap",children:"Status"}),e.jsx("th",{className:"w-12 px-2 py-3","aria-hidden":"true"})]})}),e.jsx("tbody",{className:"divide-y divide-brand-border-subtle dark:divide-brand-dark-border",children:u.map(a=>e.jsxs("tr",{className:"group border-b border-gray-200 dark:border-brand-dark-border bg-white dark:bg-brand-dark-bg-card hover:bg-gray-50 dark:hover:bg-brand-dark-bg-hover transition-colors",children:[e.jsx("td",{className:"px-4 py-4 whitespace-nowrap text-sm text-brand-text-primary dark:text-brand-dark-text-primary",children:e.jsx("span",{className:"font-mono font-semibold",children:a.code})}),e.jsxs("td",{className:"px-4 py-4 text-sm text-brand-text-primary dark:text-brand-dark-text-primary",children:[e.jsx("div",{className:"font-medium",children:a.name}),a.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-brand-dark-text-secondary mt-0.5 line-clamp-2",children:a.description})]}),e.jsx("td",{className:"px-4 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 text-xs font-semibold rounded-full ${K(a.type)}`,children:W(a.type)})}),e.jsx("td",{className:"px-4 py-4 whitespace-nowrap text-right",children:e.jsx("div",{className:"text-sm font-medium text-blue-600 dark:text-blue-400",children:O(a.allocation??0)})}),e.jsx("td",{className:"px-4 py-4 whitespace-nowrap text-right",children:e.jsx("div",{className:`text-sm font-medium ${a.total_actual>(a.allocation??0)?"text-red-600 dark:text-red-400":"text-brand-text-primary dark:text-brand-dark-text-primary"}`,children:O(a.total_actual)})}),e.jsx("td",{className:"px-4 py-4 whitespace-nowrap text-right",children:e.jsx("div",{className:`text-sm font-medium ${a.variance<0?"text-red-600 dark:text-red-400":"text-green-600 dark:text-green-400"}`,children:O(a.variance)})}),e.jsx("td",{className:"px-4 py-4 whitespace-nowrap",children:a.is_active?e.jsx("span",{className:"text-green-600 dark:text-green-400 text-sm font-medium",children:"Active"}):e.jsx("span",{className:"text-gray-400 dark:text-brand-dark-text-muted text-sm font-medium",children:"Archived"})}),e.jsx("td",{className:"px-2 py-4 text-right",children:e.jsx(ze,{actions:[...x?[{label:"Edit",icon:e.jsx(ae,{className:"w-4 h-4"}),onClick:()=>X(a)}]:[],...a.is_active&&x?[{label:"Archive",icon:e.jsx(Ue,{className:"w-4 h-4"}),onClick:()=>J(a),variant:"danger"},{label:"Delete",icon:e.jsx(se,{className:"w-4 h-4"}),onClick:()=>Q(a),variant:"danger"}]:[]]})})]},a.id))})]})})]})})]}),v&&e.jsx(vt,{onClose:()=>l(!1),onSuccess:()=>{l(!1),F()},organizationId:d,organization:m}),N&&e.jsx(st,{code:N,onClose:()=>h(null),onSuccess:()=>{h(null),F()}}),p&&m&&e.jsx(dt,{isOpen:p,organizationId:d,onClose:()=>o(!1),onUpdate:()=>{Z(),F()},currentLabels:{custom_type_1_label:m.custom_type_1_label??void 0,custom_type_2_label:m.custom_type_2_label??void 0,custom_type_3_label:m.custom_type_3_label??void 0}}),e.jsx(qe,{isOpen:ve,onClose:Ce,columns:q,defaultSelectedColumns:["code","name","type","total_allocated","total_actual","variance"],onExport:a=>Ne(a,q,u,u),totalRecords:u.length,filteredRecords:u.length,entityName:"Budget Codes",isExporting:z}),e.jsx(ft,{isOpen:k,onClose:()=>S(!1),organizationId:d,onComplete:F}),e.jsx(de,{isOpen:w,onClose:()=>{L(!1),A(null)},onConfirm:we,title:"Archive Budget Code",message:T?`Are you sure you want to archive "${T.code.code} - ${T.code.name}"? Archived codes can be reactivated later.`:"",confirmText:"Archive",confirmVariant:"danger"}),e.jsx(de,{isOpen:D,onClose:()=>{B(!1),A(null)},onConfirm:_e,title:"Delete Budget Code",message:T?`Are you sure you want to permanently delete "${T.code.code} - ${T.code.name}"? This action cannot be undone. The code will only be deleted if it has no budget line items.`:"",confirmText:"Delete",confirmVariant:"danger"})]})}function vt({onClose:t,onSuccess:r,organizationId:d,organization:i}){const{showToast:s}=ue(),[c,x]=n.useState(""),[u,E]=n.useState(""),[b,f]=n.useState("department"),[v,l]=n.useState(""),[N,h]=n.useState(""),[g,j]=n.useState(!1),m=async y=>{y.preventDefault();const p=v?parseFloat(v):null;if(be(p)){s({message:ge("Allocation"),variant:"error"});return}j(!0);try{const o=M();if(!o){s({message:"You must be logged in",variant:"error"}),j(!1);return}await I.post(`/organizations/${d}/budget-codes`,{code:c.trim(),name:u.trim(),type:b,allocation:p,description:N.trim()||null},{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}}),r()}catch(o){U(o)?s({message:pe(o,"Failed to create budget code"),variant:"error"}):s({message:"An unexpected error occurred",variant:"error"})}finally{j(!1)}};return e.jsx(e.Fragment,{children:e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 backdrop-blur-sm flex items-center justify-center z-50 p-4",onClick:y=>y.target===y.currentTarget&&t(),children:e.jsxs("div",{className:"bg-white dark:bg-brand-dark-bg-card rounded-lg shadow-xl max-w-md w-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 dark:border-brand-dark-border",children:[e.jsx("h2",{className:"text-2xl font-bold text-brand-text-primary dark:text-brand-dark-text-primary",children:"Add Budget Code"}),e.jsx("button",{onClick:t,className:"text-gray-400 hover:text-gray-600 dark:hover:text-[#A5C9D6]",children:e.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:m,className:"p-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-brand-dark-text-secondary mb-2",children:["Code ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsx("input",{type:"text",value:c,onChange:y=>x(y.target.value),required:!0,className:"w-full px-4 py-2 bg-white dark:bg-brand-dark-input border border-gray-300 dark:border-brand-dark-border rounded-lg focus:ring-2 focus:ring-focus text-brand-text-primary dark:text-brand-dark-text-primary",placeholder:"DEPT-IT-001"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-brand-dark-text-secondary mb-2",children:["Name ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsx("input",{type:"text",value:u,onChange:y=>E(y.target.value),required:!0,className:"w-full px-4 py-2 bg-white dark:bg-brand-dark-input border border-gray-300 dark:border-brand-dark-border rounded-lg focus:ring-2 focus:ring-focus text-brand-text-primary dark:text-brand-dark-text-primary",placeholder:"IT Department"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-brand-dark-text-secondary mb-2",children:["Type ",e.jsx("span",{className:"text-red-500 dark:text-red-300",children:"*"})]}),e.jsxs("select",{value:b,onChange:y=>f(y.target.value),className:Xe,style:Ze,children:[e.jsx("option",{value:"department",children:"Department"}),e.jsx("option",{value:"grant",children:"Grant"}),e.jsx("option",{value:"program",children:"Program"}),e.jsx("option",{value:"cost_center",children:"Cost Center"}),e.jsx("option",{value:"fund",children:"Fund"}),e.jsx("option",{value:"custom_1",children:(i==null?void 0:i.custom_type_1_label)||"Custom 1"}),e.jsx("option",{value:"custom_2",children:(i==null?void 0:i.custom_type_2_label)||"Custom 2"}),e.jsx("option",{value:"custom_3",children:(i==null?void 0:i.custom_type_3_label)||"Custom 3"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-brand-dark-text-secondary mb-2",children:"Allocation"}
16),e.jsx("input",{type:"number",step:"0.01",max:xe,value:v,onChange:y=>l(y.target.value),className:"w-full px-4 py-2 bg-white dark:bg-brand-dark-input border border-gray-300 dark:border-brand-dark-border rounded-lg focus:ring-2 focus:ring-focus text-brand-text-primary dark:text-brand-dark-text-primary",placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-brand-dark-text-secondary mb-2",children:"Description"}),e.jsx("textarea",{value:N,onChange:y=>h(y.target.value),rows:3,className:"w-full px-4 py-2 bg-white dark:bg-brand-dark-input border border-gray-300 dark:border-brand-dark-border rounded-lg focus:ring-2 focus:ring-focus text-brand-text-primary dark:text-brand-dark-text-primary resize-none",placeholder:"Optional description..."})]})]}),e.jsxs("div",{className:"flex gap-3 mt-6",children:[e.jsx("button",{type:"button",onClick:t,disabled:g,className:"flex-1 px-4 py-2 bg-gray-100 hover:bg-gray-200 dark:bg-brand-dark-input dark:hover:bg-brand-dark-bg-subtle text-gray-700 dark:text-white rounded-lg font-medium transition",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:g||!c.trim()||!u.trim(),className:"flex-1 px-4 py-2 bg-amber-700 dark:bg-ai-accent hover:bg-amber-800 dark:hover:bg-ai-accent-hover text-white dark:text-brand-dark-text-inverse rounded-lg font-medium transition disabled:opacity-50",children:g?"Creating...":"Create"})]})]})]})})})}export{$t 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.