1import{j as e,r,t as se,u as ns,v as et}from"./vendor-react-zwv87yMD.js";import{T as Ze,a as Je,b as oe,c as Ie}from"./tabs-Dd8Qm6LV.js";import{u as ta,a as Me}from"./vendor-query-DYq8g7OI.js";import{u as At}from"./useOrgTimezone-C1UagyKl.js";import aa from"./BusinessDocuments-DRQUK2p-.js";import{a as fs}from"./business-documents-BU88rFEc.js";import{B as o}from"./button-DlBDuKbo.js";import{I as R}from"./input-C9cRIRX4.js";import{C as ne,d as le,a as Ot,b as Et,c as ra}from"./card-CzWdebcx.js";import{B}from"./badge-QivbhJml.js";import{D as ms,a as xs,b as us,e as ue,d as st}from"./dropdown-menu-DJoX9NOt.js";import{D as be,a as ye,b as Te,c as ve,e as Rs,d as Ue}from"./dialog-CCoQRIQ_.js";import{u as Ge,h as Pe,j as tt,o as hs}from"./authStore-Bv6p2Ne2.js";import{k as Dt,p as _t,u as na,l as la,c as js}from"./document-signing-4b_jQdUI.js";import{d as ia,c as Rt,i as Lt,e as qe,C as at,B as ss,g as Ye,f as ca,b as da,I as oa,j as Is,k as ma}from"./state-tax-MSedVyrL.js";import{U as xa}from"./UploadTemplateDialog-14DbtSD3.js";import{L as j}from"./label-CSUA9GMO.js";import{C as xe}from"./checkbox-Ka5qdjOo.js";import{r as Ls,aE as Ft,P as Pt,U as bs,F as z,b0 as ys,s as Qe,E as We,_ as Mt,l as Ds,bq as He,aZ as Ne,aq as Be,aC as Ut,c as je,w as ts,a_ as ua,n as Ae,br as Fs,bs as Ps,O as de,bt as Bt,bk as Ms,p as As,bj as Os,bc as rt,ap as nt,x as ha,bu as pa,a5 as ga,aj as Gt,a as Na,bv as fa,k as Yt,q as ja,a0 as qt,bw as ba,t as ge,v as Z,az as as,b2 as lt,X as De,d as _s,ay as ya,b9 as it,C as Ta,e as va,b as Ca,bx as Wt,T as Ve,ao as ct,m as dt,bh as wa,by as ot}from"./vendor-icons-bLSWzydc.js";import{c as ka,b as Ht}from"./vendor-router-DimZLiZb.js";import{T as rs}from"./textarea-CfTUtQow.js";import{S as Ns}from"./select-D2pLZtG9.js";import{A as mt,a as xt,b as ut,c as ht,d as pt,e as gt,f as Nt,g as ft}from"./alert-dialog-P2RRIvov.js";import{R as jt,a as Xe}from"./radio-group-BoJeumSx.js";import"./vendor-charts-CtrTLS4K.js";import"./vendor-i18n-BdYkS11p.js";import"./vendor-ui-CfDMlrKu.js";import"./vendor-pdf-DQuePnfN.js";import"./vendor-state-ByI9XJey.js";import"./vendor-editor-C_dhmuey.js";import"./utils-BXSzAfFa.js";import"./employeeAuthStore-lYSKMuhw.js";import"./api-client-wl3SCNAO.js";import"./i18n-CwjSIy0a.js";const Sa={I9_FORM:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qe,{className:"h-5 w-5 text-blue-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100",children:"Federal Requirement"}),e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:"Form I-9 is required by federal law. All employers must verify the identity and employment authorization of each person hired."})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"Section 1 - Employee Information (completed by employee)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Last Name"}),e.jsx(R,{disabled:!0,placeholder:"Employee's last name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"First Name"}),e.jsx(R,{disabled:!0,placeholder:"Employee's first name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Date of Birth"}),e.jsx(R,{disabled:!0,type:"date"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Social Security Number"}),e.jsx(R,{disabled:!0,placeholder:"XXX-XX-XXXX"})]})]}),e.jsxs("div",{className:"opacity-60",children:[e.jsx(j,{children:"Citizenship/Immigration Status"}),e.jsxs("div",{className:"space-y-2 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"A citizen of the United States"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"A noncitizen national of the United States"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"A lawful permanent resident"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"An alien authorized to work until expiration date"})]})]})]})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("a",{href:"https://www.uscis.gov/i-9",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 text-sm border rounded-md hover:bg-muted transition-colors",children:[e.jsx(We,{className:"h-4 w-4"}),"View Official I-9 Form (USCIS)"]})})]}),W4_FORM:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qe,{className:"h-5 w-5 text-blue-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100",children:"IRS Requirement"}),e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:"Form W-4 determines how much federal income tax is withheld from employee paychecks."})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"Step 1 - Personal Information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"First Name & Middle Initial"}),e.jsx(R,{disabled:!0,placeholder:"Employee name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Last Name"}),e.jsx(R,{disabled:!0,placeholder:"Last name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Social Security Number"}),e.jsx(R,{disabled:!0,placeholder:"XXX-XX-XXXX"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Filing Status"}),e.jsx(R,{disabled:!0,placeholder:"Single, Married, etc."})]})]}),e.jsx("h4",{className:"font-medium pt-4",children:"Step 2-4 - Adjustments (Optional)"}),e.jsxs("div",{className:"opacity-60 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"Multiple jobs or spouse works"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"Claim dependents"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"Other adjustments"})]})]})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("a",{href:"https://www.irs.gov/forms-pubs/about-form-w-4",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 text-sm border rounded-md hover:bg-muted transition-colors",children:[e.jsx(We,{className:"h-4 w-4"}),"View Official W-4 Form (IRS)"]})})]}),W9_FORM:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qe,{className:"h-5 w-5 text-amber-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-100",children:"For Contractors"}),e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Form W-9 is used to collect taxpayer identification for independent contractors who will receive 1099 forms."})]})]})}),e.jsxs("div",{className:"space-y-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Name (as shown on income tax return)"}),e.jsx(R,{disabled:!0,placeholder:"Individual or business name"})]}
1),e.jsxs("div",{children:[e.jsx(j,{children:"Business Name (if different)"}),e.jsx(R,{disabled:!0,placeholder:"Business or DBA name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Federal Tax Classification"}),e.jsxs("div",{className:"space-y-2 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"Individual/Sole Proprietor"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"C Corporation"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"S Corporation"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"Partnership"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"LLC"})]})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Taxpayer Identification Number (TIN)"}),e.jsx(R,{disabled:!0,placeholder:"SSN or EIN"})]})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("a",{href:"https://www.irs.gov/forms-pubs/about-form-w-9",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 text-sm border rounded-md hover:bg-muted transition-colors",children:[e.jsx(We,{className:"h-4 w-4"}),"View Official W-9 Form (IRS)"]})})]}),PERSONAL_INFORMATION:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Collects essential personal details for employment records."}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"First Name"}),e.jsx(R,{disabled:!0,placeholder:"First name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Last Name"}),e.jsx(R,{disabled:!0,placeholder:"Last name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Date of Birth"}),e.jsx(R,{disabled:!0,type:"date"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Phone Number"}),e.jsx(R,{disabled:!0,placeholder:"(555) 555-5555"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(j,{children:"Street Address"}),e.jsx(R,{disabled:!0,placeholder:"123 Main St"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"City"}),e.jsx(R,{disabled:!0,placeholder:"City"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"State"}),e.jsx(R,{disabled:!0,placeholder:"State"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"ZIP Code"}),e.jsx(R,{disabled:!0,placeholder:"12345"})]})]})]}),EMERGENCY_CONTACT:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Emergency contact information for workplace safety."}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Contact Name"}),e.jsx(R,{disabled:!0,placeholder:"Full name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Relationship"}),e.jsx(R,{disabled:!0,placeholder:"Spouse, Parent, etc."})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Phone Number"}),e.jsx(R,{disabled:!0,placeholder:"(555) 555-5555"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Alternate Phone"}),e.jsx(R,{disabled:!0,placeholder:"(555) 555-5555"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(j,{children:"Address"}),e.jsx(R,{disabled:!0,placeholder:"Contact's address"})]})]})]}),DIRECT_DEPOSIT:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-green-700 dark:text-green-300",children:"Bank account information is encrypted and stored securely."})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Bank Name"}),e.jsx(R,{disabled:!0,placeholder:"Bank name"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Account Type"}),e.jsx(R,{disabled:!0,placeholder:"Checking / Savings"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Routing Number"}),e.jsx(R,{disabled:!0,placeholder:"XXXXXXXXX"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Account Number"}),e.jsx(R,{disabled:!0,placeholder:"XXXXXXXXXXXX"})]})]})]}),BACKGROUND_CHECK:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-purple-50 dark:bg-purple-950/30 border border-purple-200 dark:border-purple-800 rounded-lg p-4",children:e.jsx("p",{className:"text-sm text-purple-700 dark:text-purple-300",children:"Authorization for employer to conduct background verification."})}),e.jsxs("div",{className:"space-y-4 opacity-60",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Full Legal Name"}),e.jsx(R,{disabled:!0,placeholder:"As it appears on official documents"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Date of Birth"}),e.jsx(R,{disabled:!0,type:"date"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"SSN (Last 4)"}),e.jsx(R,{disabled:!0,placeholder:"XXXX"})]})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"I authorize the company to obtain a consumer report and/or investigative consumer report"})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(xe,{disabled:!0}),e.jsx("span",{className:"text-sm",children:"I have read and understand the disclosure regarding background checks"})]})]})]}),STATE_TAX_FORM:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Qe,{className:"h-5 w-5 text-blue-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-blue-900 dark:text-blue-100",children:"State-Specific Requirements"}),e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:"State tax with
1holding requirements vary by state. Configure this based on where your employees work."})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium",children:"State Tax Categories"}),e.jsxs("div",{className:"border rounded-lg p-4 bg-green-50 dark:bg-green-950/20",children:[e.jsx("p",{className:"font-medium text-green-800 dark:text-green-200 mb-2",children:"No State Income Tax (9 states)"}),e.jsx("p",{className:"text-sm text-green-700 dark:text-green-300 mb-2",children:"These states don't require any state tax withholding form:"}),e.jsx("p",{className:"text-sm text-green-600 dark:text-green-400",children:"Alaska, Florida, Nevada, New Hampshire*, South Dakota, Tennessee, Texas, Washington, Wyoming"}),e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400 mt-1 italic",children:"*NH only taxes dividends and interest income"})]}),e.jsxs("div",{className:"border rounded-lg p-4 bg-amber-50 dark:bg-amber-950/20",children:[e.jsx("p",{className:"font-medium text-amber-800 dark:text-amber-200 mb-2",children:"Uses Federal W-4 (3 states)"}),e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300 mb-2",children:"These states accept the federal W-4 for state withholding:"}),e.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-400",children:"New Mexico, North Dakota, Utah"})]}),e.jsxs("div",{className:"border rounded-lg p-4 bg-purple-50 dark:bg-purple-950/20",children:[e.jsx("p",{className:"font-medium text-purple-800 dark:text-purple-200 mb-2",children:"State-Specific Forms Required"}),e.jsx("p",{className:"text-sm text-purple-700 dark:text-purple-300",children:"Most other states require their own withholding certificate. Examples:"}),e.jsxs("ul",{className:"text-sm text-purple-600 dark:text-purple-400 mt-2 space-y-1",children:[e.jsx("li",{children:"⢠California: DE 4"}),e.jsx("li",{children:"⢠New York: IT-2104"}),e.jsx("li",{children:"⢠Illinois: IL-W-4"}),e.jsx("li",{children:"⢠And more..."})]})]})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Click ",e.jsx("strong",{children:"Configure"})," to set up state tax forms for your organization's operating states."]})})]})},Ia={I9_FORM:ys,W4_FORM:z,W9_FORM:z,PERSONAL_INFORMATION:bs,EMERGENCY_CONTACT:Pt,DIRECT_DEPOSIT:Ft,BACKGROUND_CHECK:Ls};function Aa({form:s,open:t,onOpenChange:w}){if(!s)return null;const T=Ia[s.id]||z,L=Sa[s.id];return e.jsx(be,{open:t,onOpenChange:w,children:e.jsxs(ye,{className:"max-w-2xl max-h-[85vh] overflow-y-auto",children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",children:e.jsx(T,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs(ve,{className:"flex items-center gap-2",children:[s.name,s.isLegalRequired&&e.jsx(B,{variant:"outline",className:"text-xs text-red-600 border-red-300",children:"Legally Required"})]}),e.jsx(Rs,{children:s.description})]})]})}),e.jsx("div",{className:"mt-4",children:L||e.jsx(ne,{children:e.jsxs(le,{className:"py-8 text-center text-muted-foreground",children:[e.jsx(z,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Preview not available for this form type."}),e.jsx("p",{className:"text-sm mt-2",children:"This form will be presented to employees during onboarding."})]})})}),e.jsxs("div",{className:"flex items-center justify-between mt-6 pt-4 border-t",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:s.isConfigurable&&e.jsx("span",{className:"text-amber-600",children:"This form has configurable options."})}),e.jsx(o,{variant:"outline",onClick:()=>w(!1),children:"Close"})]})]})})}const Us=[{code:"AL",name:"Alabama",taxType:"state",formName:"A-4"},{code:"AK",name:"Alaska",taxType:"none"},{code:"AZ",name:"Arizona",taxType:"state",formName:"A-4"},{code:"AR",name:"Arkansas",taxType:"state",formName:"AR4EC"},{code:"CA",name:"California",taxType:"state",formName:"DE 4"},{code:"CO",name:"Colorado",taxType:"state",formName:"DR 0004"},{code:"CT",name:"Connecticut",taxType:"state",formName:"CT-W4"},{code:"DE",name:"Delaware",taxType:"state",formName:"W-4"},{code:"FL",name:"Florida",taxType:"none"},{code:"GA",name:"Georgia",taxType:"state",formName:"G-4"},{code:"HI",name:"Hawaii",taxType:"state",formName:"HW-4"},{code:"ID",name:"Idaho",taxType:"state",formName:"ID W-4"},{code:"IL",name:"Illinois",taxType:"state",formName:"IL-W-4"},{code:"IN",name:"Indiana",taxType:"state",formName:"WH-4"},{code:"IA",name:"Iowa",taxType:"state",formName:"IA W-4"},{code:"KS",name:"Kansas",taxType:"state",formName:"K-4"},{code:"KY",name:"Kentucky",taxType:"state",formName:"K-4"},{code:"LA",name:"Louisiana",taxType:"state",formName:"L-4"},{code:"ME",name:"Maine",taxType:"state",formName:"W-4ME"},{code:"MD",name:"Maryland",taxType:"state",formName:"MW507"},{code:"MA",name:"Massachusetts",taxType:"state",formName:"M-4"},{code:"MI",name:"Michigan",taxType:"state",formName:"MI-W4"},{code:"MN",name:"Minnesota",taxType:"state",formName:"W-4MN"},{code:"MS",name:"Mississippi",taxType:"state",formName:"89-350"},{code:"MO",name:"Missouri",taxType:"state",formName:"MO W-4"},{code:"MT",name:"Montana",taxType:"state",formName:"MW-4"},{code:"NE",name:"Nebraska",taxType:"state",formName:"W-4N"},{code:"NV",name:"Nevada",taxType:"none"},{code:"NH",name:"New Hampshire",taxType:"none"},{code:"NJ",name:"New Jersey",taxType:"state",formName:"NJ-W4"},{code:"NM",name:"New Mexico",taxType:"federal"},{code:"NY",name:"New York",taxType:"state",formName:"IT-2104"},{code:"NC",name:"North Carolina",taxType:"state",formName:"NC-4"},{code:"ND",name:"North Dakota",taxType:"federal"},{code:"OH",name:"Ohio",taxType:"state",formName:"IT 4"},{code:"OK",name:"Oklahoma",taxType:"state",formName:"OK-W-4"},{code:"OR",name:"Oregon",taxType:"state",formName:"OR-W-4"},{code:"PA",name:"Pennsylvania",taxType:"state",formName:"REV-419"},{code:"RI",name:"Rhode Island",taxType:"state",formName:"RI W-4"},{code:"SC",name:"South Carolina",taxType:"state",formName:"SC W-4"},{code:"SD",name:"South Dakota",taxType:"none"},{code:"TN",name:"Tennessee",taxType:"none"},{code:"TX",name:"Texas",taxType:"none"},{code:"UT",name:"Utah",taxType:"federal"},{code:"VT",name:"Vermont",taxType:"state",formName:"W-4VT"},{code:"VA",name:"Virginia",taxType:"state",formName:"VA-4"},{code:"WA",name:"Washington",taxType:"none"},{code:"WV",name:"West Virginia",taxType:"state",formName:"WV/IT-104"},{code:"WI",name:"Wisconsin",taxType:"state",formName:"WT-4"},{code:"WY",name:"Wyoming",taxType:"none"}],ps=Us.filter(s=>s.taxType==="state"),bt=Us.filter(s=>s.taxType==="federal"),yt=Us.filter(s=>s.taxType==="none");function Tt(s){return`stateTaxForms_${s}`}function Oa({form:s,open:t,onOpenChange:w}){const{currentOrganizationId:T}=Ge(),[L,k]=r.useState([]),[S,q]=r.useState(!1);r.useEffect(()=>{if(t&&T){const d=localStorage.getItem(Tt(T));if(d)try{k(JSON.parse(d))}catch{k([])}}},[t,T]);const E=d=>{k(F=>F.includes(d)?F.filter(v=>v!==d):[...F,d])},M=()=>{k(ps.map(d=>d.code))},W=()=>{k([])},D=()=>
1{if(T){q(!0);try{localStorage.setItem(Tt(T),JSON.stringify(L)),se.success("State tax form settings saved"),w(!1)}catch{se.error("Failed to save settings")}finally{q(!1)}}};return!s||s.id!=="STATE_TAX_FORM"?null:e.jsx(be,{open:t,onOpenChange:w,children:e.jsxs(ye,{className:"max-w-3xl max-h-[85vh] overflow-y-auto",children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",children:e.jsx(Mt,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx(ve,{children:"Configure State Tax Forms"}),e.jsx(Rs,{children:"Select which state tax withholding forms employees should complete based on where they work."})]})]})}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ds,{className:"h-5 w-5 text-blue-600 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:"Remote Workers & Multi-State Employers"}),e.jsx("p",{className:"mt-1",children:"Enable forms for all states where you have employees. Employees will be asked to complete the appropriate form based on their work location."})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{variant:"outline",size:"sm",onClick:M,children:"Select All States"}),e.jsx(o,{variant:"outline",size:"sm",onClick:W,children:"Clear All"}),e.jsxs("span",{className:"text-sm text-muted-foreground ml-2",children:[L.length," of ",ps.length," states selected"]})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium mb-3",children:["States with State-Specific Forms (",ps.length,")"]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:ps.map(d=>e.jsxs("div",{className:`flex items-center gap-2 p-2 rounded border cursor-pointer transition-colors ${L.includes(d.code)?"bg-emerald-50 border-emerald-300 dark:bg-emerald-950/30 dark:border-emerald-700":"hover:bg-muted"}`,onClick:()=>E(d.code),children:[e.jsx(xe,{checked:L.includes(d.code),onClick:F=>F.stopPropagation(),onCheckedChange:()=>E(d.code)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(j,{className:"text-sm font-medium cursor-pointer",children:d.name}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:["Form ",d.formName]})]})]},d.code))})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium mb-2 text-muted-foreground",children:["States Using Federal W-4 (",bt.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:bt.map(d=>e.jsx(B,{variant:"secondary",className:"text-xs",children:d.name},d.code))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"These states use the Federal W-4 for state withholding. No separate state form is required."})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium mb-2 text-muted-foreground",children:["States Without Income Tax (",yt.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:yt.map(d=>e.jsx(B,{variant:"secondary",className:"text-xs",children:d.name},d.code))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"These states do not have state income tax. No state withholding form is required."})]})]}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),e.jsx(o,{onClick:D,disabled:S,children:S?"Saving...":"Save Configuration"})]})]})})}function Ea(s){return{id:`st-${s.id}`,name:s.name,description:s.description,status:s.isPublished?"published":"draft",updatedAt:s.updatedAt,createdAt:s.createdAt,signableTemplate:s}}const Da={FileCheck:ys,FileText:z,MapPin:Mt,User:bs,Phone:Pt,DollarSign:Ft,Heart:Gt,UserCheck:ga,TestTube:pa,CreditCard:ha,Building:Ms,Book:Bt,Upload:de,Shield:Ls,GraduationCap:Ps,Laptop:Fs,Plus:Ae};function _a(s){return`stateTaxForms_${s}`}function Ra(s,t){if(!t)return!1;if(s==="STATE_TAX_FORM"){const w=localStorage.getItem(_a(t));if(!w)return!0;try{const T=JSON.parse(w);return!Array.isArray(T)||T.length===0}catch{return!0}}return!1}const La={GOVERNMENT_FORM:Ms,COMPANY_POLICY:Bt,INFORMATION:bs,DOCUMENT_UPLOAD:de,COMPLIANCE:Ls,TRAINING:Ps,EQUIPMENT:Fs,CUSTOM:Ae};function Fa(s){return Da[s]||z}function Pa({initialCategory:s}={}){const{t}=ns("documentLibrary"),w=ka(),T=ta(),{permissions:L,currentOrganizationId:k}=Ge(),S=At(),q=L.includes("MANAGE_ONBOARDING_TEMPLATES"),E=L.includes("VIEW_BUSINESS_DOCUMENTS"),[M,W]=r.useState(s??"system-forms"),[D,d]=r.useState("all"),[F,v]=r.useState(""),[I,X]=r.useState("updated"),[x,u]=r.useState(!1),[G,C]=r.useState(!1),[b,U]=r.useState(null),[H,g]=r.useState(!1),[p,A]=r.useState(null),[y,Y]=r.useState(!1),[te,ie]=r.useState(null),[ae,J]=r.useState(!1),{data:V=[],isLoading:i}=Me({queryKey:["document-templates",k],queryFn:()=>js(),staleTime:300*1e3,gcTime:1200*1e3,enabled:!!k}),{data:h,isLoading:N}=Me({queryKey:["system-forms-grouped"],queryFn:()=>ia(),staleTime:1800*1e3,gcTime:3600*1e3}),P=i||M==="system-forms"&&N,he=r.useMemo(()=>{let m=V.map(Ea);if(D!=="all"&&(m=m.filter(Q=>Q.status===D)),F){const Q=F.toLowerCase();m=m.filter(K=>{var $;return K.name.toLowerCase().includes(Q)||(($=K.description)==null?void 0:$.toLowerCase().includes(Q))})}return m.sort((Q,K)=>{switch(I){case"name":return Q.name.localeCompare(K.name);case"created":return new Date(K.createdAt).getTime()-new Date(Q.createdAt).getTime();case"updated":default:return new Date(K.updatedAt).getTime()-new Date(Q.updatedAt).getTime()}}),m},[V,D,F,I]),{data:ee=[]}=Me({queryKey:["business-documents",k],queryFn:()=>fs(),staleTime:300*1e3,enabled:E&&!!k}),re=(h==null?void 0:h.groups.reduce((m,Q)=>m+Q.forms.length,0))||0,me=r.useMemo(()=>{const m=V.length,Q=V.filter($=>!$.isPublished).length,K=V.filter($=>$.isPublished).length;return{eSignature:m,draft:Q,published:K,systemForms:re,companyDocuments:ee.length}},[V,re,ee.length]),Oe=async(m,Q)=>
1{try{await Dt(m,Q),T.invalidateQueries({queryKey:["document-templates"]}),se.success(t("toast.templateUploaded"))}catch{throw se.error(t("toast.uploadFailed")),new Error("Upload failed")}},Ce=m=>{w(`/dashboard/document-signing-templates?edit=${m.signableTemplate.id}`)},Ee=async m=>{try{await _t(m.signableTemplate.id),T.invalidateQueries({queryKey:["document-templates"]}),se.success(t("toast.templatePublished"))}catch{se.error(t("toast.publishFailed"))}},_e=async m=>{try{await na(m.signableTemplate.id),T.invalidateQueries({queryKey:["document-templates"]}),se.success(t("toast.templateUnpublished"))}catch{se.error(t("toast.unpublishFailed"))}},Re=m=>{U(m),C(!0)},we=async()=>{if(b){g(!0);try{await la(b.signableTemplate.id),T.invalidateQueries({queryKey:["document-templates"]}),se.success(t("toast.documentDeleted")),C(!1),U(null)}catch{se.error(t("toast.deleteFailed"))}finally{g(!1)}}},pe=[{name:t("samples.offerLetter.name"),description:t("samples.offerLetter.description")},{name:t("samples.nda.name"),description:t("samples.nda.description")},{name:t("samples.directDeposit.name"),description:t("samples.directDeposit.description")},{name:t("samples.equipment.name"),description:t("samples.equipment.description")},{name:t("samples.nonCompete.name"),description:t("samples.nonCompete.description")},{name:t("samples.emergencyContact.name"),description:t("samples.emergencyContact.description")}],Le=()=>M==="e-signature"?e.jsx("div",{className:"bg-violet-50 dark:bg-violet-950/30 border border-violet-200 dark:border-violet-800 rounded-lg p-4 mb-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ne,{className:"h-5 w-5 text-violet-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-violet-800 dark:text-violet-200",children:t("banner.eSignature.title")}),e.jsx("p",{className:"text-violet-700 dark:text-violet-300 mt-1",children:t("banner.eSignature.body")}),e.jsx("p",{className:"text-violet-600 dark:text-violet-400 mt-2 text-xs",children:e.jsx(et,{i18nKey:"banner.eSignature.examples",components:{b:e.jsx("strong",{})}})})]})]})}):M==="system-forms"?e.jsx("div",{className:"bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-200 dark:border-emerald-800 rounded-lg p-4 mb-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(He,{className:"h-5 w-5 text-emerald-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-emerald-800 dark:text-emerald-200",children:t("banner.systemForms.title")}),e.jsx("p",{className:"text-emerald-700 dark:text-emerald-300 mt-1",children:t("banner.systemForms.body")}),e.jsx("p",{className:"text-emerald-600 dark:text-emerald-400 mt-2 text-xs",children:e.jsx(et,{i18nKey:"banner.systemForms.includes",components:{b:e.jsx("strong",{})}})})]})]})}):null,Fe=()=>M==="e-signature"&&q?e.jsxs(o,{onClick:()=>u(!0),className:"min-h-[44px] w-full sm:w-auto",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:t("buttons.uploadPdf")}),e.jsx("span",{className:"sm:hidden",children:t("buttons.upload")})]}):null,ke=e.jsx("div",{className:"mb-4 -mx-4 px-4 sm:mx-0 sm:px-0 overflow-x-auto",children:e.jsx(Ze,{value:M,onValueChange:m=>W(m),children:e.jsxs(Je,{className:"w-max sm:w-auto",children:[e.jsxs(oe,{value:"system-forms",className:"min-h-[44px] gap-1 sm:gap-2 px-2 sm:px-3",children:[e.jsx(He,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:t("tabs.systemForms")}),e.jsx("span",{className:"sm:hidden",children:t("tabs.systemFormsShort")}),e.jsx("span",{className:"text-xs bg-emerald-500/20 text-emerald-600 dark:text-emerald-400 px-1.5 py-0.5 rounded",children:me.systemForms})]}),e.jsxs(oe,{value:"e-signature",className:"min-h-[44px] gap-1 sm:gap-2 px-2 sm:px-3",children:[e.jsx(Ne,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:t("tabs.eSignature")}),e.jsx("span",{className:"sm:hidden",children:t("tabs.eSignatureShort")}),e.jsx("span",{className:"text-xs bg-violet-500/20 text-violet-600 dar
1k:text-violet-400 px-1.5 py-0.5 rounded",children:me.eSignature})]}),E&&e.jsxs(oe,{value:"company-documents",className:"min-h-[44px] gap-1 sm:gap-2 px-2 sm:px-3",children:[e.jsx(z,{className:"h-4 w-4 sm:h-3.5 sm:w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:t("tabs.companyDocuments")}),e.jsx("span",{className:"sm:hidden",children:t("tabs.companyDocumentsShort")}),e.jsx("span",{className:"text-xs bg-blue-500/20 text-blue-600 dark:text-blue-400 px-1.5 py-0.5 rounded",children:me.companyDocuments})]})]})})});return M==="company-documents"?e.jsxs("div",{className:"flex-1 flex flex-col",children:[ke,e.jsx(aa,{embedded:!0})]}):e.jsxs("div",{className:"flex-1 flex flex-col",children:[ke,Le(),e.jsxs("div",{className:"mb-4 sm:mb-6 space-y-3 sm:space-y-0 sm:flex sm:items-center sm:gap-4",children:[e.jsxs("div",{className:"relative flex-1 sm:max-w-md",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:t("filters.searchPlaceholder"),value:F,onChange:m=>v(m.target.value),className:"pl-10 min-h-[44px]"})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4",children:[e.jsxs(ms,{children:[e.jsx(xs,{asChild:!0,children:e.jsxs(o,{variant:"outline",size:"sm",className:"min-h-[44px] gap-1 sm:gap-2 flex-1 sm:flex-none",children:[e.jsx(Ut,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:t("filters.statusLabel")})," ",t(D==="all"?"filters.all":`status.${D}`)]})}),e.jsxs(us,{align:"end",children:[e.jsxs(ue,{onClick:()=>d("all"),className:"min-h-[44px]",children:[t("filters.all"),D==="all"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]}),e.jsxs(ue,{onClick:()=>d("draft"),className:"min-h-[44px]",children:[e.jsx(ts,{className:"h-4 w-4 mr-2 text-amber-500"}),t("filters.draftCount",{count:me.draft}),D==="draft"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]}),e.jsxs(ue,{onClick:()=>d("published"),className:"min-h-[44px]",children:[e.jsx(je,{className:"h-4 w-4 mr-2 text-green-500"}),t("filters.publishedCount",{count:me.published}),D==="published"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]})]})]}),e.jsxs(ms,{children:[e.jsx(xs,{asChild:!0,children:e.jsxs(o,{variant:"outline",size:"sm",className:"min-h-[44px] gap-1 sm:gap-2 flex-1 sm:flex-none",children:[e.jsx(ua,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:t("sort.label")})," ",e.jsx("span",{className:"hidden sm:inline",children:t(I==="updated"?"sort.updated":I==="created"?"sort.created":"sort.name")}),e.jsx("span",{className:"sm:hidden",children:t(I==="updated"?"sort.updatedShort":I==="created"?"sort.createdShort":"sort.nameShort")})]})}),e.jsxs(us,{align:"end",children:[e.jsxs(ue,{onClick:()=>X("updated"),className:"min-h-[44px]",children:[t("sort.updated"),I==="updated"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]}),e.jsxs(ue,{onClick:()=>X("created"),className:"min-h-[44px]",children:[t("sort.created"),I==="created"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]}),e.jsxs(ue,{onClick:()=>X("name"),className:"min-h-[44px]",children:[t("sort.nameAZ"),I==="name"&&e.jsx(je,{className:"ml-auto h-4 w-4"})]})]})]}),e.jsx("div",{className:"hidden sm:block flex-1"}),e.jsx("div",{className:"hidden sm:block",children:Fe()})]}),e.jsx("div",{className:"sm:hidden",children:Fe()})]}),e.jsx("div",{className:"flex-1",children:P?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:t("states.loading")}):M==="system-forms"?e.jsxs("div",{className:"space-y-6",children:[h==null?void 0:h.groups.map(m=>{const Q=La[m.category]||z;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Q,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h3",{className:"font-semibold",children:m.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",m.forms.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:m.forms.map(K=>{const $=Fa(K.icon);return e.jsx(ne,{className:"hover:shadow-md transition-shadow",children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400",children:e.jsx($,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium truncate",children:K.name}),K.isLegalRequired&&e.jsx(B,{variant:"outline",className:"text-xs text-red-600 border-red-300 shrink-0",children:t("badges.required")})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2 mt-1",children:K.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[K.hasPreview&&e.jsxs(o,{variant:"outline",size:"sm",className:"min-h-[36px] sm:h-7 text-xs",onClick:()=>{A(K),Y(!0)},children:[e.jsx(As,{className:"h-3 w-3 mr-1"}),t("buttons.preview")]}),K.isConfigurable&&e.jsxs(o,{variant:"outline",size:"sm",className:`min-h-[36px] sm:h-7 text-xs ${Ra(K.id,k)?"border-amber-400 bg-amber-50 text-amber-700 hover:bg-amber-100 hover:text-amber-800 dark:border-amber-600 dar
1k:bg-amber-950/30 dark:text-amber-400 dark:hover:bg-amber-900/50":""}`,onClick:()=>{ie(K),J(!0)},children:[e.jsx(Os,{className:"h-3 w-3 mr-1"}),t("buttons.configure")]})]})]})]})})},K.id)})})]},m.category)}),(!(h!=null&&h.groups)||h.groups.length===0)&&e.jsx(ne,{className:"border-dashed border-2",children:e.jsxs(le,{className:"py-12 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 mb-4",children:e.jsx(He,{className:"h-8 w-8 text-primary"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:t("emptyStates.noSystemForms.title")}),e.jsx("p",{className:"text-muted-foreground",children:t("emptyStates.noSystemForms.body")})]})})]}):he.length===0?e.jsxs("div",{className:"space-y-6",children:[e.jsx(ne,{className:"border-dashed border-2",children:e.jsxs(le,{className:"py-12 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 mb-4",children:e.jsx(Ne,{className:"h-8 w-8 text-primary"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:t(F||D!=="all"?"emptyStates.noDocuments.titleFiltered":"emptyStates.noDocuments.titleDefault")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:t(F||D!=="all"?"emptyStates.noDocuments.bodyFiltered":"emptyStates.noDocuments.bodyDefault")}),!F&&D==="all"&&q&&e.jsxs(o,{onClick:()=>u(!0),className:"min-h-[44px]",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),t("buttons.uploadPdf")]})]})}),!F&&D==="all"&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:t("emptyStates.commonDocuments")}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:pe.map(m=>e.jsx(ne,{className:"hover:bg-muted/50 transition-colors",children:e.jsx(le,{className:"p-3 sm:p-3 min-h-[60px] flex items-center",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-1.5 rounded bg-violet-100 text-violet-600 dark:bg-violet-900/30 dark:text-violet-400 shrink-0",children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm",children:m.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:m.description})]})]})})},m.name))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:t("emptyStates.prepareHint")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sm:hidden space-y-3",children:he.map(m=>e.jsx(ne,{className:"overflow-hidden",children:e.jsx(le,{className:"p-0",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("button",{onClick:()=>Ce(m),className:"text-primary font-medium text-left hover:underline min-h-[44px] flex items-center",children:m.name}),m.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:m.description})]}),e.jsxs(ms,{children:[e.jsx(xs,{asChild:!0,children:e.jsx(o,{variant:"ghost",size:"icon",className:"min-h-[44px] min-w-[44px] shrink-0",children:e.jsx(rt,{className:"h-5 w-5"})})}),e.jsxs(us,{align:"end",children:[e.jsx(ue,{onClick:()=>Ce(m),className:"min-h-[44px]",children:m.status==="draft"?e.jsxs(e.Fragment,{children:[e.jsx(Os,{className:"h-4 w-4 mr-2"}),t("menu.edit")]}):e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"h-4 w-4 mr-2"}),t("menu.view")]})}),q&&e.jsxs(e.Fragment,{children:[m.status==="draft"&&e.jsxs(ue,{onClick:()=>Ee(m),className:"min-h-[44px]",children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),t("menu.publish")]}),m.status==="published"&&e.jsxs(ue,{onClick:()=>_e(m),className:"min-h-[44px]",children:[e.jsx(ts,{className:"h-4 w-4 mr-2"}),t("menu.unpublish")]}),e.jsx(st,{}),e.jsxs(ue,{onClick:()=>Re(m),className:"text-destructive min-h-[44px]",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),t("menu.delete")]})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m.status==="draft"&&e.jsxs(B,{variant:"outline",className:"gap-1 text-xs text-amber-600 border-amber-300",children:[e.jsx(ts,{className:"h-3 w-3"}),t("status.draft")]}),m.status==="published"&&e.jsxs(B,{variant:"outline",className:"gap-1 text-xs text-green-600 border-green-300",children:[e.jsx(je,{className:"h-3 w-3"}),t("status.published")]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(m.updatedAt).toLocaleDateString(void 0,{timeZone:S})})]})]})})},m.id))}),e.jsx("div",{className:"hidden sm:block bg-card rounded-lg shadow border",children:e.jsxs("table",{className:"min-w-full divide-y divide-border",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-muted-foreground uppercase tracking-wider rounded-tl-lg",children:t("table.document")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-muted-foreground uppercase tracking-wider",children:t("table.status")}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-muted-foreground uppercase tracking-wider",children:t("table.lastUpdated")}),e.jsx("th",{className:"px-6 py-3 text-right text-xs font-medium text-muted-foreground uppercase tracking-wider rounded-tr-lg",children:t("table.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:he.map(m=>e.jsxs("tr",{className:"hover:bg-muted/30",children:[e.jsxs("td",{className:"px-6 py-4",children:[e.jsx("button",{onClick:()=>Ce(m),className:"text-primary hover:underline font-medium text-left",children:m.name}),m.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate max-w-xs",children:m.description})]}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap",children:[m.status==="draft"&&e.jsxs(B,{variant:"outline",className:"gap-1 text-amber-600 border-amber-300",children:[e.jsx(ts,{className:"h-3 w-3"}),t("status.draft")]}),m.status==="published"&&e.jsxs(B,{variant:"outline",className:"gap-1 text-green-600 border-green-300",children:[e.jsx(je,{className:"h-3 w-3"}),t("status.published")]})]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-muted-foreground",children:new Date(m.updatedAt).toLocaleDateString(void 0,{timeZone:S})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-right",children:e.jsxs(ms,{children:[e.jsx(xs,{asChild:!0,children:e.jsx(o,{variant:"ghost",size:"icon",children:e.jsx(rt,{className:"h-4 w-4"})})}),e.jsxs(us,{align:"end",children:[e.jsx(ue,{onClick:()=>Ce(m),children:m.status==="draft"?e.jsxs(e.Fragment,{children:[e.jsx(Os,{className:"h-4 w-4 mr-2"}),t("menu.edit")]}):e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"h-4 w-4 mr-2"}),t("menu.view")]})}),q&&e.jsxs(e.Fragment,{children:[m.status==="draft"&&e.jsxs(ue,{onClick:()=>Ee(m),children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),t("menu.publish")]}),m.status==="published"&&e.jsxs(ue,{onClick:()=>_e(m),children:[e.jsx(ts,{className:"h-4 w-4 mr-2"}),t("menu.unpublish")]}),e.jsx(st,{}),e.jsxs(ue,{onClick:()=>Re(m),className:"text-destructive",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),t("menu.delete")]})]})]})]})})]},m.id))})]})})]})}),e.jsx(xa,{open:x,onOpenChange:u,onUpload:Oe}),e.jsx(be,{open:G,onOpenChange:C,children:e.jsxs(ye,{children:[e.jsxs(Te,{children:[e.jsx(ve,{children:t("deleteDialog.title")}),e.jsx(Rs,{children:t("deleteDialog.body",{name:b==null?void 0:b.name})})]}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:()=>C(!1),className:"min-h-[44px]",children:t("buttons.cancel")}),e.jsx(o,{variant:"destructive",onClick:we,disabled:H,className:"min-h-[44px]",children:t(H?"buttons.deleting":"buttons.delete")})]})]})}),e.jsx(Aa,{form:p,open:y,onOpenChange:Y}),e.jsx(Oa,{form:te,open:ae,onOpenChange:J})]})}const Ma={FULL_TIME:ba,PART_TIME:bs,CONTRACTOR:z,EXECUTIVE:qt,REMOTE:Fs,ONBOARDING:He,POLICY:ja,TRAINING:Ps,COMPLIANCE:Yt,BENEFITS:Gt,OFFBOARDING:fa,CUSTOM:Na},Ua={FULL_TIME:"bg-blue-500",PART_TIME:"bg-green-500",CONTRACTOR:"bg-purple-500",EXECUTIVE:"bg-orange-500",REMOTE:"bg-cyan-500",ONBOARDING:"bg-blue-500",POLICY:"bg-amber-500",TRAINING:"bg-green-500",COMPLIANCE:"bg-red-500",BENEFITS:"bg-pink-500",OFFBOARDING:"bg-slate-500",CUSTOM:"bg-violet-500"};function Kt({template:s,onClick:t}){var E,M;const{t:w}=ns("onboarding"),T=s.category?Ma[s.category]||z:z,L=s.category&&Ua[s.category]||"bg-gray-500",k=((E=s.tasks)==null?void 0:E.length)||0,S=((M=s._count)==null?void 0:M.workflows)||s.usageCount||0,q=s.isSystemTemplate?null:Rt(s.tasks);return e.jsxs(ne,{className:"cursor-pointer hover:shadow-lg transition-shadow duration-200 border-2 hover:border-primary",onClick:t,children:[e.jsxs(Ot,{children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("div",{className:`p-2 rounded-lg ${L} bg-opacity-10`,children:e.jsx(T,{className:`h-6 w-6 ${L.replace("bg-","text-")}`})}),s.isSystemTemplate&&e.jsx(B,{variant:"secondary",children:"System"}),s.isDefault&&e.jsx(B,{variant:"default",children:"Default"})]}),e.jsx(Et,{className:"line-clamp-2",children:s.name}),s.description&&e.jsx(ra,{className:"line-clamp-2 mt-2",children:s.description})]}),e.jsxs(le,{children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsxs("span",{children:[k," tasks"]})]}),S>0&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(qt,{className:"h-4 w-4"}),e.jsxs("span",{children:["Used ",S,"x"]})]})]}),(s.category||q)&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[s.category&&e.jsx(B,{variant:"outline",className:"text-xs",children:s.category.replace(/_/g," ")}),q==="w2-specified-documents"&&e.jsx(B,{variant:"outline",className:"text-xs text-amber-800 border-amber-400 bg-amber-50 dark:text-amber-200 dark:bg-amber-950/40",children:w("templates.badgeSpecifiedI9")}),q==="contractor-government-id"&&e.jsx(B,{variant:"outline",className:"text-xs text-amber-800 border-amber-400 bg-amber-50 dark:text-amber-200 dark:bg-amber-950/40",children:w("templates.badgeGovernmentId")})]})]})]})}function vt({templates:s,isLoading:t,onTemplateClick:w,emptyMessage:T="No templates available"}){return t?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):s.length===0?e.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:T}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 my-4",children:s.map(L=>e.jsx(Kt,{template:L,onClick:()=>w(L)},L.id))})}const Ba=[{value:"ONBOARDING",label:"Employment Forms"},{value:"POLICY",label:"Policy Acknowledgment"},{value:"TRAINING",label:"Training & Certification"},{value:"COMPLIANCE",label:"Compliance Documents"}
1,{value:"BENEFITS",label:"Benefits Enrollment"},{value:"OFFBOARDING",label:"Offboarding / Separation"},{value:"CUSTOM",label:"Custom Assignment"}];function Ga({open:s,onOpenChange:t,onTemplateCreated:w}){const{systemTemplates:T,loadSystemTemplates:L,createTemplate:k,copyTemplate:S}=Pe(),[q,E]=r.useState("copy"),[M,W]=r.useState(!1),[D,d]=r.useState(""),[F,v]=r.useState(""),[I,X]=r.useState(""),[x,u]=r.useState(""),[G,C]=r.useState("");r.useEffect(()=>{s&&T.length===0&&L()},[s]);const b=()=>{d(""),v(""),X(""),u(""),C(""),E("copy"),t(!1)},U=async()=>{if(D.trim()){W(!0);try{const p=await k({name:D.trim(),description:F.trim()||void 0,category:I||void 0,tasks:[]});b(),w&&p&&w(p)}catch(p){console.error("Failed to create template:",p)}finally{W(!1)}}},H=async()=>{if(!(!x||!G.trim())){W(!0);try{const p=await S(x,G.trim());b(),w&&p&&w(p)}catch(p){console.error("Failed to copy template:",p)}finally{W(!1)}}},g=T.find(p=>p.id===x);return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Te,{children:e.jsx(ve,{children:"Create New Package"})}),e.jsxs(Ze,{value:q,onValueChange:p=>E(p),children:[e.jsxs(Je,{className:"grid w-full grid-cols-2",children:[e.jsxs(oe,{value:"copy",children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Copy from System Package"]}),e.jsxs(oe,{value:"scratch",children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Start from Scratch"]})]}),e.jsxs(Ie,{value:"copy",className:"space-y-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Select a package to copy"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Choose a pre-built package as your starting point. You can customize it after creation."}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 max-h-64 overflow-y-auto p-1",children:T.map(p=>e.jsx("div",{className:`cursor-pointer ${x===p.id?"ring-2 ring-primary":""}`,onClick:()=>u(p.id),children:e.jsx(Kt,{template:p,onClick:()=>{}})},p.id))})]}),g&&e.jsxs("div",{children:[e.jsx(j,{htmlFor:"copyName",children:"Package Name *"}),e.jsx(R,{id:"copyName",value:G,onChange:p=>C(p.target.value),placeholder:`${g.name} (Custom)`,className:"mt-1"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:['All tasks from "',g.name,'" will be copied to your new package']})]})]}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:b,disabled:M,children:"Cancel"}),e.jsxs(o,{onClick:H,disabled:!x||!G.trim()||M,children:[M&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Copy Package"]})]})]}),e.jsxs(Ie,{value:"scratch",className:"space-y-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(j,{htmlFor:"name",children:"Package Name *"}),e.jsx(R,{id:"name",value:D,onChange:p=>d(p.target.value),placeholder:"e.g., New Hire Documents, Annual Policy Review",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"description",children:"Description"}),e.jsx(rs,{id:"description",value:F,onChange:p=>v(p.target.value),placeholder:"Describe what this package is for and when to use it",className:"mt-1",rows:3})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"category",children:"Category"}),e.jsxs(Ns,{value:I,onChange:p=>X(p.target.value),className:"mt-1",children:[e.jsx("option",{value:"",children:"Select a category (optional)"}),Ba.map(p=>e.jsx("option",{value:p.value,children:p.label},p.value))]})]}),e.jsxs(ne,{className:"bg-muted",children:[e.jsx(Ot,{children:e.jsx(Et,{className:"text-sm",children:"What's Next?"})}),e.jsx(le,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:'After clicking "Create Package", the package will open so you can immediately add documents from the document library.'})})]})]}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:b,disabled:M,children:"Cancel"}),e.jsxs(o,{onClick:U,disabled:!D.trim()||M,children:[M&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Create Package"]})]})]})]})]})})}const Ya=[{value:"GOVERNMENT_FORM",label:"Government Forms",icon:z},{value:"COMPANY_POLICY",label:"Company Policies",icon:Yt},{value:"INFORMATION",label:"Information Collection",icon:z},{value:"DOCUMENT_UPLOAD",label:"Document Uploads",icon:z},{value:"TRAINING",label:"Training",icon:z},{value:"EQUIPMENT",label:"Equipment",icon:z},{value:"CUSTOM",label:"Custom Tasks",icon:z}];function qa({open:s,onOpenChange:t,onAddTask:w,existingTaskTypes:T=[]}){const{taskLibrary:L,isLoadingTaskLibrary:k,loadTaskLibrary:S}=Pe(),[q,E]=r.useState(""),[M,W]=r.useState("all"),[D,d]=r.useState([]);r.useEffect(()=>{s&&(S(),d([]))},[s]);const F=()=>{D.length!==0&&(w(D.map(x=>({...x,name:qe(x.name)}))),se.success(`${D.length} task${D.length>
11?"s":""} added to list`),d([]))},v=x=>{d(u=>u.some(C=>C.taskType===x.taskType)?u.filter(C=>C.taskType!==x.taskType):[...u,x])},I=L.filter(x=>{if(Lt(x.taskType)||M!=="all"&&x.category!==M)return!1;if(q){const u=q.toLowerCase();return qe(x.name).toLowerCase().includes(u)||x.name.toLowerCase().includes(u)||x.description.toLowerCase().includes(u)||x.taskType.toLowerCase().includes(u)}return!0}),X=I.reduce((x,u)=>(x[u.category]||(x[u.category]=[]),x[u.category].push(u),x),{});return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-5xl max-h-[90vh] flex flex-col",children:[e.jsxs(Te,{children:[e.jsx(ve,{children:"Task Library"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Browse and add tasks to your package"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search tasks by name, description, or type...",value:q,onChange:x=>E(x.target.value),className:"pl-10"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-4",children:k?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):I.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground",children:[e.jsx(Be,{className:"h-12 w-12 mb-4"}),e.jsx("p",{children:"No tasks found"})]}):Object.entries(X).map(([x,u])=>{const G=Ya.find(C=>C.value===x);return e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[G&&e.jsx(G.icon,{className:"h-4 w-4"}),(G==null?void 0:G.label)||x,e.jsx(B,{variant:"secondary",children:u.length})]}),e.jsx("div",{className:"space-y-2",children:u.map(C=>{const b=T.includes(C.taskType),U=D.some(H=>H.taskType===C.taskType);return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${U?"border-primary border-2":""}`,onClick:()=>v(C),children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium",children:qe(C.name)}),b&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800 hover:bg-green-100 border-green-200",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Added"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:C.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(B,{variant:"outline",className:"text-xs",children:C.taskType.replace(/_/g," ")}),C.isLegalRequired&&e.jsxs(B,{variant:"destructive",className:"text-xs",children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Legally Required"]}),!C.isRemovable&&e.jsx(B,{variant:"secondary",className:"text-xs",children:"Cannot be removed"})]})]}),U&&e.jsx(ge,{className:"h-5 w-5 text-primary"})]})})},C.taskType)})})]},x)})}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Done"}),e.jsxs(o,{onClick:F,disabled:D.length===0,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),D.length>1?`Add Tasks (${D.length})`:"Add Task"]})]})]})})}function Wa({open:s,onOpenChange:t,onSelect:w}){const{currentOrganizationId:T}=Ge(),L=At(),{documents:k,folders:S,isLoadingDocuments:q,loadDocuments:E,loadFolders:M,searchDocuments:W,searchQuery:D,setSearchQuery:d,uploadDocument:F}=tt(),[v,I]=r.useState(null),[X,x]=r.useState("existing"),[u,G]=r.useState(!1),[C,b]=r.useState(null),U=r.useRef(null);r.useEffect(()=>{s&&T&&(E(),M(),I(null),b(null),x("existing"))},[s,T]);const H=y=>{const Y=y.target.value;d(Y),Y.length>2?W(Y):Y.length===0&&E()},g=()=>{const y=k.find(Y=>Y.id===v);if(y){const Y=`/api/file-cabinet/documents/${y.id}/download`;w(Y,y.fileName),t(!1)}},p=y=>{y.target.files&&y.target.files[0]&&b(y.target.files[0])},A=async()=>{if(!C)return;const y=S.find(Y=>Y.name==="Resources")||S.find(Y=>Y.name==="Contracts")||S[0];if(!y){se.error("No folder available. Please create a folder in File Cabinet first.");return}G(!0);try{await F(C,{folderId:y.id,title:C.name,description:"Uploaded for workflow template",tags:["workflow-resource"]}),se.success("File uploaded successfully"),await E();const te=tt.getState().documents.find(ie=>ie.originalName===C.name||ie.fileName.includes(C.name));if(te){const ie=`/api/file-cabinet/documents/${te.id}/download`;w(ie,te.originalName),t(!1)}else x("existing");b(null)}catch(Y){console.error("Upload failed:",Y),se.error("Failed to upload file")}finally{G(!1)}};return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-2xl h-[600px] flex flex-col",children:[e.jsx(Te,{children:e.jsx(ve,{children:"Select Resource File"})}),e.jsxs(Ze,{value:X,onValueChange:x,className:"flex-1 flex flex-col",children:[e.jsxs(Je,{className:"grid w-full grid-cols-2",children:[e.jsx(oe,{value:"existing",children:"Select Existing File"}),e.jsx(oe,{value:"upload",children:"Upload New File"})]}),e.jsxs(Ie,{value:"existing",className:"flex-1 flex flex-col mt-4",children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}
1),e.jsx(R,{placeholder:"Search files...",value:D,onChange:H,className:"pl-9"})]}),e.jsx("div",{className:"flex-1 border rounded-md p-4 overflow-y-auto",children:q?e.jsx("div",{className:"flex justify-center items-center h-full",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):k.length===0?e.jsx("div",{className:"text-center text-muted-foreground py-8",children:"No files found"}):e.jsx("div",{className:"grid grid-cols-1 gap-2",children:k.map(y=>e.jsxs("div",{className:`flex items-center p-3 rounded-lg border cursor-pointer transition-colors ${v===y.id?"bg-primary/10 border-primary":"hover:bg-muted"}`,onClick:()=>I(y.id),children:[e.jsx(lt,{className:"h-8 w-8 text-blue-500 mr-3"}),e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsx("p",{className:"font-medium truncate",children:y.fileName}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[(y.fileSize/1024).toFixed(1)," KB"]}),e.jsx("span",{children:"â¢"}),e.jsx("span",{children:new Date(y.createdAt).toLocaleDateString("en-US",{timeZone:L})})]})]}),y.tags&&y.tags.length>0&&e.jsx("div",{className:"flex gap-1",children:y.tags.slice(0,2).map(Y=>e.jsx(B,{variant:"secondary",className:"text-xs",children:Y},Y))})]},y.id))})}),e.jsxs("div",{className:"flex justify-end mt-4 gap-2",children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(o,{onClick:g,disabled:!v,children:"Select File"})]})]}),e.jsxs(Ie,{value:"upload",className:"flex-1 flex flex-col mt-4",children:[e.jsx("div",{className:"flex-1 border-2 border-dashed rounded-lg p-8 flex flex-col items-center justify-center text-center",children:C?e.jsxs("div",{className:"flex items-center p-4 border rounded-lg bg-muted/50 w-full max-w-md",children:[e.jsx(lt,{className:"h-10 w-10 text-blue-500 mr-4"}),e.jsxs("div",{className:"flex-1 overflow-hidden text-left",children:[e.jsx("p",{className:"font-medium truncate",children:C.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(C.size/1024).toFixed(1)," KB"]})]}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>b(null),children:"Change"})]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"Upload a new file"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Click to select a file from your computer"}),e.jsxs(o,{onClick:()=>{var y;return(y=U.current)==null?void 0:y.click()},children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Select File"]}),e.jsx("input",{type:"file",ref:U,className:"hidden",onChange:p})]})}),e.jsxs("div",{className:"flex justify-end mt-4 gap-2",children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(o,{onClick:A,disabled:!C||u,children:[u&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Upload & Select"]})]})]})]})]})})}const Ha=["CUSTOM_FORM","INFO"],Ka=["W4_FORM","I9_FORM","W9_FORM","EMERGENCY_CONTACT","DIRECT_DEPOSIT","PERSONAL_INFO","BACKGROUND_CHECK"],za=["DOCUMENT_SIGNING","STATE_TAX_FORM","EMPLOYEE_HANDBOOK","CODE_OF_CONDUCT","NDA_CONFIDENTIALITY","NON_COMPETE","ANTI_HARASSMENT_POLICY","ACCEPTABLE_USE_POLICY","SAFETY_POLICY","REMOTE_WORK_POLICY","HARASSMENT_POLICY","BACKGROUND_CHECK_AUTHORIZATION","DRUG_TEST_AUTHORIZATION"];function $a(s){switch(s){case"STATE_TAX_FORM":return"State Tax Form";case"EMPLOYEE_HANDBOOK":return"Employee Handbook";case"CODE_OF_CONDUCT":return"Code of Conduct";case"NDA_CONFIDENTIALITY":return"Confidentiality Agreement";case"NON_COMPETE":return"Non-Compete Agreement";case"ANTI_HARASSMENT_POLICY":case"HARASSMENT_POLICY":return"Harassment Policy";
1case"SAFETY_POLICY":return"Safety Policy";case"ACCEPTABLE_USE_POLICY":return"Acceptable Use Policy";case"REMOTE_WORK_POLICY":return"Remote Work Policy";case"BACKGROUND_CHECK_AUTHORIZATION":return"Background Check Authorization";case"DRUG_TEST_AUTHORIZATION":return"Drug Test Authorization";default:return"Document Template"}}function Xa(s){switch(s){case"STATE_TAX_FORM":return"Upload your state's official tax withholding form (e.g., CA DE-4, NY IT-2104) as a Document Signing template with signature fields configured.";case"EMPLOYEE_HANDBOOK":return"Upload your company's employee handbook PDF. Employees will acknowledge receipt and understanding by signing.";case"CODE_OF_CONDUCT":return"Upload your company's code of conduct document. Employees will review and sign to acknowledge compliance.";case"NDA_CONFIDENTIALITY":return"Upload your confidentiality or NDA agreement. Employees will review and sign to protect company information.";case"NON_COMPETE":return"Upload your non-compete agreement approved by legal counsel. Employees will review and sign.";case"ANTI_HARASSMENT_POLICY":case"HARASSMENT_POLICY":return"Upload your anti-harassment policy document. Employees will review and sign to acknowledge understanding.";case"SAFETY_POLICY":return"Upload your workplace safety policy. Employees will review and sign to acknowledge safety requirements.";case"ACCEPTABLE_USE_POLICY":return"Upload your acceptable use policy for company resources. Employees will sign to agree to terms.";case"REMOTE_WORK_POLICY":return"Upload your remote work policy document. Remote employees will review and sign.";case"BACKGROUND_CHECK_AUTHORIZATION":return"Upload your FCRA-compliant background check disclosure and authorization form. Employees will sign to consent.";case"DRUG_TEST_AUTHORIZATION":return"Upload your drug testing consent form. Employees will sign to authorize testing.";default:return"Upload your PDF document and configure signature fields. Employees will review and sign."}}const Va=["COMPANY_OVERVIEW_VIDEO","ORIENTATION_VIDEO","SAFETY_TRAINING","HARASSMENT_TRAINING","SECURITY_AWARENESS_TRAINING","EQUIPMENT_TRAINING","SOFTWARE_TRAINING","DEPARTMENT_ORIENTATION","EXTERNAL_LINK"],Qa=["CUSTOM_DOCUMENT","CUSTOM_DOCUMENT_UPLOAD","CERTIFICATION_UPLOAD","FOOD_HANDLER_CERT","UPLOAD_PROFESSIONAL_LICENSE","UPLOAD_EDUCATIONAL_CREDENTIALS","ID_UPLOAD","UPLOAD_PHOTO_ID","SSN_CARD_UPLOAD","UPLOAD_SSN_CARD","UPLOAD_VOIDED_CHECK"],Za=["I9_DOCUMENT_UPLOAD"],Ja=["PAYROLL_ID_COPIES"],Ct=["CUSTOM_DOCUMENT","CUSTOM_DOCUMENT_UPLOAD"],wt=[{value:"DRIVERS_LICENSE",label:"Driver's License"},{value:"STATE_ID",label:"State ID"},{value:"PASSPORT",label:"Passport"},{value:"SSN_CARD",label:"Social Security Card"},{value:"BIRTH_CERTIFICATE",label:"Birth Certificate"},{value:"WORK_AUTHORIZATION",label:"Work Authorization"},{value:"DIRECT_DEPOSIT_VOID_CHECK",label:"Voided Check / Direct Deposit"},{value:"OTHER",label:"Other"}];function er(s){return s==="CUSTOM_FORM"||s==="INFO"?"CUSTOM_FORM":null}const Es={CUSTOM_FORM:{title:"Acknowledgment",content:`Please review the following information and confirm your acknowledgment. 2 3[Enter your content here] 4 5By completing this task, I confirm that I have read and understand the above information.`}};function sr({task:s,open:t,onOpenChange:w,onSave:T,isSystemTemplate:L=!1}){var cs,ds,os,Ke;const[k,S]=r.useState(""),[q,E]=r.useState(""),[M,W]=r.useState(""),[D,d]=r.useState(!1),[F,v]=r.useState(!1),[I,X]=r.useState(!1),[x,u]=r.useState("template"),[G,C]=r.useState(""),[b,U]=r.useState(""),[H,g]=r.useState("BUILTIN"),[p,A]=r.useState([]),[y,Y]=r.useState(""),[te,ie]=r.useState(!1),[ae,J]=r.useState(!1),[V,i]=r.useState(null),[h,N]=r.useState(""),[P,he]=r.useState(!1),ee=r.useRef(null),[re,me]=r.useState([]),[Oe,Ce]=r.useState(""),Ee=s?Ha.includes(s.taskType):!1,_e=s?Va.includes(s.taskType):!1,Re=s?Ka.includes(s.taskType):!1,we=s?Qa.includes(s.taskType):!1,pe=s?Ct.includes(s.taskType):!1,Le=s?Za.includes(s.taskType):!1,Fe=s?Ja.includes(s.taskType):!1,ke=s?za.includes(s.taskType):!1,m=(s==null?void 0:s.taskType)==="STATE_TAX_FORM",Q=s?er(s.taskType):null,K=Q!==null;r.useEffect(()=>{ke&&t&&(async()=>{ie(!0);try{const c=await js({isPublished:!0});A(c)}catch(c){console.error("Failed to load document templates:",c)}finally{ie(!1)}})()},[ke,t]),r.useEffect(()=>{if(s){const n=Ct.includes(s.taskType),c=(s.title||"").trim();S(c?n?qe(c):c:n?at:""),E(s.description||"");const _=s.taskConfig||s.metadata||{};if(W(_.link||_.url||_.resourceUrl||""),_.contentMode?(u(_.contentMode),C(_.contentText||"")):_.link||_.url||_.resourceUrl?(u("link"),C("")):Ee&&K?(u("template"),C("")):(u("link"),C("")),U(typeof _.stateCode=="string"?_.stateCode:""),_.stateTaxMode==="NONE"||_.skipStateTax)g("SKIP");else if(_.useBuiltinForm||_.stateCode&&ss[_.stateCode])g("BUILTIN");else if(_.documentTemplateId)g("ESIGNATURE");else{const $e=_.stateCode;$e&&ss[$e]?g("BUILTIN"):g("ESIGNATURE")}Y(typeof _.documentTemplateId=="string"?_.documentTemplateId:"");const ze=Array.isArray(_.acceptedDocTypes)?_.acceptedDocTypes:[];me(ze.length>
50?ze:n?["OTHER"]:[]),Ce(typeof _.customInstructions=="string"?_.customInstructions:""),X(!1),J(!1),i(null),N("")}},[s,t,Ee,K]);const $=n=>{var _;const c=(_=n.target.files)==null?void 0:_[0];if(c&&c.type==="application/pdf"&&(i(c),!h)){const ze=c.name.replace(".pdf","").replace(/[-_]/g," ").replace(/\b\w/g,$e=>$e.toUpperCase());N(ze)}},es=async()=>{if(!(!V||!h.trim())){he(!0);try{const n=await Dt({name:h.trim(),category:Ts(s==null?void 0:s.taskType)},V);await _t(n.id);const c={...n,isPublished:!0};A(_=>[..._,c]),Y(n.id),J(!1),i(null),N(""),se.success("Document template uploaded and selected!")}catch(n){console.error("Failed to upload template:",n),se.error("Failed to upload document. Please try again.")}finally{he(!1)}}},Ts=n=>{switch(n){case"EMPLOYEE_HANDBOOK":return"HANDBOOK";case"NDA_CONFIDENTIALITY":case"NON_COMPETE":return"NDA";case"CODE_OF_CONDUCT":case"ANTI_HARASSMENT_POLICY":case"HARASSMENT_POLICY":case"SAFETY_POLICY":case"ACCEPTABLE_USE_POLICY":case"REMOTE_WORK_POLICY":return"POLICY";case"BACKGROUND_CHECK_AUTHORIZATION":case"DRUG_TEST_AUTHORIZATION":return"CONTRACT";case"STATE_TAX_FORM":return"CUSTOM";default:return"CUSTOM"}},ls=async()=>{var n;v(!0);try{const c={...(s==null?void 0:s.taskConfig)||{}};Ee&&!_e?(c.contentMode=x,x==="template"?(c.contentText=Q&&((n=Es[Q])==null?void 0:n.content)||"",c.link=void 0):x==="text"?(c.contentText=G,c.link=void 0):(c.link=M||void 0,c.contentText=void 0)):c.link=M||void 0,ke&&!m&&(c.documentTemplateId=y||void 0),m&&(c.stateCode=b||void 0,H==="SKIP"?(c.stateTaxMode="NONE",c.skipStateTax=!0,c.useBuiltinForm=!1,c.documentTemplateId=void 0):H==="BUILTIN"?(c.stateTaxMode="MANUAL",c.useBuiltinForm=!0,c.documentTemplateId=void 0,b&&ss[b]&&(c.builtinFormType=ss[b].formType)):(c.stateTaxMode="MANUAL",c.useBuiltinForm=!1,c.documentTemplateId=y||void 0)),we&&(c.acceptedDocTypes=re.length>0?re:pe?["OTHER"]:void 0,c.customInstructions=Oe.trim()||void 0);const _={...s,title:k,description:q,taskConfig:c,taskType:(s==null?void 0:s.taskType)||"CUSTOM"};await T(_),w(!1)}catch(c){console.error("Failed to save task:",c)}finally{v(!1)}};if(!s)return null;const is=()=>s.taskType.includes("TRAINING")||s.taskType==="ORIENTATION_VIDEO"?"https://example.com/training-video":s.taskType.includes("HANDBOOK")||s.taskType.includes("POLICY")?"https://example.com/policy-document.pdf":"https://example.com/resource";return e.jsxs(be,{open:t,onOpenChange:w,children:[e.jsxs(ye,{className:"max-w-lg max-h-[85vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx(Te,{children:e.jsx(ve,{children:"Edit Task"})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 py-3 border-b mt-2",children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>w(!1),disabled:F,children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),"Cancel"]}),e.jsxs(o,{size:"sm",onClick:ls,disabled:!k.trim()||F,children:[F&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Save"]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsx("h3",{className:"font-medium",children:k||s.title}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:s.taskType.replace(/_/g," ")})]}),Re&&e.jsx("div",{className:"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"text-green-600 dark:text-green-400 mt-0.5",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:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-green-800 dark:text-green-200 text-sm",children:"Built-in Form"}),e.jsx("p",{className:"text-xs text-green-700 dark:text-green-300 mt-1",children:"This task uses a built-in form that employees will fill out directly. No additional configuration is needed."})]})]})}),Le&&e.jsxs("div",{className:"space-y-4 border rounded-md p-4 bg-blue-50/50 dark:bg-blue-950/20",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Document Upload Requirements"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Employees choose List A or List B + List C. Employers cannot limit which acceptable documents are offered."})]}),Fe&&e.jsxs("div",{className:"space-y-4 border rounded-md p-4 bg-blue-50/50 dark:bg-blue-950/20",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Document Upload Requirements"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This step reuses an I-9 Social Security card when present, or asks only for the SSN card. Employers cannot change which documents are collected."})]}),we&&e.jsxs("div",{className:"space-y-4 border rounded-md p-4 bg-blue-50/50 dark:bg-blue-950/20",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Document Upload Requirements"]}),e.jsxs("div",{className:"space-y-3",children:[pe&&e.jsxs("div",{children:[e.jsxs(j,{htmlFor:"collect-task-title",className:"text-sm",children:["Title",e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"What employees see for this upload step."}),e.jsx(R,{id:"collect-task-title",value:k,onChange:n=>S(n.target.value),placeholder:at})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-sm",children:"Accepted Document Types"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:pe?"Select which types of documents employees can upload. Defaults to Other if none are selected.":"Select which types of documents employees can upload for this task. If none are selected, all types will be accepted."}),e.jsx("div",{className:"grid grid-cols-2 gap-2 mt-2",children:wt.map(n=>e.jsxs("label",{className:`flex items-center gap-2 p-2 rounded border cursor-pointer transition-colors ${re.includes(n.value)?"border-primary bg-primary/5":"hover:bg-muted/50"}`,children:[e.jsx("input",{type:"checkbox",checked:re.includes(n.value),onChange:c=>{c.target.checked?me([...re,n.value]):me(re.filter(_=>_!==n.value))},className:"rounded border-gray-300"}),e.jsx("span",{className:"text-sm",children:n.label})]},n.value))})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"custom-instructions",className:"text-sm",children:"Custom Instructions (Optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Add specific instructions that will be shown to employees when uploading."}),e.jsx(rs,{id:"custom-instructions",value:Oe,onChange:n=>Ce(n.target.value),placeholder:"e.g., Please upload a clear photo of the front and back of your ID...",rows:3})]})]}),(re.length>0||Oe.trim())&&e.jsxs("div",{className:"bg-white dark:bg-gray-900 border rounded-lg p-3 mt-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Employee will see:"}),re.length>0&&e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Accepted documents: "}),re.map(n=>{var c;return(c=wt.find(_=>_.value===n))==null?void 0:c.label}
5).filter(Boolean).join(", ")]}),Oe.trim()&&e.jsx("p",{className:"text-sm mt-1 italic",children:Oe})]})]}),Ee&&!_e&&!Re&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(j,{className:"text-sm font-medium",children:"How would you like to provide this content?"}),e.jsxs(jt,{value:x,onValueChange:n=>u(n),className:"space-y-3",children:[K&&e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${x==="template"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>u("template"),children:[e.jsx(Xe,{value:"template",id:"content-template",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"content-template",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(_s,{className:"h-4 w-4 text-primary"}),"Use default template",e.jsx("span",{className:"text-xs bg-primary/10 text-primary px-2 py-0.5 rounded",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Pre-written content ready to use"}),x==="template"&&Q&&Es[Q]&&e.jsxs("div",{className:"mt-3 p-3 bg-muted/50 rounded text-xs text-muted-foreground max-h-32 overflow-y-auto whitespace-pre-wrap",children:[Es[Q].content.substring(0,300),"..."]})]})]}),e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${x==="text"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>u("text"),children:[e.jsx(Xe,{value:"text",id:"content-text",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"content-text",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4"}),"Enter your own text"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Paste or type your own content"}),x==="text"&&e.jsx(rs,{value:G,onChange:n=>C(n.target.value),placeholder:"Enter your policy, disclosure, or acknowledgment text here...",className:"mt-3",rows:6,onClick:n=>n.stopPropagation()})]})]}),e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${x==="link"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>u("link"),children:[e.jsx(Xe,{value:"link",id:"content-link",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"content-link",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(ya,{className:"h-4 w-4"}),"Link to document"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Provide URL or upload file"}),x==="link"&&e.jsxs("div",{className:"flex gap-2 mt-3",onClick:n=>n.stopPropagation(),children:[e.jsx(R,{value:M,onChange:n=>W(n.target.value),placeholder:is(),className:"flex-1"}),e.jsx(o,{variant:"outline",size:"icon",onClick:()=>d(!0),title:"Select from File Cabinet",type:"button",children:e.jsx(it,{className:"h-4 w-4"})})]})]})]})]})]}),_e&&!Re&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(j,{htmlFor:"resource-link",className:"flex items-center gap-1",children:["Resource Link",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{id:"resource-link",value:M,onChange:n=>W(n.target.value),placeholder:is(),className:"flex-1"}),e.jsx(o,{variant:"outline",size:"icon",onClick:()=>d(!0),title:"Select from File Cabinet",type:"button",children:e.jsx(it,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Link to the training video or course employees must complete."})]}),m&&e.jsxs("div",{className:"space-y-4 border rounded-md p-4 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(Ms,{className:"h-4 w-4"}),"State Tax Withholding Form"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{className:"text-sm",children:"Select State"}),e.jsxs(Ns,{value:b,onChange:n=>{const c=n.target.value;U(c);const _=Ye(c);!_||!_.hasStateTax||_.usesFederalW4||_.hasFlatTax&&!_.formName?g("SKIP"):_.hasBuiltinForm?g("BUILTIN"):g("ESIGNATURE")},className:"w-full",children:[e.jsx("option",{value:"",children:"Select a state..."}),[...ca].sort((n,c)=>n.name.localeCompare(c.name)).map(n=>e.jsxs("option",{value:n.code,children:[n.name," ",n.hasBuiltinForm?"â":""," ",n.hasStateTax?"":"(No state tax)"]},n.code))]})]}),b&&(()=>{const n=Ye(b);if(!n)return null;const c=da(n);return e.jsxs("div",{className:`rounded-lg p-3 text-sm flex items-start gap-2 ${c.type==="success"?"bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-800":c.type==="info"?"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800":"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800"}`,children:[c.type==="success"?e.jsx(Ta,{className:"h-4 w-4 mt-0.5 flex-shrink-0 text-green-600 dark:text-green-400"}):c.type==="info"?e.jsx(Ds,{className:"h-4 w-4 mt-0.5 flex-shrink-0 text-blue-600 dar
5k:text-blue-400"}):e.jsx(Qe,{className:"h-4 w-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400"}),e.jsx("p",{className:`${c.type==="success"?"text-green-800 dark:text-green-200":c.type==="info"?"text-blue-800 dark:text-blue-200":"text-amber-800 dark:text-amber-200"}`,children:c.message})]})})(),b&&(()=>{const n=Ye(b);return n?!n.hasStateTax||n.usesFederalW4||n.hasFlatTax&&!n.formName?e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n.hasStateTax?n.usesFederalW4?"This state uses the federal W-4 for state withholding. No separate state form is needed.":"This state has a flat tax rate and typically does not require a withholding form.":"This state has no state income tax, so no withholding form is required."}),e.jsx(o,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>g("SKIP"),children:"Skip this task for employees"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx(j,{className:"text-sm font-medium",children:"How would you like to collect this form?"}),e.jsxs(jt,{value:H,onValueChange:c=>g(c),className:"space-y-2",children:[n.hasBuiltinForm&&ss[b]&&e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${H==="BUILTIN"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>g("BUILTIN"),children:[e.jsx(Xe,{value:"BUILTIN",id:"source-builtin",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"source-builtin",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(_s,{className:"h-4 w-4 text-primary"}),"Use Built-in ",n.formName," Form",e.jsx("span",{className:"text-xs bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300 px-2 py-0.5 rounded",children:"Recommended"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Interactive form that auto-calculates withholding allowances. Data is validated and PDF is generated automatically."})]})]}),e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${H==="ESIGNATURE"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>g("ESIGNATURE"),children:[e.jsx(Xe,{value:"ESIGNATURE",id:"source-esign",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"source-esign",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),"Use E-Signature Template",!n.hasBuiltinForm&&e.jsx("span",{className:"text-xs bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300 px-2 py-0.5 rounded",children:"Available"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Upload the official ",n.formName||"state tax"," PDF and configure signature fields. Good for custom requirements."]})]})]}),e.jsxs("div",{className:`flex items-start space-x-3 p-3 rounded-lg border cursor-pointer transition-colors ${H==="SKIP"?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>g("SKIP"),children:[e.jsx(Xe,{value:"SKIP",id:"source-skip",className:"mt-1"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(j,{htmlFor:"source-skip",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),"Skip State Tax Form"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Don't require state tax withholding form for this template."})]})]})]}),H==="ESIGNATURE"&&e.jsx("div",{className:"mt-4 space-y-3 pl-6 border-l-2 border-primary/20",children:te?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Z,{className:"h-4 w-4 animate-spin"}),"Loading templates..."]}):e.jsx(e.Fragment,{children:p.length===0||ae?e.jsxs("div",{className:"space-y-3",children:[!ae&&e.jsxs("div",{className:"text-sm p-3 bg-muted/50 rounded",children:[e.jsx("p",{className:"font-medium",children:"No e-signature templates yet"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 mb-3",children:["Upload the official ",n.formName||"state tax"," ","PDF from your state's tax authority."]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(o,{variant:"default",size:"sm",onClick:()=>J(!0),className:"flex-1",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Upload ",n.formName||"Form"," PDF"]}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>window.open("/dashboard/document-signing-templates","_blank"),children:"Manage All â"})]})]}),ae&&e.jsxs("div",{className:"border rounded-lg p-4 space-y-3 bg-white dark:bg-gray-900",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-medium text-sm",children:["Upload ",n.formName||"State Tax Form"]}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>{J(!1),i(null),N("")},children:e.jsx(De,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors hover:border-primary/50 ${V?"border-primary bg-primary/5":"border-muted-foreground
5/25"}`,onClick:()=>{var c;return(c=ee.current)==null?void 0:c.click()},children:[e.jsx("input",{ref:ee,type:"file",accept:".pdf,application/pdf",className:"hidden",onChange:$}),V?e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(z,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:V.name}),e.jsx(o,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:c=>{c.stopPropagation(),i(null)},children:e.jsx(De,{className:"h-3 w-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-6 w-6 mx-auto mb-1 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click to select PDF"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-xs",children:"Template Name"}),e.jsx(R,{value:h,onChange:c=>N(c.target.value),placeholder:`e.g., ${n.name} ${n.formName||"Tax Form"}`,className:"h-8 text-sm"})]}),e.jsx(o,{onClick:es,disabled:!V||!h.trim()||P,className:"w-full",size:"sm",children:P?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Uploading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Upload & Select"]})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"You can add signature fields later in Document Templates"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{className:"text-sm",children:"Select Template"}),e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>J(!0),className:"h-7 text-xs",children:[e.jsx(de,{className:"h-3 w-3 mr-1"}),"Upload New"]})]}),e.jsxs(Ns,{value:y,onChange:c=>Y(c.target.value),className:"w-full",children:[e.jsx("option",{value:"",children:"Select a document template..."}),p.map(c=>{var _;return e.jsxs("option",{value:c.id,children:[c.name," (",((_=c.fields)==null?void 0:_.length)||0," fields)"]},c.id)})]})]})})})]}):null})(),b&&!((cs=Ye(b))!=null&&cs.hasBuiltinForm)&&((ds=Ye(b))==null?void 0:ds.hasStateTax)&&!((os=Ye(b))!=null&&os.usesFederalW4)&&e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-3 text-sm",children:e.jsxs("p",{className:"text-blue-800 dark:text-blue-200 flex items-start gap-2",children:[e.jsx(Ds,{className:"h-4 w-4 mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:[e.jsx("strong",{children:"Tip:"})," Download the official"," ",((Ke=Ye(b))==null?void 0:Ke.formName)||"state tax"," form from your state's tax authority website, then upload it as an e-signature template. You can configure fillable fields for employee information and signatures."]})]})})]}),ke&&!m&&e.jsxs("div",{className:"space-y-4 border rounded-md p-4 bg-violet-50/50 dark:bg-violet-950/20",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),$a(s.taskType)]}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-3 text-sm",children:e.jsx("p",{className:"text-blue-800 dark:text-blue-200",children:Xa(s.taskType)})}),te?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Z,{className:"h-4 w-4 animate-spin"}),"Loading templates..."]}):p.length===0||ae?e.jsxs("div",{className:"space-y-3",children:[!ae&&p.length===0&&e.jsxs("div",{className:"text-sm text-muted-foreground p-3 bg-muted/50 rounded",children:[e.jsx("p",{className:"font-medium",children:"No document templates yet"}),e.jsx("p",{className:"text-xs mt-1 mb-3",children:"Upload your PDF document now, or manage all templates in Document Templates."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(o,{variant:"default",size:"sm",onClick:()=>J(!0),className:"flex-1",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Upload PDF Now"]}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>window.open("/dashboard/document-signing-templates","_blank"),children:"Manage All â"})]})]}),ae&&e.jsxs("div",{className:"border rounded-lg p-4 space-y-3 bg-violet-50/30 dark:bg-violet-950/20",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"font-medium text-sm",children:"Upload Document"}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>{J(!1),i(null),N("")},children:e.jsx(De,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors hover:border-primary/50 ${V?"border-primary bg-primary/5":"border-muted-foreground
5/25"}`,onClick:()=>{var n;return(n=ee.current)==null?void 0:n.click()},children:[e.jsx("input",{ref:ee,type:"file",accept:".pdf,application/pdf",className:"hidden",onChange:$}),V?e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(z,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:V.name}),e.jsx(o,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:n=>{n.stopPropagation(),i(null)},children:e.jsx(De,{className:"h-3 w-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-6 w-6 mx-auto mb-1 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click to select PDF"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(j,{className:"text-xs",children:"Template Name"}),e.jsx(R,{value:h,onChange:n=>N(n.target.value),placeholder:"e.g., Employee Handbook 2024",className:"h-8 text-sm"})]}),e.jsx(o,{onClick:es,disabled:!V||!h.trim()||P,className:"w-full",size:"sm",children:P?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Uploading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Upload & Select"]})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"You can add signature fields later in Document Templates"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{className:"text-sm",children:"Select Template"}),e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>J(!0),className:"h-7 text-xs",children:[e.jsx(de,{className:"h-3 w-3 mr-1"}),"Upload New"]})]}),e.jsxs(Ns,{value:y,onChange:n=>Y(n.target.value),className:"w-full",children:[e.jsx("option",{value:"",children:"Select a document template..."}),p.map(n=>{var c;return e.jsxs("option",{value:n.id,children:[n.name," (",((c=n.fields)==null?void 0:c.length)||0," fields)"]},n.id)})]}),y&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Employees will review and complete this document when assigned."})]})]}),!L&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>X(!I),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors w-full",children:[I?e.jsx(va,{className:"h-4 w-4"}):e.jsx(Ca,{className:"h-4 w-4"}),I?"Hide":"Show"," advanced options"]}),I&&e.jsxs("div",{className:"space-y-4 mt-4",children:[!pe&&e.jsxs("div",{children:[e.jsx(j,{htmlFor:"task-title",children:"Title"}),e.jsx(R,{id:"task-title",value:k,onChange:n=>S(n.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"task-description",children:"Description"}),e.jsx(rs,{id:"task-description",value:q,onChange:n=>E(n.target.value),className:"mt-1",rows:3,placeholder:"What the employee will see for this task..."})]})]})]})]})})]}),e.jsx(Wa,{open:D,onOpenChange:d,onSelect:n=>{W(n)}})]})}const tr={POLICY:Wt,CONTRACT:ys,AGREEMENT:z},ar={POLICY:"Policy",CONTRACT:"Contract",AGREEMENT:"Agreement"};function rr({open:s,onOpenChange:t,onSelectDocument:w,existingDocumentIds:T=[]}){const[L,k]=r.useState(""),[S,q]=r.useState(null),{currentOrganizationId:E}=Ge(),{data:M=[],isLoading:W}=Me({queryKey:["business-documents","published",E],queryFn:()=>fs({status:"PUBLISHED"}),enabled:s&&!!E});r.useEffect(()=>{s&&(q(null),k(""))},[s]);const D=()=>{S&&(w(S),se.success(`"${S.title}" added to template`),q(null),t(!1))},d=M.filter(v=>{var I;if(L){const X=L.toLowerCase();return v.title.toLowerCase().includes(X)||((I=v.description)==null?void 0:I.toLowerCase().includes(X))||v.type.toLowerCase().includes(X)}return!0}),F=d.reduce((v,I)=>(v[I.type]||(v[I.type]=[]),v[I.type].push(I),v),{});return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-3xl max-h-[80vh] flex flex-col",children:[e.jsxs(Te,{children:[e.jsx(ve,{children:"Add Company Document"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a published company document to add to this template. Employees will need to read and acknowledge it during the assignment."})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search documents...",value:L,onChange:v=>k(v.target.value),className:"pl-10"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-4",children:W?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground",children:[e.jsx(z,{className:"h-12 w-12 mb-4"}),e.jsx("p",{className:"font-medium",children:"No published documents found"}),e.jsx("p",{className:"text-sm mt-1",children:"Create and publish company documents in the Company Documents section first."}),e.jsx(o,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>window.open("/business-documents","_blank"),children:"Go to Company Documents"})]}):Object.entries(F).map(([v,I])=>{const X=tr[v]||z;return e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4"}),ar[v]||v,e.jsx(B,{variant:"secondary",children:I.length})]}),e.jsx("div",{className:"space-y-2",children:I.map(x=>{var C;const u=T.includes(x.id),G=(S==null?void 0:S.id)===x.id;
5return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${G?"border-primary border-2":""} ${u?"opacity-60":""}`,onClick:()=>!u&&q(x),children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium",children:x.title}),u&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Already Added"]}),x.requiresSignature&&e.jsx(B,{variant:"outline",className:"text-xs",children:"Signature Required"})]}),x.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:x.description}),e.jsx("div",{className:"flex items-center gap-2 mt-2 text-xs text-muted-foreground",children:e.jsxs("span",{children:["Version ",((C=x.currentVersion)==null?void 0:C.version)||"1.0.0"]})})]}),G&&e.jsx(ge,{className:"h-5 w-5 text-primary"})]})})},x.id)})})]},v)})}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(o,{onClick:D,disabled:!S,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Add to Template"]})]})]})})}const nr={POLICY:Wt,CONTRACT:ys,AGREEMENT:z},lr={POLICY:"Policy",CONTRACT:"Contract",AGREEMENT:"Agreement"};function ir({open:s,onOpenChange:t,onSelectDocument:w,existingBusinessDocIds:T=[],existingTemplateIds:L=[],defaultCategory:k="all"}){const[S,q]=r.useState(""),[E,M]=r.useState(k),[W,D]=r.useState(null),{currentOrganizationId:d}=Ge(),{data:F=[],isLoading:v}=Me({queryKey:["business-documents","published",d],queryFn:()=>fs({status:"PUBLISHED"}),enabled:s&&!!d}),{data:I=[],isLoading:X}=Me({queryKey:["document-templates","published",d],queryFn:()=>js({isPublished:!0}),enabled:s&&!!d}),x=v||X;r.useEffect(()=>{s&&(D(null),q(""),M(k))},[s,k]);const u=r.useMemo(()=>{const g=[];F.forEach(A=>{g.push({id:`bd-${A.id}`,name:A.title,description:A.description,documentType:"read-acknowledge",businessDocument:A})}),I.forEach(A=>{g.push({id:`st-${A.id}`,name:A.name,description:A.description,documentType:"e-signature",signableTemplate:A})});let p=g;if(E==="read-acknowledge"?p=p.filter(A=>A.documentType==="read-acknowledge"):E==="e-signature"&&(p=p.filter(A=>A.documentType==="e-signature")),S){const A=S.toLowerCase();p=p.filter(y=>{var Y;return y.name.toLowerCase().includes(A)||((Y=y.description)==null?void 0:Y.toLowerCase().includes(A))})}return p},[F,I,E,S]),G=r.useMemo(()=>({all:F.length+I.length,readAcknowledge:F.length,eSignature:I.length}),[F,I]),C=()=>{W&&(w(W),se.success(`"${W.name}" added to package`),D(null),t(!1))},b=g=>g.documentType==="read-acknowledge"&&g.businessDocument?T.includes(g.businessDocument.id):g.documentType==="e-signature"&&g.signableTemplate?L.includes(g.signableTemplate.id):!1,U=r.useMemo(()=>u.filter(g=>g.documentType==="read-acknowledge").reduce((g,p)=>{var y;const A=((y=p.businessDocument)==null?void 0:y.type)||"OTHER";return g[A]||(g[A]=[]),g[A].push(p),g},{}),[u]),H=r.useMemo(()=>u.filter(g=>g.documentType==="e-signature"),[u]);return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-3xl max-h-[80vh] flex flex-col",children:[e.jsxs(Te,{children:[e.jsx(ve,{children:"Add Document to Package"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a document from your library. Employees will complete this during the assignment."})]}),e.jsx(Ze,{value:E,onValueChange:g=>M(g),children:e.jsxs(Je,{className:"w-full",children:[e.jsxs(oe,{value:"all",className:"flex-1 gap-2",children:["All",e.jsx(B,{variant:"secondary",className:"ml-1",children:G.all})]}),e.jsxs(oe,{value:"read-acknowledge",className:"flex-1 gap-2",children:[e.jsx(z,{className:"h-3.5 w-3.5"}),"Read & Acknowledge",e.jsx(B,{variant:"secondary",className:"ml-1",children:G.readAcknowledge})]}),e.jsxs(oe,{value:"e-signature",className:"flex-1 gap-2",children:[e.jsx(Ne,{className:"h-3.5 w-3.5"}),"E-Signature",e.jsx(B,{variant:"secondary",className:"ml-1",children:G.eSignature})]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search documents...",value:S,onChange:g=>q(g.target.value),className:"pl-10"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-4",children:x?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):u.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center text-muted-foreground",children:[e.jsx(z,{className:"h-12 w-12 mb-4"}),e.jsx("p",{className:"font-medium",children:"No published documents found"}),e.jsx("p",{className:"text-sm mt-1",children:E==="read-acknowledge"?"Create and publish company documents first.":E==="e-signature"?"Upload and publish e-signature templates first.":"Create documents in the Document Library first."}),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>window.open("/dashboard/documents","_blank"),children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),"Go to Document Library"]})]}):e.jsxs(e.Fragment,{children:[(E==="all"||E==="read-acknowledge")&&Object.keys(U).length>0&&e.jsxs("div",{children:[E==="all"&&e.jsxs("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2 text-muted-foreground",children:[e.jsx(z,{className:"h-4 w-4"}),"Read & Acknowledge"]}),Object.entries(U).map(([g,p])=>{const A=nr[g]||z;return e.jsxs("div",{className:"mb-4",children:[e.jsxs("h4",{className:"text-xs font-medium mb-2 flex items-center gap-2 text-muted-foreground uppercase",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),lr[g]||g]}),e.jsx("div",{className:"space-y-2",children:p.map(y=>e.jsx(kt,{document:y,isSelected:(W==null?void 0:W.id)===y.id,isAlreadyAdded:b(y),onSelect:D},y.id))})]},g)})]}),(E==="all"||E==="e-signature")&&H.length>0&&e.jsxs("div",{children:[E==="all"&&e.jsxs("h3",{className:"text-sm font-semibold mb-3 flex items-center gap-2 text-muted-foreground",children:[e.jsx(Ne,{className:"h-4 w-4"}),"E-Signature Documents"]}),e.jsx("div",{className:"space-y-2",children:H.map(g=>e.jsx(kt,{document:g,isSelected:(W==null?void 0:W.id)===g.id,isAlreadyAdded:b(g),onSelect:D},g.id))})]})]})}),e.jsxs(Ue,{children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(o,{onClick:C,disabled:!W,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Add to Package"]})]})]})})}function kt({document:s,isSelected:t,isAlreadyAdded:w,onSelect:T}
5){var L,k;return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${t?"border-primary border-2":""} ${w?"opacity-60":""}`,onClick:()=>!w&&T(t?null:s),children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h4",{className:"font-medium",children:s.name}),s.documentType==="read-acknowledge"?e.jsxs(B,{variant:"secondary",className:"text-xs gap-1",children:[e.jsx(z,{className:"h-3 w-3"}),"Read & Acknowledge"]}):e.jsxs(B,{variant:"secondary",className:"text-xs gap-1 bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400",children:[e.jsx(Ne,{className:"h-3 w-3"}),"E-Signature"]}),w&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Already Added"]})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-xs text-muted-foreground",children:[s.businessDocument&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["Version ",((L=s.businessDocument.currentVersion)==null?void 0:L.version)||"1.0.0"]}),s.businessDocument.requiresSignature&&e.jsx("span",{className:"text-amber-600",children:"Signature Required"})]}),s.signableTemplate&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:[s.signableTemplate.pageCount," page(s)"]}),e.jsxs("span",{children:[((k=s.signableTemplate.fields)==null?void 0:k.length)||0," field(s)"]})]})]})]}),t&&e.jsx(ge,{className:"h-5 w-5 text-primary flex-shrink-0"})]})})})}const cr=["GOVERNMENT_FORM","INFORMATION"],dr=["TRAINING"],or=["COMPANY_POLICY","DOCUMENT_UPLOAD","EQUIPMENT","CUSTOM"],mr=["EMPLOYEE_HANDBOOK","CODE_OF_CONDUCT","NDA_CONFIDENTIALITY","NON_COMPETE","ANTI_HARASSMENT_POLICY","ACCEPTABLE_USE_POLICY","SAFETY_POLICY","REMOTE_WORK_POLICY","HARASSMENT_POLICY","CONFIDENTIALITY_AGREEMENT","BACKGROUND_CHECK_AUTHORIZATION","DRUG_TEST_AUTHORIZATION","DOCUMENT_SIGNING"];function xr({open:s,onOpenChange:t,onAddItems:w,existingTaskTypes:T=[],existingBusinessDocIds:L=[],existingTemplateIds:k=[]}){const{taskLibrary:S,isLoadingTaskLibrary:q,loadTaskLibrary:E}=Pe(),{currentOrganizationId:M}=Ge(),[W,D]=r.useState("all"),[d,F]=r.useState(""),[v,I]=r.useState([]),{data:X=[],isLoading:x}=Me({queryKey:["business-documents","published",M],queryFn:()=>fs({status:"PUBLISHED"}),enabled:s&&!!M}),{data:u=[],isLoading:G}=Me({queryKey:["document-templates","published",M],queryFn:()=>js({isPublished:!0}),enabled:s&&!!M}),C=x||G;r.useEffect(()=>{s&&(E(),I([]),F(""))},[s,E]);const b=r.useMemo(()=>{if(!S)return{forms:[],training:[],other:[]};const i=h=>{if(mr.includes(h.taskType)||Lt(h.taskType))return!1;if(d){const N=d.toLowerCase();return qe(h.name).toLowerCase().includes(N)||h.name.toLowerCase().includes(N)||h.description.toLowerCase().includes(N)}return!0};return{forms:S.filter(h=>cr.includes(h.category)&&i(h)),training:S.filter(h=>dr.includes(h.category)&&i(h)),other:S.filter(h=>or.includes(h.category)&&i(h))}},[S,d]),U=r.useMemo(()=>{const i=(h,N)=>{if(!d)return!0;const P=d.toLowerCase();return h.toLowerCase().includes(P)||(N==null?void 0:N.toLowerCase().includes(P))};return{businessDocs:X.filter(h=>i(h.title,h.description)),signableTemplates:u.filter(h=>i(h.name,h.description))}},[X,u,d]),H=b.forms.length+b.training.length+b.other.length,g=r.useMemo(()=>({all:U.businessDocs.length+U.signableTemplates.length+H,readAcknowledge:U.businessDocs.length,eSignature:U.signableTemplates.length,systemForms:H}),[b,U,H]),p=i=>v.some(h=>h.type!==i.type?!1:h.type==="task"&&i.type==="task"?h.task.taskType===i.task.taskType:h.type==="business-document"&&i.type==="business-document"?h.document.id===i.document.id:h.type==="signable-template"&&i.type==="signable-template"?h.template.id===i.template.id:!1),A=i=>{p(i)?I(h=>h.filter(N=>N.type!==i.type?!0:N.type==="task"&&i.type==="task"?N.task.taskType!==i.task.taskType:N.type==="business-document"&&i.type==="business-document"?N.document.id!==i.document.id:N.type==="signable-template"&&i.type==="signable-template"?N.template.id!==i.template.id:!0)):I(h=>[...h,i])},y=i=>T.includes(i),Y=i=>L.includes(i),te=i=>k.includes(i),ie=()=>{if(v.length===0)return;let i=v;const h=v.some(P=>P.type==="task"&&P.task.taskType===oa),N=T.includes(Is)||v.some(P=>P.type==="task"&&P.task.taskType===Is);if(h&&!N&&S){const P=S.find(he=>he.taskType===Is);P&&(i=[...v,{type:"task",task:P}])}w(i.map(P=>P.type==="task"?{...P,task:{...P.task,name:qe(P.task.name)}}:P)),se.success(`${i.length} item${i.length>
51?"s":""} added to package`),I([]),t(!1)},ae=i=>{const h=y(i.taskType),N=p({type:"task",task:i});return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${N?"border-primary border-2 bg-primary/5":""} ${h?"opacity-60":""}`,onClick:()=>!h&&A({type:"task",task:i}),children:e.jsx(le,{className:"p-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-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("h4",{className:"font-medium text-sm",children:qe(i.name)}),h&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Added"]}),i.isLegalRequired&&e.jsx(B,{variant:"secondary",className:"text-xs bg-amber-100 text-amber-800 hover:bg-amber-100",title:"A legally required government form or training â not specific to this package",children:"Legally required"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:i.description})]}),N&&e.jsx(ge,{className:"h-5 w-5 text-primary flex-shrink-0"})]})})},i.taskType)},J=i=>{var P;const h=Y(i.id),N=p({type:"business-document",document:i});return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${N?"border-primary border-2 bg-primary/5":""} ${h?"opacity-60":""}`,onClick:()=>!h&&A({type:"business-document",document:i}),children:e.jsx(le,{className:"p-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-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(z,{className:"h-4 w-4 text-blue-600 flex-shrink-0"}),e.jsx("h4",{className:"font-medium text-sm",children:i.title}),h&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Added"]})]}),i.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:i.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(B,{variant:"outline",className:"text-xs",children:"Read & Acknowledge"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",((P=i.currentVersion)==null?void 0:P.version)||"1.0"]})]})]}),N&&e.jsx(ge,{className:"h-5 w-5 text-primary flex-shrink-0"})]})})},i.id)},V=i=>{var he,ee,re;const h=te(i.id),N=p({type:"signable-template",template:i}),P=(((he=i.fields)==null?void 0:he.length)||0)>0;return e.jsx(ne,{className:`cursor-pointer hover:border-primary transition-colors ${N?"border-primary border-2 bg-primary/5":""} ${h?"opacity-60":""}`,onClick:()=>!h&&A({type:"signable-template",template:i}),children:e.jsx(le,{className:"p-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-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(Ne,{className:"h-4 w-4 text-violet-600 flex-shrink-0"}),e.jsx("h4",{className:"font-medium text-sm",children:i.name}),h&&e.jsxs(B,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Added"]}),!P&&e.jsxs(B,{variant:"outline",className:"text-xs text-amber-600 border-amber-300",children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"}),"Needs Fields"]})]}),i.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:i.description}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(B,{variant:"outline",className:"text-xs bg-violet-50 text-violet-700 border-violet-200",children:"E-Signature"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.pageCount," page",i.pageCount!==1?"s":""]}),P&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[(ee=i.fields)==null?void 0:ee.length," field",((re=i.fields)==null?void 0:re.length)!==1?"s":""]})]})]}),N&&e.jsx(ge,{className:"h-5 w-5 text-primary flex-shrink-0"})]})})},i.id)};return e.jsx(be,{open:s,onOpenChange:t,children:e.jsxs(ye,{className:"max-w-4xl max-h-[85vh] flex flex-col",children:[e.jsxs(Te,{children:[e.jsx(ve,{children:"Add to Package"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select documents to add to this package"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:"Search all items...",value:d,onChange:i=>F(i.target.value),className:"pl-10"})]}),e.jsxs(Ze,{value:W,onValueChange:i=>D(i),className:"flex-1 flex flex-col min-h-0",children:[e.jsxs(Je,{className:"w-full h-auto flex-wrap justify-start gap-1 p-1",children:[e.jsxs(oe,{value:"all",className:"gap-1.5 text-xs px-2 py-1.5",children:["All",e.jsx(B,{variant:"secondary",className:"text-xs px-1.5",children:g.all})]}),e.jsxs(oe,{value:"read-acknowledge",className:"gap-1.5 text-xs px-2 py-1.5",children:[e.jsx(z,{className:"h-3.5 w-3.5"}),"Read & Ack",e.jsx(B,{variant:"secondary",className:"text-xs px-1.5",children:g.readAcknowledge})]}),e.jsxs(oe,{value:"e-signature",className:"gap-1.5 text-xs px-2 py-1.5",children:[e.jsx(Ne,{className:"h-3.5 w-3.5"}),"E-Signature",e.jsx(B,{variant:"secondary",className:"text-xs px-1.5",children:g.eSignature})]}),e.jsxs(oe,{value:"system-forms",className:"gap-1.5 text-xs px-2 py-1.5",children:[e.jsx(He,{className:"h-3.5 w-3.5"}),"System Forms",e.jsx(B,{variant:"secondary",className:"text-xs px-1.5",children:g.systemForms})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto mt-4",children:[e.jsx(Ie,{value:"all",className:"m-0 space-y-4",children:C||q?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[U.businessDocs.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4 text-blue-600"}),"Read & Acknowledge",e.jsx(B,{variant:"secondary",children:U.businessDocs.length})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:U.businessDocs.map(J)})]}),U.signableTemplates.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 text-violet-600"}),"E-Signature",e.jsx(B,{variant:"secondary",children:U.signableTemplates.length})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:U.signableTemplates.map(V)})]}),(b.forms.length>0||b.training.length>0||b.other.length>0)&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4 text-green-600"}),"System Forms",e.jsx(B,{variant:"secondary",children:H})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[...b.forms,...b.training,...b.other].map(ae)})]}),U.signableTemplates.length===0&&U.businessDocs.length===0&&H===0&&e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(z,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-medium",children:"No documents found"}),e.jsx("p",{className:"text-sm mt-1",children:"Create documents in the Document Library first"}),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-3",onClick:()=>window.open("/dashboard/documents","_blank"),children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),"Open Document Library"]})]})]})}),e.jsx(Ie,{value:"read-acknowledge",className:"m-0 space-y-4",children:C?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):U.businessDocs.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(z,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-medium",children:"No Read & Acknowledge documents found"}),e.jsx("p",{className:"text-sm mt-1",children:"Create documents in the Document Library first"}),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-3",onClick:()=>window.open("/dashboard/documents","_blank"),children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),"Open Document Library"]})]}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:U.businessDocs.map(J)})}),e.jsx(Ie,{value:"e-signature",className:"m-0 space-y-4",children:C?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):U.signableTemplates.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Ne,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-medium",children:"No E-Signature documents found"}),e.jsx("p",{className:"text-sm mt-1",children:"Create documents in the Document Library first"}),e.jsxs(o,{variant:"outline",size:"sm",className:"mt-3",onClick:()=>window.open("/dashboard/documents","_blank"),children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),"Open Document Library"]})]}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:U.signableTemplates.map(V)})}),e.jsx(Ie,{value:"system-forms",className:"m-0 space-y-4",children:q?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):H===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(He,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No system forms found"})]}):e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[...b.forms,...b.training,...b.other].map(ae)})})]})]}),e.jsxs(Ue,{className:"flex items-center justify-between border-t pt-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:v.length>0?e.jsxs("span",{className:"font-medium text-foreground",children:[v.length," item",v.length>
51?"s":""," selected"]}):e.jsx("span",{children:"Select items to add to package"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsxs(o,{onClick:ie,disabled:v.length===0,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Add to Package",v.length>0&&` (${v.length})`]})]})]})]})})}const St=["EMPLOYEE_HANDBOOK","CODE_OF_CONDUCT","NDA_CONFIDENTIALITY","NON_COMPETE","ANTI_HARASSMENT_POLICY","ACCEPTABLE_USE_POLICY","SAFETY_POLICY","REMOTE_WORK_POLICY","HARASSMENT_POLICY","STATE_TAX_FORM","BACKGROUND_CHECK_AUTHORIZATION","DRUG_TEST_AUTHORIZATION","DOCUMENT_SIGNING"],It=["COMPANY_OVERVIEW_VIDEO","ORIENTATION_VIDEO","SAFETY_TRAINING","HARASSMENT_TRAINING","SECURITY_AWARENESS_TRAINING","EQUIPMENT_TRAINING","SOFTWARE_TRAINING","DEPARTMENT_ORIENTATION","EXTERNAL_LINK"];function ur({template:s,open:t,onOpenChange:w}){var Bs,Gs,Ys,qs,Ws,Hs,Ks,zs,$s,Xs,Vs,Qs,Zs,Js;const{t:T}=ns("onboarding"),{updateTemplate:L,deleteTemplate:k,copyTemplate:S,replaceIdentityUploads:q,deleteTask:E,reorderTasks:M,taskLibrary:W,loadTaskLibrary:D}=Pe(),[d,F]=r.useState(!1),[v,I]=r.useState(s.name),[X,x]=r.useState(s.description||""),[u,G]=r.useState(!1),[C,b]=r.useState(!1),[U,H]=r.useState(null),[g,p]=r.useState(!1),[A,y]=r.useState(!1),[Y,te]=r.useState(!1),[ie,ae]=r.useState(!1),[J,V]=r.useState(null),[i,h]=r.useState(null),[N,P]=r.useState(s.tasks||[]),[he,ee]=r.useState(!1),[re,me]=r.useState([]),[Oe,Ce]=r.useState(!1),[Ee,_e]=r.useState(null),[Re,we]=r.useState(new Set),[pe,Le]=r.useState(!1),Fe=r.useRef(!1),ke=r.useRef(null);r.useEffect(()=>{const a=Fe.current;I(s.name),x(s.description||""),F(a),Fe.current=!1,P(s.tasks||[]),ee(!1),me([]),we(new Set),a&&setTimeout(()=>{var l;return(l=ke.current)==null?void 0:l.focus()},50)},[s.id]),r.useEffect(()=>{t&&W.length===0&&D()},[t,W.length,D]);const m=a=>{const l=W.find(O=>O.taskType===a);return l?l.isLegalRequired===!0:!1},Q=a=>{const l=W.find(O=>O.taskType===a);return l?l.isRemovable!==!1&&l.isLegalRequired!==!0:!0},K=()=>{if(!U)return null;const a=N.find(O=>O.id===U);if(!a)return null;const l=W.find(O=>O.taskType===a.taskType);return{task:a,isLegal:m(a.taskType),isRemovable:Q(a.taskType),libraryEntry:l}},$=!s.isSystemTemplate,es=Rt(N),Ts=$&&ma(N),ls=async()=>{if($){Le(!0);try{const a=await q(s.id);P(a.tasks||[]),ee(!1),me([]),we(new Set),F(!1),se.success(T("templates.replaced"))}catch(a){console.error("Failed to replace identity uploads:",a)}finally{Le(!1)}}},is=async()=>{if(!$)return;const a=N.filter(l=>l.taskType==="UPLOAD_VOIDED_CHECK");if(a.length!==0){Le(!0);try{for(const f of a)f.id.startsWith("temp-")||await hs.deleteTemplateTask(s.id,f.id);const l=N.filter(f=>f.taskType!=="UPLOAD_VOIDED_CHECK");P(l);const O=l.filter(f=>!f.id.startsWith("temp-"));O.length>0&&await hs.reorderTemplateTasks(s.id,{taskIds:O.map(f=>f.id)}),await Pe.getState().loadTemplate(s.id),se.success(T("templates.voidedCheckRemoved"))}catch(l){console.error("Failed to remove voided-check step:",l)}finally{Le(!1)}}},cs=a=>{const l=a.map((O,f)=>({id:`temp-${Date.now()}-${Math.random().toString(36).substr(2,9)}-${f}`,templateId:s.id,taskType:O.taskType,title:O.name,description:O.description,instructions:null,isRequired:O.defaultRequired??O.isLegalRequired,orderIndex:N.length+1+f,taskConfig:O.defaultConfig,conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}));P([...N,...l]),ee(!0)},ds=a=>{const l={id:`temp-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,templateId:s.id,taskType:"COMPANY_DOCUMENT",title:a.title,description:a.description||`Review and acknowledge: ${a.title}`,instructions:null,isRequired:!0,orderIndex:N.length+1,taskConfig:{businessDocumentId:a.id,requiresSignature:a.requiresSignature,documentType:a.type},conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};P([...N,l]),ee(!0)},os=a=>{if(a.documentType==="read-acknowledge"&&a.businessDocument){const l={id:`temp-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,templateId:s.id,taskType:"COMPANY_DOCUMENT",title:a.businessDocument.title,de
5scription:a.businessDocument.description||`Review and acknowledge: ${a.businessDocument.title}`,instructions:null,isRequired:!0,orderIndex:N.length+1,taskConfig:{businessDocumentId:a.businessDocument.id,requiresSignature:a.businessDocument.requiresSignature,documentType:a.businessDocument.type},conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};P([...N,l])}else if(a.documentType==="e-signature"&&a.signableTemplate){const l={id:`temp-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,templateId:s.id,taskType:"DOCUMENT_SIGNING",title:a.signableTemplate.name,description:a.signableTemplate.description||`Sign document: ${a.signableTemplate.name}`,instructions:null,isRequired:!0,orderIndex:N.length+1,taskConfig:{documentTemplateId:a.signableTemplate.id},conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};P([...N,l])}ee(!0)},Ke=N.filter(a=>{var l;return a.taskType==="COMPANY_DOCUMENT"&&((l=a.taskConfig)==null?void 0:l.businessDocumentId)}).map(a=>a.taskConfig.businessDocumentId),n=N.filter(a=>{var l;return a.taskType==="DOCUMENT_SIGNING"&&((l=a.taskConfig)==null?void 0:l.documentTemplateId)}).map(a=>a.taskConfig.documentTemplateId),c=a=>{const l=[],O=N.length;a.forEach((f,fe)=>{const ce=`temp-${Date.now()}-${Math.random().toString(36).substr(2,9)}-${fe}`,Se=O+1+fe;f.type==="task"?l.push({id:ce,templateId:s.id,taskType:f.task.taskType,title:f.task.name,description:f.task.description,instructions:null,isRequired:f.task.defaultRequired??f.task.isLegalRequired,orderIndex:Se,taskConfig:f.task.defaultConfig,conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}):f.type==="business-document"?l.push({id:ce,templateId:s.id,taskType:"COMPANY_DOCUMENT",title:f.document.title,description:f.document.description||`Review and acknowledge: ${f.document.title}`,instructions:null,isRequired:!0,orderIndex:Se,taskConfig:{businessDocumentId:f.document.id,requiresSignature:f.document.requiresSignature,documentType:f.document.type},conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()}):f.type==="signable-template"&&l.push({id:ce,templateId:s.id,taskType:"DOCUMENT_SIGNING",title:f.template.name,description:f.template.description||`Sign document: ${f.template.name}`,instructions:null,isRequired:!0,orderIndex:Se,taskConfig:{documentTemplateId:f.template.id},conditions:null,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()})}),l.length>0&&(P([...N,...l]),ee(!0))},_=a=>{_e(a),Ce(!0)},ze=async a=>{P(l=>l.map(O=>O.id===a.id?a:O)),a.id.startsWith("temp-")||we(l=>new Set(l).add(a.id))},$e=async()=>{G(!0);try{if(!$){console.error("Cannot save system template changes"),G(!1);return}{for(const a of re)try{await E(s.id,a)}catch(l){console.error(`Failed to delete task ${a}:`,l)}try{await L(s.id,{name:v.trim(),description:X.trim()||void 0})}catch(a){throw console.error("Failed to update template details:",a),a}for(const a of Re){const l=N.find(O=>O.id===a);l&&await hs.updateTemplateTask(s.id,a,{title:l.title,description:l.description||void 0,instructions:l.instructions||void 0,isRequired:l.isRequired,taskConfig:l.taskConfig||void 0})}if(he){const a=new Map,l=N.filter(f=>f.id.startsWith("temp-"));for(const f of l){const fe=await hs.addTemplateTask(s.id,{taskType:f.taskType,title:f.title,description:f.description||void 0,instructions:f.instructions||void 0,isRequired:f.isRequired,taskConfig:f.taskConfig||void 0});a.set(f.id,fe.id)}const O=N.map(f=>f.id.startsWith("temp-")?a.get(f.id):f.id);await M(s.id,O)}ee(!1),me([]),we(new Set),F(!1),await Pe.getState().loadTemplate(s.id)}}catch(a){console.error("Failed to update template:",a)}finally{G(!1)}},zt=async()=>{G(!0);try{await k(s.id),w(!1)}catch(a){console.error("Failed to delete template:",a)}finally{G(!1),b(!1)}},vs=async()=>{const a=`${s.name} (Copy)`;G(!0);try{const l=await S(s.id,a);l&&(Fe.current=!0,await Pe.getState().loadTemplate(l.id))}catch(l){console.error("Failed to copy template:",l)}finally{G(!1)}},$t=async a=>{if(a.startsWith("temp-")){P(l=>l.filter(O=>O.id!==a)),H(null);return}if(d){me(l=>[...l,a]),P(l=>l.filter(O=>O.id!==a)),H(null),ee(!0);return}try{G(!0),await E(s.id,a),P(l=>l.filter(O=>O.id!==a)),H(null)}catch(l){console.error("Failed to delete task:",l)}finally{G(!1)}},Xt=a=>{!$||!d||V(a)},Vt=(a,l)=>{a.preventDefault(),!(!$||!d||J===null)&&h(l)},Qt=(a,l)=>{if(a.preventDefault(),!$||!d||J===null||J===l){V(null),h(null);return}
5const O=[...N],[f]=O.splice(J,1);O.splice(l,0,f),P(O),ee(!0),V(null),h(null)},Zt=()=>{V(null)};return e.jsxs(e.Fragment,{children:[e.jsx(be,{open:t,onOpenChange:w,children:e.jsxs(ye,{className:"max-w-4xl max-h-[90vh] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0",children:[e.jsx(Te,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ve,{className:"text-xl",children:d?"Edit Package":s.name}),e.jsxs("div",{className:"flex gap-2",children:[s.isSystemTemplate&&e.jsx(B,{variant:"secondary",children:"System"}),s.category&&e.jsx(B,{variant:"outline",children:s.category.replace(/_/g," ")})]})]})}),e.jsx("div",{className:"flex items-center justify-between py-3 border-b mt-2",children:d?e.jsxs(e.Fragment,{children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>{F(!1),I(s.name),x(s.description||""),P(s.tasks||[]),ee(!1),me([]),we(new Set)},disabled:u,children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),"Cancel"]}),e.jsxs(o,{size:"sm",onClick:$e,disabled:!v.trim()||u,children:[u&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Changes"]})]}):$?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>F(!0),children:[e.jsx(ct,{className:"h-4 w-4 mr-2"}),"Edit"]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:vs,disabled:u,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Duplicate"]}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>b(!0),disabled:u,className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:[e.jsx(dt,{className:"h-4 w-4 mr-2"}),"Delete"]})]}),e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>w(!1),children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),"Close"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:vs,disabled:u,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Copy & Customize"]}),e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>w(!1),children:[e.jsx(De,{className:"h-4 w-4 mr-2"}),"Close"]})]})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[d?e.jsxs("div",{className:"space-y-4 py-4 px-1",children:[e.jsxs("div",{children:[e.jsx(j,{htmlFor:"edit-name",children:"Package Name"}),e.jsx(R,{ref:ke,id:"edit-name",value:v,onChange:a=>I(a.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"edit-description",children:"Description"}),e.jsx(rs,{id:"edit-description",value:X,onChange:a=>x(a.target.value),className:"mt-1",rows:2})]})]}):s.description&&e.jsx("p",{className:"text-muted-foreground py-4 px-1",children:s.description}),es==="w2-specified-documents"&&e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4 my-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ve,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:T("templates.bannerW2")}),$&&e.jsxs(o,{size:"sm",className:"mt-3",onClick:ls,disabled:pe||u,children:[pe&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),T("templates.replaceWithI9Copies")]})]})]})}),es==="contractor-government-id"&&e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4 my-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ve,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:T("templates.banner1099")}),$&&e.jsxs(o,{size:"sm",className:"mt-3",onClick:ls,disabled:pe||u,children:[pe&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),T("templates.convertToCollectDocument")]})]})]})}),Ts&&e.jsx("div",{className:"bg-slate-50 dark:bg-slate-900/40 border border-slate-200 dark:border-slate-700 rounded-lg p-4 my-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ve,{className:"h-5 w-5 text-slate-500 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-slate-700 dark:text-slate-300",children:T("templates.voidedCheckHint")}),e.jsxs(o,{size:"sm",variant:"outline",className:"mt-3",onClick:is,disabled:pe||u,children:[pe&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),T("templates.removeVoidedCheck")]})]})]})}),(()=>{const a=N.filter(f=>{const fe=St.includes(f.taskType),ce=f.taskConfig||{},Se=ce.documentTemplateId;if(f.taskType==="STATE_TAX_FORM"){const Cs=ce.useBuiltinForm&&ce.builtinFormType,ws=ce.skipStateTax||ce.stateTaxMode==="NONE",ks=ce.stateTaxMode==="AUTO";return!(Se||Cs||ws||ks)}return fe&&!Se}),l=N.filter(f=>{const fe=It.includes(f.taskType),ce=f.taskConfig||{},Se=ce.link||ce.url||ce.resourceUrl;return fe&&!Se}),O=a.length+l.length;return s.isSystemTemplate?e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 rounded-lg p-4 my-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(as,{className:"h-5 w-5 text-blue-600 dar
5k:text-blue-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-blue-800 dark:text-blue-200",children:O>0?"Ready to customize this package?":"Want to customize this package?"}),e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300 mt-1",children:O>0?"Copy this package to upload your company documents and configure tasks for your organization.":"Copy this package to customize task details, add or remove tasks, and make it your own."}),e.jsxs(o,{size:"sm",className:"mt-3",onClick:vs,disabled:u,children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Copy & Customize"]})]})]})}):a.length>0||l.length>0?e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-4 my-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Ve,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"font-medium text-amber-800 dark:text-amber-200",children:[O," ",O===1?"task needs":"tasks need"," ","configuration"]}),a.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:"Need Document Templates:"})," ",a.map(f=>f.title).join(", ")]}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-1",children:"Upload your company's PDF documents in Document Templates, then select them here."})]}),l.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:[e.jsx("strong",{children:"Need Links:"})," ",l.map(f=>f.title).join(", ")]}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-1",children:"Add links to training videos or external resources."})]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[!d&&e.jsx(o,{variant:"outline",size:"sm",className:"border-amber-300 text-amber-900 hover:bg-amber-100",onClick:()=>F(!0),children:"Configure Tasks"}),a.length>0&&e.jsx(o,{variant:"outline",size:"sm",className:"border-amber-300 text-amber-900 hover:bg-amber-100",onClick:()=>window.open("/dashboard/document-signing-templates","_blank"),children:"Open Document Templates â"})]})]})]})}):null})(),e.jsxs("div",{id:"template-tasks-section",className:"space-y-4 my-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-semibold",children:["Documents (",N.length,")"]}),e.jsx("div",{className:"flex gap-2",children:$&&d&&e.jsxs(o,{size:"sm",onClick:()=>ae(!0),children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Add Documents"]})})]}),e.jsx("div",{className:"mt-4",children:N.length===0?e.jsx(ne,{children:e.jsxs(le,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground my-4",children:"No documents added yet"}),$&&e.jsxs(o,{size:"sm",onClick:()=>{F(!0),ae(!0)},children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"}),"Add Documents"]})]})}):e.jsx("div",{className:"space-y-2",children:N.map((a,l)=>{const O=a.taskConfig||{},f=St.includes(a.taskType),fe=O.documentTemplateId,ce=a.taskType==="STATE_TAX_FORM",Se=O.useBuiltinForm&&O.builtinFormType,Cs=O.skipStateTax||O.stateTaxMode==="NONE",ws=O.stateTaxMode==="AUTO",ks=It.includes(a.taskType),Jt=O.link||O.url||O.resourceUrl,ea=ce?!(fe||Se||Cs||ws):f&&!fe||ks&&!Jt,sa=$&&d;return e.jsx(ne,{draggable:$&&d,onDragStart:()=>Xt(l),onDragOver:Ss=>Vt(Ss,l),onDrop:Ss=>Qt(Ss,l),onDragEnd:Zt,className:`transition-all ${J===l?"opacity-50":""} ${i===l&&J!==l?"border-primary border-2 scale-105":""} ${$&&d?"cursor-move":""}`,children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[d&&e.jsx(wa,{className:`h-5 w-5 ${$?"cursor-grab active:cursor-grabbing":""}`}),e.jsx("span",{className:"text-sm font-medium",children:l+1})]}),e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[a.title,ea&&e.jsx("span",{className:"flex h-2 w-2 rounded-full bg-amber-500",title:"Configuration required"})]}),a.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a.description}),a.instructions&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-1 italic",children:["Instructions: ",a.instructions]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[a.taskType.replace(/_/g," "),e.jsx("span",{className:"mx-1.5",children:"·"}),e.jsx("span",{className:a.isRequired?"text-primary font-medium":"",children:a.isRequired?"Required":"Optional"})]})]}),e.jsxs("div",{className:"flex gap-1",children:[sa&&e.jsxs(o,{variant:"ghost",size:"sm",onClick:()=>_(a),children:[e.jsx(ct,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Edit"})]}),$&&d&&e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>H(a.id),title:"Remove task from template",className:"text-muted-foreground hover:text-destructive",children:e.jsx(dt,{className:"h-4 w-4"})})]})]})})]})})},a.id)})})})]})]})]})}),e.jsx(mt,{open:C,onOpenChange:b,children:e.jsxs(xt,{children:[e.jsxs(ut,{children:[e.jsx(ht,{children:"Delete Package?"}),e.jsxs(pt,{children:['Are you sure you want to delete "',s.name,'"? This action cannot be undone.']})]}),e.jsxs(gt,{children:[e.jsx(Nt,{disabled:u,children:"Cancel"}),e.jsxs(ft,{onClick:zt,disabled:u,children:[u&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Delete"]})]})]})}),e.jsx(mt,{open:!!U,onOpenChange:a=>!a&&H(null),children:e.jsxs(xt,{children:[e.jsxs(ut,{children:[e.jsxs(ht,{className:"flex items-center gap-2",children:[(((Bs=K())==null?void 0:Bs.isLegal)||!((Gs=K())!=null&&Gs.isRemovable))&&e.jsx(Ve,{className:"h-5 w-5 text-amber-500"}),(Ys=K())!=null&&Ys.isLegal||!((qs=K())!=null&&qs.isRemovable)?"Remove Required Task?":"Remove Task?"]}),e.jsx(pt,{className:"space-y-2",children:(Ws=K())!=null&&Ws.isLegal?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-amber-600 font-medium",children:['Warning: "',(Ks=(Hs=K())==null?void 0:Hs.task)==null?void 0:Ks.title,'" is a legally required form for US employment c
5ompliance.']}),e.jsx("p",{children:"Removing this task may result in incomplete employee documentation. Are you sure you want to remove it?"})]}):(zs=K())!=null&&zs.isRemovable?e.jsx("p",{children:"Are you sure you want to remove this task from the package?"}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-amber-600 font-medium",children:['Warning: "',(Xs=($s=K())==null?void 0:$s.task)==null?void 0:Xs.title,'" is recommended for complete onboarding.']}),e.jsx("p",{children:"Are you sure you want to remove it from this package?"})]})})]}),e.jsxs(gt,{children:[e.jsx(Nt,{disabled:u,children:"Cancel"}),e.jsxs(ft,{onClick:()=>U&&$t(U),disabled:u,className:(Vs=K())!=null&&Vs.isLegal||!((Qs=K())!=null&&Qs.isRemovable)?"bg-amber-600 hover:bg-amber-700":"",children:[u&&e.jsx(Z,{className:"h-4 w-4 mr-2 animate-spin"}),(Zs=K())!=null&&Zs.isLegal||!((Js=K())!=null&&Js.isRemovable)?"Remove Anyway":"Remove"]})]})]})}),$&&e.jsx(qa,{open:g,onOpenChange:p,onAddTask:cs,existingTaskTypes:N.map(a=>a.taskType)}),e.jsx(sr,{task:Ee,open:Oe,onOpenChange:Ce,onSave:ze,isSystemTemplate:s.isSystemTemplate}),$&&e.jsx(rr,{open:A,onOpenChange:y,onSelectDocument:ds,existingDocumentIds:Ke}),$&&e.jsx(ir,{open:Y,onOpenChange:te,onSelectDocument:os,existingBusinessDocIds:Ke,existingTemplateIds:n}),$&&e.jsx(xr,{open:ie,onOpenChange:ae,onAddItems:c,existingTaskTypes:N.map(a=>a.taskType),existingBusinessDocIds:Ke,existingTemplateIds:n})]})}const gs=s=>!s||["FULL_TIME","PART_TIME","CONTRACTOR","EXECUTIVE","REMOTE","ONBOARDING"].includes(s)?"ONBOARDING":["TRAINING","COMPLIANCE","POLICY"].includes(s)?"TRAINING_COMPLIANCE":"OTHER";function hr(){const{t:s}=ns("documentLibrary"),{currentOrganizationId:t}=Ge(),[w,T]=Ht(),{systemTemplates:L,organizationTemplates:k,isLoadingTemplates:S,searchQuery:q,loadSystemTemplates:E,loadOrganizationTemplates:M,setSearchQuery:W,selectedTemplate:D,setSelectedTemplate:d}=Pe(),[F,v]=r.useState(!1),[I,X]=r.useState(!1),[x,u]=r.useState("ALL");r.useEffect(()=>{t&&(E(),M())},[t,E,M]),r.useEffect(()=>{const A=w.get("templateId");if(!A||S)return;const y=k.find(te=>te.id===A)||L.find(te=>te.id===A);if(!y)return;d(y),X(!0);const Y=new URLSearchParams(w);Y.delete("templateId"),T(Y,{replace:!0})},[w,S,k,L,d,T]);const G=A=>{d(A),X(!0)},C=()=>{X(!1),d(null)},b=A=>{let y=A;if(q){const Y=q.toLowerCase();y=y.filter(te=>{var ie,ae;return te.name.toLowerCase().includes(Y)||((ie=te.description)==null?void 0:ie.toLowerCase().includes(Y))||((ae=te.category)==null?void 0:ae.toLowerCase().includes(Y))})}return x!=="ALL"&&(y=y.filter(Y=>gs(Y.category)===x)),y},U=b(L),H=b(k),g=[...L,...k],p={ALL:g.length,ONBOARDING:g.filter(A=>gs(A.category)==="ONBOARDING").length,TRAINING_COMPLIANCE:g.filter(A=>gs(A.category)==="TRAINING_COMPLIANCE").length,OTHER:g.filter(A=>gs(A.category)==="OTHER").length};return e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex gap-1 border-b mb-6",children:[e.jsxs("button",{onClick:()=>u("ALL"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${x==="ALL"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[s("packages.tabAll"),p.ALL>0&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",p.ALL,")"]})]}),e.jsxs("button",{onClick:()=>u("ONBOARDING"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${x==="ONBOARDING"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[s("packages.tabEmploymentForms"),p.ONBOARDING>0&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",p.ONBOARDING,")"]})]}),e.jsxs("button",{onClick:()=>u("TRAINING_COMPLIANCE"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${x==="TRAINING_COMPLIANCE"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[s("packages.tabTrainingCompliance"),p.TRAINING_COMPLIANCE>0&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",p.TRAINING_COMPLIANCE,")"]})]}),e.jsxs("button",{onClick:()=>u("OTHER"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${x==="OTHER"?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"}`,children:[s("packages.tabOther"),p.OTHER>0&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",p.OTHER,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsxs("div",{className:"relative max-w-md flex-1",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(R,{placeholder:s("packages.searchPlaceholder"),value:q,onChange:A=>W(A.target.value),className:"pl-10"})]}),e.jsxs(o,{onClick:()=>v(!0),children:[e.jsx(ot,{className:"h-4 w-4 mr-2"}),s("packages.createPackage")]})]}),e.jsxs("div",{className:"flex-1 space-y-6",children:[H.length>0&&e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-3 flex items-center gap-2",children:[e.jsx(ot,{className:"h-5 w-5 text-purple-600"}),s("packages.customPackagesTitle")]}),e.jsx(vt,{templates:H,isLoading:S,onTemplateClick:G})]}),U.length>0&&e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold mb-3 flex items-center gap-2",children:[e.jsx(_s,{className:"h-5 w-5 text-green-600"}),s("packages.readyToUseTitle")]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:s("packages.readyToUseDescription")}),e.jsx(vt,{templates:U,isLoading:S,onTemplateClick:G})]}),U.length===0&&H.length===0&&!S&&e.jsx(ne,{children:e.jsxs(le,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Ut,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-muted-foreground text-center",children:s("packages.emptyNoMatch")}),e.jsx(o,{variant:"link",onClick:()=>{W(""),u("ALL")},children:s("packages.clearFilters")})]})})]}),e.jsx(Ga,{open:F,onOpenChange:v,onTemplateCreated:G}),D&&e.jsx(ur,{template:D,open:I,onOpenChange:C})]})}const pr=["all-documents","packages"];function Vr(){const{t:s}=ns("documentLibrary"),w=Ge(E=>E.permissions).includes("VIEW_BUSINESS_DOCUMENTS"),[T,L]=Ht(),k=T.get("tab"),S=k==="company"&&w,q=k&&pr.includes(k)?k:"all-documents";return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6",children:[e.jsxs("div",{className:"mb-4 sm:mb-6",children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:s("wrapper.title")}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground",children:s("wrapper.subtitle")})]}),e.jsxs(Ze,{value:q,onValueChange:E=>{L(E==="all-documents"?{}:{tab:E})},className:"flex-1 flex flex-col",children:[e.jsxs(Je,{className:"w-max mb-4",children:[e.jsx(oe,{value:"all-documents",children:s("wrapper.tabs.allDocuments")}),e.jsx(oe,{value:"packages",children:s("wrapper.tabs.packages")})]}),e.jsx(Ie,{value:"all-documents",className:"flex-1 flex flex-col mt-0",children:e.jsx(Pa,{initialCategory:S?"company-documents":void 0})}),e.jsx(Ie,{value:"packages",className:"flex-1 flex flex-col mt-0",children:e.jsx(hr,{})})]})]})}export{Vr 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.