@realtek/core-theme 0.0.358 → 0.0.359

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,11 +13,11 @@ Upload the résumé first — we can read the details straight from it`})}),(0,l
13
13
  max-height: 420px !important;
14
14
  }
15
15
  }
16
- `}),(0,l.jsxs)(s.Form,{form:u,layout:`vertical`,initialValues:MT,disabled:h,className:`template-editor-form`,children:[(0,l.jsxs)(`div`,{className:`template-editor-grid`,children:[(0,l.jsx)(s.Form.Item,{name:`name`,label:`Template name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Candidate introduction`})}),(0,l.jsx)(s.Form.Item,{name:`module`,label:`Module`,rules:[{required:!0}],children:(0,l.jsx)(s.Select,{showSearch:!0,optionFilterProp:`label`,options:r,onChange:e=>{u.setFieldValue(`action`,``),C(e)}})}),(0,l.jsx)(s.Form.Item,{name:`action`,label:`Action`,rules:[{required:!0}],tooltip:`Pick a Row Action, or TYPE a system action key. Not every email comes from a row action — the credentials mail sent when an employer's recruiters are provisioned uses "accountCreated", which is raised by a workflow and so never appears in this list.`,children:(0,l.jsx)(s.Select,{showSearch:!0,mode:`tags`,maxCount:1,optionFilterProp:`label`,options:_,placeholder:`Select a row action, or type a system key (e.g. accountCreated)`})}),(0,l.jsx)(s.Form.Item,{name:`clientId`,label:`Client scope (optional)`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,options:i,placeholder:`Available to every client`})})]}),(0,l.jsx)(s.Form.Item,{name:`description`,label:`Description`,children:(0,l.jsx)(s.Input.TextArea,{rows:2})}),(0,l.jsxs)(`div`,{className:`template-editor-grid template-editor-grid--three`,children:[(0,l.jsx)(s.Form.Item,{name:`toMail`,label:`Default To`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})}),(0,l.jsx)(s.Form.Item,{name:`ccMail`,label:`Default Cc`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})}),(0,l.jsx)(s.Form.Item,{name:`bccMail`,label:`Default Bcc`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})})]}),(0,l.jsxs)(`div`,{className:`template-editor-workspace`,style:{display:`grid`,gridTemplateColumns:`minmax(0, 1.2fr) minmax(360px, 0.8fr)`,gap:20,alignItems:`start`,marginTop:4},children:[(0,l.jsxs)(`div`,{className:`template-editor-compose-pane`,style:{minWidth:0,padding:16,border:`1px solid #e5e7eb`,borderRadius:10,background:`#fff`},children:[(0,l.jsx)(jT,{strong:!0,style:{display:`block`,marginBottom:12},children:`Email content`}),(0,l.jsx)(s.Form.Item,{name:`subject`,label:`Subject`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Email subject — drag placeholders here`,onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect=`copy`}})}),(0,l.jsx)(s.Form.Item,{label:`Message`,required:!0,style:{marginBottom:0},children:(0,l.jsx)(`div`,{onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect=`copy`},style:{minHeight:320},children:(0,l.jsx)(n.On,{value:d,onChange:f,placeholder:`Write the reusable email body… Drag placeholders from the right panel.`})})})]}),(0,l.jsxs)(`div`,{className:`template-placeholder-panel`,style:{position:`sticky`,top:0,maxHeight:`calc(100vh - 190px)`,overflowY:`auto`,padding:16,border:`1px solid #dbeafe`,borderRadius:10,background:`#f8fbff`},children:[(0,l.jsx)(jT,{strong:!0,style:{display:`block`},children:`All module placeholders`}),(0,l.jsx)(jT,{type:`secondary`,style:{display:`block`,marginTop:4},children:`Drag a placeholder into Subject or Message. You can also click a placeholder to append it to the message.`}),A.map(e=>(0,l.jsxs)(`div`,{style:{marginTop:14},children:[(0,l.jsx)(jT,{type:`secondary`,strong:!0,children:e.label||e.moduleName}),(0,l.jsx)(`div`,{className:`template-placeholder-list`,style:{marginTop:6},children:e.fields.map(t=>(0,l.jsx)(s.Tooltip,{title:`${t.label||t.key} · ${t.value}`,children:(0,l.jsx)(s.Tag,{color:`blue`,draggable:!0,onDragStart:e=>D(e,t),onClick:()=>E(t),style:{cursor:`grab`,userSelect:`none`,marginBottom:6},children:`{{.${t.key}}}`})},`${e.moduleName}:${t.key}:${t.value}`))})]},e.moduleName)),!A.length&&(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No module fields available`})]})]}),(0,l.jsx)(s.Form.Item,{name:`isActive`,label:`Available in mail composer`,valuePropName:`checked`,style:{marginTop:16},children:(0,l.jsx)(s.Switch,{})})]})]})}function zT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(1),[h,g]=(0,o.useState)(20),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)([]),[x,S]=(0,o.useState)(null),[C,w]=(0,o.useState)(!1),T=(0,o.useMemo)(()=>_.map(e=>({value:e.key??e.module??e.value,label:e.label??e.name??e.key??e.module??e.value})).filter(e=>e.value),[_]);function E(e=p,n=h,r=d){u(!0),Gw({offset:(e-1)*n,limit:n,search:r}).then(({items:e,totalCount:n})=>{t(e),i(n)}).catch(e=>s.message.error(e?.message||`Could not load templates`)).finally(()=>u(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{E(1,h,``)})},[]),(0,o.useEffect)(()=>{Promise.all([n.Sr(),n.mr({limit:200})]).then(([e,t])=>{v(hS(e).map(({value:e,label:t})=>({key:e,label:t}))),b(t)}).catch(()=>{})},[]);async function D(e,n){let r=NT(e);try{await Jw(r,{...e,isActive:n}),t(e=>e.map(e=>NT(e)===r?{...e,isActive:n}:e))}catch(e){s.message.error(e?.message||`Could not update status`)}}async function O(e){try{await Yw(e),s.message.success(`Template deleted`),E(1),m(1)}catch(e){s.message.error(e?.message||`Could not delete template`)}}let k=[{title:`Template`,key:`template`,width:300,ellipsis:!0,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell templates-primary-cell`,children:[(0,l.jsx)(jT,{strong:!0,ellipsis:{tooltip:t.name},children:t.name}),(0,l.jsx)(jT,{type:`secondary`,ellipsis:{tooltip:t.description||t.subject},children:t.description||t.subject||`No description`})]})},{title:`Module`,dataIndex:`module`,key:`module`,width:140,ellipsis:!0,responsive:[`sm`],render:e=>e?(0,l.jsx)(s.Tag,{color:`blue`,children:e}):`—`},{title:`Action`,dataIndex:`action`,key:`action`,width:180,ellipsis:!0,responsive:[`md`],render:e=>e?(0,l.jsx)(jT,{code:!0,ellipsis:{tooltip:e},children:e}):`—`},{title:`Recipients`,key:`recipients`,width:130,responsive:[`lg`],render:(e,t)=>`${(t.toMail?.length??0)+(t.ccMail?.length??0)+(t.bccMail?.length??0)} defaults`},{title:`Active`,dataIndex:`isActive`,key:`active`,width:80,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>D(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{S(NT(t)),w(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this template?`,onConfirm:()=>O(NT(t)),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],A=y.map(e=>({value:e._id??e.id,label:e.clientName??e.name??e._id})).filter(e=>e.value);return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.MailOutlined,{}),title:`Email templates`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{S(null),w(!0)},children:`New template`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(jT,{type:`secondary`,children:`Create reusable, module-aware email content. Modules, actions and placeholders are read from DB configuration.`})]}),(0,l.jsxs)(Z,{title:`${r} template${r===1?``:`s`}`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:()=>E(),children:`Reload`}),children:[(0,l.jsx)(`div`,{className:`admin-config-table-tools`,children:(0,l.jsx)(s.Input,{allowClear:!0,prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search templates`,value:d,onChange:e=>{let t=e.target.value;f(t),m(1),E(1,h,t)}})}),(0,l.jsx)(`div`,{className:`templates-table-viewport`,children:(0,l.jsx)(s.Table,{rowKey:NT,columns:k,dataSource:e,loading:a,className:`fg-table`,size:`small`,tableLayout:`fixed`,sticky:!0,scroll:{x:914,y:`calc(100vh - 410px)`},pagination:{current:p,pageSize:h,total:r,showSizeChanger:!0,responsive:!0,onChange:(e,t)=>{m(e),g(t),E(e,t)}}})})]}),(0,l.jsx)(RT,{open:C,templateId:x,modules:T,clients:A,onClose:()=>w(!1),onSaved:()=>{w(!1),E()}})]})}function BT({open:e,signatureId:t,onClose:r,onSaved:i}){let[a,c]=(0,o.useState)(``),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)({module:`userSignature`,keys:[]}),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!e)return;let n=!1;return queueMicrotask(()=>{_(!0),Promise.all([t?eT(t):Promise.resolve(null),Qw()]).then(([e,t])=>{n||(c(e?.signatureName??``),d(e?.signature??``),p(t??{module:`userSignature`,keys:[]}))}).catch(()=>{n||s.message.error(`Could not load signature details`)}).finally(()=>{n||_(!1)})}),()=>{n=!0}},[e,t]);function v(e){let t=`{{.${e.key}}}`;d(e=>`${e}${e?` `:``}${t}`)}async function y(){if(!a.trim())return s.message.error(`Signature name is required`);if(!u.trim())return s.message.error(`Signature content is required`);h(!0);try{let e=LT(u),n=(f.keys??[]).filter(t=>e.has(t.key)).map(e=>({key:e.key,value:e.value})),r={signatureId:t,signatureName:a,signature:u,signatureLogoPath:``,placeHolder:n.length?[{moduleName:f.module||`userSignature`,holders:n}]:[]};t?await nT(r):await tT(r),s.message.success(t?`Signature updated`:`Signature created`),i()}catch(e){s.message.error(e?.message||`Could not save signature`)}finally{h(!1)}}let b=(f.keys??[]).filter(e=>![`Role_id`,`Role_name`,`Reporting_manager`].includes(e.key)),x=(f.keys??[]).filter(e=>[`Role_id`,`Role_name`,`Reporting_manager`].includes(e.key)),S=e=>(0,l.jsx)(`div`,{className:`template-placeholder-list`,children:e.map(e=>(0,l.jsx)(s.Tooltip,{title:`Mongo field: ${e.value}`,children:(0,l.jsx)(s.Tag,{color:`blue`,style:{cursor:`pointer`},onClick:()=>v(e),children:`{{.${e.key}}}`})},e.key))});return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(820px, 96vw)`,title:t?`Edit signature`:`New signature`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:m,onClick:y,children:t?`Update`:`Create`})]}),children:(0,l.jsxs)(s.Form,{layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{label:`Signature name`,required:!0,children:(0,l.jsx)(s.Input,{value:a,onChange:e=>c(e.target.value)})}),(0,l.jsx)(s.Form.Item,{label:`Signature content`,required:!0,children:(0,l.jsx)(n.On,{value:u,onChange:d,placeholder:`Create the reusable signature…`})}),(0,l.jsxs)(`div`,{className:`template-placeholder-panel`,children:[(0,l.jsx)(jT,{strong:!0,children:`Signature placeholders`}),(0,l.jsx)(jT,{type:`secondary`,children:`Click a placeholder to add it to the signature. Values resolve from MongoDB users and roles when mail is generated.`}),g?(0,l.jsx)(jT,{type:`secondary`,children:`Loading placeholders…`}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)(jT,{strong:!0,children:`User details`}),S(b)]}),(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)(jT,{strong:!0,children:`Role details`}),S(x)]}),!f.keys?.length&&(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No signature placeholders available`})]})]})]})})}function VT(){let[e,t]=(0,o.useState)([]),[n,r]=(0,o.useState)(0),[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)(1),[m,h]=(0,o.useState)(20),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null);function b(e=f,n=m,i=u){a(!0),$w({offset:(e-1)*n,limit:n,search:i}).then(({items:e,totalCount:n})=>{t(e),r(n)}).catch(()=>s.message.error(`Could not load signatures`)).finally(()=>a(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{b(1,m,``)})},[]);async function x(e,n){try{await iT(e.signatureId,n),t(t=>t.map(t=>t.signatureId===e.signatureId?{...t,isActive:n}:t))}catch{s.message.error(`Could not update status`)}}async function S(e){try{await rT(e),s.message.success(`Signature deleted`),p(1),b(1)}catch{s.message.error(`Could not delete signature`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.MailOutlined,{}),title:`Signature templates`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{y(null),_(!0)},children:`New signature`}),children:(0,l.jsx)(jT,{type:`secondary`,children:`Existing company and user signatures from the shared DB.`})}),(0,l.jsxs)(Z,{title:`${n} signature${n===1?``:`s`}`,children:[(0,l.jsx)(`div`,{className:`admin-config-table-tools`,children:(0,l.jsx)(s.Input,{allowClear:!0,prefix:(0,l.jsx)(c.SearchOutlined,{}),value:u,placeholder:`Search signatures`,onChange:e=>{d(e.target.value),p(1),b(1,m,e.target.value)}})}),(0,l.jsx)(`div`,{className:`templates-table-viewport`,children:(0,l.jsx)(s.Table,{rowKey:`signatureId`,dataSource:e,columns:[{title:`Signature`,dataIndex:`templateName`,key:`name`,width:300,ellipsis:!0,render:e=>(0,l.jsx)(jT,{strong:!0,ellipsis:{tooltip:e},children:e||`Untitled signature`})},{title:`Created`,dataIndex:`createdDt`,key:`created`,width:150,responsive:[`md`],render:e=>e?new Date(e).toLocaleDateString():`—`},{title:`Active`,dataIndex:`isActive`,key:`active`,width:80,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>x(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{y(t.signatureId),_(!0)}}),(0,l.jsx)(s.Popconfirm,{title:`Delete this signature?`,onConfirm:()=>S(t.signatureId),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],loading:i,className:`fg-table`,size:`small`,tableLayout:`fixed`,sticky:!0,scroll:{x:614,y:`calc(100vh - 410px)`},pagination:{current:f,pageSize:m,total:n,responsive:!0,onChange:(e,t)=>{p(e),h(t),b(e,t)}}})})]}),(0,l.jsx)(BT,{open:g,signatureId:v,onClose:()=>_(!1),onSaved:()=>{_(!1),b()}})]})}function HT(){return(0,l.jsx)(s.Tabs,{defaultActiveKey:`email`,className:`admin-config-tabs`,items:[{key:`email`,label:`Email templates`,children:(0,l.jsx)(zT,{})},{key:`signature`,label:`Signatures`,children:(0,l.jsx)(VT,{})}]})}var{Text:UT}=s.Typography,WT={serviceKey:``,label:``,baseUrl:``,authHeader:``,authValue:``,enabled:!0};function GT({open:e,service:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[c,u]=(0,o.useState)(!1);(0,o.useEffect)(()=>{e&&a.setFieldsValue({...WT,...t,authValue:``})},[e,t,a]);async function d(){try{let e=await a.validateFields();u(!0),await n.ni(e),s.message.success(`AI service saved`),i()}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save AI service`)}finally{u(!1)}}return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(560px, 96vw)`,title:t?`Edit AI service`:`New AI service`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:c,onClick:d,children:`Save`})]}),children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,initialValues:WT,children:[(0,l.jsx)(s.Form.Item,{name:`serviceKey`,label:`Service Key`,rules:[{required:!0,message:`Service key is required`}],tooltip:`Referenced by an AI Action's Service Key on any form field (e.g. pyOps).`,children:(0,l.jsx)(s.Input,{placeholder:`pyOps`,disabled:!!t,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`label`,label:`Label`,children:(0,l.jsx)(s.Input,{placeholder:`Resume/JD Parsing Service`})}),(0,l.jsx)(s.Form.Item,{name:`baseUrl`,label:`Base URL`,rules:[{required:!0,message:`Base URL is required`}],children:(0,l.jsx)(s.Input,{placeholder:`https://ai.example.com`,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`authHeader`,label:`Auth Header (optional)`,children:(0,l.jsx)(s.Input,{placeholder:`x-api-key`,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`authValue`,label:`Auth Value`,tooltip:`Write-only — leave blank to keep the currently saved value.`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?`Unchanged`:``})}),(0,l.jsx)(s.Form.Item,{name:`enabled`,label:`Enabled`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{})})]})})}function KT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null);function p(){i(!0),n.gr().then(e=>t(Array.isArray(e)?e:[])).catch(e=>s.message.error(e?.message||`Could not load AI services`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{p()})},[]);async function m(e,r){try{await n.ni({...e,enabled:r}),t(t=>t.map(t=>t.serviceKey===e.serviceKey?{...t,enabled:r}:t))}catch(e){s.message.error(e?.message||`Could not update AI service`)}}async function h(e){try{await n.rr(e),s.message.success(`AI service deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete AI service`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`AI Services`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New service`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(UT,{type:`secondary`,children:`Register the AI/automation backends that admin-configured "AI Actions" (Generate/Parse-style buttons on any form field) call. A field's AI Action names a Service Key here — no URL is ever hardcoded in the app.`})]}),(0,l.jsx)(Z,{title:`${e.length} service${e.length===1?``:`s`}`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),children:(0,l.jsx)(s.Table,{rowKey:`serviceKey`,columns:[{title:`Service`,key:`service`,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell`,children:[(0,l.jsx)(UT,{strong:!0,children:t.label||t.serviceKey}),(0,l.jsx)(UT,{type:`secondary`,code:!0,children:t.serviceKey})]})},{title:`Base URL`,dataIndex:`baseUrl`,key:`baseUrl`,ellipsis:!0,render:e=>(0,l.jsx)(UT,{code:!0,ellipsis:{tooltip:e},children:e})},{title:`Auth Header`,dataIndex:`authHeader`,key:`authHeader`,width:140,render:e=>e||`—`},{title:`Enabled`,dataIndex:`enabled`,key:`enabled`,width:90,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>m(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this AI service?`,onConfirm:()=>h(t.serviceKey),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:e,loading:r,className:`fg-table`,size:`small`})}),(0,l.jsx)(GT,{open:a,service:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}var{Text:qT}=s.Typography,JT={integrationKey:``,label:``,category:`GENERAL`,updateMethod:`MANUAL`,enabled:!0,provider:``,baseUrl:``,authType:`API_KEY`,authHeader:`x-api-key`,authValue:``,clientId:``,clientSecret:``,tokenUrl:``,createPath:``,statusPath:``,testPath:``,webhookSecret:``,targetModule:``,targetField:``,stageMatchField:``,stageMatchValue:``,stageStatusField:``,providerStatusPath:``,providerReferencePath:``,statusMappings:[{providerStatus:``,applicationStatus:``}]},YT=[{label:`API Key`,value:`API_KEY`},{label:`Bearer Token`,value:`BEARER_TOKEN`},{label:`Basic Authentication`,value:`BASIC_AUTH`},{label:`OAuth 2.0 Client Credentials`,value:`OAUTH2_CLIENT_CREDENTIALS`}];function XT(e){let t=Object.fromEntries((e.statusMappings??[]).filter(e=>e?.providerStatus&&e?.applicationStatus).map(e=>[e.providerStatus.trim(),e.applicationStatus.trim()])),n={...e,statusMapping:e.updateMethod===`API`?{targetModule:e.targetModule,targetField:e.targetField,stageMatchField:e.stageMatchField,stageMatchValue:e.stageMatchValue,stageStatusField:e.stageStatusField,providerStatusPath:e.providerStatusPath,providerReferencePath:e.providerReferencePath,values:t}:void 0};return[`statusMappings`,`targetModule`,`targetField`,`stageMatchField`,`stageMatchValue`,`stageStatusField`,`providerStatusPath`,`providerReferencePath`].forEach(e=>delete n[e]),n}function ZT({open:e,integration:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[u,d]=(0,o.useState)(!1),[f,p]=(0,o.useState)(!1),m=s.Form.useWatch(`updateMethod`,a),h=s.Form.useWatch(`authType`,a),g=m===`API`,_=h===`OAUTH2_CLIENT_CREDENTIALS`;(0,o.useEffect)(()=>{if(!e)return;let n=t?.statusMapping??{};a.setFieldsValue({...JT,...t,authValue:``,clientSecret:``,webhookSecret:``,targetModule:n.targetModule??``,targetField:n.targetField??``,stageMatchField:n.stageMatchField??``,stageMatchValue:n.stageMatchValue??``,stageStatusField:n.stageStatusField??``,providerStatusPath:n.providerStatusPath??``,providerReferencePath:n.providerReferencePath??``,statusMappings:Object.entries(n.values??{}).map(([e,t])=>({providerStatus:e,applicationStatus:t})).concat(Object.keys(n.values??{}).length?[]:[{providerStatus:``,applicationStatus:``}])})},[a,t,e]);async function v(){try{let e=XT(await a.validateFields());d(!0),await n.si(e),s.message.success(`Integration saved`),i()}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save integration`)}finally{d(!1)}}async function y(){try{let e=await a.validateFields([`integrationKey`,`baseUrl`,`testPath`,`authType`,`authHeader`,`authValue`,`clientId`,`clientSecret`,`tokenUrl`]);p(!0);let t=await n.mi(XT({...a.getFieldsValue(!0),...e}));s.message.success(t?.message||`Connection successful${t?.statusCode?` (${t.statusCode})`:``}`)}catch(e){e?.errorFields||s.message.error(e?.message||`Connection test failed`)}finally{p(!1)}}return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(680px, 96vw)`,title:t?`Edit ${t.label}`:`Add Integration`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[g&&(0,l.jsx)(s.Button,{loading:f,onClick:y,children:`Test Connection`}),(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:u,onClick:v,children:`Save`})]}),children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,initialValues:JT,children:[(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`label`,label:`Integration Name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Background Check`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`integrationKey`,label:`Integration Key`,rules:[{required:!0},{pattern:/^[a-z][a-z0-9_-]{1,63}$/,message:`Use lowercase letters, numbers, _ or -`}],children:(0,l.jsx)(s.Input,{placeholder:`bgc`,disabled:!!t})})})]}),(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`category`,label:`Category`,children:(0,l.jsx)(s.Select,{options:[{value:`ONBOARDING`,label:`Onboarding`},{value:`HRMS`,label:`HRMS`},{value:`PAYROLL`,label:`Payroll`},{value:`ESIGNATURE`,label:`E-Signature`},{value:`VMS`,label:`VMS`},{value:`GENERAL`,label:`General / Custom`}]})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`enabled`,label:`Enabled`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{})})})]}),(0,l.jsx)(s.Form.Item,{name:`updateMethod`,label:`Update Method`,rules:[{required:!0}],children:(0,l.jsx)(s.Radio.Group,{optionType:`button`,buttonStyle:`solid`,options:[{label:`Manual Update`,value:`MANUAL`},{label:`API Integration`,value:`API`}]})}),!g&&(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`This integration will use manual updates.`}),g&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Alert,{type:t?.credentialsConfigured?`success`:`warning`,showIcon:!0,message:t?.credentialsConfigured?`Credentials configured`:`Credentials required`,description:`Secrets are write-only. Leave a secret blank while editing to keep its current value.`,style:{marginBottom:16}}),(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`provider`,label:`Provider`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Provider name`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`baseUrl`,label:`API Base URL`,rules:[{required:!0,type:`url`}],children:(0,l.jsx)(s.Input,{placeholder:`https://api.provider.com`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`createPath`,label:`Create/Submit Path`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`/v1/requests`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`statusPath`,label:`Status Path`,rules:[{required:!0}],tooltip:`Use {referenceId} as a placeholder.`,children:(0,l.jsx)(s.Input,{placeholder:`/v1/requests/{referenceId}`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`testPath`,label:`Test Connection Path`,rules:[{required:!0}],tooltip:`A safe GET endpoint used only to validate URL and credentials.`,children:(0,l.jsx)(s.Input,{placeholder:`/v1/health`})})})]}),(0,l.jsx)(s.Form.Item,{name:`authType`,label:`Authentication Type`,rules:[{required:!0}],children:(0,l.jsx)(s.Select,{options:YT})}),_?(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`clientId`,label:`Client ID`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`clientSecret`,label:`Client Secret`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.credentialsConfigured?`Unchanged`:`Required`})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{name:`tokenUrl`,label:`Token URL`,rules:[{required:!0,type:`url`}],children:(0,l.jsx)(s.Input,{})})})]}):(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`authHeader`,label:`Authentication Header`,children:(0,l.jsx)(s.Input,{placeholder:`x-api-key`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`authValue`,label:`API Credential`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.credentialsConfigured?`Unchanged`:`Required`})})})]}),(0,l.jsx)(s.Form.Item,{name:`webhookSecret`,label:`Webhook Signing Secret (optional)`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.webhookConfigured?`Unchanged`:``})}),(0,l.jsxs)(Z,{title:`Status Mapping`,children:[(0,l.jsx)(qT,{type:`secondary`,children:`Map a status from the provider response into a module field or a matching workflow stage.`}),(0,l.jsxs)(s.Row,{gutter:16,style:{marginTop:16},children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`targetModule`,label:`Target Module`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`onboarding`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`targetField`,label:`Target Field`,rules:[{required:!0}],tooltip:`Use stages for a stage-array update, or a direct field name.`,children:(0,l.jsx)(s.Input,{placeholder:`stages`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`providerStatusPath`,label:`Provider Status JSON Path`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`data.status`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`providerReferencePath`,label:`Provider Reference JSON Path`,children:(0,l.jsx)(s.Input,{placeholder:`data.id`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageMatchField`,label:`Stage Match Field`,children:(0,l.jsx)(s.Input,{placeholder:`stageCode`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageMatchValue`,label:`Stage Match Value`,children:(0,l.jsx)(s.Input,{placeholder:`BGC`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageStatusField`,label:`Stage Status Field`,children:(0,l.jsx)(s.Input,{placeholder:`status`})})})]}),(0,l.jsx)(qT,{strong:!0,children:`Status Values`}),(0,l.jsx)(s.Form.List,{name:`statusMappings`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(s.Space,{direction:`vertical`,style:{width:`100%`,marginTop:8},children:[e.map(e=>(0,l.jsxs)(s.Row,{gutter:12,children:[(0,l.jsx)(s.Col,{flex:`1 1 220px`,children:(0,l.jsx)(s.Form.Item,{...e,name:[e.name,`providerStatus`],rules:[{required:!0,message:`Provider status is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Provider status, e.g. completed`})})}),(0,l.jsx)(s.Col,{flex:`1 1 220px`,children:(0,l.jsx)(s.Form.Item,{...e,name:[e.name,`applicationStatus`],rules:[{required:!0,message:`Application status is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Zinnext status, e.g. CLEARED`})})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{danger:!0,onClick:()=>n(e.name),children:`Remove`})})]},e.key)),(0,l.jsx)(s.Button,{type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>t({providerStatus:``,applicationStatus:``}),children:`Add Status Mapping`})]})})]})]})]})})}function QT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),p=(0,o.useCallback)(()=>{i(!0),n.Mr().then(e=>t(Array.isArray(e)?e:[])).catch(e=>s.message.error(e?.message||`Could not load integrations`)).finally(()=>i(!1))},[]);(0,o.useEffect)(()=>{queueMicrotask(p)},[p]);async function m(e){try{await n.ar(e),s.message.success(`Integration deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete integration`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ApiOutlined,{}),title:`Integrations`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`Add Integration`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(qT,{type:`secondary`,children:`Configure reusable manual or API integrations for onboarding, payroll, e-signature, VMS, HRMS, and custom workflows.`})]}),(0,l.jsx)(Z,{title:`${e.length} integration${e.length===1?``:`s`}`,children:(0,l.jsx)(s.Table,{rowKey:`integrationKey`,columns:[{title:`Integration`,key:`name`,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell`,children:[(0,l.jsx)(qT,{strong:!0,children:t.label}),(0,l.jsx)(qT,{type:`secondary`,code:!0,children:t.integrationKey})]})},{title:`Category`,dataIndex:`category`,width:130,render:e=>e||`GENERAL`},{title:`Method`,dataIndex:`updateMethod`,width:110,render:e=>(0,l.jsx)(s.Tag,{color:e===`API`?`blue`:`default`,children:e})},{title:`Provider`,dataIndex:`provider`,render:e=>e||`—`},{title:`Enabled`,dataIndex:`enabled`,width:90,render:e=>(0,l.jsx)(s.Tag,{color:e?`green`:`default`,children:e?`Yes`:`No`})},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}}),(0,l.jsx)(s.Popconfirm,{title:`Delete this integration?`,onConfirm:()=>m(t.integrationKey),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:e,loading:r,size:`small`,className:`fg-table`})}),(0,l.jsx)(ZT,{open:a,integration:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}var{Text:$}=s.Typography;function $T({rows:e,onChange:t,keyPlaceholder:n,valuePlaceholder:r}){let i=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),a=n=>t(e.filter((e,t)=>t!==n));return(0,l.jsxs)(`div`,{children:[e.map((e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:6},children:[(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:n,value:e.key,onChange:e=>i(t,{key:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(`span`,{style:{color:`#94a3b8`,alignSelf:`center`},children:`→`}),(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:r,value:e.value,onChange:e=>i(t,{value:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>a(t)})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:6},onClick:()=>t([...e,{key:``,value:``}]),children:`Add`})]})}function eE({rows:e,onChange:t,keyPlaceholder:n=`field`,valuePlaceholder:r=`literal or {{field.path}}`}){let i=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),a=n=>t(e.filter((e,t)=>t!==n));return(0,l.jsxs)(`div`,{children:[e.map((e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:6},children:[(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:n,value:e.key,onChange:e=>i(t,{key:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Input,{size:`small`,style:{flex:1.6},placeholder:r,value:e.value,onChange:e=>i(t,{value:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>a(t)})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:6},onClick:()=>t([...e,{key:``,value:``}]),children:`Add`}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:11,display:`block`,marginTop:4},children:[`Values are read as JSON when possible (true, 123, ["a","b"]) — otherwise kept as literal text. Use `,(0,l.jsx)(`code`,{children:`{{field.path}}`}),` to reference a payload field, or `,(0,l.jsx)(`code`,{children:`{{now}}`}),` for the current time.`]})]})}function tE(e){return Object.entries(e??{}).map(([e,t])=>({key:e,value:String(t??``)}))}function nE(e){let t={};for(let n of e??[])n.key?.trim()&&(t[n.key.trim()]=n.value??``);return t}function rE(e){return Object.entries(e??{}).map(([e,t])=>({key:e,value:typeof t==`string`?t:JSON.stringify(t)}))}function iE(e){let t={};for(let n of e??[]){if(!n.key?.trim())continue;let e=n.value;if(typeof e==`string`){let t=e.trim();if(t!==``)try{e=JSON.parse(t)}catch{}}t[n.key.trim()]=e}return t}function aE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceModule:``,sourceIdField:``,required:!1,...t??{},fieldMapRows:tE(t?.fieldMap)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:640,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.DatabaseOutlined,{}),` `,t?`Edit Denormalize Rule`:`New Denormalize Rule`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceModule?.trim())return s.message.error(`Source module is required`);if(!i.sourceIdField?.trim())return s.message.error(`Source id field is required`);let{fieldMapRows:e,...t}=i;r({...t,fieldMap:nE(e)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source module`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`job`,value:i.sourceModule??``,onChange:e=>u(`sourceModule`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source id field (on THIS payload)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobId`,value:i.sourceIdField??``,onChange:e=>u(`sourceIdField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!i.required,onChange:e=>u(`required`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Required — block the write if the source record can't be found`})]}),(0,l.jsxs)(`div`,{style:{marginTop:16},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Field map (source field → this payload's field)`}),(0,l.jsx)($T,{rows:i.fieldMapRows??[],onChange:e=>u(`fieldMapRows`,e),keyPlaceholder:`jobTitle`,valuePlaceholder:`jobTitle`})]})]})})}function oE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceField:``,targetField:``,sourceCollection:``,idField:``,idOutputKey:``,stampNow:``,...t??{},fieldMapRows:tE(t?.fieldMap)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:640,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Array Enrichment`:`New Array Enrichment`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceField?.trim())return s.message.error(`Source field is required`);if(!i.targetField?.trim())return s.message.error(`Target field is required`);let{fieldMapRows:e,...t}=i;r({...t,fieldMap:nE(e)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source field (array of ids on this payload)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruitersData`,value:i.sourceField??``,onChange:e=>u(`sourceField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Target field (enriched array written here)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruiters`,value:i.targetField??``,onChange:e=>u(`targetField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source collection`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`users (default)`,value:i.sourceCollection??``,onChange:e=>u(`sourceCollection`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Id field on that collection`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`legacyUserId (default)`,value:i.idField??``,onChange:e=>u(`idField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:16},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Field map (source collection field → output key)`}),(0,l.jsx)($T,{rows:i.fieldMapRows??[],onChange:e=>u(`fieldMapRows`,e),keyPlaceholder:`firstName`,valuePlaceholder:`recruiterName`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Also write the matched id as`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruiterId`,value:i.idOutputKey??``,onChange:e=>u(`idOutputKey`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Also stamp the current time as`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`assignedDateTime`,value:i.stampNow??``,onChange:e=>u(`stampNow`,e.target.value),className:`fg-mono-input`})]})]})]})})}function sE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceField:``,targetField:``,uploadedFileNameField:``,uniqueNameField:``,uploadedAtField:``,uploadedByField:``,arrayMode:!1,nameFromField:``,nameOutputField:``,historyField:``,historySnapshotKey:``,historyReason:``,...t??{},staticFieldRows:tE(t?.staticFields),arrayFieldNameRows:tE(t?.arrayFieldNames)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:760,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.DatabaseOutlined,{}),` `,t?`Edit File Field Map`:`New File Field Map`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceField?.trim())return s.message.error(`Source field (the multipart upload key) is required`);if(!i.targetField?.trim())return s.message.error(`Target field is required`);let{staticFieldRows:e,arrayFieldNameRows:t,...n}=i;r({...n,staticFields:nE(e),arrayFieldNames:nE(t)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Turns one uploaded file field into a nested object (or array of objects) instead of a flat S3 path string — for schemas like a candidate's resume/passport/visa that store location + filename + who/when as sub-fields.`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source field (multipart upload key)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume`,value:i.sourceField??``,onChange:e=>u(`sourceField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12},children:[`Target field `,i.arrayMode?`(array)`:`(location sub-field)`]}),(0,l.jsx)(s.Input,{size:`small`,placeholder:i.arrayMode?`documents`:`resume.location`,value:i.targetField??``,onChange:e=>u(`targetField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!i.arrayMode,onChange:e=>u(`arrayMode`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Array mode — every uploaded file becomes one element (e.g. "documents")`})]}),i.arrayMode?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Sub-field names (location / uploadedFileName / uniqueName → this schema's names)`}),(0,l.jsx)($T,{rows:i.arrayFieldNameRows??[],onChange:e=>u(`arrayFieldNameRows`,e),keyPlaceholder:`location`,valuePlaceholder:`documentCopyLocation`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Take each element's display name from (payload array field)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documents`,value:i.nameFromField??``,onChange:e=>u(`nameFromField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...reading its field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documentName`,value:i.nameOutputField??``,onChange:e=>u(`nameOutputField`,e.target.value),className:`fg-mono-input`})]})]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Original filename field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedFileName`,value:i.uploadedFileNameField??``,onChange:e=>u(`uploadedFileNameField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Unique name field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uniqueName`,value:i.uniqueNameField??``,onChange:e=>u(`uniqueNameField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Uploaded-at field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedAt`,value:i.uploadedAtField??``,onChange:e=>u(`uploadedAtField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Uploaded-by field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedBy`,value:i.uploadedByField??``,onChange:e=>u(`uploadedByField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Static fields (literal value written alongside the upload)`}),(0,l.jsx)($T,{rows:i.staticFieldRows??[],onChange:e=>u(`staticFieldRows`,e),keyPlaceholder:`resume.source`,valuePlaceholder:`candidate`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Append a snapshot to (history array field)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resumeHistory`,value:i.historyField??``,onChange:e=>u(`historyField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...under snapshot key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume`,value:i.historySnapshotKey??``,onChange:e=>u(`historySnapshotKey`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...with reason`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`Initial resume upload`,value:i.historyReason??``,onChange:e=>u(`historyReason`,e.target.value),className:`fg-mono-input`})]})]})]})]})})}function cE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({name:``,seedField:``,direction:`up`,stopRole:0,includeSeed:!0,...t??{}})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:620,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Hierarchy Expansion`:`New Hierarchy Expansion`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.name?.trim())return s.message.error(`Name is required — this is how RelatedUpdates/Notify reference the result`);if(!/^[a-zA-Z0-9_]+$/.test(i.name))return s.message.error(`Name: letters, numbers, underscores only`);r(i)},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Name`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`chain`,value:i.name??``,onChange:e=>u(`name`,e.target.value),className:`fg-mono-input`}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:11},children:[`Referenced as `,(0,l.jsx)(`code`,{children:`{{hierarchy.`+(i.name||`name`)+`}}`})]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Seed field (blank = the caller)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruitersData`,value:i.seedField??``,onChange:e=>u(`seedField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Direction`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:i.direction||`up`,onChange:e=>u(`direction`,e),options:[{value:`up`,label:`Up — toward admin (reporting chain)`},{value:`down`,label:`Down — toward subordinates (team)`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Stop at role id (up only, 0 = walk to the top)`}),(0,l.jsx)(s.InputNumber,{size:`small`,style:{width:`100%`},min:0,value:i.stopRole??0,onChange:e=>u(`stopRole`,e??0),disabled:i.direction!==`up`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:i.includeSeed!==!1,onChange:e=>u(`includeSeed`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Include the seed user(s) themselves in the result`})]})]})})}function lE({open:e,rule:t,hierarchyNames:n,onClose:r,onSave:i}){let[a,u]=(0,o.useState)(()=>({collectionName:``,targetModule:``,matchField:``,scopeTenant:!1,forEach:``,insertMode:!!(t?.insertIfMissing&&Object.keys(t.insertIfMissing).length),...t??{},extraFilterRows:rE(t?.extraFilter),pullRows:rE(t?.pull),pushRows:rE(t?.push),setRows:rE(t?.set),setIfNonBlankRows:rE(t?.setIfNonBlank),insertIfMissingRows:rE(t?.insertIfMissing)})),d=(e,t)=>u(n=>({...n,[e]:t})),f=()=>{if(!a.collectionName?.trim()&&!a.targetModule?.trim())return s.message.error(`Set either a collection name or a target module`);let{extraFilterRows:e,pullRows:t,pushRows:n,setRows:r,setIfNonBlankRows:o,insertIfMissingRows:c,insertMode:l,...u}=a;i({...u,extraFilter:iE(e),pull:l?{}:iE(t),push:l?{}:iE(n),set:l?{}:iE(r),setIfNonBlank:l?{}:iE(o),insertIfMissing:l?iE(c):{}})},p=(n??[]).map(e=>({value:`hierarchy.${e}`,label:`{{hierarchy.${e}}}`}));return(0,l.jsx)(s.Modal,{open:e,onCancel:r,width:820,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` `,t?`Edit Related Update`:`New Related Update`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:f,children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsx)(`div`,{className:`fg-form-section-label`,children:`Target`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Collection name (used verbatim)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`hiringProgress`,value:a.collectionName??``,onChange:e=>d(`collectionName`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`— or — target module`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`job`,value:a.targetModule??``,onChange:e=>d(`targetModule`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Match field (this payload's field holding the target _id)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobId (blank for a tenant-scoped board)`,value:a.matchField??``,onChange:e=>d(`matchField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Repeat once per element of (ForEach)`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},allowClear:!0,showSearch:!0,placeholder:`e.g. {{hierarchy.chain}}`,value:a.forEach||void 0,onChange:e=>d(`forEach`,e??``),options:p})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!a.scopeTenant,onChange:e=>d(`scopeTenant`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Scope filter to the caller's tenant/business/businessUnit`})]}),(0,l.jsxs)(`div`,{style:{marginTop:14},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Extra filter (merged into the match filter)`}),(0,l.jsx)(eE,{rows:a.extraFilterRows??[],onChange:e=>d(`extraFilterRows`,e),keyPlaceholder:`recruiterId`,valuePlaceholder:`{"$in":"{{hierarchy.chain}}"}`})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:18},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!a.insertMode,onChange:e=>d(`insertMode`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Insert-only-if-missing (seed a new document instead of updating an existing one)`})]}),a.insertMode?(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Document to insert when the filter matches nothing`}),(0,l.jsx)(eE,{rows:a.insertIfMissingRows??[],onChange:e=>d(`insertIfMissingRows`,e),keyPlaceholder:`hiringProgressJobStatus`,valuePlaceholder:`"unread"`})]}):(0,l.jsx)(s.Tabs,{size:`small`,style:{marginTop:10},items:[{key:`pull`,label:`Pull`,children:(0,l.jsx)(eE,{rows:a.pullRows??[],onChange:e=>d(`pullRows`,e),keyPlaceholder:`submitted`,valuePlaceholder:`{"candidateId":"{{applicantId}}"}`})},{key:`push`,label:`Push`,children:(0,l.jsx)(eE,{rows:a.pushRows??[],onChange:e=>d(`pushRows`,e),keyPlaceholder:`submitted`,valuePlaceholder:`{"status":"{{submissionStatus}}"}`})},{key:`set`,label:`Set`,children:(0,l.jsx)(eE,{rows:a.setRows??[],onChange:e=>d(`setRows`,e),keyPlaceholder:`hiringProgressJobStatus`,valuePlaceholder:`"unread"`})},{key:`setIfNonBlank`,label:`Set if non-blank`,children:(0,l.jsx)(eE,{rows:a.setIfNonBlankRows??[],onChange:e=>d(`setIfNonBlankRows`,e),keyPlaceholder:`resume.location`,valuePlaceholder:`{{resume.location}}`})}]})]})})}function uE({icon:e,title:t,description:n,rules:r,columns:i,onAdd:a,onEdit:o,onDelete:u}){return(0,l.jsxs)(Z,{title:(0,l.jsxs)(`span`,{children:[e,` `,t]}),extra:(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:a,children:`Add`}),styles:{body:{paddingTop:8}},children:[n&&(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:n}),(0,l.jsx)(s.Table,{rowKey:(e,t)=>t,dataSource:r,columns:[...i,{title:``,key:`actions`,width:80,align:`right`,render:(e,t,n)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>o(n,t)})}),(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>u(n)})})]})}],pagination:!1,size:`small`,className:`fg-table`,locale:{emptyText:(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`Not configured`})}})]})}var dE={sequence:null,duplicateCheck:null,fileVersioning:null,denormalizations:[],arrayEnrichments:[],fileFieldMaps:[],sanitizeFields:[],defaults:{},hierarchyExpands:[],relatedUpdates:[],notify:null,cacheInvalidate:[]};function fE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(``),[d,f]=(0,o.useState)({storage:`mongo`}),[p,m]=(0,o.useState)(`mongo`),[h,g]=(0,o.useState)(dE),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)(null),[T,E]=(0,o.useState)(null),[D,O]=(0,o.useState)(null),[k,A]=(0,o.useState)(null),[j,M]=(0,o.useState)(null);(0,o.useEffect)(()=>{n.Sr().then(e=>{let n=hS(e).map(({value:e,label:t})=>({key:e,label:t}));t(n),n.length&&u(n[0].key)}).catch(()=>t([])).finally(()=>i(!1))},[]),(0,o.useEffect)(()=>{if(!a)return;let e=!1;return(async()=>{v(!0),S(``);try{let t=await n.zr(a);if(e)return;let r=t.gateway??{storage:`mongo`};f(r),m(r.storage||`mongo`),g({...dE,...t.strategies??{}})}catch(t){e||S(t?.message||`Failed to load automations`)}finally{e||v(!1)}})(),()=>{e=!0}},[a]);let N=(0,o.useMemo)(()=>(h.hierarchyExpands??[]).map(e=>e.name).filter(Boolean),[h.hierarchyExpands]);function P(e,t){g(n=>({...n,[e]:t}))}function F(e,t){g(n=>{let r=n.duplicateCheck??{},i=[...r.stages??[]];return i[e]=t,{...n,duplicateCheck:{...r,stages:i}}})}function I(){b(!0);let e={...h,denormalizations:h.denormalizations?.length?h.denormalizations:void 0,arrayEnrichments:h.arrayEnrichments?.length?h.arrayEnrichments:void 0,fileFieldMaps:h.fileFieldMaps?.length?h.fileFieldMaps:void 0,sanitizeFields:h.sanitizeFields?.length?h.sanitizeFields:void 0,hierarchyExpands:h.hierarchyExpands?.length?h.hierarchyExpands:void 0,relatedUpdates:h.relatedUpdates?.length?h.relatedUpdates:void 0,cacheInvalidate:h.cacheInvalidate?.length?h.cacheInvalidate:void 0,defaults:Object.keys(h.defaults??{}).length?h.defaults:void 0};n.ci(a,{gateway:d,strategies:e}).then(()=>{m(d.storage||`mongo`),s.message.success(`Automations saved`)}).catch(e=>s.message.error(e?.message||`Could not save automations`)).finally(()=>b(!1))}function L(){if((d.storage||`mongo`)!==p){s.Modal.confirm({title:`Change how this module persists writes?`,content:`You're switching ${a} from "${p}" to "${d.storage}". `+(d.storage===`mongo`?`This module will stop calling its downstream service and this gateway will own the write + every Strategy below.`:`This module will stop using the Strategies below and go back to calling its downstream service.`)+` Make sure the downstream service / e2e checks are ready before confirming.`,okText:`Confirm cutover`,okButtonProps:{danger:!0},onOk:I});return}I()}let R=[{title:`Source module`,dataIndex:`sourceModule`,key:`sourceModule`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Source id field`,dataIndex:`sourceIdField`,key:`sourceIdField`},{title:`Fields`,key:`fields`,render:(e,t)=>(0,l.jsx)(s.Badge,{count:Object.keys(t.fieldMap??{}).length,showZero:!0,color:`var(--color-brand)`})},{title:`Required`,dataIndex:`required`,key:`required`,width:90,render:e=>e?(0,l.jsx)(s.Tag,{color:`volcano`,children:`Required`}):(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`optional`})}],z=[{title:`Source field`,dataIndex:`sourceField`,key:`sourceField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Target field`,dataIndex:`targetField`,key:`targetField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`From collection`,key:`coll`,render:(e,t)=>t.sourceCollection||`users`},{title:`Fields`,key:`fields`,render:(e,t)=>(0,l.jsx)(s.Badge,{count:Object.keys(t.fieldMap??{}).length,showZero:!0,color:`var(--color-brand)`})}],B=[{title:`Source field`,dataIndex:`sourceField`,key:`sourceField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Target field`,dataIndex:`targetField`,key:`targetField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Mode`,dataIndex:`arrayMode`,key:`arrayMode`,width:100,render:e=>e?(0,l.jsx)(s.Tag,{color:`blue`,children:`Array`}):(0,l.jsx)(s.Tag,{children:`Single`})},{title:`History`,dataIndex:`historyField`,key:`historyField`,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`—`})}],V=[{title:`Name`,dataIndex:`name`,key:`name`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:`{{hierarchy.`+e+`}}`})},{title:`Seed field`,dataIndex:`seedField`,key:`seedField`,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`caller`})},{title:`Direction`,dataIndex:`direction`,key:`direction`,render:e=>(0,l.jsx)(s.Tag,{color:e===`down`?`blue`:`purple`,children:e===`down`?`Down — team`:`Up — chain`})},{title:`Stop role`,dataIndex:`stopRole`,key:`stopRole`,width:90,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`top`})}],H=[{title:`Target`,key:`target`,render:(e,t)=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:t.collectionName||t.targetModule})},{title:`Match`,key:`match`,render:(e,t)=>t.matchField||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`tenant-scoped`})},{title:`For each`,key:`forEach`,render:(e,t)=>t.forEach?(0,l.jsx)(s.Tag,{color:`geekblue`,children:`{{${t.forEach}}}`}):(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`once`})},{title:`Mode`,key:`mode`,render:(e,t)=>Object.keys(t.insertIfMissing??{}).length?(0,l.jsx)(s.Tag,{color:`green`,children:`Insert if missing`}):(0,l.jsx)(s.Tag,{children:`Update`})}],ee=e.map(e=>({key:e.key,label:e.label}));return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`Automations`,extra:(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:y,disabled:!a,onClick:L,children:`Save Automations`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)($,{type:`secondary`,style:{fontSize:13},children:`Config-driven side-effects the common CRUD gateway runs around a create — reference ids, duplicate checks, cross-module field snapshots, reporting-chain hierarchy expansion, board updates, notifications, cache invalidation. Nothing here is module-specific: the same engine serves every module.`})]}),(0,l.jsx)(Z,{styles:{body:{paddingTop:8}},children:(0,l.jsxs)(s.Spin,{spinning:r,children:[(0,l.jsx)(s.Tabs,{activeKey:a,onChange:u,items:ee.map(e=>({...e,children:null})),className:`admin-module-tabs`}),x&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:x,style:{marginBottom:12}}),(0,l.jsxs)(s.Spin,{spinning:_,children:[(0,l.jsxs)(Z,{title:`Gateway`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Selects how a write to this module persists. "Proxy" forwards to a downstream microservice (which owns every side-effect below itself). "Mongo" makes THIS gateway own the write and run every Strategy configured below.`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Storage`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:d.storage||`mongo`,onChange:e=>f(t=>({...t,storage:e})),options:[{value:`mongo`,label:`Mongo — this gateway owns the write`},{value:`proxy`,label:`Proxy — forward to a downstream service`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`File field key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`file`,value:d.fileKey??``,onChange:e=>f(t=>({...t,fileKey:e.target.value})),className:`fg-mono-input`})]})]}),d.storage===`proxy`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Base URL env var`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`JOBS_SERVICE_URL`,value:d.baseUrlEnv??``,onChange:e=>f(t=>({...t,baseUrlEnv:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Base URL (fallback)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`http://...`,value:d.baseUrl??``,onChange:e=>f(t=>({...t,baseUrl:e.target.value})),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Create path`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`/v1/jobs`,value:d.createPath??``,onChange:e=>f(t=>({...t,createPath:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Update path (%s = id)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`/v1/edit/%s`,value:d.updatePath??``,onChange:e=>f(t=>({...t,updatePath:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Update method`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:d.updateMethod||`PUT`,onChange:e=>f(t=>({...t,updateMethod:e})),options:[`PUT`,`POST`,`PATCH`].map(e=>({value:e,label:e}))})]})]})]})]}),(0,l.jsxs)(Z,{title:`Reference ID (Sequence)`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.sequence,onChange:e=>P(`sequence`,e?{field:``,prefix:``,counterKey:``}:null)}),(0,l.jsxs)($,{style:{fontSize:13},children:[`Generate a "`,`{prefix}{n}`,`" reference id on create`]})]}),h.sequence&&(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Payload field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`submissionId`,value:h.sequence.field??``,onChange:e=>P(`sequence`,{...h.sequence,field:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Prefix`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`sub`,value:h.sequence.prefix??``,onChange:e=>P(`sequence`,{...h.sequence,prefix:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Counter key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`submissions`,value:h.sequence.counterKey??``,onChange:e=>P(`sequence`,{...h.sequence,counterKey:e.target.value}),className:`fg-mono-input`})]})]})]}),(0,l.jsxs)(Z,{title:`Check for someone already on file`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Before a new record is saved, look for one that already matches. This is what stops the same person being added twice under slightly different details.`}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.duplicateCheck,onChange:e=>P(`duplicateCheck`,e?{stages:[],policy:`prompt`,displayFields:[],message:``}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Check before saving a new record`})]}),h.duplicateCheck&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:6},children:[(0,l.jsx)(`b`,{children:`Checks run in order, top first, and stop at the first match.`}),` Put your most certain check first — matching an email or a phone number is near proof; matching a name alone is only a maybe, so it belongs lower down.`]}),(h.duplicateCheck.stages??[]).map((e,t)=>(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginBottom:8,alignItems:`flex-end`},children:[(0,l.jsxs)(`div`,{style:{flex:1.6},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12},children:[`Check `,t+1,` — compare these`]}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`email, contactNumber`,value:e.fields??[],onChange:n=>F(t,{...e,fields:n})})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Counts as a match when`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:e.match??`all`,onChange:n=>F(t,{...e,match:n}),options:[{value:`any`,label:`Any one of them matches`},{value:`all`,label:`All of them match`}]})]}),(0,l.jsxs)(`div`,{style:{flex:.8},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`How sure is it?`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:e.weight??`strong`,onChange:n=>F(t,{...e,weight:n}),options:[{value:`strong`,label:`Almost certainly the same`},{value:`weak`,label:`Possibly the same`}]})]}),(0,l.jsxs)(`div`,{style:{flex:2},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`What to tell the user`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`A candidate with this email already exists — {name}, last updated {age}.`,value:e.message??``,onChange:n=>F(t,{...e,message:n.target.value})})]}),(0,l.jsx)(s.Button,{size:`small`,danger:!0,type:`text`,onClick:()=>P(`duplicateCheck`,{...h.duplicateCheck,stages:(h.duplicateCheck.stages??[]).filter((e,n)=>n!==t)}),children:`Remove`})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,style:{marginBottom:12},onClick:()=>P(`duplicateCheck`,{...h.duplicateCheck,stages:[...h.duplicateCheck.stages??[],{fields:[],match:`any`,weight:`strong`}]}),children:`Add another check`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`When a match is found`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:h.duplicateCheck.policy??`prompt`,onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,policy:e}),options:[{value:`prompt`,label:`Ask, and offer to update the existing one`},{value:`block`,label:`Refuse to save, and name the existing one`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1.2},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Which details identify the record`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`firstName, lastName, email`,value:h.duplicateCheck.displayFields??[],onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,displayFields:e})})]})]}),(0,l.jsx)(`div`,{className:`fg-field-meta-row`,style:{marginTop:10},children:(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Where to open the existing record`}),(0,l.jsx)(s.Input,{size:`small`,className:`fg-mono-input`,placeholder:`/candidate/edit/:id`,value:h.duplicateCheck.editRoute??``,onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,editRoute:e.target.value})})]})}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:[`The page that opens when someone chooses to update the record you already have. Use `,(0,l.jsx)(`b`,{children:`:id`}),` where the record's id goes. This has to be filled in — it cannot be worked out, because addresses follow no single pattern (this app uses `,(0,l.jsx)(`code`,{children:`/candidate/edit/:id`}),` but `,(0,l.jsx)(`code`,{children:`/clients/edit/:id`}),`). Left blank, the dialog still appears and simply does not navigate, rather than sending anyone to a page that does not exist.`]}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:8},children:[`In any message you can use `,(0,l.jsx)(`b`,{children:`{name}`}),` for the matched record and`,(0,l.jsxs)(`b`,{children:[` `,`{age}`]}),` for how long ago it was last touched ("about 2 months ago"). `,(0,l.jsx)(`b`,{children:`{updatedOn}`}),` gives the date instead. Only the details listed above are shown — nothing else about the record is revealed.`]})]})]}),(0,l.jsxs)(Z,{title:`Keep previous versions of an uploaded file`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Normally a new upload replaces the old one and it is gone. Turn this on and the last few are kept instead — useful when someone sends an updated CV and you may want to look back at the earlier one. Everywhere in the app still shows the newest; the older ones sit behind it.`}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.fileVersioning,onChange:e=>P(`fileVersioning`,e?{fields:[],keep:2,historyKey:``,s3Prefix:``,deleteEvicted:!1}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Keep previous uploads`})]}),h.fileVersioning&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginBottom:10},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`},children:`Where the older versions are kept`}),(0,l.jsxs)(s.Radio.Group,{size:`small`,value:h.fileVersioning.store===`documents`?`documents`:`record`,onChange:e=>{let t=e.target.value,n={...h.fileVersioning,store:t===`documents`?`documents`:``};t===`documents`&&(n.linkField=n.linkField||`documentIds`,n.clearRecordKeys=n.clearRecordKeys?.length?n.clearRecordKeys:(n.fields??[]).flatMap(e=>[`${e}History`,`${e}Versions`])),P(`fileVersioning`,n)},children:[(0,l.jsx)(s.Radio,{value:`documents`,children:`In Documents (recommended)`}),(0,l.jsx)(s.Radio,{value:`record`,children:`On the record itself`})]}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:[(0,l.jsx)(`b`,{children:`In Documents`}),` keeps the file and all its earlier versions in one place, the same place every other document lives. The record just points at it — so when a candidate is submitted for a job, the submission shows the very same file, and replacing it updates both at once. `,(0,l.jsx)(`b`,{children:`On the record itself`}),` is the older way: each record keeps its own copy of the history, which is why the same résumé could end up recorded several times over and the copies could disagree.`]})]}),h.fileVersioning.store===`documents`&&(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginBottom:10},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`List of attached documents is kept in`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documentIds`,value:h.fileVersioning.linkField??``,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,linkField:e.target.value})})]}),(0,l.jsxs)(`div`,{style:{flex:1.6},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Old history fields to clear off the record`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`resumeHistory`,value:h.fileVersioning.clearRecordKeys??[],onChange:e=>P(`fileVersioning`,{...h.fileVersioning,clearRecordKeys:e})})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1.4},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Which uploads`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`resume`,value:h.fileVersioning.fields??[],onChange:e=>P(`fileVersioning`,{...h.fileVersioning,fields:e})})]}),(0,l.jsxs)(`div`,{style:{flex:.7},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`How many to keep`}),(0,l.jsx)(s.Input,{size:`small`,type:`number`,min:1,value:h.fileVersioning.keep??2,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,keep:Number(e.target.value)||1})})]}),(0,l.jsxs)(`div`,{style:{flex:1.4},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Where the files are grouped`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`candidates/{recordId}/resume`,value:h.fileVersioning.s3Prefix??``,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,s3Prefix:e.target.value})})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.fileVersioning.deleteEvicted,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,deleteEvicted:e})}),(0,l.jsx)($,{style:{fontSize:13},children:`Also delete the file once it drops off the end`})]}),(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:`Leave that switch OFF unless you are sure. With it off, an older file simply stops being shown and can still be recovered. With it on, it is deleted from storage permanently and cannot be brought back. Keeping 2 means a third upload pushes the first one off the end.`})]})]}),(0,l.jsx)(uE,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Denormalizations`,description:`Copy fields from ANOTHER module's record onto this payload before insert (e.g. a submission snapshotting job title/client).`,rules:h.denormalizations??[],columns:R,onAdd:()=>w({index:null,rule:null}),onEdit:(e,t)=>w({index:e,rule:t}),onDelete:e=>P(`denormalizations`,(h.denormalizations??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(uE,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Array Enrichments`,description:`Enrich a payload array of ids (e.g. recruitersData) into objects carrying looked-up fields (name, email) before insert.`,rules:h.arrayEnrichments??[],columns:z,onAdd:()=>E({index:null,rule:null}),onEdit:(e,t)=>E({index:e,rule:t}),onDelete:e=>P(`arrayEnrichments`,(h.arrayEnrichments??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(uE,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`File Field Maps`,description:`Turn an uploaded file field into a nested object (location + filename + who/when) or an array of such objects, instead of a flat S3 path string — needed for schemas like resume/passport/visa.`,rules:h.fileFieldMaps??[],columns:B,onAdd:()=>O({index:null,rule:null}),onEdit:(e,t)=>O({index:e,rule:t}),onDelete:e=>P(`fileFieldMaps`,(h.fileFieldMaps??[]).filter((t,n)=>n!==e))}),(0,l.jsxs)(Z,{title:`Sanitize Fields`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:`Trim and HTML-escape these payload fields before anything else runs — basic XSS-safety for free-text fields (e.g. firstName/lastName) that might later be embedded in an HTML activity comment or email.`}),(0,l.jsx)(s.Select,{mode:`tags`,style:{width:`100%`},placeholder:`firstName, lastName, email`,value:h.sanitizeFields??[],onChange:e=>P(`sanitizeFields`,e)})]}),(0,l.jsxs)(Z,{title:`Defaults`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:`Set a field only when the payload doesn't already carry a non-blank value — status defaults, empty arrays.`}),(0,l.jsx)(eE,{rows:rE(h.defaults),onChange:e=>P(`defaults`,iE(e)),keyPlaceholder:`internalSubmissionStatus.internalSubmissionStatusText`,valuePlaceholder:`"Under Evaluation"`})]}),(0,l.jsx)(uE,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Hierarchy Expansions`,description:`Walk the reporting chain up (toward admin) or down (toward a team) from a seed user, publishing the result as {{hierarchy.<name>}} for Related Updates / Notify to use.`,rules:h.hierarchyExpands??[],columns:V,onAdd:()=>A({index:null,rule:null}),onEdit:(e,t)=>A({index:e,rule:t}),onDelete:e=>P(`hierarchyExpands`,(h.hierarchyExpands??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(uE,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`Related Updates`,description:`Best-effort side-effect writes to other collections after a successful insert — board state, activity logs. Combine with ForEach + a Hierarchy Expansion to seed one document per user in a chain.`,rules:h.relatedUpdates??[],columns:H,onAdd:()=>M({index:null,rule:null}),onEdit:(e,t)=>M({index:e,rule:t}),onDelete:e=>P(`relatedUpdates`,(h.relatedUpdates??[]).filter((t,n)=>n!==e))}),(0,l.jsxs)(Z,{title:`Notify`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.notify,onChange:e=>P(`notify`,e?{action:``,subjectDefault:``,bodyDefault:``,toReportingManager:!1,toHierarchy:``}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Send a best-effort email after a successful insert`})]}),h.notify&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Action (matched against an EmailTemplates doc)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`internalSubmit`,value:h.notify.action??``,onChange:e=>P(`notify`,{...h.notify,action:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Notify entire hierarchy chain`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},allowClear:!0,placeholder:`pick a Hierarchy Expansion`,value:h.notify.toHierarchy||void 0,onChange:e=>P(`notify`,{...h.notify,toHierarchy:e??``}),options:N.map(e=>({value:e,label:e}))})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:12},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.notify.toReportingManager,onChange:e=>P(`notify`,{...h.notify,toReportingManager:e})}),(0,l.jsx)($,{style:{fontSize:13},children:`Also notify the caller's direct reporting manager`})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Default subject`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`New submission`,value:h.notify.subjectDefault??``,onChange:e=>P(`notify`,{...h.notify,subjectDefault:e.target.value})})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Default body (used when no EmailTemplates doc matches)`}),(0,l.jsx)(s.Input.TextArea,{rows:4,value:h.notify.bodyDefault??``,onChange:e=>P(`notify`,{...h.notify,bodyDefault:e.target.value}),className:`fg-mono-input`})]})]})]}),(0,l.jsxs)(Z,{title:`Cache Invalidate`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:[`Redis key patterns (with `,`{{field}}`,` tokens) to SCAN+DEL after a successful insert.`]}),(0,l.jsx)(s.Select,{mode:`tags`,style:{width:`100%`},placeholder:`jobs:{{tenantId}}:{{businessId}}:{{businessUnitId}}:*`,value:h.cacheInvalidate??[],onChange:e=>P(`cacheInvalidate`,e)})]})]})]})}),(0,l.jsx)(aE,{open:!!C,rule:C?.rule,onClose:()=>w(null),onSave:e=>{P(`denormalizations`,C.index===null?[...h.denormalizations??[],e]:(h.denormalizations??[]).map((t,n)=>n===C.index?e:t)),w(null)}},C?`denorm-${C.index??`new`}`:`denorm-closed`),(0,l.jsx)(oE,{open:!!T,rule:T?.rule,onClose:()=>E(null),onSave:e=>{P(`arrayEnrichments`,T.index===null?[...h.arrayEnrichments??[],e]:(h.arrayEnrichments??[]).map((t,n)=>n===T.index?e:t)),E(null)}},T?`enrich-${T.index??`new`}`:`enrich-closed`),(0,l.jsx)(sE,{open:!!D,rule:D?.rule,onClose:()=>O(null),onSave:e=>{P(`fileFieldMaps`,D.index===null?[...h.fileFieldMaps??[],e]:(h.fileFieldMaps??[]).map((t,n)=>n===D.index?e:t)),O(null)}},D?`filemap-${D.index??`new`}`:`filemap-closed`),(0,l.jsx)(cE,{open:!!k,rule:k?.rule,onClose:()=>A(null),onSave:e=>{P(`hierarchyExpands`,k.index===null?[...h.hierarchyExpands??[],e]:(h.hierarchyExpands??[]).map((t,n)=>n===k.index?e:t)),A(null)}},k?`hier-${k.index??`new`}`:`hier-closed`),(0,l.jsx)(lE,{open:!!j,rule:j?.rule,hierarchyNames:N,onClose:()=>M(null),onSave:e=>{P(`relatedUpdates`,j.index===null?[...h.relatedUpdates??[],e]:(h.relatedUpdates??[]).map((t,n)=>n===j.index?e:t)),M(null)}},j?`ru-${j.index??`new`}`:`ru-closed`)]})}var{Text:pE}=s.Typography,mE=[`beforeCreate`,`afterCreate`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`],hE=[`sanitizeFields`,`generateSequence`,`duplicateCheck`,`copyFields`,`arrayEnrich`,`setDefaults`,`resolve`,`updateRelated`,`notify`,`invalidateCache`,`webhook`,`linkDocuments`,`captureFileUrls`,`resolveUploads`],gE={resolveUploads:{text:`Turn one submit into a list with ONE ENTRY PER UPLOADED FILE, so the actions after it can create one record per document instead of a single record holding all of them. Works for both shapes: a repeatable (Add Row) group gives one entry per row — carrying that row’s own values — and a multi-file upload field gives one entry per file. Publishes {{uploads.<as>}} (all entries), {{uploads.<as>First}} (the first, as an object) and {{uploads.<as>Rest}} (all but the first). Each entry has groupName, groupLabel, groupModule, fieldName, rowIndex, fileName, uniqueName, contentType, fileSize, s3Key, tenantId/businessId/businessUnitId, the row under "row", and the row’s own values at the top level. Leave "groups" empty for every group with an upload field. Set "heading" to "label" to use the group heading text instead of its name — note the heading changes whenever an admin renames the group, while the name does not.`,sample:{as:`docs`,groups:[],includeEmptyRows:!1,heading:`name`}},updateRelated:{text:`Update this record or another configured collection with values from the event. For uploaded files, after* workflows can read {{__uploads.<field>.fieldName|fileName|contentType|fileSize|s3Key|uniqueName}}. Add a $notEmpty condition on the upload s3Key so unrelated edits do not run it. To create one record PER FILE, run resolveUploads first, then set forEach to "uploads.<as>Rest" with insertIfMissing (an extraFilter on {{forEach.value.s3Key}} keeps a re-save from inserting duplicates). "unset" removes exact fields and "unsetPrefixes" removes a repeatable upload’s generated keys (document[0], document[1], …) in the SAME write — use it on the record being reused as the first row, and put that action LAST with Stop on error enabled so nothing is cleared when the inserts failed.`,sample:{targetModule:`documents`,matchField:`_id`,scopeTenant:!0,set:{module:`{{module}}`,moduleRefId:`{{_id}}`,fieldName:`{{__uploads.docPan.fieldName}}`,fileName:`{{__uploads.docPan.fileName}}`,contentType:`{{__uploads.docPan.contentType}}`,fileSize:`{{__uploads.docPan.fileSize}}`,s3Key:`{{__uploads.docPan.s3Key}}`,uniqueName:`{{__uploads.docPan.uniqueName}}`}}},linkDocuments:{text:`Share one record’s uploaded files with another, without making a second copy. Used so a submission shows the candidate’s résumé and paperwork, and anything uploaded during the submission appears on the candidate too. Both records get the list of document ids written onto them.`,sample:{sourceModule:`candidates`,sourceIdField:`applicantId`,targetModule:`submissions`,linkField:`documentIds`,fieldNames:[],backLink:!0}},captureFileUrls:{text:`File a document that was generated elsewhere and handed to us as a link — a formatted résumé or an attestation PDF — so it sits with every other attachment instead of being a loose field on the record.`,sample:{linkField:`documentIds`,files:[{urlField:`resumeUrl`,nameField:`resumeFileName`,fieldName:`formattedResume`,defaultName:`Formatted Resume.pdf`},{urlField:`attestationUrl`,nameField:`attestationFileName`,fieldName:`attestation`,defaultName:`Attestation.pdf`}]}}};function _E(e){return JSON.stringify(e??{},null,2)}function vE({action:e,onChange:t,onRemove:n}){let[r,i]=(0,o.useState)(()=>_E(e.config)),[a,u]=(0,o.useState)(!1);return(0,l.jsxs)(`div`,{style:{border:`1px solid #e2e8f0`,borderRadius:8,padding:10,marginTop:8},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`},children:[(0,l.jsx)(s.Select,{size:`small`,style:{width:200},showSearch:!0,value:e.type||void 0,placeholder:`action type`,options:hE.map(e=>({value:e})),onChange:n=>{let r=e.config&&Object.keys(e.config).length>0,i=gE[n]?.sample;t(r||!i?{...e,type:n}:{...e,type:n,config:i})}}),a&&(0,l.jsx)(s.Tag,{color:`red`,children:`invalid JSON`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),style:{marginLeft:`auto`},onClick:n})]}),gE[e.type]&&(0,l.jsx)(`p`,{style:{margin:`8px 0 0`,fontSize:12,color:`#64748b`,lineHeight:1.5},children:gE[e.type].text}),(0,l.jsx)(s.Input.TextArea,{rows:Math.min(14,Math.max(3,r.split(`
17
- `).length)),value:r,className:`fg-mono-input`,style:{marginTop:8,fontSize:12},onChange:n=>{i(n.target.value);try{t({...e,config:JSON.parse(n.target.value||`{}`)}),u(!1)}catch{u(!0)}}})]})}function yE({open:e,doc:t,moduleOptions:n,onClose:r,onSave:i}){let[a,u]=(0,o.useState)(()=>({key:``,module:``,event:`afterCreate`,order:10,isActive:!0,stopOnError:!1,condition:{},actions:[],...t??{}})),[d,f]=(0,o.useState)(()=>_E(t?.condition)),[p,m]=(0,o.useState)(!1),h=(e,t)=>u(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:r,width:840,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Workflow`:`New Workflow`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!a.key?.trim())return s.message.error(`Key is required`);if(!a.module?.trim())return s.message.error(`Module is required`);if(p)return s.message.error(`Condition JSON is invalid`);if(!(a.actions??[]).length)return s.message.error(`At least one action is required`);if((a.actions??[]).some(e=>!e.type))return s.message.error(`Every action needs a type`);let e={...a};delete e.id,delete e._id,i(e)},children:`Save Workflow`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(pE,{type:`secondary`,style:{fontSize:12},children:`Key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobs-create-after`,value:a.key??``,onChange:e=>h(`key`,e.target.value),className:`fg-mono-input`,disabled:!!t})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(pE,{type:`secondary`,style:{fontSize:12},children:`Module`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},showSearch:!0,value:a.module||void 0,options:n,onChange:e=>h(`module`,e),placeholder:`jobs`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(pE,{type:`secondary`,style:{fontSize:12},children:`Event`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:a.event,options:mE.map(e=>({value:e})),onChange:e=>h(`event`,e)})]}),(0,l.jsxs)(`div`,{style:{width:90},children:[(0,l.jsx)(pE,{type:`secondary`,style:{fontSize:12},children:`Order`}),(0,l.jsx)(s.InputNumber,{size:`small`,style:{width:`100%`},value:a.order??10,onChange:e=>h(`order`,e??10)})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:24,marginTop:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:a.isActive!==!1,onChange:e=>h(`isActive`,e)}),(0,l.jsx)(pE,{style:{fontSize:13},children:`Active`})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:a.stopOnError===!0,onChange:e=>h(`stopOnError`,e)}),(0,l.jsx)(s.Tooltip,{title:`Off (default): if an action fails after the record is saved, it is logged and the next action still runs — right for independent side effects like a notification and a cache clear. On: the remaining actions are skipped, for a sequence whose later steps are only safe because the earlier ones worked (creating records and THEN clearing the data they came from).`,children:(0,l.jsx)(pE,{style:{fontSize:13},children:`Stop on error`})})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsxs)(pE,{type:`secondary`,style:{fontSize:12},children:[`Condition (all must match the payload; empty = always run) `,p&&(0,l.jsx)(s.Tag,{color:`red`,children:`invalid JSON`})]}),(0,l.jsx)(s.Input.TextArea,{rows:2,value:d,className:`fg-mono-input`,style:{fontSize:12},onChange:e=>{f(e.target.value);try{h(`condition`,JSON.parse(e.target.value||`{}`)),m(!1)}catch{m(!0)}}})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:14},children:[(0,l.jsx)(pE,{strong:!0,style:{fontSize:13},children:`Actions (run in order)`}),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>h(`actions`,[...a.actions??[],{type:``,config:{}}]),children:`Add Action`})]}),(a.actions??[]).map((e,t)=>(0,l.jsx)(vE,{action:e,onChange:e=>h(`actions`,a.actions.map((n,r)=>r===t?e:n)),onRemove:()=>h(`actions`,a.actions.filter((e,n)=>n!==t))},t)),(0,l.jsxs)(pE,{type:`secondary`,style:{fontSize:11,display:`block`,marginTop:8},children:[`Config supports `,(0,l.jsx)(`code`,{children:`{{field.path}}`}),`, `,(0,l.jsx)(`code`,{children:`{{now}}`}),`, `,(0,l.jsx)(`code`,{children:`{{__userId}}`}),`,`,` `,(0,l.jsx)(`code`,{children:`{{__userName}}`}),`, and `,(0,l.jsx)(`code`,{children:`{{hierarchy.<name>}}`}),` from a `,(0,l.jsx)(`code`,{children:`resolve`}),` action.`]})]})})}function bE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)(!0),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(null),[h,g]=(0,o.useState)(``),[_,v]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=!1;return n.ei(`workflows`).then(n=>{e||t(n)}).catch(t=>{e||f(t?.message||`Failed to load workflows`)}).finally(()=>{e||u(!1)}),()=>{e=!0}},[_]),(0,o.useEffect)(()=>{n.Sr().then(e=>i(hS(e).map(({value:e,label:t})=>({value:e,label:t})))).catch(()=>i([]))},[]);let y=()=>{u(!0),f(``),v(e=>e+1)};async function b(e){try{await n.di(`workflows`,e),s.message.success(`Workflow "${e.key}" saved`),m(null),y()}catch(e){s.message.error(e?.message||`Could not save workflow`)}}async function x(e){try{await n.ur(`workflows`,e),s.message.success(`Workflow "${e}" deleted`),y()}catch(e){s.message.error(e?.message||`Could not delete workflow`)}}async function S(e,t){let r={...e};delete r.id,delete r._id;try{await n.di(`workflows`,{...r,isActive:t}),y()}catch(e){s.message.error(e?.message||`Could not update workflow`)}}let C=(0,o.useMemo)(()=>e.filter(e=>!h||e.module===h),[e,h]);return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Workflows`,extra:(0,l.jsxs)(s.Space,{size:8,children:[(0,l.jsx)(s.Select,{size:`small`,style:{minWidth:160},allowClear:!0,placeholder:`Filter by module`,options:r,value:h||void 0,onChange:e=>g(e??``)}),(0,l.jsx)(s.Button,{size:`small`,icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:y,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>m({doc:null}),children:`New Workflow`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsxs)(pE,{type:`secondary`,style:{fontSize:13},children:[`Event-driven behavior per module — reference ids, duplicate checks, snapshots, hierarchy fan-outs, board updates, notifications, cache — executed by the platform Workflow Engine on every create/update/delete.`,(0,l.jsx)(s.Tag,{style:{marginLeft:8},children:`before*`}),` actions can block the write; `,(0,l.jsx)(s.Tag,{children:`after*`}),` actions are best-effort.`]})]}),(0,l.jsxs)(Z,{styles:{body:{paddingTop:8}},children:[d&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:d,style:{marginBottom:12}}),(0,l.jsxs)(s.Spin,{spinning:a,children:[(0,l.jsxs)(`div`,{style:{marginBottom:8},children:[(0,l.jsx)(s.Badge,{count:C.length,showZero:!0,color:`var(--color-brand)`}),` `,(0,l.jsx)(pE,{type:`secondary`,style:{fontSize:12},children:`workflows`})]}),(0,l.jsx)(s.Table,{rowKey:`key`,dataSource:C,columns:[{title:`Key`,dataIndex:`key`,key:`key`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Module`,dataIndex:`module`,key:`module`,width:130,render:e=>(0,l.jsx)(s.Tag,{color:`geekblue`,children:e})},{title:`Event`,dataIndex:`event`,key:`event`,width:130,render:e=>(0,l.jsx)(s.Tag,{color:String(e).startsWith(`before`)?`purple`:`green`,children:e})},{title:`Actions`,key:`acts`,render:(e,t)=>(0,l.jsx)(s.Space,{size:4,wrap:!0,children:(t.actions??[]).map((e,t)=>(0,l.jsx)(s.Tag,{style:{margin:0},children:e.type},t))})},{title:`Order`,dataIndex:`order`,key:`order`,width:70,align:`center`},{title:`Active`,key:`active`,width:80,align:`center`,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:t.isActive!==!1,onChange:e=>S(t,e)})},{title:``,key:`ops`,width:90,align:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>m({doc:t})})}),(0,l.jsx)(s.Popconfirm,{title:`Delete workflow "${t.key}"?`,onConfirm:()=>x(t.key),children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],pagination:!1,size:`small`,className:`fg-table`,locale:{emptyText:(0,l.jsx)(s.Empty,{description:`No workflows configured.`,image:s.Empty.PRESENTED_IMAGE_SIMPLE})}})]})]}),(0,l.jsx)(yE,{open:!!p,doc:p?.doc,moduleOptions:r,onClose:()=>m(null),onSave:b},p?p.doc?.key??`new`:`closed`)]})}var{Text:xE}=s.Typography,SE=e=>e?._id??e?.id,CE=`masters`;function wE(){return{tenantId:localStorage.getItem(`tenantId`)||``,businessId:localStorage.getItem(`businessId`)||``,businessUnitId:localStorage.getItem(`businessUnitId`)||``}}function TE(e){return e&&typeof e==`object`?e.$oid??e.oid??e.id??``:e??``}function EE(e,t){return t.map(t=>TE(e?.[t])).find(e=>e!=null&&e!==``)??``}function DE(e,t){return[[t.tenantId,[`tid`,`tenantId`]],[t.businessId,[`bid`,`businessId`]],[t.businessUnitId,[`buid`,`businessUnitId`]]].every(([t,n])=>{if(!t)return!0;let r=String(EE(e,n));return!r||r===String(t)})}function OE(e){return Array.isArray(e?.masterFeeds)?e.masterFeeds:[]}function kE(e){return e.reduce((e,t)=>Math.max(e,Number(t?.uniqueId)||0),0)+1}function AE(e){return Array.isArray(e?.taxHistory)?e.taxHistory:[]}function jE(e){let t=e?.taxValue;if(t!=null&&t!==``)return Number(t);let n=AE(e).at(-1),r=n?.taxValue??n?.value;return r!=null&&r!==``?Number(r):void 0}function ME(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}function NE(e){let t=AE(e).at(-1);return t?.updatedAt??t?.timestamp??e?.updatedAt}function PE({open:e,record:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[c,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(!1),h=(0,o.useRef)(null),g=!!t;(0,o.useEffect)(()=>{e&&queueMicrotask(()=>{a.resetFields(),a.setFieldsValue({name:t?.name??void 0,taxValue:jE(t)}),f(t?.name?[{label:t.name,value:t.name}]:[])})},[e,t,a]);function _(e){if(h.current&&clearTimeout(h.current),!e||e.trim().length<2){f([]);return}m(!0),h.current=setTimeout(()=>{n.Pr(e.trim()).then(f).catch(()=>f([])).finally(()=>m(!1))},350)}async function v(){let e=await a.validateFields(),r=Number(e.taxValue),o={name:e.name,taxValue:r,taxHistory:{taxValue:r}};u(!0);try{g?await n.bi(`locations`,SE(t),o):await n.er(`locations`,o),s.message.success(g?`Tax updated`:`Location and tax created`),i()}catch(e){s.message.error(e?.message||`Could not save location and tax`)}finally{u(!1)}}return(0,l.jsx)(s.Modal,{open:e,onCancel:r,onOk:v,confirmLoading:c,destroyOnHidden:!0,title:g?`Edit Tax — ${t?.name??``}`:`New Location`,children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{name:`name`,label:`Location`,rules:[{required:!0,message:`Location is required`}],tooltip:g?`Location cannot be changed once created — only the tax is editable.`:`Search and pick from the location master.`,children:(0,l.jsx)(s.Select,{showSearch:!0,disabled:g,placeholder:`Type at least 2 characters to search…`,filterOption:!1,onSearch:_,notFoundContent:p?`Searching…`:null,options:d})}),(0,l.jsx)(s.Form.Item,{name:`taxValue`,label:`Tax`,rules:[{required:!0,message:`Tax is required`},{type:`number`,min:0,max:100,message:`Tax must be between 0 and 100`}],children:(0,l.jsx)(s.InputNumber,{style:{width:`100%`},min:0,max:100,step:.01,suffix:`%`,placeholder:`8.875`,autoFocus:g})})]})})}function FE({record:e}){let t=[...AE(e)].reverse();return t.length?(0,l.jsx)(s.Space,{direction:`vertical`,size:4,style:{padding:`4px 8px`},children:t.map((e,t)=>(0,l.jsxs)(s.Space,{size:10,children:[(0,l.jsxs)(s.Tag,{color:t===0?`green`:`default`,style:{margin:0},children:[e.taxValue??e.value,`%`]}),(0,l.jsx)(xE,{type:`secondary`,style:{fontSize:12},children:ME(e.updatedAt??e.timestamp)}),t===0&&(0,l.jsx)(xE,{type:`secondary`,style:{fontSize:12},children:`(current)`})]},t))}):(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No tax history yet`})}function IE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null);function p(){i(!0),n.$r(`locations`).then(({items:e})=>t(e)).catch(e=>s.message.error(e?.message||`Could not load locations`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(p)},[]);async function m(e){try{await n.lr(`locations`,e),s.message.success(`Location deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete location`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{title:`${e.length} location${e.length===1?``:`s`}`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New location`})]}),children:(0,l.jsx)(s.Table,{rowKey:SE,columns:[{title:`Location`,dataIndex:`name`,key:`name`},{title:`Tax`,key:`taxValue`,width:100,render:(e,t)=>{let n=jE(t);return Number.isFinite(n)?(0,l.jsxs)(s.Tag,{color:`blue`,children:[n,`%`]}):`—`}},{title:`Tax updated`,key:`taxUpdatedAt`,render:(e,t)=>ME(NE(t))},{title:`Created`,key:`createdAt`,responsive:[`lg`],render:(e,t)=>ME(t?.createdAt)},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit tax`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this location?`,onConfirm:()=>m(SE(t)),children:(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})})]})}],dataSource:e,loading:r,size:`small`,pagination:!1,className:`fg-table`,expandable:{expandedRowRender:e=>(0,l.jsx)(FE,{record:e}),rowExpandable:e=>AE(e).length>0},locale:{emptyText:`No locations yet. Click "New location" to add one.`}})}),(0,l.jsx)(PE,{open:a,record:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}function LE({open:e,record:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[u,d]=(0,o.useState)(!1),f=!!t,p=s.Form.useWatch(`masterName`,a),m=s.Form.useWatch(`masterFeeds`,a)??[],h=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(p??t?.masterName??``).trim().toLowerCase()),g=m.map(e=>({label:String(e?.name??``).trim()||`Status ${e?.uniqueId??``}`,value:Number(e?.uniqueId)})).filter(e=>Number.isInteger(e.value)&&e.value>0);function _(e,t){if(!t){a.setFieldValue([`masterFeeds`,e,`isInitialStatus`],!1);return}(a.getFieldValue(`masterFeeds`)??[]).forEach((t,n)=>{a.setFieldValue([`masterFeeds`,n,`isInitialStatus`],n===e)})}function v(e,t){a.setFieldValue([`masterFeeds`,e,`isTerminalStatus`],t),t&&a.setFieldValue([`masterFeeds`,e,`allowedNextStatusIds`],[])}(0,o.useEffect)(()=>{e&&queueMicrotask(()=>{a.resetFields();let e=t?.masterName??``,n=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(e).trim().toLowerCase()),r=OE(t),i=r.length?r.map(e=>({...e})):[{uniqueId:1,name:``,type:`neutral`,status:!0,isdeleted:!1}];if(n&&!i.some(e=>e?.status!==!1&&e?.isdeleted!==!0&&e?.isInitialStatus===!0)){let e=i.findIndex(e=>e?.status!==!1&&e?.isdeleted!==!0);e>=0&&(i=i.map((t,n)=>({...t,isInitialStatus:n===e,isTerminalStatus:t?.isTerminalStatus===!0,allowedNextStatusIds:Array.isArray(t?.allowedNextStatusIds)?t.allowedNextStatusIds:[]})))}a.setFieldsValue({masterName:e,schemaVersion:t?.schemaVersion??1,masterFeeds:i})})},[e,t,a]),(0,o.useEffect)(()=>{!e||!h||(Number(a.getFieldValue(`schemaVersion`))||1)<2&&a.setFieldValue(`schemaVersion`,2)},[e,h,a]);async function y(){let e=await a.validateFields(),r=wE(),o=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(e.masterName??``).trim().toLowerCase()),c=(e.masterFeeds??[]).map((e,t)=>{let n=Number(e.uniqueId)||t+1,r=o&&e.isTerminalStatus===!0,i=o&&!r?[...new Set((e.allowedNextStatusIds??[]).map(Number).filter(e=>Number.isInteger(e)&&e>0&&e!==n))]:[];return{uniqueId:n,name:String(e.name??``).trim(),type:String(e.type??``).trim(),status:e.status!==!1,...o?{isInitialStatus:e.isInitialStatus===!0,isTerminalStatus:r,allowedNextStatusIds:i}:{},isdeleted:e.isdeleted===!0}}).filter(e=>e.name);if(o){let e=c.filter(e=>e.status&&!e.isdeleted&&e.isInitialStatus);if(e.length===0){let t=c.findIndex(e=>e.status&&!e.isdeleted);t>=0&&(c[t]={...c[t],isInitialStatus:!0},e=[c[t]],a.setFieldValue([`masterFeeds`,t,`isInitialStatus`],!0))}if(e.length!==1){s.message.error(`Client Submission Status must have exactly one active Initial Status.`);return}}let l={...r,tid:r.tenantId,bid:r.businessId,buid:r.businessUnitId,schemaVersion:o?Math.max(2,Number(e.schemaVersion)||2):Number(e.schemaVersion)||1,masterName:e.masterName.trim(),masterFeeds:c};d(!0);try{f?await n.bi(CE,SE(t),l):await n.er(CE,l),s.message.success(f?`Master value updated`:`Master value created`),i()}catch(e){s.message.error(e?.message||`Could not save master value`)}finally{d(!1)}}return(0,l.jsx)(s.Modal,{open:e,onCancel:r,onOk:y,confirmLoading:u,destroyOnHidden:!0,title:f?`Edit Master Feed`:`New Master Feed`,width:1040,children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{name:`masterName`,label:`Master Name`,rules:[{required:!0,message:`Master name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`blacklistType`,autoFocus:!f,disabled:f})}),(0,l.jsx)(s.Form.Item,{name:`schemaVersion`,label:`Schema Version`,children:(0,l.jsx)(s.InputNumber,{min:1,style:{width:`100%`}})}),(0,l.jsx)(s.Form.List,{name:`masterFeeds`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(s.Space,{direction:`vertical`,style:{width:`100%`},size:10,children:[e.map(({key:e,name:t})=>(0,l.jsxs)(s.Space,{align:`baseline`,wrap:!0,children:[(0,l.jsx)(s.Form.Item,{name:[t,`uniqueId`],label:`ID`,rules:[{required:!0,message:`ID required`}],children:(0,l.jsx)(s.InputNumber,{min:1,style:{width:90}})}),(0,l.jsx)(s.Form.Item,{name:[t,`name`],label:`Name`,rules:[{required:!0,message:`Name required`}],children:(0,l.jsx)(s.Input,{placeholder:`Dropdown label`,style:{width:280}})}),(0,l.jsx)(s.Form.Item,{name:[t,`type`],label:`Type`,children:(0,l.jsx)(s.Select,{allowClear:!0,placeholder:`Select type`,style:{width:120},options:[{label:`Positive`,value:`positive`},{label:`Neutral`,value:`neutral`},{label:`Negative`,value:`negative`}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`status`],label:`Status`,initialValue:!0,children:(0,l.jsx)(s.Select,{style:{width:110},options:[{label:`Active`,value:!0},{label:`Inactive`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`isdeleted`],label:`Deleted`,initialValue:!1,children:(0,l.jsx)(s.Select,{style:{width:110},options:[{label:`No`,value:!1},{label:`Yes`,value:!0}]})}),h&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Form.Item,{name:[t,`isInitialStatus`],label:`Initial`,initialValue:!1,tooltip:`The initial status is the only option shown before a candidate has a client submission status. Only one active initial status is allowed.`,children:(0,l.jsx)(s.Select,{style:{width:100},onChange:e=>_(t,e===!0),options:[{label:`Yes`,value:!0},{label:`No`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`isTerminalStatus`],label:`End Status`,initialValue:!1,tooltip:`End Status stops the configured client submission flow. Once reached, Change Status is hidden and no next statuses are allowed.`,children:(0,l.jsx)(s.Select,{style:{width:105},onChange:e=>v(t,e===!0),options:[{label:`Yes`,value:!0},{label:`No`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{noStyle:!0,shouldUpdate:(e,n)=>e?.masterFeeds?.[t]?.isTerminalStatus!==n?.masterFeeds?.[t]?.isTerminalStatus||e?.masterFeeds?.[t]?.uniqueId!==n?.masterFeeds?.[t]?.uniqueId||e?.masterFeeds!==n?.masterFeeds,children:({getFieldValue:e})=>{let n=e([`masterFeeds`,t,`isTerminalStatus`])===!0,r=Number(e([`masterFeeds`,t,`uniqueId`]));return(0,l.jsx)(s.Form.Item,{name:[t,`allowedNextStatusIds`],label:`Allowed Next Statuses`,tooltip:n?`End Status cannot move to another status.`:`Only these statuses will appear after the current status is saved.`,children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,disabled:n,placeholder:n?`End status`:`Select next statuses`,style:{minWidth:280},options:g.filter(e=>e.value!==r)})})}})]}),(0,l.jsx)(s.Tooltip,{title:`Remove row`,children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>n(t)})})]},e)),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>t({uniqueId:kE(a.getFieldValue(`masterFeeds`)??[]),name:``,type:`neutral`,status:!0,isdeleted:!1,...h?{isInitialStatus:!1,isTerminalStatus:!1,allowedNextStatusIds:[]}:{}}),children:`Add feed value`})]})})]})})}function RE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),[p,m]=(0,o.useState)(``);function h(){let e=wE();i(!0),n.$r(CE,{limit:500}).then(({items:n})=>{let r=n.filter(t=>DE(t,e));t(r)}).catch(e=>s.message.error(e?.message||`Could not load master values`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(h)},[]);async function g(e){try{await n.lr(CE,e),s.message.success(`Master value deleted`),h()}catch(e){s.message.error(e?.message||`Could not delete master value`)}}let _=p?e.filter(e=>String(e?.masterName??``).toLowerCase()===p.toLowerCase()):e,v=[...new Set(e.map(e=>e?.masterName).filter(Boolean))].sort((e,t)=>String(e).localeCompare(String(t))).map(e=>({label:e,value:e}));return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{title:`${_.length} master${_.length===1?``:`s`}`,extra:(0,l.jsxs)(s.Space,{wrap:!0,children:[(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,placeholder:`Filter master name`,value:p||void 0,options:v,onChange:e=>m(e??``),style:{minWidth:220}}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:h,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New master`})]}),children:(0,l.jsx)(s.Table,{rowKey:SE,columns:[{title:`Master Name`,dataIndex:`masterName`,key:`masterName`,width:180},{title:`Feed Values`,key:`masterFeeds`,render:(e,t)=>(0,l.jsx)(s.Space,{wrap:!0,children:OE(t).filter(e=>!e.isdeleted).map(e=>(0,l.jsx)(s.Tag,{color:e.status===!1?`default`:`blue`,children:e.name},e.uniqueId??e.name))})},{title:`Count`,key:`count`,width:90,render:(e,t)=>OE(t).filter(e=>!e.isdeleted).length},{title:`Updated`,key:`updatedAt`,responsive:[`lg`],render:(e,t)=>ME(t?.updatedAt)},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this master?`,onConfirm:()=>g(SE(t)),children:(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})})]})}],dataSource:_,loading:r,size:`small`,pagination:{pageSize:10,showSizeChanger:!0},className:`fg-table`,locale:{emptyText:`No masters yet. Click "New master" to add one.`}})}),(0,l.jsx)(LE,{open:a,record:d,onClose:()=>u(!1),onSaved:()=>{u(!1),h()}})]})}function zE(){return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Master Collections`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(xE,{type:`secondary`,style:{fontSize:13},children:`Create, update, and delete master documents, then customize multiple dropdown values inside masterFeeds. Records are saved with the current tenant, business, business unit, and master name.`})]}),(0,l.jsx)(RE,{}),(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Location Tax Master`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(xE,{type:`secondary`,style:{fontSize:13},children:`Pick a location from the master list and set its tax. Once added, only the tax can be changed — every change is kept in a timeline with its timestamp. Expand a row to see the full tax history.`})]}),(0,l.jsx)(IE,{})]})}var{Text:BE}=s.Typography,VE={employerMsaValidityDays:365,referralMsaValidityDays:365,expiryWarningDays:30};function HE(){let[e]=s.Form.useForm(),[t,r]=(0,o.useState)(!0),[i,a]=(0,o.useState)(!1),u=async()=>{r(!0);try{let t=await n.Gr();e.setFieldsValue({...VE,...t||{}})}catch(t){s.message.error(t?.message||`Could not load PO/MSA settings`),e.setFieldsValue(VE)}finally{r(!1)}};return(0,o.useEffect)(()=>{u()},[]),(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.SettingOutlined,{}),title:`PO/MSA Validity Settings`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:u,disabled:i,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,onClick:async()=>{try{let t=await e.validateFields();a(!0);let r=await n.ui(t);e.setFieldsValue({...VE,...r||t}),s.message.success(`PO/MSA validity settings saved`)}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save PO/MSA settings`)}finally{a(!1)}},children:`Save`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(BE,{type:`secondary`,children:`Configure how long a signed MSA remains valid. Employer/referral status is calculated from the signed MSA date plus these values; no validity period is hardcoded in the onboarding UI.`})]}),(0,l.jsx)(Z,{title:`Validity Rules`,children:(0,l.jsx)(s.Spin,{spinning:t,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,initialValues:VE,style:{maxWidth:620},children:[(0,l.jsx)(s.Form.Item,{name:`employerMsaValidityDays`,label:`Employer MSA Validity Days`,tooltip:`Number of days an employer MSA remains active from its signed date.`,rules:[{required:!0,message:`Employer MSA validity is required`}],children:(0,l.jsx)(s.InputNumber,{min:1,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})}),(0,l.jsx)(s.Form.Item,{name:`referralMsaValidityDays`,label:`Referral MSA Validity Days`,tooltip:`Number of days a referral MSA remains active from its signed date.`,rules:[{required:!0,message:`Referral MSA validity is required`}],children:(0,l.jsx)(s.InputNumber,{min:1,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})}),(0,l.jsx)(s.Form.Item,{name:`expiryWarningDays`,label:`Expiry Warning Days`,tooltip:`Reserved for upcoming-expiry indicators and notifications.`,rules:[{required:!0,message:`Expiry warning days is required`}],children:(0,l.jsx)(s.InputNumber,{min:0,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})})]})})})]})}var{Text:UE,Title:WE}=s.Typography,GE=[{value:`Dashboard`,label:`Dashboard`,icon:(0,l.jsx)(c.DashboardOutlined,{})},{value:`ClientManagement`,label:`Client Management`,icon:(0,l.jsx)(c.BankOutlined,{})},{value:`EmployerManagement`,label:`Employer / Referral`,icon:(0,l.jsx)(c.TeamOutlined,{})},{value:`Candidates`,label:`Candidates`,icon:(0,l.jsx)(c.UsergroupAddOutlined,{})},{value:`Jobs`,label:`Jobs`,icon:(0,l.jsx)(c.FileTextOutlined,{})},{value:`Submissions`,label:`Submissions`,icon:(0,l.jsx)(c.FileTextOutlined,{})},{value:`Onboarding`,label:`Onboarding`,icon:(0,l.jsx)(c.UserOutlined,{})},{value:`Assignments`,label:`Assignments`,icon:(0,l.jsx)(c.AppstoreOutlined,{})},{value:`Timesheet`,label:`Timesheet`,icon:(0,l.jsx)(c.CalendarOutlined,{})},{value:`Campaign`,label:`Campaign`,icon:(0,l.jsx)(c.TeamOutlined,{})},{value:`FileProtectOutlined`,label:`PO / MSA`,icon:(0,l.jsx)(c.FileProtectOutlined,{})},{value:`FolderOpenOutlined`,label:`Batches`,icon:(0,l.jsx)(c.FolderOpenOutlined,{})},{value:`BankOutlined`,label:`Billing / Finance`,icon:(0,l.jsx)(c.BankOutlined,{})},{value:`SettingOutlined`,label:`Settings / Admin`,icon:(0,l.jsx)(c.SettingOutlined,{})},{value:`UploadOutlined`,label:`Upload`,icon:(0,l.jsx)(c.UploadOutlined,{})},{value:`AppstoreOutlined`,label:`General Module`,icon:(0,l.jsx)(c.AppstoreOutlined,{})}];function KE({option:e}){return(0,l.jsxs)(s.Space,{size:8,children:[(0,l.jsx)(`span`,{style:{display:`inline-flex`,fontSize:16},children:e.icon}),(0,l.jsx)(`span`,{children:e.label}),(0,l.jsx)(UE,{type:`secondary`,style:{fontSize:11},children:e.value})]})}function qE(e,t){let n=localStorage.getItem(`menu`);if(n)try{let r=JSON.parse(n),i=Array.isArray(r)?r:r?.menu;if(!Array.isArray(i))return;let a=String(e??t.menu_key??``).trim().toLowerCase(),o=e=>e.map(e=>{let n=String(e?.key??``).trim().toLowerCase()===a?{...e,icon:t.icon??e.icon,label:t.menu_name??e.label,status:String(t.status??e.status??`ACTIVE`).toLowerCase()}:e;return Array.isArray(n?.children)?{...n,children:o(n.children)}:n}),s=o(i);localStorage.setItem(`menu`,JSON.stringify(Array.isArray(r)?s:{...r,menu:s})),window.dispatchEvent(new Event(`menu:updated`))}catch{}}function JE(){let[e]=s.Form.useForm(),[t,n]=(0,o.useState)([]),[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),[p,m]=(0,o.useState)(!1);async function h(){i(!0);try{n(await Rx())}catch(e){s.message.error(e.message||`Unable to load menus`)}finally{i(!1)}}(0,o.useEffect)(()=>{h()},[]);let g=(0,o.useMemo)(()=>t.filter(e=>!d||e.menu_id!==d.menu_id).map(e=>({label:e.menu_name,value:e.menu_id})),[d,t]);function _(){f(null),e.resetFields(),e.setFieldsValue({menu_type:`MENU`,display_order:t.length+1,status:`ACTIVE`}),m(!0)}function v(t){f(t),e.setFieldsValue(t),m(!0)}async function y(e){u(!0);try{d?(await Bx(d.menu_id,e),qE(d.menu_key,e)):await zx(e),s.message.success(d?`Menu updated`:`Menu created`),m(!1),await h()}catch(e){s.message.error(e.message||`Unable to save menu`)}finally{u(!1)}}async function b(e){try{await Vx(e),s.message.success(`Menu deleted`),await h()}catch(e){s.message.error(e.message||`Unable to delete menu`)}}return(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(WE,{level:4,children:`Menus`}),(0,l.jsx)(UE,{type:`secondary`,children:`Manage records in the MongoDB menus collection.`})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:_,children:`Add Menu`})]}),(0,l.jsx)(s.Table,{rowKey:`menu_id`,loading:r,columns:[{title:`Name`,dataIndex:`menu_name`},{title:`Key`,dataIndex:`menu_key`,render:e=>(0,l.jsx)(s.Tag,{children:e})},{title:`Route / API`,dataIndex:`api_url`},{title:`Icon`,dataIndex:`icon`,width:170,render:e=>(0,l.jsx)(s.Tag,{children:e||`Auto`})},{title:`Type`,dataIndex:`menu_type`,width:110},{title:`Order`,dataIndex:`display_order`,width:80},{title:`Status`,dataIndex:`status`,width:100,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Edit menu`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>v(t)}),(0,l.jsx)(s.Popconfirm,{title:`Delete menu?`,onConfirm:()=>b(t.menu_id),children:(0,l.jsx)(s.Button,{"aria-label":`Delete menu`,danger:!0,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:t,size:`small`,pagination:{pageSize:10}}),(0,l.jsx)(s.Modal,{title:d?`Edit Menu`:`Add Menu`,open:p,onCancel:()=>m(!1),onOk:()=>e.submit(),confirmLoading:a,destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,onFinish:y,children:[(0,l.jsx)(s.Form.Item,{name:`menu_name`,label:`Menu name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{})}),(0,l.jsx)(s.Form.Item,{name:`menu_key`,label:`Menu key`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`jobs`})}),(0,l.jsx)(s.Form.Item,{name:`api_url`,label:`Route / API URL`,children:(0,l.jsx)(s.Input,{placeholder:`/jobs`})}),(0,l.jsx)(s.Form.Item,{name:`component_name`,label:`Component`,children:(0,l.jsx)(s.Input,{placeholder:`Jobs`})}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{name:`menu_type`,label:`Type`,children:(0,l.jsx)(s.Select,{options:[{value:`MENU`},{value:`FOOTER`},{value:`CHILD`}]})}),(0,l.jsx)(s.Form.Item,{name:`parent_menu_id`,label:`Parent`,children:(0,l.jsx)(s.Select,{allowClear:!0,options:g})})]}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{name:`display_order`,label:`Display order`,children:(0,l.jsx)(s.InputNumber,{min:0})}),(0,l.jsx)(s.Form.Item,{name:`status`,label:`Status`,children:(0,l.jsx)(s.Select,{options:[{value:`ACTIVE`},{value:`INACTIVE`}]})})]}),(0,l.jsx)(s.Form.Item,{name:`icon`,label:`Sidebar icon`,extra:`Saved in the menus collection and used dynamically in the application sidebar.`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,placeholder:`Select sidebar icon`,optionFilterProp:`label`,options:GE.map(({value:e,label:t})=>({value:e,label:t})),optionRender:e=>{let t=e?.value??e?.data?.value,n=GE.find(e=>e.value===t);return n?(0,l.jsx)(KE,{option:n}):t}})})]})})]})}var{Text:YE}=s.Typography,XE={call:10,sms:10,whatsapp:10,email:10},ZE=[{name:`call`,label:`Calls per day`,tooltip:`Calls each counsellor can make in one day.`},{name:`sms`,label:`SMS per day`,tooltip:`SMS messages each counsellor can send in one day.`},{name:`whatsapp`,label:`WhatsApp per day`,tooltip:`WhatsApp messages each counsellor can send in one day.`},{name:`email`,label:`Mail per day`,tooltip:`Emails each counsellor can send in one day.`}];function QE(){let[e]=s.Form.useForm(),[t,r]=(0,o.useState)(!0),[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)({canEdit:!1,maxLimit:1e3,defaultLimit:10}),m=t=>{e.setFieldsValue({...XE,...t?.limits||{}}),p({canEdit:!!t?.canEdit,maxLimit:Number(t?.maxLimit??1e3),defaultLimit:Number(t?.defaultLimit??10)})},h=async()=>{r(!0),d(``);try{m(await n.Er())}catch(t){let n=t?.message||`Could not load communication limits`;d(n),s.message.error(n),e.setFieldsValue(XE)}finally{r(!1)}};return(0,o.useEffect)(()=>{h()},[]),(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.MessageOutlined,{}),title:`Communication Limits`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:h,disabled:i,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,disabled:!f.canEdit,onClick:async()=>{try{let t=await e.validateFields();a(!0),m(await n.ii(t)),s.message.success(`Communication limits saved. They apply immediately.`)}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save communication limits`)}finally{a(!1)}},children:`Save`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(YE,{type:`secondary`,children:`Set how many calls, SMS, WhatsApp messages and emails each counsellor can use per day. The same number applies to every counsellor and is shared across all their leads. The count starts again every day (India time); unused ones do not carry over.`})]}),(0,l.jsxs)(Z,{title:`Daily Limits`,children:[!t&&u&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:`Could not load the communication limits`,description:`${u}. The numbers below are only the defaults. Check that the backend has /communication-daily-limits, then press Reload.`,style:{marginBottom:16,maxWidth:620}}),!t&&!u&&!f.canEdit&&(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`Your role cannot change these limits. You can view them here.`,style:{marginBottom:16,maxWidth:620}}),(0,l.jsxs)(s.Spin,{spinning:t,children:[(0,l.jsx)(s.Form,{form:e,layout:`vertical`,initialValues:XE,style:{maxWidth:620},disabled:!f.canEdit,children:ZE.map(({name:e,label:t,tooltip:n})=>(0,l.jsx)(s.Form.Item,{name:e,label:t,tooltip:n,rules:[{required:!0,message:`${t} is required`}],children:(0,l.jsx)(s.InputNumber,{min:0,max:f.maxLimit,precision:0,style:{width:`100%`},addonAfter:`per day`})},e))}),(0,l.jsxs)(YE,{type:`secondary`,children:[`Allowed range: 0 to `,f.maxLimit,`. Use 0 to block a channel. Where nothing has been saved, the default of `,f.defaultLimit,` per day is used.`]})]})]})]})}var{Content:$E,Header:eD,Sider:tD}=s.Layout,{Text:nD,Title:rD}=s.Typography;function iD(e){return String(e??``).trim().replace(/[\s_-]+/g,` `).toUpperCase()}function aD(e){return String(e||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim()}function oD(e){return String(e||``).trim().toLowerCase()}function sD(e){return e?.key||e?.collectionName||e?.value||``}function cD(e=[],t=[]){let n=[],r=new Set,i=new Set,a=new Set;return e.forEach(e=>{let t=sD(e);if(!t)return;let o=oD(e.key||t),s=oD(e.collectionName);e.seeded&&(i.add(o),s&&i.add(s)),s&&a.add(s),r.add(t),n.push({label:e.label||aD(t),value:t,disabled:!!e.seeded})}),t.forEach(e=>{let t=String(e||``).trim();if(!t||r.has(t))return;let o=oD(t);a.has(o)||i.has(o)||(r.add(t),n.push({label:aD(t),value:t,disabled:!1}))}),n}function lD(e){return iD(e?.user_type_name??e?.userTypeName??e?.name)===`SUPER ADMIN`}function uD(e){return`${e?.first_name??e?.firstName??``} ${e?.last_name??e?.lastName??``}`.trim()||e?.username||e?.userName||e?.email||`User ${e?.user_id??e?.userId??``}`}function dD(e){return e.flatMap(e=>{let t=e.menu_id??e.menuId??e.MenuID,n=e.menu_name??e.menuName??e.MenuName??`Menu ${t??``}`,r=e.menu_key??e.menuKey??e.MenuKey??``,i=e.permissions??e.Permissions??{};return Object.entries(i).map(([e,i])=>{let a=i.permission_id??i.permissionId??i.PermissionID,o=i.permission_key??i.permissionKey??i.PermissionKey??e,s=i.value??i.Value??i.access_value??i.accessValue??i;return{key:`${r??n??t}:${a??o}`,menuId:t,menuName:n,menuKey:r,permissionId:a,permissionKey:o,accessValue:+(Number(s)===1)}})})}function fD(e){return String(e.menuKey??e.menuName??e.menuId).trim().toLowerCase()}var pD=[{permissionId:null,permissionKey:`sendApprove`,permissionName:`Send Approve`}];function mD(e){let t=Array.isArray(e)?e:e?.permissions??e?.actions??e?.data??e,n=(Array.isArray(t)?t:Object.values(t??{})).map(e=>({permissionId:e.permission_id??e.permissionId??e.legacyPermissionId??e.id??null,permissionKey:e.permission_key??e.permissionKey??e.key,permissionName:e.permission_name??e.permissionName??e.name??e.label})).filter(e=>e.permissionKey),r=new Set(n.map(e=>String(e.permissionKey).trim().toLowerCase()));return pD.forEach(e=>{r.has(e.permissionKey.toLowerCase())||n.push(e)}),n}function hD(e={}){return String(e.permissionName??``).trim()||String(e.permissionKey??``).replaceAll(`_`,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function gD({title:e,description:t,selectedName:n,loading:r,saving:i,rows:a,onChange:o,onMove:u,onSave:d}){let f=Object.values(a.reduce((e,t)=>{let n=fD(t);return e[n]||(e[n]={key:n,menuName:t.menuName,menuKey:t.menuKey,permissions:[]}),e[n].permissions.push(t),e},{}));return(0,l.jsxs)(`section`,{className:`admin-editor`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:e}),(0,l.jsx)(nD,{type:`secondary`,children:n||t})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,disabled:!n||a.length===0,onClick:d,children:`Save`})]}),r?(0,l.jsx)(`div`,{className:`admin-loading`,children:(0,l.jsx)(s.Spin,{})}):f.length?(0,l.jsx)(s.Table,{size:`small`,rowKey:`key`,columns:[{title:`Menu`,dataIndex:`menuName`,width:220,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-menu-order-cell`,children:[(0,l.jsxs)(`div`,{className:`admin-menu-cell`,children:[(0,l.jsx)(`span`,{children:e}),(0,l.jsx)(nD,{type:`secondary`,children:t.menuKey})]}),(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{size:`small`,type:`text`,icon:(0,l.jsx)(c.ArrowUpOutlined,{}),onClick:()=>u(t.key,-1),"aria-label":`Move ${e} up`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,icon:(0,l.jsx)(c.ArrowDownOutlined,{}),onClick:()=>u(t.key,1),"aria-label":`Move ${e} down`})]})]})},{title:`Actions`,dataIndex:`permissions`,render:e=>(0,l.jsx)(`div`,{className:`admin-permission-controls`,children:e.filter(e=>Kx(e.menuName??e.menuKey,e.permissionKey)).map(e=>(0,l.jsx)(`label`,{className:`admin-permission-control`,children:(0,l.jsx)(s.Checkbox,{checked:e.accessValue===1,onChange:t=>o(e.key,+!!t.target.checked),"aria-label":`${e.menuName} ${e.permissionKey}`,children:hD(e)})},e.key))})}],dataSource:f,pagination:!1,scroll:{y:420}}):(0,l.jsx)(s.Empty,{description:`Select a record to customize permissions`})]})}function _D({onLogout:e}){let[r]=s.Form.useForm(),[i]=s.Form.useForm(),[a,u]=(0,o.useState)(`users`),[d,f]=(0,o.useState)(!0),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(0),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),[T,E]=(0,o.useState)(``),[D,O]=(0,o.useState)(!1),[k,A]=(0,o.useState)([]),[j,M]=(0,o.useState)([]),[N,P]=(0,o.useState)([]),[F,I]=(0,o.useState)(null),[L,R]=(0,o.useState)([]),[z,B]=(0,o.useState)(!1),[V,H]=(0,o.useState)(null),[ee,U]=(0,o.useState)(!1),[te,ne]=(0,o.useState)(null),[re,ie]=(0,o.useState)([]),[ae,W]=(0,o.useState)(!1),[oe,se]=(0,o.useState)(!1),[ce,le]=(0,o.useState)(null),[ue,de]=(0,o.useState)(!1),[G,fe]=(0,o.useState)(null),[pe,me]=(0,o.useState)(`listView`),[he,ge]=(0,o.useState)([]),[_e,ve]=(0,o.useState)([]),[ye,be]=(0,o.useState)(!1),[xe,K]=(0,o.useState)(!1),q=t.d(),Se=(0,o.useMemo)(()=>he.filter(e=>!e.disabled),[he]),Ce=!ye&&Se.length===0,we=(0,o.useCallback)(async()=>{be(!0);try{let[e,t]=await Promise.all([n.Ar(),n.xr()]),r=cD(e.modules,t),i=new Set(r.filter(e=>!e.disabled).map(e=>e.value));ge(r),ve(e=>e.filter(e=>i.has(e)))}catch{s.message.error(`Failed to load seed status`)}finally{be(!1)}},[]);(0,o.useEffect)(()=>{we()},[we]);async function Te(){if(_e.length===0){s.message.warning(Ce?`All modules already seeded.`:`Select at least one module to seed.`);return}K(!0);try{await n.pi(_e),s.message.success(`User type field config seeded`),ve([]),await we()}catch(e){s.message.error(e?.message||`Seed failed`)}finally{K(!1)}}async function Ee(){f(!0);try{let[e,t,n]=await Promise.allSettled([Px(),Rx(),Hx()]),r=e.status===`fulfilled`?e.value:[];e.status===`rejected`&&s.message.error(e.reason?.message||`Unable to load user types`),A(r??[]),M(t.status===`fulfilled`?t.value??[]:[]),P(n.status===`fulfilled`?mD(n.value):[]),I((r??[])[0]?.user_type_id??null)}catch(e){s.message.error(e.message||`Unable to load admin data`)}finally{f(!1)}}(0,o.useEffect)(()=>{queueMicrotask(()=>{Ee()})},[]);let De=(0,o.useCallback)(async()=>{O(!0);try{let{users:e,total:t}=await kx({limit:C,offset:(x-1)*C,search:T});v(e??[]),b(t??0)}catch(e){s.message.error(e?.message||`Unable to load users`),v([]),b(0)}finally{O(!1)}},[x,C,T]);(0,o.useEffect)(()=>{De()},[De]),(0,o.useEffect)(()=>{queueMicrotask(()=>{if(!F){R([]);return}m(!0),console.log(`DEBUG requesting role permissions for selectedUserTypeId=`,F,`localStorage scope=`,{tenantId:localStorage.getItem(`tenantId`),businessId:localStorage.getItem(`businessId`),businessUnitId:localStorage.getItem(`businessUnitId`)}),Ux(F).then(e=>{console.log(`DEBUG raw groups from /get-role-details`,e);let t=dD(e??[]);console.log(`DEBUG savedRows (jobs only)`,t.filter(e=>fD(e)===`jobs`||fD(e)===`job`));let n=new Map(t.map(e=>[`${fD(e)}:${String(e.permissionKey).toLowerCase()}`,e.accessValue]));console.log(`DEBUG savedAccess keys`,[...n.keys()]),console.log(`DEBUG menus (jobs only)`,j.filter(e=>String(e.menu_key??e.menu_name??e.menu_id).trim().toLowerCase()===`jobs`));let r=j.flatMap(e=>N.map(t=>{let r=String(e.menu_key??e.menu_name??e.menu_id).trim().toLowerCase(),i=String(t.permissionKey).toLowerCase();return{key:`${e.menu_key??e.menu_name??e.menu_id}:${t.permissionId??t.permissionKey}`,menuId:e.menu_id,menuName:e.menu_name,menuKey:e.menu_key,permissionId:t.permissionId,permissionKey:t.permissionKey,accessValue:n.get(`${r}:${i}`)??0}}));console.log(`DEBUG final rows (jobs only)`,r.filter(e=>fD(e)===`jobs`||fD(e)===`job`)),R(r)}).catch(e=>s.message.error(e.message||`Unable to load role permissions`)).finally(()=>m(!1))})},[F,j,N]);let Oe=(0,o.useMemo)(()=>k.find(e=>e.user_type_id===F),[F,k]),ke=(0,o.useMemo)(()=>k.reduce((e,t)=>({...e,[t.user_type_id]:t.user_type_name}),{}),[k]),Ae=(0,o.useMemo)(()=>_.reduce((e,t)=>({...e,[t.user_id]:uD(t)}),{}),[_]),je=(0,o.useMemo)(()=>k.filter(e=>!lD(e)),[k]),J=(0,o.useMemo)(()=>_.filter(e=>!lD({user_type_id:e.user_type_id,user_type_name:ke[e.user_type_id]})),[ke,_]);(0,o.useEffect)(()=>{if(!z){ie([]);return}let e=Number(r.getFieldValue(`user_type_id`)??0);if(!e){ie([]);return}let t=!1;return W(!0),Ax(e).then(e=>{t||ie(e.filter(e=>!V||e.user_id!==V.user_id))}).catch(e=>{t||(s.message.error(e.message||`Unable to load reporting users`),ie([]))}).finally(()=>{t||W(!1)}),()=>{t=!0}},[V,r,z]);let Me=(0,o.useMemo)(()=>{let e=re.map(e=>({label:uD(e),value:e.user_id})),t=Number(V?.reporting_id??V?.reportingId??0);return!t||e.some(e=>Number(e.value)===t)?e:[{label:V?.reportingName??V?.reporting_name??Ae[t]??`User ${t}`,value:t},...e]},[V,re,Ae]),Ne=(0,o.useMemo)(()=>{let e=je.map(e=>({label:e.user_type_name,value:e.user_type_id}));if(!V)return e;let t=Number(V.user_type_id??0);return e.some(e=>Number(e.value)===t)?e:[{label:ke[t]??V.userType??V.roleName??(t>0?`Type ${t}`:`Unassigned`),value:t},...e]},[V,je,ke]);k.length,j.length;let Pe=[{key:`form-groups`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Form Groups`]}),title:`Form Groups`,description:`Build module add and edit form groups with validations, dropdowns, and custom forms.`,component:(0,l.jsx)(ow,{})},{key:`detail-groups`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.BgColorsOutlined,{}),` Detail Groups`]}),title:`Detail Groups`,description:`Control detail-view labels, rendering, lookups, merged fields, and display defaults.`,component:(0,l.jsx)(Vw,{})},{key:`actions`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` Actions`]}),title:`Actions`,description:`Manage row action buttons and their visibility rules from one workspace.`,component:(0,l.jsx)(AT,{})},{key:`templates`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MailOutlined,{}),` Templates`]}),title:`Templates`,description:`Manage reusable email templates and signatures.`,component:(0,l.jsx)(HT,{})},{key:`ai-services`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` AI Services`]}),title:`AI Services`,description:`Register the AI and automation services used by admin-configured AI actions.`,component:(0,l.jsx)(KT,{})},{key:`bgc-integration`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` Integrations`]}),title:`Integrations`,description:`Manage manual and API integrations used across application workflows.`,component:(0,l.jsx)(QT,{})},{key:`automations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ApartmentOutlined,{}),` Automations`]}),title:`Automations`,description:`Reference ids, duplicate checks, cross-module snapshots, reporting-chain hierarchy expansion, board updates, notifications, and cache invalidation — per module, config-driven.`,component:(0,l.jsx)(fE,{})},{key:`workflows`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ApartmentOutlined,{}),` Workflows`]}),title:`Workflows`,description:`Event-driven behavior per module (beforeCreate/afterCreate/…): the metadata the platform Workflow Engine executes — where the jobs, candidates, and submissions create flows live.`,component:(0,l.jsx)(bE,{})},{key:`po-msa-settings`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` PO/MSA Settings`]}),title:`PO/MSA Settings`,description:`Configure employer and referral MSA validity and expiry warning days.`,component:(0,l.jsx)(HE,{})},{key:`po-msa-settings`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` PO/MSA Settings`]}),title:`PO/MSA Settings`,description:`Configure employer and referral MSA validity and expiry warning days.`,component:(0,l.jsx)(HE,{})},{key:`communication-limits`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MessageOutlined,{}),` Communication Limits`]}),title:`Communication Limits`,description:`Set the daily number of calls, SMS, WhatsApp messages and emails each counsellor can use.`,component:(0,l.jsx)(QE,{})},{key:`masters`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Masters`]}),title:`Masters`,description:`Shared Location and Tax lists used across modules (e.g. the submission form’s W2 employer section).`,component:(0,l.jsx)(zE,{})}],Fe=[{key:`users`,icon:(0,l.jsx)(c.UserOutlined,{}),label:`Users`},{key:`roles`,icon:(0,l.jsx)(c.TeamOutlined,{}),label:`User Types`},{key:`menus`,icon:(0,l.jsx)(c.MenuOutlined,{}),label:`Menus`},{key:`configurations`,icon:(0,l.jsx)(c.AppstoreAddOutlined,{}),label:`Configurations`},{key:`integrations`,icon:(0,l.jsx)(c.SafetyCertificateOutlined,{}),label:`Integrations`}];function Ie(e,t){R(n=>{let r=n.filter(t=>t.key===e).length;return console.log(`DEBUG updateRolePermission`,{key:e,value:t,matchCount:r}),n.map(n=>n.key===e?{...n,accessValue:t}:n)})}async function Le(){g(!0);try{console.log(`DEBUG saveRolePermissions jobs rows`,L.filter(e=>fD(e)===`jobs`||fD(e)===`job`)),await Wx(F,L.map(e=>({menu_id:e.menuId,menu_name:e.menuName,menu_key:e.menuKey,permission_id:e.permissionId,permission_key:e.permissionKey,access_value:e.accessValue,updated_by:q?.userId??null}))),s.message.success(`Role permissions updated`)}catch(e){s.message.error(e.message||`Unable to save role permissions`)}finally{g(!1)}}function Re(){H(null),r.resetFields(),r.setFieldsValue({status:`ACTIVE`,user_type_id:je[0]?.user_type_id,reporting_id:0}),B(!0)}function ze(e){H(e),r.setFieldsValue({first_name:e.first_name,last_name:e.last_name,username:e.username,email:e.email,mobile:e.mobile,user_type_id:e.user_type_id,reporting_id:e.reporting_id??e.reportingId??0,profile_image:e.profile_image,status:e.status}),B(!0)}async function Be(e){U(!0);try{let t={...e,status:e.status===1||e.status===`1`||e.status===!0?`ACTIVE`:e.status===0||e.status===`0`||e.status===!1?`INACTIVE`:String(e.status??`ACTIVE`).toUpperCase(),updated_by:q?.userId??null,created_by:q?.userId??null};t.password||delete t.password,V?(await Mx(V.user_id,t),s.message.success(`User updated`)):(await jx(t),s.message.success(`User created`)),B(!1),H(null),await De()}catch(e){s.message.error(e.message||`Unable to save user`)}finally{U(!1)}}async function Y(e){ne(e);try{await Nx(e),s.message.success(`User deleted`),await De()}catch(e){s.message.error(e.message||`Unable to delete user`)}finally{ne(null)}}function Ve(e,t){me(`listView`),fe({kind:e,record:t}),e===`role`&&I(t.user_type_id)}function He(e,t){R(n=>{let r=[...new Set(n.map(fD))],i=r.indexOf(e),a=i+t;if(i<0||a<0||a>=r.length)return n;[r[i],r[a]]=[r[a],r[i]];let o=new Map(r.map((e,t)=>[e,t]));return[...n].sort((e,t)=>o.get(fD(e))-o.get(fD(t)))})}function Ue(){le(null),i.resetFields(),i.setFieldsValue({status:`ACTIVE`}),se(!0)}function X(e){le(e),se(!0),i.setFieldsValue(e)}async function We(e){de(!0);try{let t=q?.userId??null,n=!!ce,r=n?await Ix(ce.user_type_id,{...e,updated_by:t}):await Fx({...e,created_by:t,visible_menu_ids:[]}),i=r.user_type_id;s.message.success(n?`User type updated`:`User type created. Customize its menus and permissions.`),se(!1),await Ee(),I(i),n||(me(`permissions`),fe({kind:`role`,record:{...e,...r,user_type_id:i,user_type_name:r.user_type_name??e.user_type_name}}))}catch(e){s.message.error(e.message||`Unable to save role`)}finally{de(!1)}}async function Ge(e){try{await Lx(e),s.message.success(`Role deleted`),await Ee()}catch(e){s.message.error(e.message||`Unable to delete role`)}}return(0,l.jsxs)(s.Layout,{className:`admin-shell`,children:[(0,l.jsx)(tD,{width:248,className:`admin-sider`,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-nav`,children:[(0,l.jsx)(nD,{className:`admin-sidebar-title`,children:`Admin Menu`}),(0,l.jsx)(s.Menu,{theme:`dark`,mode:`inline`,selectedKeys:[a],onClick:({key:e})=>u(e),items:Fe})]})}),(0,l.jsx)(s.Layout,{children:(0,l.jsxs)($E,{className:`admin-content`,children:[(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(s.Tabs,{activeKey:a,onChange:u,tabBarStyle:{display:`none`},items:[{key:`users`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.UserOutlined,{}),` Users`]}),children:(0,l.jsx)(`div`,{className:`admin-stack`,children:(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:`Users`}),(0,l.jsx)(nD,{type:`secondary`,children:`Create and manage users with non-super-admin user types.`})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:Re,children:`Add`})]}),(0,l.jsx)($m,{listName:`Users`,loading:D,fields:[{label:`Name`,value:`first_name`,render:(e,t)=>`${e??``} ${t.last_name??``}`.trim()||t.username},{label:`Email`,value:`email`},{label:`User Type`,value:`user_type_id`,width:160,render:(e,t)=>ke[e]||t?.userType||t?.user_type||(Number(e)>0?`Type ${e}`:`—`)},{label:`Reporting Manager`,value:`reporting_id`,width:180,render:(e,t)=>Ae[e]||t?.reportingName||t?.reporting_name||(Number(e)>0?`User ${e}`:`None`)},{label:`Status`,value:`status`,width:110,sorter:!1,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{label:`Actions`,value:`_actions`,width:150,sorter:!1,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Edit user`,icon:(0,l.jsx)(c.EditOutlined,{}),size:`small`,onClick:()=>ze(t)}),(0,l.jsx)(s.Popconfirm,{title:`Delete user?`,description:`This removes the user from the auth database.`,okText:`Delete`,okButtonProps:{danger:!0},onConfirm:()=>Y(t.user_id),children:(0,l.jsx)(s.Button,{danger:!0,"aria-label":`Delete user`,icon:(0,l.jsx)(c.DeleteOutlined,{}),loading:te===t.user_id,size:`small`})})]})}],dataSource:J.map(e=>({...e,key:e.user_id})),total:y,current:x,pageSize:C,onPageChange:S,onPageSizeChange:e=>{w(e),S(1)},onSearch:e=>{E(e??``),S(1)},rowSelection:!1})]})})},{key:`roles`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.TeamOutlined,{}),` User Types`]}),children:(0,l.jsxs)(`div`,{className:`admin-stack`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Field Config Seed`,style:{marginBottom:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,flexWrap:`wrap`},children:[(0,l.jsx)(`div`,{style:{minWidth:320,flex:1},children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,showSearch:!0,value:_e,options:he,placeholder:Ce?`All modules already seeded`:`Select modules or collections to seed`,disabled:ye||xe||Ce,loading:ye,onChange:ve,style:{width:`100%`}})}),(0,l.jsx)(s.Button,{type:`primary`,loading:xe,disabled:ye||_e.length===0,onClick:Te,children:`Seed Field Config`})]}),(0,l.jsx)(nD,{type:`secondary`,style:{display:`block`,marginTop:8,fontSize:12},children:Ce?`Seed is disabled because all configured modules already have user type field config data.`:`Already seeded modules are disabled. New modules or collections can still be seeded.`})]}),(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:`User Types`}),(0,l.jsx)(nD,{type:`secondary`,children:`Role level permissions are inherited by users.`})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:Ue,children:`Add Role`})]}),(0,l.jsx)($m,{listName:`User Types`,loading:d,fields:[{label:`User Type`,value:`user_type_name`},{label:`Description`,value:`description`},{label:`Status`,value:`status`,width:110,sorter:!1,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{label:`Actions`,value:`_actions`,width:260,sorter:!1,render:(e,t)=>{let n=Number(t.role_type)===1;return(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Configure role`,size:`small`,onClick:()=>Ve(`role`,t),children:`Config`}),(0,l.jsx)(s.Button,{"aria-label":`Edit role`,disabled:!n,icon:(0,l.jsx)(c.EditOutlined,{}),size:`small`,onClick:()=>X(t)}),n&&!lD(t)&&(0,l.jsx)(s.Popconfirm,{title:`Delete role?`,onConfirm:()=>Ge(t.user_type_id),children:(0,l.jsx)(s.Button,{"aria-label":`Delete role`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),size:`small`})})]})}}],dataSource:k.map(e=>({...e,key:e.user_type_id,roleId:e.user_type_id,roleName:e.user_type_name})),total:k.length,rowSelection:!1})]})]})},{key:`menus`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MenuOutlined,{}),` Menus`]}),children:(0,l.jsx)(JE,{})},{key:`configurations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Configurations`]}),children:(0,l.jsxs)(`section`,{className:`admin-section admin-config-workspace`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:`Configuration Center`}),(0,l.jsx)(nD,{type:`secondary`,children:`CORE-THEME admin modules embedded into the admin dashboard.`})]}),(0,l.jsxs)(s.Tag,{color:`blue`,children:[Pe.length,` configurations`]})]}),(0,l.jsx)(s.Tabs,{className:`admin-config-tabs`,defaultActiveKey:`form-groups`,tabPosition:`left`,items:Pe.map(e=>({key:e.key,label:e.label,children:(0,l.jsxs)(`div`,{className:`admin-config-panel`,children:[(0,l.jsx)(`div`,{className:`admin-config-panel-head`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:e.title}),(0,l.jsx)(nD,{type:`secondary`,children:e.description})]})}),(0,l.jsx)(`div`,{className:`admin-config-panel-body`,children:e.component})]})}))})]})},{key:`integrations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` Integrations`]}),children:(0,l.jsxs)(`section`,{className:`admin-section admin-config-workspace`,children:[(0,l.jsx)(`div`,{className:`admin-section-head`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:`Integrations`}),(0,l.jsx)(nD,{type:`secondary`,children:`Configure external services used by onboarding and other workflows.`})]})}),(0,l.jsx)(`div`,{className:`admin-config-panel`,children:(0,l.jsx)(`div`,{className:`admin-config-panel-body`,children:(0,l.jsx)(QT,{})})})]})}]})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,title:`Configure User Type: ${G?.record?.user_type_name??``}`,open:!!G,onCancel:()=>fe(null),footer:null,destroyOnHidden:!0,width:900,children:[(0,l.jsx)(`div`,{className:`uss-config-toggle`,style:{marginBottom:12},children:[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`},{key:`permissions`,label:`Permissions`},{key:`actions`,label:`Actions`}].map(e=>(0,l.jsx)(`button`,{type:`button`,className:`uss-config-btn${pe===e.key?` active`:``}`,onClick:()=>me(e.key),children:e.label},e.key))}),G&&pe===`permissions`?(0,l.jsx)(gD,{title:`Role Permissions`,description:`Configure menu permissions for this user type`,selectedName:Oe?.user_type_name,loading:p,saving:h,rows:L,onChange:Ie,onMove:He,onSave:Le}):G&&pe===`actions`?(0,l.jsx)(OS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name}},`${G.record?.user_type_id}-actions`):G&&pe===`form`?(0,l.jsx)(bS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name}},`${G.record?.user_type_id}-form`):G?(0,l.jsx)(lS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name},configType:pe},`${G.record?.user_type_id}-${pe}`):null]}),(0,l.jsx)(s.Modal,{className:`admin-role-modal`,title:ce?`Edit User Type`:`Create User Type`,open:oe,onCancel:()=>se(!1),onOk:()=>i.submit(),okText:ce?`Save`:`Next`,confirmLoading:ue,destroyOnHidden:!0,width:900,children:(0,l.jsxs)(s.Form,{form:i,layout:`vertical`,onFinish:We,children:[(0,l.jsx)(s.Form.Item,{name:`user_type_name`,label:`Role name`,rules:[{required:!0,message:`Role name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Recruiter`})}),(0,l.jsx)(s.Form.Item,{name:`description`,label:`Description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3})}),(0,l.jsx)(s.Form.Item,{name:`status`,label:`Status`,children:(0,l.jsx)(s.Select,{options:[{value:`ACTIVE`},{value:`INACTIVE`}]})})]})}),(0,l.jsx)(s.Modal,{className:`admin-user-modal`,title:V?`Edit User`:`Add User`,open:z,onCancel:()=>B(!1),onOk:()=>r.submit(),confirmLoading:ee,destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:r,layout:`vertical`,requiredMark:!1,onFinish:Be,children:[(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{label:`First Name`,name:`first_name`,rules:[{required:!0,message:`First name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`John`})}),(0,l.jsx)(s.Form.Item,{label:`Last Name`,name:`last_name`,children:(0,l.jsx)(s.Input,{placeholder:`Doe`})})]}),(0,l.jsx)(s.Form.Item,{label:`Username`,name:`username`,rules:[{required:!0,message:`Username is required`}],children:(0,l.jsx)(s.Input,{placeholder:`john.doe`})}),(0,l.jsx)(s.Form.Item,{label:`Email`,name:`email`,rules:[{required:!0,message:`Email is required`},{type:`email`,message:`Enter a valid email`}],children:(0,l.jsx)(s.Input,{placeholder:`john@example.com`})}),(0,l.jsx)(s.Form.Item,{label:`Password`,name:`password`,rules:V?[]:[{required:!0,message:`Password is required`}],children:(0,l.jsx)(s.Input.Password,{placeholder:V?`Leave empty to keep current password`:`Password`})}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{label:`Mobile`,name:`mobile`,children:(0,l.jsx)(s.Input,{placeholder:`9999999999`})}),(0,l.jsx)(s.Form.Item,{label:`User Type`,name:`user_type_id`,rules:[{required:!0,message:`User type is required`}],children:(0,l.jsx)(s.Select,{placeholder:`Select user type`,onChange:()=>{ie([]),queueMicrotask(()=>{let e=Number(r.getFieldValue(`user_type_id`)??0);e&&(W(!0),Ax(e).then(e=>{ie(e.filter(e=>!V||e.user_id!==V.user_id))}).catch(e=>{s.message.error(e.message||`Unable to load reporting users`),ie([])}).finally(()=>{W(!1)}))})},options:Ne})})]}),(0,l.jsx)(s.Form.Item,{label:`Reporting Manager`,name:`reporting_id`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:ae,placeholder:`Select reporting manager`,optionFilterProp:`label`,options:[{label:`None`,value:0},...Me]})}),(0,l.jsx)(s.Form.Item,{label:`Profile Image`,name:`profile_image`,children:(0,l.jsx)(s.Input,{placeholder:`https://...`})}),(0,l.jsx)(s.Form.Item,{label:`Status`,name:`status`,children:(0,l.jsx)(s.Select,{options:[{label:`ACTIVE`,value:`ACTIVE`},{label:`INACTIVE`,value:`INACTIVE`}]})})]})})]})})]})}var vD=_D;function yD(e,t){return String(e||t).replace(/\/\*$/,``).replace(/\/+$/,``)||t}function bD({loginPath:e=`/login`,adminPath:t=`/admin`,fallbackPath:n=`/`}){let r=(0,d.useNavigate)(),i=yD(e,`/login`),a=yD(t,`/admin`),o=`${a}/*`;return(0,l.jsxs)(d.Routes,{children:[(0,l.jsx)(d.Route,{path:i,element:(0,l.jsx)(Fb,{defaultRedirectPath:a,onLogin:()=>r(a,{replace:!0})})}),(0,l.jsx)(d.Route,{path:o,element:(0,l.jsx)(Db,{loginPath:i,children:(0,l.jsx)(Pb,{children:(0,l.jsx)(vD,{onLogout:()=>r(i,{replace:!0})})})})}),(0,l.jsx)(d.Route,{path:n,element:(0,l.jsx)(d.Navigate,{to:a,replace:!0})}),(0,l.jsx)(d.Route,{path:`*`,element:(0,l.jsx)(d.Navigate,{to:a,replace:!0})})]})}function xD(e){return(0,l.jsx)(d.BrowserRouter,{children:(0,l.jsx)(bD,{...e})})}function SD(e){return Array.isArray(e)?e.map(String).map(e=>e.trim()).filter(Boolean):String(e??``).split(`,`).map(e=>e.trim()).filter(Boolean)}function CD(e){return SD(e).every(e=>/^[^,\s@]+@[^,\s@]+\.[^\s@]{2,}$/.test(e))}var{Text:wD}=s.Typography,TD=new Set([`file`,`document`,`attachment`]);function ED(e){return TD.has(String(e?.type??``).trim().toLowerCase())}function DD(e){return String(e??``).trim().toLowerCase().replace(/[^a-z0-9]/g,``)}function OD(e){return e?typeof e==`string`?e:String(typeof e==`object`?e?._id??e?.id??e?.$oid??``:e):``}function kD(e,t,n){if(!e)return``;let r=DD(t),i=DD(n);if(!r||r===i||r.replace(/s$/,``)===i.replace(/s$/,``))return OD(e?._id??e?.id);let a=r.replace(/s$/,``),o=[`${a}Id`,`${r}Id`,a,r,`${a}._id`,`${r}._id`];for(let t of o){let n=OD(PD(e,t));if(n)return n}return``}async function AD(e){let t=e?.fileUrl??e?.url??e?.downloadUrl;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load attachment ${e?.fileName||``}`.trim());let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.uniqueName??`attachment`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function jD(e,t,r){if(!t)return[];let i=[];(e?.placeholders??[]).forEach(e=>{(e?.holders??[]).filter(ED).forEach(a=>{let o=kD(t,e?.moduleName,r);o&&i.push((async()=>{let t=await n.yn(e.moduleName,o,a.value);return Promise.all((t?.data??[]).map(AD))})())})});let a=(await Promise.all(i)).flat().filter(Boolean),o=new Set;return a.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!o.has(t)&&(o.add(t),!0)})}function MD(e,t){return[...new Set([...SD(e),...SD(t)])].join(`, `)}function ND(e=[],t=[]){let n=new Set;return[...e,...t].filter(e=>{if(!e)return!1;let t=`${e.name}:${e.size}:${e.type}`;return!n.has(t)&&(n.add(t),!0)})}function PD(e,t,n=``){let r=String(n??``).trim().toLowerCase();return String(t??``).split(`.`).reduce((e,t)=>{let n=e;return Array.isArray(n)&&r===`last`&&(n=n.at(-1)),n?.[t]},e)}function FD(e,t,n){if(!n)return String(e??``);let r=new Map;return(t??[]).forEach(e=>(e.holders??[]).forEach(e=>{r.set(e.key,ED(e)?``:PD(n,e.value,e.arrayMode))})),String(e??``).replace(/{{\.?([\w.]+)}}/g,(e,t)=>{let n=r.get(t);return n==null?e:String(n)})}function ID({value:e,onChange:t,defaultTemplateId:r=``,ready:i=!0,title:a=`Mail`,hint:u,bccHint:d,afterBcc:f,beforeFields:p,className:m=``,contextRecords:h=[],moduleName:g=``}){let _=(0,o.useRef)(``),v=n=>t?.({...e,...n});async function y(t,n=!1){if(t)try{let r=await Zw(t),i=h[0],a=await jD(r,i,g);v({to:MD(e.to,(r?.toMail??[]).map(e=>FD(e,r?.placeholders,i))),cc:MD(e.cc,(r?.ccMail??[]).map(e=>FD(e,r?.placeholders,i))),bcc:MD(e.bcc,(r?.bccMail??[]).map(e=>FD(e,r?.placeholders,i))),subject:FD(r?.subject,r?.placeholders,i),contents:FD(r?.body,r?.placeholders,i),attachments:ND(e.attachments,a)}),n||s.message.success(`Loaded ${r?.name||`email template`}`)}catch(e){n||s.message.error(e?.message||`Could not load email template`)}}return(0,o.useEffect)(()=>{!i||!r||_.current===r||(_.current=r,y(r,!0))},[r,i]),(0,l.jsxs)(`div`,{className:`common-mail-composer ${m}`.trim(),children:[(0,l.jsx)(`div`,{className:`mail-popup__header`,children:(0,l.jsxs)(`div`,{className:`mail-popup__header-brand`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box`,children:(0,l.jsx)(c.MailOutlined,{})}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:a}),u&&(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__header-hint`,children:u})]})]})}),(0,l.jsxs)(`div`,{className:`mail-popup__body`,children:[p&&(0,l.jsxs)(l.Fragment,{children:[p,(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__field-label`,children:`To`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:SD(e.to),onChange:e=>v({to:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`,placeholder:`Add email addresses`}),(0,l.jsxs)(`div`,{className:`mail-popup__cc-bcc-actions`,children:[!e.showCc&&(0,l.jsx)(`span`,{className:`mail-popup__cc-bcc-link`,onClick:()=>v({showCc:!0}),children:`Cc`}),!e.showBcc&&(0,l.jsx)(`span`,{className:`mail-popup__cc-bcc-link`,onClick:()=>v({showBcc:!0}),children:`Bcc`})]})]}),(0,l.jsx)(s.Divider,{}),e.showCc&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__field-label`,children:`Cc`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:SD(e.cc),onChange:e=>v({cc:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`})]}),(0,l.jsx)(s.Divider,{})]}),e.showBcc&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__field-label`,children:`Bcc`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:SD(e.bcc),onChange:e=>v({bcc:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`,placeholder:d})]}),f,(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__field-label`,children:`Subject`}),(0,l.jsx)(s.Input,{variant:`borderless`,value:e.subject,onChange:e=>v({subject:e.target.value}),placeholder:`Enter subject`,className:`mail-popup__field-input`})]}),(0,l.jsx)(s.Divider,{}),!!e.attachments?.length&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__field-label`,children:`Attachments`}),(0,l.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6,padding:`4px 0`},children:e.attachments.map((e,t)=>(0,l.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:4},children:[(0,l.jsx)(c.PaperClipOutlined,{}),e.name]},`${e.name}:${e.size}:${t}`))})]}),(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__message-section`,children:[(0,l.jsx)(wD,{type:`secondary`,className:`mail-popup__message-label`,children:`Message`}),(0,l.jsx)(n.On,{value:e.contents,onChange:e=>v({contents:e})})]})]})]})}var{Text:LD}=s.Typography,RD=/^[a-fA-F0-9]{24}$/,zD=new Set([`file`,`document`,`attachment`]);function BD(e){return e?typeof e==`object`?BD(e.$oid??e._id??e.id??e.oid):String(e).trim():``}async function VD(e){let t=e?.fileUrl??e?.url??e?.downloadUrl;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load attachment ${e?.fileName||``}`.trim());let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.uniqueName??`attachment`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function HD(e,t,r=[]){let i=String(e??``);if(!i||!r.length||!t)return{contents:i,attachments:[]};let a=(await n.Ur(t).catch(()=>[])).filter(e=>zD.has(String(e?.type??``).trim().toLowerCase())).filter(e=>{let t=String(e?.value??e?.field??e?.fieldKey??e?.key??e?.name??``).replace(/^\./,``);return t&&(i.includes(`{{.${t}}}`)||i.includes(`{{${t}}}`))});if(!a.length)return{contents:i,attachments:[]};let o=[];for(let e of a){let a=String(e?.value??e?.field??e?.fieldKey??e?.key??e?.name??``).replace(/^\./,``);i=i.replaceAll(`{{.${a}}}`,``).replaceAll(`{{${a}}}`,``);for(let e of r){let r=String(e?._id??e?.id??``);if(!RD.test(r))continue;let i=await n.yn(t,r,a).catch(()=>({data:[]})),s=await Promise.all((i?.data??[]).map(VD));o.push(...s.filter(Boolean))}}let s=new Set,c=o.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!s.has(t)&&(s.add(t),!0)});return{contents:i,attachments:c}}function UD(e){return e===!0?!0:typeof e==`number`?e===1:typeof e==`string`&&[`true`,`1`,`yes`,`y`,`on`].includes(e.trim().toLowerCase())}function WD(e){return[`candidate`,`candidates`].includes(String(e??``).trim().toLowerCase())}function GD(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&String(t).trim()!==``)return t}}function KD(e){return[GD(e,`jobReferenceId`,`clientJobId`,`jobCode`,`reqId`,`jobId`),GD(e,`jobTitle`,`title`,`name`)].filter(Boolean).join(` - `)||String(GD(e,`_id`,`id`)??`Job`)}function qD(e){let t=GD(e,`_id`,`id`,`jobId`);return t?{value:String(t),label:KD(e),raw:e}:null}function JD(e=[],t=[]){let n=[...t,`email`,`candidateEmail`,`candidate_email`,`emailId`,`mailId`,`alternateEmail`,`altEmail`,`basicDetails.email`,`basicDetails.alternateEmail`,`basicDetails.altEmail`,`candidate.email`,`candidate.emailId`,`submission.email`,`submission.candidateEmail`].filter(Boolean);return e.flatMap(e=>n.map(t=>GD(e,t))).flatMap(e=>Array.isArray(e)?e:[e]).flatMap(SD)}function YD(e){return e?.data?.record??e?.record??e?.data??e}function XD(e){let t=GD(e,`jobId`,`job_id`,`job._id`,`job.id`,`jobs._id`,`jobs.id`);return typeof t==`object`?GD(t,`_id`,`id`,`$oid`):t}function ZD(e={}){return{subject:e.subject??e.Subject??``,contents:e.contents??e.Contents??e.body??e.Body??``,toMail:e.toMail??e.ToMail??[],ccMail:e.ccMail??e.CcMail??[],bccMail:e.bccMail??e.BccMail??[]}}function QD(){let e=(0,d.useNavigate)(),{state:t={}}=(0,d.useLocation)(),{selectedIds:r=[],selectedRecords:i=[],recipients:a=[],subject:c=``,contents:u=``,attachments:f=[],onSend:p,moduleName:m=``,popupAction:h={}}=t,g=String(t.mailTarget??``).toLowerCase()===`lead`||String(m??``).trim().toLowerCase()===`lead`,_=g?BD(t.leadId??i[0]?.leadId??i[0]?._id??i[0]?.id??r[0]):``,v=!g&&(UD(h.requireJobId)||UD(t.requireJobId)||WD(m)),y=(0,o.useMemo)(()=>[h.recipientField,h.recipientPath,t.recipientField,t.recipientPath],[h.recipientField,h.recipientPath,t.recipientField,t.recipientPath]),b=r.join(`|`),x=(0,o.useMemo)(()=>[...a,...JD(i,y)],[a,i,y]),S=g?``:String(t.jobId??XD(i[0])??``).trim(),C=g?``:r[0]??i[0]?._id??i[0]?.id??``,[w,T]=(0,o.useState)(S),[E,D]=(0,o.useState)(v?S:String(S||C||``)),[O,k]=(0,o.useState)({to:[...new Set(x)].join(`, `),cc:``,bcc:``,subject:c,contents:u,attachments:f,showCc:!1,showBcc:!1}),[A,j]=(0,o.useState)(!E),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)([]),[I,L]=(0,o.useState)(!1),[R,z]=(0,o.useState)(!1),B=(0,o.useRef)(!1),V=(0,o.useRef)(``),H=(0,o.useRef)(0);(0,o.useEffect)(()=>{if(!WD(m)||B.current||SD(O.to).length>0||r.length===0||V.current===b)return;let e=!1;return V.current=b,Promise.all(r.map(e=>n.hn(m,e).catch(()=>null))).then(t=>{if(e)return;let n=JD(t.map(YD).filter(Boolean),y);n.length&&k(e=>SD(e.to).length>0?e:{...e,to:[...new Set(n)].join(`, `)})}),()=>{e=!0}},[O.to,m,y,b,r]),(0,o.useEffect)(()=>{if(!E){j(!0);return}let e=++H.current,t=!1;async function n(){j(!1),N(!0),k(e=>({...e,contents:``}));try{let n=ZD(await dn(E)),r=await HD(n.contents||``,m,i),a=r.contents;if(a.trim())try{a=await fn(a,n.subject||c)}catch(n){!t&&e===H.current&&s.message.warning(n?.message||`Mail content formatting failed. Showing original content.`)}if(t||e!==H.current)return;k(e=>({...e,subject:n.subject||e.subject,to:n.toMail?.length?Array.isArray(n.toMail)?n.toMail.join(`, `):String(n.toMail):e.to,cc:n.ccMail?.length?Array.isArray(n.ccMail)?n.ccMail.join(`, `):String(n.ccMail):e.cc,bcc:n.bccMail?.length?Array.isArray(n.bccMail)?n.bccMail.join(`, `):String(n.bccMail):e.bcc,contents:a||r.contents||e.contents,attachments:r.attachments,showCc:e.showCc||!!n.ccMail?.length,showBcc:e.showBcc||!!n.bccMail?.length}))}catch(n){!t&&e===H.current&&v&&s.message.error(n?.message||`Could not load mail template for this Job ID`)}finally{!t&&e===H.current&&(j(!0),N(!1))}}return n(),()=>{t=!0}},[E,v]);function ee(e=w){let t=String(e??``).trim();if(!RD.test(t)){D(``),t&&s.message.warning(`Enter a valid 24-character Job ID`);return}if(t===E){D(``),queueMicrotask(()=>D(t));return}D(t)}function U(e,t){if(!e){D(``),T(``);return}let n=t?.label??``;T(String(n||(e??``))),ee(e)}function te(e){let t=String(e??``).trim();if(T(t),t.length<3){F([]);return}L(!0),ie(t).then(e=>{let t=(Array.isArray(e)?e:[]).map(qD).filter(Boolean);F(t)}).catch(e=>s.message.error(e?.message||`Unable to search jobs`)).finally(()=>L(!1))}let ne=A&&(!v||RD.test(E))&&(!g||RD.test(_))&&SD(O.to).length+SD(O.cc).length+SD(O.bcc).length>0&&CD(O.to)&&CD(O.cc)&&CD(O.bcc)&&O.subject.trim()&&O.contents.trim();async function re(){if(!(!ne||R)){z(!0);try{await pn({jobId:E,leadId:_,toMail:SD(O.to),ccMail:SD(O.cc),bccMail:SD(O.bcc),subject:O.subject,contents:O.contents,attachments:O.attachments??[]}),s.message.success(`Mail sent successfully`),typeof p==`function`&&p({...O,message:O.contents,selectedIds:r}),e(-1)}catch(e){s.message.error(e?.message||`Failed to send mail`)}finally{z(!1)}}}function ae(e){e?.to!==O.to&&(B.current=!0),k(e)}return(0,l.jsx)(s.Drawer,{open:!0,placement:`right`,onClose:()=>e(-1),closable:!1,rootClassName:`mail-popup`,width:620,maskClosable:!1,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>e(-1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:R,disabled:!ne,onClick:re,children:`Send`})]}),children:(0,l.jsx)(s.Spin,{spinning:M,tip:`Loading mail content...`,size:`large`,children:(0,l.jsx)(ID,{value:O,onChange:ae,moduleName:m,defaultTemplateId:v?``:h.defaultTemplateId??t.defaultTemplateId??``,ready:A,contextRecords:i,beforeFields:v?(0,l.jsxs)(`div`,{className:`mail-popup__job-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`Job Title / ID`}),(0,l.jsx)(s.Select,{showSearch:!0,allowClear:!0,filterOption:!1,value:E||void 0,searchValue:w,onSearch:te,onChange:U,onClear:()=>{D(``),T(``),F([])},placeholder:`Minimum 3 characters`,notFoundContent:I||M?(0,l.jsx)(s.Spin,{size:`small`}):null,options:P,className:`mail-popup__job-input`})]}):null})})})}var{Text:$D}=s.Typography,eO=2,tO=`overview.summary.role summary.job summary.role overview.job description.description.about the role.about the job.job title.role.responsibilities.roles responsibilities.roles and responsibilities.roles & responsibilities.key responsibilities.requirements.required skills.preferred skills.technical skills.key skills.skills.competencies.nice to have.good to have.qualifications.required qualifications.preferred qualifications.education.experience.benefits`.split(`.`),nO=new Set(tO),rO=/(education|qualification)/i,iO=/(skill|competenc)/i,aO=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),oO=e=>e.replace(/\w[^\s/]*/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),sO=e=>[...new Set(e)];function cO(e){let t=String(e);return t=t.replace(/<\s*(br|\/p|\/div|\/h[1-6]|\/li|\/tr)\s*\/?>/gi,`
16
+ `}),(0,l.jsxs)(s.Form,{form:u,layout:`vertical`,initialValues:MT,disabled:h,className:`template-editor-form`,children:[(0,l.jsxs)(`div`,{className:`template-editor-grid`,children:[(0,l.jsx)(s.Form.Item,{name:`name`,label:`Template name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Candidate introduction`})}),(0,l.jsx)(s.Form.Item,{name:`module`,label:`Module`,rules:[{required:!0}],children:(0,l.jsx)(s.Select,{showSearch:!0,optionFilterProp:`label`,options:r,onChange:e=>{u.setFieldValue(`action`,``),C(e)}})}),(0,l.jsx)(s.Form.Item,{name:`action`,label:`Action`,rules:[{required:!0}],tooltip:`Pick a Row Action, or TYPE a system action key. Not every email comes from a row action — the credentials mail sent when an employer's recruiters are provisioned uses "accountCreated", which is raised by a workflow and so never appears in this list.`,children:(0,l.jsx)(s.Select,{showSearch:!0,mode:`tags`,maxCount:1,optionFilterProp:`label`,options:_,placeholder:`Select a row action, or type a system key (e.g. accountCreated)`})}),(0,l.jsx)(s.Form.Item,{name:`clientId`,label:`Client scope (optional)`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,options:i,placeholder:`Available to every client`})})]}),(0,l.jsx)(s.Form.Item,{name:`description`,label:`Description`,children:(0,l.jsx)(s.Input.TextArea,{rows:2})}),(0,l.jsxs)(`div`,{className:`template-editor-grid template-editor-grid--three`,children:[(0,l.jsx)(s.Form.Item,{name:`toMail`,label:`Default To`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})}),(0,l.jsx)(s.Form.Item,{name:`ccMail`,label:`Default Cc`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})}),(0,l.jsx)(s.Form.Item,{name:`bccMail`,label:`Default Bcc`,children:(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`]})})]}),(0,l.jsxs)(`div`,{className:`template-editor-workspace`,style:{display:`grid`,gridTemplateColumns:`minmax(0, 1.2fr) minmax(360px, 0.8fr)`,gap:20,alignItems:`start`,marginTop:4},children:[(0,l.jsxs)(`div`,{className:`template-editor-compose-pane`,style:{minWidth:0,padding:16,border:`1px solid #e5e7eb`,borderRadius:10,background:`#fff`},children:[(0,l.jsx)(jT,{strong:!0,style:{display:`block`,marginBottom:12},children:`Email content`}),(0,l.jsx)(s.Form.Item,{name:`subject`,label:`Subject`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Email subject — drag placeholders here`,onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect=`copy`}})}),(0,l.jsx)(s.Form.Item,{label:`Message`,required:!0,style:{marginBottom:0},children:(0,l.jsx)(`div`,{onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect=`copy`},style:{minHeight:320},children:(0,l.jsx)(n.On,{value:d,onChange:f,placeholder:`Write the reusable email body… Drag placeholders from the right panel.`})})})]}),(0,l.jsxs)(`div`,{className:`template-placeholder-panel`,style:{position:`sticky`,top:0,maxHeight:`calc(100vh - 190px)`,overflowY:`auto`,padding:16,border:`1px solid #dbeafe`,borderRadius:10,background:`#f8fbff`},children:[(0,l.jsx)(jT,{strong:!0,style:{display:`block`},children:`All module placeholders`}),(0,l.jsx)(jT,{type:`secondary`,style:{display:`block`,marginTop:4},children:`Drag a placeholder into Subject or Message. You can also click a placeholder to append it to the message.`}),A.map(e=>(0,l.jsxs)(`div`,{style:{marginTop:14},children:[(0,l.jsx)(jT,{type:`secondary`,strong:!0,children:e.label||e.moduleName}),(0,l.jsx)(`div`,{className:`template-placeholder-list`,style:{marginTop:6},children:e.fields.map(t=>(0,l.jsx)(s.Tooltip,{title:`${t.label||t.key} · ${t.value}`,children:(0,l.jsx)(s.Tag,{color:`blue`,draggable:!0,onDragStart:e=>D(e,t),onClick:()=>E(t),style:{cursor:`grab`,userSelect:`none`,marginBottom:6},children:`{{.${t.key}}}`})},`${e.moduleName}:${t.key}:${t.value}`))})]},e.moduleName)),!A.length&&(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No module fields available`})]})]}),(0,l.jsx)(s.Form.Item,{name:`isActive`,label:`Available in mail composer`,valuePropName:`checked`,style:{marginTop:16},children:(0,l.jsx)(s.Switch,{})})]})]})}function zT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(1),[h,g]=(0,o.useState)(20),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)([]),[x,S]=(0,o.useState)(null),[C,w]=(0,o.useState)(!1),T=(0,o.useMemo)(()=>_.map(e=>({value:e.key??e.module??e.value,label:e.label??e.name??e.key??e.module??e.value})).filter(e=>e.value),[_]);function E(e=p,n=h,r=d){u(!0),Gw({offset:(e-1)*n,limit:n,search:r}).then(({items:e,totalCount:n})=>{t(e),i(n)}).catch(e=>s.message.error(e?.message||`Could not load templates`)).finally(()=>u(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{E(1,h,``)})},[]),(0,o.useEffect)(()=>{Promise.all([n.Sr(),n.mr({limit:200})]).then(([e,t])=>{v(hS(e).map(({value:e,label:t})=>({key:e,label:t}))),b(t)}).catch(()=>{})},[]);async function D(e,n){let r=NT(e);try{await Jw(r,{...e,isActive:n}),t(e=>e.map(e=>NT(e)===r?{...e,isActive:n}:e))}catch(e){s.message.error(e?.message||`Could not update status`)}}async function O(e){try{await Yw(e),s.message.success(`Template deleted`),E(1),m(1)}catch(e){s.message.error(e?.message||`Could not delete template`)}}let k=[{title:`Template`,key:`template`,width:300,ellipsis:!0,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell templates-primary-cell`,children:[(0,l.jsx)(jT,{strong:!0,ellipsis:{tooltip:t.name},children:t.name}),(0,l.jsx)(jT,{type:`secondary`,ellipsis:{tooltip:t.description||t.subject},children:t.description||t.subject||`No description`})]})},{title:`Module`,dataIndex:`module`,key:`module`,width:140,ellipsis:!0,responsive:[`sm`],render:e=>e?(0,l.jsx)(s.Tag,{color:`blue`,children:e}):`—`},{title:`Action`,dataIndex:`action`,key:`action`,width:180,ellipsis:!0,responsive:[`md`],render:e=>e?(0,l.jsx)(jT,{code:!0,ellipsis:{tooltip:e},children:e}):`—`},{title:`Recipients`,key:`recipients`,width:130,responsive:[`lg`],render:(e,t)=>`${(t.toMail?.length??0)+(t.ccMail?.length??0)+(t.bccMail?.length??0)} defaults`},{title:`Active`,dataIndex:`isActive`,key:`active`,width:80,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>D(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{S(NT(t)),w(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this template?`,onConfirm:()=>O(NT(t)),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],A=y.map(e=>({value:e._id??e.id,label:e.clientName??e.name??e._id})).filter(e=>e.value);return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.MailOutlined,{}),title:`Email templates`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{S(null),w(!0)},children:`New template`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(jT,{type:`secondary`,children:`Create reusable, module-aware email content. Modules, actions and placeholders are read from DB configuration.`})]}),(0,l.jsxs)(Z,{title:`${r} template${r===1?``:`s`}`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:()=>E(),children:`Reload`}),children:[(0,l.jsx)(`div`,{className:`admin-config-table-tools`,children:(0,l.jsx)(s.Input,{allowClear:!0,prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search templates`,value:d,onChange:e=>{let t=e.target.value;f(t),m(1),E(1,h,t)}})}),(0,l.jsx)(`div`,{className:`templates-table-viewport`,children:(0,l.jsx)(s.Table,{rowKey:NT,columns:k,dataSource:e,loading:a,className:`fg-table`,size:`small`,tableLayout:`fixed`,sticky:!0,scroll:{x:914,y:`calc(100vh - 410px)`},pagination:{current:p,pageSize:h,total:r,showSizeChanger:!0,responsive:!0,onChange:(e,t)=>{m(e),g(t),E(e,t)}}})})]}),(0,l.jsx)(RT,{open:C,templateId:x,modules:T,clients:A,onClose:()=>w(!1),onSaved:()=>{w(!1),E()}})]})}function BT({open:e,signatureId:t,onClose:r,onSaved:i}){let[a,c]=(0,o.useState)(``),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)({module:`userSignature`,keys:[]}),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!e)return;let n=!1;return queueMicrotask(()=>{_(!0),Promise.all([t?eT(t):Promise.resolve(null),Qw()]).then(([e,t])=>{n||(c(e?.signatureName??``),d(e?.signature??``),p(t??{module:`userSignature`,keys:[]}))}).catch(()=>{n||s.message.error(`Could not load signature details`)}).finally(()=>{n||_(!1)})}),()=>{n=!0}},[e,t]);function v(e){let t=`{{.${e.key}}}`;d(e=>`${e}${e?` `:``}${t}`)}async function y(){if(!a.trim())return s.message.error(`Signature name is required`);if(!u.trim())return s.message.error(`Signature content is required`);h(!0);try{let e=LT(u),n=(f.keys??[]).filter(t=>e.has(t.key)).map(e=>({key:e.key,value:e.value})),r={signatureId:t,signatureName:a,signature:u,signatureLogoPath:``,placeHolder:n.length?[{moduleName:f.module||`userSignature`,holders:n}]:[]};t?await nT(r):await tT(r),s.message.success(t?`Signature updated`:`Signature created`),i()}catch(e){s.message.error(e?.message||`Could not save signature`)}finally{h(!1)}}let b=(f.keys??[]).filter(e=>![`Role_id`,`Role_name`,`Reporting_manager`].includes(e.key)),x=(f.keys??[]).filter(e=>[`Role_id`,`Role_name`,`Reporting_manager`].includes(e.key)),S=e=>(0,l.jsx)(`div`,{className:`template-placeholder-list`,children:e.map(e=>(0,l.jsx)(s.Tooltip,{title:`Mongo field: ${e.value}`,children:(0,l.jsx)(s.Tag,{color:`blue`,style:{cursor:`pointer`},onClick:()=>v(e),children:`{{.${e.key}}}`})},e.key))});return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(820px, 96vw)`,title:t?`Edit signature`:`New signature`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:m,onClick:y,children:t?`Update`:`Create`})]}),children:(0,l.jsxs)(s.Form,{layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{label:`Signature name`,required:!0,children:(0,l.jsx)(s.Input,{value:a,onChange:e=>c(e.target.value)})}),(0,l.jsx)(s.Form.Item,{label:`Signature content`,required:!0,children:(0,l.jsx)(n.On,{value:u,onChange:d,placeholder:`Create the reusable signature…`})}),(0,l.jsxs)(`div`,{className:`template-placeholder-panel`,children:[(0,l.jsx)(jT,{strong:!0,children:`Signature placeholders`}),(0,l.jsx)(jT,{type:`secondary`,children:`Click a placeholder to add it to the signature. Values resolve from MongoDB users and roles when mail is generated.`}),g?(0,l.jsx)(jT,{type:`secondary`,children:`Loading placeholders…`}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)(jT,{strong:!0,children:`User details`}),S(b)]}),(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)(jT,{strong:!0,children:`Role details`}),S(x)]}),!f.keys?.length&&(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No signature placeholders available`})]})]})]})})}function VT(){let[e,t]=(0,o.useState)([]),[n,r]=(0,o.useState)(0),[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)(1),[m,h]=(0,o.useState)(20),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(null);function b(e=f,n=m,i=u){a(!0),$w({offset:(e-1)*n,limit:n,search:i}).then(({items:e,totalCount:n})=>{t(e),r(n)}).catch(()=>s.message.error(`Could not load signatures`)).finally(()=>a(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{b(1,m,``)})},[]);async function x(e,n){try{await iT(e.signatureId,n),t(t=>t.map(t=>t.signatureId===e.signatureId?{...t,isActive:n}:t))}catch{s.message.error(`Could not update status`)}}async function S(e){try{await rT(e),s.message.success(`Signature deleted`),p(1),b(1)}catch{s.message.error(`Could not delete signature`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.MailOutlined,{}),title:`Signature templates`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{y(null),_(!0)},children:`New signature`}),children:(0,l.jsx)(jT,{type:`secondary`,children:`Existing company and user signatures from the shared DB.`})}),(0,l.jsxs)(Z,{title:`${n} signature${n===1?``:`s`}`,children:[(0,l.jsx)(`div`,{className:`admin-config-table-tools`,children:(0,l.jsx)(s.Input,{allowClear:!0,prefix:(0,l.jsx)(c.SearchOutlined,{}),value:u,placeholder:`Search signatures`,onChange:e=>{d(e.target.value),p(1),b(1,m,e.target.value)}})}),(0,l.jsx)(`div`,{className:`templates-table-viewport`,children:(0,l.jsx)(s.Table,{rowKey:`signatureId`,dataSource:e,columns:[{title:`Signature`,dataIndex:`templateName`,key:`name`,width:300,ellipsis:!0,render:e=>(0,l.jsx)(jT,{strong:!0,ellipsis:{tooltip:e},children:e||`Untitled signature`})},{title:`Created`,dataIndex:`createdDt`,key:`created`,width:150,responsive:[`md`],render:e=>e?new Date(e).toLocaleDateString():`—`},{title:`Active`,dataIndex:`isActive`,key:`active`,width:80,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>x(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{y(t.signatureId),_(!0)}}),(0,l.jsx)(s.Popconfirm,{title:`Delete this signature?`,onConfirm:()=>S(t.signatureId),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],loading:i,className:`fg-table`,size:`small`,tableLayout:`fixed`,sticky:!0,scroll:{x:614,y:`calc(100vh - 410px)`},pagination:{current:f,pageSize:m,total:n,responsive:!0,onChange:(e,t)=>{p(e),h(t),b(e,t)}}})})]}),(0,l.jsx)(BT,{open:g,signatureId:v,onClose:()=>_(!1),onSaved:()=>{_(!1),b()}})]})}function HT(){return(0,l.jsx)(s.Tabs,{defaultActiveKey:`email`,className:`admin-config-tabs`,items:[{key:`email`,label:`Email templates`,children:(0,l.jsx)(zT,{})},{key:`signature`,label:`Signatures`,children:(0,l.jsx)(VT,{})}]})}var{Text:UT}=s.Typography,WT={serviceKey:``,label:``,baseUrl:``,authHeader:``,authValue:``,enabled:!0};function GT({open:e,service:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[c,u]=(0,o.useState)(!1);(0,o.useEffect)(()=>{e&&a.setFieldsValue({...WT,...t,authValue:``})},[e,t,a]);async function d(){try{let e=await a.validateFields();u(!0),await n.ni(e),s.message.success(`AI service saved`),i()}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save AI service`)}finally{u(!1)}}return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(560px, 96vw)`,title:t?`Edit AI service`:`New AI service`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:c,onClick:d,children:`Save`})]}),children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,initialValues:WT,children:[(0,l.jsx)(s.Form.Item,{name:`serviceKey`,label:`Service Key`,rules:[{required:!0,message:`Service key is required`}],tooltip:`Referenced by an AI Action's Service Key on any form field (e.g. pyOps).`,children:(0,l.jsx)(s.Input,{placeholder:`pyOps`,disabled:!!t,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`label`,label:`Label`,children:(0,l.jsx)(s.Input,{placeholder:`Resume/JD Parsing Service`})}),(0,l.jsx)(s.Form.Item,{name:`baseUrl`,label:`Base URL`,rules:[{required:!0,message:`Base URL is required`}],children:(0,l.jsx)(s.Input,{placeholder:`https://ai.example.com`,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`authHeader`,label:`Auth Header (optional)`,children:(0,l.jsx)(s.Input,{placeholder:`x-api-key`,className:`fg-mono-input`})}),(0,l.jsx)(s.Form.Item,{name:`authValue`,label:`Auth Value`,tooltip:`Write-only — leave blank to keep the currently saved value.`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?`Unchanged`:``})}),(0,l.jsx)(s.Form.Item,{name:`enabled`,label:`Enabled`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{})})]})})}function KT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null);function p(){i(!0),n.gr().then(e=>t(Array.isArray(e)?e:[])).catch(e=>s.message.error(e?.message||`Could not load AI services`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(()=>{p()})},[]);async function m(e,r){try{await n.ni({...e,enabled:r}),t(t=>t.map(t=>t.serviceKey===e.serviceKey?{...t,enabled:r}:t))}catch(e){s.message.error(e?.message||`Could not update AI service`)}}async function h(e){try{await n.rr(e),s.message.success(`AI service deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete AI service`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`AI Services`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New service`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(UT,{type:`secondary`,children:`Register the AI/automation backends that admin-configured "AI Actions" (Generate/Parse-style buttons on any form field) call. A field's AI Action names a Service Key here — no URL is ever hardcoded in the app.`})]}),(0,l.jsx)(Z,{title:`${e.length} service${e.length===1?``:`s`}`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),children:(0,l.jsx)(s.Table,{rowKey:`serviceKey`,columns:[{title:`Service`,key:`service`,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell`,children:[(0,l.jsx)(UT,{strong:!0,children:t.label||t.serviceKey}),(0,l.jsx)(UT,{type:`secondary`,code:!0,children:t.serviceKey})]})},{title:`Base URL`,dataIndex:`baseUrl`,key:`baseUrl`,ellipsis:!0,render:e=>(0,l.jsx)(UT,{code:!0,ellipsis:{tooltip:e},children:e})},{title:`Auth Header`,dataIndex:`authHeader`,key:`authHeader`,width:140,render:e=>e||`—`},{title:`Enabled`,dataIndex:`enabled`,key:`enabled`,width:90,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:e,onChange:e=>m(t,e)})},{title:``,key:`actions`,width:84,fixed:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this AI service?`,onConfirm:()=>h(t.serviceKey),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:e,loading:r,className:`fg-table`,size:`small`})}),(0,l.jsx)(GT,{open:a,service:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}var{Text:qT}=s.Typography,JT={integrationKey:``,label:``,category:`GENERAL`,updateMethod:`MANUAL`,enabled:!0,provider:``,baseUrl:``,authType:`API_KEY`,authHeader:`x-api-key`,authValue:``,clientId:``,clientSecret:``,tokenUrl:``,createPath:``,statusPath:``,testPath:``,webhookSecret:``,targetModule:``,targetField:``,stageMatchField:``,stageMatchValue:``,stageStatusField:``,providerStatusPath:``,providerReferencePath:``,statusMappings:[{providerStatus:``,applicationStatus:``}]},YT=[{label:`API Key`,value:`API_KEY`},{label:`Bearer Token`,value:`BEARER_TOKEN`},{label:`Basic Authentication`,value:`BASIC_AUTH`},{label:`OAuth 2.0 Client Credentials`,value:`OAUTH2_CLIENT_CREDENTIALS`}];function XT(e){let t=Object.fromEntries((e.statusMappings??[]).filter(e=>e?.providerStatus&&e?.applicationStatus).map(e=>[e.providerStatus.trim(),e.applicationStatus.trim()])),n={...e,statusMapping:e.updateMethod===`API`?{targetModule:e.targetModule,targetField:e.targetField,stageMatchField:e.stageMatchField,stageMatchValue:e.stageMatchValue,stageStatusField:e.stageStatusField,providerStatusPath:e.providerStatusPath,providerReferencePath:e.providerReferencePath,values:t}:void 0};return[`statusMappings`,`targetModule`,`targetField`,`stageMatchField`,`stageMatchValue`,`stageStatusField`,`providerStatusPath`,`providerReferencePath`].forEach(e=>delete n[e]),n}function ZT({open:e,integration:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[u,d]=(0,o.useState)(!1),[f,p]=(0,o.useState)(!1),m=s.Form.useWatch(`updateMethod`,a),h=s.Form.useWatch(`authType`,a),g=m===`API`,_=h===`OAUTH2_CLIENT_CREDENTIALS`;(0,o.useEffect)(()=>{if(!e)return;let n=t?.statusMapping??{};a.setFieldsValue({...JT,...t,authValue:``,clientSecret:``,webhookSecret:``,targetModule:n.targetModule??``,targetField:n.targetField??``,stageMatchField:n.stageMatchField??``,stageMatchValue:n.stageMatchValue??``,stageStatusField:n.stageStatusField??``,providerStatusPath:n.providerStatusPath??``,providerReferencePath:n.providerReferencePath??``,statusMappings:Object.entries(n.values??{}).map(([e,t])=>({providerStatus:e,applicationStatus:t})).concat(Object.keys(n.values??{}).length?[]:[{providerStatus:``,applicationStatus:``}])})},[a,t,e]);async function v(){try{let e=XT(await a.validateFields());d(!0),await n.si(e),s.message.success(`Integration saved`),i()}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save integration`)}finally{d(!1)}}async function y(){try{let e=await a.validateFields([`integrationKey`,`baseUrl`,`testPath`,`authType`,`authHeader`,`authValue`,`clientId`,`clientSecret`,`tokenUrl`]);p(!0);let t=await n.mi(XT({...a.getFieldsValue(!0),...e}));s.message.success(t?.message||`Connection successful${t?.statusCode?` (${t.statusCode})`:``}`)}catch(e){e?.errorFields||s.message.error(e?.message||`Connection test failed`)}finally{p(!1)}}return(0,l.jsx)(s.Drawer,{open:e,onClose:r,width:`min(680px, 96vw)`,title:t?`Edit ${t.label}`:`Add Integration`,destroyOnClose:!0,extra:(0,l.jsxs)(s.Space,{children:[g&&(0,l.jsx)(s.Button,{loading:f,onClick:y,children:`Test Connection`}),(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:u,onClick:v,children:`Save`})]}),children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,initialValues:JT,children:[(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`label`,label:`Integration Name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Background Check`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`integrationKey`,label:`Integration Key`,rules:[{required:!0},{pattern:/^[a-z][a-z0-9_-]{1,63}$/,message:`Use lowercase letters, numbers, _ or -`}],children:(0,l.jsx)(s.Input,{placeholder:`bgc`,disabled:!!t})})})]}),(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`category`,label:`Category`,children:(0,l.jsx)(s.Select,{options:[{value:`ONBOARDING`,label:`Onboarding`},{value:`HRMS`,label:`HRMS`},{value:`PAYROLL`,label:`Payroll`},{value:`ESIGNATURE`,label:`E-Signature`},{value:`VMS`,label:`VMS`},{value:`GENERAL`,label:`General / Custom`}]})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`enabled`,label:`Enabled`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{})})})]}),(0,l.jsx)(s.Form.Item,{name:`updateMethod`,label:`Update Method`,rules:[{required:!0}],children:(0,l.jsx)(s.Radio.Group,{optionType:`button`,buttonStyle:`solid`,options:[{label:`Manual Update`,value:`MANUAL`},{label:`API Integration`,value:`API`}]})}),!g&&(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`This integration will use manual updates.`}),g&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Alert,{type:t?.credentialsConfigured?`success`:`warning`,showIcon:!0,message:t?.credentialsConfigured?`Credentials configured`:`Credentials required`,description:`Secrets are write-only. Leave a secret blank while editing to keep its current value.`,style:{marginBottom:16}}),(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`provider`,label:`Provider`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`Provider name`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`baseUrl`,label:`API Base URL`,rules:[{required:!0,type:`url`}],children:(0,l.jsx)(s.Input,{placeholder:`https://api.provider.com`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`createPath`,label:`Create/Submit Path`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`/v1/requests`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`statusPath`,label:`Status Path`,rules:[{required:!0}],tooltip:`Use {referenceId} as a placeholder.`,children:(0,l.jsx)(s.Input,{placeholder:`/v1/requests/{referenceId}`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`testPath`,label:`Test Connection Path`,rules:[{required:!0}],tooltip:`A safe GET endpoint used only to validate URL and credentials.`,children:(0,l.jsx)(s.Input,{placeholder:`/v1/health`})})})]}),(0,l.jsx)(s.Form.Item,{name:`authType`,label:`Authentication Type`,rules:[{required:!0}],children:(0,l.jsx)(s.Select,{options:YT})}),_?(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`clientId`,label:`Client ID`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`clientSecret`,label:`Client Secret`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.credentialsConfigured?`Unchanged`:`Required`})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{name:`tokenUrl`,label:`Token URL`,rules:[{required:!0,type:`url`}],children:(0,l.jsx)(s.Input,{})})})]}):(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`authHeader`,label:`Authentication Header`,children:(0,l.jsx)(s.Input,{placeholder:`x-api-key`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`authValue`,label:`API Credential`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.credentialsConfigured?`Unchanged`:`Required`})})})]}),(0,l.jsx)(s.Form.Item,{name:`webhookSecret`,label:`Webhook Signing Secret (optional)`,children:(0,l.jsx)(s.Input.Password,{placeholder:t?.webhookConfigured?`Unchanged`:``})}),(0,l.jsxs)(Z,{title:`Status Mapping`,children:[(0,l.jsx)(qT,{type:`secondary`,children:`Map a status from the provider response into a module field or a matching workflow stage.`}),(0,l.jsxs)(s.Row,{gutter:16,style:{marginTop:16},children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`targetModule`,label:`Target Module`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`onboarding`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`targetField`,label:`Target Field`,rules:[{required:!0}],tooltip:`Use stages for a stage-array update, or a direct field name.`,children:(0,l.jsx)(s.Input,{placeholder:`stages`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`providerStatusPath`,label:`Provider Status JSON Path`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`data.status`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{name:`providerReferencePath`,label:`Provider Reference JSON Path`,children:(0,l.jsx)(s.Input,{placeholder:`data.id`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageMatchField`,label:`Stage Match Field`,children:(0,l.jsx)(s.Input,{placeholder:`stageCode`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageMatchValue`,label:`Stage Match Value`,children:(0,l.jsx)(s.Input,{placeholder:`BGC`})})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsx)(s.Form.Item,{name:`stageStatusField`,label:`Stage Status Field`,children:(0,l.jsx)(s.Input,{placeholder:`status`})})})]}),(0,l.jsx)(qT,{strong:!0,children:`Status Values`}),(0,l.jsx)(s.Form.List,{name:`statusMappings`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(s.Space,{direction:`vertical`,style:{width:`100%`,marginTop:8},children:[e.map(e=>(0,l.jsxs)(s.Row,{gutter:12,children:[(0,l.jsx)(s.Col,{flex:`1 1 220px`,children:(0,l.jsx)(s.Form.Item,{...e,name:[e.name,`providerStatus`],rules:[{required:!0,message:`Provider status is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Provider status, e.g. completed`})})}),(0,l.jsx)(s.Col,{flex:`1 1 220px`,children:(0,l.jsx)(s.Form.Item,{...e,name:[e.name,`applicationStatus`],rules:[{required:!0,message:`Application status is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Zinnext status, e.g. CLEARED`})})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{danger:!0,onClick:()=>n(e.name),children:`Remove`})})]},e.key)),(0,l.jsx)(s.Button,{type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>t({providerStatus:``,applicationStatus:``}),children:`Add Status Mapping`})]})})]})]})]})})}function QT(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),p=(0,o.useCallback)(()=>{i(!0),n.Mr().then(e=>t(Array.isArray(e)?e:[])).catch(e=>s.message.error(e?.message||`Could not load integrations`)).finally(()=>i(!1))},[]);(0,o.useEffect)(()=>{queueMicrotask(p)},[p]);async function m(e){try{await n.ar(e),s.message.success(`Integration deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete integration`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ApiOutlined,{}),title:`Integrations`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`Add Integration`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(qT,{type:`secondary`,children:`Configure reusable manual or API integrations for onboarding, payroll, e-signature, VMS, HRMS, and custom workflows.`})]}),(0,l.jsx)(Z,{title:`${e.length} integration${e.length===1?``:`s`}`,children:(0,l.jsx)(s.Table,{rowKey:`integrationKey`,columns:[{title:`Integration`,key:`name`,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-config-primary-cell`,children:[(0,l.jsx)(qT,{strong:!0,children:t.label}),(0,l.jsx)(qT,{type:`secondary`,code:!0,children:t.integrationKey})]})},{title:`Category`,dataIndex:`category`,width:130,render:e=>e||`GENERAL`},{title:`Method`,dataIndex:`updateMethod`,width:110,render:e=>(0,l.jsx)(s.Tag,{color:e===`API`?`blue`:`default`,children:e})},{title:`Provider`,dataIndex:`provider`,render:e=>e||`—`},{title:`Enabled`,dataIndex:`enabled`,width:90,render:e=>(0,l.jsx)(s.Tag,{color:e?`green`:`default`,children:e?`Yes`:`No`})},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}}),(0,l.jsx)(s.Popconfirm,{title:`Delete this integration?`,onConfirm:()=>m(t.integrationKey),children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:e,loading:r,size:`small`,className:`fg-table`})}),(0,l.jsx)(ZT,{open:a,integration:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}var $T=`${t.v}/admin/facebook`;async function eE(e,n={}){let r=t.u(),i=await fetch(`${$T}${e}`,{...n,headers:{"Content-Type":`application/json`,...t.D({"X-App-Id":String(t.y)}),...r?{Authorization:`Bearer ${r}`}:{},...n.headers||{}}}),a=await i.json().catch(()=>({}));if(!i.ok||a?.status===!1)throw Error(a?.error||a?.message||a?.reason||`HTTP ${i.status}`);return a?.data??a}var tE=()=>eE(`/forms`),nE=()=>eE(`/courses`),rE=()=>eE(`/course-mappings`),iE=(e,t=!1)=>eE(t?`/course-mappings/${encodeURIComponent(e.formId)}`:`/course-mappings`,{method:t?`PUT`:`POST`,body:JSON.stringify(e)}),aE=e=>eE(`/course-mappings/${encodeURIComponent(e)}`,{method:`DELETE`}),{Text:oE,Title:sE}=s.Typography,cE=`Unmapped`,lE={fontSize:12,color:`#6b7280`};function uE(e,t){return Array.isArray(e)?e:Array.isArray(e?.[t])?e[t]:[]}function dE(){let[e,t]=(0,o.useState)([]),[n,r]=(0,o.useState)([]),[i,a]=(0,o.useState)([]),[u,d]=(0,o.useState)(!1),[f,p]=(0,o.useState)(!1),[m,h]=(0,o.useState)(``),[g,_]=(0,o.useState)(`all`),[v,y]=(0,o.useState)(!1),[b,x]=(0,o.useState)(null),[S,C]=(0,o.useState)(``),[w]=s.Form.useForm(),T=(0,o.useCallback)(async()=>{d(!0),C(``);let[e,n,i]=await Promise.allSettled([tE(),nE(),rE()]),o=[];e.status===`fulfilled`?t(uE(e.value,`forms`)):o.push(`Facebook forms: ${e.reason.message}`),n.status===`fulfilled`?r(uE(n.value,`courses`)):o.push(`LMS courses: ${n.reason.message}`),i.status===`fulfilled`?a(uE(i.value,`mappings`)):o.push(`Saved mappings: ${i.reason.message}`),C(o.join(` | `)),d(!1)},[]);(0,o.useEffect)(()=>{T()},[T]);let E=(0,o.useMemo)(()=>new Map(i.map(e=>[String(e.formId),e])),[i]),D=(0,o.useMemo)(()=>new Map(n.map(e=>[String(e.courseId),e.courseName])),[n]),O=(0,o.useMemo)(()=>{let t=e.map(e=>({formId:String(e.id),formName:e.name||String(e.id),formStatus:e.status})),n=new Set(t.map(e=>e.formId));return i.forEach(e=>{n.has(e.formId)||t.push({formId:e.formId,formName:e.formName||e.formId,formStatus:`Unknown`})}),t.map(e=>{let t=E.get(e.formId);return{...e,key:e.formId,mapping:t,courseName:t?D.get(t.courseId)||t.courseName:``,status:t?t.isActive?`active`:`inactive`:`unmapped`}})},[e,i,E,D]),k=(0,o.useMemo)(()=>O.filter(e=>g!==`all`&&e.status!==g?!1:`${e.formName} ${e.formId} ${e.courseName}`.toLowerCase().includes(m.trim().toLowerCase())),[O,g,m]),A=O.filter(e=>e.status===`active`).length,j=O.filter(e=>e.status===`unmapped`).length,M=(e=null)=>{x(e?.formId||null),w.resetFields(),w.setFieldsValue({formId:e?.formId,courseId:e?.mapping?.courseId,isActive:e?.mapping?.isActive??!0}),y(!0)},N=async()=>{try{let e=await w.validateFields();p(!0),await iE(e,!!(b&&E.has(b))),s.message.success(`Facebook form mapped to LMS course`),y(!1),await T()}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save mapping`)}finally{p(!1)}},P=async e=>{try{await aE(e),s.message.success(`Mapping removed; future leads will be unmapped unless another rule matches`),await T()}catch(e){s.message.error(e?.message||`Could not remove mapping`)}};return(0,l.jsxs)(`div`,{className:`facebook-course-mapping`,style:{padding:`4px 0 18px`},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`,alignItems:`center`,marginBottom:16},children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(sE,{level:4,style:{marginBottom:4},children:`Facebook Lead Form → Course Mapping`}),(0,l.jsx)(oE,{type:`secondary`,children:`One LMS course may receive leads from multiple Facebook forms and advertisements.`})]}),(0,l.jsxs)(s.Space,{wrap:!0,children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:T,loading:u,children:`Sync Facebook Forms`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>M(),children:`Add Mapping`})]})]}),S&&(0,l.jsx)(s.Alert,{showIcon:!0,type:`warning`,message:`Some configuration data could not be loaded`,description:S,style:{marginBottom:16}}),(0,l.jsxs)(s.Row,{gutter:[12,12],style:{marginBottom:16},children:[(0,l.jsx)(s.Col,{xs:12,md:6,children:(0,l.jsx)(s.Card,{size:`small`,children:(0,l.jsx)(s.Statistic,{title:`Facebook Forms`,value:O.length,prefix:(0,l.jsx)(c.LinkOutlined,{})})})}),(0,l.jsx)(s.Col,{xs:12,md:6,children:(0,l.jsx)(s.Card,{size:`small`,children:(0,l.jsx)(s.Statistic,{title:`Active Mappings`,value:A,prefix:(0,l.jsx)(c.CheckCircleOutlined,{})})})}),(0,l.jsx)(s.Col,{xs:12,md:6,children:(0,l.jsx)(s.Card,{size:`small`,children:(0,l.jsx)(s.Statistic,{title:`Unmapped Forms`,value:j,prefix:(0,l.jsx)(c.WarningOutlined,{})})})}),(0,l.jsx)(s.Col,{xs:12,md:6,children:(0,l.jsx)(s.Card,{size:`small`,children:(0,l.jsx)(s.Statistic,{title:`Available Courses`,value:n.length,prefix:(0,l.jsx)(c.BookOutlined,{})})})})]}),(0,l.jsxs)(s.Card,{size:`small`,children:[(0,l.jsxs)(s.Space,{wrap:!0,style:{marginBottom:14,width:`100%`,display:`flex`},children:[(0,l.jsx)(s.Input,{allowClear:!0,style:{width:320,maxWidth:`100%`},placeholder:`Search form, Form ID or course`,prefix:(0,l.jsx)(c.SearchOutlined,{}),value:m,onChange:e=>h(e.target.value)}),(0,l.jsx)(s.Select,{style:{width:185},value:g,onChange:_,options:[{value:`all`,label:`All mappings`},{value:`active`,label:`Active`},{value:`inactive`,label:`Inactive`},{value:`unmapped`,label:`Unmapped`}]})]}),(0,l.jsx)(s.Table,{rowKey:`formId`,columns:[{title:`Facebook Form`,dataIndex:`formName`,key:`formName`,width:`31%`,render:(e,t)=>(0,l.jsxs)(`div`,{children:[(0,l.jsx)(oE,{strong:!0,children:e}),(0,l.jsxs)(`div`,{style:lE,children:[`Form ID: `,t.formId]})]})},{title:`LMS Course`,dataIndex:`courseName`,key:`courseName`,render:(e,t)=>(0,l.jsxs)(`div`,{children:[(0,l.jsx)(oE,{children:e||cE}),t.mapping&&(0,l.jsx)(`div`,{style:lE,children:t.mapping.courseId})]})},{title:`Mapping Status`,dataIndex:`status`,key:`status`,width:158,render:e=>e===`active`?(0,l.jsx)(s.Tag,{color:`success`,children:`Active`}):e===`inactive`?(0,l.jsx)(s.Tag,{color:`default`,children:`Inactive`}):(0,l.jsx)(s.Tag,{color:`warning`,children:`Unmapped`})},{title:`Actions`,key:`actions`,width:116,render:(e,t)=>(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{size:`small`,title:`Add or edit mapping`,icon:t.mapping?(0,l.jsx)(c.EditOutlined,{}):(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>M(t)}),t.mapping&&(0,l.jsx)(s.Popconfirm,{title:`Remove this mapping?`,description:`Existing LMS leads will not be changed.`,onConfirm:()=>P(t.formId),children:(0,l.jsx)(s.Button,{size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:k,loading:u,size:`middle`,scroll:{x:680},pagination:{pageSize:10,showSizeChanger:!1,showTotal:e=>`${e} Facebook forms`},locale:{emptyText:(0,l.jsx)(s.Empty,{description:`No Facebook forms found`})}}),(0,l.jsx)(oE,{type:`secondary`,style:{fontSize:12},children:`Ad count isn't available from the current forms API. Multiple ads using one Form ID need just one mapping. Multiple Form IDs can select the same LMS course. Existing lead courses are not changed when mappings are edited.`})]}),(0,l.jsx)(s.Drawer,{title:b&&E.has(b)?`Edit Course Mapping`:`Add Course Mapping`,width:440,open:v,destroyOnClose:!0,onClose:()=>y(!1),extra:(0,l.jsx)(s.Button,{type:`primary`,onClick:N,loading:f,children:`Save Mapping`}),children:(0,l.jsxs)(s.Form,{form:w,layout:`vertical`,initialValues:{isActive:!0},children:[(0,l.jsx)(s.Form.Item,{name:`formId`,label:`Facebook Lead Form`,rules:[{required:!0,message:`Select a Facebook form`}],children:(0,l.jsx)(s.Select,{showSearch:!0,optionFilterProp:`label`,placeholder:`Select Facebook form`,disabled:!!b,options:O.map(e=>({value:e.formId,label:`${e.formName} (${e.formId})`,disabled:!b&&!!e.mapping}))})}),(0,l.jsx)(s.Form.Item,{name:`courseId`,label:`Available LMS Course`,rules:[{required:!0,message:`Select an LMS course`}],children:(0,l.jsx)(s.Select,{showSearch:!0,optionFilterProp:`label`,placeholder:`Select LMS course`,options:n.map(e=>({value:e.courseId,label:e.courseName}))})}),(0,l.jsx)(s.Form.Item,{name:`isActive`,label:`Mapping Status`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{checkedChildren:`Active`,unCheckedChildren:`Inactive`})}),(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`Multiple forms can map to the same course`,description:`The selected course will be saved as courseId on newly imported Facebook leads. Forms without an active mapping can still import with course mapping pending.`})]})})]})}var{Text:$}=s.Typography;function fE({rows:e,onChange:t,keyPlaceholder:n,valuePlaceholder:r}){let i=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),a=n=>t(e.filter((e,t)=>t!==n));return(0,l.jsxs)(`div`,{children:[e.map((e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:6},children:[(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:n,value:e.key,onChange:e=>i(t,{key:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(`span`,{style:{color:`#94a3b8`,alignSelf:`center`},children:`→`}),(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:r,value:e.value,onChange:e=>i(t,{value:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>a(t)})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:6},onClick:()=>t([...e,{key:``,value:``}]),children:`Add`})]})}function pE({rows:e,onChange:t,keyPlaceholder:n=`field`,valuePlaceholder:r=`literal or {{field.path}}`}){let i=(n,r)=>t(e.map((e,t)=>t===n?{...e,...r}:e)),a=n=>t(e.filter((e,t)=>t!==n));return(0,l.jsxs)(`div`,{children:[e.map((e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:6,marginTop:6},children:[(0,l.jsx)(s.Input,{size:`small`,style:{flex:1},placeholder:n,value:e.key,onChange:e=>i(t,{key:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Input,{size:`small`,style:{flex:1.6},placeholder:r,value:e.value,onChange:e=>i(t,{value:e.target.value}),className:`fg-mono-input`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>a(t)})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:6},onClick:()=>t([...e,{key:``,value:``}]),children:`Add`}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:11,display:`block`,marginTop:4},children:[`Values are read as JSON when possible (true, 123, ["a","b"]) — otherwise kept as literal text. Use `,(0,l.jsx)(`code`,{children:`{{field.path}}`}),` to reference a payload field, or `,(0,l.jsx)(`code`,{children:`{{now}}`}),` for the current time.`]})]})}function mE(e){return Object.entries(e??{}).map(([e,t])=>({key:e,value:String(t??``)}))}function hE(e){let t={};for(let n of e??[])n.key?.trim()&&(t[n.key.trim()]=n.value??``);return t}function gE(e){return Object.entries(e??{}).map(([e,t])=>({key:e,value:typeof t==`string`?t:JSON.stringify(t)}))}function _E(e){let t={};for(let n of e??[]){if(!n.key?.trim())continue;let e=n.value;if(typeof e==`string`){let t=e.trim();if(t!==``)try{e=JSON.parse(t)}catch{}}t[n.key.trim()]=e}return t}function vE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceModule:``,sourceIdField:``,required:!1,...t??{},fieldMapRows:mE(t?.fieldMap)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:640,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.DatabaseOutlined,{}),` `,t?`Edit Denormalize Rule`:`New Denormalize Rule`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceModule?.trim())return s.message.error(`Source module is required`);if(!i.sourceIdField?.trim())return s.message.error(`Source id field is required`);let{fieldMapRows:e,...t}=i;r({...t,fieldMap:hE(e)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source module`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`job`,value:i.sourceModule??``,onChange:e=>u(`sourceModule`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source id field (on THIS payload)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobId`,value:i.sourceIdField??``,onChange:e=>u(`sourceIdField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!i.required,onChange:e=>u(`required`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Required — block the write if the source record can't be found`})]}),(0,l.jsxs)(`div`,{style:{marginTop:16},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Field map (source field → this payload's field)`}),(0,l.jsx)(fE,{rows:i.fieldMapRows??[],onChange:e=>u(`fieldMapRows`,e),keyPlaceholder:`jobTitle`,valuePlaceholder:`jobTitle`})]})]})})}function yE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceField:``,targetField:``,sourceCollection:``,idField:``,idOutputKey:``,stampNow:``,...t??{},fieldMapRows:mE(t?.fieldMap)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:640,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Array Enrichment`:`New Array Enrichment`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceField?.trim())return s.message.error(`Source field is required`);if(!i.targetField?.trim())return s.message.error(`Target field is required`);let{fieldMapRows:e,...t}=i;r({...t,fieldMap:hE(e)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source field (array of ids on this payload)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruitersData`,value:i.sourceField??``,onChange:e=>u(`sourceField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Target field (enriched array written here)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruiters`,value:i.targetField??``,onChange:e=>u(`targetField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source collection`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`users (default)`,value:i.sourceCollection??``,onChange:e=>u(`sourceCollection`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Id field on that collection`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`legacyUserId (default)`,value:i.idField??``,onChange:e=>u(`idField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:16},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Field map (source collection field → output key)`}),(0,l.jsx)(fE,{rows:i.fieldMapRows??[],onChange:e=>u(`fieldMapRows`,e),keyPlaceholder:`firstName`,valuePlaceholder:`recruiterName`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Also write the matched id as`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruiterId`,value:i.idOutputKey??``,onChange:e=>u(`idOutputKey`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Also stamp the current time as`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`assignedDateTime`,value:i.stampNow??``,onChange:e=>u(`stampNow`,e.target.value),className:`fg-mono-input`})]})]})]})})}function bE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({sourceField:``,targetField:``,uploadedFileNameField:``,uniqueNameField:``,uploadedAtField:``,uploadedByField:``,arrayMode:!1,nameFromField:``,nameOutputField:``,historyField:``,historySnapshotKey:``,historyReason:``,...t??{},staticFieldRows:mE(t?.staticFields),arrayFieldNameRows:mE(t?.arrayFieldNames)})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:760,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.DatabaseOutlined,{}),` `,t?`Edit File Field Map`:`New File Field Map`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.sourceField?.trim())return s.message.error(`Source field (the multipart upload key) is required`);if(!i.targetField?.trim())return s.message.error(`Target field is required`);let{staticFieldRows:e,arrayFieldNameRows:t,...n}=i;r({...n,staticFields:hE(e),arrayFieldNames:hE(t)})},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Turns one uploaded file field into a nested object (or array of objects) instead of a flat S3 path string — for schemas like a candidate's resume/passport/visa that store location + filename + who/when as sub-fields.`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Source field (multipart upload key)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume`,value:i.sourceField??``,onChange:e=>u(`sourceField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12},children:[`Target field `,i.arrayMode?`(array)`:`(location sub-field)`]}),(0,l.jsx)(s.Input,{size:`small`,placeholder:i.arrayMode?`documents`:`resume.location`,value:i.targetField??``,onChange:e=>u(`targetField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!i.arrayMode,onChange:e=>u(`arrayMode`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Array mode — every uploaded file becomes one element (e.g. "documents")`})]}),i.arrayMode?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Sub-field names (location / uploadedFileName / uniqueName → this schema's names)`}),(0,l.jsx)(fE,{rows:i.arrayFieldNameRows??[],onChange:e=>u(`arrayFieldNameRows`,e),keyPlaceholder:`location`,valuePlaceholder:`documentCopyLocation`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Take each element's display name from (payload array field)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documents`,value:i.nameFromField??``,onChange:e=>u(`nameFromField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...reading its field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documentName`,value:i.nameOutputField??``,onChange:e=>u(`nameOutputField`,e.target.value),className:`fg-mono-input`})]})]})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Original filename field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedFileName`,value:i.uploadedFileNameField??``,onChange:e=>u(`uploadedFileNameField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Unique name field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uniqueName`,value:i.uniqueNameField??``,onChange:e=>u(`uniqueNameField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Uploaded-at field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedAt`,value:i.uploadedAtField??``,onChange:e=>u(`uploadedAtField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Uploaded-by field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume.uploadedBy`,value:i.uploadedByField??``,onChange:e=>u(`uploadedByField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Static fields (literal value written alongside the upload)`}),(0,l.jsx)(fE,{rows:i.staticFieldRows??[],onChange:e=>u(`staticFieldRows`,e),keyPlaceholder:`resume.source`,valuePlaceholder:`candidate`})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Append a snapshot to (history array field)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resumeHistory`,value:i.historyField??``,onChange:e=>u(`historyField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...under snapshot key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`resume`,value:i.historySnapshotKey??``,onChange:e=>u(`historySnapshotKey`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`...with reason`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`Initial resume upload`,value:i.historyReason??``,onChange:e=>u(`historyReason`,e.target.value),className:`fg-mono-input`})]})]})]})]})})}function xE({open:e,rule:t,onClose:n,onSave:r}){let[i,a]=(0,o.useState)(()=>({name:``,seedField:``,direction:`up`,stopRole:0,includeSeed:!0,...t??{}})),u=(e,t)=>a(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:n,width:620,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Hierarchy Expansion`:`New Hierarchy Expansion`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:n,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!i.name?.trim())return s.message.error(`Name is required — this is how RelatedUpdates/Notify reference the result`);if(!/^[a-zA-Z0-9_]+$/.test(i.name))return s.message.error(`Name: letters, numbers, underscores only`);r(i)},children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Name`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`chain`,value:i.name??``,onChange:e=>u(`name`,e.target.value),className:`fg-mono-input`}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:11},children:[`Referenced as `,(0,l.jsx)(`code`,{children:`{{hierarchy.`+(i.name||`name`)+`}}`})]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Seed field (blank = the caller)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`recruitersData`,value:i.seedField??``,onChange:e=>u(`seedField`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Direction`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:i.direction||`up`,onChange:e=>u(`direction`,e),options:[{value:`up`,label:`Up — toward admin (reporting chain)`},{value:`down`,label:`Down — toward subordinates (team)`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Stop at role id (up only, 0 = walk to the top)`}),(0,l.jsx)(s.InputNumber,{size:`small`,style:{width:`100%`},min:0,value:i.stopRole??0,onChange:e=>u(`stopRole`,e??0),disabled:i.direction!==`up`})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:i.includeSeed!==!1,onChange:e=>u(`includeSeed`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Include the seed user(s) themselves in the result`})]})]})})}function SE({open:e,rule:t,hierarchyNames:n,onClose:r,onSave:i}){let[a,u]=(0,o.useState)(()=>({collectionName:``,targetModule:``,matchField:``,scopeTenant:!1,forEach:``,insertMode:!!(t?.insertIfMissing&&Object.keys(t.insertIfMissing).length),...t??{},extraFilterRows:gE(t?.extraFilter),pullRows:gE(t?.pull),pushRows:gE(t?.push),setRows:gE(t?.set),setIfNonBlankRows:gE(t?.setIfNonBlank),insertIfMissingRows:gE(t?.insertIfMissing)})),d=(e,t)=>u(n=>({...n,[e]:t})),f=()=>{if(!a.collectionName?.trim()&&!a.targetModule?.trim())return s.message.error(`Set either a collection name or a target module`);let{extraFilterRows:e,pullRows:t,pushRows:n,setRows:r,setIfNonBlankRows:o,insertIfMissingRows:c,insertMode:l,...u}=a;i({...u,extraFilter:_E(e),pull:l?{}:_E(t),push:l?{}:_E(n),set:l?{}:_E(r),setIfNonBlank:l?{}:_E(o),insertIfMissing:l?_E(c):{}})},p=(n??[]).map(e=>({value:`hierarchy.${e}`,label:`{{hierarchy.${e}}}`}));return(0,l.jsx)(s.Modal,{open:e,onCancel:r,width:820,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` `,t?`Edit Related Update`:`New Related Update`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:f,children:`Apply`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsx)(`div`,{className:`fg-form-section-label`,children:`Target`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Collection name (used verbatim)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`hiringProgress`,value:a.collectionName??``,onChange:e=>d(`collectionName`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`— or — target module`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`job`,value:a.targetModule??``,onChange:e=>d(`targetModule`,e.target.value),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Match field (this payload's field holding the target _id)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobId (blank for a tenant-scoped board)`,value:a.matchField??``,onChange:e=>d(`matchField`,e.target.value),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Repeat once per element of (ForEach)`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},allowClear:!0,showSearch:!0,placeholder:`e.g. {{hierarchy.chain}}`,value:a.forEach||void 0,onChange:e=>d(`forEach`,e??``),options:p})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:14},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!a.scopeTenant,onChange:e=>d(`scopeTenant`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Scope filter to the caller's tenant/business/businessUnit`})]}),(0,l.jsxs)(`div`,{style:{marginTop:14},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Extra filter (merged into the match filter)`}),(0,l.jsx)(pE,{rows:a.extraFilterRows??[],onChange:e=>d(`extraFilterRows`,e),keyPlaceholder:`recruiterId`,valuePlaceholder:`{"$in":"{{hierarchy.chain}}"}`})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:18},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!a.insertMode,onChange:e=>d(`insertMode`,e)}),(0,l.jsx)($,{style:{fontSize:13},children:`Insert-only-if-missing (seed a new document instead of updating an existing one)`})]}),a.insertMode?(0,l.jsxs)(`div`,{style:{marginTop:10},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Document to insert when the filter matches nothing`}),(0,l.jsx)(pE,{rows:a.insertIfMissingRows??[],onChange:e=>d(`insertIfMissingRows`,e),keyPlaceholder:`hiringProgressJobStatus`,valuePlaceholder:`"unread"`})]}):(0,l.jsx)(s.Tabs,{size:`small`,style:{marginTop:10},items:[{key:`pull`,label:`Pull`,children:(0,l.jsx)(pE,{rows:a.pullRows??[],onChange:e=>d(`pullRows`,e),keyPlaceholder:`submitted`,valuePlaceholder:`{"candidateId":"{{applicantId}}"}`})},{key:`push`,label:`Push`,children:(0,l.jsx)(pE,{rows:a.pushRows??[],onChange:e=>d(`pushRows`,e),keyPlaceholder:`submitted`,valuePlaceholder:`{"status":"{{submissionStatus}}"}`})},{key:`set`,label:`Set`,children:(0,l.jsx)(pE,{rows:a.setRows??[],onChange:e=>d(`setRows`,e),keyPlaceholder:`hiringProgressJobStatus`,valuePlaceholder:`"unread"`})},{key:`setIfNonBlank`,label:`Set if non-blank`,children:(0,l.jsx)(pE,{rows:a.setIfNonBlankRows??[],onChange:e=>d(`setIfNonBlankRows`,e),keyPlaceholder:`resume.location`,valuePlaceholder:`{{resume.location}}`})}]})]})})}function CE({icon:e,title:t,description:n,rules:r,columns:i,onAdd:a,onEdit:o,onDelete:u}){return(0,l.jsxs)(Z,{title:(0,l.jsxs)(`span`,{children:[e,` `,t]}),extra:(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:a,children:`Add`}),styles:{body:{paddingTop:8}},children:[n&&(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:n}),(0,l.jsx)(s.Table,{rowKey:(e,t)=>t,dataSource:r,columns:[...i,{title:``,key:`actions`,width:80,align:`right`,render:(e,t,n)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>o(n,t)})}),(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>u(n)})})]})}],pagination:!1,size:`small`,className:`fg-table`,locale:{emptyText:(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`Not configured`})}})]})}var wE={sequence:null,duplicateCheck:null,fileVersioning:null,denormalizations:[],arrayEnrichments:[],fileFieldMaps:[],sanitizeFields:[],defaults:{},hierarchyExpands:[],relatedUpdates:[],notify:null,cacheInvalidate:[]};function TE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(``),[d,f]=(0,o.useState)({storage:`mongo`}),[p,m]=(0,o.useState)(`mongo`),[h,g]=(0,o.useState)(wE),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)(null),[T,E]=(0,o.useState)(null),[D,O]=(0,o.useState)(null),[k,A]=(0,o.useState)(null),[j,M]=(0,o.useState)(null);(0,o.useEffect)(()=>{n.Sr().then(e=>{let n=hS(e).map(({value:e,label:t})=>({key:e,label:t}));t(n),n.length&&u(n[0].key)}).catch(()=>t([])).finally(()=>i(!1))},[]),(0,o.useEffect)(()=>{if(!a)return;let e=!1;return(async()=>{v(!0),S(``);try{let t=await n.zr(a);if(e)return;let r=t.gateway??{storage:`mongo`};f(r),m(r.storage||`mongo`),g({...wE,...t.strategies??{}})}catch(t){e||S(t?.message||`Failed to load automations`)}finally{e||v(!1)}})(),()=>{e=!0}},[a]);let N=(0,o.useMemo)(()=>(h.hierarchyExpands??[]).map(e=>e.name).filter(Boolean),[h.hierarchyExpands]);function P(e,t){g(n=>({...n,[e]:t}))}function F(e,t){g(n=>{let r=n.duplicateCheck??{},i=[...r.stages??[]];return i[e]=t,{...n,duplicateCheck:{...r,stages:i}}})}function I(){b(!0);let e={...h,denormalizations:h.denormalizations?.length?h.denormalizations:void 0,arrayEnrichments:h.arrayEnrichments?.length?h.arrayEnrichments:void 0,fileFieldMaps:h.fileFieldMaps?.length?h.fileFieldMaps:void 0,sanitizeFields:h.sanitizeFields?.length?h.sanitizeFields:void 0,hierarchyExpands:h.hierarchyExpands?.length?h.hierarchyExpands:void 0,relatedUpdates:h.relatedUpdates?.length?h.relatedUpdates:void 0,cacheInvalidate:h.cacheInvalidate?.length?h.cacheInvalidate:void 0,defaults:Object.keys(h.defaults??{}).length?h.defaults:void 0};n.ci(a,{gateway:d,strategies:e}).then(()=>{m(d.storage||`mongo`),s.message.success(`Automations saved`)}).catch(e=>s.message.error(e?.message||`Could not save automations`)).finally(()=>b(!1))}function L(){if((d.storage||`mongo`)!==p){s.Modal.confirm({title:`Change how this module persists writes?`,content:`You're switching ${a} from "${p}" to "${d.storage}". `+(d.storage===`mongo`?`This module will stop calling its downstream service and this gateway will own the write + every Strategy below.`:`This module will stop using the Strategies below and go back to calling its downstream service.`)+` Make sure the downstream service / e2e checks are ready before confirming.`,okText:`Confirm cutover`,okButtonProps:{danger:!0},onOk:I});return}I()}let R=[{title:`Source module`,dataIndex:`sourceModule`,key:`sourceModule`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Source id field`,dataIndex:`sourceIdField`,key:`sourceIdField`},{title:`Fields`,key:`fields`,render:(e,t)=>(0,l.jsx)(s.Badge,{count:Object.keys(t.fieldMap??{}).length,showZero:!0,color:`var(--color-brand)`})},{title:`Required`,dataIndex:`required`,key:`required`,width:90,render:e=>e?(0,l.jsx)(s.Tag,{color:`volcano`,children:`Required`}):(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`optional`})}],z=[{title:`Source field`,dataIndex:`sourceField`,key:`sourceField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Target field`,dataIndex:`targetField`,key:`targetField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`From collection`,key:`coll`,render:(e,t)=>t.sourceCollection||`users`},{title:`Fields`,key:`fields`,render:(e,t)=>(0,l.jsx)(s.Badge,{count:Object.keys(t.fieldMap??{}).length,showZero:!0,color:`var(--color-brand)`})}],B=[{title:`Source field`,dataIndex:`sourceField`,key:`sourceField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Target field`,dataIndex:`targetField`,key:`targetField`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Mode`,dataIndex:`arrayMode`,key:`arrayMode`,width:100,render:e=>e?(0,l.jsx)(s.Tag,{color:`blue`,children:`Array`}):(0,l.jsx)(s.Tag,{children:`Single`})},{title:`History`,dataIndex:`historyField`,key:`historyField`,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`—`})}],V=[{title:`Name`,dataIndex:`name`,key:`name`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:`{{hierarchy.`+e+`}}`})},{title:`Seed field`,dataIndex:`seedField`,key:`seedField`,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`caller`})},{title:`Direction`,dataIndex:`direction`,key:`direction`,render:e=>(0,l.jsx)(s.Tag,{color:e===`down`?`blue`:`purple`,children:e===`down`?`Down — team`:`Up — chain`})},{title:`Stop role`,dataIndex:`stopRole`,key:`stopRole`,width:90,render:e=>e||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`top`})}],H=[{title:`Target`,key:`target`,render:(e,t)=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:t.collectionName||t.targetModule})},{title:`Match`,key:`match`,render:(e,t)=>t.matchField||(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`tenant-scoped`})},{title:`For each`,key:`forEach`,render:(e,t)=>t.forEach?(0,l.jsx)(s.Tag,{color:`geekblue`,children:`{{${t.forEach}}}`}):(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`once`})},{title:`Mode`,key:`mode`,render:(e,t)=>Object.keys(t.insertIfMissing??{}).length?(0,l.jsx)(s.Tag,{color:`green`,children:`Insert if missing`}):(0,l.jsx)(s.Tag,{children:`Update`})}],ee=e.map(e=>({key:e.key,label:e.label}));return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`Automations`,extra:(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:y,disabled:!a,onClick:L,children:`Save Automations`}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)($,{type:`secondary`,style:{fontSize:13},children:`Config-driven side-effects the common CRUD gateway runs around a create — reference ids, duplicate checks, cross-module field snapshots, reporting-chain hierarchy expansion, board updates, notifications, cache invalidation. Nothing here is module-specific: the same engine serves every module.`})]}),(0,l.jsx)(Z,{styles:{body:{paddingTop:8}},children:(0,l.jsxs)(s.Spin,{spinning:r,children:[(0,l.jsx)(s.Tabs,{activeKey:a,onChange:u,items:ee.map(e=>({...e,children:null})),className:`admin-module-tabs`}),x&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:x,style:{marginBottom:12}}),(0,l.jsxs)(s.Spin,{spinning:_,children:[(0,l.jsxs)(Z,{title:`Gateway`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Selects how a write to this module persists. "Proxy" forwards to a downstream microservice (which owns every side-effect below itself). "Mongo" makes THIS gateway own the write and run every Strategy configured below.`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Storage`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:d.storage||`mongo`,onChange:e=>f(t=>({...t,storage:e})),options:[{value:`mongo`,label:`Mongo — this gateway owns the write`},{value:`proxy`,label:`Proxy — forward to a downstream service`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`File field key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`file`,value:d.fileKey??``,onChange:e=>f(t=>({...t,fileKey:e.target.value})),className:`fg-mono-input`})]})]}),d.storage===`proxy`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Base URL env var`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`JOBS_SERVICE_URL`,value:d.baseUrlEnv??``,onChange:e=>f(t=>({...t,baseUrlEnv:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Base URL (fallback)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`http://...`,value:d.baseUrl??``,onChange:e=>f(t=>({...t,baseUrl:e.target.value})),className:`fg-mono-input`})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginTop:12},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Create path`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`/v1/jobs`,value:d.createPath??``,onChange:e=>f(t=>({...t,createPath:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Update path (%s = id)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`/v1/edit/%s`,value:d.updatePath??``,onChange:e=>f(t=>({...t,updatePath:e.target.value})),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Update method`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:d.updateMethod||`PUT`,onChange:e=>f(t=>({...t,updateMethod:e})),options:[`PUT`,`POST`,`PATCH`].map(e=>({value:e,label:e}))})]})]})]})]}),(0,l.jsxs)(Z,{title:`Reference ID (Sequence)`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.sequence,onChange:e=>P(`sequence`,e?{field:``,prefix:``,counterKey:``}:null)}),(0,l.jsxs)($,{style:{fontSize:13},children:[`Generate a "`,`{prefix}{n}`,`" reference id on create`]})]}),h.sequence&&(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Payload field`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`submissionId`,value:h.sequence.field??``,onChange:e=>P(`sequence`,{...h.sequence,field:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Prefix`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`sub`,value:h.sequence.prefix??``,onChange:e=>P(`sequence`,{...h.sequence,prefix:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Counter key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`submissions`,value:h.sequence.counterKey??``,onChange:e=>P(`sequence`,{...h.sequence,counterKey:e.target.value}),className:`fg-mono-input`})]})]})]}),(0,l.jsxs)(Z,{title:`Check for someone already on file`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Before a new record is saved, look for one that already matches. This is what stops the same person being added twice under slightly different details.`}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.duplicateCheck,onChange:e=>P(`duplicateCheck`,e?{stages:[],policy:`prompt`,displayFields:[],message:``}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Check before saving a new record`})]}),h.duplicateCheck&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:6},children:[(0,l.jsx)(`b`,{children:`Checks run in order, top first, and stop at the first match.`}),` Put your most certain check first — matching an email or a phone number is near proof; matching a name alone is only a maybe, so it belongs lower down.`]}),(h.duplicateCheck.stages??[]).map((e,t)=>(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginBottom:8,alignItems:`flex-end`},children:[(0,l.jsxs)(`div`,{style:{flex:1.6},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12},children:[`Check `,t+1,` — compare these`]}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`email, contactNumber`,value:e.fields??[],onChange:n=>F(t,{...e,fields:n})})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Counts as a match when`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:e.match??`all`,onChange:n=>F(t,{...e,match:n}),options:[{value:`any`,label:`Any one of them matches`},{value:`all`,label:`All of them match`}]})]}),(0,l.jsxs)(`div`,{style:{flex:.8},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`How sure is it?`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:e.weight??`strong`,onChange:n=>F(t,{...e,weight:n}),options:[{value:`strong`,label:`Almost certainly the same`},{value:`weak`,label:`Possibly the same`}]})]}),(0,l.jsxs)(`div`,{style:{flex:2},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`What to tell the user`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`A candidate with this email already exists — {name}, last updated {age}.`,value:e.message??``,onChange:n=>F(t,{...e,message:n.target.value})})]}),(0,l.jsx)(s.Button,{size:`small`,danger:!0,type:`text`,onClick:()=>P(`duplicateCheck`,{...h.duplicateCheck,stages:(h.duplicateCheck.stages??[]).filter((e,n)=>n!==t)}),children:`Remove`})]},t)),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,style:{marginBottom:12},onClick:()=>P(`duplicateCheck`,{...h.duplicateCheck,stages:[...h.duplicateCheck.stages??[],{fields:[],match:`any`,weight:`strong`}]}),children:`Add another check`}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`When a match is found`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:h.duplicateCheck.policy??`prompt`,onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,policy:e}),options:[{value:`prompt`,label:`Ask, and offer to update the existing one`},{value:`block`,label:`Refuse to save, and name the existing one`}]})]}),(0,l.jsxs)(`div`,{style:{flex:1.2},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Which details identify the record`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`firstName, lastName, email`,value:h.duplicateCheck.displayFields??[],onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,displayFields:e})})]})]}),(0,l.jsx)(`div`,{className:`fg-field-meta-row`,style:{marginTop:10},children:(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Where to open the existing record`}),(0,l.jsx)(s.Input,{size:`small`,className:`fg-mono-input`,placeholder:`/candidate/edit/:id`,value:h.duplicateCheck.editRoute??``,onChange:e=>P(`duplicateCheck`,{...h.duplicateCheck,editRoute:e.target.value})})]})}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:[`The page that opens when someone chooses to update the record you already have. Use `,(0,l.jsx)(`b`,{children:`:id`}),` where the record's id goes. This has to be filled in — it cannot be worked out, because addresses follow no single pattern (this app uses `,(0,l.jsx)(`code`,{children:`/candidate/edit/:id`}),` but `,(0,l.jsx)(`code`,{children:`/clients/edit/:id`}),`). Left blank, the dialog still appears and simply does not navigate, rather than sending anyone to a page that does not exist.`]}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:8},children:[`In any message you can use `,(0,l.jsx)(`b`,{children:`{name}`}),` for the matched record and`,(0,l.jsxs)(`b`,{children:[` `,`{age}`]}),` for how long ago it was last touched ("about 2 months ago"). `,(0,l.jsx)(`b`,{children:`{updatedOn}`}),` gives the date instead. Only the details listed above are shown — nothing else about the record is revealed.`]})]})]}),(0,l.jsxs)(Z,{title:`Keep previous versions of an uploaded file`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:10},children:`Normally a new upload replaces the old one and it is gone. Turn this on and the last few are kept instead — useful when someone sends an updated CV and you may want to look back at the earlier one. Everywhere in the app still shows the newest; the older ones sit behind it.`}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.fileVersioning,onChange:e=>P(`fileVersioning`,e?{fields:[],keep:2,historyKey:``,s3Prefix:``,deleteEvicted:!1}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Keep previous uploads`})]}),h.fileVersioning&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{style:{marginBottom:10},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`},children:`Where the older versions are kept`}),(0,l.jsxs)(s.Radio.Group,{size:`small`,value:h.fileVersioning.store===`documents`?`documents`:`record`,onChange:e=>{let t=e.target.value,n={...h.fileVersioning,store:t===`documents`?`documents`:``};t===`documents`&&(n.linkField=n.linkField||`documentIds`,n.clearRecordKeys=n.clearRecordKeys?.length?n.clearRecordKeys:(n.fields??[]).flatMap(e=>[`${e}History`,`${e}Versions`])),P(`fileVersioning`,n)},children:[(0,l.jsx)(s.Radio,{value:`documents`,children:`In Documents (recommended)`}),(0,l.jsx)(s.Radio,{value:`record`,children:`On the record itself`})]}),(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:[(0,l.jsx)(`b`,{children:`In Documents`}),` keeps the file and all its earlier versions in one place, the same place every other document lives. The record just points at it — so when a candidate is submitted for a job, the submission shows the very same file, and replacing it updates both at once. `,(0,l.jsx)(`b`,{children:`On the record itself`}),` is the older way: each record keeps its own copy of the history, which is why the same résumé could end up recorded several times over and the copies could disagree.`]})]}),h.fileVersioning.store===`documents`&&(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,style:{marginBottom:10},children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`List of attached documents is kept in`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`documentIds`,value:h.fileVersioning.linkField??``,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,linkField:e.target.value})})]}),(0,l.jsxs)(`div`,{style:{flex:1.6},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Old history fields to clear off the record`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`resumeHistory`,value:h.fileVersioning.clearRecordKeys??[],onChange:e=>P(`fileVersioning`,{...h.fileVersioning,clearRecordKeys:e})})]})]}),(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1.4},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Which uploads`}),(0,l.jsx)(s.Select,{mode:`tags`,size:`small`,style:{width:`100%`},placeholder:`resume`,value:h.fileVersioning.fields??[],onChange:e=>P(`fileVersioning`,{...h.fileVersioning,fields:e})})]}),(0,l.jsxs)(`div`,{style:{flex:.7},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`How many to keep`}),(0,l.jsx)(s.Input,{size:`small`,type:`number`,min:1,value:h.fileVersioning.keep??2,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,keep:Number(e.target.value)||1})})]}),(0,l.jsxs)(`div`,{style:{flex:1.4},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Where the files are grouped`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`candidates/{recordId}/resume`,value:h.fileVersioning.s3Prefix??``,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,s3Prefix:e.target.value})})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.fileVersioning.deleteEvicted,onChange:e=>P(`fileVersioning`,{...h.fileVersioning,deleteEvicted:e})}),(0,l.jsx)($,{style:{fontSize:13},children:`Also delete the file once it drops off the end`})]}),(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginTop:6},children:`Leave that switch OFF unless you are sure. With it off, an older file simply stops being shown and can still be recovered. With it on, it is deleted from storage permanently and cannot be brought back. Keeping 2 means a third upload pushes the first one off the end.`})]})]}),(0,l.jsx)(CE,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Denormalizations`,description:`Copy fields from ANOTHER module's record onto this payload before insert (e.g. a submission snapshotting job title/client).`,rules:h.denormalizations??[],columns:R,onAdd:()=>w({index:null,rule:null}),onEdit:(e,t)=>w({index:e,rule:t}),onDelete:e=>P(`denormalizations`,(h.denormalizations??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(CE,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Array Enrichments`,description:`Enrich a payload array of ids (e.g. recruitersData) into objects carrying looked-up fields (name, email) before insert.`,rules:h.arrayEnrichments??[],columns:z,onAdd:()=>E({index:null,rule:null}),onEdit:(e,t)=>E({index:e,rule:t}),onDelete:e=>P(`arrayEnrichments`,(h.arrayEnrichments??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(CE,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`File Field Maps`,description:`Turn an uploaded file field into a nested object (location + filename + who/when) or an array of such objects, instead of a flat S3 path string — needed for schemas like resume/passport/visa.`,rules:h.fileFieldMaps??[],columns:B,onAdd:()=>O({index:null,rule:null}),onEdit:(e,t)=>O({index:e,rule:t}),onDelete:e=>P(`fileFieldMaps`,(h.fileFieldMaps??[]).filter((t,n)=>n!==e))}),(0,l.jsxs)(Z,{title:`Sanitize Fields`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:`Trim and HTML-escape these payload fields before anything else runs — basic XSS-safety for free-text fields (e.g. firstName/lastName) that might later be embedded in an HTML activity comment or email.`}),(0,l.jsx)(s.Select,{mode:`tags`,style:{width:`100%`},placeholder:`firstName, lastName, email`,value:h.sanitizeFields??[],onChange:e=>P(`sanitizeFields`,e)})]}),(0,l.jsxs)(Z,{title:`Defaults`,styles:{body:{paddingTop:8}},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:`Set a field only when the payload doesn't already carry a non-blank value — status defaults, empty arrays.`}),(0,l.jsx)(pE,{rows:gE(h.defaults),onChange:e=>P(`defaults`,_E(e)),keyPlaceholder:`internalSubmissionStatus.internalSubmissionStatusText`,valuePlaceholder:`"Under Evaluation"`})]}),(0,l.jsx)(CE,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Hierarchy Expansions`,description:`Walk the reporting chain up (toward admin) or down (toward a team) from a seed user, publishing the result as {{hierarchy.<name>}} for Related Updates / Notify to use.`,rules:h.hierarchyExpands??[],columns:V,onAdd:()=>A({index:null,rule:null}),onEdit:(e,t)=>A({index:e,rule:t}),onDelete:e=>P(`hierarchyExpands`,(h.hierarchyExpands??[]).filter((t,n)=>n!==e))}),(0,l.jsx)(CE,{icon:(0,l.jsx)(c.ThunderboltOutlined,{}),title:`Related Updates`,description:`Best-effort side-effect writes to other collections after a successful insert — board state, activity logs. Combine with ForEach + a Hierarchy Expansion to seed one document per user in a chain.`,rules:h.relatedUpdates??[],columns:H,onAdd:()=>M({index:null,rule:null}),onEdit:(e,t)=>M({index:e,rule:t}),onDelete:e=>P(`relatedUpdates`,(h.relatedUpdates??[]).filter((t,n)=>n!==e))}),(0,l.jsxs)(Z,{title:`Notify`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:10},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.notify,onChange:e=>P(`notify`,e?{action:``,subjectDefault:``,bodyDefault:``,toReportingManager:!1,toHierarchy:``}:null)}),(0,l.jsx)($,{style:{fontSize:13},children:`Send a best-effort email after a successful insert`})]}),h.notify&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Action (matched against an EmailTemplates doc)`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`internalSubmit`,value:h.notify.action??``,onChange:e=>P(`notify`,{...h.notify,action:e.target.value}),className:`fg-mono-input`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Notify entire hierarchy chain`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},allowClear:!0,placeholder:`pick a Hierarchy Expansion`,value:h.notify.toHierarchy||void 0,onChange:e=>P(`notify`,{...h.notify,toHierarchy:e??``}),options:N.map(e=>({value:e,label:e}))})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginTop:12},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:!!h.notify.toReportingManager,onChange:e=>P(`notify`,{...h.notify,toReportingManager:e})}),(0,l.jsx)($,{style:{fontSize:13},children:`Also notify the caller's direct reporting manager`})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Default subject`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`New submission`,value:h.notify.subjectDefault??``,onChange:e=>P(`notify`,{...h.notify,subjectDefault:e.target.value})})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsx)($,{type:`secondary`,style:{fontSize:12},children:`Default body (used when no EmailTemplates doc matches)`}),(0,l.jsx)(s.Input.TextArea,{rows:4,value:h.notify.bodyDefault??``,onChange:e=>P(`notify`,{...h.notify,bodyDefault:e.target.value}),className:`fg-mono-input`})]})]})]}),(0,l.jsxs)(Z,{title:`Cache Invalidate`,styles:{body:{paddingTop:8}},children:[(0,l.jsxs)($,{type:`secondary`,style:{fontSize:12,display:`block`,marginBottom:8},children:[`Redis key patterns (with `,`{{field}}`,` tokens) to SCAN+DEL after a successful insert.`]}),(0,l.jsx)(s.Select,{mode:`tags`,style:{width:`100%`},placeholder:`jobs:{{tenantId}}:{{businessId}}:{{businessUnitId}}:*`,value:h.cacheInvalidate??[],onChange:e=>P(`cacheInvalidate`,e)})]})]})]})}),(0,l.jsx)(vE,{open:!!C,rule:C?.rule,onClose:()=>w(null),onSave:e=>{P(`denormalizations`,C.index===null?[...h.denormalizations??[],e]:(h.denormalizations??[]).map((t,n)=>n===C.index?e:t)),w(null)}},C?`denorm-${C.index??`new`}`:`denorm-closed`),(0,l.jsx)(yE,{open:!!T,rule:T?.rule,onClose:()=>E(null),onSave:e=>{P(`arrayEnrichments`,T.index===null?[...h.arrayEnrichments??[],e]:(h.arrayEnrichments??[]).map((t,n)=>n===T.index?e:t)),E(null)}},T?`enrich-${T.index??`new`}`:`enrich-closed`),(0,l.jsx)(bE,{open:!!D,rule:D?.rule,onClose:()=>O(null),onSave:e=>{P(`fileFieldMaps`,D.index===null?[...h.fileFieldMaps??[],e]:(h.fileFieldMaps??[]).map((t,n)=>n===D.index?e:t)),O(null)}},D?`filemap-${D.index??`new`}`:`filemap-closed`),(0,l.jsx)(xE,{open:!!k,rule:k?.rule,onClose:()=>A(null),onSave:e=>{P(`hierarchyExpands`,k.index===null?[...h.hierarchyExpands??[],e]:(h.hierarchyExpands??[]).map((t,n)=>n===k.index?e:t)),A(null)}},k?`hier-${k.index??`new`}`:`hier-closed`),(0,l.jsx)(SE,{open:!!j,rule:j?.rule,hierarchyNames:N,onClose:()=>M(null),onSave:e=>{P(`relatedUpdates`,j.index===null?[...h.relatedUpdates??[],e]:(h.relatedUpdates??[]).map((t,n)=>n===j.index?e:t)),M(null)}},j?`ru-${j.index??`new`}`:`ru-closed`)]})}var{Text:EE}=s.Typography,DE=[`beforeCreate`,`afterCreate`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`],OE=[`sanitizeFields`,`generateSequence`,`duplicateCheck`,`copyFields`,`arrayEnrich`,`setDefaults`,`resolve`,`updateRelated`,`notify`,`invalidateCache`,`webhook`,`linkDocuments`,`captureFileUrls`,`resolveUploads`],kE={resolveUploads:{text:`Turn one submit into a list with ONE ENTRY PER UPLOADED FILE, so the actions after it can create one record per document instead of a single record holding all of them. Works for both shapes: a repeatable (Add Row) group gives one entry per row — carrying that row’s own values — and a multi-file upload field gives one entry per file. Publishes {{uploads.<as>}} (all entries), {{uploads.<as>First}} (the first, as an object) and {{uploads.<as>Rest}} (all but the first). Each entry has groupName, groupLabel, groupModule, fieldName, rowIndex, fileName, uniqueName, contentType, fileSize, s3Key, tenantId/businessId/businessUnitId, the row under "row", and the row’s own values at the top level. Leave "groups" empty for every group with an upload field. Set "heading" to "label" to use the group heading text instead of its name — note the heading changes whenever an admin renames the group, while the name does not.`,sample:{as:`docs`,groups:[],includeEmptyRows:!1,heading:`name`}},updateRelated:{text:`Update this record or another configured collection with values from the event. For uploaded files, after* workflows can read {{__uploads.<field>.fieldName|fileName|contentType|fileSize|s3Key|uniqueName}}. Add a $notEmpty condition on the upload s3Key so unrelated edits do not run it. To create one record PER FILE, run resolveUploads first, then set forEach to "uploads.<as>Rest" with insertIfMissing (an extraFilter on {{forEach.value.s3Key}} keeps a re-save from inserting duplicates). "unset" removes exact fields and "unsetPrefixes" removes a repeatable upload’s generated keys (document[0], document[1], …) in the SAME write — use it on the record being reused as the first row, and put that action LAST with Stop on error enabled so nothing is cleared when the inserts failed.`,sample:{targetModule:`documents`,matchField:`_id`,scopeTenant:!0,set:{module:`{{module}}`,moduleRefId:`{{_id}}`,fieldName:`{{__uploads.docPan.fieldName}}`,fileName:`{{__uploads.docPan.fileName}}`,contentType:`{{__uploads.docPan.contentType}}`,fileSize:`{{__uploads.docPan.fileSize}}`,s3Key:`{{__uploads.docPan.s3Key}}`,uniqueName:`{{__uploads.docPan.uniqueName}}`}}},linkDocuments:{text:`Share one record’s uploaded files with another, without making a second copy. Used so a submission shows the candidate’s résumé and paperwork, and anything uploaded during the submission appears on the candidate too. Both records get the list of document ids written onto them.`,sample:{sourceModule:`candidates`,sourceIdField:`applicantId`,targetModule:`submissions`,linkField:`documentIds`,fieldNames:[],backLink:!0}},captureFileUrls:{text:`File a document that was generated elsewhere and handed to us as a link — a formatted résumé or an attestation PDF — so it sits with every other attachment instead of being a loose field on the record.`,sample:{linkField:`documentIds`,files:[{urlField:`resumeUrl`,nameField:`resumeFileName`,fieldName:`formattedResume`,defaultName:`Formatted Resume.pdf`},{urlField:`attestationUrl`,nameField:`attestationFileName`,fieldName:`attestation`,defaultName:`Attestation.pdf`}]}}};function AE(e){return JSON.stringify(e??{},null,2)}function jE({action:e,onChange:t,onRemove:n}){let[r,i]=(0,o.useState)(()=>AE(e.config)),[a,u]=(0,o.useState)(!1);return(0,l.jsxs)(`div`,{style:{border:`1px solid #e2e8f0`,borderRadius:8,padding:10,marginTop:8},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`},children:[(0,l.jsx)(s.Select,{size:`small`,style:{width:200},showSearch:!0,value:e.type||void 0,placeholder:`action type`,options:OE.map(e=>({value:e})),onChange:n=>{let r=e.config&&Object.keys(e.config).length>0,i=kE[n]?.sample;t(r||!i?{...e,type:n}:{...e,type:n,config:i})}}),a&&(0,l.jsx)(s.Tag,{color:`red`,children:`invalid JSON`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),style:{marginLeft:`auto`},onClick:n})]}),kE[e.type]&&(0,l.jsx)(`p`,{style:{margin:`8px 0 0`,fontSize:12,color:`#64748b`,lineHeight:1.5},children:kE[e.type].text}),(0,l.jsx)(s.Input.TextArea,{rows:Math.min(14,Math.max(3,r.split(`
17
+ `).length)),value:r,className:`fg-mono-input`,style:{marginTop:8,fontSize:12},onChange:n=>{i(n.target.value);try{t({...e,config:JSON.parse(n.target.value||`{}`)}),u(!1)}catch{u(!0)}}})]})}function ME({open:e,doc:t,moduleOptions:n,onClose:r,onSave:i}){let[a,u]=(0,o.useState)(()=>({key:``,module:``,event:`afterCreate`,order:10,isActive:!0,stopOnError:!1,condition:{},actions:[],...t??{}})),[d,f]=(0,o.useState)(()=>AE(t?.condition)),[p,m]=(0,o.useState)(!1),h=(e,t)=>u(n=>({...n,[e]:t}));return(0,l.jsx)(s.Modal,{open:e,onCancel:r,width:840,centered:!0,destroyOnClose:!0,maskClosable:!1,className:`fg-editor-modal`,title:(0,l.jsxs)(`span`,{className:`fg-drawer-title`,children:[(0,l.jsx)(c.ApartmentOutlined,{}),` `,t?`Edit Workflow`:`New Workflow`]}),footer:(0,l.jsxs)(`div`,{className:`fg-drawer-footer`,children:[(0,l.jsx)(s.Button,{onClick:r,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),onClick:()=>{if(!a.key?.trim())return s.message.error(`Key is required`);if(!a.module?.trim())return s.message.error(`Module is required`);if(p)return s.message.error(`Condition JSON is invalid`);if(!(a.actions??[]).length)return s.message.error(`At least one action is required`);if((a.actions??[]).some(e=>!e.type))return s.message.error(`Every action needs a type`);let e={...a};delete e.id,delete e._id,i(e)},children:`Save Workflow`})]}),children:(0,l.jsxs)(`div`,{className:`fg-form-section`,children:[(0,l.jsxs)(`div`,{className:`fg-field-meta-row`,children:[(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(EE,{type:`secondary`,style:{fontSize:12},children:`Key`}),(0,l.jsx)(s.Input,{size:`small`,placeholder:`jobs-create-after`,value:a.key??``,onChange:e=>h(`key`,e.target.value),className:`fg-mono-input`,disabled:!!t})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(EE,{type:`secondary`,style:{fontSize:12},children:`Module`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},showSearch:!0,value:a.module||void 0,options:n,onChange:e=>h(`module`,e),placeholder:`jobs`})]}),(0,l.jsxs)(`div`,{style:{flex:1},children:[(0,l.jsx)(EE,{type:`secondary`,style:{fontSize:12},children:`Event`}),(0,l.jsx)(s.Select,{size:`small`,style:{width:`100%`},value:a.event,options:DE.map(e=>({value:e})),onChange:e=>h(`event`,e)})]}),(0,l.jsxs)(`div`,{style:{width:90},children:[(0,l.jsx)(EE,{type:`secondary`,style:{fontSize:12},children:`Order`}),(0,l.jsx)(s.InputNumber,{size:`small`,style:{width:`100%`},value:a.order??10,onChange:e=>h(`order`,e??10)})]})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:24,marginTop:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:a.isActive!==!1,onChange:e=>h(`isActive`,e)}),(0,l.jsx)(EE,{style:{fontSize:13},children:`Active`})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(s.Switch,{size:`small`,checked:a.stopOnError===!0,onChange:e=>h(`stopOnError`,e)}),(0,l.jsx)(s.Tooltip,{title:`Off (default): if an action fails after the record is saved, it is logged and the next action still runs — right for independent side effects like a notification and a cache clear. On: the remaining actions are skipped, for a sequence whose later steps are only safe because the earlier ones worked (creating records and THEN clearing the data they came from).`,children:(0,l.jsx)(EE,{style:{fontSize:13},children:`Stop on error`})})]})]}),(0,l.jsxs)(`div`,{style:{marginTop:12},children:[(0,l.jsxs)(EE,{type:`secondary`,style:{fontSize:12},children:[`Condition (all must match the payload; empty = always run) `,p&&(0,l.jsx)(s.Tag,{color:`red`,children:`invalid JSON`})]}),(0,l.jsx)(s.Input.TextArea,{rows:2,value:d,className:`fg-mono-input`,style:{fontSize:12},onChange:e=>{f(e.target.value);try{h(`condition`,JSON.parse(e.target.value||`{}`)),m(!1)}catch{m(!0)}}})]}),(0,l.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:14},children:[(0,l.jsx)(EE,{strong:!0,style:{fontSize:13},children:`Actions (run in order)`}),(0,l.jsx)(s.Button,{size:`small`,type:`dashed`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>h(`actions`,[...a.actions??[],{type:``,config:{}}]),children:`Add Action`})]}),(a.actions??[]).map((e,t)=>(0,l.jsx)(jE,{action:e,onChange:e=>h(`actions`,a.actions.map((n,r)=>r===t?e:n)),onRemove:()=>h(`actions`,a.actions.filter((e,n)=>n!==t))},t)),(0,l.jsxs)(EE,{type:`secondary`,style:{fontSize:11,display:`block`,marginTop:8},children:[`Config supports `,(0,l.jsx)(`code`,{children:`{{field.path}}`}),`, `,(0,l.jsx)(`code`,{children:`{{now}}`}),`, `,(0,l.jsx)(`code`,{children:`{{__userId}}`}),`,`,` `,(0,l.jsx)(`code`,{children:`{{__userName}}`}),`, and `,(0,l.jsx)(`code`,{children:`{{hierarchy.<name>}}`}),` from a `,(0,l.jsx)(`code`,{children:`resolve`}),` action.`]})]})})}function NE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)(!0),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(null),[h,g]=(0,o.useState)(``),[_,v]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=!1;return n.ei(`workflows`).then(n=>{e||t(n)}).catch(t=>{e||f(t?.message||`Failed to load workflows`)}).finally(()=>{e||u(!1)}),()=>{e=!0}},[_]),(0,o.useEffect)(()=>{n.Sr().then(e=>i(hS(e).map(({value:e,label:t})=>({value:e,label:t})))).catch(()=>i([]))},[]);let y=()=>{u(!0),f(``),v(e=>e+1)};async function b(e){try{await n.di(`workflows`,e),s.message.success(`Workflow "${e.key}" saved`),m(null),y()}catch(e){s.message.error(e?.message||`Could not save workflow`)}}async function x(e){try{await n.ur(`workflows`,e),s.message.success(`Workflow "${e}" deleted`),y()}catch(e){s.message.error(e?.message||`Could not delete workflow`)}}async function S(e,t){let r={...e};delete r.id,delete r._id;try{await n.di(`workflows`,{...r,isActive:t}),y()}catch(e){s.message.error(e?.message||`Could not update workflow`)}}let C=(0,o.useMemo)(()=>e.filter(e=>!h||e.module===h),[e,h]);return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.ApartmentOutlined,{}),title:`Workflows`,extra:(0,l.jsxs)(s.Space,{size:8,children:[(0,l.jsx)(s.Select,{size:`small`,style:{minWidth:160},allowClear:!0,placeholder:`Filter by module`,options:r,value:h||void 0,onChange:e=>g(e??``)}),(0,l.jsx)(s.Button,{size:`small`,icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:y,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>m({doc:null}),children:`New Workflow`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsxs)(EE,{type:`secondary`,style:{fontSize:13},children:[`Event-driven behavior per module — reference ids, duplicate checks, snapshots, hierarchy fan-outs, board updates, notifications, cache — executed by the platform Workflow Engine on every create/update/delete.`,(0,l.jsx)(s.Tag,{style:{marginLeft:8},children:`before*`}),` actions can block the write; `,(0,l.jsx)(s.Tag,{children:`after*`}),` actions are best-effort.`]})]}),(0,l.jsxs)(Z,{styles:{body:{paddingTop:8}},children:[d&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:d,style:{marginBottom:12}}),(0,l.jsxs)(s.Spin,{spinning:a,children:[(0,l.jsxs)(`div`,{style:{marginBottom:8},children:[(0,l.jsx)(s.Badge,{count:C.length,showZero:!0,color:`var(--color-brand)`}),` `,(0,l.jsx)(EE,{type:`secondary`,style:{fontSize:12},children:`workflows`})]}),(0,l.jsx)(s.Table,{rowKey:`key`,dataSource:C,columns:[{title:`Key`,dataIndex:`key`,key:`key`,render:e=>(0,l.jsx)(`code`,{className:`fg-table-code`,children:e})},{title:`Module`,dataIndex:`module`,key:`module`,width:130,render:e=>(0,l.jsx)(s.Tag,{color:`geekblue`,children:e})},{title:`Event`,dataIndex:`event`,key:`event`,width:130,render:e=>(0,l.jsx)(s.Tag,{color:String(e).startsWith(`before`)?`purple`:`green`,children:e})},{title:`Actions`,key:`acts`,render:(e,t)=>(0,l.jsx)(s.Space,{size:4,wrap:!0,children:(t.actions??[]).map((e,t)=>(0,l.jsx)(s.Tag,{style:{margin:0},children:e.type},t))})},{title:`Order`,dataIndex:`order`,key:`order`,width:70,align:`center`},{title:`Active`,key:`active`,width:80,align:`center`,render:(e,t)=>(0,l.jsx)(s.Switch,{size:`small`,checked:t.isActive!==!1,onChange:e=>S(t,e)})},{title:``,key:`ops`,width:90,align:`right`,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>m({doc:t})})}),(0,l.jsx)(s.Popconfirm,{title:`Delete workflow "${t.key}"?`,onConfirm:()=>x(t.key),children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],pagination:!1,size:`small`,className:`fg-table`,locale:{emptyText:(0,l.jsx)(s.Empty,{description:`No workflows configured.`,image:s.Empty.PRESENTED_IMAGE_SIMPLE})}})]})]}),(0,l.jsx)(ME,{open:!!p,doc:p?.doc,moduleOptions:r,onClose:()=>m(null),onSave:b},p?p.doc?.key??`new`:`closed`)]})}var{Text:PE}=s.Typography,FE=e=>e?._id??e?.id,IE=`masters`;function LE(){return{tenantId:localStorage.getItem(`tenantId`)||``,businessId:localStorage.getItem(`businessId`)||``,businessUnitId:localStorage.getItem(`businessUnitId`)||``}}function RE(e){return e&&typeof e==`object`?e.$oid??e.oid??e.id??``:e??``}function zE(e,t){return t.map(t=>RE(e?.[t])).find(e=>e!=null&&e!==``)??``}function BE(e,t){return[[t.tenantId,[`tid`,`tenantId`]],[t.businessId,[`bid`,`businessId`]],[t.businessUnitId,[`buid`,`businessUnitId`]]].every(([t,n])=>{if(!t)return!0;let r=String(zE(e,n));return!r||r===String(t)})}function VE(e){return Array.isArray(e?.masterFeeds)?e.masterFeeds:[]}function HE(e){return e.reduce((e,t)=>Math.max(e,Number(t?.uniqueId)||0),0)+1}function UE(e){return Array.isArray(e?.taxHistory)?e.taxHistory:[]}function WE(e){let t=e?.taxValue;if(t!=null&&t!==``)return Number(t);let n=UE(e).at(-1),r=n?.taxValue??n?.value;return r!=null&&r!==``?Number(r):void 0}function GE(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}function KE(e){let t=UE(e).at(-1);return t?.updatedAt??t?.timestamp??e?.updatedAt}function qE({open:e,record:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[c,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(!1),h=(0,o.useRef)(null),g=!!t;(0,o.useEffect)(()=>{e&&queueMicrotask(()=>{a.resetFields(),a.setFieldsValue({name:t?.name??void 0,taxValue:WE(t)}),f(t?.name?[{label:t.name,value:t.name}]:[])})},[e,t,a]);function _(e){if(h.current&&clearTimeout(h.current),!e||e.trim().length<2){f([]);return}m(!0),h.current=setTimeout(()=>{n.Pr(e.trim()).then(f).catch(()=>f([])).finally(()=>m(!1))},350)}async function v(){let e=await a.validateFields(),r=Number(e.taxValue),o={name:e.name,taxValue:r,taxHistory:{taxValue:r}};u(!0);try{g?await n.bi(`locations`,FE(t),o):await n.er(`locations`,o),s.message.success(g?`Tax updated`:`Location and tax created`),i()}catch(e){s.message.error(e?.message||`Could not save location and tax`)}finally{u(!1)}}return(0,l.jsx)(s.Modal,{open:e,onCancel:r,onOk:v,confirmLoading:c,destroyOnHidden:!0,title:g?`Edit Tax — ${t?.name??``}`:`New Location`,children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{name:`name`,label:`Location`,rules:[{required:!0,message:`Location is required`}],tooltip:g?`Location cannot be changed once created — only the tax is editable.`:`Search and pick from the location master.`,children:(0,l.jsx)(s.Select,{showSearch:!0,disabled:g,placeholder:`Type at least 2 characters to search…`,filterOption:!1,onSearch:_,notFoundContent:p?`Searching…`:null,options:d})}),(0,l.jsx)(s.Form.Item,{name:`taxValue`,label:`Tax`,rules:[{required:!0,message:`Tax is required`},{type:`number`,min:0,max:100,message:`Tax must be between 0 and 100`}],children:(0,l.jsx)(s.InputNumber,{style:{width:`100%`},min:0,max:100,step:.01,suffix:`%`,placeholder:`8.875`,autoFocus:g})})]})})}function JE({record:e}){let t=[...UE(e)].reverse();return t.length?(0,l.jsx)(s.Space,{direction:`vertical`,size:4,style:{padding:`4px 8px`},children:t.map((e,t)=>(0,l.jsxs)(s.Space,{size:10,children:[(0,l.jsxs)(s.Tag,{color:t===0?`green`:`default`,style:{margin:0},children:[e.taxValue??e.value,`%`]}),(0,l.jsx)(PE,{type:`secondary`,style:{fontSize:12},children:GE(e.updatedAt??e.timestamp)}),t===0&&(0,l.jsx)(PE,{type:`secondary`,style:{fontSize:12},children:`(current)`})]},t))}):(0,l.jsx)(s.Empty,{image:s.Empty.PRESENTED_IMAGE_SIMPLE,description:`No tax history yet`})}function YE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null);function p(){i(!0),n.$r(`locations`).then(({items:e})=>t(e)).catch(e=>s.message.error(e?.message||`Could not load locations`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(p)},[]);async function m(e){try{await n.lr(`locations`,e),s.message.success(`Location deleted`),p()}catch(e){s.message.error(e?.message||`Could not delete location`)}}return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{title:`${e.length} location${e.length===1?``:`s`}`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:p,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New location`})]}),children:(0,l.jsx)(s.Table,{rowKey:FE,columns:[{title:`Location`,dataIndex:`name`,key:`name`},{title:`Tax`,key:`taxValue`,width:100,render:(e,t)=>{let n=WE(t);return Number.isFinite(n)?(0,l.jsxs)(s.Tag,{color:`blue`,children:[n,`%`]}):`—`}},{title:`Tax updated`,key:`taxUpdatedAt`,render:(e,t)=>GE(KE(t))},{title:`Created`,key:`createdAt`,responsive:[`lg`],render:(e,t)=>GE(t?.createdAt)},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit tax`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this location?`,onConfirm:()=>m(FE(t)),children:(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})})]})}],dataSource:e,loading:r,size:`small`,pagination:!1,className:`fg-table`,expandable:{expandedRowRender:e=>(0,l.jsx)(JE,{record:e}),rowExpandable:e=>UE(e).length>0},locale:{emptyText:`No locations yet. Click "New location" to add one.`}})}),(0,l.jsx)(qE,{open:a,record:d,onClose:()=>u(!1),onSaved:()=>{u(!1),p()}})]})}function XE({open:e,record:t,onClose:r,onSaved:i}){let[a]=s.Form.useForm(),[u,d]=(0,o.useState)(!1),f=!!t,p=s.Form.useWatch(`masterName`,a),m=s.Form.useWatch(`masterFeeds`,a)??[],h=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(p??t?.masterName??``).trim().toLowerCase()),g=m.map(e=>({label:String(e?.name??``).trim()||`Status ${e?.uniqueId??``}`,value:Number(e?.uniqueId)})).filter(e=>Number.isInteger(e.value)&&e.value>0);function _(e,t){if(!t){a.setFieldValue([`masterFeeds`,e,`isInitialStatus`],!1);return}(a.getFieldValue(`masterFeeds`)??[]).forEach((t,n)=>{a.setFieldValue([`masterFeeds`,n,`isInitialStatus`],n===e)})}function v(e,t){a.setFieldValue([`masterFeeds`,e,`isTerminalStatus`],t),t&&a.setFieldValue([`masterFeeds`,e,`allowedNextStatusIds`],[])}(0,o.useEffect)(()=>{e&&queueMicrotask(()=>{a.resetFields();let e=t?.masterName??``,n=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(e).trim().toLowerCase()),r=VE(t),i=r.length?r.map(e=>({...e})):[{uniqueId:1,name:``,type:`neutral`,status:!0,isdeleted:!1}];if(n&&!i.some(e=>e?.status!==!1&&e?.isdeleted!==!0&&e?.isInitialStatus===!0)){let e=i.findIndex(e=>e?.status!==!1&&e?.isdeleted!==!0);e>=0&&(i=i.map((t,n)=>({...t,isInitialStatus:n===e,isTerminalStatus:t?.isTerminalStatus===!0,allowedNextStatusIds:Array.isArray(t?.allowedNextStatusIds)?t.allowedNextStatusIds:[]})))}a.setFieldsValue({masterName:e,schemaVersion:t?.schemaVersion??1,masterFeeds:i})})},[e,t,a]),(0,o.useEffect)(()=>{!e||!h||(Number(a.getFieldValue(`schemaVersion`))||1)<2&&a.setFieldValue(`schemaVersion`,2)},[e,h,a]);async function y(){let e=await a.validateFields(),r=LE(),o=[`clientsubmissionstatus`,`clientsubmission`,`clientsubmissions`].includes(String(e.masterName??``).trim().toLowerCase()),c=(e.masterFeeds??[]).map((e,t)=>{let n=Number(e.uniqueId)||t+1,r=o&&e.isTerminalStatus===!0,i=o&&!r?[...new Set((e.allowedNextStatusIds??[]).map(Number).filter(e=>Number.isInteger(e)&&e>0&&e!==n))]:[];return{uniqueId:n,name:String(e.name??``).trim(),type:String(e.type??``).trim(),status:e.status!==!1,...o?{isInitialStatus:e.isInitialStatus===!0,isTerminalStatus:r,allowedNextStatusIds:i}:{},isdeleted:e.isdeleted===!0}}).filter(e=>e.name);if(o){let e=c.filter(e=>e.status&&!e.isdeleted&&e.isInitialStatus);if(e.length===0){let t=c.findIndex(e=>e.status&&!e.isdeleted);t>=0&&(c[t]={...c[t],isInitialStatus:!0},e=[c[t]],a.setFieldValue([`masterFeeds`,t,`isInitialStatus`],!0))}if(e.length!==1){s.message.error(`Client Submission Status must have exactly one active Initial Status.`);return}}let l={...r,tid:r.tenantId,bid:r.businessId,buid:r.businessUnitId,schemaVersion:o?Math.max(2,Number(e.schemaVersion)||2):Number(e.schemaVersion)||1,masterName:e.masterName.trim(),masterFeeds:c};d(!0);try{f?await n.bi(IE,FE(t),l):await n.er(IE,l),s.message.success(f?`Master value updated`:`Master value created`),i()}catch(e){s.message.error(e?.message||`Could not save master value`)}finally{d(!1)}}return(0,l.jsx)(s.Modal,{open:e,onCancel:r,onOk:y,confirmLoading:u,destroyOnHidden:!0,title:f?`Edit Master Feed`:`New Master Feed`,width:1040,children:(0,l.jsxs)(s.Form,{form:a,layout:`vertical`,children:[(0,l.jsx)(s.Form.Item,{name:`masterName`,label:`Master Name`,rules:[{required:!0,message:`Master name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`blacklistType`,autoFocus:!f,disabled:f})}),(0,l.jsx)(s.Form.Item,{name:`schemaVersion`,label:`Schema Version`,children:(0,l.jsx)(s.InputNumber,{min:1,style:{width:`100%`}})}),(0,l.jsx)(s.Form.List,{name:`masterFeeds`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(s.Space,{direction:`vertical`,style:{width:`100%`},size:10,children:[e.map(({key:e,name:t})=>(0,l.jsxs)(s.Space,{align:`baseline`,wrap:!0,children:[(0,l.jsx)(s.Form.Item,{name:[t,`uniqueId`],label:`ID`,rules:[{required:!0,message:`ID required`}],children:(0,l.jsx)(s.InputNumber,{min:1,style:{width:90}})}),(0,l.jsx)(s.Form.Item,{name:[t,`name`],label:`Name`,rules:[{required:!0,message:`Name required`}],children:(0,l.jsx)(s.Input,{placeholder:`Dropdown label`,style:{width:280}})}),(0,l.jsx)(s.Form.Item,{name:[t,`type`],label:`Type`,children:(0,l.jsx)(s.Select,{allowClear:!0,placeholder:`Select type`,style:{width:120},options:[{label:`Positive`,value:`positive`},{label:`Neutral`,value:`neutral`},{label:`Negative`,value:`negative`}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`status`],label:`Status`,initialValue:!0,children:(0,l.jsx)(s.Select,{style:{width:110},options:[{label:`Active`,value:!0},{label:`Inactive`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`isdeleted`],label:`Deleted`,initialValue:!1,children:(0,l.jsx)(s.Select,{style:{width:110},options:[{label:`No`,value:!1},{label:`Yes`,value:!0}]})}),h&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Form.Item,{name:[t,`isInitialStatus`],label:`Initial`,initialValue:!1,tooltip:`The initial status is the only option shown before a candidate has a client submission status. Only one active initial status is allowed.`,children:(0,l.jsx)(s.Select,{style:{width:100},onChange:e=>_(t,e===!0),options:[{label:`Yes`,value:!0},{label:`No`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{name:[t,`isTerminalStatus`],label:`End Status`,initialValue:!1,tooltip:`End Status stops the configured client submission flow. Once reached, Change Status is hidden and no next statuses are allowed.`,children:(0,l.jsx)(s.Select,{style:{width:105},onChange:e=>v(t,e===!0),options:[{label:`Yes`,value:!0},{label:`No`,value:!1}]})}),(0,l.jsx)(s.Form.Item,{noStyle:!0,shouldUpdate:(e,n)=>e?.masterFeeds?.[t]?.isTerminalStatus!==n?.masterFeeds?.[t]?.isTerminalStatus||e?.masterFeeds?.[t]?.uniqueId!==n?.masterFeeds?.[t]?.uniqueId||e?.masterFeeds!==n?.masterFeeds,children:({getFieldValue:e})=>{let n=e([`masterFeeds`,t,`isTerminalStatus`])===!0,r=Number(e([`masterFeeds`,t,`uniqueId`]));return(0,l.jsx)(s.Form.Item,{name:[t,`allowedNextStatusIds`],label:`Allowed Next Statuses`,tooltip:n?`End Status cannot move to another status.`:`Only these statuses will appear after the current status is saved.`,children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,disabled:n,placeholder:n?`End status`:`Select next statuses`,style:{minWidth:280},options:g.filter(e=>e.value!==r)})})}})]}),(0,l.jsx)(s.Tooltip,{title:`Remove row`,children:(0,l.jsx)(s.Button,{type:`text`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),onClick:()=>n(t)})})]},e)),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>t({uniqueId:HE(a.getFieldValue(`masterFeeds`)??[]),name:``,type:`neutral`,status:!0,isdeleted:!1,...h?{isInitialStatus:!1,isTerminalStatus:!1,allowedNextStatusIds:[]}:{}}),children:`Add feed value`})]})})]})})}function ZE(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),[p,m]=(0,o.useState)(``);function h(){let e=LE();i(!0),n.$r(IE,{limit:500}).then(({items:n})=>{let r=n.filter(t=>BE(t,e));t(r)}).catch(e=>s.message.error(e?.message||`Could not load master values`)).finally(()=>i(!1))}(0,o.useEffect)(()=>{queueMicrotask(h)},[]);async function g(e){try{await n.lr(IE,e),s.message.success(`Master value deleted`),h()}catch(e){s.message.error(e?.message||`Could not delete master value`)}}let _=p?e.filter(e=>String(e?.masterName??``).toLowerCase()===p.toLowerCase()):e,v=[...new Set(e.map(e=>e?.masterName).filter(Boolean))].sort((e,t)=>String(e).localeCompare(String(t))).map(e=>({label:e,value:e}));return(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsx)(Z,{title:`${_.length} master${_.length===1?``:`s`}`,extra:(0,l.jsxs)(s.Space,{wrap:!0,children:[(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,placeholder:`Filter master name`,value:p||void 0,options:v,onChange:e=>m(e??``),style:{minWidth:220}}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:h,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>{f(null),u(!0)},children:`New master`})]}),children:(0,l.jsx)(s.Table,{rowKey:FE,columns:[{title:`Master Name`,dataIndex:`masterName`,key:`masterName`,width:180},{title:`Feed Values`,key:`masterFeeds`,render:(e,t)=>(0,l.jsx)(s.Space,{wrap:!0,children:VE(t).filter(e=>!e.isdeleted).map(e=>(0,l.jsx)(s.Tag,{color:e.status===!1?`default`:`blue`,children:e.name},e.uniqueId??e.name))})},{title:`Count`,key:`count`,width:90,render:(e,t)=>VE(t).filter(e=>!e.isdeleted).length},{title:`Updated`,key:`updatedAt`,responsive:[`lg`],render:(e,t)=>GE(t?.updatedAt)},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{f(t),u(!0)}})}),(0,l.jsx)(s.Popconfirm,{title:`Delete this master?`,onConfirm:()=>g(FE(t)),children:(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{})})})})]})}],dataSource:_,loading:r,size:`small`,pagination:{pageSize:10,showSizeChanger:!0},className:`fg-table`,locale:{emptyText:`No masters yet. Click "New master" to add one.`}})}),(0,l.jsx)(XE,{open:a,record:d,onClose:()=>u(!1),onSaved:()=>{u(!1),h()}})]})}function QE(){return(0,l.jsxs)(`div`,{className:`fg-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Master Collections`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(PE,{type:`secondary`,style:{fontSize:13},children:`Create, update, and delete master documents, then customize multiple dropdown values inside masterFeeds. Records are saved with the current tenant, business, business unit, and master name.`})]}),(0,l.jsx)(ZE,{}),(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DatabaseOutlined,{}),title:`Location Tax Master`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(PE,{type:`secondary`,style:{fontSize:13},children:`Pick a location from the master list and set its tax. Once added, only the tax can be changed — every change is kept in a timeline with its timestamp. Expand a row to see the full tax history.`})]}),(0,l.jsx)(YE,{})]})}var{Text:$E}=s.Typography,eD={employerMsaValidityDays:365,referralMsaValidityDays:365,expiryWarningDays:30};function tD(){let[e]=s.Form.useForm(),[t,r]=(0,o.useState)(!0),[i,a]=(0,o.useState)(!1),u=async()=>{r(!0);try{let t=await n.Gr();e.setFieldsValue({...eD,...t||{}})}catch(t){s.message.error(t?.message||`Could not load PO/MSA settings`),e.setFieldsValue(eD)}finally{r(!1)}};return(0,o.useEffect)(()=>{u()},[]),(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.SettingOutlined,{}),title:`PO/MSA Validity Settings`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:u,disabled:i,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,onClick:async()=>{try{let t=await e.validateFields();a(!0);let r=await n.ui(t);e.setFieldsValue({...eD,...r||t}),s.message.success(`PO/MSA validity settings saved`)}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save PO/MSA settings`)}finally{a(!1)}},children:`Save`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)($E,{type:`secondary`,children:`Configure how long a signed MSA remains valid. Employer/referral status is calculated from the signed MSA date plus these values; no validity period is hardcoded in the onboarding UI.`})]}),(0,l.jsx)(Z,{title:`Validity Rules`,children:(0,l.jsx)(s.Spin,{spinning:t,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,initialValues:eD,style:{maxWidth:620},children:[(0,l.jsx)(s.Form.Item,{name:`employerMsaValidityDays`,label:`Employer MSA Validity Days`,tooltip:`Number of days an employer MSA remains active from its signed date.`,rules:[{required:!0,message:`Employer MSA validity is required`}],children:(0,l.jsx)(s.InputNumber,{min:1,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})}),(0,l.jsx)(s.Form.Item,{name:`referralMsaValidityDays`,label:`Referral MSA Validity Days`,tooltip:`Number of days a referral MSA remains active from its signed date.`,rules:[{required:!0,message:`Referral MSA validity is required`}],children:(0,l.jsx)(s.InputNumber,{min:1,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})}),(0,l.jsx)(s.Form.Item,{name:`expiryWarningDays`,label:`Expiry Warning Days`,tooltip:`Reserved for upcoming-expiry indicators and notifications.`,rules:[{required:!0,message:`Expiry warning days is required`}],children:(0,l.jsx)(s.InputNumber,{min:0,max:3650,precision:0,style:{width:`100%`},addonAfter:`days`})})]})})})]})}var{Text:nD,Title:rD}=s.Typography,iD=[{value:`Dashboard`,label:`Dashboard`,icon:(0,l.jsx)(c.DashboardOutlined,{})},{value:`ClientManagement`,label:`Client Management`,icon:(0,l.jsx)(c.BankOutlined,{})},{value:`EmployerManagement`,label:`Employer / Referral`,icon:(0,l.jsx)(c.TeamOutlined,{})},{value:`Candidates`,label:`Candidates`,icon:(0,l.jsx)(c.UsergroupAddOutlined,{})},{value:`Jobs`,label:`Jobs`,icon:(0,l.jsx)(c.FileTextOutlined,{})},{value:`Submissions`,label:`Submissions`,icon:(0,l.jsx)(c.FileTextOutlined,{})},{value:`Onboarding`,label:`Onboarding`,icon:(0,l.jsx)(c.UserOutlined,{})},{value:`Assignments`,label:`Assignments`,icon:(0,l.jsx)(c.AppstoreOutlined,{})},{value:`Timesheet`,label:`Timesheet`,icon:(0,l.jsx)(c.CalendarOutlined,{})},{value:`Campaign`,label:`Campaign`,icon:(0,l.jsx)(c.TeamOutlined,{})},{value:`FileProtectOutlined`,label:`PO / MSA`,icon:(0,l.jsx)(c.FileProtectOutlined,{})},{value:`FolderOpenOutlined`,label:`Batches`,icon:(0,l.jsx)(c.FolderOpenOutlined,{})},{value:`BankOutlined`,label:`Billing / Finance`,icon:(0,l.jsx)(c.BankOutlined,{})},{value:`SettingOutlined`,label:`Settings / Admin`,icon:(0,l.jsx)(c.SettingOutlined,{})},{value:`UploadOutlined`,label:`Upload`,icon:(0,l.jsx)(c.UploadOutlined,{})},{value:`AppstoreOutlined`,label:`General Module`,icon:(0,l.jsx)(c.AppstoreOutlined,{})}];function aD({option:e}){return(0,l.jsxs)(s.Space,{size:8,children:[(0,l.jsx)(`span`,{style:{display:`inline-flex`,fontSize:16},children:e.icon}),(0,l.jsx)(`span`,{children:e.label}),(0,l.jsx)(nD,{type:`secondary`,style:{fontSize:11},children:e.value})]})}function oD(e,t){let n=localStorage.getItem(`menu`);if(n)try{let r=JSON.parse(n),i=Array.isArray(r)?r:r?.menu;if(!Array.isArray(i))return;let a=String(e??t.menu_key??``).trim().toLowerCase(),o=e=>e.map(e=>{let n=String(e?.key??``).trim().toLowerCase()===a?{...e,icon:t.icon??e.icon,label:t.menu_name??e.label,status:String(t.status??e.status??`ACTIVE`).toLowerCase()}:e;return Array.isArray(n?.children)?{...n,children:o(n.children)}:n}),s=o(i);localStorage.setItem(`menu`,JSON.stringify(Array.isArray(r)?s:{...r,menu:s})),window.dispatchEvent(new Event(`menu:updated`))}catch{}}function sD(){let[e]=s.Form.useForm(),[t,n]=(0,o.useState)([]),[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(null),[p,m]=(0,o.useState)(!1);async function h(){i(!0);try{n(await Rx())}catch(e){s.message.error(e.message||`Unable to load menus`)}finally{i(!1)}}(0,o.useEffect)(()=>{h()},[]);let g=(0,o.useMemo)(()=>t.filter(e=>!d||e.menu_id!==d.menu_id).map(e=>({label:e.menu_name,value:e.menu_id})),[d,t]);function _(){f(null),e.resetFields(),e.setFieldsValue({menu_type:`MENU`,display_order:t.length+1,status:`ACTIVE`}),m(!0)}function v(t){f(t),e.setFieldsValue(t),m(!0)}async function y(e){u(!0);try{d?(await Bx(d.menu_id,e),oD(d.menu_key,e)):await zx(e),s.message.success(d?`Menu updated`:`Menu created`),m(!1),await h()}catch(e){s.message.error(e.message||`Unable to save menu`)}finally{u(!1)}}async function b(e){try{await Vx(e),s.message.success(`Menu deleted`),await h()}catch(e){s.message.error(e.message||`Unable to delete menu`)}}return(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(rD,{level:4,children:`Menus`}),(0,l.jsx)(nD,{type:`secondary`,children:`Manage records in the MongoDB menus collection.`})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:_,children:`Add Menu`})]}),(0,l.jsx)(s.Table,{rowKey:`menu_id`,loading:r,columns:[{title:`Name`,dataIndex:`menu_name`},{title:`Key`,dataIndex:`menu_key`,render:e=>(0,l.jsx)(s.Tag,{children:e})},{title:`Route / API`,dataIndex:`api_url`},{title:`Icon`,dataIndex:`icon`,width:170,render:e=>(0,l.jsx)(s.Tag,{children:e||`Auto`})},{title:`Type`,dataIndex:`menu_type`,width:110},{title:`Order`,dataIndex:`display_order`,width:80},{title:`Status`,dataIndex:`status`,width:100,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{title:``,key:`actions`,width:90,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Edit menu`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>v(t)}),(0,l.jsx)(s.Popconfirm,{title:`Delete menu?`,onConfirm:()=>b(t.menu_id),children:(0,l.jsx)(s.Button,{"aria-label":`Delete menu`,danger:!0,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{})})})]})}],dataSource:t,size:`small`,pagination:{pageSize:10}}),(0,l.jsx)(s.Modal,{title:d?`Edit Menu`:`Add Menu`,open:p,onCancel:()=>m(!1),onOk:()=>e.submit(),confirmLoading:a,destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,onFinish:y,children:[(0,l.jsx)(s.Form.Item,{name:`menu_name`,label:`Menu name`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{})}),(0,l.jsx)(s.Form.Item,{name:`menu_key`,label:`Menu key`,rules:[{required:!0}],children:(0,l.jsx)(s.Input,{placeholder:`jobs`})}),(0,l.jsx)(s.Form.Item,{name:`api_url`,label:`Route / API URL`,children:(0,l.jsx)(s.Input,{placeholder:`/jobs`})}),(0,l.jsx)(s.Form.Item,{name:`component_name`,label:`Component`,children:(0,l.jsx)(s.Input,{placeholder:`Jobs`})}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{name:`menu_type`,label:`Type`,children:(0,l.jsx)(s.Select,{options:[{value:`MENU`},{value:`FOOTER`},{value:`CHILD`}]})}),(0,l.jsx)(s.Form.Item,{name:`parent_menu_id`,label:`Parent`,children:(0,l.jsx)(s.Select,{allowClear:!0,options:g})})]}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{name:`display_order`,label:`Display order`,children:(0,l.jsx)(s.InputNumber,{min:0})}),(0,l.jsx)(s.Form.Item,{name:`status`,label:`Status`,children:(0,l.jsx)(s.Select,{options:[{value:`ACTIVE`},{value:`INACTIVE`}]})})]}),(0,l.jsx)(s.Form.Item,{name:`icon`,label:`Sidebar icon`,extra:`Saved in the menus collection and used dynamically in the application sidebar.`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,placeholder:`Select sidebar icon`,optionFilterProp:`label`,options:iD.map(({value:e,label:t})=>({value:e,label:t})),optionRender:e=>{let t=e?.value??e?.data?.value,n=iD.find(e=>e.value===t);return n?(0,l.jsx)(aD,{option:n}):t}})})]})})]})}var{Text:cD}=s.Typography,lD={call:10,sms:10,whatsapp:10,email:10},uD=[{name:`call`,label:`Calls per day`,tooltip:`Calls each counsellor can make in one day.`},{name:`sms`,label:`SMS per day`,tooltip:`SMS messages each counsellor can send in one day.`},{name:`whatsapp`,label:`WhatsApp per day`,tooltip:`WhatsApp messages each counsellor can send in one day.`},{name:`email`,label:`Mail per day`,tooltip:`Emails each counsellor can send in one day.`}];function dD(){let[e]=s.Form.useForm(),[t,r]=(0,o.useState)(!0),[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(``),[f,p]=(0,o.useState)({canEdit:!1,maxLimit:1e3,defaultLimit:10}),m=t=>{e.setFieldsValue({...lD,...t?.limits||{}}),p({canEdit:!!t?.canEdit,maxLimit:Number(t?.maxLimit??1e3),defaultLimit:Number(t?.defaultLimit??10)})},h=async()=>{r(!0),d(``);try{m(await n.Er())}catch(t){let n=t?.message||`Could not load communication limits`;d(n),s.message.error(n),e.setFieldsValue(lD)}finally{r(!1)}};return(0,o.useEffect)(()=>{h()},[]),(0,l.jsxs)(`div`,{className:`fg-section admin-config-section`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.MessageOutlined,{}),title:`Communication Limits`,extra:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:h,disabled:i,children:`Reload`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,disabled:!f.canEdit,onClick:async()=>{try{let t=await e.validateFields();a(!0),m(await n.ii(t)),s.message.success(`Communication limits saved. They apply immediately.`)}catch(e){e?.errorFields||s.message.error(e?.message||`Could not save communication limits`)}finally{a(!1)}},children:`Save`})]}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(cD,{type:`secondary`,children:`Set how many calls, SMS, WhatsApp messages and emails each counsellor can use per day. The same number applies to every counsellor and is shared across all their leads. The count starts again every day (India time); unused ones do not carry over.`})]}),(0,l.jsxs)(Z,{title:`Daily Limits`,children:[!t&&u&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:`Could not load the communication limits`,description:`${u}. The numbers below are only the defaults. Check that the backend has /communication-daily-limits, then press Reload.`,style:{marginBottom:16,maxWidth:620}}),!t&&!u&&!f.canEdit&&(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`Your role cannot change these limits. You can view them here.`,style:{marginBottom:16,maxWidth:620}}),(0,l.jsxs)(s.Spin,{spinning:t,children:[(0,l.jsx)(s.Form,{form:e,layout:`vertical`,initialValues:lD,style:{maxWidth:620},disabled:!f.canEdit,children:uD.map(({name:e,label:t,tooltip:n})=>(0,l.jsx)(s.Form.Item,{name:e,label:t,tooltip:n,rules:[{required:!0,message:`${t} is required`}],children:(0,l.jsx)(s.InputNumber,{min:0,max:f.maxLimit,precision:0,style:{width:`100%`},addonAfter:`per day`})},e))}),(0,l.jsxs)(cD,{type:`secondary`,children:[`Allowed range: 0 to `,f.maxLimit,`. Use 0 to block a channel. Where nothing has been saved, the default of `,f.defaultLimit,` per day is used.`]})]})]})]})}var{Content:fD,Header:pD,Sider:mD}=s.Layout,{Text:hD,Title:gD}=s.Typography;function _D(e){return String(e??``).trim().replace(/[\s_-]+/g,` `).toUpperCase()}function vD(e){return String(e||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim()}function yD(e){return String(e||``).trim().toLowerCase()}function bD(e){return e?.key||e?.collectionName||e?.value||``}function xD(e=[],t=[]){let n=[],r=new Set,i=new Set,a=new Set;return e.forEach(e=>{let t=bD(e);if(!t)return;let o=yD(e.key||t),s=yD(e.collectionName);e.seeded&&(i.add(o),s&&i.add(s)),s&&a.add(s),r.add(t),n.push({label:e.label||vD(t),value:t,disabled:!!e.seeded})}),t.forEach(e=>{let t=String(e||``).trim();if(!t||r.has(t))return;let o=yD(t);a.has(o)||i.has(o)||(r.add(t),n.push({label:vD(t),value:t,disabled:!1}))}),n}function SD(e){return _D(e?.user_type_name??e?.userTypeName??e?.name)===`SUPER ADMIN`}function CD(e){return`${e?.first_name??e?.firstName??``} ${e?.last_name??e?.lastName??``}`.trim()||e?.username||e?.userName||e?.email||`User ${e?.user_id??e?.userId??``}`}function wD(e){return e.flatMap(e=>{let t=e.menu_id??e.menuId??e.MenuID,n=e.menu_name??e.menuName??e.MenuName??`Menu ${t??``}`,r=e.menu_key??e.menuKey??e.MenuKey??``,i=e.permissions??e.Permissions??{};return Object.entries(i).map(([e,i])=>{let a=i.permission_id??i.permissionId??i.PermissionID,o=i.permission_key??i.permissionKey??i.PermissionKey??e,s=i.value??i.Value??i.access_value??i.accessValue??i;return{key:`${r??n??t}:${a??o}`,menuId:t,menuName:n,menuKey:r,permissionId:a,permissionKey:o,accessValue:+(Number(s)===1)}})})}function TD(e){return String(e.menuKey??e.menuName??e.menuId).trim().toLowerCase()}var ED=[{permissionId:null,permissionKey:`sendApprove`,permissionName:`Send Approve`}];function DD(e){let t=Array.isArray(e)?e:e?.permissions??e?.actions??e?.data??e,n=(Array.isArray(t)?t:Object.values(t??{})).map(e=>({permissionId:e.permission_id??e.permissionId??e.legacyPermissionId??e.id??null,permissionKey:e.permission_key??e.permissionKey??e.key,permissionName:e.permission_name??e.permissionName??e.name??e.label})).filter(e=>e.permissionKey),r=new Set(n.map(e=>String(e.permissionKey).trim().toLowerCase()));return ED.forEach(e=>{r.has(e.permissionKey.toLowerCase())||n.push(e)}),n}function OD(e={}){return String(e.permissionName??``).trim()||String(e.permissionKey??``).replaceAll(`_`,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/\b\w/g,e=>e.toUpperCase())}function kD({title:e,description:t,selectedName:n,loading:r,saving:i,rows:a,onChange:o,onMove:u,onSave:d}){let f=Object.values(a.reduce((e,t)=>{let n=TD(t);return e[n]||(e[n]={key:n,menuName:t.menuName,menuKey:t.menuKey,permissions:[]}),e[n].permissions.push(t),e},{}));return(0,l.jsxs)(`section`,{className:`admin-editor`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:e}),(0,l.jsx)(hD,{type:`secondary`,children:n||t})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:i,disabled:!n||a.length===0,onClick:d,children:`Save`})]}),r?(0,l.jsx)(`div`,{className:`admin-loading`,children:(0,l.jsx)(s.Spin,{})}):f.length?(0,l.jsx)(s.Table,{size:`small`,rowKey:`key`,columns:[{title:`Menu`,dataIndex:`menuName`,width:220,render:(e,t)=>(0,l.jsxs)(`div`,{className:`admin-menu-order-cell`,children:[(0,l.jsxs)(`div`,{className:`admin-menu-cell`,children:[(0,l.jsx)(`span`,{children:e}),(0,l.jsx)(hD,{type:`secondary`,children:t.menuKey})]}),(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{size:`small`,type:`text`,icon:(0,l.jsx)(c.ArrowUpOutlined,{}),onClick:()=>u(t.key,-1),"aria-label":`Move ${e} up`}),(0,l.jsx)(s.Button,{size:`small`,type:`text`,icon:(0,l.jsx)(c.ArrowDownOutlined,{}),onClick:()=>u(t.key,1),"aria-label":`Move ${e} down`})]})]})},{title:`Actions`,dataIndex:`permissions`,render:e=>(0,l.jsx)(`div`,{className:`admin-permission-controls`,children:e.filter(e=>Kx(e.menuName??e.menuKey,e.permissionKey)).map(e=>(0,l.jsx)(`label`,{className:`admin-permission-control`,children:(0,l.jsx)(s.Checkbox,{checked:e.accessValue===1,onChange:t=>o(e.key,+!!t.target.checked),"aria-label":`${e.menuName} ${e.permissionKey}`,children:OD(e)})},e.key))})}],dataSource:f,pagination:!1,scroll:{y:420}}):(0,l.jsx)(s.Empty,{description:`Select a record to customize permissions`})]})}function AD({onLogout:e}){let[r]=s.Form.useForm(),[i]=s.Form.useForm(),[a,u]=(0,o.useState)(`users`),[d,f]=(0,o.useState)(!0),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(0),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),[T,E]=(0,o.useState)(``),[D,O]=(0,o.useState)(!1),[k,A]=(0,o.useState)([]),[j,M]=(0,o.useState)([]),[N,P]=(0,o.useState)([]),[F,I]=(0,o.useState)(null),[L,R]=(0,o.useState)([]),[z,B]=(0,o.useState)(!1),[V,H]=(0,o.useState)(null),[ee,U]=(0,o.useState)(!1),[te,ne]=(0,o.useState)(null),[re,ie]=(0,o.useState)([]),[ae,W]=(0,o.useState)(!1),[oe,se]=(0,o.useState)(!1),[ce,le]=(0,o.useState)(null),[ue,de]=(0,o.useState)(!1),[G,fe]=(0,o.useState)(null),[pe,me]=(0,o.useState)(`listView`),[he,ge]=(0,o.useState)([]),[_e,ve]=(0,o.useState)([]),[ye,be]=(0,o.useState)(!1),[xe,K]=(0,o.useState)(!1),q=t.d(),Se=(0,o.useMemo)(()=>he.filter(e=>!e.disabled),[he]),Ce=!ye&&Se.length===0,we=(0,o.useCallback)(async()=>{be(!0);try{let[e,t]=await Promise.all([n.Ar(),n.xr()]),r=xD(e.modules,t),i=new Set(r.filter(e=>!e.disabled).map(e=>e.value));ge(r),ve(e=>e.filter(e=>i.has(e)))}catch{s.message.error(`Failed to load seed status`)}finally{be(!1)}},[]);(0,o.useEffect)(()=>{we()},[we]);async function Te(){if(_e.length===0){s.message.warning(Ce?`All modules already seeded.`:`Select at least one module to seed.`);return}K(!0);try{await n.pi(_e),s.message.success(`User type field config seeded`),ve([]),await we()}catch(e){s.message.error(e?.message||`Seed failed`)}finally{K(!1)}}async function Ee(){f(!0);try{let[e,t,n]=await Promise.allSettled([Px(),Rx(),Hx()]),r=e.status===`fulfilled`?e.value:[];e.status===`rejected`&&s.message.error(e.reason?.message||`Unable to load user types`),A(r??[]),M(t.status===`fulfilled`?t.value??[]:[]),P(n.status===`fulfilled`?DD(n.value):[]),I((r??[])[0]?.user_type_id??null)}catch(e){s.message.error(e.message||`Unable to load admin data`)}finally{f(!1)}}(0,o.useEffect)(()=>{queueMicrotask(()=>{Ee()})},[]);let De=(0,o.useCallback)(async()=>{O(!0);try{let{users:e,total:t}=await kx({limit:C,offset:(x-1)*C,search:T});v(e??[]),b(t??0)}catch(e){s.message.error(e?.message||`Unable to load users`),v([]),b(0)}finally{O(!1)}},[x,C,T]);(0,o.useEffect)(()=>{De()},[De]),(0,o.useEffect)(()=>{queueMicrotask(()=>{if(!F){R([]);return}m(!0),console.log(`DEBUG requesting role permissions for selectedUserTypeId=`,F,`localStorage scope=`,{tenantId:localStorage.getItem(`tenantId`),businessId:localStorage.getItem(`businessId`),businessUnitId:localStorage.getItem(`businessUnitId`)}),Ux(F).then(e=>{console.log(`DEBUG raw groups from /get-role-details`,e);let t=wD(e??[]);console.log(`DEBUG savedRows (jobs only)`,t.filter(e=>TD(e)===`jobs`||TD(e)===`job`));let n=new Map(t.map(e=>[`${TD(e)}:${String(e.permissionKey).toLowerCase()}`,e.accessValue]));console.log(`DEBUG savedAccess keys`,[...n.keys()]),console.log(`DEBUG menus (jobs only)`,j.filter(e=>String(e.menu_key??e.menu_name??e.menu_id).trim().toLowerCase()===`jobs`));let r=j.flatMap(e=>N.map(t=>{let r=String(e.menu_key??e.menu_name??e.menu_id).trim().toLowerCase(),i=String(t.permissionKey).toLowerCase();return{key:`${e.menu_key??e.menu_name??e.menu_id}:${t.permissionId??t.permissionKey}`,menuId:e.menu_id,menuName:e.menu_name,menuKey:e.menu_key,permissionId:t.permissionId,permissionKey:t.permissionKey,accessValue:n.get(`${r}:${i}`)??0}}));console.log(`DEBUG final rows (jobs only)`,r.filter(e=>TD(e)===`jobs`||TD(e)===`job`)),R(r)}).catch(e=>s.message.error(e.message||`Unable to load role permissions`)).finally(()=>m(!1))})},[F,j,N]);let Oe=(0,o.useMemo)(()=>k.find(e=>e.user_type_id===F),[F,k]),ke=(0,o.useMemo)(()=>k.reduce((e,t)=>({...e,[t.user_type_id]:t.user_type_name}),{}),[k]),Ae=(0,o.useMemo)(()=>_.reduce((e,t)=>({...e,[t.user_id]:CD(t)}),{}),[_]),je=(0,o.useMemo)(()=>k.filter(e=>!SD(e)),[k]),J=(0,o.useMemo)(()=>_.filter(e=>!SD({user_type_id:e.user_type_id,user_type_name:ke[e.user_type_id]})),[ke,_]);(0,o.useEffect)(()=>{if(!z){ie([]);return}let e=Number(r.getFieldValue(`user_type_id`)??0);if(!e){ie([]);return}let t=!1;return W(!0),Ax(e).then(e=>{t||ie(e.filter(e=>!V||e.user_id!==V.user_id))}).catch(e=>{t||(s.message.error(e.message||`Unable to load reporting users`),ie([]))}).finally(()=>{t||W(!1)}),()=>{t=!0}},[V,r,z]);let Me=(0,o.useMemo)(()=>{let e=re.map(e=>({label:CD(e),value:e.user_id})),t=Number(V?.reporting_id??V?.reportingId??0);return!t||e.some(e=>Number(e.value)===t)?e:[{label:V?.reportingName??V?.reporting_name??Ae[t]??`User ${t}`,value:t},...e]},[V,re,Ae]),Ne=(0,o.useMemo)(()=>{let e=je.map(e=>({label:e.user_type_name,value:e.user_type_id}));if(!V)return e;let t=Number(V.user_type_id??0);return e.some(e=>Number(e.value)===t)?e:[{label:ke[t]??V.userType??V.roleName??(t>0?`Type ${t}`:`Unassigned`),value:t},...e]},[V,je,ke]);k.length,j.length;let Pe=[{key:`form-groups`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Form Groups`]}),title:`Form Groups`,description:`Build module add and edit form groups with validations, dropdowns, and custom forms.`,component:(0,l.jsx)(ow,{})},{key:`detail-groups`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.BgColorsOutlined,{}),` Detail Groups`]}),title:`Detail Groups`,description:`Control detail-view labels, rendering, lookups, merged fields, and display defaults.`,component:(0,l.jsx)(Vw,{})},{key:`actions`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` Actions`]}),title:`Actions`,description:`Manage row action buttons and their visibility rules from one workspace.`,component:(0,l.jsx)(AT,{})},{key:`templates`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MailOutlined,{}),` Templates`]}),title:`Templates`,description:`Manage reusable email templates and signatures.`,component:(0,l.jsx)(HT,{})},{key:`ai-services`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ThunderboltOutlined,{}),` AI Services`]}),title:`AI Services`,description:`Register the AI and automation services used by admin-configured AI actions.`,component:(0,l.jsx)(KT,{})},{key:`bgc-integration`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` Integrations`]}),title:`Integrations`,description:`Manage manual and API integrations used across application workflows.`,component:(0,l.jsx)(QT,{})},{key:`automations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ApartmentOutlined,{}),` Automations`]}),title:`Automations`,description:`Reference ids, duplicate checks, cross-module snapshots, reporting-chain hierarchy expansion, board updates, notifications, and cache invalidation — per module, config-driven.`,component:(0,l.jsx)(TE,{})},{key:`workflows`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.ApartmentOutlined,{}),` Workflows`]}),title:`Workflows`,description:`Event-driven behavior per module (beforeCreate/afterCreate/…): the metadata the platform Workflow Engine executes — where the jobs, candidates, and submissions create flows live.`,component:(0,l.jsx)(NE,{})},{key:`po-msa-settings`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` PO/MSA Settings`]}),title:`PO/MSA Settings`,description:`Configure employer and referral MSA validity and expiry warning days.`,component:(0,l.jsx)(tD,{})},{key:`po-msa-settings`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` PO/MSA Settings`]}),title:`PO/MSA Settings`,description:`Configure employer and referral MSA validity and expiry warning days.`,component:(0,l.jsx)(tD,{})},{key:`communication-limits`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MessageOutlined,{}),` Communication Limits`]}),title:`Communication Limits`,description:`Set the daily number of calls, SMS, WhatsApp messages and emails each counsellor can use.`,component:(0,l.jsx)(dD,{})},{key:`masters`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Masters`]}),title:`Masters`,description:`Shared Location and Tax lists used across modules (e.g. the submission form’s W2 employer section).`,component:(0,l.jsx)(QE,{})}],Fe=[{key:`users`,icon:(0,l.jsx)(c.UserOutlined,{}),label:`Users`},{key:`roles`,icon:(0,l.jsx)(c.TeamOutlined,{}),label:`User Types`},{key:`menus`,icon:(0,l.jsx)(c.MenuOutlined,{}),label:`Menus`},{key:`configurations`,icon:(0,l.jsx)(c.AppstoreAddOutlined,{}),label:`Configurations`},{key:`integrations`,icon:(0,l.jsx)(c.SafetyCertificateOutlined,{}),label:`Integrations`}];function Ie(e,t){R(n=>{let r=n.filter(t=>t.key===e).length;return console.log(`DEBUG updateRolePermission`,{key:e,value:t,matchCount:r}),n.map(n=>n.key===e?{...n,accessValue:t}:n)})}async function Le(){g(!0);try{console.log(`DEBUG saveRolePermissions jobs rows`,L.filter(e=>TD(e)===`jobs`||TD(e)===`job`)),await Wx(F,L.map(e=>({menu_id:e.menuId,menu_name:e.menuName,menu_key:e.menuKey,permission_id:e.permissionId,permission_key:e.permissionKey,access_value:e.accessValue,updated_by:q?.userId??null}))),s.message.success(`Role permissions updated`)}catch(e){s.message.error(e.message||`Unable to save role permissions`)}finally{g(!1)}}function Re(){H(null),r.resetFields(),r.setFieldsValue({status:`ACTIVE`,user_type_id:je[0]?.user_type_id,reporting_id:0}),B(!0)}function ze(e){H(e),r.setFieldsValue({first_name:e.first_name,last_name:e.last_name,username:e.username,email:e.email,mobile:e.mobile,user_type_id:e.user_type_id,reporting_id:e.reporting_id??e.reportingId??0,profile_image:e.profile_image,status:e.status}),B(!0)}async function Be(e){U(!0);try{let t={...e,status:e.status===1||e.status===`1`||e.status===!0?`ACTIVE`:e.status===0||e.status===`0`||e.status===!1?`INACTIVE`:String(e.status??`ACTIVE`).toUpperCase(),updated_by:q?.userId??null,created_by:q?.userId??null};t.password||delete t.password,V?(await Mx(V.user_id,t),s.message.success(`User updated`)):(await jx(t),s.message.success(`User created`)),B(!1),H(null),await De()}catch(e){s.message.error(e.message||`Unable to save user`)}finally{U(!1)}}async function Y(e){ne(e);try{await Nx(e),s.message.success(`User deleted`),await De()}catch(e){s.message.error(e.message||`Unable to delete user`)}finally{ne(null)}}function Ve(e,t){me(`listView`),fe({kind:e,record:t}),e===`role`&&I(t.user_type_id)}function He(e,t){R(n=>{let r=[...new Set(n.map(TD))],i=r.indexOf(e),a=i+t;if(i<0||a<0||a>=r.length)return n;[r[i],r[a]]=[r[a],r[i]];let o=new Map(r.map((e,t)=>[e,t]));return[...n].sort((e,t)=>o.get(TD(e))-o.get(TD(t)))})}function Ue(){le(null),i.resetFields(),i.setFieldsValue({status:`ACTIVE`}),se(!0)}function X(e){le(e),se(!0),i.setFieldsValue(e)}async function We(e){de(!0);try{let t=q?.userId??null,n=!!ce,r=n?await Ix(ce.user_type_id,{...e,updated_by:t}):await Fx({...e,created_by:t,visible_menu_ids:[]}),i=r.user_type_id;s.message.success(n?`User type updated`:`User type created. Customize its menus and permissions.`),se(!1),await Ee(),I(i),n||(me(`permissions`),fe({kind:`role`,record:{...e,...r,user_type_id:i,user_type_name:r.user_type_name??e.user_type_name}}))}catch(e){s.message.error(e.message||`Unable to save role`)}finally{de(!1)}}async function Ge(e){try{await Lx(e),s.message.success(`Role deleted`),await Ee()}catch(e){s.message.error(e.message||`Unable to delete role`)}}return(0,l.jsxs)(s.Layout,{className:`admin-shell`,children:[(0,l.jsx)(mD,{width:248,className:`admin-sider`,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-nav`,children:[(0,l.jsx)(hD,{className:`admin-sidebar-title`,children:`Admin Menu`}),(0,l.jsx)(s.Menu,{theme:`dark`,mode:`inline`,selectedKeys:[a],onClick:({key:e})=>u(e),items:Fe})]})}),(0,l.jsx)(s.Layout,{children:(0,l.jsxs)(fD,{className:`admin-content`,children:[(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(s.Tabs,{activeKey:a,onChange:u,tabBarStyle:{display:`none`},items:[{key:`users`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.UserOutlined,{}),` Users`]}),children:(0,l.jsx)(`div`,{className:`admin-stack`,children:(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:`Users`}),(0,l.jsx)(hD,{type:`secondary`,children:`Create and manage users with non-super-admin user types.`})]}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:Re,children:`Add`})]}),(0,l.jsx)($m,{listName:`Users`,loading:D,fields:[{label:`Name`,value:`first_name`,render:(e,t)=>`${e??``} ${t.last_name??``}`.trim()||t.username},{label:`Email`,value:`email`},{label:`User Type`,value:`user_type_id`,width:160,render:(e,t)=>ke[e]||t?.userType||t?.user_type||(Number(e)>0?`Type ${e}`:`—`)},{label:`Reporting Manager`,value:`reporting_id`,width:180,render:(e,t)=>Ae[e]||t?.reportingName||t?.reporting_name||(Number(e)>0?`User ${e}`:`None`)},{label:`Status`,value:`status`,width:110,sorter:!1,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{label:`Actions`,value:`_actions`,width:150,sorter:!1,render:(e,t)=>(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Edit user`,icon:(0,l.jsx)(c.EditOutlined,{}),size:`small`,onClick:()=>ze(t)}),(0,l.jsx)(s.Popconfirm,{title:`Delete user?`,description:`This removes the user from the auth database.`,okText:`Delete`,okButtonProps:{danger:!0},onConfirm:()=>Y(t.user_id),children:(0,l.jsx)(s.Button,{danger:!0,"aria-label":`Delete user`,icon:(0,l.jsx)(c.DeleteOutlined,{}),loading:te===t.user_id,size:`small`})})]})}],dataSource:J.map(e=>({...e,key:e.user_id})),total:y,current:x,pageSize:C,onPageChange:S,onPageSizeChange:e=>{w(e),S(1)},onSearch:e=>{E(e??``),S(1)},rowSelection:!1})]})})},{key:`roles`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.TeamOutlined,{}),` User Types`]}),children:(0,l.jsxs)(`div`,{className:`admin-stack`,children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Field Config Seed`,style:{marginBottom:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,flexWrap:`wrap`},children:[(0,l.jsx)(`div`,{style:{minWidth:320,flex:1},children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,showSearch:!0,value:_e,options:he,placeholder:Ce?`All modules already seeded`:`Select modules or collections to seed`,disabled:ye||xe||Ce,loading:ye,onChange:ve,style:{width:`100%`}})}),(0,l.jsx)(s.Button,{type:`primary`,loading:xe,disabled:ye||_e.length===0,onClick:Te,children:`Seed Field Config`})]}),(0,l.jsx)(hD,{type:`secondary`,style:{display:`block`,marginTop:8,fontSize:12},children:Ce?`Seed is disabled because all configured modules already have user type field config data.`:`Already seeded modules are disabled. New modules or collections can still be seeded.`})]}),(0,l.jsxs)(`section`,{className:`admin-section`,children:[(0,l.jsx)(`div`,{className:`admin-section-head`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:`Integrations`}),(0,l.jsx)(hD,{type:`secondary`,children:`Configure external services used by onboarding and other workflows.`})]})}),(0,l.jsxs)(`div`,{className:`admin-config-panel`,children:[(0,l.jsx)(`div`,{className:`admin-config-panel-body`,children:(0,l.jsx)(s.Tabs,{defaultActiveKey:`facebook-courses`,items:[{key:`facebook-courses`,label:`Facebook Form → Course Mapping`,children:(0,l.jsx)(dE,{})},{key:`service-integrations`,label:`Other Integrations`,children:(0,l.jsx)(QT,{})}]})}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:Ue,children:`Add Role`})]}),(0,l.jsx)($m,{listName:`User Types`,loading:d,fields:[{label:`User Type`,value:`user_type_name`},{label:`Description`,value:`description`},{label:`Status`,value:`status`,width:110,sorter:!1,render:e=>(0,l.jsx)(s.Tag,{color:e===`ACTIVE`?`green`:`default`,children:e})},{label:`Actions`,value:`_actions`,width:260,sorter:!1,render:(e,t)=>{let n=Number(t.role_type)===1;return(0,l.jsxs)(s.Space,{size:4,children:[(0,l.jsx)(s.Button,{"aria-label":`Configure role`,size:`small`,onClick:()=>Ve(`role`,t),children:`Config`}),(0,l.jsx)(s.Button,{"aria-label":`Edit role`,disabled:!n,icon:(0,l.jsx)(c.EditOutlined,{}),size:`small`,onClick:()=>X(t)}),n&&!SD(t)&&(0,l.jsx)(s.Popconfirm,{title:`Delete role?`,onConfirm:()=>Ge(t.user_type_id),children:(0,l.jsx)(s.Button,{"aria-label":`Delete role`,danger:!0,icon:(0,l.jsx)(c.DeleteOutlined,{}),size:`small`})})]})}}],dataSource:k.map(e=>({...e,key:e.user_type_id,roleId:e.user_type_id,roleName:e.user_type_name})),total:k.length,rowSelection:!1})]})]})},{key:`menus`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.MenuOutlined,{}),` Menus`]}),children:(0,l.jsx)(sD,{})},{key:`configurations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.AppstoreAddOutlined,{}),` Configurations`]}),children:(0,l.jsxs)(`section`,{className:`admin-section admin-config-workspace`,children:[(0,l.jsxs)(`div`,{className:`admin-section-head`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:`Configuration Center`}),(0,l.jsx)(hD,{type:`secondary`,children:`CORE-THEME admin modules embedded into the admin dashboard.`})]}),(0,l.jsxs)(s.Tag,{color:`blue`,children:[Pe.length,` configurations`]})]}),(0,l.jsx)(s.Tabs,{className:`admin-config-tabs`,defaultActiveKey:`form-groups`,tabPosition:`left`,items:Pe.map(e=>({key:e.key,label:e.label,children:(0,l.jsxs)(`div`,{className:`admin-config-panel`,children:[(0,l.jsx)(`div`,{className:`admin-config-panel-head`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:e.title}),(0,l.jsx)(hD,{type:`secondary`,children:e.description})]})}),(0,l.jsx)(`div`,{className:`admin-config-panel-body`,children:e.component})]})}))})]})},{key:`integrations`,label:(0,l.jsxs)(`span`,{children:[(0,l.jsx)(c.SafetyCertificateOutlined,{}),` Integrations`]}),children:(0,l.jsxs)(`section`,{className:`admin-section admin-config-workspace`,children:[(0,l.jsx)(`div`,{className:`admin-section-head`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(gD,{level:4,children:`Integrations`}),(0,l.jsx)(hD,{type:`secondary`,children:`Configure external services used by onboarding and other workflows.`})]})}),(0,l.jsx)(`div`,{className:`admin-config-panel`,children:(0,l.jsx)(`div`,{className:`admin-config-panel-body`,children:(0,l.jsx)(QT,{})})})]})}]})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,title:`Configure User Type: ${G?.record?.user_type_name??``}`,open:!!G,onCancel:()=>fe(null),footer:null,destroyOnHidden:!0,width:900,children:[(0,l.jsx)(`div`,{className:`uss-config-toggle`,style:{marginBottom:12},children:[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`},{key:`permissions`,label:`Permissions`},{key:`actions`,label:`Actions`}].map(e=>(0,l.jsx)(`button`,{type:`button`,className:`uss-config-btn${pe===e.key?` active`:``}`,onClick:()=>me(e.key),children:e.label},e.key))}),G&&pe===`permissions`?(0,l.jsx)(kD,{title:`Role Permissions`,description:`Configure menu permissions for this user type`,selectedName:Oe?.user_type_name,loading:p,saving:h,rows:L,onChange:Ie,onMove:He,onSave:Le}):G&&pe===`actions`?(0,l.jsx)(OS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name}},`${G.record?.user_type_id}-actions`):G&&pe===`form`?(0,l.jsx)(bS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name}},`${G.record?.user_type_id}-form`):G?(0,l.jsx)(lS,{role:{...G.record,roleId:G.record.user_type_id,roleName:G.record.user_type_name},configType:pe},`${G.record?.user_type_id}-${pe}`):null]}),(0,l.jsx)(s.Modal,{className:`admin-role-modal`,title:ce?`Edit User Type`:`Create User Type`,open:oe,onCancel:()=>se(!1),onOk:()=>i.submit(),okText:ce?`Save`:`Next`,confirmLoading:ue,destroyOnHidden:!0,width:900,children:(0,l.jsxs)(s.Form,{form:i,layout:`vertical`,onFinish:We,children:[(0,l.jsx)(s.Form.Item,{name:`user_type_name`,label:`Role name`,rules:[{required:!0,message:`Role name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`Recruiter`})}),(0,l.jsx)(s.Form.Item,{name:`description`,label:`Description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3})}),(0,l.jsx)(s.Form.Item,{name:`status`,label:`Status`,children:(0,l.jsx)(s.Select,{options:[{value:`ACTIVE`},{value:`INACTIVE`}]})})]})}),(0,l.jsx)(s.Modal,{className:`admin-user-modal`,title:V?`Edit User`:`Add User`,open:z,onCancel:()=>B(!1),onOk:()=>r.submit(),confirmLoading:ee,destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:r,layout:`vertical`,requiredMark:!1,onFinish:Be,children:[(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{label:`First Name`,name:`first_name`,rules:[{required:!0,message:`First name is required`}],children:(0,l.jsx)(s.Input,{placeholder:`John`})}),(0,l.jsx)(s.Form.Item,{label:`Last Name`,name:`last_name`,children:(0,l.jsx)(s.Input,{placeholder:`Doe`})})]}),(0,l.jsx)(s.Form.Item,{label:`Username`,name:`username`,rules:[{required:!0,message:`Username is required`}],children:(0,l.jsx)(s.Input,{placeholder:`john.doe`})}),(0,l.jsx)(s.Form.Item,{label:`Email`,name:`email`,rules:[{required:!0,message:`Email is required`},{type:`email`,message:`Enter a valid email`}],children:(0,l.jsx)(s.Input,{placeholder:`john@example.com`})}),(0,l.jsx)(s.Form.Item,{label:`Password`,name:`password`,rules:V?[]:[{required:!0,message:`Password is required`}],children:(0,l.jsx)(s.Input.Password,{placeholder:V?`Leave empty to keep current password`:`Password`})}),(0,l.jsxs)(`div`,{className:`admin-form-row`,children:[(0,l.jsx)(s.Form.Item,{label:`Mobile`,name:`mobile`,children:(0,l.jsx)(s.Input,{placeholder:`9999999999`})}),(0,l.jsx)(s.Form.Item,{label:`User Type`,name:`user_type_id`,rules:[{required:!0,message:`User type is required`}],children:(0,l.jsx)(s.Select,{placeholder:`Select user type`,onChange:()=>{ie([]),queueMicrotask(()=>{let e=Number(r.getFieldValue(`user_type_id`)??0);e&&(W(!0),Ax(e).then(e=>{ie(e.filter(e=>!V||e.user_id!==V.user_id))}).catch(e=>{s.message.error(e.message||`Unable to load reporting users`),ie([])}).finally(()=>{W(!1)}))})},options:Ne})})]}),(0,l.jsx)(s.Form.Item,{label:`Reporting Manager`,name:`reporting_id`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:ae,placeholder:`Select reporting manager`,optionFilterProp:`label`,options:[{label:`None`,value:0},...Me]})}),(0,l.jsx)(s.Form.Item,{label:`Profile Image`,name:`profile_image`,children:(0,l.jsx)(s.Input,{placeholder:`https://...`})}),(0,l.jsx)(s.Form.Item,{label:`Status`,name:`status`,children:(0,l.jsx)(s.Select,{options:[{label:`ACTIVE`,value:`ACTIVE`},{label:`INACTIVE`,value:`INACTIVE`}]})})]})})]})})]})}var jD=AD;function MD(e,t){return String(e||t).replace(/\/\*$/,``).replace(/\/+$/,``)||t}function ND({loginPath:e=`/login`,adminPath:t=`/admin`,fallbackPath:n=`/`}){let r=(0,d.useNavigate)(),i=MD(e,`/login`),a=MD(t,`/admin`),o=`${a}/*`;return(0,l.jsxs)(d.Routes,{children:[(0,l.jsx)(d.Route,{path:i,element:(0,l.jsx)(Fb,{defaultRedirectPath:a,onLogin:()=>r(a,{replace:!0})})}),(0,l.jsx)(d.Route,{path:o,element:(0,l.jsx)(Db,{loginPath:i,children:(0,l.jsx)(Pb,{children:(0,l.jsx)(jD,{onLogout:()=>r(i,{replace:!0})})})})}),(0,l.jsx)(d.Route,{path:n,element:(0,l.jsx)(d.Navigate,{to:a,replace:!0})}),(0,l.jsx)(d.Route,{path:`*`,element:(0,l.jsx)(d.Navigate,{to:a,replace:!0})})]})}function PD(e){return(0,l.jsx)(d.BrowserRouter,{children:(0,l.jsx)(ND,{...e})})}function FD(e){return Array.isArray(e)?e.map(String).map(e=>e.trim()).filter(Boolean):String(e??``).split(`,`).map(e=>e.trim()).filter(Boolean)}function ID(e){return FD(e).every(e=>/^[^,\s@]+@[^,\s@]+\.[^\s@]{2,}$/.test(e))}var{Text:LD}=s.Typography,RD=new Set([`file`,`document`,`attachment`]);function zD(e){return RD.has(String(e?.type??``).trim().toLowerCase())}function BD(e){return String(e??``).trim().toLowerCase().replace(/[^a-z0-9]/g,``)}function VD(e){return e?typeof e==`string`?e:String(typeof e==`object`?e?._id??e?.id??e?.$oid??``:e):``}function HD(e,t,n){if(!e)return``;let r=BD(t),i=BD(n);if(!r||r===i||r.replace(/s$/,``)===i.replace(/s$/,``))return VD(e?._id??e?.id);let a=r.replace(/s$/,``),o=[`${a}Id`,`${r}Id`,a,r,`${a}._id`,`${r}._id`];for(let t of o){let n=VD(qD(e,t));if(n)return n}return``}async function UD(e){let t=e?.fileUrl??e?.url??e?.downloadUrl;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load attachment ${e?.fileName||``}`.trim());let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.uniqueName??`attachment`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function WD(e,t,r){if(!t)return[];let i=[];(e?.placeholders??[]).forEach(e=>{(e?.holders??[]).filter(zD).forEach(a=>{let o=HD(t,e?.moduleName,r);o&&i.push((async()=>{let t=await n.yn(e.moduleName,o,a.value);return Promise.all((t?.data??[]).map(UD))})())})});let a=(await Promise.all(i)).flat().filter(Boolean),o=new Set;return a.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!o.has(t)&&(o.add(t),!0)})}function GD(e,t){return[...new Set([...FD(e),...FD(t)])].join(`, `)}function KD(e=[],t=[]){let n=new Set;return[...e,...t].filter(e=>{if(!e)return!1;let t=`${e.name}:${e.size}:${e.type}`;return!n.has(t)&&(n.add(t),!0)})}function qD(e,t,n=``){let r=String(n??``).trim().toLowerCase();return String(t??``).split(`.`).reduce((e,t)=>{let n=e;return Array.isArray(n)&&r===`last`&&(n=n.at(-1)),n?.[t]},e)}function JD(e,t,n){if(!n)return String(e??``);let r=new Map;return(t??[]).forEach(e=>(e.holders??[]).forEach(e=>{r.set(e.key,zD(e)?``:qD(n,e.value,e.arrayMode))})),String(e??``).replace(/{{\.?([\w.]+)}}/g,(e,t)=>{let n=r.get(t);return n==null?e:String(n)})}function YD({value:e,onChange:t,defaultTemplateId:r=``,ready:i=!0,title:a=`Mail`,hint:u,bccHint:d,afterBcc:f,beforeFields:p,className:m=``,contextRecords:h=[],moduleName:g=``}){let _=(0,o.useRef)(``),v=n=>t?.({...e,...n});async function y(t,n=!1){if(t)try{let r=await Zw(t),i=h[0],a=await WD(r,i,g);v({to:GD(e.to,(r?.toMail??[]).map(e=>JD(e,r?.placeholders,i))),cc:GD(e.cc,(r?.ccMail??[]).map(e=>JD(e,r?.placeholders,i))),bcc:GD(e.bcc,(r?.bccMail??[]).map(e=>JD(e,r?.placeholders,i))),subject:JD(r?.subject,r?.placeholders,i),contents:JD(r?.body,r?.placeholders,i),attachments:KD(e.attachments,a)}),n||s.message.success(`Loaded ${r?.name||`email template`}`)}catch(e){n||s.message.error(e?.message||`Could not load email template`)}}return(0,o.useEffect)(()=>{!i||!r||_.current===r||(_.current=r,y(r,!0))},[r,i]),(0,l.jsxs)(`div`,{className:`common-mail-composer ${m}`.trim(),children:[(0,l.jsx)(`div`,{className:`mail-popup__header`,children:(0,l.jsxs)(`div`,{className:`mail-popup__header-brand`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box`,children:(0,l.jsx)(c.MailOutlined,{})}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:a}),u&&(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__header-hint`,children:u})]})]})}),(0,l.jsxs)(`div`,{className:`mail-popup__body`,children:[p&&(0,l.jsxs)(l.Fragment,{children:[p,(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`To`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:FD(e.to),onChange:e=>v({to:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`,placeholder:`Add email addresses`}),(0,l.jsxs)(`div`,{className:`mail-popup__cc-bcc-actions`,children:[!e.showCc&&(0,l.jsx)(`span`,{className:`mail-popup__cc-bcc-link`,onClick:()=>v({showCc:!0}),children:`Cc`}),!e.showBcc&&(0,l.jsx)(`span`,{className:`mail-popup__cc-bcc-link`,onClick:()=>v({showBcc:!0}),children:`Bcc`})]})]}),(0,l.jsx)(s.Divider,{}),e.showCc&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`Cc`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:FD(e.cc),onChange:e=>v({cc:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`})]}),(0,l.jsx)(s.Divider,{})]}),e.showBcc&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`Bcc`}),(0,l.jsx)(s.Select,{mode:`tags`,open:!1,tokenSeparators:[`,`],value:FD(e.bcc),onChange:e=>v({bcc:e.join(`, `)}),variant:`borderless`,className:`mail-popup__recipient-select`,placeholder:d})]}),f,(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`Subject`}),(0,l.jsx)(s.Input,{variant:`borderless`,value:e.subject,onChange:e=>v({subject:e.target.value}),placeholder:`Enter subject`,className:`mail-popup__field-input`})]}),(0,l.jsx)(s.Divider,{}),!!e.attachments?.length&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`mail-popup__field-row`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__field-label`,children:`Attachments`}),(0,l.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:6,padding:`4px 0`},children:e.attachments.map((e,t)=>(0,l.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:4},children:[(0,l.jsx)(c.PaperClipOutlined,{}),e.name]},`${e.name}:${e.size}:${t}`))})]}),(0,l.jsx)(s.Divider,{})]}),(0,l.jsxs)(`div`,{className:`mail-popup__message-section`,children:[(0,l.jsx)(LD,{type:`secondary`,className:`mail-popup__message-label`,children:`Message`}),(0,l.jsx)(n.On,{value:e.contents,onChange:e=>v({contents:e})})]})]})]})}var{Text:XD}=s.Typography,ZD=/^[a-fA-F0-9]{24}$/,QD=new Set([`file`,`document`,`attachment`]);function $D(e){return e?typeof e==`object`?$D(e.$oid??e._id??e.id??e.oid):String(e).trim():``}async function eO(e){let t=e?.fileUrl??e?.url??e?.downloadUrl;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load attachment ${e?.fileName||``}`.trim());let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.uniqueName??`attachment`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function tO(e,t,r=[]){let i=String(e??``);if(!i||!r.length||!t)return{contents:i,attachments:[]};let a=(await n.Ur(t).catch(()=>[])).filter(e=>QD.has(String(e?.type??``).trim().toLowerCase())).filter(e=>{let t=String(e?.value??e?.field??e?.fieldKey??e?.key??e?.name??``).replace(/^\./,``);return t&&(i.includes(`{{.${t}}}`)||i.includes(`{{${t}}}`))});if(!a.length)return{contents:i,attachments:[]};let o=[];for(let e of a){let a=String(e?.value??e?.field??e?.fieldKey??e?.key??e?.name??``).replace(/^\./,``);i=i.replaceAll(`{{.${a}}}`,``).replaceAll(`{{${a}}}`,``);for(let e of r){let r=String(e?._id??e?.id??``);if(!ZD.test(r))continue;let i=await n.yn(t,r,a).catch(()=>({data:[]})),s=await Promise.all((i?.data??[]).map(eO));o.push(...s.filter(Boolean))}}let s=new Set,c=o.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!s.has(t)&&(s.add(t),!0)});return{contents:i,attachments:c}}function nO(e){return e===!0?!0:typeof e==`number`?e===1:typeof e==`string`&&[`true`,`1`,`yes`,`y`,`on`].includes(e.trim().toLowerCase())}function rO(e){return[`candidate`,`candidates`].includes(String(e??``).trim().toLowerCase())}function iO(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&String(t).trim()!==``)return t}}function aO(e){return[iO(e,`jobReferenceId`,`clientJobId`,`jobCode`,`reqId`,`jobId`),iO(e,`jobTitle`,`title`,`name`)].filter(Boolean).join(` - `)||String(iO(e,`_id`,`id`)??`Job`)}function oO(e){let t=iO(e,`_id`,`id`,`jobId`);return t?{value:String(t),label:aO(e),raw:e}:null}function sO(e=[],t=[]){let n=[...t,`email`,`candidateEmail`,`candidate_email`,`emailId`,`mailId`,`alternateEmail`,`altEmail`,`basicDetails.email`,`basicDetails.alternateEmail`,`basicDetails.altEmail`,`candidate.email`,`candidate.emailId`,`submission.email`,`submission.candidateEmail`].filter(Boolean);return e.flatMap(e=>n.map(t=>iO(e,t))).flatMap(e=>Array.isArray(e)?e:[e]).flatMap(FD)}function cO(e){return e?.data?.record??e?.record??e?.data??e}function lO(e){let t=iO(e,`jobId`,`job_id`,`job._id`,`job.id`,`jobs._id`,`jobs.id`);return typeof t==`object`?iO(t,`_id`,`id`,`$oid`):t}function uO(e={}){return{subject:e.subject??e.Subject??``,contents:e.contents??e.Contents??e.body??e.Body??``,toMail:e.toMail??e.ToMail??[],ccMail:e.ccMail??e.CcMail??[],bccMail:e.bccMail??e.BccMail??[]}}function dO(){let e=(0,d.useNavigate)(),{state:t={}}=(0,d.useLocation)(),{selectedIds:r=[],selectedRecords:i=[],recipients:a=[],subject:c=``,contents:u=``,attachments:f=[],onSend:p,moduleName:m=``,popupAction:h={}}=t,g=String(t.mailTarget??``).toLowerCase()===`lead`||String(m??``).trim().toLowerCase()===`lead`,_=g?$D(t.leadId??i[0]?.leadId??i[0]?._id??i[0]?.id??r[0]):``,v=!g&&(nO(h.requireJobId)||nO(t.requireJobId)||rO(m)),y=(0,o.useMemo)(()=>[h.recipientField,h.recipientPath,t.recipientField,t.recipientPath],[h.recipientField,h.recipientPath,t.recipientField,t.recipientPath]),b=r.join(`|`),x=(0,o.useMemo)(()=>[...a,...sO(i,y)],[a,i,y]),S=g?``:String(t.jobId??lO(i[0])??``).trim(),C=g?``:r[0]??i[0]?._id??i[0]?.id??``,[w,T]=(0,o.useState)(S),[E,D]=(0,o.useState)(v?S:String(S||C||``)),[O,k]=(0,o.useState)({to:[...new Set(x)].join(`, `),cc:``,bcc:``,subject:c,contents:u,attachments:f,showCc:!1,showBcc:!1}),[A,j]=(0,o.useState)(!E),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)([]),[I,L]=(0,o.useState)(!1),[R,z]=(0,o.useState)(!1),B=(0,o.useRef)(!1),V=(0,o.useRef)(``),H=(0,o.useRef)(0);(0,o.useEffect)(()=>{if(!rO(m)||B.current||FD(O.to).length>0||r.length===0||V.current===b)return;let e=!1;return V.current=b,Promise.all(r.map(e=>n.hn(m,e).catch(()=>null))).then(t=>{if(e)return;let n=sO(t.map(cO).filter(Boolean),y);n.length&&k(e=>FD(e.to).length>0?e:{...e,to:[...new Set(n)].join(`, `)})}),()=>{e=!0}},[O.to,m,y,b,r]),(0,o.useEffect)(()=>{if(!E){j(!0);return}let e=++H.current,t=!1;async function n(){j(!1),N(!0),k(e=>({...e,contents:``}));try{let n=uO(await dn(E)),r=await tO(n.contents||``,m,i),a=r.contents;if(a.trim())try{a=await fn(a,n.subject||c)}catch(n){!t&&e===H.current&&s.message.warning(n?.message||`Mail content formatting failed. Showing original content.`)}if(t||e!==H.current)return;k(e=>({...e,subject:n.subject||e.subject,to:n.toMail?.length?Array.isArray(n.toMail)?n.toMail.join(`, `):String(n.toMail):e.to,cc:n.ccMail?.length?Array.isArray(n.ccMail)?n.ccMail.join(`, `):String(n.ccMail):e.cc,bcc:n.bccMail?.length?Array.isArray(n.bccMail)?n.bccMail.join(`, `):String(n.bccMail):e.bcc,contents:a||r.contents||e.contents,attachments:r.attachments,showCc:e.showCc||!!n.ccMail?.length,showBcc:e.showBcc||!!n.bccMail?.length}))}catch(n){!t&&e===H.current&&v&&s.message.error(n?.message||`Could not load mail template for this Job ID`)}finally{!t&&e===H.current&&(j(!0),N(!1))}}return n(),()=>{t=!0}},[E,v]);function ee(e=w){let t=String(e??``).trim();if(!ZD.test(t)){D(``),t&&s.message.warning(`Enter a valid 24-character Job ID`);return}if(t===E){D(``),queueMicrotask(()=>D(t));return}D(t)}function U(e,t){if(!e){D(``),T(``);return}let n=t?.label??``;T(String(n||(e??``))),ee(e)}function te(e){let t=String(e??``).trim();if(T(t),t.length<3){F([]);return}L(!0),ie(t).then(e=>{let t=(Array.isArray(e)?e:[]).map(oO).filter(Boolean);F(t)}).catch(e=>s.message.error(e?.message||`Unable to search jobs`)).finally(()=>L(!1))}let ne=A&&(!v||ZD.test(E))&&(!g||ZD.test(_))&&FD(O.to).length+FD(O.cc).length+FD(O.bcc).length>0&&ID(O.to)&&ID(O.cc)&&ID(O.bcc)&&O.subject.trim()&&O.contents.trim();async function re(){if(!(!ne||R)){z(!0);try{await pn({jobId:E,leadId:_,toMail:FD(O.to),ccMail:FD(O.cc),bccMail:FD(O.bcc),subject:O.subject,contents:O.contents,attachments:O.attachments??[]}),s.message.success(`Mail sent successfully`),typeof p==`function`&&p({...O,message:O.contents,selectedIds:r}),e(-1)}catch(e){s.message.error(e?.message||`Failed to send mail`)}finally{z(!1)}}}function ae(e){e?.to!==O.to&&(B.current=!0),k(e)}return(0,l.jsx)(s.Drawer,{open:!0,placement:`right`,onClose:()=>e(-1),closable:!1,rootClassName:`mail-popup`,width:620,maskClosable:!1,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>e(-1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:R,disabled:!ne,onClick:re,children:`Send`})]}),children:(0,l.jsx)(s.Spin,{spinning:M,tip:`Loading mail content...`,size:`large`,children:(0,l.jsx)(YD,{value:O,onChange:ae,moduleName:m,defaultTemplateId:v?``:h.defaultTemplateId??t.defaultTemplateId??``,ready:A,contextRecords:i,beforeFields:v?(0,l.jsxs)(`div`,{className:`mail-popup__job-row`,children:[(0,l.jsx)(XD,{type:`secondary`,className:`mail-popup__field-label`,children:`Job Title / ID`}),(0,l.jsx)(s.Select,{showSearch:!0,allowClear:!0,filterOption:!1,value:E||void 0,searchValue:w,onSearch:te,onChange:U,onClear:()=>{D(``),T(``),F([])},placeholder:`Minimum 3 characters`,notFoundContent:I||M?(0,l.jsx)(s.Spin,{size:`small`}):null,options:P,className:`mail-popup__job-input`})]}):null})})})}var{Text:fO}=s.Typography,pO=2,mO=`overview.summary.role summary.job summary.role overview.job description.description.about the role.about the job.job title.role.responsibilities.roles responsibilities.roles and responsibilities.roles & responsibilities.key responsibilities.requirements.required skills.preferred skills.technical skills.key skills.skills.competencies.nice to have.good to have.qualifications.required qualifications.preferred qualifications.education.experience.benefits`.split(`.`),hO=new Set(mO),gO=/(education|qualification)/i,_O=/(skill|competenc)/i,vO=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),yO=e=>e.replace(/\w[^\s/]*/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()),bO=e=>[...new Set(e)];function xO(e){let t=String(e);return t=t.replace(/<\s*(br|\/p|\/div|\/h[1-6]|\/li|\/tr)\s*\/?>/gi,`
18
18
  `).replace(/<\s*li[^>]*>/gi,`
19
19
  `).replace(/<[^>]+>/g,` `),t=t.replace(/&nbsp;/gi,` `).replace(/&amp;/gi,`&`).replace(/&lt;/gi,`<`).replace(/&gt;/gi,`>`).replace(/&#39;|&apos;/gi,`'`).replace(/&quot;/gi,`"`),t.replace(/[ \t\f\v]+/g,` `).replace(/\n{2,}/g,`
20
- `).trim()}function lO(e){return e.replace(/•/g,`
21
- `).split(/\n+/).map(e=>e.trim().replace(/^[-–—•]\s*/,``).trim()).filter(Boolean)}function uO(e){return lO(e.replace(/(?:^|\s)[-–—]\s+/g,`
22
- `))}function dO(e){let t=e.match(/^([A-Za-z][A-Za-z&/ ]{1,28}?)\s*:\s*(\S.+)$/);if(!t)return null;let n=t[1].trim(),r=t[2].trim();return n.split(/\s+/).length>3||r.length>60?null:{fieldKey:n.toLowerCase().replace(/\s+/g,`-`),fieldLabel:oO(n),value:r}}function fO(e){let t=e.toLowerCase().replace(/[\s:.\-–—]+$/,``).trim();return nO.has(t)?rO.test(t)?`education`:iO.test(t)?`keySkills`:`overview`:null}function pO(e){let t=[],n={overview:[],keySkills:[],education:[]},r=`overview`;return e.forEach(e=>{let i=fO(e);if(i){r=i;return}if(r===`overview`){let n=dO(e);if(n){t.push(n);return}}n[r].push(e)}),{meta:t,overview:sO(n.overview),keySkills:sO(n.keySkills),education:sO(n.education)}}function mO(e){let t=[...tO].sort((e,t)=>t.length-e.length),n=RegExp(`\\b(${t.map(aO).join(`|`)})\\b\\s*:?`,`gi`),r=[...e.matchAll(n)];if(!r.length)return{meta:[],overview:sO(uO(e)),keySkills:[],education:[]};let i={overview:[],keySkills:[],education:[]},a=e.slice(0,r[0].index).trim();return a&&i.overview.push(...uO(a)),r.forEach((t,n)=>{let a=t[1].trim().toLowerCase(),o=t.index+t[0].length,s=n+1<r.length?r[n+1].index:e.length,c=uO(e.slice(o,s).trim());if(!c.length)return;let l=rO.test(a)?`education`:iO.test(a)?`keySkills`:`overview`;i[l].push(...c)}),{meta:[],overview:sO(i.overview),keySkills:sO(i.keySkills),education:sO(i.education)}}function hO(e){let t=cO(e);if(!t)return{meta:[],overview:[],keySkills:[],education:[]};let n=lO(t);return n.length>=4?pO(n):mO(t)}function gO({items:e}){return(0,l.jsx)(`ul`,{className:`jdv-ats-bullets`,children:e.map((e,t)=>(0,l.jsx)(`li`,{className:`jdv-ats-bullet-item`,children:e},t))})}function _O({raw:e=``,meta:t=[]}){let[n,r]=(0,o.useState)(!1),i=(0,o.useMemo)(()=>hO(e),[e]),a=t.length?t:i.meta,s=[];if(i.overview.length&&s.push({key:`overview`,title:`Overview`,items:i.overview}),i.keySkills.length&&s.push({key:`keySkills`,title:`Key Skills`,items:i.keySkills,card:!0,icon:`🛠️`}),i.education.length&&s.push({key:`education`,title:`Education`,items:i.education,card:!0,icon:`🎓`}),!a.length&&!s.length)return(0,l.jsx)($D,{type:`secondary`,children:`No description available.`});let c=n?s:s.slice(0,eO),u=s.length-eO;return(0,l.jsxs)(`div`,{className:`jdv-ats-desc`,children:[a.length>0&&(0,l.jsx)(`div`,{className:`jdv-ats-meta-grid`,children:a.map(({fieldKey:e,fieldLabel:t,value:n})=>(0,l.jsxs)(`div`,{className:`jdv-ats-meta-row`,children:[(0,l.jsx)(`span`,{className:`jdv-ats-meta-key`,children:t}),(0,l.jsx)(`span`,{className:`jdv-ats-meta-val`,children:n})]},e??t))}),(0,l.jsx)(`div`,{className:`jdv-ats-sections`,children:c.map(e=>e.card?(0,l.jsxs)(`div`,{className:`education-block`,children:[(0,l.jsxs)(`div`,{className:`education-header`,children:[(0,l.jsx)(`span`,{children:e.icon}),(0,l.jsx)(`span`,{children:e.title})]}),(0,l.jsx)(`ul`,{className:`education-list`,children:e.items.map((e,t)=>(0,l.jsx)(`li`,{className:`education-list-item`,children:e},t))})]},e.key):(0,l.jsxs)(`div`,{className:`jdv-ats-section`,children:[(0,l.jsx)(`div`,{className:`jdv-ats-section-hd`,children:(0,l.jsx)(`span`,{children:e.title})}),(0,l.jsx)(gO,{items:e.items})]},e.key))}),u>0&&(0,l.jsx)(`span`,{className:`jdv-desc-toggle`,onClick:()=>r(e=>!e),children:n?`Show less`:`Show more (${u} more section${u>1?`s`:``})`})]})}var{Text:vO}=s.Typography;function yO(e){return e?e.trim().split(/\s+/).slice(0,2).map(e=>e[0].toUpperCase()).join(``):`?`}function bO(e){return e?e.name?e.name:e.fullName?e.fullName:e.firstName||e.lastName?[e.firstName,e.lastName].filter(Boolean).join(` `):e.candidateName??e.clientName??e.jobTitle??``:``}function xO(e){return e?e.email??e.emailId??e.emailAddress??``:``}function SO(e){return e?e.status?e.status:e.stage?e.stage:typeof e.isActive==`boolean`?e.isActive?`Active`:`Inactive`:``:``}function CO(e){return e==null||e===``?`-`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e.label??e.name??Object.values(e).join(` `):String(e)}var wO=[`jobDescription`,`description`,`rawDescription`,`jobDescriptionText`];function TO(e){return String(e??``).toLowerCase()===`job`}function EO(e){let t=wO.includes(e.field),n=/description/i.test(e.label??``);return t||n}function DO({record:e}){let t=bO(e),n=xO(e),r=SO(e);return!t&&!n?null:(0,l.jsxs)(`div`,{className:`preview-profile-card`,children:[(0,l.jsxs)(`div`,{className:`preview-profile-card__info`,children:[(0,l.jsx)(s.Avatar,{className:`preview-profile-card__avatar`,children:yO(t)}),(0,l.jsxs)(`div`,{className:`preview-profile-card__text`,children:[t&&(0,l.jsx)(`span`,{className:`preview-profile-card__name`,children:t}),n&&(0,l.jsx)(`span`,{className:`preview-profile-card__email`,children:n})]})]}),r&&(0,l.jsx)(s.Tag,{className:`preview-profile-card__status`,children:r})]})}function OO({fields:e,moduleName:t,centralDocuments:r=[]}){let[i,a]=(0,o.useState)([]),[s,c]=(0,o.useState)(0),[u,d]=(0,o.useState)(!1);if(!e?.length)return null;function f(e){let t=String(e?.type??``).trim().toLowerCase(),n=`${e?.field??``} ${e?.label??``}`;return[`file`,`document`,`upload`].includes(t)||/resume|cv|document|attachment/i.test(n)}function p(e,t){a(e),c(t),d(!0)}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`preview-field-grid`,children:e.map(e=>{let i=e.value,a=Array.isArray(i)&&i.length>0,o=TO(t)&&EO(e)&&typeof i==`string`&&i.trim(),s=f(e)?r.filter(t=>{let n=String(t?.fieldName??t?.field??t?.formField??t?.key??``).trim().toLowerCase(),r=String(e?.field??``).trim().toLowerCase();if(n&&r&&n===r)return!0;let i=`${e?.field??``} ${e?.label??``}`;return/resume|cv/i.test(i)?/resume|cv/i.test(`${n} ${t?.fileName??``} ${t?.name??``}`):!1}).map(t=>({name:t?.fileName||t?.name||t?.uploadedFileName||t?.originalName||e?.label||`Document`,url:t?.fileUrl||t?.downloadUrl||t?.signedUrl||t?.url||``,type:t?.mimeType||t?.contentType||t?.type})).filter(e=>e.url):[],c=f(e)?s.length?s:n.Bt(i).filter(e=>e.url):[];return c.length?(0,l.jsxs)(`div`,{className:`preview-field-card preview-field-card--documents`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`div`,{className:`preview-document-list`,children:c.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,className:`preview-document-link`,onClick:()=>p(c,t),title:`Preview ${e.name||`document`}`,children:[(0,l.jsx)(`span`,{className:`preview-document-link__icon`,"aria-hidden":`true`,children:`▣`}),(0,l.jsx)(`span`,{className:`preview-document-link__name`,children:e.name||`Document ${t+1}`}),(0,l.jsx)(`span`,{className:`preview-document-link__action`,children:`Preview`})]},`${e.url}-${t}`))})]},e.field??e.label):a?i.map((t,n)=>(0,l.jsxs)(`div`,{className:`preview-field-card`,children:[(0,l.jsxs)(`span`,{className:`preview-field-card__label`,children:[e.label,i.length>1?` (${n+1})`:``]}),(0,l.jsx)(`span`,{className:`preview-field-card__value`,children:CO(t)})]},`${e.field??e.label}-${n}`)):o?(0,l.jsxs)(`div`,{className:`preview-field-card preview-field-card--description`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`div`,{className:`preview-field-card__description`,children:(0,l.jsx)(_O,{raw:i})})]},e.field??e.label):(0,l.jsxs)(`div`,{className:`preview-field-card`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`span`,{className:`preview-field-card__value`,children:CO(i)})]},e.field??e.label)})}),(0,l.jsx)(n.En,{documents:i,open:u,onClose:()=>d(!1),initialIndex:s})]})}function kO(){let e=(0,d.useNavigate)(),{moduleName:t=``,record:r=null}=(0,d.useLocation)().state??{},i=r?.id??r?._id,[c,u]=(0,o.useState)([]),[f,p]=(0,o.useState)(!!(t&&i)),[m,h]=(0,o.useState)(null),[g,_]=(0,o.useState)([]),[v,y]=(0,o.useState)(0),b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)([]),C=(0,o.useRef)([]);(0,o.useEffect)(()=>{if(!t||!i)return;let e=!1;return Promise.all([a.r({module:t,id:i}),n.yn(t,i).catch(()=>({data:[]}))]).then(([t,n])=>{e||(u(Array.isArray(t)?t:[]),_(Array.isArray(n)?n:n?.data??[]),p(!1))}).catch(t=>{e||(h(t.message||`Failed to load preview`),_([]),p(!1))}),()=>{e=!0}},[t,i]);function w(){e(-1)}function T(e,t){return e?.label??e?.name??`Section ${t+1}`}function E(e){let t=b.current,n=C.current[e];if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=(t.querySelector(`.preview-stepper-wrap`)?.offsetHeight??0)+12,o=t.scrollTop+i.top-r.top-a;y(e),t.scrollTo({top:Math.max(0,o),behavior:`smooth`})}function D(){let e=b.current;if(!e||!C.current.length)return;let t=e.getBoundingClientRect().top+(e.querySelector(`.preview-stepper-wrap`)?.offsetHeight??0)+24,n=0;C.current.forEach((e,r)=>{e&&e.getBoundingClientRect().top<=t&&(n=r)}),y(e=>e===n?e:n)}(0,o.useEffect)(()=>{let e=x.current,t=S.current[v];if(!e||!t)return;let n=t.offsetLeft-(e.clientWidth-t.offsetWidth)/2,r=Math.max(0,e.scrollWidth-e.clientWidth);e.scrollTo({left:Math.min(Math.max(0,n),r),behavior:`smooth`})},[v,c.length]);function O(){return c.length?(0,l.jsx)(`div`,{ref:x,className:`preview-stepper-wrap`,"aria-label":`Preview sections`,children:(0,l.jsx)(`div`,{className:`preview-stepper`,children:c.map((e,t)=>(0,l.jsxs)(`div`,{className:`preview-stepper__segment`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`preview-stepper__item`,ref:e=>{S.current[t]=e},onClick:()=>E(t),"aria-current":v===t?`step`:void 0,title:`Go to ${T(e,t)}`,children:[(0,l.jsx)(`span`,{className:[`preview-stepper__circle`,t<v?`preview-stepper__circle--done`:``,t===v?`preview-stepper__circle--active`:``].filter(Boolean).join(` `),children:t+1}),(0,l.jsx)(`span`,{className:[`preview-stepper__label`,t===v?`preview-stepper__label--active`:``].filter(Boolean).join(` `),children:T(e,t)})]}),t<c.length-1&&(0,l.jsx)(`span`,{className:[`preview-stepper__line`,t<v?`preview-stepper__line--done`:``].filter(Boolean).join(` `),"aria-hidden":`true`})]},e.name??e.id??t))})}):null}let k=(0,l.jsxs)(`div`,{className:`preview-modal-header`,children:[(0,l.jsx)(`span`,{className:`preview-modal-module`,children:t.toUpperCase()}),(0,l.jsx)(`span`,{className:`preview-modal-title`,children:t?` Details`:`Preview`})]}),A=(0,l.jsx)(`div`,{className:`wizard-footer preview-scroll-footer`,children:(0,l.jsx)(`div`,{className:`wizard-footer-nav`,children:(0,l.jsx)(s.Button,{onClick:w,children:`Close`})})});function j(){return!t||!i?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:`Preview id is missing.`}):f?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:(0,l.jsx)(s.Spin,{size:`small`})}):m?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status job-preview-error`,children:m}):c.length?(0,l.jsx)(`div`,{className:`preview-section-list`,children:c.map((e,n)=>(0,l.jsxs)(`section`,{ref:e=>{C.current[n]=e},className:`preview-section-card`,"data-section-index":n,children:[(0,l.jsxs)(`div`,{className:`preview-section-card__header`,children:[(0,l.jsx)(`span`,{className:`preview-section-card__number`,children:n+1}),(0,l.jsx)(`span`,{className:`preview-section-card__title`,children:T(e,n)})]}),(0,l.jsx)(`div`,{className:`preview-section-card__body`,children:e.fields?.length>0?(0,l.jsx)(OO,{fields:e.fields,moduleName:t,centralDocuments:g}):(0,l.jsx)(vO,{type:`secondary`,children:`No fields in this group.`})})]},e.name??e.id??n))}):(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:`No form groups found.`})}return(0,l.jsx)(s.Modal,{centered:!0,className:`wizard-modal preview-modal preview-scroll-modal`,footer:A,open:!0,title:k,width:`min(900px, calc(100vw - 32px))`,onCancel:w,maskClosable:!1,children:(0,l.jsxs)(`div`,{ref:b,className:`wizard-body preview-scroll-body`,onScroll:D,children:[!f&&!m&&c.length>0&&O(),r&&(0,l.jsx)(DO,{record:r}),j()]})})}var{Text:AO}=s.Typography,{TextArea:jO}=s.Input,MO=[{key:`basic`,title:`Basic Info`,description:`General details`,fields:[{name:`firstName`,label:`First Name`,type:`input`,required:!0,placeholder:`Enter first name`,span:12},{name:`lastName`,label:`Last Name`,type:`input`,required:!0,placeholder:`Enter last name`,span:12},{name:`email`,label:`Email Address`,type:`input`,required:!0,placeholder:`Enter email address`,rules:[{type:`email`,message:`Please enter a valid email`}]},{name:`phone`,label:`Phone`,type:`input`,placeholder:`Enter phone number`}]},{key:`details`,title:`Details`,description:`Additional info`,fields:[{name:`role`,label:`Role`,type:`select`,required:!0,placeholder:`Select a role`,span:12,options:[{label:`Developer`,value:`developer`},{label:`Designer`,value:`designer`},{label:`Manager`,value:`manager`},{label:`Analyst`,value:`analyst`}]},{name:`department`,label:`Department`,type:`select`,placeholder:`Select department`,span:12,options:[{label:`Engineering`,value:`engineering`},{label:`Product`,value:`product`},{label:`Operations`,value:`operations`},{label:`Finance`,value:`finance`}]},{name:`notes`,label:`Notes`,type:`textarea`,placeholder:`Any additional notes...`}]},{key:`confirm`,title:`Confirm`,description:`Review & submit`,isReview:!0}];function NO(e){switch(e.type){case`select`:return(0,l.jsx)(s.Select,{placeholder:e.placeholder,options:e.options,style:{width:`100%`}});case`textarea`:return(0,l.jsx)(jO,{rows:3,placeholder:e.placeholder});case`number`:return(0,l.jsx)(s.InputNumber,{placeholder:e.placeholder,style:{width:`100%`}});default:return(0,l.jsx)(s.Input,{type:e.inputType||`text`,placeholder:e.placeholder})}}function PO({steps:e,form:t}){let n=t.getFieldsValue(),r=e.filter(e=>!e.isReview);return r.some(e=>(e.fields||[]).some(e=>n[e.name]!==void 0&&n[e.name]!==``))?(0,l.jsxs)(`div`,{className:`wizard-review-content`,children:[r.map(e=>(0,l.jsxs)(`div`,{className:`wizard-review-section`,children:[(0,l.jsx)(AO,{className:`wizard-review-section-title`,children:e.title}),(0,l.jsx)(`div`,{className:`wizard-review-grid`,children:(e.fields||[]).map(e=>{let t=n[e.name],r=t===void 0||t===``||t===null?`—`:String(t);return(0,l.jsxs)(`div`,{className:`wizard-review-row`,children:[(0,l.jsx)(`span`,{className:`wizard-review-label`,children:e.label}),(0,l.jsx)(`span`,{className:`wizard-review-separator`,children:`:`}),(0,l.jsx)(`span`,{className:`wizard-review-value`,children:r})]},e.name)})})]},e.key)),(0,l.jsxs)(`div`,{className:`wizard-review-confirm-note`,children:[(0,l.jsx)(c.CheckCircleOutlined,{className:`wizard-review-confirm-icon`}),(0,l.jsx)(AO,{type:`secondary`,children:`Please review the information above before submitting.`})]})]}):(0,l.jsx)(`div`,{className:`wizard-review-empty`,children:(0,l.jsx)(AO,{type:`secondary`,children:`No data entered yet.`})})}function FO(){let[e]=s.Form.useForm(),t=(0,d.useNavigate)(),{title:n=`Wizard`,moduleName:r=``,steps:i=MO,onSubmit:a}=(0,d.useLocation)().state??{},[c,u]=(0,o.useState)(0),f=i[c],p=c===i.length-1,m=c===0;function h(){t(-1)}function g(){let t=(f.fields||[]).map(e=>e.name);e.validateFields(t.length>0?t:void 0).then(()=>{u(e=>e+1)})}function _(){u(e=>e-1)}function v(){let n=e.getFieldsValue();typeof a==`function`&&a(n),t(-1)}let y=i.map((e,t)=>({title:e.title,description:e.description,status:t<c?`finish`:t===c?`process`:`wait`})),b=r?`${n} — ${r}`:n;return(0,l.jsxs)(s.Modal,{open:!0,title:b,footer:(0,l.jsxs)(`div`,{className:`wizard-footer`,children:[(0,l.jsx)(s.Button,{onClick:h,children:`Cancel`}),(0,l.jsxs)(`div`,{className:`wizard-footer-nav`,children:[!m&&(0,l.jsx)(s.Button,{onClick:_,children:`Back`}),p?(0,l.jsx)(s.Button,{type:`primary`,onClick:v,children:`Submit`}):(0,l.jsx)(s.Button,{type:`primary`,onClick:g,children:`Next`})]})]}),onCancel:h,width:`min(680px, calc(100vw - 32px))`,centered:!0,className:`wizard-modal`,children:[(0,l.jsx)(`div`,{className:`wizard-steps-container`,children:(0,l.jsx)(s.Steps,{current:c,items:y,size:`small`,className:`wizard-steps`})}),(0,l.jsx)(`div`,{className:`wizard-body`,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,children:[i.filter(e=>!e.isReview).map((e,t)=>(0,l.jsx)(`div`,{style:{display:t===c?`block`:`none`},children:(0,l.jsx)(s.Row,{gutter:16,children:(e.fields||[]).map(e=>(0,l.jsx)(s.Col,{span:e.span||24,children:(0,l.jsx)(s.Form.Item,{name:e.name,label:e.label,rules:[...e.required?[{required:!0,message:`${e.label} is required`}]:[],...e.rules||[]],children:NO(e)})},e.name))})},e.key)),f.isReview&&(0,l.jsx)(PO,{steps:i,form:e})]})})]})}function IO({titleText:e,titleIcon:t}){let n=t===`delete`;return(0,l.jsxs)(`span`,{className:`dynamic-popup__header`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box${n?` dynamic-popup__header-icon-box--danger`:``}`,children:n?(0,l.jsx)(c.DeleteOutlined,{}):(0,l.jsx)(c.AppstoreOutlined,{})}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:e})]})}function LO({note:e,description:t,showSelectedCount:r,count:i,itemLabel:a,bodyText:o,deleteError:s}){return(0,l.jsxs)(l.Fragment,{children:[e&&(0,l.jsx)(n.kn,{variant:`body`,color:`secondary`,className:`dynamic-popup__note`,children:e}),t&&(0,l.jsx)(n.kn,{variant:`body`,className:`dynamic-popup__description`,children:t}),r&&i>0&&(0,l.jsxs)(n.kn,{variant:`body`,className:`dynamic-popup__selected-count`,children:[`Changing status for `,(0,l.jsx)(`strong`,{children:i}),` selected `,a,`.`]}),o&&(0,l.jsx)(n.kn,{variant:`body`,children:o}),s&&(0,l.jsx)(n.kn,{variant:`caption`,color:`danger`,className:`dynamic-popup__error`,children:s})]})}function RO({footerNote:e}){return e?(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,className:`dynamic-popup__footer-note`,children:e}):null}function zO(e,t){return e.replace(/\{(\w+)\}/g,(e,n)=>t?.[n]??``).trim()}function BO(e){return String(e).replace(/\(\s*\)/g,``).replace(/\s+/g,` `).replace(/(^|\s)([-–—·|])(?=\s*\2)/g,``).replace(/^[\s\-–—·|]+/,``).replace(/[\s\-–—·|]+$/,``).trim()}function VO(e){if(!e)return!1;let t=new Date(e).getTime();return Number.isNaN(t)||t<=0?!1:t<=Date.now()+864e5}function HO(e){if(!VO(e))return``;let t=new Date(e),n=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=new Date,i=Math.round((n(r)-n(t))/864e5);if(i<=0)return`Today`;if(i===1)return`Yesterday`;if(i<=30)return`${i} days ago`;let a=(r.getFullYear()-t.getFullYear())*12+(r.getMonth()-t.getMonth());if(r.getDate()<t.getDate()&&--a,a=Math.max(1,a),a<12)return`${a} month${a===1?``:`s`} ago`;let o=Math.floor(a/12);return`${o} year${o===1?``:`s`} ago`}function UO(e){let t=Array.isArray(e?.submissionHistory)?e.submissionHistory:[],n=[e?.lastSubmittedAt,e?.submittedAt,e?.updatedAt,...t.map(e=>e?.submittedAt||e?.updatedAt)].filter(Boolean);return n.length?n.reduce((e,t)=>new Date(t)>new Date(e)?t:e):null}function WO(e){let t=Array.isArray(e?.submissionHistory)?e.submissionHistory:[],n=[e?.lastSubmittedAt,e?.submittedAt,...t.map(e=>e?.submittedAt)].filter(Boolean);return n.length?n.reduce((e,t)=>new Date(t)>new Date(e)?t:e):null}function GO(e,t){if(typeof e==`string`)return{label:e,value:e};if(e?.label!==void 0&&e?.value!==void 0&&!t?.labelTemplate&&!t?.valueKey)return e;let{labelKey:n,valueKey:r,labelTemplate:i}=t??{},a=i?.includes(`{lastdate}`)?{...e,lastdate:HO(UO(e))}:e,o=(i?BO(zO(i,a)):null)||(n?e?.[n]:null)||e?.name||e?.fullName||e?.candidateName||e?.title||e?.displayName||e?.text||e?.applicantReferenceId||e?.applicantRefrenceId||String(Object.values(e||{})[0]??``),s=(r?e?.[r]:null)??e?.id??e?._id??e?.applicantReferenceId??e?.applicantRefrenceId??String(Object.values(e||{})[0]??``),c=e?.disabled===!0||e?.disable===!0,l=String(e?.optionNote??``).trim(),u={label:l?`${String(o)} — ${l}`:String(o),value:String(s),_raw:e};if(c&&(u.disabled=!0),l&&(u.title=l),e?.isSubmitted===!0||e?.alreadySubmitted===!0){u.alreadySubmitted=!0,u.existingSubmissionId=String(e?.existingSubmissionId??e?.jobSubmissionId??e?.submissionId??``);let t=e?.submittedAt||WO(e);t&&(u.submittedAt=t)}if(e?.isFromSubmission===!0&&e?.submissionId){u.isFromSubmission=!0,u.priorSubmissionId=String(e.submissionId);let t=e?.lastSubmittedAt||WO(e);t&&(u.priorSubmittedAt=t)}return u}function KO(e,t){return(t?.[e.optionsKey]??e.defaultOptions??[]).map(t=>GO(t,e))}function qO(e={}){return{selectedIds:[],selectedRecords:[],moduleName:``,removedIds:[],...e}}var JO=`DD MMM YYYY`,YO=`DD MMM YYYY, h:mm A`;function XO(e,t){if(e==null||e===``)return``;let n=(0,u.default)(e);return n.isValid()?t===`relative`?HO(e)||(VO(e)?n.format(JO):`Not updated`):VO(e)?n.format(JO):``:String(e)}function ZO(e,t){return e?String(e).includes(`{`)?BO(zO(e,t)):String(t?.[e]??e).trim():``}function QO(e){if(e?.alreadySubmitted){let t=e?.submittedAt?(0,u.default)(e.submittedAt):null;return{tone:`blocked`,tooltip:t?.isValid()?`Already submitted to this job on ${t.format(YO)}`:`Already submitted to this job — a candidate can only be submitted once per job`}}if(e?.isFromSubmission){let t=e?.priorSubmittedAt?(0,u.default)(e.priorSubmittedAt):null;return{tone:`history`,tooltip:t?.isValid()?`Previously submitted on ${t.format(YO)} — this form will prefill from it`:`Submitted to another job before — this form will prefill from it`}}return null}function $O(e,t){return e?.alreadySubmitted||!e?.disabled?``:String(t?.message??e?.title??``).trim()}function ek({meta:e}){return(0,l.jsx)(`div`,{className:`dynamic-popup__option-dates`,children:e.map(e=>(0,l.jsxs)(o.Fragment,{children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-date-label`,children:e.label}),(0,l.jsx)(`span`,{className:`dynamic-popup__option-date-value`,children:e.text})]},e.label))})}function tk({option:e,layout:t}){let n=e?._raw??e??{},r=ZO(t.id,n),i=ZO(t.title,n)||String(e?.label??``),a=ZO(t.subtitle,n),o=ZO(t.titleAccent?.key,n),u=ZO(t.titleAccent?.toneKey,n),d=t.titleAccent?.prefix??``,f=(t.meta??[]).map(e=>({label:e.label,text:XO(n?.[e.key],e.type)})).filter(e=>e.text),p=$O(e,n),m=QO(e);return(0,l.jsxs)(`div`,{className:`dynamic-popup__option`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-tick${m?` dynamic-popup__option-tick--${m.tone}`:``}`,children:m&&(0,l.jsx)(s.Tooltip,{title:m.tooltip,placement:`topLeft`,children:(0,l.jsx)(c.CheckCircleFilled,{"aria-label":m.tooltip})})}),(0,l.jsxs)(`div`,{className:`dynamic-popup__option-main`,children:[(0,l.jsxs)(`div`,{className:`dynamic-popup__option-head`,children:[r&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-id`,children:r}),(0,l.jsxs)(`span`,{className:`dynamic-popup__option-title`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-title-text`,children:i}),o&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-title-accent${u?` dynamic-popup__option-title-accent--${u}`:``}`,children:`${d}${o}`})]}),p&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-flag`,children:p})]}),a&&(0,l.jsx)(`div`,{className:`dynamic-popup__option-sub`,children:a})]}),e?.alreadySubmitted?(0,l.jsx)(`span`,{className:`dynamic-popup__option-onjob`,children:`On this job`}):f.length>0&&(0,l.jsx)(ek,{meta:f})]})}var{Text:nk}=s.Typography,{TextArea:rk}=s.Input,ik=[{label:`$`,value:`$`},{label:`EUR`,value:`EUR`},{label:`GBP`,value:`GBP`},{label:`INR`,value:`INR`}],ak=[{label:`Hourly`,value:`Hourly`},{label:`Daily`,value:`Daily`},{label:`Weekly`,value:`Weekly`},{label:`Monthly`,value:`Monthly`},{label:`Yearly`,value:`Yearly`}];function ok(e=[]){return e.map(e=>{if(!e||typeof e!=`object`)return e;let t=[e.value,e.user_id,e.userId,e.USER_ID,e.legacyUserId,e.id,e._id].find(e=>e!=null&&String(e).trim()!==``),n=t==null?``:String(t).trim();return{...e,value:n}}).filter(e=>typeof e!=`object`||!e||String(e.value??``).trim()!==``)}function sk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.Input,{value:t,onChange:n,placeholder:e.placeholder,maxLength:e.maxLength,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function ck({field:e,value:t,onChange:n}){return(0,l.jsx)(rk,{value:t,onChange:n,rows:e.rows??5,placeholder:e.placeholder,maxLength:e.maxLength,showCount:!!e.maxLength})}function lk({field:e,options:t,value:n,onChange:r}){let i=ok(t);return(0,l.jsx)(s.Select,{showSearch:!0,value:n,onChange:r,options:i,placeholder:e.placeholder,className:`dynamic-popup__field-select`,optionFilterProp:`label`,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function uk({field:e,options:t,value:n,onChange:r}){let i=ok(t);return(0,l.jsx)(s.Select,{mode:`multiple`,showSearch:!0,value:n,onChange:r,options:i,placeholder:e.placeholder,className:`dynamic-popup__field-select`,optionFilterProp:`label`,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function dk({field:e,options:t,onSearch:n,value:r,onChange:i,popupContext:a}){let o=ok(t),u=e.optionLayout,d=new Map(o.map(e=>[String(e?.value??``),e]));async function f(t,n){if(e.multiple){i?.(Array.isArray(t)?t:[]);return}let r=n??d.get(String(t??``));(typeof e.onSelectGuard!=`function`||await e.onSelectGuard({value:t,option:r,field:e,popupContext:a,confirm:s.Modal.confirm})!==!1)&&i?.(t)}return(0,l.jsx)(s.Select,{mode:e.multiple?`multiple`:void 0,showSearch:!0,filterOption:!1,notFoundContent:e.notFoundContent??null,value:r,onChange:f,options:o,placeholder:e.placeholder,onSearch:n,className:`dynamic-popup__field-select${u?` dynamic-popup__field-select--rich`:``}`,popupClassName:u?`dynamic-popup__option-dropdown`:void 0,listHeight:u?340:void 0,optionLabelProp:`label`,optionRender:u?e=>(0,l.jsx)(tk,{option:e?.data??e,layout:u}):void 0,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function fk({field:e,mentionOpts:t,onMentionSearch:n,value:r,onChange:i}){let a=Number(e.maxLength)>0?Number(e.maxLength):void 0,o=String(r??``).length;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Mentions,{value:r,onChange:i,rows:e.rows??5,placeholder:e.placeholder,prefix:`@`,options:t,onSearch:n,maxLength:a,className:`dynamic-popup__mention-textarea`}),a?(0,l.jsxs)(`div`,{className:`dynamic-popup__char-count`,style:{textAlign:`right`,fontSize:12,marginTop:4,color:o>a*.9?`#b45309`:`#8c8c8c`},children:[o,` / `,a]}):null]})}function pk({field:e={},value:t={},onChange:n}){let r=t.period??`Hourly`,i=t.isRange??!1;function a(e){n?.({...t,...e})}(0,o.useEffect)(()=>{let e={};t.currency??(e.currency=`$`),t.period??(e.period=`Hourly`),Object.keys(e).length&&n?.({...t,...e})},[]);let c=Number(i?t.maxAmount:t.amount),u=i&&t.minAmount!=null&&t.maxAmount!=null&&Number(t.maxAmount)<=Number(t.minAmount),d=e.rateCeiling!=null&&Number.isFinite(c)&&c>Number(e.rateCeiling);return(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[i?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`From`,value:t.minAmount,onChange:e=>a({minAmount:e}),style:{flex:1}}),(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`To`,value:t.maxAmount,onChange:e=>a({maxAmount:e}),style:{flex:1}})]}):(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`0`,value:t.amount,onChange:e=>a({amount:e}),style:{flex:2}}),(0,l.jsx)(s.Select,{value:t.currency??`$`,options:ik,onChange:e=>a({currency:e}),style:{width:80}}),(0,l.jsx)(s.Select,{value:r,options:ak,onChange:e=>a({period:e}),style:{width:110}})]}),(u||d)&&(0,l.jsxs)(`div`,{style:{marginTop:4},children:[u&&(0,l.jsx)(nk,{type:`danger`,style:{fontSize:12,display:`block`},children:`To rate must be greater than From rate.`}),d&&(0,l.jsxs)(nk,{type:`danger`,style:{fontSize:12,display:`block`},children:[`Rate must not exceed the client rate (`,e.rateCeiling,`).`]})]}),(0,l.jsxs)(s.Space,{size:`small`,style:{marginTop:8},children:[(0,l.jsx)(s.Switch,{checked:i,onChange:e=>a({isRange:e})}),(0,l.jsx)(`span`,{children:`Range`})]})]})}function mk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.DatePicker,{value:t,onChange:n,placeholder:e.placeholder??`Select date`,style:{width:`100%`},format:`YYYY-MM-DD`})}function hk({field:e,checked:t,onChange:n}){return(0,l.jsx)(s.Checkbox,{checked:t,onChange:n,children:e.checkboxLabel})}function gk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.InputNumber,{value:t,onChange:n,min:e.min,max:e.max,placeholder:e.placeholder,style:{width:`100%`}})}function _k({options:e,value:t,onChange:n}){return(0,l.jsx)(s.Radio.Group,{value:t,onChange:n,options:e})}var vk={input:sk,text:sk,textarea:ck,select:lk,"multi-select":uk,"search-select":dk,"mention-textarea":fk,"candidate-rate":pk,"priority-checkbox":hk,"date-picker":mk,number:gk,radio:_k};function yk(e){return e===`priority-checkbox`?{valuePropName:`checked`}:{}}var bk=new Set([`input`,`text`,`textarea`,`mention-textarea`]);function xk({form:e,fields:t,initialValues:r,dynamicOptions:i,popupContext:a,extraData:o,removedIds:c,setRemovedIds:u,showAlreadyAssigned:d,onValuesChange:f,getSearchHandler:p,getMentionSearchHandler:m,mentionOptions:h}){let g=(o?.recruitersData??[]).filter(e=>{let t=String(e?.user_id??e?.id??e?.userId??``);return t&&!c.includes(t)}),_=d&&o,v=new Set(d?g.map(e=>String(e?.user_id??e?.id??e?.userId??``).trim()).filter(Boolean):[]),y=e=>v.size===0||!Array.isArray(e)?e:e.filter(e=>!v.has(String((e&&typeof e==`object`?e.value??e.id:e)??``).trim()));return!t.length&&!_?null:(0,l.jsxs)(l.Fragment,{children:[_&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`dynamic-popup__already-assigned`,children:[(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,children:`Already Assigned People`}),(0,l.jsx)(`div`,{style:{marginTop:6,display:`flex`,flexWrap:`wrap`,gap:6},children:g.length===0?(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,children:`No one is currently assigned to this job.`}):g.map(e=>{let t=String(e?.user_id??e?.id??e?.userId??``),n=e?.name??e?.user_name??e?.userName??e?.email??`Assigned user`;return(0,l.jsx)(s.Tag,{closable:!0,onClose:()=>{t&&u(e=>Array.from(new Set([...e,t])))},children:n},t||n)})})]}),(0,l.jsx)(s.Divider,{style:{margin:`12px 0`}})]}),t.length>0&&(0,l.jsx)(s.Form,{form:e,layout:`vertical`,initialValues:r,onValuesChange:(e,t)=>f(t),children:Sk(t).map(e=>Ck(e,e=>{let t=y(i[e.name]??KO(e,a)),r=p(e),o=m(e),c=h[e.name]??[],u=yk(e.type),d=vk[e.type],f=[];return e.required&&f.push({required:!0,message:`${e.label||`This field`} is required`}),typeof e.validator==`function`&&f.push({validator:(t,n)=>{let r=e.validator(n,a);return r?Promise.reject(Error(r)):Promise.resolve()}}),bk.has(e.type)&&f.push(n.cn({label:e.label,field:e.name,type:e.type,maxLength:e.maxLength})),(0,l.jsx)(s.Form.Item,{name:e.name,label:e.label,rules:f,...u,children:d?(0,l.jsx)(d,{field:e,options:t,onSearch:r,mentionOpts:c,onMentionSearch:o,popupContext:a}):null},e.name)}))})]})}function Sk(e){let t=[];for(let n of e){let e=t[t.length-1];n.inlineRow&&e?.inlineRow===n.inlineRow?e.fields.push(n):t.push({inlineRow:n.inlineRow,fields:[n]})}return t.map(e=>e.fields)}function Ck(e,t){return e.length===1?t(e[0]):(0,l.jsx)(`div`,{style:{display:`flex`,gap:8,alignItems:`flex-start`},children:e.map((e,n)=>(0,l.jsx)(`div`,{style:{flex:n===0?2:1,minWidth:0},children:t(e)},e.name))},`row-${e.map(e=>e.name).join(`-`)}`)}function wk(e){return[`select`,`multi-select`,`search-select`,`radio`].includes(e?.type)&&e?.dataSource===`master`&&e?.masterName}function Tk(e){let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.data)?t.data:Array.isArray(t?.items)?t.items:Array.isArray(t?.rows)?t.rows:Array.isArray(t?.records)?t.records:[]}function Ek(e){let t=String(e?.masterName??``).trim().toLowerCase();return t===`clientsubmissions`||t===`clientsubmissionstatus`}function Dk(e){if(e==null)return null;if(typeof e==`string`){let t=e.trim();return t?{label:t,value:t,_raw:{name:t}}:null}let t=String(e?.name??e?.clientSubmissionStatusText??e?.label??e?.text??``).trim();if(!t)return null;let n=Number(e?.id??e?.uniqueId??e?.clientSubmissionStatusId??e?.value??0)||0;return{label:t,value:t,_raw:{...e,...n>0?{id:n,uniqueId:n}:{},name:t,type:String(e?.type??e?.clientSubmissionStatusType??``).trim(),isInitialStatus:e?.isInitialStatus===!0,isTerminalStatus:e?.isTerminalStatus===!0,allowedNextStatusIds:Array.isArray(e?.allowedNextStatusIds)?e.allowedNextStatusIds.map(Number).filter(e=>Number.isInteger(e)&&e>0):[]}}}function Ok(e,t){return Ek(t)?Dk(e):GO(e,t)}function kk(e){let t=e?.clientSubmissionStatus,n=Number((t&&typeof t==`object`?t?.clientSubmissionStatusId??t?.id??t?.uniqueId:void 0)??e?.clientSubmissionStatusId??e?.clientStatusId??e?.[`clientSubmissionStatus.clientSubmissionStatusId`]??0)||0,r=t&&typeof t==`object`?t?.clientSubmissionStatusText??t?.name??t?.text??t?.label:t;return{id:n,text:String(r??e?.clientSubmissionStatusText??e?.clientStatus??e?.clientStatusText??e?.[`clientSubmissionStatus.clientSubmissionStatusText`]??``).trim()}}function Ak(e){let t=Number(e?.id??0)||0,n=String(e?.text??``).trim();return n&&n.toLowerCase()===`not submitted`?!0:t<=0&&!n}function jk(e){return Number(e?._raw?.id??e?._raw?.uniqueId??0)||0}function Mk(e){let t=e?._raw?.allowedNextStatusIds;return Array.isArray(t)?t.map(Number).filter(e=>Number.isInteger(e)&&e>0):[]}function Nk(e){let t=e?.data??e;return t?Array.isArray(t)?t[0]??null:t?.record&&typeof t.record==`object`?t.record:t?.data&&typeof t.data==`object`&&!Array.isArray(t.data)?t.data:typeof t==`object`?t:null:null}function Pk(e){return(Array.isArray(e?.selectedRecords)?e.selectedRecords.filter(Boolean):[]).some(e=>!Ak(kk(e)))?!0:!Ak(kk(e??{}))}async function Fk(e,n){if(Pk(e))return e;let r=e?.selectedIds?.[0]??e?.selectedRecords?.[0]?._id??e?.selectedRecords?.[0]?.id;if(!r)return e;let i=String(e?.moduleName??`submissions`).trim()||`submissions`,a=new URLSearchParams({module:i,id:String(r)});n&&a.set(`app_id`,n);try{let r=Nk(await t.o(t.x,`/module-data-detail?${a.toString()}`,{headers:n?{"X-App-Id":n}:void 0}));if(!r)return e;let i=Array.isArray(e?.selectedRecords)?e.selectedRecords:[];return{...e,selectedRecords:i.length?i.map((e,t)=>t===0?{...e,...r}:e):[r]}}catch(t){return console.warn(`[DynamicPopup] Could not load selected submission detail for client status transition:`,t),e}}function Ik(e,t){if(!Array.isArray(e)||!e.length)return[];if(!e.some(e=>e?._raw?.isInitialStatus===!0||e?._raw?.isTerminalStatus===!0||Array.isArray(e?._raw?.allowedNextStatusIds)))return e;let n=Array.isArray(t?.selectedRecords)?t.selectedRecords.filter(Boolean):[],r={clientSubmissionStatus:t?.clientSubmissionStatus,clientSubmissionStatusId:t?.clientSubmissionStatusId,clientSubmissionStatusText:t?.clientSubmissionStatusText,clientStatus:t?.clientStatus,clientStatusId:t?.clientStatusId,clientStatusText:t?.clientStatusText,"clientSubmissionStatus.clientSubmissionStatusId":t?.[`clientSubmissionStatus.clientSubmissionStatusId`],"clientSubmissionStatus.clientSubmissionStatusText":t?.[`clientSubmissionStatus.clientSubmissionStatusText`]},i=n.length?n:[r];return e.filter(t=>i.every(n=>{let i=kk(n);if(Ak(i)){let e=kk(r);Ak(e)||(i=e)}if(Ak(i))return t?._raw?.isInitialStatus===!0;let a=e.find(e=>{let t=jk(e),n=String(e?.label??``).trim();return i.id>0&&t===i.id||i.text&&n.toLowerCase()===i.text.toLowerCase()});return!a||a?._raw?.isTerminalStatus===!0?!1:Mk(a).includes(jk(t))}))}function Lk({open:e,config:n,api:r,fields:i,popupContext:a,formValues:s}){let[c,l]=(0,o.useState)({}),[u,d]=(0,o.useState)(null);return(0,o.useEffect)(()=>{e||(l({}),d(null))},[e]),(0,o.useEffect)(()=>{if(!e||!n||!r.getOptions)return;let t=new AbortController;return i.forEach(e=>{!e.fetchOptionsKey||e.fetchOptionsParamKey||Promise.resolve(r.getOptions(e,void 0,a)).then(n=>{t.signal.aborted||l(t=>({...t,[e.name]:n}))}).catch(n=>{t.signal.aborted||console.error(`[DynamicPopup] Failed to load options for field "${e.name}":`,n)})}),()=>t.abort()},[e,r,n,i,a]),(0,o.useEffect)(()=>{if(!e||!n)return;let r=i.filter(wk);if(!r.length)return;let o=new AbortController;return r.forEach(e=>{let n=new URLSearchParams({masterName:e.masterName,offset:`0`,limit:String(e.limit??50)}),r=String(t.b??``).trim();r&&n.set(`app_id`,r),t.o(t.x,`/masters/dropdown?${n.toString()}`,{headers:r?{"X-App-Id":r}:void 0}).then(async t=>{if(o.signal.aborted)return;let n=Tk(t).map(t=>Ok(t,e)).filter(Boolean),i=a;if(Ek(e)&&(i=await Fk(a,r)),o.signal.aborted)return;let s=Ek(e)?Ik(n,i):n;l(t=>({...t,[e.name]:s}))}).catch(t=>{o.signal.aborted||console.error(`[DynamicPopup] Failed to load master options for field "${e.name}":`,t)})}),()=>o.abort()},[e,n,i,a]),(0,o.useEffect)(()=>{if(!e||!n||!r.getOptions)return;let t=i.filter(e=>e.fetchOptionsKey&&e.fetchOptionsParamKey);if(!t.length)return;let o=new AbortController;return t.forEach(e=>{let t=s[e.fetchOptionsParamKey]??a[e.fetchOptionsParamKey],n={[e.fetchOptionsParamKey]:t};Promise.resolve(r.getOptions(e,n,a)).then(t=>{o.signal.aborted||l(n=>({...n,[e.name]:t}))}).catch(t=>{o.signal.aborted||console.error(`[DynamicPopup] Failed to load param-dependent options for "${e.name}":`,t)})}),()=>o.abort()},[e,r,n,i,s,a]),(0,o.useEffect)(()=>{if(!e||!n||!r.loadExtraData)return;let t=new AbortController;return Promise.resolve(r.loadExtraData(a)).then(e=>{t.signal.aborted||d(e)}).catch(e=>{t.signal.aborted||(console.error(`[DynamicPopup] Failed to load extra data:`,e),d(null))}),()=>t.abort()},[e,r,n,a]),{dynamicOptions:c,setDynamicOptions:l,extraData:u}}var Rk=500,zk=3;function Bk({api:e,open:t,fields:n=[],popupContext:r,setDynamicOptions:i}){let[a,s]=(0,o.useState)({}),c=(0,o.useRef)({}),l=(0,o.useRef)({}),u=(0,o.useRef)({}),d=(0,o.useCallback)((t,n)=>{let a=e.searchOptions??e.searchFetcher;if(typeof a!=`function`)return;l.current[t.name]?.abort();let o=new AbortController;return l.current[t.name]=o,Promise.resolve(a(t,n,r)).then(e=>{if(o.signal.aborted)return;let n=Array.isArray(e)?e:e?.items??e?.list??[];i(e=>({...e,[t.name]:n.map(e=>GO(e,t))}))}).catch(e=>{o.signal.aborted||console.error(`[DynamicPopup] Search failed for field "${t.name}":`,e)}),o},[e,r,i]),f=n.filter(e=>(e.searchFetchKey||e.searchFetcher)&&e.preloadOptions!==!1),p=f.map(e=>e.name).join(`|`),m=(0,o.useRef)({runSearch:d,preloadFields:f});(0,o.useEffect)(()=>{m.current={runSearch:d,preloadFields:f}}),(0,o.useEffect)(()=>{if(!t||!p)return;let{runSearch:e,preloadFields:n}=m.current,r=n.map(t=>e(t,``)).filter(Boolean);return()=>r.forEach(e=>e.abort())},[t,p]);function h(t){if(!t.searchFetchKey&&!t.searchFetcher||typeof(e.searchOptions??e.searchFetcher)!=`function`)return;let n=t.searchMinLength??zk;return e=>{clearTimeout(c.current[t.name]);let r=e.length<n?``:e;c.current[t.name]=setTimeout(()=>{d(t,r)},Rk)}}function g(t){let n=e.getMentionOptions??e.mentionFetcher;if(typeof n==`function`)return e=>{u.current[t.name]?.abort();let i=new AbortController;u.current[t.name]=i,Promise.resolve(n(t,e,r)).then(e=>{if(i.signal.aborted)return;let n=Array.isArray(e)?e:e?.items??e?.list??[];s(e=>({...e,[t.name]:n.map(e=>({value:e.user_name??e.userName??e.username??String(e),label:e.user_name??e.userName??e.username??String(e)}))}))}).catch(e=>{i.signal.aborted||console.error(`[DynamicPopup] Mention search failed for field "${t.name}":`,e)})}}return{mentionOptions:a,getSearchHandler:h,getMentionSearchHandler:g}}function Vk({form:e,config:t,api:n,popupContext:r,resolvedIds:i,dynamicOptions:a,extraData:c,removedIds:l,removalOnlySubmit:u=!1,fields:d,onClose:f,onSubmit:p}){let[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(null);async function v(e){let t={resolvedIds:i,dynamicOptions:a,extraData:c,removedIds:l};if(typeof n.submit==`function`)return n.submit(e,r,t);if(typeof p==`function`)return p(e,r,t)}function y(){if(t){if(!d.length){if(t.mode===`delete`&&typeof n.deleteItems==`function`){h(!0),_(null),Promise.resolve(n.deleteItems(i,r)).then(()=>{s.message.success(t.successMessage||`Deleted successfully`),f({success:!0})}).catch(e=>{let t=e?.message||`Delete failed. Please try again.`;_(t),h(!1),s.message.error(t)});return}if(typeof n.onOk==`function`){h(!0),Promise.resolve(n.onOk(r)).then(()=>f({success:!0})).catch(e=>{let t=e?.message||`Failed. Please try again.`;s.message.error(t),h(!1)});return}if(typeof n.submit==`function`){h(!0),Promise.resolve(v({})).then(e=>{e?.cancelled||e?.navigated||(s.message.success(t.successMessage||`Saved successfully`),f({success:!0}))}).catch(e=>{s.message.error(e?.message||`Failed. Please try again.`)}).finally(()=>h(!1));return}f();return}if(u){h(!0),Promise.resolve(v(e.getFieldsValue())).then(e=>{e?.cancelled||e?.navigated||(s.message.success(t.successMessage||`Saved successfully`),f({success:!0}))}).catch(e=>{s.message.error(e?.message||`Failed. Please try again.`)}).finally(()=>h(!1));return}e.validateFields().then(async e=>{h(!0);try{let n=await v(e);if(n?.cancelled||n?.navigated)return;s.message.success(t.successMessage||`Saved successfully`),f({success:!0})}catch(e){s.message.error(e?.message||`Failed. Please try again.`)}finally{h(!1)}}).catch(()=>{})}}function b(){h(!1),_(null)}return{handleOk:y,confirming:m,deleteError:g,resetSubmitState:b}}function Hk({open:e=!0,config:t,context:n={},onClose:r,onSubmit:i,api:a={}}){let[c]=s.Form.useForm(),[d,f]=(0,o.useState)({}),[p,m]=(0,o.useState)([]),h=s.Form.useWatch([],c,{preserve:!0})??{},g=(0,o.useMemo)(()=>qO(n),[n]),{selectedIds:_=[],selectedRecords:v=[],moduleName:y=``}=g,b=(0,o.useMemo)(()=>_.map((e,t)=>{let n=v[t];return n?.id??n?._id??e}),[_,v]),x=(0,o.useMemo)(()=>t?typeof t.getFields==`function`?t.getFields(g):t.fields??[]:[],[t,g]),S=(0,o.useMemo)(()=>{let e={};return x.forEach(t=>{let n=g[t.initialValueKey];!t.initialValueKey||n===void 0||(e[t.name]=t.type===`date-picker`?(0,u.default)(n):n)}),e},[x,g]),{dynamicOptions:C,setDynamicOptions:w,extraData:T}=Lk({open:e,config:t,api:a,fields:x,popupContext:g,formValues:d}),{mentionOptions:E,getSearchHandler:D,getMentionSearchHandler:O}=Bk({api:a,open:e,fields:x,popupContext:g,setDynamicOptions:w});function k(e){typeof r==`function`&&r(e)}let A=x.filter(e=>e.required),j=A.every(e=>{let t=h[e.name];return!(t==null||t===``||Array.isArray(t)&&t.length===0||typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).length===0)}),M=(g.removedIds??[]).length,N=p.length>M,P=A.some(e=>{let t=h[e.name];return!(t==null||t===``||Array.isArray(t)&&t.length===0)}),{handleOk:F,confirming:I,deleteError:L,resetSubmitState:R}=Vk({form:c,config:t,api:a,popupContext:g,resolvedIds:b,dynamicOptions:C,extraData:T,removedIds:p,removalOnlySubmit:!!t?.allowRemovalOnlySubmit&&N&&!P,fields:x,onClose:k,onSubmit:i});(0,o.useEffect)(()=>{e&&(c.resetFields(),f(S??{}),m(g.removedIds??[]),R())},[e,S]);let z=!!t?.autoSubmitWhenNoFields&&x.length===0;(0,o.useEffect)(()=>{!e||!z||F()},[e,z]);let B=_.length,V=String(y).replace(/s$/i,``),H=B===1?V:y,ee=v[0]??{},U=t?.getTitleText?t.getTitleText(B,H,ee,g):t?.title,te=B===1?ee.jobTitle??ee.title??ee.name??ee.fullName??ee.candidateName??null:null,ne=t?.getBodyText?t.getBodyText(B,V,H,te,g):t?.bodyText??null,re=typeof t?.getNote==`function`?t.getNote(g):t?.note,ie=t?.disabledUntilFilled&&!j&&!N;if(!t||!e||z)return null;let ae=t.component;return ae?(0,l.jsx)(s.Modal,{open:e,title:t.title||t.getTitleText?(0,l.jsx)(IO,{titleText:U,titleIcon:t.titleIcon}):null,footer:null,width:t.width??760,centered:!0,maskClosable:!1,onCancel:()=>k(),className:`dynamic-popup${t.className?` ${t.className}`:``}`,children:(0,l.jsx)(ae,{context:g,selectedIds:b,selectedRecords:v,moduleName:y,onClose:k})}):(0,l.jsxs)(s.Modal,{open:e,title:(0,l.jsx)(IO,{titleText:U,titleIcon:t.titleIcon}),okText:t.okText||`OK`,cancelText:t.cancelText??`Cancel`,onOk:F,onCancel:()=>k(),okButtonProps:{danger:t.okButtonDanger,disabled:ie,loading:I},cancelButtonProps:{disabled:I},closable:!I,maskClosable:!1,width:t.width??480,centered:!0,className:`dynamic-popup${t.className?` ${t.className}`:``}`,children:[(0,l.jsx)(LO,{note:re,description:t.description,showSelectedCount:t.showSelectedCount,count:B,itemLabel:H,bodyText:ne,deleteError:L}),(0,l.jsx)(RO,{footerNote:t.footerNote}),(0,l.jsx)(xk,{form:c,fields:x,initialValues:S,dynamicOptions:C,popupContext:g,extraData:T,removedIds:p,setRemovedIds:m,showAlreadyAssigned:t.showAlreadyAssigned,onValuesChange:f,getSearchHandler:D,getMentionSearchHandler:O,mentionOptions:E})]})}var Uk={mode:`delete`,getTitleText:(e,t)=>`Delete ${e>0?`${e} `:``}${t}`,titleIcon:`delete`,okText:`Delete`,okButtonDanger:!0,width:420,getBodyText:(e,t,n,r)=>r?`Are you sure you want to delete the ${r} ${t}?`:e>1?`Are you sure you want to delete ${e} selected ${n}?`:`Are you sure you want to delete this ${t}?`,footerNote:`This action cannot be undone.`,fields:[]},Wk={deleteItems:async(e,t)=>{await re(t.moduleName,e)}},Gk=new Map;async function Kk(e){return e?(Gk.has(e)||Gk.set(e,a.r({module:e}).catch(t=>(Gk.delete(e),console.warn(`[in-progress gate] could not read ${e} form groups:`,t),[]))),Gk.get(e)):[]}function qk(e=[],t){return e.some(e=>{let r=n.C(e,t);return r&&r.severity!==`allow`})}async function Jk({targetModule:e,sourceModule:t,recordId:r,region:i}={}){let o={severity:`allow`,message:``,group:null};if(!e||!t||!r)return o;let s=i??n.Un().region;try{let i=await Kk(e);if(!qk(i,s))return o;let c=await a.r({module:t,id:r}),l={};for(let e of c){let t=e?.payloadKey||e?.name;t&&Array.isArray(e?.rows)&&(l[t]=e.rows)}return n.D(i,s,l)}catch(e){return console.warn(`[in-progress gate] check skipped:`,e),o}}var Yk=`Already submitted`,Xk=`submissions`,Zk=`candidates`,Qk=864e5,$k=90,eA=`This candidate was created or last updated more than 90 days ago. Only candidates created or updated within the last 90 days can be selected. Please update this candidate first.`,tA=[`createdAt`,`createdDate`,`dateCreated`,`created_on`,`createdOn`],nA=[`updatedAt`,`updatedDate`,`lastUpdatedAt`,`lastUpdatedDate`,`modifiedAt`,`modifiedDate`];function rA(e,t){for(let n of t){let t=e?.[n];if(!t)continue;let r=new Date(t);if(!Number.isNaN(r.getTime()))return r}return null}function iA(e){return rA(e,tA)}function aA(e){return rA(e,nA)}function oA(e){if(!(e instanceof Date)||Number.isNaN(e.getTime()))return null;let t=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();return Math.max(0,Math.floor((t(new Date)-t(e))/Qk))}function sA(e){return e===null?``:e<=14?`green`:e<=89?`yellow`:`red`}function cA(e,t=$k){if(!e)return!1;let n=Date.now()-t*Qk,r=iA(e),i=aA(e),a=r&&r.getTime()>=n,o=i&&i.getTime()>=n;return!a&&!o}function lA(e){let t=iA(e);if(!t)return{createdAgo:``,createdAgoTone:``};let n=HO(t);return n?{createdAgo:n,createdAgoTone:sA(oA(t))}:{createdAgo:``,createdAgoTone:``}}function uA(e){return{...e,...lA(e),isStaleCandidate:cA(e)}}function dA(e){return String(e?.applicantId??e?._id??e?.id??``)}var fA=null;async function pA(){return fA||=n.zr(Zk).then(e=>e?.strategies?.duplicateCheck?.editRoute??``).catch(()=>``),fA}async function mA(e){let t=dA(e);if(!t)return``;let n=await pA();return n?n.replace(/:(_?id)\b/g,encodeURIComponent(t)):``}async function hA({option:e,popupContext:t,confirm:n}){let r=e?._raw??e??{},i=dA(r);if(i){let e=await Jk({targetModule:Xk,sourceModule:Zk,recordId:i});if(e.severity===`block`)return new Promise(t=>{n({title:`This candidate cannot be submitted`,content:e.message,okText:`Pick someone else`,cancelText:`Close`,onOk:()=>t(!1),onCancel:()=>t(!1)})})}if(!cA(r))return!0;let a=t?.navigate;return!a||!i?!1:new Promise(e=>{n({title:`Candidate update required`,content:eA,okText:`OK`,cancelText:`Cancel`,onOk:async()=>{let t=await mA(r);t&&a(t),e(!1)},onCancel:()=>e(!1)})})}function gA(e,t,n){return{...e,label:`${e.label} - ${Yk}`,disabled:!0,title:`${Yk}${t?` (submission ${t})`:``}`,alreadySubmitted:!0,existingSubmissionId:t||``,...n?{submittedAt:n}:{}}}var _A={searchOptions:async(e,t,n)=>{if(e.searchFetchKey===`quickSubmitJobList`){let e=n.selectedRecords?.[0]??{},r=e.id??e._id??n.selectedIds?.[0],i,a=!0;try{i=await Ce({searchQuery:t,candidateId:r})}catch{a=!1;let e=await Ln({searchQuery:t,candidateId:r});i=Array.isArray(e?.data)?e.data:[]}let o=i.map(e=>({label:[e.jobReferenceId??e.clientJobReferenceId,e.jobTitle].filter(Boolean).join(` - `)||String(e._id??``),value:e._id??``,_raw:e}));if(a)return o.map(e=>{if(e._raw?.isSubmitted||e._raw?.alreadySubmitted)return gA(e,e._raw?.jobSubmissionId||``,e._raw?.submittedAt||``);if(e._raw?.disable){let t=String(e._raw?.message??``).trim();return{...e,disabled:!0,label:t?`${e.label} - ${t}`:e.label,title:t}}return e});let s=await Te({applicantId:r,jobIds:o.map(e=>e.value)}).catch(()=>new Map);return o.map(e=>{let t=s.get(String(e.value));return t?gA(e,t.submissionId,t.submittedAt):e})}if(e.searchFetchKey===`quickSubmitCandidates`){let e=n.selectedRecords?.[0]??{},r=n.jobId??e.jobId??e.id??e._id??n.selectedIds?.[0],i,a=new Map;try{i=await we({search:t,jobId:r})}catch{let e=await is({isFromSubmission:n.isFromSubmission,jobId:r,submissionId:n.submissionId,search:t});i=Array.isArray(e)?e:[],a=await Te({jobId:r,applicantIds:i.map(dA)}).catch(()=>new Map)}return i.map(e=>uA(e)).map(e=>{let t=a.get(dA(e));if(!(t||e?.isSubmitted===!0||e?.alreadySubmitted===!0))return e;let n=t?.submissionId||e?.jobSubmissionId||``,r=t?.submittedAt||e?.submittedAt||``;return{...e,disabled:!0,optionNote:Yk,isSubmitted:!0,alreadySubmitted:!0,existingSubmissionId:n,...r?{submittedAt:r}:{}}})}return[]},submit:async(e,t,n)=>{let{navigate:r,selectedRecords:i=[],selectedIds:a=[],moduleName:o}=t,s=i[0]??{},c,l;t.jobId?(c=t.jobId,l=s.id??s._id??a[0]??``):o===`candidate`?(c=e.jobId??``,l=s.id??s._id??a[0]??``):(c=s.jobId??s.id??s._id??a[0]??``,l=e.candidate??``);let u=n?.dynamicOptions?.candidate?.find(e=>dA(e?._raw)===String(l)),d=n?.dynamicOptions?.jobId?.find(e=>String(e?.value)===String(c)),f=u?._raw?.isSubmitted||u?._raw?.alreadySubmitted||d?.alreadySubmitted||d?._raw?.isSubmitted||d?._raw?.alreadySubmitted;if(!c||!l)throw Error(`Select both a job and a candidate to quick submit.`);if(cA(u?._raw))throw Error(eA);let p=await Jk({targetModule:Xk,sourceModule:Zk,recordId:l});if(p.severity===`block`)throw Error(p.message);let m=f,h=u?._raw?.existingSubmissionId||u?._raw?.jobSubmissionId||d?.existingSubmissionId||d?._raw?.jobSubmissionId||``;try{let e=await Se({jobId:c,applicantId:l});m||=!!e?.exists,h=e?.submissionId||h}catch(e){throw Error(`Could not verify existing submissions (${e?.message??`request failed`}). Please try again.`,{cause:e})}if(m)throw Error(`This candidate is already submitted for this job${h?` (submission ${h})`:``}.`);let g=new URLSearchParams;l&&g.set(`candidateId`,l);let _=u?.priorSubmissionId||u?._raw?.submissionId||d?.priorSubmissionId||d?._raw?.submissionId||``;_?(g.set(`submissionId`,String(_)),g.set(`isFromSubmission`,`true`)):g.set(`isFromSubmission`,`false`);let v=ts(rs({jobId:c,applicantId:l}).catch(()=>[]));return r(`/submission-create/${c}?${g.toString()}`,{state:{relevantSkillsToken:v}}),{navigated:!0}}},vA={title:`Submit`,okText:`Submit`,width:640,disabledUntilFilled:!0,autoSubmitWhenNoFields:!0,getNote:e=>e.moduleName===`candidate`?`Note: Select a job to submit this candidate.`:`Note: Select a candidate to submit for this job`,getFields:e=>e.jobId?[]:e.moduleName===`candidate`?[{name:`jobId`,label:`Job list`,type:`search-select`,required:!0,placeholder:`Search Job ID / job name - or pick a recent job`,searchFetchKey:`quickSubmitJobList`,optionLayout:{id:`{jobReferenceId}`,title:`{jobTitle}`,subtitle:`{clientJobReferenceId}`,meta:[{label:`Created`,key:`createdAt`,type:`date`},{label:`Updated`,key:`updatedAt`,type:`relative`}]}}]:[{name:`candidate`,label:`Candidate`,type:`search-select`,required:!0,placeholder:`Search candidate name / email - or pick a recent candidate`,optionsKey:`candidateOptions`,searchFetchKey:`quickSubmitCandidates`,labelTemplate:`{applicantRefrenceId} - {firstName} {lastName} - {createdAgo}`,valueKey:`applicantId`,optionLayout:{id:`{applicantRefrenceId}`,title:`{firstName} {lastName}`,titleAccent:{key:`createdAgo`,toneKey:`createdAgoTone`,prefix:` - `},subtitle:`{designation} - {email}`,meta:[{label:`Created`,key:`createdAt`,type:`date`},{label:`Updated`,key:`updatedAt`,type:`relative`}]},onSelectGuard:hA}]},yA={title:`Add Notes & Share`,okText:`Save & Share`,width:480,fields:[{name:`notes`,label:`Notes`,type:`mention-textarea`,required:!0,rows:5,maxLength:2e3,placeholder:`Add your notes on the job. Use '@' to mention someone.`,mentionFetchKey:`mentionUsers`}]},bA=e=>e?.data??e;async function xA({relatedId:e,notes:n,title:r,notesFor:i}){return bA(await yn(t.x,`/notes`,{method:`POST`,body:JSON.stringify({relatedId:e,notes:n,title:r,notesFor:i})}))}var SA={getMentionOptions:async(e,t)=>ae(t),submit:async(e,t)=>{let n=Array.isArray(t.selectedIds)?t.selectedIds[0]:t.selectedIds;if(!n)throw Error(`Please select a record before adding a note.`);await xA({relatedId:String(n),notes:e.notes,notesFor:t.moduleName})}},CA={name:`jobId`,label:`Job Title / ID`,type:`search-select`,multiple:!0,required:!0,placeholder:`Minimum 3 characters`,searchFetchKey:`tagToJobJobList`,valueKey:`_id`,labelTemplate:`{jobReferenceId} - {jobTitle}`},wA={name:`hiringStage`,label:`Hiring stage`,type:`select`,required:!0,optionsKey:`hiringStageOptions`,defaultOptions:[{label:`Shortlisted`,value:`shortlisted`},{label:`Pipeline`,value:`pipeline`}],initialValueKey:`hiringStage`},TA={title:`Tag to Job`,okText:`Tag`,width:480,disabledUntilFilled:!0,autoSubmitWhenNoFields:!0,getFields:e=>e.jobId&&e.hiringStage?[]:e.jobId?[wA]:[CA,wA]},EA=e=>e?.data??e;function DA(e){return Array.isArray(e)&&e.every(e=>e&&typeof e==`object`&&`Key`in e)?e.reduce((e,{Key:t,Value:n})=>(e[t]=n,e),{}):e}function OA(e){return e?Array.isArray(e.data)?e.data.map(DA):e.stage&&Array.isArray(e.stage.data)?e.stage.data.map(DA):Array.isArray(e)?e.map(DA):[]:[]}async function kA(e=1,n=10){let r=await t.o(t.x,`/workflow/list/all?page=${e}&limit=${n}`),i=EA(r),a=Array.isArray(i)?i:i?.data??[];return{items:a,total:Number(r?.total??i?.total)||a.length,page:e,limit:n}}async function AA(e,n){let r=EA(await t.o(t.x,`/workflow/${e}/stage/${n}`));return Array.isArray(r)?{data:r}:r}async function jA(e,n){if(!e||!n)return null;try{let r=new URLSearchParams({module:e,limit:`1`,offset:`0`,scope:`allJobs`,filters:JSON.stringify([{field:`_id`,op:`in`,values:[String(n)],operator:`and`}])}),i=EA(await t.o(t.x,`/module-data-list?${r}`));if(Array.isArray(i))return i[0]??null;if(i?.data&&Array.isArray(i.data))return i.data[0]??null;let a=i?.rows??i?.records??i?.items??i?.list;return Array.isArray(a)?a[0]??null:i??null}catch(t){return console.error(`[getModuleRecordById] failed: ${e}/${n}`,t),null}}async function MA(e){return EA(await t.o(t.C,`/source/workflow-instance`,{method:`POST`,body:JSON.stringify(e)}))}var NA={pipeline:`pipeline`,goodfited:`goodfited`,contacted:`contacted`,submitted:`submitted`,shortlisted:`shortlisted`,interviewinprogress:`interviewInprogress`,selected:`selected`},PA=`Already submitted`;function FA(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&t!==``)return t}}function IA(e){let t=String(e??``).trim();return t?NA[t.toLowerCase()]??t:``}function LA(e,t=``){return String(FA(e,`candidateId`,`candidate_id`,`applicantId`,`applicantID`,`applicantReferenceId`,`applicantRefrenceId`,`_id`,`id`)??t??``)}function RA(e){return String(FA(e,`_id`,`id`,`candidateId`,`candidate_id`,`applicantId`,`applicantID`)??``)}function zA(e,t,n){let r=String(e.jobTitle??``).trim();return{...e,jobTitle:r?`${r} (${PA})`:`(${PA})`,disabled:!0,title:PA,alreadySubmitted:!0,existingSubmissionId:t||``,...n?{submittedAt:n}:{}}}function BA(e,t){let n=String(t??``).trim();return n?/already submitted/i.test(n)?`${e} (${PA})`:/fulfilled/i.test(n)?`${e} (Fullfilled)`:`${e} (${n})`:e}function VA(e){let t=String(e.jobReferenceId??e.clientJobReferenceId??``).trim(),n=String(e.jobTitle??``).trim();return{...e,jobReferenceId:t,jobTitle:n}}function HA(e){return WA(e).map(e=>e.id)}function UA(e,t=``){return(FA(e,`candidateName`,`candidate_name`,`fullName`,`name`)??[FA(e,`firstName`,`first_name`),FA(e,`lastName`,`last_name`)].filter(Boolean).join(` `)??t)||`Unknown candidate`}function WA(e){let t=Array.isArray(e?.selectedIds)?e.selectedIds:[],n=Array.isArray(e?.selectedRecords)?e.selectedRecords:[],r=[],i=new Set,a=Math.max(t.length,n.length);for(let e=0;e<a;e+=1){let a=n[e]??{},o=t[e]?String(t[e]):``,s=LA(a,o);!s||i.has(s)||(i.add(s),r.push({id:s,name:UA(a,o),record:a,selectedId:o||s}))}return r}function GA(e,t){return Array.isArray(e?.jobId)?e.jobId.map(String).filter(Boolean):e?.jobId?[String(e.jobId)]:Array.isArray(t?.jobId)?t.jobId.map(String).filter(Boolean):t?.jobId?[String(t.jobId)]:[]}function KA(e,t=``){let n=String(e?.jobTitle??e?._raw?.jobTitle??``).trim();if(n)return n;let r=String(e?.label??e?._raw?.label??``).trim();return r.includes(` - `)?r.split(` - `).slice(1).join(` - `).trim():r||String(t??``)}function qA(e,t=``){return KA(e,t)}function JA(e,t,n){let r=[...new Set(GA(e,t))],i=Array.isArray(n?.dynamicOptions?.jobId)?n.dynamicOptions.jobId:[],a=new Map(i.map(e=>[String(e?._id??e?.value??``),e]));return r.map(e=>{let t=a.get(String(e))??{};return{id:String(e),label:qA(t,e),record:t}})}function YA(e){return e.filter(e=>e.blockedCandidates.length>0).map(e=>`${e.job.label} - ${e.blockedCandidates.map(e=>e.name).join(`, `)}`).join(` | `)}function XA(e){return e.filter(e=>e.allowedCandidates.length>0).map(e=>`${e.job.label} - ${e.allowedCandidates.map(e=>e.name).join(`, `)}`).join(` | `)}function ZA(e,t){let n=RA(e);if(!n)return null;let r=UA(e,t)||void 0,i={candidateId:String(n),candidateName:r,phone:FA(e,`phone`,`phoneNumber`,`phone_number`,`mobile`,`mobileNumber`,`mobile_number`),source:FA(e,`source`,`sourceType`,`candidateSource`,`profileSource`),submittedAt:FA(e,`submittedAt`,`lastSubmittedAt`,`updatedAt`),remarks:FA(e,`remarks`,`comment`,`comments`,`notes`),assignedRecruiter:FA(e,`assignedRecruiter`,`recruiterName`,`ownerName`,`assignedToName`),screeningStatus:FA(e,`screeningStatus`,`screening.status`,`screeningResult`),screeningScore:FA(e,`screeningScore`,`screening.score`,`score`),assignedDate:FA(e,`assignedDate`,`assignedAt`,`createdAt`)};return Object.fromEntries(Object.entries(i).filter(([,e])=>e!=null&&e!==``))}var QA={searchOptions:async(e,t,n)=>{if(e.searchFetchKey===`tagToJobJobList`){let e=HA(n),r=e.length===1?e[0]:``,i,a=!1;if(r)try{i=await Ce({searchQuery:t,candidateId:r}),a=!0}catch{a=!1}Array.isArray(i)||(i=await ie(t));let o=i.map(VA);if(a)return o.map(e=>{if(e?.isSubmitted||e?.alreadySubmitted)return zA(e,e?.jobSubmissionId||e?.submissionId||``,e?.submittedAt||``);if(e?.disable){let t=String(e?.message??``).trim();return{...e,jobTitle:e.jobTitle?BA(e.jobTitle,t):`(${t})`,disabled:!0,optionNote:t,title:t}}return e});if(!r)return o;let s=await Te({applicantId:r,jobIds:o.map(e=>e._id).filter(Boolean)}).catch(()=>new Map);return o.map(e=>{let t=s.get(String(e._id));return t?zA(e,t.submissionId,t.submittedAt):e})}return[]},submit:async(e,t,r)=>{let i=IA(e.hiringStage??t.hiringStage),a=WA(t),o=JA(e,t,r);if(!o.length||!a.length)return{cancelled:!0};let s=[];for(let e of o){let t=await Te({jobId:e.id,applicantIds:a.map(e=>e.id)}).catch(()=>new Map);s.push({job:e,blockedCandidates:a.filter(e=>t.has(String(e.id))),allowedCandidates:a.filter(e=>!t.has(String(e.id)))})}let c=YA(s),l=XA(s),u=s.filter(e=>e.allowedCandidates.length>0);if(!u.length)return await n.Wt({tone:`duplicate`,title:`Selected candidates are already submitted`,body:`Every selected candidate is already submitted to the selected jobs. Choose different jobs to continue.`,facts:[{label:`Blocked combinations`,value:c}],okText:`Close`}),{cancelled:!0};if(s.some(e=>e.blockedCandidates.length>0)&&!await n.Ut({tone:`duplicate`,title:`Some candidate-job combinations are already submitted`,body:`Those combinations will be skipped. Continue tagging the remaining valid combinations?`,facts:[{label:`Will be skipped`,value:c},{label:`Will be tagged`,value:l}],okText:`Tag remaining`,cancelText:`Cancel`,footnote:`Already submitted combinations will be left unchanged.`}))return{cancelled:!0};for(let e of u){for(let t of e.allowedCandidates){let n=ZA(t.record??{},t.selectedId);await MA({jobId:e.job.id,module:`jobs`,currentStage:i,...n?{candidateDetails:n}:{}})}await ce({jobId:e.job.id,candidateIds:e.allowedCandidates.map(e=>e.selectedId||e.id),hiringStage:i})}}},$A={title:`Change Status`,okText:`Apply`,width:420,showSelectedCount:!0,fields:[{name:`status`,label:`New Status`,type:`select`,required:!0,placeholder:`Select a status`,dataSource:`master`,masterName:`clientSubmissions`,labelKey:`name`,valueKey:`name`,initialValueKey:`currentStatus`,defaultOptions:[{label:`Active`,value:`active`},{label:`Inactive`,value:`inactive`},{label:`Pending`,value:`pending`},{label:`Closed`,value:`closed`}]}]};function ej(e,t){let n=String(e??``).trim().toLowerCase();return(Array.isArray(t?.status)?t.status:[]).find(e=>String(e?.value??``).trim().toLowerCase()===n||String(e?.label??``).trim().toLowerCase()===n||String(e?._raw?.name??``).trim().toLowerCase()===n)??null}var tj={submit:async(e,t,n)=>{let r=ej(e.status,n?.dynamicOptions),i=r?._raw??{},a={clientSubmissionStatusText:String(i.name??r?.label??e.status??``).trim(),clientSubmissionStatusId:Number(i.id??i.uniqueId??0)||0,clientSubmissionStatusType:String(i.type??``).trim()};await ne(t.moduleName,t.selectedIds,a)}},nj={getTitleText:e=>`Remove ${e>1?`${e} Candidates`:`Candidate`} from Shortlist`,titleIcon:`delete`,okText:`Remove`,okButtonDanger:!0,width:420,getBodyText:e=>e>1?`Are you sure you want to remove ${e} selected candidates from the shortlist?`:`Are you sure you want to remove this candidate from the shortlist?`,footerNote:`The candidate will be moved back to the pipeline.`,fields:[]},rj={onOk:async e=>{await Ee({jobId:e.jobId??e.selectedIds[0],candidateIds:e.selectedIds})}},ij={title:`Add to Groups`,description:`Select a group to add the selected candidate(s) to`,okText:`Add to Group`,width:480,disabledUntilFilled:!0,fields:[{name:`groupId`,label:`Group`,type:`select`,required:!0,placeholder:`Select a group`,fetchOptionsKey:`candidateGroups`}]},aj={getOptions:async e=>e.fetchOptionsKey===`candidateGroups`?le():[],submit:async(e,t,{dynamicOptions:n})=>{let r=(n.groupId??[]).find(t=>String(t.value)===String(e.groupId));await ue({candidateIds:t.selectedIds,groupId:e.groupId,groupName:r?.label??``})}},oj=[{title:`Name`,key:`name`,render:(e,t)=>t.name||`${t.first_name??``} ${t.last_name??``}`.trim()||t.user_name||`Assigned user`},{title:`Role`,dataIndex:`role_name`,key:`role`,render:e=>e||`-`},{title:`Reporting`,dataIndex:`reporting_name`,key:`reporting`,render:e=>e||`-`}];function sj({selectedIds:e,onClose:t}){let n=e?.[0],[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)({assignedUsers:[],totalSubmissions:0,message:``}),[p,m]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1;return i(!0),Promise.all([G(n).catch(t=>(e||s.message.error(t?.message??`Failed to load self-assign details`),{assignedUsers:[],totalSubmissions:0,message:``})),me(n).catch(()=>({recruitersData:[]}))]).then(([t,n])=>{e||(f(t),m(Array.isArray(n?.recruitersData)?n.recruitersData:[]))}).finally(()=>{e||i(!1)}),()=>{e=!0}},[n]);let h=async()=>{u(!0);try{await de({jobIds:[n]}),s.message.success(`Job assigned successfully`),t?.({success:!0})}catch(e){s.message.error(e?.message??`Failed to assign job`)}finally{u(!1)}};if(r)return(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})});let g=p.map(e=>({user_id:e.recruiterId??e.id??e.user_id,name:e.name??``,role_name:e.role_name??e.roleName??``,reporting_name:e.reporting_name??e.reportingName??``})),_=new Map(g.map(e=>[String(e.user_id??``),e])),v=(d.assignedUsers?.length??0)>0?d.assignedUsers.map(e=>{let t=e.user_id??e.userId??e.recruiterId??e.id,n=_.get(String(t??``))??{};return{...e,user_id:t,name:n.name||e.name||``,role_name:n.role_name||e.role_name||e.roleName||``,reporting_name:n.reporting_name||e.reporting_name||e.reportingName||``}}):g,y=v.length>0;return(0,l.jsxs)(`div`,{className:`self-assign-popup-body`,children:[y?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{style:{fontWeight:700,marginBottom:8},children:`Team Members Allocated`}),(0,l.jsx)(s.Table,{columns:oj,dataSource:v,pagination:!1,rowKey:e=>e.user_id??`${e.first_name}-${e.last_name}`,size:`small`,className:`mb-3 no-header-bg`,scroll:{y:200}}),(0,l.jsxs)(`div`,{className:`warning-card`,style:{display:`flex`,alignItems:`center`,gap:8,marginTop:12},children:[(0,l.jsx)(c.ExclamationCircleFilled,{style:{color:`#faad14`,fontSize:18}}),(0,l.jsx)(`div`,{style:{fontSize:13},children:`These users are already assigned to this job. Do you still want to assign yourself as well?`})]})]}):(0,l.jsx)(`div`,{style:{padding:`8px 0`},children:d.message||`No one is currently assigned to this job. Do you want to assign yourself?`}),(0,l.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12,marginTop:24},children:[(0,l.jsx)(s.Button,{size:`small`,onClick:()=>t?.(),disabled:a,children:`No`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,onClick:h,loading:a,children:`Yes`})]})]})}sj.propTypes={selectedIds:f.default.array,onClose:f.default.func};var cj={title:`Self Assign`,width:480,className:`self-assign-modal`,component:sj},lj={submit:async()=>{}};function uj(e={}){let t=Array.isArray(e.jobPayDetails)?e.jobPayDetails[e.jobPayDetails.length-1]:e.jobPayDetails??e.clientBudget??{},n=Number(t.clientBudgetEnd),r=Number(t.clientBudgetStart);return Number.isFinite(n)&&n>0?n:Number.isFinite(r)&&r>0?r:null}var dj={getTitleText:(e,t,n)=>{let r=n?.jobTitle||n?.title||``;return r?`Assign - ${r}`:`Assign`},okText:`Assign`,width:520,disabledUntilFilled:!0,showAlreadyAssigned:!0,allowRemovalOnlySubmit:!0,getFields:e=>(uj(e?.selectedRecords?.[0]??{}),[{name:`assignToUserId`,label:`Assign to`,type:`multi-select`,required:!0,placeholder:`Select recruiter(s)`,fetchOptionsKey:`assignToUsers`}])},fj={getOptions:async e=>e.fetchOptionsKey===`assignToUsers`?pe():[],loadExtraData:async e=>me(e.selectedIds[0]),submit:async(e,t,{removedIds:n,extraData:r})=>{await ve({jobIds:t.selectedIds,userId:e.assignToUserId,removedIds:n,existingRecruiters:r?.recruitersData})}},pj={title:`Add Sticky Notes`,getTitleText:(e,t,n,r)=>r.editingNoteId?`Edit Sticky Notes`:`Add Sticky Notes`,okText:`Save`,width:480,fields:[{name:`heading`,label:`Heading`,type:`input`,required:!0,placeholder:`Enter heading`,initialValueKey:`editingHeading`},{name:`targetDate`,label:`Target Date`,type:`date-picker`,required:!1,initialValueKey:`editingTargetDate`},{name:`comments`,label:`Comments`,type:`mention-textarea`,required:!0,rows:5,placeholder:`Enter your note here... Use '@' to mention someone.`,mentionFetchKey:`mentionUsers`,initialValueKey:`editingComments`}]},mj={getMentionOptions:async(e,t)=>ae(t),submit:async(e,t)=>{let n=e.targetDate?e.targetDate.toISOString():``;t.editingNoteId?await oe(t.editingNoteId,{title:e.heading,targetDate:n,notes:e.comments}):await W({relatedIds:t.selectedIds,module:t.moduleName,title:e.heading,targetDate:n,notes:e.comments}),window.dispatchEvent(new Event(`sticky-notes:refresh`))}},hj={title:`Move to Onboarding`,bodyText:`Are you sure you want to move this candidate to onboarding?`,okText:`Yes`,cancelText:`No`,width:420,successMessage:`Moved to onboarding successfully`,successNavigate:`/onboarding`,fields:[{name:`sendOnboardingEmail`,type:`priority-checkbox`,checkboxLabel:`Send Onboarding Email`}]},gj={submit:async(e,t)=>{await ye({submissionId:t.selectedRecords?.[0]?.submissionId,isMail:e.sendOnboardingEmail})}};function _j(e){return Array.isArray(e)?e[e.length-1]??{}:e&&typeof e==`object`?e:{}}var vj={USD:`$`,INR:`₹`,EUR:`€`,GBP:`£`};function yj(e,t,n){let r=_j(e?.[t])[n];if(r!=null&&r!==``)return r;let i=e?.[`${t}.${n}`];return i!=null&&i!==``?i:void 0}function bj(e){let t=e.selectedRecords?.[0]??{},n=yj(t,`candidateRate`,`candidateAcceptedRate`)??yj(t,`candidateBudget`,`candidateBudgetStart`);if(n===void 0||Number(n)===0)return null;let r=yj(t,`candidateRate`,`candidateAcceptedCurrency`)??yj(t,`candidateBudget`,`candidateBudgetCurrency`);return{amount:n,symbol:yj(t,`candidateRate`,`candidateAcceptedCurrencySymbol`)??yj(t,`candidateBudget`,`candidateBudgetCurrencySymbol`)??vj[String(r??``).toUpperCase()]??(r||`$`),unit:yj(t,`candidateRate`,`candidateAcceptedPayUnit`)??yj(t,`candidateBudget`,`candidateBudgetUnit`)??``}}var xj={title:`Approve Rate`,okText:`Approve`,width:520,className:`medium-modal`,successMessage:`Rate approved`,getBodyText:(e,t,n,r,i)=>{let a=bj(i);return`Candidate Rate: ${a?`${a.symbol}${a.amount}${a.unit?`/${a.unit}`:``}`:`-`}`},fields:[{name:`candidateProposedRate`,label:`Proposed Rate`,type:`number`,required:!0,placeholder:`Amount`,min:0,inlineRow:`proposedRate`,validator:(e,t)=>{if(e==null||e===``)return;let n=bj(t);if(n&&Number(e)<=Number(n.amount))return`Proposed rate must be greater than Candidate Rate`}},{name:`candidateProposedRateCurrency`,label:`Currency`,type:`select`,required:!0,inlineRow:`proposedRate`,defaultOptions:[{label:`$ USD`,value:`$`},{label:`₹ INR`,value:`₹`},{label:`€ EUR`,value:`€`}]},{name:`candidateProposedRateUnit`,label:`Unit`,type:`select`,required:!0,inlineRow:`proposedRate`,defaultOptions:[{label:`Year`,value:`yr`},{label:`Month`,value:`mo`},{label:`Week`,value:`wk`},{label:`Hour`,value:`hr`},{label:`Daily`,value:`day`}]},{name:`submitVia`,label:`Submit Via`,type:`radio`,required:!0,defaultOptions:[{label:`Mail`,value:`Mail`},{label:`VMS`,value:`VMS`}]}]},Sj={submit:async(e,t)=>{let n=t.selectedIds[0];if(await be(n,{candidateProposedRate:e.candidateProposedRate,candidateProposedRateCurrency:e.candidateProposedRateCurrency,candidateProposedRateUnit:e.candidateProposedRateUnit,submitVia:e.submitVia}),e.submitVia===`VMS`)try{await xe(n)}catch{s.message.warning(`Approved. VMS notification could not be sent — use Send Mail to notify the client.`)}else s.message.info(`Approved — use Send Mail to notify the client.`)}};async function Cj(e,n={}){let r=t.u();if(!r){let e=Error(`Authentication required`);throw e.status=401,e}let i=await fetch(`${t.T}${e}`,{...n,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${r}`,...n.headers}});if(i.status===401&&t.h(),!i.ok){let e=Error(`API ${i.status}: ${i.statusText}`);throw e.status=i.status,e}return i.json()}async function wj(e){let t=await Cj(`/mail-form?${new URLSearchParams({submissionId:e,submissionType:`manager`}).toString()}`);return t.data??t}function Tj(e){return Array.isArray(e)?e[e.length-1]:e}function Ej(e={}){let t=Tj(e?.proposedRate)?.candidateProposedRate??e?.candidateProposedRate??e?.proposedRateValue,n=Number(t);return Number.isFinite(n)?n:0}function Dj(e,t={}){let n=Tj((e?.record?.job??e?.job??t?.job??{})?.jobPayDetails)??{},r=e?.record?.submission??t??{},i=Tj(r?.clientBudget)??r?.clientBudget??{},a=n?.clientBudgetEnd??n?.clientBudgetStart??i?.clientBudgetEnd??i?.clientBudgetStart,o=Number(a);return Number.isFinite(o)?o:0}function Oj(e={}){let t=String(e?.currencyRaw??``).trim().toUpperCase(),n=String(e?.currency??``).trim();return n&&!/^[A-Z]{3}$/i.test(n)?n:t===`USD`||n.toUpperCase()===`USD`?`$`:t===`INR`||n.toUpperCase()===`INR`?`₹`:t===`EUR`||n.toUpperCase()===`EUR`?`€`:t===`GBP`||n.toUpperCase()===`GBP`?`£`:n||t}function kj(e={}){return String(e?.rateUnit??`hr`).trim().replace(/^\/+/,``)||`hr`}function Aj(e,t={}){let n=Number(e);return Number.isFinite(n)?`${Oj(t)}${n}/${kj(t)}`:``}function jj(e,t,n){if(n==null||n===``)return String(e??``);let r=String(e??``),i=String(n),a=!1,o=RegExp(`(<(?:td|th)[^>]*>[\\s\\S]*?${t}[\\s\\S]*?</(?:td|th)>\\s*<(?:td|th)[^>]*>)([\\s\\S]*?)(</(?:td|th)>)`,`gi`);r=r.replace(o,(e,t,n,r)=>(a=!0,`${t}${i}${r}`));let s=RegExp(`(<(?:strong|b)[^>]*>\\s*${t}\\s*:?\\s*</(?:strong|b)>\\s*)([\\s\\S]*?)(?=</(?:li|p|div)>)`,`gi`);if(r=r.replace(s,(e,t)=>(a=!0,`${t}${i}`)),!a){let e=RegExp(`(${t}\\s*:?[ \\t]*)([^<\\r\\n]*)`,`gi`);r=r.replace(e,(e,t)=>`${t}${i}`)}return r}function Mj(e,t,n,r,i){let a=Number(n?.proposedRate),o=Number.isFinite(a)?a:Ej(t),s=Number(n?.clientJobRate),c=Number.isFinite(s)&&s>0?s:Dj(r,i),l={proposedRate:o,jobBillRate:c},u=String(e??``).replace(/{{\.?((?:proposedRate)|(?:jobBillRate))}}/g,(e,t)=>{let n=l[t];return n==null?e:String(n)});return u=jj(u,`(?:Proposed\\s*Rate|Pay\\s*Rate)`,Aj(o,n)),u=jj(u,`(?:Job\\s*)?Bill\\s*Rate`,Aj(c,n)),u}function Nj(...e){return e.map(e=>e==null?``:String(e).trim()).find(Boolean)??``}var Pj=(e,t)=>!!e&&e.toLowerCase()===Nj(t).toLowerCase();function Fj(e,t,n){let r=Nj(t.submittedBy);return Nj(Pj(r,n)||Pj(r,e.submitSource)||Pj(r,e.supplierName)||Pj(r,e.source)||Pj(r,e.candidateSource)?``:r,e.signatureEmail)}function Ij(e,t={}){let n=t.employerName??e.supplierName??e.submitSource;return{client:t.clientName??e.clientName,role:t.jobTitle??e.jobTitle??e.designation,reqId:t.reqId??e.jobClientRefrenceId??e.mspReqId??e.submissionId,name:t.candidateName||[e.firstName,e.lastName].filter(Boolean).join(` `)||e.candidateFullName,location:t.jobLocation??e.city??e.currentLocation??e.jobLocation,vendor:n,submittedBy:Fj(e,t,n),submittedAt:t.createdAt??e.createdAt,email:t.email??e.email,employerLocation:t.employerLocation,employerName:t.employerName}}function Lj(e){let t=e?.$oid??e?._id?.$oid??e?._id??e?.id?.$oid??e?.id??e;if(t==null||typeof t==`object`)return``;let n=String(t).trim();return/^[a-f\d]{24}$/i.test(n)?n:``}function Rj(...e){for(let t of e){let e=[t?.jobId,t?.JobId,t?.job_id,t?.jobDetails?._id,t?.jobDetails?.id,t?.job?._id,t?.job?.id,t?.submission?.jobId,t?.submission?.JobId,t?.submission?.job_id,t?.submission?.jobDetails?._id,t?.submission?.jobDetails?.id,t?.submission?.job?._id,t?.submission?.job?.id,t?.recordMeta?.jobId,t?.recordMeta?.JobId,t?.recordMeta?.job_id,t?.submission?.recordMeta?.jobId,t?.submission?.recordMeta?.JobId,t?.submission?.recordMeta?.job_id].map(Lj).find(Boolean);if(e)return e}return``}function zj(e){if(!e?.referralId)return{};let t=Number(e.referralRate??e.referalRate??0)||0,n=String(e.referralType??e.referalType??`RECURRING`).trim()||`RECURRING`,r=e.referralId??e.referalId;return{referralId:r,referalId:r,referralRate:t,referalRate:t,referralType:n,referalType:n,referralEnabled:!0,referalEnabled:!0,isReferralApplicable:!0,referralDetails:{referralId:r,referalId:r,referralRate:t,referalRate:t,referralType:n,referalType:n,referralEnabled:!0,referalEnabled:!0,isReferralApplicable:!0}}}function Bj(e=``){return String(e??``).replace(/map\[[^\]]*(?:resume|document|attachment|file)[^\]]*\]/gi,``).replace(/<p>\s*<\/p>/gi,``).replace(/(?:<br\s*\/?>\s*){3,}/gi,`<br><br>`).trim()}function Vj(...e){for(let t of e){let e=[t?.candidateId,t?.applicantId,t?.candidate?._id,t?.candidate?.id,t?.submission?.candidateId,t?.submission?.applicantId,t?.recordMeta?.candidateId,t?.recordMeta?.applicantId].map(Lj).find(Boolean);if(e)return e}return``}async function Hj(e){let t=e?.fileUrl??e?.downloadUrl??e?.url;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load ${e?.fileName||`resume`}`);let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.originalName??e?.uniqueName??`resume`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function Uj(e,r,i){let a=[],o=await n.yn(`submissions`,e,`resume`).catch(()=>({data:[]}));a.push(...o?.data??[]);let s=Vj(r?.record?.submission,i,r?.record);if(!s){let n=await t.o(t.x,`/module/list?module=submissions&id=${encodeURIComponent(e)}`).catch(()=>({})),r=n?.data??n??{};s=Vj((Array.isArray(r?.data)?r.data:Array.isArray(r)?r:[])[0])}if(s){let e=await n.yn(`candidates`,s,`resume`).catch(()=>({data:[]}));a.push(...e?.data??[])}let c=(await Promise.all(a.map(Hj))).filter(Boolean),l=new Set;return c.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!l.has(t)&&(l.add(t),!0)})}function Wj(e={}){return{to:(e.to??e.To??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),cc:(e.cc??e.Cc??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),bcc:(e.bcc??e.Bcc??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),subject:e.subject??e.Subject??``,contents:Bj(e.content?.value??e.Content?.Value??e.contents??e.body??``)}}function Gj({context:e,selectedIds:t,selectedRecords:n,moduleName:r,onClose:i}){let a=n?.[0]??{},c=t?.[0]??xv(a),[u,d]=(0,o.useState)(null),[f,p]=(0,o.useState)(!0),[m,h]=(0,o.useState)([]),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(`vms`),[b,x]=(0,o.useState)(null),[S,C]=(0,o.useState)(null),[w,T]=(0,o.useState)(!1),[E,D]=(0,o.useState)(!1),[O,k]=(0,o.useState)(!1),[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)({to:``,cc:``,bcc:``,subject:``,contents:``,attachments:[],showCc:!1,showBcc:!1});(0,o.useEffect)(()=>{let e=!1;return cy(c,a).then(t=>{e||d(t)}).catch(t=>{e||(s.message.error(t?.message??`Unable to load finance details`),d({record:{submission:a},lookups:{},display:{}}))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[c]),(0,o.useEffect)(()=>{let e=!1;return _y().then(t=>{e||h(t)}).catch(()=>{}),()=>{e=!0}},[]);let P=async()=>{if(b){if(v===`mail`){_(!1),D(!0),k(!0);try{let[e,t]=await Promise.all([wj(c).then(Wj),Uj(c,u,a).catch(e=>(console.warn(`Unable to resolve resume attachment:`,e),[]))]),n=u?.record?.submission??a;N({to:Mj(e.to,n,b,u,a),cc:Mj(e.cc,n,b,u,a),bcc:Mj(e.bcc,n,b,u,a),subject:Mj(e.subject,n,b,u,a),contents:Mj(e.contents,n,b,u,a),attachments:t,showCc:!!e.cc,showBcc:!!e.bcc})}catch(e){s.message.error(e?.message??`Unable to prepare approval mail`)}finally{k(!1)}return}T(!0);try{await be(c,{candidateProposedRate:b.proposedRate,candidateProposedRateCurrency:b.currencyRaw??b.currency,candidateProposedRateUnit:b.rateUnit,submitVia:`VMS`,...zj(S)}),s.message.success(`Submission approved`),_(!1),x(null),C(null),i?.({success:!0})}catch(e){s.message.error(e?.message??`Unable to approve submission`)}finally{T(!1)}}},F=!O&&SD(M.to).length>0&&CD(M.to)&&CD(M.cc)&&CD(M.bcc)&&M.subject.trim()&&M.contents.trim(),I=async()=>{if(!b||!F||A)return;j(!0);let e={candidateProposedRate:b.proposedRate,candidateProposedRateCurrency:b.currencyRaw??b.currency,candidateProposedRateUnit:b.rateUnit};try{await be(c,{...e,submitVia:`VMS`,...zj(S)});let t=Rj(u?.record,a);if(!t)s.message.warning(`Submission approved, but job details were not available to send mail`);else try{await pn({jobId:t,toMail:SD(M.to),ccMail:SD(M.cc),bccMail:SD(M.bcc),subject:M.subject,contents:M.contents,attachments:M.attachments??[]}),s.message.success(`Approval mail sent and submission approved`)}catch(e){s.message.warning(e?.message?`Submission approved, but mail was not sent: ${e.message}`:`Submission approved, but mail was not sent`)}D(!1),x(null),C(null),i?.({success:!0})}catch(e){s.message.error(e?.message??`Unable to send approval mail`)}finally{j(!1)}},L=(0,o.useMemo)(()=>({submissionApprove:async({computed:e,referral:t})=>{x(e),C(t??null),y(`vms`),_(!0)},submissionReject:async()=>{e?.navigate?.(`/popup/reject`,{replace:!0,state:{background:e?.background??null,selectedIds:t,selectedRecords:n,moduleName:r}})}}),[e,t,n,r]);return f||!u?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Zv,{type:Y_,record:u.record,lookups:u.lookups,identity:Ij(a,u.display),referralOptions:m,onAddReferral:()=>e?.navigate?.(`/referrals-create`),currentUserId:typeof localStorage<`u`?localStorage.getItem(`userId`)??void 0:void 0,actions:L,onClose:()=>i?.(),variant:`popup`}),(0,l.jsx)(s.Modal,{title:`Choose approval method`,open:g,okText:`Approve`,confirmLoading:w,onOk:P,onCancel:()=>{w||(_(!1),x(null),C(null))},children:(0,l.jsxs)(s.Radio.Group,{value:v,onChange:e=>y(e.target.value),style:{display:`grid`,gap:12},children:[(0,l.jsx)(s.Radio,{value:`vms`,children:`Via VMS`}),(0,l.jsx)(s.Radio,{value:`mail`,children:`Via Mail`})]})}),(0,l.jsx)(s.Drawer,{open:E,placement:`right`,onClose:()=>{A||D(!1)},closable:!1,rootClassName:`mail-popup`,width:620,maskClosable:!1,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>D(!1),disabled:A,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:A,disabled:!F,onClick:I,children:`Send`})]}),children:O?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsx)(ID,{value:M,onChange:N,moduleName:`submissions`,ready:!O,title:`Submit Via Mail`,contextRecords:[u.record?.submission??a]})})]})}Gj.propTypes={context:f.default.object,selectedIds:f.default.array,selectedRecords:f.default.array,moduleName:f.default.string,onClose:f.default.func};var Kj={title:`Manager Approve`,width:780,className:`fa-modal manager-approve-modal`,component:Gj},qj={submit:async()=>{}};function Jj(...e){return e.map(e=>e==null?``:String(e).trim()).find(Boolean)??``}var Yj=(e,t)=>!!e&&e.toLowerCase()===Jj(t).toLowerCase();function Xj(e,t,n){let r=Jj(t.submittedBy);return Jj(Yj(r,n)||Yj(r,e.submitSource)||Yj(r,e.supplierName)||Yj(r,e.source)||Yj(r,e.candidateSource)?``:r,e.signatureEmail)}function Zj(e,t={}){let n=t.employerName??e.supplierName??e.submitSource;return{client:t.clientName??e.clientName,role:t.jobTitle??e.jobTitle??e.designation,reqId:t.reqId??e.jobClientRefrenceId??e.mspReqId??e.submissionId,name:t.candidateName||[e.firstName,e.lastName].filter(Boolean).join(` `)||e.candidateFullName,location:t.jobLocation??e.city??e.currentLocation??e.jobLocation,vendor:n,submittedBy:Xj(e,t,n),submittedAt:t.createdAt??e.createdAt,email:t.email??e.email,employerLocation:t.employerLocation,employerName:t.employerName}}function Qj(e){let t=Array.isArray(e)?e:[];for(let e=t.length-1;e>=0;--e)if(String(t[e]?.activityType??``).trim().toLowerCase()===`cfo rejected`)return t[e];return null}function $j(e){return String(e??``).toLowerCase().replace(/\b\w/g,e=>e.toUpperCase())}function eM({selectedIds:e,selectedRecords:t,onClose:r}){let i=t?.[0]??{},a=e?.[0]??xv(i),[c,u]=(0,o.useState)(null),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(!0);(0,o.useEffect)(()=>{let e=!1;return m(!0),Promise.all([cy(a,i),n.pn(`submission`,a).catch(()=>[])]).then(([t,n])=>{if(e)return;let r=Qj(n);f(xv(t?.meta?.workforceEngagementId??i?.onboarding?.workforceEngagementId??i?.workforceEngagementId));let a=t?.meta?.rejectReasonComments||r?.activityComments||``;u({...t,record:{...t.record,submission:{...t.record.submission,cfoRejectionReason:a?$j(a):``,cfoRejectedAt:t?.meta?.rejectedAt??r?.activityTime??null}}})}).catch(t=>{e||(s.message.error(t?.message??`Unable to load finance details`),u({record:{submission:i},lookups:{},display:{}}))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[a]);let h=(0,o.useMemo)(()=>({submissionReapproveSend:async({computed:e})=>{await K(d,{submissionId:a,billRate:e.proposedRate,payRate:e.employerRate,currency:e.currencyRaw??e.currency,rateUnit:e.rateUnit,vmsPercent:e.clientVmsPercent}),await be(a,{candidateProposedRate:e.proposedRate,candidateProposedRateCurrency:e.currencyRaw??e.currency,candidateProposedRateUnit:e.rateUnit,submitVia:`Mail`,context:`resend`}),s.message.success(`Re-approved and sent for CFO approval`),r?.({success:!0})}}),[a,d,r]);return p||!c?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsx)(Zv,{type:$_,record:c.record,lookups:c.lookups,identity:Zj(i,c.display),currentUserId:typeof localStorage<`u`?localStorage.getItem(`userId`)??void 0:void 0,actions:h,onClose:()=>r?.(),variant:`popup`})}eM.propTypes={selectedIds:f.default.array,selectedRecords:f.default.array,onClose:f.default.func};var tM={title:`Re-Approve`,width:780,className:`fa-modal manager-approve-modal`,component:eM},nM={submit:async()=>{}},rM=[{id:1,name:`Re-Submission`},{id:2,name:`Candidate doesn't fit into the profile`},{id:3,name:`Incomplete candidate details - (Re-Submission)`}],iM={title:`Reject`,okText:`Reject`,okButtonDanger:!0,width:480,successMessage:`Submission rejected successfully`,fields:[{name:`rejectReason`,label:`Rejection Reasons`,type:`select`,required:!0,placeholder:`Select rejection reasons`,defaultOptions:rM.map(e=>({label:e.name,value:e.id}))},{name:`rejectReasonComments`,label:`Comments`,type:`textarea`,required:!0,rows:4}]},aM={submit:async(e,t)=>{let n=rM.find(t=>String(t.id)===String(e.rejectReason));await q({submissionId:t.selectedIds[0],rejectReasonId:e.rejectReason,rejectReason:n?.name??``,rejectReasonComments:e.rejectReasonComments})}},oM={title:`Request Document Edit`,okText:`Submit Request`,cancelText:`Cancel`,width:480,successMessage:`Edit request submitted successfully.`,fields:[{name:`reason`,label:`Reason for Edit`,type:`textarea`,required:!0,rows:4,maxLength:1e3,placeholder:`Enter the reason for requesting changes to this document`}]},sM=`documents`,cM={submit:async(e,t)=>{let n=await ke({module:t.moduleName||sM,documentIds:t.selectedIds??[],reason:String(e.reason??``).trim()}),r=Number(n?.failedCount)||0;if(r>0){let e=Number(n?.createdCount)||0,t=n?.failures?.find(e=>e?.error)?.error;s.message.warning(`${e} of ${e+r} edit requests raised${t?` — ${t}`:``}.`)}}},lM={title:`Reject Edit Request`,okText:`Reject`,cancelText:`Cancel`,okButtonDanger:!0,width:480,successMessage:`Edit request rejected successfully.`,fields:[{name:`rejectionReason`,label:`Rejection Reason`,type:`textarea`,required:!0,rows:4,maxLength:1e3,placeholder:`Explain why this edit request is being rejected`}]},uM={submit:async(e,t)=>{let n=t.selectedIds??[],r=await Ae({ids:n,rejectionReason:String(e.rejectionReason??``).trim()}),i=Number(r?.rejectedCount)||0,a=Number(r?.failedCount)||0;if(i===0)throw Error(n.length>1?`None of the selected requests could be rejected — they are no longer pending or are outside your review scope.`:`This request could not be rejected — it is no longer pending or is outside your review scope.`);a>0&&s.message.warning(`${i} of ${i+a} edit requests rejected — the rest are no longer pending or are outside your review scope.`)}},dM={delete:Uk,"quick-submit":vA,"add-notes":yA,"tag-to-job":TA,"change-status":$A,"remove-from-shortlist":nj,"add-to-groups":ij,"self-assign":cj,"others-assign":dj,"sticky-notes":pj,"move-to-onboarding":hj,"approve-rate":xj,"manager-approve":Kj,"manager-reapprove":tM,reject:iM,"document-edit-request":oM,"document-edit-reject":lM},fM={delete:Wk,"quick-submit":_A,"add-notes":SA,"tag-to-job":QA,"change-status":tj,"remove-from-shortlist":rj,"add-to-groups":aj,"self-assign":lj,"others-assign":fj,"sticky-notes":mj,"move-to-onboarding":gj,"approve-rate":Sj,"manager-approve":qj,"manager-reapprove":nM,reject:aM,"document-edit-request":cM,"document-edit-reject":uM};function pM(e){let t=e?.data??e;return Array.isArray(t)?t:t?.data??t?.rows??t?.records??t?.items??t?.list??[]}function mM(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&t!==``)return t}return``}function hM(e){let t=String(mM(e,`isDeleted`,`deleted`)).toLowerCase(),n=String(mM(e,`assignmentStatus`,`status`)).toLowerCase();return t!==`true`&&t!==`1`&&![`removed`,`inactive`,`deleted`].includes(n)}function gM(e){let t=mM(e,`candidateName`,`candidate_name`,`fullName`,`name`);return t?String(t):[mM(e,`firstName`,`first_name`),mM(e,`lastName`,`last_name`)].filter(Boolean).join(` `)||`Unnamed candidate`}function _M(e){return String(mM(e,`candidateId`,`candidate_id`,`candidate._id`,`candidate.id`))}function vM(e){return String(mM(e,`workforceEngagementId`,`engagementId`,`_id`,`id`))}function yM(e){return String(mM(e,`batchName`,`name`,`title`,`batch_name`))}function bM({open:e=!0,context:r={},onClose:i}){let[a,c]=(0,o.useState)([]),[u,d]=(0,o.useState)([]),[f,p]=(0,o.useState)(``),[m,h]=(0,o.useState)(!0),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(``),[b,x]=(0,o.useState)(new Map),S=String(r.selectedIds?.[0]??r.selectedRecords?.[0]?._id??r.selectedRecords?.[0]?.id??r.batchId??``);(0,o.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve().then(()=>(t||h(!0),Promise.all([n.Sn(`onboarding`,200,0),n.Sn(`batchCandidates`,1e3,0).catch(()=>[])]))).then(([e,n])=>{t||(c(pM(e)),x(new Map(pM(n).filter(hM).map(e=>[String(mM(e,`candidateId`,`candidate_id`)),e]).filter(([e])=>e))))}).catch(e=>{t||y(e.message||`Unable to load onboarding candidates`)}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e]);let C=(0,o.useMemo)(()=>{let e=f.trim().toLowerCase();return e?a.filter(t=>[gM(t),mM(t,`email`,`candidateEmail`,`candidate_email`),mM(t,`status`,`onboardingStatus`,`onboarding_status`)].some(t=>String(t).toLowerCase().includes(e))):a},[a,f]);async function w(){if(!S){y(`Select a batch before adding candidates`);return}let e=a.filter(e=>u.includes(vM(e)));if(!e.length)return;let o=e.map(e=>({record:e,assignment:b.get(_M(e))})).filter(e=>e.assignment);if(o.length){let e=o.map(({record:e})=>gM(e)).join(`, `);y(`${e} ${o.length===1?`is`:`are`} already added to a batch. Each candidate can be added to only one batch.`);return}_(!0),y(``);try{let{userId:a}=t.s(),o=yM(r.selectedRecords?.[0])||yM(r);await Promise.all(e.map(e=>n.er(`batchCandidates`,{schemaVersion:1,batchId:S,batchName:o,candidateId:_M(e),workforceEngagementId:vM(e),source:`ONBOARDING`,assignmentStatus:`ASSIGNED`,assignedAt:new Date().toISOString(),assignedBy:a??0,isDeleted:!1}))),s.message.success(`${e.length} candidate${e.length===1?``:`s`} added to the batch`),i?.({refresh:!0})}catch(e){y(e.message||`Unable to add candidates to the batch`)}finally{_(!1)}}return(0,l.jsxs)(s.Modal,{open:e,title:`Add Candidate to Batch`,okText:`Add`,onOk:w,onCancel:()=>i?.(),okButtonProps:{disabled:u.length===0||!S,loading:g},cancelButtonProps:{disabled:g},closable:!g,maskClosable:!1,width:760,centered:!0,children:[v&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:v,style:{marginBottom:12}}),(0,l.jsx)(s.Input.Search,{allowClear:!0,placeholder:`Search onboarding candidates`,value:f,onChange:e=>p(e.target.value),style:{marginBottom:12}}),(0,l.jsx)(s.Table,{rowKey:e=>vM(e),columns:[{title:`Candidate`,key:`candidate`,render:(e,t)=>gM(t)},{title:`Email`,key:`email`,render:(e,t)=>mM(t,`email`,`candidateEmail`,`candidate_email`)||`—`},{title:`Onboarding status`,key:`status`,render:(e,t)=>mM(t,`status`,`onboardingStatus`,`onboarding_status`)||`—`}],dataSource:C,loading:m,size:`small`,pagination:{pageSize:10,showSizeChanger:!1},rowSelection:{selectedRowKeys:u,onChange:d,getCheckboxProps:e=>{let t=b.get(_M(e));return{disabled:!_M(e)||!vM(e)||!!t,title:t?`Candidate is already added to a batch`:void 0}}},locale:{emptyText:m?`Loading candidates…`:`No onboarding candidates found`}})]})}var xM={text:`input`,string:`input`,textarea:`textarea`,date:`date-picker`,datepicker:`date-picker`,multiselect:`multi-select`,lookup:`search-select`};function SM(e){if(!e)return null;let t=[...e.groups??[]].sort((e,t)=>Number(e.order??0)-Number(t.order??0)).flatMap(e=>[...e.fields??[]].filter(e=>e.show!==0&&e.show!==!1).sort((e,t)=>Number(e.order??0)-Number(t.order??0)).map(e=>({...e,name:e.name??e.field,label:e.label??e.field,type:xM[String(e.type??`text`).toLowerCase()]??e.type??`input`,required:e.required??e.req===1,options:(e.options??[]).map(e=>({label:e.label??e.name??e.value,value:e.value??e.id??e.label}))}))),n=CM(e.successNavigate);return{title:e.label,fields:t,...n?{successNavigate:n}:{}}}function CM(e){let t=String(e??``).trim();return!t||!t.startsWith(`/`)||t.startsWith(`//`)||/^[a-z][a-z0-9+.-]*:/i.test(t)?null:t}function wM(e,t=[]){if(!e||!Array.isArray(t)||!t.length)return e;let n=new Map(t.filter(e=>e?.name).map(e=>[String(e.name),e]));return n.size?{...e,fields:(e.fields??[]).map(r=>{let i=n.get(String(r.name))??n.get(String(r.label))??(n.size===1&&(e.fields??[]).length===1?t[0]:null);if(!i)return r;let{name:a,...o}=i;return{...r,...o}})}:e}function TM({apiMap:e={},extraConfigs:r={}}){let i=(0,o.useMemo)(()=>({...fM,...e}),[e]),a=(0,o.useMemo)(()=>{let e={...dM};return Object.entries(r).forEach(([t,n])=>{e[t]={...e[t]??{},...n}}),e},[r]),{popupKey:s}=(0,d.useParams)(),c=(0,d.useNavigate)(),{state:u={}}=(0,d.useLocation)(),[f,p]=(0,o.useState)({key:``,config:null});(0,o.useEffect)(()=>{let e=!1;if(!s||!u.moduleName)return;let t=`${u.moduleName}:${s}`;return n.Dr(u.moduleName,`popup`,s).then(n=>{e||p({key:t,config:SM(n[0])})}).catch(()=>{e||p({key:t,config:null})}),()=>{e=!0}},[s,u.moduleName]);let m=(0,o.useMemo)(()=>{let e=a[s],t=`${u.moduleName}:${s}`,n=f.key===t?f.config:null;return wM(n?{...e,...n}:e,u.popupAction?.popupFieldOverrides)},[f,a,s,u.moduleName,u.popupAction?.popupFieldOverrides]),h=(0,o.useMemo)(()=>({selectedIds:u.selectedIds??[],selectedRecords:u.selectedRecords??[],moduleName:u.moduleName??``,navigate:c,background:u.background??null,...u.popupContext??{}}),[c,u.selectedIds,u.selectedRecords,u.moduleName,u.popupContext,u.background]),g=(0,o.useMemo)(()=>{let e=u.popupAction;return e?.apiPath?{submit:(n,r)=>{let i=String(e.apiMethod||`POST`).toUpperCase();return t.o(t.x,e.apiPath.startsWith(`/`)?e.apiPath:`/${e.apiPath}`,{method:i,body:[`GET`,`DELETE`].includes(i)?void 0:JSON.stringify({...n,selectedIds:r.selectedIds,selectedRecords:r.selectedRecords,moduleName:r.moduleName})})}}:{}},[u.popupAction]),_=e=>{let t=u.background;if(e?.success&&m?.successNavigate){c(m.successNavigate,{replace:!0,state:{refreshTimestamp:Date.now()}});return}if(e?.success&&t?.pathname){c(`${t.pathname}${t.search??``}`,{replace:!0,state:{...t.state??{},refreshTimestamp:Date.now()}});return}c(-1)};return s===`add-batch-candidate`?(0,l.jsx)(bM,{open:!0,context:h,onClose:_}):(0,l.jsx)(Hk,{open:!0,config:m,context:h,onClose:_,api:{...i[s]??{},...g}})}var EM={title:`Vendor Share`,maxVendorSelect:1e3,defaultTab:`myVendor`,defaultPageSize:10,vendorTabs:[{key:`myVendor`,label:`My Vendors`},{key:`allVendor`,label:`All Vendors`}],vendorColumns:[{title:`Vendor Name`,dataIndex:`vendorName`,key:`vendorName`},{title:`Email`,dataIndex:`vendorEmail`,key:`vendorEmail`},{title:`Location`,dataIndex:`vendorLocation`,key:`vendorLocation`},{title:`Updated On`,dataIndex:`updatedOn`,key:`updatedOn`}]},DM={getVendorList:({jobId:e,limit:t,offset:n,type:r})=>un({jobId:e,limit:t,offset:n,sortBy:`new`,type:r}),getMailDetails:e=>dn(e),submit:({jobId:e,toMail:t,ccMail:n,bccMail:r,subject:i,contents:a})=>pn({jobId:e,toMail:t,ccMail:n,bccMail:r,subject:i,contents:a})},OM=EM.vendorColumns.map(e=>({...e,render:e=>e||`-`}));function kM(){let e=(0,d.useNavigate)(),t=(0,d.useLocation)(),{selectedIds:n=[],selectedRecords:r=[],recipients:i=[],subject:a=``,onSend:u,moduleName:f=``,popupAction:p={}}=t.state??{},m=n[0]??r[0]?._id??r[0]?.id,[h,g]=(0,o.useState)({to:i.join(`, `),cc:``,bcc:``,subject:a,contents:``,showCc:!1,showBcc:!1}),[_,v]=(0,o.useState)(!m),[y,b]=(0,o.useState)(EM.defaultTab),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)([]),[T,E]=(0,o.useState)(0),[D,O]=(0,o.useState)(0),[k,A]=(0,o.useState)(0),[j,M]=(0,o.useState)(1),[N,P]=(0,o.useState)(EM.defaultPageSize),[F,I]=(0,o.useState)(!1),[L,R]=(0,o.useState)([]);(0,o.useEffect)(()=>{if(!m)return;let e=!1;I(!0);let t=x?100:N,n=x?0:(j-1)*N;return DM.getVendorList({jobId:m,limit:t,offset:n,type:y}).then(t=>{if(e)return;let n=t?.data?.vendorList??t?.data??[],r=t?.data?.myVendorCount??0,i=t?.data?.allVendorCount??0;w(Array.isArray(n)?n:[]),E(r),O(i),A(y===`myVendor`?r:i)}).catch(()=>{e||(w([]),A(0))}).finally(()=>{e||I(!1)}),()=>{e=!0}},[m,y,j,N,x]),(0,o.useEffect)(()=>{m&&DM.getMailDetails(m).then(e=>g(t=>({...t,subject:e.subject||t.subject,contents:e.contents||t.contents,to:e.toMail?.length?Array.isArray(e.toMail)?e.toMail.join(`, `):String(e.toMail):t.to,cc:e.ccMail?.length?Array.isArray(e.ccMail)?e.ccMail.join(`, `):String(e.ccMail):t.cc}))).catch(()=>{}).finally(()=>v(!0))},[m]);let z=(0,o.useMemo)(()=>L.map(e=>C.find(t=>t.vendorId===e)?.vendorEmail??``).filter(Boolean),[L,C]),B=(0,o.useMemo)(()=>({...h,bcc:[...new Set([...SD(h.bcc),...z])].join(`, `),showBcc:h.showBcc||z.length>0}),[h,z]);function V(e){let t=new Set(z);g({...e,bcc:SD(e.bcc).filter(e=>!t.has(e)).join(`, `)})}let H=(SD(B.to).length||SD(B.bcc).length)&&CD(B.to)&&CD(B.cc)&&CD(B.bcc)&&B.subject.trim(),ee=e=>e===`myVendor`?T:D;function U(){e(-1)}function te(){H&&DM.submit({jobId:m,toMail:SD(B.to),ccMail:SD(B.cc),bccMail:SD(B.bcc),subject:B.subject,contents:B.contents}).then(t=>{t?.status===!0?(s.message.success(t?.data||`Mail sent successfully.`),typeof u==`function`&&u({...B,message:B.contents,selectedIds:n}),e(-1)):s.message.error(t?.message||t?.data||`Failed to send mail. Please try again.`)}).catch(e=>{s.message.error(e?.message||`Failed to send mail. Please try again.`)})}let ne=(0,o.useMemo)(()=>{if(!x)return C;let e=x.toLowerCase();return C.filter(t=>(t.vendorName??``).toLowerCase().includes(e)||(t.vendorEmail??``).toLowerCase().includes(e)||(t.vendorLocation??``).toLowerCase().includes(e))},[C,x]);return(0,l.jsx)(s.Drawer,{open:!0,placement:`right`,onClose:U,closable:!1,rootClassName:`vendor-share`,width:`95%`,footer:(0,l.jsxs)(`div`,{className:`vendor-share__footer`,children:[(0,l.jsx)(s.Button,{onClick:U,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,disabled:!H,onClick:te,children:`Send`})]}),children:(0,l.jsxs)(`div`,{className:`vendor-share__body`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__left`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__vendor-header`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__vendor-header-row`,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.CloseOutlined,{}),onClick:U,size:`small`,style:{marginRight:8}}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box`,children:(0,l.jsx)(c.TeamOutlined,{})}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:`Vendor List`}),(0,l.jsxs)(`div`,{className:`vendor-share__vendor-search`,children:[(0,l.jsx)(c.SearchOutlined,{className:`vendor-share__search-icon`}),(0,l.jsx)(s.Input,{variant:`borderless`,placeholder:`Search vendor`,value:x,onChange:e=>{S(e.target.value),M(1)},className:`vendor-share__search-input`})]})]}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-tabs`,children:EM.vendorTabs.map(e=>(0,l.jsxs)(`span`,{className:`vendor-share__vendor-tab${y===e.key?` vendor-share__vendor-tab--active`:``}`,onClick:()=>{b(e.key),M(1),R([])},children:[e.label,` (`,ee(e.key),`)`]},e.key))})]}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-table-wrapper`,children:(0,l.jsx)(s.Table,{rowKey:e=>e.vendorId,columns:OM,dataSource:ne,loading:F,pagination:!1,size:`small`,rowSelection:{selectedRowKeys:L,onChange:e=>{e.length>EM.maxVendorSelect||R(e)}},scroll:{y:`calc(100vh - 340px)`}})}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-footer`,children:(0,l.jsx)(Be,{current:j,pageSize:N,total:k,onChange:e=>M(e),onPageSizeChange:e=>P(e)})})]}),(0,l.jsx)(`div`,{className:`vendor-share__right`,children:(0,l.jsx)(ID,{value:B,onChange:V,moduleName:f,defaultTemplateId:p.defaultTemplateId??t.state?.defaultTemplateId??``,ready:_,contextRecords:r,title:`Share`,hint:`Select vendors or add email addresses`,bccHint:`Vendor emails are added automatically`,afterBcc:L.length>0?(0,l.jsxs)(`div`,{className:`vendor-share__selected-count`,children:[L.length,` / `,EM.maxVendorSelect,` Vendors selected`]}):null})})]})})}function AM(e){return e?.data??e}async function jM(e){let n=String(e??``).trim();if(!n)throw Error(`Invoice id is required`);return AM(await t.o(t.x,`/payments/invoice/${encodeURIComponent(n)}`))}function MM(...e){for(let t of e){let e=String(t??``).trim();if(e&&e!==`undefined`&&e!==`null`)return e}return``}async function NM(e,t,n){if(!e)return null;let r=await fetch(e);if(!r.ok)throw Error(`Unable to load invoice attachment`);let i=await r.blob();return new File([i],t||`payment-invoice.html`,{type:n||i.type||`text/html`})}function PM(e){let t=MM(e?.courseName,`your course`),n=MM(e?.invoiceNumber,e?.invoiceFileName,e?.transactionId);return{subject:`Payment invoice - ${t}`,contents:`<p>Hello ${MM(e?.recipientName,`Student`)},</p><p>Please find attached the invoice for your successful payment${n?` (${n})`:``}.</p><p>Thank you.</p>`}}function FM(){let e=(0,d.useNavigate)(),{id:t}=(0,d.useParams)(),[r,i]=(0,o.useState)(null),[a,u]=(0,o.useState)(``),[f,p]=(0,o.useState)(!0),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)({to:``,cc:``,bcc:``,subject:``,contents:``,attachments:[],showCc:!1,showBcc:!1}),b=(0,o.useMemo)(()=>r?.invoiceUrl?[{id:r.invoiceS3Key||r.invoiceUrl,name:r.invoiceFileName||`payment-invoice.html`,url:r.invoiceUrl,type:r.invoiceContentType||`html`}]:[],[r]);(0,o.useEffect)(()=>{let e=!1;async function n(){p(!0);try{let n=await jM(t);if(e)return;i(n);let r=PM(n),a=await NM(n?.invoiceUrl,n?.invoiceFileName,n?.invoiceContentType).catch(()=>null),o={to:MM(n?.recipientEmail),cc:``,bcc:``,subject:r.subject,contents:r.contents,attachments:a?[a]:[],showCc:!1,showBcc:!1},s=(await Xw({module:`payments`,action:`invoice`}).catch(()=>[]))[0];if(!s?._id){y(o);return}u(String(s._id));let c=await Zw(s._id).catch(()=>null);if(!c){y(o);return}y({...o,to:MM(o.to,...(c.toMail??[]).map(e=>FD(e,c.placeholders,n))),cc:(c.ccMail??[]).map(e=>FD(e,c.placeholders,n)).filter(Boolean).join(`, `),bcc:(c.bccMail??[]).map(e=>FD(e,c.placeholders,n)).filter(Boolean).join(`, `),subject:MM(FD(c.subject,c.placeholders,n),o.subject),contents:MM(FD(c.body,c.placeholders,n),o.contents),showCc:!!c.ccMail?.length,showBcc:!!c.bccMail?.length})}catch(t){e||s.message.error(t?.message||`Unable to load invoice`)}finally{e||p(!1)}}return n(),()=>{e=!0}},[t]);let x=SD(v.to).length>0&&CD(v.to)&&CD(v.cc)&&CD(v.bcc)&&v.subject.trim()&&v.contents.trim();async function S(){if(!(!x||g)){_(!0);try{await pn({jobId:``,toMail:SD(v.to),ccMail:SD(v.cc),bccMail:SD(v.bcc),subject:v.subject,contents:v.contents,attachments:v.attachments}),s.message.success(`Invoice mail sent successfully`),h(!1)}catch(e){s.message.error(e?.message||`Failed to send invoice mail`)}finally{_(!1)}}}return(0,l.jsxs)(s.Drawer,{open:!0,placement:`right`,onClose:()=>e(-1),width:`min(1040px, 96vw)`,title:`Payment Invoice`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.MailOutlined,{}),onClick:()=>h(!0),disabled:!r,children:`Send Mail`}),destroyOnClose:!0,children:[(0,l.jsx)(s.Spin,{spinning:f,tip:`Loading invoice...`,children:!f&&!b.length?(0,l.jsx)(s.Alert,{type:`warning`,message:`Invoice document is not available for this payment.`,showIcon:!0}):(0,l.jsx)(`div`,{style:{height:`calc(100vh - 140px)`},children:(0,l.jsx)(n.En,{documents:b,inline:!0})})}),(0,l.jsx)(s.Drawer,{open:m,placement:`right`,onClose:()=>h(!1),width:620,rootClassName:`mail-popup`,destroyOnClose:!0,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>h(!1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:g,disabled:!x,onClick:S,children:`Send`})]}),children:(0,l.jsx)(ID,{value:v,onChange:y,moduleName:`payments`,defaultTemplateId:a,contextRecords:r?[r]:[],title:`Invoice Mail`,hint:`Customer email and invoice attachment are prefilled.`})})]})}var IM={EMAIL:/^[a-zA-Z0-9._%+-]+@[a-zA-Z][a-zA-Z-]*\.[a-zA-Z]{2,}$/,PHONE:/^[0-9]{10}$/,PASSWORD:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,ALPHABETS:/^[A-Za-z ]+$/,ALPHANUMERIC:/^(?!\s)[A-Za-z0-9 ]+$/,NUMBER:/^[0-9]+$/,URL:/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+(com|org|net|in|co|io|gov|edu)(\/[^\s]*)?$/i,CANDIDATE_ID:/^[A-Za-z0-9-]+$/,REMARKS:/^[A-Za-z0-9\s.,'"\-()!?/@#$%&]*$/,DESIGNATION:/^[a-zA-Z0-9\s,.\-&()]{2,100}$/,DOB:/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/\d{4}$/,COMPANY_NAME:/^[A-Za-z0-9\s&.,'()-]+$/,FIRST_NAME:/^[A-Z][a-zA-Z]*$/,FULL_NAME:/^[A-Z][a-zA-Z]*(?: [A-Z][a-zA-Z]*)*$/,NO_SPACES:/^\S+$/,STARTS_WITH_CAPITAL:/^[A-Z].*$/},LM={SINGLE_FILE_COUNT:1,MULTI_FILE_COUNT:5,MAX_FILE_SIZE:2,ALLOWED_FILE_TYPES:[`image/jpeg`,`image/png`,`application/pdf`]},RM={REQUIRED:e=>`Mandatory Field`,INVALID_EMAIL:`Please enter a valid email address.`,INVALID_PHONE:`Phone number must contain exactly 10 digits.`,INVALID_PASSWORD:`Password must contain uppercase, lowercase, number, special character and minimum 8 characters.`,INVALID_ALPHABETS:`Only alphabets and spaces are allowed.`,INVALID_ALPHANUMERIC:`Only letters, numbers and spaces are allowed.`,INVALID_NUMBER:`Only numbers are allowed.`,INVALID_URL:`Please enter a valid URL.`,INVALID_CANDIDATE_ID:e=>`${e} can contain only letters, numbers and hyphens.`,INVALID_REMARKS:`Remarks contain invalid characters.`,INVALID_DESIGNATION:`Designation contains invalid characters.`,INVALID_DOB:`DOB must be in MM/DD/YYYY format.`,INVALID_LINKEDIN:`Please enter a valid LinkedIn URL.`,INVALID_COMPANY_NAME:`Company name contains invalid characters.`,INVALID_FIRST_NAME:`First letter must be capital and spaces are not allowed.`,INVALID_FULL_NAME:`Each word must start with a capital letter.`,NO_SPACES_ALLOWED:`Spaces are not allowed.`,MUST_START_WITH_CAPITAL:`First letter must be capital.`,INVALID_FILE_TYPE:`Only JPG, PNG and PDF files are allowed.`,INVALID_FILE_SIZE:`File upload must be ${LM.MAX_FILE_SIZE} MB below.`,INVALID_FILE_TYPE:`Only JPG, PNG and PDF files are allowed.`,SINGLE_FILE_ONLY:`Only one file can be uploaded.`},zM={FIRST_NAME_MIN:3,FIRST_NAME_MAX:30},BM={REMARKS_MIN:10,REMARKS_MAX:250},VM={removeSpaces:(e=``)=>e.replace(/\s/g,``),capitalizeFirstLetter:(e=``)=>e.charAt(0).toUpperCase()+e.slice(1),capitalizeWords:(e=``)=>e.replace(/\b\w/g,e=>e.toUpperCase()),removeExtraSpaces:(e=``)=>e.replace(/\s+/g,` `).trim(),firstNameFormatter:(e=``)=>e.replace(/\s+/g,` `).trimStart().replace(/\b\w/g,e=>e.toUpperCase()),fullNameFormatter:(e=``)=>e.replace(/\s+/g,` `).trimStart().replace(/\b\w/g,e=>e.toUpperCase()),phoneFormatter:(e=``)=>e.replace(/\D/g,``).slice(0,10),dobFormatter:(e=``)=>{let t=e.replace(/\D/g,``);return t.length<=2?t:t.length<=4?`${t.slice(0,2)}/${t.slice(2)}`:`${t.slice(0,2)}/${t.slice(2,4)}/${t.slice(4,8)}`}},HM={required:(e=`Field`)=>({required:!0,message:RM.REQUIRED(e)}),email:()=>({pattern:IM.EMAIL,message:RM.INVALID_EMAIL}),phone:()=>({pattern:IM.PHONE,message:RM.INVALID_PHONE}),password:()=>({pattern:IM.PASSWORD,message:RM.INVALID_PASSWORD}),alphabets:()=>({pattern:IM.ALPHABETS,message:RM.INVALID_ALPHABETS}),alphanumeric:()=>({pattern:IM.ALPHANUMERIC,message:RM.INVALID_ALPHANUMERIC}),number:()=>({pattern:IM.NUMBER,message:RM.INVALID_NUMBER}),url:()=>({pattern:IM.URL,message:RM.INVALID_URL}),candidateId:(e=`ID`)=>({pattern:IM.CANDIDATE_ID,message:RM.INVALID_CANDIDATE_ID(e)}),remarks:()=>({pattern:IM.REMARKS,message:RM.INVALID_REMARKS,REMARKS_MIN:`Remarks must be at least ${BM.REMARKS_MIN} characters.`,REMARKS_MAX:`Remarks must not exceed ${BM.REMARKS_MAX} characters.`}),designation:()=>({pattern:IM.DESIGNATION,message:RM.INVALID_DESIGNATION}),dob:(e=!0)=>({validator:(t,n)=>{if(!n)return e?Promise.reject(Error(`Date of Birth is required.`)):Promise.resolve();if(!IM.DOB.test(n))return Promise.reject(Error(RM.INVALID_DOB));let r=(0,u.default)(n,`MM/DD/YYYY`,!0);if(!r.isValid())return Promise.reject(Error(RM.INVALID_DOB));let i=(0,u.default)().endOf(`day`);return r.isAfter(i)?Promise.reject(Error(`Date of Birth cannot be a future date.`)):i.diff(r,`year`)<21?Promise.reject(Error(`Age must be at least 21 years.`)):Promise.resolve()}}),linkedin:()=>({pattern:IM.LINKEDIN,message:RM.INVALID_LINKEDIN}),companyName:()=>({pattern:IM.COMPANY_NAME,message:RM.INVALID_COMPANY_NAME}),firstName:()=>({pattern:IM.FIRST_NAME,message:RM.INVALID_FIRST_NAME,FIRST_NAME_MIN:`First Name must be at least ${zM.FIRST_NAME_MIN} characters.`,FIRST_NAME_MAX:`First Name must not exceed ${zM.FIRST_NAME_MAX} characters.`}),firstNameMinLength:()=>({min:zM.FIRST_NAME_MIN,message:RM.FIRST_NAME_MIN}),firstNameMaxLength:()=>({max:zM.FIRST_NAME_MAX,message:RM.FIRST_NAME_MAX}),remarksMinLength:()=>({min:BM.REMARKS_MIN,message:RM.REMARKS_MIN}),remarksMaxLength:()=>({max:BM.REMARKS_MAX,message:RM.REMARKS_MAX}),fullName:()=>({pattern:IM.FULL_NAME,message:RM.INVALID_FULL_NAME}),noSpaces:()=>({pattern:IM.NO_SPACES,message:RM.NO_SPACES_ALLOWED}),startsWithCapital:()=>({pattern:IM.STARTS_WITH_CAPITAL,message:RM.MUST_START_WITH_CAPITAL}),fileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();for(let e of t){let t=e.originFileObj||e;if(!(t.size/1024/1024<=LM.MAX_FILE_SIZE))return s.message.error(RM.INVALID_FILE_SIZE),Promise.reject(Error(RM.INVALID_FILE_SIZE));if(!LM.ALLOWED_FILE_TYPES.includes(t.type))return Promise.reject(Error(RM.INVALID_FILE_TYPE))}return Promise.resolve()}}),singleFileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();if(t.length>LM.SINGLE_FILE_COUNT)return Promise.reject(Error(RM.SINGLE_FILE_ONLY));let n=t[0];return n.size/1024/1024<LM.MAX_FILE_SIZE?LM.ALLOWED_FILE_TYPES.includes(n.type)?Promise.resolve():Promise.reject(Error(RM.INVALID_FILE_TYPE)):Promise.reject(Error(RM.INVALID_FILE_SIZE))}}),multiFileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();if(t.length>LM.MULTI_FILE_COUNT)return Promise.reject(Error(RM.INVALID_FILE_COUNT));for(let e of t){if(!(e.size/1024/1024<LM.MAX_FILE_SIZE))return Promise.reject(Error(RM.INVALID_FILE_SIZE));if(!LM.ALLOWED_FILE_TYPES.includes(e.type))return Promise.reject(Error(RM.INVALID_FILE_TYPE))}return Promise.resolve()}})},UM={beforeUpload:e=>[`image/jpeg`,`image/png`,`application/pdf`].includes(e.type)?e.size/1024/1024<=2?!1:(s.message.error(`File upload must be 2 MB below.`),s.Upload.LIST_IGNORE):(s.message.error(`Only JPG, PNG and PDF files are allowed.`),s.Upload.LIST_IGNORE)},WM=()=>{let[e]=s.Form.useForm();return(0,l.jsx)(`div`,{style:{padding:24},children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,onFinish:e=>{console.log(`Form Values:`,e)},autoComplete:`off`,children:[(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Email`,name:`email`,rules:[HM.required(`Email`),HM.email()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Phone Number`,name:`phone`,rules:[HM.required(`Phone Number`),HM.phone()],validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,onChange:t=>{e.setFieldsValue({phone:VM.phoneFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Password`,name:`password`,rules:[HM.required(`Password`),HM.password()],children:(0,l.jsx)(s.Input.Password,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Full Name`,name:`fullName`,rules:[HM.required(`Full Name`),HM.alphabets(),HM.firstNameMinLength(),HM.firstNameMaxLength()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({fullName:VM.firstNameFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Username`,name:`username`,rules:[HM.required(`Username`),HM.alphanumeric()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({username:VM.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Website URL`,name:`website`,rules:[HM.required(`Website URL`),HM.url()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({website:VM.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`MSP Req ID`,name:`mspreqID`,rules:[HM.required(`MSP Req ID`),HM.candidateId(`MSP Req ID`)],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({mspreqID:VM.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Candidate ID`,name:`candidateId`,rules:[HM.required(`Candidate ID`),HM.candidateId(`Candidate ID`)],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({candidateId:VM.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:24,children:(0,l.jsx)(s.Form.Item,{label:`Remarks`,name:`remarks`,rules:[HM.required(`Remarks`),HM.remarks(),HM.remarksMinLength(),HM.remarksMaxLength()],children:(0,l.jsx)(s.Input.TextArea,{rows:4})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Designation`,name:`designation`,rules:[HM.required(`Designation`),HM.designation()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Date of Birth`,name:`dob`,rules:[HM.dob()],children:(0,l.jsx)(s.Input,{placeholder:`MM/DD/YYYY`,maxLength:10,onChange:t=>{e.setFieldsValue({dob:VM.dobFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Company Name`,name:`companyName`,rules:[HM.required(`Company Name`),HM.companyName()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{name:`contractType`,label:`Contract Type`,children:(0,l.jsxs)(s.Select,{showSearch:!0,allowClear:!0,filterOption:(e,t)=>(t?.label??``).toLowerCase().includes(e.toLowerCase()),children:[(0,l.jsx)(s.Select.Option,{value:`C2C`,label:`C2C`,children:`C2C`}),(0,l.jsx)(s.Select.Option,{value:`W2-Contract`,label:`W2-Contract`,children:`W2-Contract`}),(0,l.jsx)(s.Select.Option,{value:`W2-Fulltime`,label:`W2-Fulltime`,children:`W2-Fulltime`}),(0,l.jsx)(s.Select.Option,{value:`1099`,label:`1099`,children:`1099`})]})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{name:`candidateProposedRateCurrency`,label:`Currency`,children:(0,l.jsxs)(s.Select,{showSearch:!0,allowClear:!0,children:[(0,l.jsx)(s.Select.Option,{value:`$`,children:`$`}),(0,l.jsx)(s.Select.Option,{value:`₹`,children:`₹`}),(0,l.jsx)(s.Select.Option,{value:`€`,children:`€`}),(0,l.jsx)(s.Select.Option,{value:`zł`,children:`zł`}),(0,l.jsx)(s.Select.Option,{value:`£`,children:`£`}),(0,l.jsx)(s.Select.Option,{value:`kr`,children:`kr`}),(0,l.jsx)(s.Select.Option,{value:`Fr`,children:`Fr`}),(0,l.jsx)(s.Select.Option,{value:`kr`,children:`kr`})]})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Resume new`,name:`resume`,children:(0,l.jsx)(s.Upload,{beforeUpload:UM.beforeUpload,maxCount:1,children:(0,l.jsx)(s.Button,{children:`Upload Resume`})})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Documents`,name:`documents`,valuePropName:`fileList`,getValueFromEvent:e=>e?.fileList,rules:[HM.multiFileUpload()],children:(0,l.jsx)(s.Upload,{multiple:!0,beforeUpload:UM.beforeUpload,children:(0,l.jsx)(s.Button,{children:`Upload Documents`})})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Upload File`,name:`file`,valuePropName:`fileList`,getValueFromEvent:e=>e?.fileList,rules:[HM.fileUpload()],children:(0,l.jsx)(s.Upload,{beforeUpload:UM.beforeUpload,maxCount:1,children:(0,l.jsx)(s.Button,{children:`Upload`})})})})]}),(0,l.jsx)(s.Row,{children:(0,l.jsx)(s.Form.List,{name:`users`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(l.Fragment,{children:[e.map(({key:e,name:t,...r})=>(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{required:!0,...r,rules:[{required:!0,message:`First name is requried`}],name:[t,`first`],children:(0,l.jsx)(s.Input,{placeholder:`First Name`})})}),(0,l.jsx)(s.Col,{span:11,children:(0,l.jsx)(s.Form.Item,{...r,required:!0,name:[t,`last`],children:(0,l.jsx)(s.Input,{placeholder:`Last Name`})})}),(0,l.jsx)(s.Col,{span:1,children:(0,l.jsx)(c.MinusCircleOutlined,{onClick:()=>n(t)})})]})),(0,l.jsx)(s.Form.Item,{children:(0,l.jsx)(s.Button,{type:`dashed`,onClick:()=>t(),block:!0,icon:(0,l.jsx)(c.PlusOutlined,{}),children:`Add field`})})]})})}),(0,l.jsxs)(s.Form.Item,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,children:`Submit`}),(0,l.jsx)(s.Button,{style:{marginLeft:10},onClick:()=>e.resetFields(),children:`Reset`})]})]})})};function GM(e){return(0,l.jsx)(Pb,{children:(0,l.jsx)(_D,{...e})})}var{Text:KM}=s.Typography,qM=[{label:`Total Jobs`,value:1697,icon:`fileText`},{label:`Active Jobs`,value:1685,icon:`checkCircle`},{label:`My Jobs`,value:600,icon:`user`}],JM={fileText:(0,l.jsx)(c.FileTextOutlined,{}),checkCircle:(0,l.jsx)(c.CheckCircleOutlined,{}),user:(0,l.jsx)(c.UserOutlined,{}),filter:(0,l.jsx)(c.FilterOutlined,{})};function YM({stats:e=qM}){return(0,l.jsx)(s.Card,{children:(0,l.jsx)(s.Row,{gutter:[12,12],children:e.map(e=>(0,l.jsx)(s.Col,{xs:24,sm:24,md:8,lg:8,xl:8,children:(0,l.jsxs)(s.Card,{className:`stats-inner-card`,children:[(0,l.jsxs)(s.Space,{align:`center`,children:[JM[e.icon]??JM.fileText,(0,l.jsx)(KM,{children:e.label})]}),(0,l.jsx)(s.Statistic,{value:e.value})]})},e.label))})})}var{Text:XM}=s.Typography;function ZM(e){return e?.USER_NAME??e?.user_name??e?.username??e?.name??e?.full_name??e?.fullName??e?.email??`User ${e?.USER_ID??e?.user_id??`?`}`}function QM(e){return{...e,key:e.USER_ID??e.user_id??e.userId??e.id??e._id,_name:ZM(e),_email:e.email??e.EMAIL??e.user_email??``,_role:e.role_name??e.roleName??e.ROLE_NAME??``,_rawRef:e}}function $M(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(1),[p,m]=(0,o.useState)(10),[h,g]=(0,o.useState)(``),_=(0,o.useCallback)(async({offset:e,limit:r,searchQuery:a}={})=>{u(!0);try{let o=await n.yr({offset:e,limit:r,searchQuery:a??``}),s=(o.users??[]).map(QM);t(s),i(o.total??s.length)}catch{s.message.error(`Failed to load users`)}finally{u(!1)}},[]);return(0,o.useEffect)(()=>{queueMicrotask(()=>{_({offset:(d-1)*p,limit:p,searchQuery:h})})},[_,d,p,h]),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.TeamOutlined,{}),title:`Users`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Users`,dataSource:e,fields:[{label:`Name`,value:`_name`,width:220,render:(e,t)=>(0,l.jsxs)(`div`,{children:[(0,l.jsx)(XM,{strong:!0,style:{fontSize:13},children:e}),t._email&&(0,l.jsx)(`div`,{style:{fontSize:11,color:`var(--color-text-muted)`},children:t._email})]})},{label:`Role`,value:`_role`,width:180}],loading:a,total:r,current:d,pageSize:p,onPageChange:e=>f(e),onPageSizeChange:e=>{m(e),f(1)},onSearch:e=>{g(e),f(1)}})})}var{Text:eN}=s.Typography,tN=[{key:`job`,label:`Jobs`},{key:`candidate`,label:`Candidates`},{key:`submissions`,label:`Submissions`}],nN=[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`}];function rN({field:e,index:t,onToggle:n,onReorder:r}){let i=(0,o.useRef)(null),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(!1);function p(e){i.current=t,e.dataTransfer.effectAllowed=`move`,f(!0)}function m(){f(!1),u(!1)}function h(e){e.preventDefault(),u(!0)}function g(){u(!1)}function _(e){e.preventDefault(),u(!1),i.current!==null&&i.current!==t&&r(i.current,t),i.current=null}return(0,l.jsxs)(`div`,{draggable:!0,onDragStart:p,onDragEnd:m,onDragOver:h,onDragLeave:g,onDrop:_,className:`uss-field-row with-edit${a?` drag-over`:``}${d?` dragging`:``}`,children:[(0,l.jsx)(`span`,{className:`uss-drag-handle`,children:(0,l.jsx)(c.HolderOutlined,{})}),(0,l.jsxs)(`span`,{className:`uss-field-name`,children:[e.fieldName,(0,l.jsx)(`span`,{className:`uss-field-key`,children:e.fieldKey})]}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:e.isVisible,onChange:e=>n(t,`isVisible`,e)})}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:!!e.isEditable,onChange:e=>n(t,`isEditable`,e)})}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:!!e.ismandatory,onChange:e=>n(t,`ismandatory`,e)})})]})}function iN({team:e,configType:t}){let[r,i]=(0,o.useState)({}),[a,c]=(0,o.useState)(!1),[u,d]=(0,o.useState)({}),[f,p]=(0,o.useState)(`job`);(0,o.useEffect)(()=>{e&&(c(!0),n.Qr(e,t).then(i).catch(()=>s.message.error(`Failed to load field config`)).finally(()=>c(!1)))},[e,t]);let m=r[f]??[];function h(e,t){i(n=>({...n,[e]:typeof t==`function`?t(n[e]??[]):t}))}function g(e,t,n){h(f,r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))}function _(e,t){h(f,n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r.map((e,t)=>({...e,order:t}))})}async function v(){let r=f;d(e=>({...e,[r]:!0}));try{await n.Ti(e,r,m,t),s.message.success(`Saved`)}catch{s.message.error(`Save failed`)}finally{d(e=>({...e,[r]:!1}))}}return(0,l.jsxs)(s.Spin,{spinning:a,children:[(0,l.jsx)(s.Tabs,{size:`small`,activeKey:f,onChange:p,items:tN.map(e=>({key:e.key,label:e.label}))}),(0,l.jsxs)(`div`,{className:`uss-field-header with-edit`,children:[(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{children:`Field`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Visible`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Editable`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Mandatory`})]}),(0,l.jsxs)(`div`,{className:`uss-field-list`,children:[m.length===0&&!a&&(0,l.jsx)(`div`,{className:`uss-empty`,children:`No fields found.`}),m.map((e,t)=>(0,l.jsx)(rN,{field:e,index:t,onToggle:g,onReorder:_},e.fieldKey??t))]}),(0,l.jsx)(`div`,{className:`uss-modal-footer`,children:(0,l.jsxs)(s.Button,{type:`primary`,size:`small`,loading:u[f],onClick:v,children:[`Save `,tN.find(e=>e.key===f)?.label]})})]})}function aN(){let[e,t]=(0,o.useState)(null),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(`listView`),[p,m]=(0,o.useState)([]),[h,g]=(0,o.useState)(0),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(``),[x,S]=(0,o.useState)(!1),C=(0,o.useCallback)(async()=>{v(!0);try{let e=await n.vr();m(e.teams),g(e.total)}catch{s.message.error(`Failed to load teams`)}finally{v(!1)}},[]);(0,o.useEffect)(()=>{C()},[C]);function w(e){t(e),f(`listView`),i(!0)}function T(e){t(e),b(e.teamName??``),u(!0)}async function E(){if(!y.trim()){s.message.warning(`Team name is required`);return}S(!0);try{await n.wi(e,{teamName:y.trim(),managerId:e.managerId,memberIds:e.memberIds}),s.message.success(`Team updated`),u(!1),C()}catch{s.message.error(`Failed to update team`)}finally{S(!1)}}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.TeamOutlined,{}),title:`Teams`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Teams`,dataSource:p,fields:[{label:`Team Name`,value:`teamName`,width:200},{label:`Manager`,value:`manager`,width:200},{label:`Members`,value:`memberCount`,width:90,sorter:!1},{label:`Actions`,value:`_actions`,width:160,sorter:!1,render:(e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:4},children:[(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>T(t),children:`Edit`}),(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>w(t),children:`Configure`})]})}],loading:_,total:h})}),(0,l.jsx)(s.Modal,{open:a,onCancel:()=>u(!1),title:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.TeamOutlined,{style:{color:`var(--color-brand)`,marginRight:6}}),`Edit Team`]}),width:420,footer:null,destroyOnClose:!0,children:(0,l.jsxs)(`div`,{className:`uss-edit-team-body`,style:{paddingTop:12},children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`uss-edit-team-label`,children:`Team Name`}),(0,l.jsx)(s.Input,{value:y,onChange:e=>b(e.target.value),onPressEnter:E,placeholder:`Enter team name`})]}),(0,l.jsxs)(`div`,{className:`uss-modal-footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>u(!1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:x,onClick:E,children:`Save`})]})]})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,open:r,onCancel:()=>i(!1),title:(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.TeamOutlined,{style:{color:`var(--color-brand)`}}),(0,l.jsxs)(`span`,{children:[`Configure: `,e?.teamName]})]}),width:720,footer:null,destroyOnClose:!0,children:[(0,l.jsx)(`div`,{style:{marginBottom:12},children:(0,l.jsx)(`div`,{className:`uss-config-toggle`,children:nN.map(e=>(0,l.jsx)(`button`,{className:`uss-config-btn${d===e.key?` active`:``}`,onClick:()=>f(e.key),children:e.label},e.key))})}),e&&(0,l.jsx)(iN,{team:e,configType:d},`${e?.teamId}-${d}`)]})]})}var oN=[`view`,`add`,`edit`,`delete`],sN={view:`View`,add:`Add`,edit:`Edit`,delete:`Delete`,sourcing:`Sourcing`,assign:`Assign`,share:`Share`,change_status:`Status`,my_jobs:`My Jobs`,all_jobs:`All Jobs`,po_msa:`PO MSA`,reApprove:`ReApprove`,sendApprove:`Send Approve`};function cN(e){return sN[e]??e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function lN(e){let t=oN.filter(t=>e.includes(t)),n=e.filter(e=>!oN.includes(e)).sort();return[...t,...n]}function uN(e){let t=new Set;return Object.values(e).forEach(({permissions:e})=>Object.keys(e??{}).forEach(e=>t.add(e))),lN([...t])}function dN(e){let t=0,n=0;return Object.entries(e).forEach(([e,{permissions:r}])=>{Object.entries(r??{}).forEach(([r,{value:i}])=>{Kx(e,r)&&(n++,i===`1`&&t++)})}),{enabled:t,total:n}}function fN(e={}){if(!e||typeof e!=`object`)return e;let t=Object.keys(e).find(e=>String(e).trim().toLowerCase()===`onboarding`);if(!t)return e;let n=e[t]??{},r={...n.permissions??{}};for(let e of[`sendApprove`,`reApprove`])Object.keys(r).some(t=>t.toLowerCase()===e.toLowerCase())||(r[e]={id:0,value:`0`});return{...e,[t]:{...n,permissions:r}}}function pN({value:e,onSave:t,className:n}){let[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(e);(0,o.useEffect)(()=>{s(e)},[e]);function u(){i(!1);let n=a.trim();n&&n!==e?t(n):s(e)}return r?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-inline-input${n?` ${n}`:``}`,value:a,style:{width:Math.max(48,a.length*8)},onChange:e=>s(e.target.value),onBlur:u,onKeyDown:t=>{t.key===`Enter`&&u(),t.key===`Escape`&&(i(!1),s(e)),t.stopPropagation()},onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`span`,{className:`perm-editable-name${n?` ${n}`:``}`,onDoubleClick:e=>{e.stopPropagation(),i(!0)},children:[e,(0,l.jsx)(c.EditOutlined,{className:`perm-name-edit-icon`})]})}function mN({entry:e,label:t,onToggle:n,onLabelSave:r}){let[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(t),f=e?.value===`1`,p=!!e;(0,o.useEffect)(()=>{d(t)},[t]);function m(){a(!1);let e=u.trim();e&&e!==t?r(e):d(t)}return(0,l.jsx)(s.Tooltip,{title:p?f?`Click to disable`:`Click to enable`:`Not applicable for this module`,children:(0,l.jsxs)(`div`,{className:`perm-action-pill${f?` on`:``}${p?``:` na`}`,onClick:()=>{!i&&p&&n()},children:[(0,l.jsx)(`span`,{className:`perm-action-pill-dot${f?` on`:``}`}),i?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-pill-input`,value:u,style:{width:Math.max(36,u.length*7)},onChange:e=>d(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&(a(!1),d(t)),e.stopPropagation()},onClick:e=>e.stopPropagation()}):(0,l.jsx)(`span`,{className:`perm-action-pill-label`,onDoubleClick:e=>{e.stopPropagation(),a(!0)},children:t}),f&&!i&&(0,l.jsx)(c.CheckOutlined,{className:`perm-action-pill-check`})]})})}function hN({menuName:e,menuData:t,permKeys:n,onChange:r,displayName:i,actionLabels:a,onModuleLabelSave:o,onActionLabelSave:s}){let c=t?.permissions??{},u=n.filter(t=>Kx(e,t)),d=u.filter(e=>c[e]?.value===`1`).length,f=u.filter(e=>c[e]).length,p=f>0&&d===f;return(0,l.jsxs)(`div`,{className:`perm-module-card${p?` all-on`:d>0&&!p?` some-on`:``}`,children:[(0,l.jsxs)(`div`,{className:`perm-module-card-header`,children:[(0,l.jsx)(pN,{value:i,onSave:t=>o(e,t),className:`perm-module-card-name`}),f>0&&(0,l.jsxs)(`span`,{className:`perm-module-card-badge${d>0?` active`:``}`,children:[d,`/`,f]})]}),(0,l.jsx)(`div`,{className:`perm-module-card-body`,children:u.map(t=>(0,l.jsx)(mN,{entry:c[t],label:a[t]??cN(t),onToggle:()=>r(e,t),onLabelSave:e=>s(t,e)},t))})]})}function gN({role:e,moduleLabels:t={},actionLabels:r={},onModuleLabelSave:i=()=>{},onActionLabelSave:a=()=>{}}){let[u,d]=(0,o.useState)({}),[f,p]=(0,o.useState)({}),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),b=n.qr(e);(0,o.useEffect)(()=>{b&&(h(!0),y(!1),n.Xr(b).then(e=>{let t=fN(e);d(t),p(t)}).catch(()=>s.message.error(`Failed to load permissions`)).finally(()=>h(!1)))},[b]);function x(e,t){y(!0),p(n=>{let r=n[e]??{menuId:u[e]?.menuId??0,permissions:{}},i=r.permissions?.[t]??{id:0,value:`0`};return{...n,[e]:{...r,permissions:{...r.permissions,[t]:{...i,value:i.value===`1`?`0`:`1`}}}}})}async function S(){_(!0);try{await n.Si(b,f),d(f),y(!1),s.message.success(`Permissions saved`)}catch(e){s.message.error(e?.message||`Save failed`)}finally{_(!1)}}let C=(0,o.useMemo)(()=>Object.keys(f).sort(),[f]),w=(0,o.useMemo)(()=>uN(f),[f]),{enabled:T,total:E}=(0,o.useMemo)(()=>dN(f),[f]);return(0,l.jsxs)(s.Spin,{spinning:m,children:[(0,l.jsxs)(`div`,{className:`perm-panel-header`,children:[(0,l.jsxs)(`div`,{className:`perm-panel-title`,children:[(0,l.jsx)(c.LockOutlined,{style:{color:`var(--color-brand)`,marginRight:6}}),(0,l.jsx)(`span`,{children:e?.roleName}),!m&&E>0&&(0,l.jsxs)(s.Tag,{color:`blue`,style:{marginLeft:8,fontSize:11},children:[T,`/`,E,` enabled`]})]}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.UnlockOutlined,{}),loading:g,disabled:!v,onClick:S,children:`Save Changes`})]}),(0,l.jsxs)(`div`,{className:`perm-hint`,children:[(0,l.jsx)(c.InfoCircleOutlined,{className:`perm-hint-icon`}),(0,l.jsxs)(`span`,{children:[`Click a pill to toggle. `,(0,l.jsx)(`strong`,{children:`Double-click`}),` a module name or action label to rename it — labels are saved locally.`]})]}),C.length===0&&!m?(0,l.jsx)(`div`,{className:`perm-empty`,children:`No permission entries found for this role.`}):(0,l.jsx)(`div`,{className:`perm-cards-grid`,children:C.map(e=>(0,l.jsx)(hN,{menuName:e,menuData:f[e],permKeys:w,onChange:x,displayName:t[e]??e,actionLabels:r,onModuleLabelSave:i,onActionLabelSave:a},e))})]})}var{Text:_N}=s.Typography,vN=[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`},{key:`permissions`,label:`Permissions`}];function yN(e){return String(e||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim()}function bN(e){return String(e||``).trim().toLowerCase()}function xN(e){return e?.key||e?.collectionName||e?.value||``}function SN(e=[],t=[]){let n=[],r=new Set,i=new Set,a=new Set;return e.forEach(e=>{let t=xN(e);if(!t)return;let o=bN(e.key||t),s=bN(e.collectionName);e.seeded&&(i.add(o),s&&i.add(s)),s&&a.add(s),r.add(t),n.push({label:e.label||yN(t),value:t,disabled:!!e.seeded})}),t.forEach(e=>{let t=String(e||``).trim();if(!t||r.has(t))return;let o=bN(t);a.has(o)||i.has(o)||(r.add(t),n.push({label:yN(t),value:t,disabled:!1}))}),n}function CN(){let[e,t]=(0,o.useState)(null),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(`listView`),[d,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(0),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)([]),[x,S]=(0,o.useState)(!1),[C,w]=(0,o.useState)(!1),T=(0,o.useMemo)(()=>_.filter(e=>!e.disabled),[_]),E=!x&&T.length===0,D=(0,o.useCallback)(async()=>{g(!0);try{let e=await n._r();f(e.roles),m(e.total)}catch{s.message.error(`Failed to load roles`)}finally{g(!1)}},[]),O=(0,o.useCallback)(async()=>{S(!0);try{let[e,t]=await Promise.all([n.Ar(),n.xr()]),r=SN(e.modules,t),i=new Set(r.filter(e=>!e.disabled).map(e=>e.value));v(r),b(e=>e.filter(e=>i.has(e)))}catch{s.message.error(`Failed to load seed status`)}finally{S(!1)}},[]);(0,o.useEffect)(()=>{D()},[D]),(0,o.useEffect)(()=>{O()},[O]);async function k(){if(y.length===0){s.message.warning(E?`All modules already seeded.`:`Select at least one module to seed.`);return}w(!0);try{await n.pi(y),s.message.success(`Role field config seeded`),b([]),await O()}catch(e){s.message.error(e?.message||`Seed failed`)}finally{w(!1)}}function A(e,n=`listView`){t(e),u(n),i(!0)}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Field Config Seed`,style:{marginBottom:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,flexWrap:`wrap`},children:[(0,l.jsx)(`div`,{style:{minWidth:320,flex:1},children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,showSearch:!0,value:y,options:_,placeholder:E?`All modules already seeded`:`Select modules or collections to seed`,disabled:x||C||E,loading:x,onChange:b,style:{width:`100%`}})}),(0,l.jsx)(s.Button,{type:`primary`,loading:C,disabled:x||y.length===0,onClick:k,children:`Seed Field Config`})]}),(0,l.jsx)(_N,{type:`secondary`,style:{display:`block`,marginTop:8,fontSize:12},children:E?`Seed is disabled because all configured modules already have role field config data.`:`Already seeded modules are disabled. New modules or collections can still be seeded.`})]}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.SafetyOutlined,{}),title:`Roles`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Roles`,dataSource:d,fields:[{label:`Role Name`,value:`roleName`,width:200},{label:`Description`,value:`description`,width:240},{label:`Users`,value:`userCount`,width:70,sorter:!1},{label:`Actions`,value:`_configure`,width:200,sorter:!1,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>A(t),children:`Configure`}),(0,l.jsx)(s.Button,{size:`small`,type:`link`,icon:(0,l.jsx)(c.LockOutlined,{}),onClick:()=>A(t,`permissions`),children:`Permissions`})]})}],loading:h,total:p})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,open:r,onCancel:()=>i(!1),title:(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.SafetyOutlined,{style:{color:`var(--color-brand)`}}),(0,l.jsxs)(`span`,{children:[`Configure: `,e?.roleName]})]}),width:720,footer:null,destroyOnClose:!0,children:[(0,l.jsx)(`div`,{style:{marginBottom:12},children:(0,l.jsx)(`div`,{className:`uss-config-toggle`,children:vN.map(e=>(0,l.jsx)(`button`,{className:`uss-config-btn${a===e.key?` active`:``}`,onClick:()=>u(e.key),children:e.label},e.key))})}),e&&(a===`permissions`?(0,l.jsx)(gN,{role:e},e?.roleId):(0,l.jsx)(lS,{role:e,configType:a},`${e?.roleId}-${a}`))]})]})}var wN=`perm-module-labels`,TN=`perm-action-labels`;function EN(e){try{return JSON.parse(localStorage.getItem(e)??`{}`)}catch{return{}}}function DN(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}function ON({label:e,onSave:t,onDelete:n,loading:r}){let[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(e);function f(){a(!1);let n=u.trim();n&&n!==e?t(n):d(e)}return(0,l.jsxs)(`div`,{className:`perm-manage-row`,children:[i?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-inline-input`,value:u,style:{flex:1,minWidth:0},onChange:e=>d(e.target.value),onBlur:f,onKeyDown:t=>{t.key===`Enter`&&f(),t.key===`Escape`&&(a(!1),d(e))}}):(0,l.jsx)(`span`,{className:`perm-manage-row-label`,children:e}),(0,l.jsxs)(`div`,{className:`perm-manage-row-actions`,children:[(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{d(e),a(!0)},loading:r}),(0,l.jsx)(s.Popconfirm,{title:`Delete this item?`,onConfirm:n,okText:`Delete`,cancelText:`Cancel`,okType:`danger`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{}),danger:!0})})]})]})}function kN({open:e,onClose:t}){let[r,i]=(0,o.useState)(`modules`),[a,u]=(0,o.useState)([]),[d,f]=(0,o.useState)(!1),[p,m]=(0,o.useState)(``),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)(``),[T,E]=(0,o.useState)(!1);(0,o.useEffect)(()=>{e&&(D(),O())},[e]);async function D(){f(!0);try{u(await n.Lr())}catch{s.message.error(`Failed to load modules`)}finally{f(!1)}}async function O(){b(!0);try{v(await n.Ir())}catch{s.message.error(`Failed to load actions`)}finally{b(!1)}}async function k(){let e=p.trim();if(!e){s.message.warning(`Enter a module name`);return}g(!0);try{let t=await n.Qn({menuName:e});u(e=>[...e,t]),m(``),s.message.success(`Module added`)}catch{s.message.error(`Failed to add module`)}finally{g(!1)}}async function A(e,t){try{await n.vi(e,{menuName:t}),u(n=>n.map(n=>n.MENUID===e?{...n,MENUNAME:t}:n))}catch{s.message.error(`Failed to update module`)}}async function j(e){try{await n.sr(e),u(t=>t.filter(t=>t.MENUID!==e)),s.message.success(`Module deleted`)}catch{s.message.error(`Failed to delete module`)}}async function M(){let e=x.trim(),t=C.trim().toLowerCase().replace(/\s+/g,`_`);if(!e||!t){s.message.warning(`Enter both name and key`);return}E(!0);try{let r=await n.Zn({permissionName:e,permissionKey:t});v(e=>[...e,r]),S(``),w(``),s.message.success(`Action added`)}catch(e){s.message.error(e?.message?.includes(`409`)||e?.status===409?`Permission key already exists`:`Failed to add action`)}finally{E(!1)}}async function N(e,t){try{await n._i(e,{permissionName:t}),v(n=>n.map(n=>n.permissionId===e?{...n,permissionName:t}:n))}catch{s.message.error(`Failed to update action`)}}async function P(e){try{await n.or(e),v(t=>t.filter(t=>t.permissionId!==e)),s.message.success(`Action deleted`)}catch{s.message.error(`Failed to delete action`)}}let F=[{key:`modules`,label:`Modules`,children:(0,l.jsxs)(s.Spin,{spinning:d,children:[(0,l.jsxs)(`div`,{className:`perm-manage-add-row`,children:[(0,l.jsx)(s.Input,{placeholder:`Module name`,value:p,onChange:e=>m(e.target.value),onPressEnter:k,style:{flex:1},size:`small`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),loading:h,onClick:k,children:`Add`})]}),(0,l.jsxs)(`div`,{className:`perm-manage-list`,children:[a.length===0&&!d&&(0,l.jsx)(`div`,{className:`perm-empty`,style:{paddingTop:24},children:`No modules found`}),a.map(e=>(0,l.jsx)(ON,{label:e.MENUNAME,onSave:t=>A(e.MENUID,t),onDelete:()=>j(e.MENUID)},e.MENUID))]})]})},{key:`actions`,label:`Actions`,children:(0,l.jsxs)(s.Spin,{spinning:y,children:[(0,l.jsxs)(`div`,{className:`perm-manage-add-row`,children:[(0,l.jsx)(s.Input,{placeholder:`Action name (e.g. Approve)`,value:x,onChange:e=>S(e.target.value),style:{flex:1},size:`small`}),(0,l.jsx)(s.Input,{placeholder:`Key (e.g. approve)`,value:C,onChange:e=>w(e.target.value),onPressEnter:M,style:{width:140},size:`small`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),loading:T,onClick:M,children:`Add`})]}),(0,l.jsxs)(`div`,{className:`perm-manage-list`,children:[_.length===0&&!y&&(0,l.jsx)(`div`,{className:`perm-empty`,style:{paddingTop:24},children:`No actions found`}),_.map(e=>(0,l.jsx)(ON,{label:`${e.permissionName} (${e.permissionKey})`,onSave:t=>N(e.permissionId,t),onDelete:()=>P(e.permissionId)},e.permissionId))]})]})}];return(0,l.jsx)(s.Modal,{open:e,onCancel:t,title:(0,l.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.SettingOutlined,{style:{color:`var(--color-brand)`}}),`Manage Modules & Actions`]}),width:520,footer:null,destroyOnClose:!0,children:(0,l.jsx)(s.Tabs,{activeKey:r,onChange:i,size:`small`,items:F})})}function AN(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(null),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(()=>EN(wN)),[_,v]=(0,o.useState)(()=>EN(TN)),y=(0,o.useCallback)((e,t)=>{g(n=>{let r={...n,[e]:t};return DN(wN,r),r})},[]),b=(0,o.useCallback)((e,t)=>{v(n=>{let r={...n,[e]:t};return DN(TN,r),r})},[]);function x(){g({}),v({}),DN(wN,{}),DN(TN,{}),s.message.success(`Labels reset to defaults`)}let S=(0,o.useCallback)(async()=>{i(!0);try{let{roles:e}=await n._r();t(e),e.length>0&&u(e[0])}catch{s.message.error(`Failed to load roles`)}finally{i(!1)}},[]);(0,o.useEffect)(()=>{S()},[S]);let C=(0,o.useMemo)(()=>{let t=d.trim().toLowerCase();return t?e.filter(e=>e.roleName.toLowerCase().includes(t)):e},[e,d]),w=Object.keys(h).length>0||Object.keys(_).length>0;return(0,l.jsxs)(`div`,{className:`perm-page`,children:[(0,l.jsxs)(Z,{className:`perm-left-card`,icon:(0,l.jsx)(c.SafetyOutlined,{}),title:`Roles`,bodyStyle:{padding:0},children:[(0,l.jsx)(`div`,{className:`perm-role-search`,children:(0,l.jsx)(s.Input,{prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search roles…`,allowClear:!0,size:`small`,value:d,onChange:e=>f(e.target.value)})}),(0,l.jsx)(s.Spin,{spinning:r,children:(0,l.jsxs)(`div`,{className:`perm-role-list`,children:[C.length===0&&!r&&(0,l.jsx)(`div`,{className:`perm-role-empty`,children:`No roles found`}),C.map(e=>{let t=a?.roleId===e.roleId,n=e.description&&e.description!==`N/A`?e.description:e.roleType===0?`Default role`:`Custom role`;return(0,l.jsxs)(`div`,{className:`perm-role-item${t?` active`:``}`,onClick:()=>u(e),children:[(0,l.jsx)(`div`,{className:`perm-role-item-name`,children:e.roleName}),(0,l.jsx)(`div`,{className:`perm-role-item-desc`,children:n})]},e.roleId)})]})})]}),(0,l.jsx)(Z,{className:`perm-right-card`,icon:(0,l.jsx)(c.LockOutlined,{}),title:`Module Permissions`,extra:(0,l.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[w&&(0,l.jsx)(`button`,{className:`perm-reset-btn`,onClick:x,children:`Reset labels`}),(0,l.jsx)(s.Button,{size:`small`,icon:(0,l.jsx)(c.SettingOutlined,{}),onClick:()=>m(!0),children:`Manage`})]}),bodyStyle:{padding:`12px 16px`},children:a?(0,l.jsx)(gN,{role:a,moduleLabels:h,actionLabels:_,onModuleLabelSave:y,onActionLabelSave:b},a.roleId):(0,l.jsx)(`div`,{className:`perm-empty`,children:`Select a role from the left to manage its permissions.`})}),(0,l.jsx)(kN,{open:p,onClose:()=>m(!1)})]})}var{Title:jN,Text:MN}=s.Typography,NN=[{label:`In Progress`,value:107,sub:`Under review`,color:`blue`},{label:`Hired`,value:2,sub:`Onboarded`,color:`green`},{label:`Project Completed`,value:2,sub:`Project cycle closed`,color:`purple`},{label:`Archive`,value:2,sub:`No longer active`,color:`peach`}];function PN({items:e=NN}){return(0,l.jsx)(s.Card,{className:`onboarding-card`,title:(0,l.jsx)(jN,{level:5,children:`Onboarding`}),extra:(0,l.jsx)(s.Button,{type:`link`,children:`View all`}),children:(0,l.jsx)(s.Row,{gutter:[12,12],children:e.map(e=>(0,l.jsx)(s.Col,{xs:12,sm:6,md:6,lg:12,xl:12,children:(0,l.jsxs)(`div`,{className:`onboarding-item ${e.color}`,children:[(0,l.jsx)(MN,{className:`onboarding-item-label`,children:e.label}),(0,l.jsx)(s.Statistic,{value:e.value,className:`onboarding-stat`}),(0,l.jsx)(`div`,{className:`onboarding-item-footer`,children:(0,l.jsx)(MN,{className:`onboarding-item-sub`,children:e.sub})})]})},e.label))})})}var{Text:FN,Title:IN}=s.Typography,LN=[{group:`Dashboard`,items:[{id:`dashboard`,label:`Admin Dashboard`,icon:(0,l.jsx)(c.DashboardOutlined,{})}]},{group:`Settings`,items:[{id:`org`,label:`Organization`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Organization Settings`,desc:`Manage your company profile and location details`,cards:[{label:`Company Information`,icon:(0,l.jsx)(c.BankOutlined,{}),desc:`Manage company profile, address and business details.`},{label:`Location`,icon:(0,l.jsx)(c.BuildOutlined,{}),desc:`Manage office locations, branches and regions.`}]},{id:`users`,label:`Users`,icon:(0,l.jsx)(c.UserOutlined,{}),heading:`Users`,desc:`Manage platform users and configure their field views.`,component:`users`},{id:`teams`,label:`Teams`,icon:(0,l.jsx)(c.TeamOutlined,{}),heading:`Teams`,desc:`Organize users into teams and configure field visibility per team.`,component:`teams`},{id:`roles`,label:`Roles`,icon:(0,l.jsx)(c.SafetyOutlined,{}),heading:`Roles`,desc:`Control permissions and configure field visibility per role.`,component:`roles`},{id:`permissions`,label:`Permissions`,icon:(0,l.jsx)(c.LockOutlined,{}),heading:`Permissions`,desc:`Manage module-wise action permissions (view, add, edit, delete, and more) per role.`,component:`permissions`},{id:`templates`,label:`Templates`,icon:(0,l.jsx)(c.FileTextOutlined,{}),heading:`Templates`,desc:`Email and signature templates for communications`,component:`templates`},{id:`ai-services`,label:`AI Services`,icon:(0,l.jsx)(c.ThunderboltOutlined,{}),heading:`AI Services`,desc:`Register the AI/automation backends (base URL + auth) that admin-configured AI Actions call.`,component:`ai-services`},{id:`bgc-integration`,label:`Integrations`,icon:(0,l.jsx)(c.SafetyOutlined,{}),heading:`Integrations`,desc:`Manage manual and API integrations used across application workflows.`,component:`bgc-integration`}]},{group:`Clients`,items:[{id:`clients`,label:`Clients`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Clients`,desc:`Manage client accounts and settings`,cards:[{label:`Clients`,icon:(0,l.jsx)(c.BankOutlined,{}),desc:`Manage client companies and account details.`}]}]},{group:`Forms`,items:[{id:`form-groups`,label:`Form Groups`,icon:(0,l.jsx)(c.AppstoreAddOutlined,{}),heading:`Form Groups`,desc:`Define field groups for module add/edit forms with validations and dropdown sources.`,component:`form-groups`},{id:`detail-groups`,label:`Detail Groups`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),heading:`Detail Groups`,desc:`Customize the detail view per module: labels, prefix/suffix, colour, capitalization, reference lookups and merged fields.`,component:`detail-groups`},{id:`row-actions`,label:`Actions`,icon:(0,l.jsx)(c.ToolOutlined,{}),heading:`Actions`,desc:`Configure which action buttons appear per row in each module's list view, scoped per role.`,component:`row-actions`}]},{group:`Master`,items:[{id:`jobs`,label:`Jobs`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),heading:`Jobs Master`,desc:`Configure job sources and status types`,cards:[{label:`Sources`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Manage job source master values.`},{label:`Job Status`,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),desc:`Configure job workflow status.`}]},{id:`candidates`,label:`Candidates`,icon:(0,l.jsx)(c.UserOutlined,{}),heading:`Candidates Master`,desc:`Skills, sources and work authorization settings`,cards:[{label:`Sources`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Manage candidate source values.`},{label:`Skills`,icon:(0,l.jsx)(c.SettingOutlined,{}),desc:`Manage skill master data.`},{label:`Work Authorization`,icon:(0,l.jsx)(c.SafetyOutlined,{}),desc:`Manage visa and authorization types.`}]},{id:`submissions`,label:`Submissions`,icon:(0,l.jsx)(c.FileTextOutlined,{}),heading:`Submissions Master`,desc:`Rejection reasons and submission status configuration`,cards:[{label:`Rejection Reasons`,icon:(0,l.jsx)(c.FileTextOutlined,{}),desc:`Manage common rejection reasons.`},{label:`Client Submission Status`,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),desc:`Manage client submission statuses.`}]},{id:`clientmaster`,label:`Client Master`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Client Master`,desc:`Payment terms, client types and contact types`,cards:[{label:`Payment Terms`,icon:(0,l.jsx)(c.FileTextOutlined,{}),desc:`Manage billing and payment terms.`},{label:`Client Type`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Classify client business types.`},{label:`Client Contact Type`,icon:(0,l.jsx)(c.TeamOutlined,{}),desc:`Manage client contact categories.`}]}]}],RN=[{label:`Sourced`,count:312,color:`#378ADD`,pct:35},{label:`Screened`,count:223,color:`#7F77DD`,pct:25},{label:`Interview`,count:161,color:`#1D9E75`,pct:18},{label:`Offered`,count:107,color:`#EF9F27`,pct:12},{label:`Rejected`,count:89,color:`#E24B4A`,pct:10}],zN=[{name:`Tcs`,jobs:14,candidates:86},{name:`Empasis`,jobs:9,candidates:64},{name:`NovaSystems`,jobs:7,candidates:51},{name:`Brightwave`,jobs:5,candidates:38}],BN=[{text:`New candidate Ravi Kumar added to Java Developer role`,time:`2 min ago`,color:`#378ADD`},{text:`Submission approved by Acme Corp for Sr. React Dev`,time:`18 min ago`,color:`#1D9E75`},{text:`User Priya S. added to Recruiters team`,time:`1 hr ago`,color:`#7F77DD`},{text:`Job Data Analyst — TechFlow moved to archived`,time:`3 hr ago`,color:`#EF9F27`},{text:`Candidate rejected — work authorization mismatch`,time:`5 hr ago`,color:`#E24B4A`}];function VN(){return(0,l.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:16},children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DashboardOutlined,{}),title:`Admin Dashboard`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(IN,{level:5,children:`Admin Dashboard`}),(0,l.jsx)(FN,{type:`secondary`,children:`Overview of jobs, candidates, onboarding and recent activity`})]}),(0,l.jsx)(`div`,{className:`admin-dashboard-stats`,children:(0,l.jsx)(YM,{stats:[{label:`Total Jobs`,value:1697,icon:`fileText`},{label:`Active Jobs`,value:1685,icon:`checkCircle`},{label:`My Jobs`,value:600,icon:`user`},{label:`Total Candidates`,value:4320,icon:`team`},{label:`Submissions`,value:892,icon:`fileText`}]})}),(0,l.jsxs)(`div`,{className:`admin-dashboard-mid-row`,children:[(0,l.jsx)(PN,{}),(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Candidate Pipeline`,children:[(0,l.jsx)(FN,{type:`secondary`,style:{fontSize:12},children:`By stage (892 total)`}),(0,l.jsx)(`div`,{className:`admin-pipeline-bar`,children:RN.map(e=>(0,l.jsx)(`div`,{className:`admin-pipeline-seg`,style:{width:`${e.pct}%`,background:e.color}},e.label))}),(0,l.jsx)(`div`,{className:`admin-pipeline-legend`,children:RN.map(e=>(0,l.jsxs)(`div`,{className:`admin-pipeline-legend-item`,children:[(0,l.jsx)(`span`,{className:`admin-pipeline-dot`,style:{background:e.color}}),e.label,` `,e.count]},e.label))}),(0,l.jsx)(`div`,{className:`admin-divider`}),(0,l.jsx)(FN,{strong:!0,style:{fontSize:12},children:`Submission status`}),(0,l.jsxs)(`div`,{className:`admin-sub-status-list`,style:{marginTop:6},children:[(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(FN,{style:{fontSize:13},children:`Pending client review`}),(0,l.jsx)(`span`,{className:`admin-badge warn`,children:`312`})]}),(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(FN,{style:{fontSize:13},children:`Client approved`}),(0,l.jsx)(`span`,{className:`admin-badge success`,children:`248`})]}),(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(FN,{style:{fontSize:13},children:`Rejected`}),(0,l.jsx)(`span`,{className:`admin-badge danger`,children:`89`})]})]})]})]}),(0,l.jsxs)(`div`,{className:`admin-dashboard-bottom-row`,children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.BankOutlined,{}),title:`Top Clients`,extra:(0,l.jsx)(s.Button,{type:`link`,size:`small`,children:`View all`}),children:zN.map(e=>(0,l.jsxs)(`div`,{className:`admin-client-row`,children:[(0,l.jsxs)(`div`,{className:`admin-client-left`,children:[(0,l.jsx)(`div`,{className:`admin-client-icon`,children:(0,l.jsx)(c.BankOutlined,{})}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`admin-client-name`,children:e.name}),(0,l.jsxs)(`div`,{className:`admin-client-sub`,children:[e.jobs,` open jobs`]})]})]}),(0,l.jsxs)(`div`,{className:`admin-client-right`,children:[(0,l.jsx)(`div`,{className:`admin-client-val`,children:e.candidates}),(0,l.jsx)(`div`,{className:`admin-client-sub`,children:`candidates`})]})]},e.name))}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.BellOutlined,{}),title:`Recent Activity`,children:BN.map((e,t)=>(0,l.jsxs)(`div`,{className:`admin-activity-row`,children:[(0,l.jsx)(`div`,{className:`admin-activity-dot`,style:{background:e.color}}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`admin-activity-text`,children:e.text}),(0,l.jsx)(`div`,{className:`admin-activity-time`,children:e.time})]})]},t))})]}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.SettingOutlined,{}),title:`Admin Configuration Overview`,extra:(0,l.jsx)(s.Button,{type:`link`,size:`small`,children:`Manage`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(FN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`Settings`}),[[`Organization`,2],[`User Settings`,4],[`Templates`,2]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(FN,{style:{fontSize:12},children:e}),(0,l.jsxs)(`span`,{className:`admin-badge info`,children:[t,` items`]})]},e))]}),(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(FN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`Master`}),[[`Jobs`,2],[`Candidates`,3],[`Submissions`,2]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(FN,{style:{fontSize:12},children:e}),(0,l.jsxs)(`span`,{className:`admin-badge info`,children:[t,` items`]})]},e))]}),(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(FN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`System`}),[[`Total Groups`,4],[`Total Modules`,9],[`Config Items`,19]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(FN,{style:{fontSize:12},children:e}),(0,l.jsx)(FN,{strong:!0,style:{fontSize:12},children:t})]},e))]})]})})]})}function HN({activeSection:e,activeGroup:t,filteredCards:n,searchText:r,setSearchText:i,allItems:a,handleNav:o}){return(0,l.jsxs)(s.Row,{gutter:[16,16],children:[(0,l.jsx)(s.Col,{span:24,children:(0,l.jsxs)(Z,{icon:e?.icon,title:e?.heading,extra:(0,l.jsx)(s.Input,{className:`admin-search`,prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search settings…`,allowClear:!0,value:r,onChange:e=>i(e.target.value)}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(IN,{level:5,children:e?.heading}),(0,l.jsx)(FN,{type:`secondary`,children:e?.desc})]})}),(0,l.jsx)(s.Col,{xs:24,xl:16,style:{alignSelf:`flex-start`},children:(0,l.jsx)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Configuration Items`,extra:(0,l.jsxs)(FN,{type:`secondary`,children:[n.length,` item`,n.length===1?``:`s`]}),children:(0,l.jsx)(s.Row,{gutter:[14,14],children:n.length>0?n.map(e=>(0,l.jsx)(s.Col,{xs:24,sm:12,xl:8,children:(0,l.jsxs)(`div`,{className:`admin-config-item`,children:[(0,l.jsx)(`div`,{className:`admin-config-top-bar`}),(0,l.jsxs)(`div`,{className:`admin-config-body`,children:[(0,l.jsx)(`div`,{className:`admin-config-icon`,children:e.icon}),(0,l.jsxs)(`div`,{className:`admin-config-text`,children:[(0,l.jsx)(`span`,{className:`admin-config-label`,children:e.label}),(0,l.jsx)(`span`,{className:`admin-config-desc`,children:e.desc})]})]}),(0,l.jsx)(`div`,{className:`admin-config-divider`}),(0,l.jsx)(s.Button,{type:`link`,size:`small`,className:`admin-config-manage`,icon:(0,l.jsx)(c.RightOutlined,{}),iconPosition:`end`,children:`Manage`})]})},e.label)):(0,l.jsx)(s.Col,{span:24,children:(0,l.jsx)(`div`,{className:`admin-config-empty`,children:(0,l.jsx)(s.Empty,{description:`No settings found`,image:s.Empty.PRESENTED_IMAGE_SIMPLE})})})})})}),(0,l.jsx)(s.Col,{xs:24,xl:8,style:{alignSelf:`flex-start`},children:(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`Section Overview`,children:[(0,l.jsx)(`div`,{className:`admin-overview-list`,children:LN.filter(e=>e.group!==`Dashboard`).map(e=>{let n=e.group===t?.group;return(0,l.jsxs)(`div`,{className:`admin-overview-item${n?` active`:``}`,onClick:()=>{let t=e.items[0];t&&o(t.id)},children:[(0,l.jsxs)(`div`,{className:`admin-overview-left`,children:[(0,l.jsx)(`div`,{className:`admin-overview-icon`,children:e.items[0]?.icon}),(0,l.jsxs)(`div`,{className:`admin-overview-text`,children:[(0,l.jsx)(`span`,{className:`admin-overview-name`,children:e.group}),(0,l.jsxs)(`span`,{className:`admin-overview-sub`,children:[e.items.length,` module`,e.items.length===1?``:`s`]})]})]}),(0,l.jsx)(`span`,{className:`admin-overview-count${n?` active`:``}`,children:e.items.length})]},e.group)})}),(0,l.jsxs)(`div`,{className:`admin-overview-footer`,children:[(0,l.jsx)(`span`,{className:`admin-overview-footer-label`,children:`Total configuration items`}),(0,l.jsx)(`span`,{className:`admin-overview-footer-value`,children:a.filter(e=>e.cards).reduce((e,t)=>e+t.cards.length,0)})]})]})})]})}function UN(){let[e,t]=(0,o.useState)(`dashboard`),[n,r]=(0,o.useState)(``),i=(0,o.useMemo)(()=>LN.flatMap(e=>e.items),[]),a=(0,o.useMemo)(()=>i.find(t=>t.id===e),[i,e]),u=(0,o.useMemo)(()=>LN.find(t=>t.items.some(t=>t.id===e)),[e]),d=(0,o.useMemo)(()=>{if(!a?.cards)return[];let e=n.trim().toLowerCase();return e?a.cards.filter(t=>t.label.toLowerCase().includes(e)||t.desc.toLowerCase().includes(e)):a.cards},[a,n]),f=(0,o.useMemo)(()=>LN.map(e=>({key:e.group,type:`group`,label:e.group,children:e.items.map(e=>({key:e.id,icon:e.icon,label:e.label}))})),[]),p=e=>{t(e),r(``)};return e===`dashboard`||a?.heading,(0,l.jsxs)(`main`,{className:`admin-page`,children:[(0,l.jsx)(`div`,{className:`admin-breadcrumb`,children:(0,l.jsx)(s.Breadcrumb,{items:[{title:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.HomeOutlined,{}),` Home`]})},{title:`Admin`}]})}),(0,l.jsxs)(s.Row,{gutter:[16,16],className:`admin-wrapper`,children:[(0,l.jsx)(s.Col,{xs:24,lg:6,xl:5,children:(0,l.jsxs)(Z,{title:`Admin Console`,icon:(0,l.jsx)(c.SettingOutlined,{}),children:[(0,l.jsxs)(`div`,{className:`admin-sidebar-banner`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-banner-title`,children:`Admin Panel`}),(0,l.jsx)(`span`,{className:`admin-sidebar-banner-sub`,children:`Configuration Center`}),(0,l.jsxs)(s.Row,{gutter:[8,0],children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-pill`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-pill-label`,children:`Groups`}),(0,l.jsx)(`span`,{className:`admin-sidebar-pill-value`,children:LN.length})]})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-pill`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-pill-label`,children:`Modules`}),(0,l.jsx)(`span`,{className:`admin-sidebar-pill-value`,children:i.length})]})})]})]}),(0,l.jsx)(s.Menu,{mode:`inline`,selectedKeys:[e],items:f,onClick:({key:e})=>p(e),className:`admin-sidebar-menu`})]})}),(0,l.jsx)(s.Col,{xs:24,lg:18,xl:19,children:e===`dashboard`?(0,l.jsx)(VN,{}):a?.component===`form-groups`?(0,l.jsx)(ow,{}):a?.component===`detail-groups`?(0,l.jsx)(Vw,{}):a?.component===`row-actions`?(0,l.jsx)(AT,{}):a?.component===`users`?(0,l.jsx)($M,{}):a?.component===`teams`?(0,l.jsx)(aN,{}):a?.component===`roles`?(0,l.jsx)(CN,{}):a?.component===`permissions`?(0,l.jsx)(AN,{}):a?.component===`templates`?(0,l.jsx)(HT,{}):a?.component===`ai-services`?(0,l.jsx)(KT,{}):a?.component===`bgc-integration`?(0,l.jsx)(QT,{}):(0,l.jsx)(HN,{activeSection:a,activeGroup:u,filteredCards:d,searchText:n,setSearchText:r,allItems:i,handleNav:p})})]})]})}var{Title:WN}=s.Typography;function GN(){let e=(0,d.useNavigate)(),{state:t}=(0,d.useLocation)(),n=t?.moduleName||`stickyNotes`,r=t?.title||`Sticky Notes`,i={...t?.request,params:{...t?.request?.params,limit:200,offset:0}};return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.ArrowLeftOutlined,{}),onClick:()=>e(-1),style:{marginBottom:12},children:`Back`}),(0,l.jsx)(Rt,{moduleName:n,title:r,columns:4,request:i,viewAll:!1})]})}var{Text:KN,Title:qN}=s.Typography,JN=10485760,YN=`/templates/test_cases_flow_template.base64.txt`,XN=`test_cases_flow_template.xlsx`,ZN=`module | subModule | step_order | description | actions | key | value | expected | scenario`,QN={idle:0,module_set:1,encoding:1,validating:2,preview:3,inserting:3,done:4,error:1},$N=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Bulk upload`,href:`/bulk-upload`}];function eP(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result).split(`,`)[1]),r.onerror=n,r.readAsDataURL(e)})}function tP(e){return e.filter(e=>e.row_status===`valid`).map(e=>{let t={...e};return delete t.row_status,delete t.errors,t})}function nP(e){return e.flatMap(e=>(e.errors??[]).map(t=>({id:e.id,...t})))}function rP({errors:e}){return(0,l.jsx)(`div`,{className:`bulk-tooltip-errors`,children:(e??[]).map((e,t)=>(0,l.jsx)(`div`,{children:e.message},`${e.field}-${t}`))})}function iP({errors:e,expanded:t,onToggle:n,onSummaryClick:r}){return e.length===0?null:(0,l.jsxs)(`div`,{className:`bulk-error-banner`,children:[(0,l.jsxs)(`div`,{className:`bulk-error-summary`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`bulk-error-summary-main`,onClick:r,"aria-label":`Scroll to first invalid row`,children:[(0,l.jsx)(c.ExclamationCircleOutlined,{className:`bulk-error-icon`}),(0,l.jsxs)(`span`,{children:[e.length,` validation error(s) found`]})]}),(0,l.jsx)(s.Button,{type:`link`,onClick:n,"aria-expanded":t,children:t?`Hide Errors`:`View Errors`})]}),t&&(0,l.jsx)(`div`,{className:`bulk-error-list`,role:`region`,"aria-label":`Validation error details`,children:e.map((e,t)=>(0,l.jsxs)(`div`,{className:`bulk-error-line`,children:[(0,l.jsxs)(`span`,{className:`bulk-row-chip`,children:[`Row `,e.id]}),(0,l.jsx)(`span`,{children:e.message})]},`${e.id}-${e.field}-${t}`))})]})}function aP({rows:e,view:t,onViewChange:n,onConfirm:r,onReset:i,saving:a,firstInvalidRowId:o,firstInvalidRowRef:u}){let d=e.filter(e=>e.row_status===`invalid`),f=t===`errors`?d:e,p=d.length>0||a;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(s.Row,{justify:`space-between`,align:`middle`,gutter:[16,16],className:`bulk-table-toolbar`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space.Compact,{children:[(0,l.jsx)(s.Button,{type:t===`all`?`primary`:`default`,onClick:()=>n(`all`),children:`All rows`}),(0,l.jsx)(s.Button,{type:t===`errors`?`primary`:`default`,onClick:()=>n(`errors`),children:`Errors only`})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsxs)(KN,{type:`secondary`,children:[e.length,` row(s)`]})})]}),(0,l.jsx)(`div`,{className:`bulk-table-wrap`,children:(0,l.jsxs)(`table`,{className:`bulk-preview-table`,children:[(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{children:[(0,l.jsx)(`th`,{className:`bulk-col-row`,children:`Row`}),(0,l.jsx)(`th`,{className:`bulk-col-flow`,children:`Submodule`}),(0,l.jsx)(`th`,{className:`bulk-col-description`,children:`Description`}),(0,l.jsx)(`th`,{className:`bulk-col-keyword`,children:`Action`}),(0,l.jsx)(`th`,{className:`bulk-col-target`,children:`Key`}),(0,l.jsx)(`th`,{className:`bulk-col-status`,children:`Status`}),(0,l.jsx)(`th`,{className:`bulk-col-error`,children:`Error`})]})}),(0,l.jsx)(`tbody`,{children:f.map(e=>{let t=e.errors??[],n=e.row_status===`invalid`;return(0,l.jsxs)(`tr`,{ref:n&&e.id===o?u:null,className:n?`bulk-row-invalid`:``,children:[(0,l.jsx)(`td`,{children:e.id}),(0,l.jsx)(`td`,{title:e.submodule,children:e.submodule}),(0,l.jsx)(`td`,{title:e.description,children:e.description?e.description:(0,l.jsx)(`span`,{className:`bulk-empty-text`,children:`-empty-`})}),(0,l.jsx)(`td`,{children:(0,l.jsx)(`code`,{className:`bulk-code-chip`,children:e.actions})}),(0,l.jsx)(`td`,{title:e.key,children:e.key}),(0,l.jsx)(`td`,{children:n?(0,l.jsx)(s.Tag,{color:`red`,children:`Error`}):(0,l.jsx)(s.Tag,{color:`green`,children:`Valid`})}),(0,l.jsx)(`td`,{children:n?(0,l.jsx)(s.Tooltip,{title:(0,l.jsx)(rP,{errors:t}),placement:`left`,children:(0,l.jsxs)(`button`,{type:`button`,className:`bulk-error-info`,"aria-label":`View ${t.length} error(s) for row ${e.id}`,children:[(0,l.jsx)(c.InfoCircleOutlined,{}),(0,l.jsx)(s.Badge,{count:t.length,size:`small`})]})}):(0,l.jsx)(`span`,{className:`bulk-error-none`,children:`-`})})]},`${e.id}-${e.step_order}`)})})]})}),(0,l.jsxs)(s.Space,{className:`bulk-actions`,children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:i,children:`Reset`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:a,disabled:p,onClick:r,children:d.length>0?`Fix ${d.length} error(s) to proceed`:`Save to database`})]})]})}function oP(){let e=(0,d.useNavigate)(),r=(0,o.useMemo)(()=>t.l(),[]),i=(0,o.useRef)(null),a=(0,o.useRef)(null),[u,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(``),[h,g]=(0,o.useState)(`idle`),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[x,S]=(0,o.useState)([]),[C,w]=(0,o.useState)(`all`),[T,E]=(0,o.useState)(null),[D,O]=(0,o.useState)(null),[k,A]=(0,o.useState)(!1),j=u.map(e=>({value:e.modulename,label:e.modulename})),M=nP(x),N=h===`encoding`||h===`validating`,P=!!p&&!N,F=QN[h]??0,I=x.find(e=>e.row_status===`invalid`)?.id,L=(0,o.useCallback)(()=>{m(``),g(`idle`),v(!1),b(null),S([]),w(`all`),E(null),O(null),i.current&&(i.current.value=``)},[]);(0,o.useEffect)(()=>{async function e(){try{let e=await Zb({project:r?.name??``,activeOnly:!0});f(e?.items??[])}catch(e){console.error(e),s.message.error(`Unable to load modules.`)}}e()},[r?.name]);let R=e=>{m(e??``),S([]),O(null),E(null),b(null),A(!1),g(e?`module_set`:`idle`)},z=async e=>{if(!e||!P)return;let t=e.name.split(`.`).pop()?.toLowerCase();if(![`xlsx`,`csv`].includes(t)){g(`module_set`),E({message:`Invalid file type. Please upload an Excel .xlsx or CSV .csv file.`});return}if(e.size>JN){g(`module_set`),E({message:`File must be 10 MB or smaller.`});return}E(null),S([]),O(null),b({name:e.name,size:e.size}),g(`encoding`);try{let n=await eP(e);g(`validating`);let i=await Kb({filename:e.name,project:r?.name??``,module:p,file_base64:n,file_type:t});S(i?.rows??[]),w(`all`),g(`preview`)}catch(e){console.error(e),E(e.payload??{code:`NETWORK_ERROR`,message:e.message||`Could not reach the server.`}),g(`error`)}},B=async()=>{try{let e=await fetch(YN);if(!e.ok)throw Error(`Template file not found (${e.status})`);let t=(await e.text()).trim(),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);let i=new Blob([r],{type:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=XN,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),s.message.success(`Sample template downloaded.`)}catch(e){console.error(e),s.message.error(`Unable to download sample template.`)}},V=async()=>{g(`inserting`),E(null);try{let t=await qb({project:r?.name??``,module:p,uploaded_by:localStorage.getItem(`user_Email`)??``,rows:tP(x)});O(t),g(`done`),s.message.success(`Bulk upload saved. Redirecting to view test cases...`),window.setTimeout(()=>e(`/viewTestCase`),900)}catch(e){console.error(e),E(e.payload??{code:`NETWORK_ERROR`,message:e.message||`Could not reach the server.`}),g(`preview`)}},H=(0,o.useCallback)(()=>{a.current?.scrollIntoView({behavior:`smooth`,block:`center`})},[]),ee=[`bulk-dropzone`,_?`bulk-dropzone-dragging`:``,y?`bulk-dropzone-has-file`:``,T&&h!==`preview`?`bulk-dropzone-error`:``,p?``:`bulk-dropzone-disabled`].filter(Boolean).join(` `);return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:$N})}),r?.name&&(0,l.jsx)(s.Col,{children:(0,l.jsx)(KN,{strong:!0,children:r.name})})]}),(0,l.jsxs)(`div`,{className:`zt-page zt-page-wide bulk-page`,children:[(0,l.jsxs)(`div`,{className:`bulk-header`,children:[(0,l.jsx)(qN,{level:3,children:`Bulk upload test cases`}),(0,l.jsxs)(s.Space,{direction:`vertical`,size:4,children:[(0,l.jsx)(KN,{type:`secondary`,children:ZN}),(0,l.jsx)(KN,{type:`secondary`,children:`Use the sample template for the required columns. Uploaded rows are saved as Active by default.`})]})]}),(0,l.jsx)(`div`,{className:`bulk-stepbar`,children:[`Select`,`Upload`,`Validate`,`Save`].map((e,t)=>(0,l.jsxs)(`span`,{className:t<F?`bulk-step-active`:``,children:[t+1,` `,e]},e))}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:`1. Module selector`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,className:`bulk-module-select`,placeholder:`Choose a module`,options:j,value:p||void 0,onChange:R})}),p&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`2. File upload`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.DownloadOutlined,{}),onClick:B,children:`Download Sample Template`}),children:[(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`First time uploading?`,description:`Download the sample template, keep the column names unchanged, fill your test steps, and upload either .xlsx or .csv.`,className:`bulk-inline-alert`}),(0,l.jsxs)(`button`,{type:`button`,className:ee,disabled:!P,onClick:()=>i.current?.click(),onDragOver:e=>{e.preventDefault(),P&&v(!0)},onDragLeave:()=>v(!1),onDrop:e=>{e.preventDefault(),v(!1),z(e.dataTransfer.files?.[0])},children:[(0,l.jsx)(c.CloudUploadOutlined,{className:`bulk-upload-icon`}),y?(0,l.jsxs)(`span`,{className:`bulk-file-chip`,children:[y.name,` - `,Math.ceil(y.size/1024),` KB`]}):(0,l.jsx)(`span`,{children:`Drag & drop here, or click to browse`})]}),(0,l.jsx)(`input`,{ref:i,hidden:!0,type:`file`,accept:`.xlsx,.csv`,onChange:e=>z(e.target.files?.[0])}),N&&(0,l.jsx)(s.Progress,{percent:h===`encoding`?45:82,showInfo:!1,size:`small`}),T&&h!==`preview`&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:T.message,className:`bulk-inline-alert`})]}),x.length>0&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`3. Validation result`,children:[(0,l.jsx)(iP,{errors:M,expanded:k,onToggle:()=>A(e=>!e),onSummaryClick:H}),T&&h===`preview`&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:T.message,className:`bulk-inline-alert`}),(0,l.jsx)(aP,{rows:x,view:C,onViewChange:w,onConfirm:V,onReset:L,saving:h===`inserting`,firstInvalidRowId:I,firstInvalidRowRef:a})]}),D&&h===`done`&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`4. Upload complete`,children:[(0,l.jsxs)(s.Row,{gutter:[16,16],className:`bulk-metrics`,children:[(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(KN,{children:`Total`}),(0,l.jsx)(`strong`,{children:x.length})]})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(KN,{children:`Inserted`}),(0,l.jsx)(`strong`,{children:D.inserted??0})]})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(KN,{children:`Failed`}),(0,l.jsx)(`strong`,{children:D.failed??0})]})})]}),(0,l.jsx)(s.Alert,{type:`success`,showIcon:!0,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),message:`${D.inserted??0} test cases saved to database - module: ${p}`,className:`bulk-inline-alert`}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:L,children:`Upload another file`})]})]})]})}var sP=[{value:`navigate`,label:`Navigate`},{value:`fill`,label:`Fill`},{value:`click`,label:`Click`},{value:`select`,label:`Select`},{value:`press_key`,label:`Press Key`},{value:`type_and_select`,label:`Type and Select`},{value:`type_and_select_modal`,label:`Type and Select (Modal)`},{value:`upload_file`,label:`Upload File`},{value:`check_checkbox`,label:`Check Checkbox`},{value:`check_filter_checkbox`,label:`Check Filter Checkbox`},{value:`select_page_size`,label:`Select Page Size`},{value:`check_n_checkboxes`,label:`Check N Checkboxes`},{value:`store_text`,label:`Store Text`},{value:`reset_session`,label:`Reset Session`},{value:`switch_to_new_tab`,label:`Switch To New Tab`},{value:`close_tab`,label:`Close Tab`},{value:`assert_visible`,label:`Assert Visible`},{value:`assert_hidden`,label:`Assert Hidden`},{value:`assert_text`,label:`Assert Text`},{value:`assert_url`,label:`Assert URL`},{value:`assert_body_contains`,label:`Assert Body Contains`},{value:`assert_button_disabled`,label:`Assert Button Disabled`},{value:`assert_field_error`,label:`Assert Field Error`},{value:`assert_field_accepted`,label:`Assert Field Accepted`},{value:`assert_children_disabled`,label:`Assert Children Disabled`},{value:`assert_children_visible`,label:`Assert Children Visible`},{value:`assert_element_count`,label:`Assert Element Count`},{value:`assert_toast`,label:`Assert Toast`},{value:`assert_toast_success`,label:`Assert Toast Success`},{value:`assert_toast_error`,label:`Assert Toast Error`},{value:`wait_for_visible`,label:`Wait For Visible`},{value:`wait_for_hidden`,label:`Wait For Hidden`},{value:`wait_for_text`,label:`Wait For Text`}],{Text:cP}=s.Typography,lP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/test-cases`}],uP={tags:`regression`,active:1},dP={module:{dbName:`Modules`,formField:`module`,label:`Module`}};function fP(e=[]){return e.map(e=>({value:e,label:e}))}function pP(e=``){return String(e??``).trim()}function mP(e=``){return pP(e).toLowerCase()}function hP(e=[]){let t=new Map;return e.forEach(e=>{let n=pP(e?.flow),r=n.toLowerCase();n&&!t.has(r)&&t.set(r,n)}),Array.from(t.values()).map(e=>({value:e,label:e}))}function gP(e=[],t,n){let r=pP(t).toLowerCase(),i=pP(n).toLowerCase();return e.reduce((e,t)=>{let n=pP(t?.module).toLowerCase(),a=pP(t?.flow).toLowerCase();if(n!==r||a!==i)return e;let o=Number(t?.step_order)||0;return Math.max(e,o)},0)+1}function _P({icon:e,title:t}){return(0,l.jsxs)(s.Space,{size:10,align:`center`,children:[(0,l.jsx)(`div`,{className:`v1-section-icon-box`,children:e}),(0,l.jsx)(cP,{strong:!0,className:`v1-section-label`,children:t})]})}function vP(){let[e]=s.Form.useForm(),[t]=s.Form.useForm(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)([]),[f,p]=(0,o.useState)([]),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)({open:!1,typeKey:`module`}),[b,x]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),[w,T]=(0,o.useState)(!1),E=(0,d.useNavigate)(),D=dP[v.typeKey],O=(0,o.useMemo)(()=>fP(r),[r]),k=s.Form.useWatch(`module`,e),A=s.Form.useWatch(`flow`,e),j=!!pP(k),M=!!pP(A),N=!j,P=!j||!M,F=(e,t=[])=>{e===`module`&&i(t)},I=async()=>{h(!0);try{let e=await Vb(dP.module.dbName);i(e?.items??[])}catch(e){console.error(`Unable to load testing options:`,e),s.message.error(`Unable to load testing options.`)}finally{h(!1)}},L=(0,o.useCallback)(async t=>{let n=pP(t);if(u([]),p([]),e.setFieldsValue({step_order:void 0}),n){_(!0);try{let e=await Gb({limit:1e4,offset:0,module:n}),t=Array.isArray(e?.items)?e.items:[];u(t),p(hP(t))}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{_(!1)}}},[e]),R=(0,o.useCallback)(async(t,n,r)=>{let i=pP(t),a=pP(n);if(!i||!a){e.setFieldsValue({step_order:void 0});return}C(!0);try{e.setFieldsValue({step_order:gP(r,i,a)})}catch(e){console.error(`Unable to load step order:`,e),s.message.error(`Unable to load step order.`)}finally{C(!1)}},[e]);(0,o.useEffect)(()=>{Promise.resolve().then(I)},[]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>L(k))},[L,k]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>R(k,A,a))},[a,R,A,k]);let z=async t=>{let n={module:pP(t.module),flow:pP(t.flow),step_order:Number(t.step_order),description:pP(t.description),keyword:mP(t.keyword),target:pP(t.target),value:pP(t.value),expected:pP(t.expected),tags:t.tags?pP(t.tags):uP.tags,active:Number(t.active)};T(!0);try{await Wb(n),s.message.success(`Test case details saved successfully.`),e.resetFields(),u([]),p([])}catch(e){console.error(`Unable to save test case:`,e),s.message.error(`Unable to save test case.`)}finally{T(!1)}},B=(t,n)=>{e.setFieldsValue({[t]:pP(n)})},V=t=>{e.setFieldsValue({module:pP(t),flow:void 0,step_order:void 0,keyword:void 0,description:void 0,target:void 0,tags:uP.tags,value:void 0,expected:void 0})},H=t=>{e.setFieldsValue({flow:pP(t),step_order:void 0})},ee=e=>{let n=dP[e];y({open:!0,typeKey:e}),t.setFieldsValue({name:``,type:n.label})},U=()=>{y(e=>({...e,open:!1})),t.resetFields()},te=async()=>{try{let n=pP((await t.validateFields()).name),r=await Hb({name:n,type:D.dbName});F(v.typeKey,r?.items??[]),e.setFieldsValue({[D.formField]:n}),s.message.success(`${D.label} added successfully.`),U()}catch(e){if(e?.errorFields)return;console.error(`Unable to save testing option:`,e),s.message.error(`Unable to add ${D.label.toLowerCase()}.`)}finally{x(!1)}};return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:lP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>E(`/zinnext-home`),children:`View Table`})})]}),(0,l.jsx)(`div`,{className:`v1-page`,children:(0,l.jsxs)(`div`,{className:`v1-page-inner`,children:[(0,l.jsx)(`div`,{className:`v1-page-header`,children:(0,l.jsxs)(s.Space,{align:`center`,size:10,children:[(0,l.jsx)(c.ProfileOutlined,{className:`v1-outer-icon`}),(0,l.jsx)(`div`,{children:(0,l.jsx)(cP,{strong:!0,style:{fontSize:16},children:`Add Test Case`})})]})}),(0,l.jsx)(Z,{children:(0,l.jsxs)(s.Form,{form:e,className:`v1-form`,layout:`vertical`,colon:!1,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),initialValues:uP,onFinish:z,autoComplete:`off`,children:[(0,l.jsx)(s.Card,{className:`v1-card`,title:(0,l.jsx)(_P,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`Test Case Details`}),extra:(0,l.jsx)(cP,{type:`secondary`,className:`v1-card-subtitle`,children:`Module, flow, step order and execution data`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,style:{flex:1},children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:m,optionFilterProp:`label`,placeholder:`Select module`,options:O,onChange:V})}),(0,l.jsx)(s.Button,{"aria-label":`Add module`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:30},onClick:()=>ee(`module`)})]})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Flow`,name:`flow`,children:(0,l.jsx)(s.AutoComplete,{maxLength:100,allowClear:!0,disabled:N,options:f,placeholder:g?`Loading flows`:`Enter flow`,onChange:H,filterOption:(e,t)=>t?.value?.toLowerCase().includes(e.toLowerCase())})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,disabled:!0,placeholder:S?`Loading step order`:`Step order`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`keyword`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,disabled:P,optionFilterProp:`label`,placeholder:`Select action`,options:sP,onChange:t=>e.setFieldsValue({keyword:mP(t)})})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3,maxLength:255,disabled:P,placeholder:`Enter description`,showCount:!0,onBlur:e=>B(`description`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`target`,children:(0,l.jsx)(s.Input,{maxLength:255,disabled:P,placeholder:`Enter target`,onBlur:e=>B(`target`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Tags`,name:`tags`,children:(0,l.jsx)(s.Input,{maxLength:200,disabled:P,placeholder:`Enter tags`,prefix:(0,l.jsx)(c.TagsOutlined,{className:`v1-input-icon`}),onBlur:e=>B(`tags`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:P,placeholder:`Enter value`,onBlur:e=>B(`value`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:P,placeholder:`Enter expected result`,onBlur:e=>B(`expected`,e.target.value)})})})]})}),(0,l.jsx)(`div`,{className:`v1-form-actions`,children:(0,l.jsx)(s.Form.Item,{children:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:w,disabled:P,children:`Submit`}),(0,l.jsx)(s.Button,{onClick:()=>{e.resetFields(),u([]),p([])},children:`Reset`})]})})})]})}),(0,l.jsx)(s.Modal,{title:`Add ${D.label}`,open:v.open,confirmLoading:b,okText:`Add`,onCancel:U,onOk:()=>{x(!0),te()},destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:t,layout:`vertical`,colon:!1,className:`v1-form`,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),children:[(0,l.jsx)(s.Form.Item,{label:`Name`,name:`name`,children:(0,l.jsx)(s.Input,{maxLength:100,placeholder:`Enter ${D.label.toLowerCase()} name`,onBlur:e=>{t.setFieldsValue({name:pP(e.target.value)})}})}),(0,l.jsx)(s.Form.Item,{label:`Type`,name:`type`,children:(0,l.jsx)(s.Input,{disabled:!0})})]})})]})})]})}var{Text:yP}=s.Typography,bP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`}];function xP(e=``){return String(e??``).trim()}function SP(e=[],t){return e.map(e=>({value:e.id,label:e[t]}))}var CP=[{label:`Step`,value:`step_order`,width:70},{label:`Action`,value:`actions`,width:140},{label:`Key`,value:`key`,width:160,ellipsis:!0},{label:`Value`,value:`value`,ellipsis:!0},{label:`Description`,value:`description`,ellipsis:!0},{label:`Scenario`,value:`scenario`,width:110,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`green`,children:`Positive`}):(0,l.jsx)(s.Tag,{color:`red`,children:`Negative`})}],wP={key:!1,value:!1,expected:!1};function TP(e,t){return t?e[t]??wP:wP}function EP(e,t){e.setFields(t.map(e=>({name:e,errors:[]})))}function DP(){let[e]=s.Form.useForm(),r=(0,d.useNavigate)(),[i]=(0,d.useSearchParams)(),a=i.get(`edit`),u=!!a,f=(0,o.useMemo)(()=>t.l(),[]),[p,m]=(0,o.useState)([]),[h,g]=(0,o.useState)([]),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(sP),[x,S]=(0,o.useState)({}),[C,w]=(0,o.useState)(!1),[T,E]=(0,o.useState)(!1),[D,O]=(0,o.useState)(!1),[k,A]=(0,o.useState)(!1),[j,M]=(0,o.useState)(!1),N=s.Form.useWatch(`module`,e),P=s.Form.useWatch(`submodule`,e),F=s.Form.useWatch(`actions`,e),I=!!N,L=!!P,R=(0,o.useMemo)(()=>TP(x,F),[x,F]),z=(0,o.useMemo)(()=>SP(p,`modulename`),[p]),B=(0,o.useMemo)(()=>SP(h,`submodulename`),[h]),V=(0,o.useMemo)(()=>p.find(e=>e.id===N)?.modulename??``,[p,N]),H=(0,o.useMemo)(()=>h.find(e=>e.id===P)?.submodulename??``,[P,h]),ee=(0,o.useCallback)(async()=>{try{let e=await Ub();Array.isArray(e?.options)&&e.options.length>0&&b(e.options),e?.rules&&typeof e.rules==`object`&&S(e.rules)}catch(e){console.error(`Unable to load action field rules:`,e),s.message.error(`Unable to load action validation rules.`)}},[]),U=(0,o.useCallback)(async e=>{if(!e){m([]);return}w(!0);try{let t=await Zb({project:e,activeOnly:!0});m(t?.items??[])}catch(e){console.error(`Unable to load modules:`,e),s.message.error(`Unable to load modules.`)}finally{w(!1)}},[]),te=(0,o.useCallback)(async(e,t)=>{if(!e||!t){g([]);return}E(!0);try{let n=await ex({project:e,module:t,activeOnly:!0});g(n?.items??[])}catch(e){console.error(`Unable to load submodules:`,e),s.message.error(`Unable to load submodules.`)}finally{E(!1)}},[]),ne=(0,o.useCallback)(async(t,n,r,i=``)=>{if(!t||!n||!r){v([]),e.setFieldsValue({step_order:void 0});return}O(!0);try{let[a,o]=await Promise.all([rx({product_parent_ID:t,module_parent_ID:n,submodule_parent_ID:r,actions:i,limit:1e3}),ox({product_parent_ID:t,module_parent_ID:n,submodule_parent_ID:r})]);v(a?.items??[]),e.setFieldsValue({step_order:o?.step_order??1})}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{O(!1)}},[e]),re=(0,o.useCallback)(async(e=``)=>{if(!(!f?.id||!N||!P)){O(!0);try{let t=await rx({product_parent_ID:f.id,module_parent_ID:N,submodule_parent_ID:P,actions:e,limit:1e3});v(t?.items??[])}catch(e){console.error(`Unable to load action flows:`,e),s.message.error(`Unable to load action steps.`)}finally{O(!1)}}},[f?.id,N,P]),ie=(0,o.useCallback)(async()=>{if(!(!a||!f?.name)){M(!0);try{let t=await ax(a);await te(f.name,t.module);let n=await rx({product_parent_ID:t.product_parent_ID,module_parent_ID:t.module_parent_ID,submodule_parent_ID:t.submodule_parent_ID,limit:1e3});v(n?.items??[]),e.setFieldsValue({module:t.module_parent_ID,submodule:t.submodule_parent_ID,step_order:t.step_order,actions:t.actions,key:t.key,value:t.value,expected:t.expected,description:t.description,scenario:t.scenario===1,active:Number(t.active)!==0})}catch(e){console.error(`Unable to load test flow:`,e),s.message.error(`Unable to load test flow for edit.`),r(`/viewTestCase`)}finally{M(!1)}}},[a,e,te,r,f?.name]);return(0,o.useEffect)(()=>{if(!f){r(`/select-project`,{replace:!0});return}Promise.resolve().then(async()=>{await ee(),await U(f.name),a&&await ie()})},[f,r,ee,U,a,ie]),f?(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:bP})}),(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(yP,{strong:!0,children:f.name})]})})]}),(0,l.jsx)(`div`,{className:`zt-page`,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,colon:!1,className:`v1-form`,initialValues:{scenario:!0,active:!0},onFinish:async t=>{let n={product_parent_ID:Number(f?.id),module_parent_ID:Number(t.module),submodule_parent_ID:Number(t.submodule),description:xP(t.description),actions:xP(t.actions),key:xP(t.key),value:xP(t.value),expected:xP(t.expected),scenario:+!!t.scenario,active:+!!t.active};A(!0);try{if(u){await sx(a,{...n,step_order:Number(t.step_order)}),s.message.success(`Test case updated successfully.`),r(`/viewTestCase`);return}await ix(n),s.message.success(`Step saved (#${t.step_order}).`),e.setFieldsValue({actions:void 0,key:void 0,value:void 0,expected:void 0,description:void 0}),await ne(n.product_parent_ID,n.module_parent_ID,n.submodule_parent_ID)}catch(e){console.error(`Unable to save test case:`,e),s.message.error(u?`Unable to update test case.`:`Unable to save step.`)}finally{A(!1)}},autoComplete:`off`,disabled:j,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:8,className:`zt-section-title`,children:[(0,l.jsx)(`span`,{className:`zt-step-tag`,children:`1`}),(0,l.jsx)(`span`,{children:`Module & Submodule`})]}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],align:`bottom`,children:[(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,loading:C,placeholder:`Select module`,options:z,onChange:t=>{let n=p.find(e=>e.id===t)?.modulename??``;e.setFieldsValue({module:t,submodule:void 0,step_order:void 0,actions:void 0,key:void 0,value:void 0,expected:void 0}),EP(e,[`actions`,`key`,`value`,`expected`]),g([]),v([]),te(f?.name,n)}})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Submodule`,name:`submodule`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,disabled:!I,loading:T,placeholder:I?`Select submodule`:`Select module first`,options:B,onChange:t=>{e.setFieldsValue({submodule:t,actions:void 0,key:void 0,value:void 0,expected:void 0}),EP(e,[`actions`,`key`,`value`,`expected`]),ne(f?.id,N,t)}})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Scenario`,name:`scenario`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{disabled:!L,checkedChildren:`Positive`,unCheckedChildren:`Negative`})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Active`,name:`active`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{checkedChildren:`Active`,unCheckedChildren:`Inactive`})})})]})}),L&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:8,className:`zt-section-title`,children:[(0,l.jsx)(`span`,{className:`zt-step-tag`,children:`2`}),(0,l.jsx)(c.FileTextOutlined,{}),(0,l.jsx)(`span`,{children:`Step Details`})]}),extra:(0,l.jsxs)(yP,{type:`secondary`,children:[V,` / `,H]}),children:[(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,children:(0,l.jsx)(s.Input,{disabled:!0,placeholder:D?`Loading…`:`Auto`})})}),(0,l.jsx)(s.Col,{xs:24,md:18,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`actions`,rules:[{required:!0,message:`Mandatory Field`}],children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,placeholder:`Select action`,options:y,onChange:t=>{let n=TP(x,t);e.setFieldsValue({actions:t,key:n.key?e.getFieldValue(`key`):void 0,value:n.value?e.getFieldValue(`value`):void 0,expected:n.expected?e.getFieldValue(`expected`):void 0}),EP(e,[`key`,`value`,`expected`]),re(t||``)}})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`key`,rules:[{required:R.key,message:`Key is required for this action`}],children:(0,l.jsx)(s.Input,{maxLength:255,disabled:F&&!R.key,placeholder:F?R.key?`Required — Enter selector / locator`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,rules:[{required:R.value,message:`Value is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:1,autoSize:{minRows:1,maxRows:4},disabled:F&&!R.value,placeholder:F?R.value?`Required — Enter value`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,rules:[{required:R.expected,message:`Expected result is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:2,disabled:F&&!R.expected,placeholder:F?R.expected?`Required — Enter expected result`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:2,maxLength:255,showCount:!0,placeholder:`Enter description`})})})]}),(0,l.jsxs)(s.Space,{className:`zt-actions`,children:[(0,l.jsx)(s.Button,{onClick:()=>{if(u){r(`/viewTestCase`);return}e.resetFields(),g([]),v([]),E(!1),O(!1)},children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:k||j,children:u?`Update Test Case`:`Save & Continue`})]})]},`${N}-${P}`),L&&(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.TableOutlined,{}),(0,l.jsx)(`span`,{children:`Added Steps`})]}),extra:(0,l.jsx)(s.Tag,{children:F?`${_.length} ${F} step(s)`:`${_.length} step(s)`}),children:(0,l.jsx)($m,{listName:`Added Steps`,loading:D,fields:CP,dataSource:_,current:1,pageSize:Math.max(_.length,1),total:_.length,rowSelection:!1,className:`zt-list-plain zt-list-static`})})]})})]}):null}var{Text:OP}=s.Typography,kP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Manage Modules`,href:`/manageModules`}];function AP(){let e=(0,d.useNavigate)(),r=(0,o.useMemo)(()=>t.l(),[]),[i,a]=(0,o.useState)([]),[u,f]=(0,o.useState)({}),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)(``),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),T=(0,o.useCallback)(async e=>{if(!e){a([]);return}m(!0);try{let[t,n]=await Promise.all([Zb({project:e}),ex({project:e})]);a(t?.items??[]);let r={};(n?.items??[]).forEach(e=>{let t=e.modulename;r[t]=(r[t]??0)+1}),f(r)}catch(e){console.error(e),s.message.error(`Unable to load modules.`)}finally{m(!1)}},[]);(0,o.useEffect)(()=>{if(!r){e(`/select-project`,{replace:!0});return}Promise.resolve().then(()=>T(r.name))},[r,e,T]);let E=async(e,t)=>{try{await $b(e.id,+!!t),a(n=>n.map(n=>n.id===e.id?{...n,active:+!!t}:n)),s.message.success(`Module ${t?`activated`:`deactivated`}.`)}catch(e){console.error(e),s.message.error(`Unable to update module status.`)}},D=async()=>{let e=_.trim();if(!e){s.message.warning(`Enter a module name.`);return}b(!0);try{await Qb({project:r.name,modulename:e}),s.message.success(`Module added.`),g(!1),v(``),S(1),T(r.name)}catch(e){console.error(e),s.message.error(`Unable to add module (maybe it already exists).`)}finally{b(!1)}},O=t=>{e(`/test-cases/zinnext/submodules?module=${encodeURIComponent(t.modulename)}`)};return r?(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:kP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/addTestCase`),children:`Back to Form`})})]}),(0,l.jsxs)(`div`,{className:`zt-page`,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-bar`,children:(0,l.jsxs)(s.Row,{gutter:[16,16],align:`middle`,justify:`space-between`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(`span`,{children:`Project:`}),(0,l.jsx)(OP,{strong:!0,children:r.name})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>g(!0),children:`Add Module`})})]})}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Modules`})]}),children:(0,l.jsx)($m,{listName:`Modules`,loading:p,fields:[{label:`Module`,value:`modulename`},{label:`Submodules`,value:`submoduleCount`,width:140,render:(e,t)=>(0,l.jsxs)(s.Button,{type:`link`,className:`zt-count-link`,onClick:()=>O(t),children:[u[t.modulename]??0,` submodule(s)`]})},{label:`Active`,value:`active`,width:120,render:(e,t)=>(0,l.jsx)(s.Switch,{checked:e===1,checkedChildren:`On`,unCheckedChildren:`Off`,onChange:e=>E(t,e)})}],dataSource:i,current:x,pageSize:C,total:i.length,onPageChange:S,onPageSizeChange:e=>{S(1),w(e)},rowSelection:!1,className:`zt-list-plain`})})]}),(0,l.jsx)(s.Modal,{title:`Add Module`,open:h,confirmLoading:y,okText:`Add`,onOk:D,onCancel:()=>{g(!1),v(``)},destroyOnHidden:!0,children:(0,l.jsxs)(s.Space,{direction:`vertical`,className:`zt-modal-stack`,children:[(0,l.jsxs)(OP,{type:`secondary`,children:[`Project: `,(0,l.jsx)(`b`,{children:r.name})]}),(0,l.jsx)(s.Input,{placeholder:`Enter module name`,maxLength:100,value:_,onChange:e=>v(e.target.value),onPressEnter:D})]})})]}):null}var{Text:jP}=s.Typography,MP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Manage Modules`,href:`/manageModules`},{label:`Manage Submodules`,href:`/test-cases/zinnext/submodules`}];function NP(){let e=(0,d.useNavigate)(),[r]=(0,d.useSearchParams)(),i=(0,o.useMemo)(()=>t.l(),[]),a=r.get(`module`)??``,[u,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)(``),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),T=(0,o.useCallback)(async(e,t)=>{if(!e||!t){f([]);return}m(!0);try{let n=await ex({project:e,module:t});f(n?.items??[])}catch(e){console.error(e),s.message.error(`Unable to load submodules.`)}finally{m(!1)}},[]);(0,o.useEffect)(()=>{if(!i){e(`/select-project`,{replace:!0});return}if(!a){e(`/manageModules`,{replace:!0});return}Promise.resolve().then(()=>T(i.name,a))},[i,a,e,T]);let E=async(e,t)=>{try{await nx(e.id,+!!t),f(n=>n.map(n=>n.id===e.id?{...n,active:+!!t}:n)),s.message.success(`Submodule ${t?`activated`:`deactivated`}.`)}catch(e){console.error(e),s.message.error(`Unable to update submodule status.`)}},D=async()=>{let e=_.trim();if(!e){s.message.warning(`Enter a submodule name.`);return}b(!0);try{await tx({project:i.name,modulename:a,submodulename:e}),s.message.success(`Submodule added.`),g(!1),v(``),S(1),T(i.name,a)}catch(e){console.error(e),s.message.error(`Unable to add submodule (maybe it already exists).`)}finally{b(!1)}};return!i||!a?null:(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:MP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/manageModules`),children:`Back to Modules`})})]}),(0,l.jsxs)(`div`,{className:`zt-page`,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-bar`,children:(0,l.jsxs)(s.Row,{gutter:[16,16],align:`middle`,justify:`space-between`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:16,wrap:!0,className:`zt-section-title`,children:[(0,l.jsxs)(s.Space,{size:6,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(`span`,{children:`Project:`}),(0,l.jsx)(jP,{strong:!0,children:i.name})]}),(0,l.jsxs)(s.Space,{size:6,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Module:`}),(0,l.jsx)(jP,{strong:!0,children:a})]})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>g(!0),children:`Add Submodule`})})]})}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Submodules`})]}),children:(0,l.jsx)($m,{listName:`Submodules`,loading:p,fields:[{label:`Submodule`,value:`submodulename`},{label:`Active`,value:`active`,width:120,render:(e,t)=>(0,l.jsx)(s.Switch,{checked:e===1,checkedChildren:`On`,unCheckedChildren:`Off`,onChange:e=>E(t,e)})}],dataSource:u,current:x,pageSize:C,total:u.length,onPageChange:S,onPageSizeChange:e=>{S(1),w(e)},rowSelection:!1,className:`zt-list-plain`})})]}),(0,l.jsx)(s.Modal,{title:`Add Submodule`,open:h,confirmLoading:y,okText:`Add`,onOk:D,onCancel:()=>{g(!1),v(``)},destroyOnHidden:!0,children:(0,l.jsxs)(s.Space,{direction:`vertical`,className:`zt-modal-stack`,children:[(0,l.jsxs)(jP,{type:`secondary`,children:[`Project: `,(0,l.jsx)(`b`,{children:i.name}),` \xA0|\xA0 Module: `,(0,l.jsx)(`b`,{children:a})]}),(0,l.jsx)(s.Input,{placeholder:`Enter submodule name`,maxLength:100,value:_,onChange:e=>v(e.target.value),onPressEnter:D})]})})]})}var{Text:PP}=s.Typography,FP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Table`,href:`/viewTestCase`}];function IP(){let e=(0,d.useNavigate)(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)(0),[f,p]=(0,o.useState)(!1),m=(0,o.useMemo)(()=>t.l(),[]),[h,g]=(0,o.useState)(``),[_,v]=(0,o.useState)(1),[y,b]=(0,o.useState)(20),[x,S]=(0,o.useState)(null),C=(0,o.useCallback)(async(e={})=>{p(!0);try{let t=await rx({product_parent_ID:e.project??m?.id??``,search:e.search??h??``,limit:e.pageSize??y,offset:((e.page??_)-1)*(e.pageSize??y)});i(t?.items??[]),u(t?.total??0)}catch(e){console.error(e),s.message.error(`Unable to load test flows.`)}finally{p(!1)}},[m?.id,h,_,y]),w=e=>{s.Modal.confirm({title:`Delete Test Case`,icon:(0,l.jsx)(c.ExclamationCircleOutlined,{}),content:`Are you sure you want to delete this test case?`,okText:`Delete`,okButtonProps:{danger:!0,loading:x===e.id},cancelText:`Cancel`,async onOk(){S(e.id);try{await cx(e.id),s.message.success(`Test case deleted successfully.`);let t=r.length===1&&_>1?_-1:_;v(t),await C({page:t})}catch(e){throw console.error(`Unable to delete test flow:`,e),s.message.error(`Unable to delete test case.`),e}finally{S(null)}}})};return(0,o.useEffect)(()=>{Promise.resolve().then(()=>{if(!m?.id){e(`/select-project`,{replace:!0});return}C({page:1})})},[]),(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:FP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/addTestCase`),children:`Back to Form`})})]}),(0,l.jsx)(`div`,{className:`zt-page zt-page-wide`,children:(0,l.jsxs)(s.Card,{className:`v1-card`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.TableOutlined,{}),(0,l.jsx)(`span`,{children:`Test Flows`})]}),extra:(0,l.jsxs)(PP,{type:`secondary`,children:[a,` row(s)`]}),children:[(0,l.jsxs)(s.Space,{wrap:!0,className:`zt-toolbar`,children:[(0,l.jsx)(s.Input.Search,{allowClear:!0,className:`zt-search-filter`,placeholder:`Search module / key / description`,value:h,onChange:e=>g(e.target.value),onSearch:()=>{v(1),C({page:1})}}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:()=>C(),children:`Refresh`})]}),(0,l.jsx)($m,{listName:`Test Flows`,loading:f,fields:[{label:`Actions`,value:`rowActions`,width:112,fixed:`left`,sorter:!1,render:(t,n)=>(0,l.jsxs)(s.Space,{size:4,className:`zt-row-actions`,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>e(`/addTestCase?edit=${n.id}`)})}),(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{danger:!0,type:`text`,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{}),loading:x===n.id,onClick:()=>w(n)})})]})},{label:`ID`,value:`id`,width:70,fixed:`left`},{label:`Project`,value:`project`,width:130},{label:`Module`,value:`module`,width:130},{label:`Submodule`,value:`submodule`,width:140},{label:`Step`,value:`step_order`,width:70},{label:`Action`,value:`actions`,width:140},{label:`Key`,value:`key`,width:160,ellipsis:!0},{label:`Value`,value:`value`,width:200,ellipsis:!0},{label:`Expected`,value:`expected`,width:180,ellipsis:!0},{label:`Description`,value:`description`,width:180,ellipsis:!0},{label:`Scenario`,value:`scenario`,width:110,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`green`,children:`Positive`}):(0,l.jsx)(s.Tag,{color:`red`,children:`Negative`})},{label:`Active`,value:`active`,width:90,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`blue`,children:`Active`}):(0,l.jsx)(s.Tag,{children:`Inactive`})}],dataSource:r,current:_,pageSize:y,total:a,onPageChange:e=>{v(e),C({page:e})},onPageSizeChange:e=>{v(1),b(e),C({page:1,pageSize:e})},rowSelection:!1,className:`zt-list-plain`})]})})]})}var LP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/test-cases`}];function RP(){return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsx)(n.t,{items:LP}),(0,l.jsx)(Qo,{moduleName:`test-flows`,rowKey:`id`})]})}var{Text:zP}=s.Typography,BP=[{label:`Home`,href:`/`},{label:`LMS Cases`,href:`/lms-cases`}],VP={tags:`regression`,active:1},HP={module:{dbName:`Modules`,formField:`module`,label:`Module`}},UP={key:!1,value:!1,expected:!1};function WP(e,t){return t?e[t]??UP:UP}function GP(e,t){e.setFields(t.map(e=>({name:e,errors:[]})))}function KP(e=[]){return e.map(e=>({value:e,label:e}))}function qP(e=``){return String(e??``).trim()}function JP(e=[]){let t=new Map;return e.forEach(e=>{let n=qP(e?.flow),r=n.toLowerCase();n&&!t.has(r)&&t.set(r,n)}),Array.from(t.values()).map(e=>({value:e,label:e}))}function YP(e=[],t,n){let r=qP(t).toLowerCase(),i=qP(n).toLowerCase();return e.reduce((e,t)=>{let n=qP(t?.module).toLowerCase(),a=qP(t?.flow).toLowerCase();if(n!==r||a!==i)return e;let o=Number(t?.step_order)||0;return Math.max(e,o)},0)+1}function XP({icon:e,title:t}){return(0,l.jsxs)(s.Space,{size:10,align:`center`,children:[(0,l.jsx)(`div`,{className:`v1-section-icon-box`,children:e}),(0,l.jsx)(zP,{strong:!0,className:`v1-section-label`,children:t})]})}function ZP(){let[e]=s.Form.useForm(),[t]=s.Form.useForm(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)([]),[f,p]=(0,o.useState)([]),[m,h]=(0,o.useState)(sP),[g,_]=(0,o.useState)({}),[v,y]=(0,o.useState)(!1),[b,x]=(0,o.useState)(!1),[S,C]=(0,o.useState)({open:!1,typeKey:`module`}),[w,T]=(0,o.useState)(!1),[E,D]=(0,o.useState)(!1),[O,k]=(0,o.useState)(!1),A=(0,d.useNavigate)(),j=HP[S.typeKey],M=(0,o.useMemo)(()=>KP(r),[r]),N=s.Form.useWatch(`module`,e),P=s.Form.useWatch(`flow`,e),F=s.Form.useWatch(`keyword`,e),I=!!qP(N),L=!!qP(P),R=!I,z=!I||!L,B=(0,o.useMemo)(()=>WP(g,F),[g,F]),V=(e,t=[])=>{e===`module`&&i(t)},H=async()=>{y(!0);try{let e=await Vb(HP.module.dbName);i(e?.items??[])}catch(e){console.error(`Unable to load testing options:`,e),s.message.error(`Unable to load testing options.`)}finally{y(!1)}},ee=async()=>{try{let e=await Ub();Array.isArray(e?.options)&&e.options.length>0&&h(e.options),e?.rules&&typeof e.rules==`object`&&_(e.rules)}catch(e){console.error(`Unable to load action field rules:`,e),s.message.error(`Unable to load action validation rules.`)}},U=(0,o.useCallback)(async t=>{let n=qP(t);if(u([]),p([]),e.setFieldsValue({step_order:void 0}),n){x(!0);try{let e=await Yb({limit:1e4,offset:0,module:n}),t=Array.isArray(e?.items)?e.items:[];u(t),p(JP(t))}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{x(!1)}}},[e]),te=(0,o.useCallback)(async(t,n,r)=>{let i=qP(t),a=qP(n);if(!i||!a){e.setFieldsValue({step_order:void 0});return}D(!0);try{e.setFieldsValue({step_order:YP(r,i,a)})}catch(e){console.error(`Unable to load step order:`,e),s.message.error(`Unable to load step order.`)}finally{D(!1)}},[e]);(0,o.useEffect)(()=>{Promise.resolve().then(async()=>{await Promise.all([H(),ee()])})},[]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>U(N))},[U,N]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>te(N,P,a))},[a,te,P,N]);let ne=async t=>{let n={module:qP(t.module),flow:qP(t.flow),step_order:Number(t.step_order),description:qP(t.description),keyword:qP(t.keyword),target:qP(t.target),value:qP(t.value),expected:qP(t.expected),tags:t.tags?qP(t.tags):VP.tags,active:Number(t.active)};k(!0);try{await Jb(n),s.message.success(`LMS case details saved successfully.`),e.resetFields(),u([]),p([])}catch(e){console.error(`Unable to save LMS case:`,e),s.message.error(`Unable to save LMS case.`)}finally{k(!1)}},re=(t,n)=>{e.setFieldsValue({[t]:qP(n)})},ie=t=>{e.setFieldsValue({module:qP(t),flow:void 0,step_order:void 0,keyword:void 0,description:void 0,target:void 0,tags:VP.tags,value:void 0,expected:void 0}),GP(e,[`keyword`,`target`,`value`,`expected`])},ae=t=>{e.setFieldsValue({flow:qP(t),step_order:void 0,keyword:void 0,target:void 0,value:void 0,expected:void 0}),GP(e,[`keyword`,`target`,`value`,`expected`])},W=t=>{let n=WP(g,t);e.setFieldsValue({keyword:qP(t),target:n.key?e.getFieldValue(`target`):void 0,value:n.value?e.getFieldValue(`value`):void 0,expected:n.expected?e.getFieldValue(`expected`):void 0}),GP(e,[`target`,`value`,`expected`])},oe=e=>{let n=HP[e];C({open:!0,typeKey:e}),t.setFieldsValue({name:``,type:n.label})},se=()=>{C(e=>({...e,open:!1})),t.resetFields()},ce=async()=>{try{let n=qP((await t.validateFields()).name),r=await Hb({name:n,type:j.dbName});V(S.typeKey,r?.items??[]),e.setFieldsValue({[j.formField]:n}),s.message.success(`${j.label} added successfully.`),se()}catch(e){if(e?.errorFields)return;console.error(`Unable to save testing option:`,e),s.message.error(`Unable to add ${j.label.toLowerCase()}.`)}finally{T(!1)}};return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:BP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>A(`/lms-home`),children:`View Table`})})]}),(0,l.jsx)(`div`,{className:`v1-page`,children:(0,l.jsxs)(`div`,{className:`v1-page-inner`,children:[(0,l.jsx)(`div`,{className:`v1-page-header`,children:(0,l.jsxs)(s.Space,{align:`center`,size:10,children:[(0,l.jsx)(c.ProfileOutlined,{className:`v1-outer-icon`}),(0,l.jsx)(`div`,{children:(0,l.jsx)(zP,{strong:!0,style:{fontSize:16},children:`Add LMS Case`})})]})}),(0,l.jsx)(Z,{children:(0,l.jsxs)(s.Form,{form:e,className:`v1-form`,layout:`vertical`,colon:!1,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),initialValues:VP,onFinish:ne,autoComplete:`off`,children:[(0,l.jsx)(s.Card,{className:`v1-card`,title:(0,l.jsx)(XP,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`LMS Case Details`}),extra:(0,l.jsx)(zP,{type:`secondary`,className:`v1-card-subtitle`,children:`Module, flow, step order and execution data`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,style:{flex:1},children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:v,optionFilterProp:`label`,placeholder:`Select module`,options:M,onChange:ie})}),(0,l.jsx)(s.Button,{"aria-label":`Add module`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:30},onClick:()=>oe(`module`)})]})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Flow`,name:`flow`,children:(0,l.jsx)(s.AutoComplete,{maxLength:100,allowClear:!0,disabled:R,options:f,placeholder:b?`Loading flows`:`Enter flow`,onChange:ae,filterOption:(e,t)=>t?.value?.toLowerCase().includes(e.toLowerCase())})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,disabled:!0,placeholder:E?`Loading step order`:`Step order`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`keyword`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,disabled:z,optionFilterProp:`label`,placeholder:`Select action`,options:m,onChange:W})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3,maxLength:255,disabled:z,placeholder:`Enter description`,showCount:!0,onBlur:e=>re(`description`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`target`,rules:[{required:B.key,message:`Key is required for this action`}],children:(0,l.jsx)(s.Input,{maxLength:255,disabled:z||!!F&&!B.key,placeholder:z?`Select module and flow first`:F?B.key?`Required — Enter selector / locator`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`target`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Tags`,name:`tags`,children:(0,l.jsx)(s.Input,{maxLength:200,disabled:z,placeholder:`Enter tags`,prefix:(0,l.jsx)(c.TagsOutlined,{className:`v1-input-icon`}),onBlur:e=>re(`tags`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,rules:[{required:B.value,message:`Value is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:z||!!F&&!B.value,placeholder:z?`Select module and flow first`:F?B.value?`Required — Enter value`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`value`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,rules:[{required:B.expected,message:`Expected result is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:z||!!F&&!B.expected,placeholder:z?`Select module and flow first`:F?B.expected?`Required — Enter expected result`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`expected`,e.target.value)})})})]})}),(0,l.jsx)(`div`,{className:`v1-form-actions`,children:(0,l.jsx)(s.Form.Item,{children:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:O,disabled:z,children:`Submit`}),(0,l.jsx)(s.Button,{onClick:()=>{e.resetFields(),u([]),p([])},children:`Reset`})]})})})]})}),(0,l.jsx)(s.Modal,{title:`Add ${j.label}`,open:S.open,confirmLoading:w,okText:`Add`,onCancel:se,onOk:()=>{T(!0),ce()},destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:t,layout:`vertical`,colon:!1,className:`v1-form`,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),children:[(0,l.jsx)(s.Form.Item,{label:`Name`,name:`name`,children:(0,l.jsx)(s.Input,{maxLength:100,placeholder:`Enter ${j.label.toLowerCase()} name`,onBlur:e=>{t.setFieldsValue({name:qP(e.target.value)})}})}),(0,l.jsx)(s.Form.Item,{label:`Type`,name:`type`,children:(0,l.jsx)(s.Input,{disabled:!0})})]})})]})})]})}var QP=[{label:`Home`,href:`/`},{label:`LMS Cases`,href:`/lms-cases`}];function $P(){return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsx)(n.t,{items:QP}),(0,l.jsx)(Qo,{moduleName:`lms-flows`,rowKey:`id`})]})}var eF=[`referenceId`,`ReferenceId`,`candidateId`,`CandidateId`,`entityId`,`EntityId`,`id`,`Id`,`_id`];function tF(e=eF){return function(t){if(!t||typeof t!=`object`)return``;for(let n of e){let e=t[n];if(e!=null&&e!==``)return String(e)}return``}}function nF(e,t=eF){if(!e||typeof e!=`object`)return[];let n=[];for(let r of t){let t=e[r];t!=null&&t!==``&&n.push(String(t))}return n}var rF=tF();function iF(e){return typeof e==`function`?e:typeof e==`string`?tF([e]):Array.isArray(e)?tF(e):rF}function aF(e,t,n){return!t||typeof t!=`object`?e:{...t,...e,id:e?.id??t?.id??n}}function oF(e,t,n={}){return{status:`success`,total:t,data:{data:e,...n}}}var sF=[`fields`,`fieldConfig`,`tabs`,`tabField`,`actionRules`,`actions`,`columnActions`];function cF(e){let t=e?.data??e,n={};for(let r of sF){let i=e?.[r]??t?.[r];i==null||Array.isArray(i)&&i.length===0||(n[r]=i)}return n}var lF=e=>String(e??``).replace(/[^a-zA-Z0-9]/g,``).toLowerCase();function uF(e,t,n){let r=(Array.isArray(n)?n:[n]).map(lF).filter(Boolean),i=r.length?e.findIndex(e=>r.includes(lF(e?.value))||r.includes(lF(e?.label))):-1;if(i===-1)return[...e,...t];let a=Number(e[i]?.order),o=Number.isFinite(a)?t.map((e,n)=>e.order==null||e.order===``?{...e,order:a+(n+1)/(t.length+1)}:e):t;return[...e.slice(0,i+1),...o,...e.slice(i+1)]}var dF=(e,t)=>_i(e,t).rows,fF=(e,t)=>{let{rows:n,total:r}=_i(e,t);return{rows:n,total:r}};function pF(e,t){return function(n,r,i,a={}){return e(t??n,r,i,a)}}function mF(e){return!e||typeof e!=`object`||typeof(e.fetchByKeys??e.fetch??e.function)!=`function`?null:{...e,fetchByKeys:typeof e.fetchByKeys==`function`?e.fetchByKeys:null,fetch:typeof e.fetch==`function`?e.fetch:null,function:typeof e.function==`function`?e.function:null,extractRows:typeof e.extractRows==`function`?e.extractRows:dF,mergeRow:typeof e.mergeRow==`function`?e.mergeRow:aF,fetchById:typeof e.fetchById==`function`?e.fetchById:null}}function hF({fetchSecondaryByKeys:e,fetchSecondary:t,extractSecondaryRows:n,fetchSecondaryById:r,secondaryKey:i,mergeRow:a,secondaryFetchLimit:o}){return!e&&!t&&!r?[]:[mF({key:i,fetchByKeys:e?(t,n,r)=>e(t,n,r):null,function:t?({moduleName:e,options:n})=>t(e,o,0,n):null,extractRows:n,fetchById:r,mergeRow:a})].filter(Boolean)}function gF(e){if(typeof e==`function`)return t=>{let n=e(t);return n==null||n===``?[]:[String(n)]};let t=typeof e==`string`?[e]:Array.isArray(e)&&e.length?e:eF;return e=>nF(e,t)}function _F(e,t){let n=new Map;return e.forEach(e=>{for(let r of t(e))n.has(r)||n.set(r,e)}),n}function vF({moduleName:e,limit:t,offset:n,options:r,keys:i,primaryResponse:a,primaryRows:o,pageRows:s,total:c,source:l}){return{moduleName:e,limit:t,offset:n,options:r,keys:i,primaryResponse:a,primaryRows:o,pageRows:s,total:c,source:l}}async function yF(e,t){if(typeof e.args==`function`){let n=e.args(t);return(e.fetch??e.function??e.fetchByKeys)(...Array.isArray(n)?n:[n])}if(Array.isArray(e.args))return(e.fetch??e.function??e.fetchByKeys)(...e.args);if(e.fetchByKeys&&Array.isArray(t.keys))return e.fetchByKeys(t.moduleName,t.keys,t.options,t);let n=e.fetch??e.function;return typeof n==`function`?n(t):null}function bF({fetchPrimaryPage:e,extractPrimaryPage:t=fF,fetchSecondaryByKeys:n,joinSources:r=[],fetchPrimary:i,extractPrimaryRows:a=dF,fetchSecondary:o,extractSecondaryRows:s=dF,fetchSecondaryById:c,primaryKey:l,secondaryKey:u,mergeRow:d=aF,secondaryFetchLimit:f=200,extraFields:p=[],extraFieldsAfter:m}){let h=Array.isArray(r)&&r.length?r.map(mF).filter(Boolean):hF({fetchSecondaryByKeys:n,fetchSecondary:o,extractSecondaryRows:s,fetchSecondaryById:c,secondaryKey:u,mergeRow:d,secondaryFetchLimit:f}),g=0;async function _(e,t,n,r){if(!e.fetchById||!r)return null;try{let i=await e.fetchById(n,r);return i&&t(i).includes(String(r))?i:null}catch(e){return console.error(`[mergedListApi] per-id join lookup failed for "${r}"`,e),null}}async function v(e,t,n,r,i){if(!n)return e;let a=t.extractRows(n,r)??[],o=iF(t.primaryKey??l),s=gF(t.key),c=_F(a,s);return Promise.all(e.map(async e=>{let n=o(e),a=c.get(n)??(i()?null:await _(t,s,r,n));return t.mergeRow(e,a,n)}))}async function y(e,t,n,r){let i=e;for(let e of t)i=await v(i,e.source,e.response,n,r);return i}function b(e,t,n){let r={};for(let e of n){if(!e)continue;let t=cF(e);for(let e of Object.keys(t))r[e]??(r[e]=t[e])}return p.length&&(r.fields=uF(r.fields??[],p,m)),oF(e,t,r)}async function x({moduleName:e,limit:t,offset:n,options:r,primaryResponse:i,primaryRows:a,pageRows:o,total:s}){return Promise.all(h.map(async c=>{try{let u=iF(c.primaryKey??l),d=[...new Set(o.map(u).filter(Boolean))];return c.fetchByKeys&&d.length===0?{source:c,response:null}:{source:c,response:await yF(c,vF({moduleName:e,limit:t,offset:n,options:r,keys:d,primaryResponse:i,primaryRows:a,pageRows:o,total:s,source:c}))}}catch(e){return console.error(`[mergedListApi] join fetch failed — rendering page without that join`,e),{source:c,response:null}}}))}async function S(n,r,i,a,o){let s=await e(n,r,i,a),c=t(s,n)??{},l=Array.isArray(c.rows)?c.rows:[],u=Number.isFinite(Number(c.total))?Number(c.total):l.length,d=await x({moduleName:n,limit:r,offset:i,options:a,primaryResponse:s,primaryRows:l,pageRows:l,total:u});return b(await y(l,d,n,o),u,[s,...d.map(e=>e.response)])}async function C(e,t,n,r,o){let s=await i(e,t,n,r),c=a(s,e)??[],l=c.length,u=c.slice(n,n+t),d=await x({moduleName:e,limit:t,offset:n,options:r,primaryResponse:s,primaryRows:c,pageRows:u,total:l});return b(await y(u,d,e,o),l,[s,...d.map(e=>e.response)])}return async function(t,n=10,r=0,i={}){let a=++g,o=()=>a!==g;return e?S(t,n,r,i,o):C(t,n,r,i,o)}}function xF(e,t,n={}){return bF({fetchPrimary:()=>AA(e,t),extractPrimaryRows:OA,fetchSecondary:Dn,fetchSecondaryById:jA,secondaryFetchLimit:n.moduleFetchLimit??200})}function SF(e){let t=String(e??``).trim().split(/[^a-zA-Z0-9]+/).filter(Boolean);return t.length?`${t.map((e,t)=>t===0?e.toLowerCase():e[0].toUpperCase()+e.slice(1).toLowerCase()).join(``)}Count`:``}function CF(e){let t=Array.isArray(e?.stages)?e.stages:[];if(!t.length)return e;let n={};for(let e of t){let t=SF(e?.stageName);t&&(n[t]=Number(e?.count)||0)}return{...n,...e}}var wF=e=>{let t=Number(e?.targetSubmission??e?.targetSubmissions);return Number.isFinite(t)&&t>0?t:null};function TF({submittedCountField:e=`submittedCount`,progressField:t=`targetSubmissionProgress`}={}){return function(n,r,i){let a=aF(n,r,i),o=wF(a);return o!=null&&(a[t]=`${Number(a?.[e])||0} of ${o}`),a}}function EF(e={}){let t=TF();return bF({primaryKey:`_id`,extraFields:e.extraFields,extraFieldsAfter:e.extraFieldsAfter,fetchPrimaryPage:Dn,joinSources:[{key:`entityId`,fetchByKeys:(e,t,n,r)=>{let i=Math.max(1,Number(r?.limit)||10);return kA(Math.floor((Number(r?.offset)||0)/i)+1,i)},extractRows:e=>(e?.items??[]).map(CF),mergeRow:(e,n,r)=>{let i=t(e,n,r);return n?._id&&(i.workflowId=n._id),i}}]})}async function DF(e,t=10,n=0,r={},i={}){return _i(await EF(i)(e,t,n,r),e)}async function OF(e,t,n,r=10,i=0,a={}){return _i(await xF(e,t)(n,r,i,a),n)}typeof window<`u`&&(window.__CORE_THEME_BUILD__=`2026-10-22T09:43:43.383Z`);var kF=GM,AF=dx(UN),jF=dx(GN),MF=dx(oP),NF=dx(vP),PF=dx(DP),FF=dx(AP),IF=dx(NP),LF=dx(IP),RF=dx(RP),zF=dx(ZP),BF=dx($P);exports.ADMIN_API_URL=t.v,exports.ADMIN_APP_ID=t.y,exports.APP_ID=t.b,exports.AUTH_URL=t.x,exports.ActivityNotesCard=qc,exports.ActivityTab=Hc,exports.AddBatchCandidatePopup=bM,exports.AddFormV1=Tc,exports.AdminDashboard=GM,exports.AdminDashboardContent=_D,exports.AdminPage=kF,exports.AppAlert=Ec,exports.AppButton=n.ft,exports.AppShell=Pb,exports.ApprovalActionBar=U_,exports.AssigneeAvatars=Jc,exports.AuthGuard=Db,exports.BILLING_STATUS_FLOW=wf,exports.BOOLEAN_API_KEYS=kg,exports.BOOLEAN_PARSEABLE_API_KEYS=mh,exports.BULK_UPLOAD_DEFAULT_ACCEPT=Yc,exports.BULK_UPLOAD_DEFAULT_MAX_SIZE_MB=Xc,exports.Breadcrumb=n.t,exports.BulkUploadPage=MF,exports.BulkUploadPanel=il,exports.CANDIDATES_URL=t.S,exports.CONTRACT_C2C=pv,exports.CONTRACT_W2=fv,exports.CURRENCY_SYMBOLS=Du,exports.CalendarCard=A,exports.CoreThemeAdminApp=xD,exports.CoreThemeAdminRoutes=bD,exports.CustomPagination=Be,exports.DEFAULT_HOURS_POLICY=d_,exports.DEFAULT_RESULTS_VIEW=Tg,exports.DayLogModal=F_,exports.DescriptionBlock=_l,exports.DetailHeaderCard=Ep,exports.DetailViewPage=Np,exports.DetailViewV1=Sd,exports.DocumentViewer=n.En,exports.DynamicCards=Rt,exports.DynamicPopup=Hk,exports.DynamicPopupRoute=TM,exports.DynamicTabs=P,exports.EditFormV1=jm,exports.FIELD_TYPE_REGISTRY=Yh,exports.FINANCE_APPROVAL_CONFIG=iv,exports.FINANCE_TYPE_CFO=Z_,exports.FINANCE_TYPE_ONBOARDING_MANAGER=X_,exports.FINANCE_TYPE_ONBOARDING_MANAGER_REAPPROVE=ev,exports.FINANCE_TYPE_ONLY_FINANCE=Q_,exports.FINANCE_TYPE_SUBMISSION_MANAGER=Y_,exports.FINANCE_TYPE_SUBMISSION_MANAGER_REAPPROVE=$_,exports.FileListCard=vy,exports.FinanceApprovalPanel=Zv,exports.FinanceAvatar=ap,exports.FinanceBadge=lp,exports.FinanceDayCell=G_,exports.FinanceDivider=Zf,exports.FinanceEmployeeCell=op,exports.FinanceEmptyState=Jf,exports.FinanceEquation=Qf,exports.FinanceHistoryTimeline=np,exports.FinanceHoursGrid=qf,exports.FinanceKpiRow=Kf,exports.FinanceLine=Xf,exports.FinanceListToolbar=u_,exports.FinanceMarginBadge=up,exports.FinanceMoneyCell=cp,exports.FinanceRecordsTable=pp,exports.FinanceRowChevron=dp,exports.FinanceSection=Yf,exports.FinanceStatusPill=Gf,exports.FinanceTextCell=sp,exports.FinanceTimesheetAnalysis=q_,exports.FinanceWorkflowSteps=$f,exports.HOURS_MESSAGES=f_,exports.Header=qy,exports.HierarchyUserFilter=Ut,exports.JOBS_URL=t.C,exports.LegacyAdminPage=AF,exports.ListView=Qo,exports.LmsHomePage=BF,exports.LmsTestForm=zF,exports.Login=Fb,exports.MailPopup=QD,exports.ManageModules=FF,exports.ManageSubmodules=IF,exports.ModuleRowActions=Bm,exports.NotesPanel=H_,exports.NotesTab=Kc,exports.OPEN_AS_OPTIONS=gg,exports.PAYROLL_STATUS_FLOW=Tf,exports.POPUP_CONFIGS=dM,exports.ParamCardView=qm,exports.ParamListView=$m,exports.PaymentInvoicePopup=FM,exports.PeriodBadgeTag=w_,exports.PreviewPopup=kO,exports.ProjectSelect=ux,exports.ProofUploadPreview=V_,exports.QuickLogBar=R_,exports.QuickLogSelectionBar=I_,exports.RESULTS_VIEW_OPTIONS=wg,exports.RejectionReasonModal=L_,exports.SUBMISSIONS_URL=t.T,exports.SearchBuilderV1=t_,exports.Sidebar=Cb,exports.StatusBadge=r_,exports.StatusBadgeTag=C_,exports.StickyNotesFullPage=jF,exports.StylishDynamicTabs=a_,exports.TemplateEditor=s_,exports.TestForm=NF,exports.TestingHomePage=RF,exports.TimelineGroups=Pc,exports.TimesheetDayCell=M_,exports.TipTapEditor=n.On,exports.UserForm=WM,exports.VendorShareDrawer=kM,exports.ViewSummaryWidget=Ui,exports.WizardPopup=FO,exports.ZinnextTableView=LF,exports.ZinnextTestForm=PF,exports.appNow=n.Mn,exports.applyIntegrationStatus=n.Jn,exports.approveSubmission=be,exports.buildAcceptAttr=tl,exports.buildBooleanRequest=Pg,exports.buildCsv=zf,exports.buildDailyRows=Nf,exports.buildDayGradient=A_,exports.buildRateHistoryEntries=Rv,exports.buildWeeklyRollup=If,exports.clearSelectedProject=t.i,exports.colors=n.jn,exports.computeFinance=Av,exports.computeHoursPolicy=v_,exports.computeMarginBand=Lf,exports.conditionMatches=n.i,exports.configureCoreTheme=t.E,exports.configuredFieldLabel=n.a,exports.createAllWorkflowsListFetcher=EF,exports.createMergedListFetcher=bF,exports.createModuleListFetchAdapter=pF,exports.createWorkflowStageListFetcher=xF,exports.currencySymbol=Ou,exports.defaultMergeRow=aF,exports.deleteIntegrationConfig=n.ar,exports.deriveDayStats=Mf,exports.describeCapacity=b_,exports.downloadCsv=Uf,exports.evaluateShowIfWith=n.o,exports.findEmployerRow=wv,exports.flattenGroups=Sv,exports.formatAmount=Pu,exports.formatApp=n.Nn,exports.formatAppDateTime=n.Pn,exports.formatFileSize=el,exports.formatFinanceMoney=zv,exports.formatHours=hf,exports.formatMoney=Fu,exports.formatPercent=_f,exports.formatRate=Iu,exports.getActivity=n.pn,exports.getAllWorkflowsModuleList=DF,exports.getAppTimeZone=n.Fn,exports.getApprovalDate=xf,exports.getBgcIntegrationConfig=n.Cr,exports.getBgcIntegrationSummary=n.wr,exports.getBillingActionStates=Ef,exports.getBooleanEligibleTypes=tg,exports.getCurrentRoleName=t.c,exports.getFieldLabel=Vf,exports.getFieldType=Zh,exports.getFileExtension=$c,exports.getFinanceApprovalConfig=lv,exports.getFormGroupsRaw=sy,exports.getIntegrationConfig=n.jr,exports.getIntegrationConfigs=n.Mr,exports.getIntegrationSummary=n.Nr,exports.getModuleConfig=Le,exports.getModuleDataDetail=n.hn,exports.getPayrollActionStates=Df,exports.getPeriodBadgeConfig=ze,exports.getSearchPopup=pg,exports.getSelectedProject=t.l,exports.getStoredToken=t.u,exports.getStoredUser=t.d,exports.getUserRoles=t.f,exports.getVMSApprove=xe,exports.getValueStyle=Hf,exports.getWorkflowStageModuleList=OF,exports.getWorkflowSteps=Of,exports.humanizeEvent=bf,Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Cs}}),exports.indexFieldConfig=Bf,exports.initialsOf=vf,exports.insertTokenAtCursor=vh,exports.isBooleanEligible=Qh,exports.isBooleanParsable=gh,exports.isTester=t.p,exports.logout=t.h,exports.marginIncludesReferral=dv,exports.matchLocationTax=kv,Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Vp}}),exports.normalizeContract=Ev,Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return al}}),exports.rateUnitLabel=Au,exports.rateUnitShort=Mu,exports.readActionButtons=bg,exports.reconcileHours=y_,exports.registerFieldType=Xh,exports.registerSearchPopup=fg,exports.rejectSubmission=q,exports.resolveActivityMeta=zc,exports.resolveAndCompute=jv,exports.resolveDayKind=g_,exports.resolveFinanceInputs=Ov,exports.resolveMergeKey=rF,exports.resolveMergedListKey=rF,exports.resolveOpenAs=vg,exports.resolveRejectionReason=uv,exports.resolveResultsSearchPlaceholder=Og,exports.resolveResultsView=Dg,exports.resolveSubmissionFinance=cy,exports.saveBgcIntegrationConfig=n.ri,exports.saveIntegrationConfig=n.si,exports.setSelectedProject=t._,exports.showIfConditions=n.c,exports.stageCountKey=SF,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Ib}}),exports.testIntegrationConnection=n.mi,exports.toApp=n.Ln,exports.toNumber=Nu,exports.tzLabel=n.Rn,exports.tzShortLabel=n.zn,exports.unregisterSearchPopup=mg,exports.useDropdownFields=Un,exports.useDropdownValues=Wi,exports.useEditForm=yy,exports.useFieldConfig=Wn,exports.useFilterFields=Gn,exports.useMenuPermission=sr,exports.useModuleActions=Nm,exports.useRecordRefresh=Ap,exports.validateBooleanQuery=_h,exports.validateBulkFile=nl,exports.withAdminAppId=t.D,exports.withAppId=t.O,exports.withAuthGuard=dx;
20
+ `).trim()}function SO(e){return e.replace(/•/g,`
21
+ `).split(/\n+/).map(e=>e.trim().replace(/^[-–—•]\s*/,``).trim()).filter(Boolean)}function CO(e){return SO(e.replace(/(?:^|\s)[-–—]\s+/g,`
22
+ `))}function wO(e){let t=e.match(/^([A-Za-z][A-Za-z&/ ]{1,28}?)\s*:\s*(\S.+)$/);if(!t)return null;let n=t[1].trim(),r=t[2].trim();return n.split(/\s+/).length>3||r.length>60?null:{fieldKey:n.toLowerCase().replace(/\s+/g,`-`),fieldLabel:yO(n),value:r}}function TO(e){let t=e.toLowerCase().replace(/[\s:.\-–—]+$/,``).trim();return hO.has(t)?gO.test(t)?`education`:_O.test(t)?`keySkills`:`overview`:null}function EO(e){let t=[],n={overview:[],keySkills:[],education:[]},r=`overview`;return e.forEach(e=>{let i=TO(e);if(i){r=i;return}if(r===`overview`){let n=wO(e);if(n){t.push(n);return}}n[r].push(e)}),{meta:t,overview:bO(n.overview),keySkills:bO(n.keySkills),education:bO(n.education)}}function DO(e){let t=[...mO].sort((e,t)=>t.length-e.length),n=RegExp(`\\b(${t.map(vO).join(`|`)})\\b\\s*:?`,`gi`),r=[...e.matchAll(n)];if(!r.length)return{meta:[],overview:bO(CO(e)),keySkills:[],education:[]};let i={overview:[],keySkills:[],education:[]},a=e.slice(0,r[0].index).trim();return a&&i.overview.push(...CO(a)),r.forEach((t,n)=>{let a=t[1].trim().toLowerCase(),o=t.index+t[0].length,s=n+1<r.length?r[n+1].index:e.length,c=CO(e.slice(o,s).trim());if(!c.length)return;let l=gO.test(a)?`education`:_O.test(a)?`keySkills`:`overview`;i[l].push(...c)}),{meta:[],overview:bO(i.overview),keySkills:bO(i.keySkills),education:bO(i.education)}}function OO(e){let t=xO(e);if(!t)return{meta:[],overview:[],keySkills:[],education:[]};let n=SO(t);return n.length>=4?EO(n):DO(t)}function kO({items:e}){return(0,l.jsx)(`ul`,{className:`jdv-ats-bullets`,children:e.map((e,t)=>(0,l.jsx)(`li`,{className:`jdv-ats-bullet-item`,children:e},t))})}function AO({raw:e=``,meta:t=[]}){let[n,r]=(0,o.useState)(!1),i=(0,o.useMemo)(()=>OO(e),[e]),a=t.length?t:i.meta,s=[];if(i.overview.length&&s.push({key:`overview`,title:`Overview`,items:i.overview}),i.keySkills.length&&s.push({key:`keySkills`,title:`Key Skills`,items:i.keySkills,card:!0,icon:`🛠️`}),i.education.length&&s.push({key:`education`,title:`Education`,items:i.education,card:!0,icon:`🎓`}),!a.length&&!s.length)return(0,l.jsx)(fO,{type:`secondary`,children:`No description available.`});let c=n?s:s.slice(0,pO),u=s.length-pO;return(0,l.jsxs)(`div`,{className:`jdv-ats-desc`,children:[a.length>0&&(0,l.jsx)(`div`,{className:`jdv-ats-meta-grid`,children:a.map(({fieldKey:e,fieldLabel:t,value:n})=>(0,l.jsxs)(`div`,{className:`jdv-ats-meta-row`,children:[(0,l.jsx)(`span`,{className:`jdv-ats-meta-key`,children:t}),(0,l.jsx)(`span`,{className:`jdv-ats-meta-val`,children:n})]},e??t))}),(0,l.jsx)(`div`,{className:`jdv-ats-sections`,children:c.map(e=>e.card?(0,l.jsxs)(`div`,{className:`education-block`,children:[(0,l.jsxs)(`div`,{className:`education-header`,children:[(0,l.jsx)(`span`,{children:e.icon}),(0,l.jsx)(`span`,{children:e.title})]}),(0,l.jsx)(`ul`,{className:`education-list`,children:e.items.map((e,t)=>(0,l.jsx)(`li`,{className:`education-list-item`,children:e},t))})]},e.key):(0,l.jsxs)(`div`,{className:`jdv-ats-section`,children:[(0,l.jsx)(`div`,{className:`jdv-ats-section-hd`,children:(0,l.jsx)(`span`,{children:e.title})}),(0,l.jsx)(kO,{items:e.items})]},e.key))}),u>0&&(0,l.jsx)(`span`,{className:`jdv-desc-toggle`,onClick:()=>r(e=>!e),children:n?`Show less`:`Show more (${u} more section${u>1?`s`:``})`})]})}var{Text:jO}=s.Typography;function MO(e){return e?e.trim().split(/\s+/).slice(0,2).map(e=>e[0].toUpperCase()).join(``):`?`}function NO(e){return e?e.name?e.name:e.fullName?e.fullName:e.firstName||e.lastName?[e.firstName,e.lastName].filter(Boolean).join(` `):e.candidateName??e.clientName??e.jobTitle??``:``}function PO(e){return e?e.email??e.emailId??e.emailAddress??``:``}function FO(e){return e?e.status?e.status:e.stage?e.stage:typeof e.isActive==`boolean`?e.isActive?`Active`:`Inactive`:``:``}function IO(e){return e==null||e===``?`-`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?e.join(`, `):typeof e==`object`?e.label??e.name??Object.values(e).join(` `):String(e)}var LO=[`jobDescription`,`description`,`rawDescription`,`jobDescriptionText`];function RO(e){return String(e??``).toLowerCase()===`job`}function zO(e){let t=LO.includes(e.field),n=/description/i.test(e.label??``);return t||n}function BO({record:e}){let t=NO(e),n=PO(e),r=FO(e);return!t&&!n?null:(0,l.jsxs)(`div`,{className:`preview-profile-card`,children:[(0,l.jsxs)(`div`,{className:`preview-profile-card__info`,children:[(0,l.jsx)(s.Avatar,{className:`preview-profile-card__avatar`,children:MO(t)}),(0,l.jsxs)(`div`,{className:`preview-profile-card__text`,children:[t&&(0,l.jsx)(`span`,{className:`preview-profile-card__name`,children:t}),n&&(0,l.jsx)(`span`,{className:`preview-profile-card__email`,children:n})]})]}),r&&(0,l.jsx)(s.Tag,{className:`preview-profile-card__status`,children:r})]})}function VO({fields:e,moduleName:t,centralDocuments:r=[]}){let[i,a]=(0,o.useState)([]),[s,c]=(0,o.useState)(0),[u,d]=(0,o.useState)(!1);if(!e?.length)return null;function f(e){let t=String(e?.type??``).trim().toLowerCase(),n=`${e?.field??``} ${e?.label??``}`;return[`file`,`document`,`upload`].includes(t)||/resume|cv|document|attachment/i.test(n)}function p(e,t){a(e),c(t),d(!0)}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`preview-field-grid`,children:e.map(e=>{let i=e.value,a=Array.isArray(i)&&i.length>0,o=RO(t)&&zO(e)&&typeof i==`string`&&i.trim(),s=f(e)?r.filter(t=>{let n=String(t?.fieldName??t?.field??t?.formField??t?.key??``).trim().toLowerCase(),r=String(e?.field??``).trim().toLowerCase();if(n&&r&&n===r)return!0;let i=`${e?.field??``} ${e?.label??``}`;return/resume|cv/i.test(i)?/resume|cv/i.test(`${n} ${t?.fileName??``} ${t?.name??``}`):!1}).map(t=>({name:t?.fileName||t?.name||t?.uploadedFileName||t?.originalName||e?.label||`Document`,url:t?.fileUrl||t?.downloadUrl||t?.signedUrl||t?.url||``,type:t?.mimeType||t?.contentType||t?.type})).filter(e=>e.url):[],c=f(e)?s.length?s:n.Bt(i).filter(e=>e.url):[];return c.length?(0,l.jsxs)(`div`,{className:`preview-field-card preview-field-card--documents`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`div`,{className:`preview-document-list`,children:c.map((e,t)=>(0,l.jsxs)(`button`,{type:`button`,className:`preview-document-link`,onClick:()=>p(c,t),title:`Preview ${e.name||`document`}`,children:[(0,l.jsx)(`span`,{className:`preview-document-link__icon`,"aria-hidden":`true`,children:`▣`}),(0,l.jsx)(`span`,{className:`preview-document-link__name`,children:e.name||`Document ${t+1}`}),(0,l.jsx)(`span`,{className:`preview-document-link__action`,children:`Preview`})]},`${e.url}-${t}`))})]},e.field??e.label):a?i.map((t,n)=>(0,l.jsxs)(`div`,{className:`preview-field-card`,children:[(0,l.jsxs)(`span`,{className:`preview-field-card__label`,children:[e.label,i.length>1?` (${n+1})`:``]}),(0,l.jsx)(`span`,{className:`preview-field-card__value`,children:IO(t)})]},`${e.field??e.label}-${n}`)):o?(0,l.jsxs)(`div`,{className:`preview-field-card preview-field-card--description`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`div`,{className:`preview-field-card__description`,children:(0,l.jsx)(AO,{raw:i})})]},e.field??e.label):(0,l.jsxs)(`div`,{className:`preview-field-card`,children:[(0,l.jsx)(`span`,{className:`preview-field-card__label`,children:e.label}),(0,l.jsx)(`span`,{className:`preview-field-card__value`,children:IO(i)})]},e.field??e.label)})}),(0,l.jsx)(n.En,{documents:i,open:u,onClose:()=>d(!1),initialIndex:s})]})}function HO(){let e=(0,d.useNavigate)(),{moduleName:t=``,record:r=null}=(0,d.useLocation)().state??{},i=r?.id??r?._id,[c,u]=(0,o.useState)([]),[f,p]=(0,o.useState)(!!(t&&i)),[m,h]=(0,o.useState)(null),[g,_]=(0,o.useState)([]),[v,y]=(0,o.useState)(0),b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)([]),C=(0,o.useRef)([]);(0,o.useEffect)(()=>{if(!t||!i)return;let e=!1;return Promise.all([a.r({module:t,id:i}),n.yn(t,i).catch(()=>({data:[]}))]).then(([t,n])=>{e||(u(Array.isArray(t)?t:[]),_(Array.isArray(n)?n:n?.data??[]),p(!1))}).catch(t=>{e||(h(t.message||`Failed to load preview`),_([]),p(!1))}),()=>{e=!0}},[t,i]);function w(){e(-1)}function T(e,t){return e?.label??e?.name??`Section ${t+1}`}function E(e){let t=b.current,n=C.current[e];if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=(t.querySelector(`.preview-stepper-wrap`)?.offsetHeight??0)+12,o=t.scrollTop+i.top-r.top-a;y(e),t.scrollTo({top:Math.max(0,o),behavior:`smooth`})}function D(){let e=b.current;if(!e||!C.current.length)return;let t=e.getBoundingClientRect().top+(e.querySelector(`.preview-stepper-wrap`)?.offsetHeight??0)+24,n=0;C.current.forEach((e,r)=>{e&&e.getBoundingClientRect().top<=t&&(n=r)}),y(e=>e===n?e:n)}(0,o.useEffect)(()=>{let e=x.current,t=S.current[v];if(!e||!t)return;let n=t.offsetLeft-(e.clientWidth-t.offsetWidth)/2,r=Math.max(0,e.scrollWidth-e.clientWidth);e.scrollTo({left:Math.min(Math.max(0,n),r),behavior:`smooth`})},[v,c.length]);function O(){return c.length?(0,l.jsx)(`div`,{ref:x,className:`preview-stepper-wrap`,"aria-label":`Preview sections`,children:(0,l.jsx)(`div`,{className:`preview-stepper`,children:c.map((e,t)=>(0,l.jsxs)(`div`,{className:`preview-stepper__segment`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`preview-stepper__item`,ref:e=>{S.current[t]=e},onClick:()=>E(t),"aria-current":v===t?`step`:void 0,title:`Go to ${T(e,t)}`,children:[(0,l.jsx)(`span`,{className:[`preview-stepper__circle`,t<v?`preview-stepper__circle--done`:``,t===v?`preview-stepper__circle--active`:``].filter(Boolean).join(` `),children:t+1}),(0,l.jsx)(`span`,{className:[`preview-stepper__label`,t===v?`preview-stepper__label--active`:``].filter(Boolean).join(` `),children:T(e,t)})]}),t<c.length-1&&(0,l.jsx)(`span`,{className:[`preview-stepper__line`,t<v?`preview-stepper__line--done`:``].filter(Boolean).join(` `),"aria-hidden":`true`})]},e.name??e.id??t))})}):null}let k=(0,l.jsxs)(`div`,{className:`preview-modal-header`,children:[(0,l.jsx)(`span`,{className:`preview-modal-module`,children:t.toUpperCase()}),(0,l.jsx)(`span`,{className:`preview-modal-title`,children:t?` Details`:`Preview`})]}),A=(0,l.jsx)(`div`,{className:`wizard-footer preview-scroll-footer`,children:(0,l.jsx)(`div`,{className:`wizard-footer-nav`,children:(0,l.jsx)(s.Button,{onClick:w,children:`Close`})})});function j(){return!t||!i?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:`Preview id is missing.`}):f?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:(0,l.jsx)(s.Spin,{size:`small`})}):m?(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status job-preview-error`,children:m}):c.length?(0,l.jsx)(`div`,{className:`preview-section-list`,children:c.map((e,n)=>(0,l.jsxs)(`section`,{ref:e=>{C.current[n]=e},className:`preview-section-card`,"data-section-index":n,children:[(0,l.jsxs)(`div`,{className:`preview-section-card__header`,children:[(0,l.jsx)(`span`,{className:`preview-section-card__number`,children:n+1}),(0,l.jsx)(`span`,{className:`preview-section-card__title`,children:T(e,n)})]}),(0,l.jsx)(`div`,{className:`preview-section-card__body`,children:e.fields?.length>0?(0,l.jsx)(VO,{fields:e.fields,moduleName:t,centralDocuments:g}):(0,l.jsx)(jO,{type:`secondary`,children:`No fields in this group.`})})]},e.name??e.id??n))}):(0,l.jsx)(`div`,{className:`job-preview-content job-preview-status`,children:`No form groups found.`})}return(0,l.jsx)(s.Modal,{centered:!0,className:`wizard-modal preview-modal preview-scroll-modal`,footer:A,open:!0,title:k,width:`min(900px, calc(100vw - 32px))`,onCancel:w,maskClosable:!1,children:(0,l.jsxs)(`div`,{ref:b,className:`wizard-body preview-scroll-body`,onScroll:D,children:[!f&&!m&&c.length>0&&O(),r&&(0,l.jsx)(BO,{record:r}),j()]})})}var{Text:UO}=s.Typography,{TextArea:WO}=s.Input,GO=[{key:`basic`,title:`Basic Info`,description:`General details`,fields:[{name:`firstName`,label:`First Name`,type:`input`,required:!0,placeholder:`Enter first name`,span:12},{name:`lastName`,label:`Last Name`,type:`input`,required:!0,placeholder:`Enter last name`,span:12},{name:`email`,label:`Email Address`,type:`input`,required:!0,placeholder:`Enter email address`,rules:[{type:`email`,message:`Please enter a valid email`}]},{name:`phone`,label:`Phone`,type:`input`,placeholder:`Enter phone number`}]},{key:`details`,title:`Details`,description:`Additional info`,fields:[{name:`role`,label:`Role`,type:`select`,required:!0,placeholder:`Select a role`,span:12,options:[{label:`Developer`,value:`developer`},{label:`Designer`,value:`designer`},{label:`Manager`,value:`manager`},{label:`Analyst`,value:`analyst`}]},{name:`department`,label:`Department`,type:`select`,placeholder:`Select department`,span:12,options:[{label:`Engineering`,value:`engineering`},{label:`Product`,value:`product`},{label:`Operations`,value:`operations`},{label:`Finance`,value:`finance`}]},{name:`notes`,label:`Notes`,type:`textarea`,placeholder:`Any additional notes...`}]},{key:`confirm`,title:`Confirm`,description:`Review & submit`,isReview:!0}];function KO(e){switch(e.type){case`select`:return(0,l.jsx)(s.Select,{placeholder:e.placeholder,options:e.options,style:{width:`100%`}});case`textarea`:return(0,l.jsx)(WO,{rows:3,placeholder:e.placeholder});case`number`:return(0,l.jsx)(s.InputNumber,{placeholder:e.placeholder,style:{width:`100%`}});default:return(0,l.jsx)(s.Input,{type:e.inputType||`text`,placeholder:e.placeholder})}}function qO({steps:e,form:t}){let n=t.getFieldsValue(),r=e.filter(e=>!e.isReview);return r.some(e=>(e.fields||[]).some(e=>n[e.name]!==void 0&&n[e.name]!==``))?(0,l.jsxs)(`div`,{className:`wizard-review-content`,children:[r.map(e=>(0,l.jsxs)(`div`,{className:`wizard-review-section`,children:[(0,l.jsx)(UO,{className:`wizard-review-section-title`,children:e.title}),(0,l.jsx)(`div`,{className:`wizard-review-grid`,children:(e.fields||[]).map(e=>{let t=n[e.name],r=t===void 0||t===``||t===null?`—`:String(t);return(0,l.jsxs)(`div`,{className:`wizard-review-row`,children:[(0,l.jsx)(`span`,{className:`wizard-review-label`,children:e.label}),(0,l.jsx)(`span`,{className:`wizard-review-separator`,children:`:`}),(0,l.jsx)(`span`,{className:`wizard-review-value`,children:r})]},e.name)})})]},e.key)),(0,l.jsxs)(`div`,{className:`wizard-review-confirm-note`,children:[(0,l.jsx)(c.CheckCircleOutlined,{className:`wizard-review-confirm-icon`}),(0,l.jsx)(UO,{type:`secondary`,children:`Please review the information above before submitting.`})]})]}):(0,l.jsx)(`div`,{className:`wizard-review-empty`,children:(0,l.jsx)(UO,{type:`secondary`,children:`No data entered yet.`})})}function JO(){let[e]=s.Form.useForm(),t=(0,d.useNavigate)(),{title:n=`Wizard`,moduleName:r=``,steps:i=GO,onSubmit:a}=(0,d.useLocation)().state??{},[c,u]=(0,o.useState)(0),f=i[c],p=c===i.length-1,m=c===0;function h(){t(-1)}function g(){let t=(f.fields||[]).map(e=>e.name);e.validateFields(t.length>0?t:void 0).then(()=>{u(e=>e+1)})}function _(){u(e=>e-1)}function v(){let n=e.getFieldsValue();typeof a==`function`&&a(n),t(-1)}let y=i.map((e,t)=>({title:e.title,description:e.description,status:t<c?`finish`:t===c?`process`:`wait`})),b=r?`${n} — ${r}`:n;return(0,l.jsxs)(s.Modal,{open:!0,title:b,footer:(0,l.jsxs)(`div`,{className:`wizard-footer`,children:[(0,l.jsx)(s.Button,{onClick:h,children:`Cancel`}),(0,l.jsxs)(`div`,{className:`wizard-footer-nav`,children:[!m&&(0,l.jsx)(s.Button,{onClick:_,children:`Back`}),p?(0,l.jsx)(s.Button,{type:`primary`,onClick:v,children:`Submit`}):(0,l.jsx)(s.Button,{type:`primary`,onClick:g,children:`Next`})]})]}),onCancel:h,width:`min(680px, calc(100vw - 32px))`,centered:!0,className:`wizard-modal`,children:[(0,l.jsx)(`div`,{className:`wizard-steps-container`,children:(0,l.jsx)(s.Steps,{current:c,items:y,size:`small`,className:`wizard-steps`})}),(0,l.jsx)(`div`,{className:`wizard-body`,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,children:[i.filter(e=>!e.isReview).map((e,t)=>(0,l.jsx)(`div`,{style:{display:t===c?`block`:`none`},children:(0,l.jsx)(s.Row,{gutter:16,children:(e.fields||[]).map(e=>(0,l.jsx)(s.Col,{span:e.span||24,children:(0,l.jsx)(s.Form.Item,{name:e.name,label:e.label,rules:[...e.required?[{required:!0,message:`${e.label} is required`}]:[],...e.rules||[]],children:KO(e)})},e.name))})},e.key)),f.isReview&&(0,l.jsx)(qO,{steps:i,form:e})]})})]})}function YO({titleText:e,titleIcon:t}){let n=t===`delete`;return(0,l.jsxs)(`span`,{className:`dynamic-popup__header`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box${n?` dynamic-popup__header-icon-box--danger`:``}`,children:n?(0,l.jsx)(c.DeleteOutlined,{}):(0,l.jsx)(c.AppstoreOutlined,{})}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:e})]})}function XO({note:e,description:t,showSelectedCount:r,count:i,itemLabel:a,bodyText:o,deleteError:s}){return(0,l.jsxs)(l.Fragment,{children:[e&&(0,l.jsx)(n.kn,{variant:`body`,color:`secondary`,className:`dynamic-popup__note`,children:e}),t&&(0,l.jsx)(n.kn,{variant:`body`,className:`dynamic-popup__description`,children:t}),r&&i>0&&(0,l.jsxs)(n.kn,{variant:`body`,className:`dynamic-popup__selected-count`,children:[`Changing status for `,(0,l.jsx)(`strong`,{children:i}),` selected `,a,`.`]}),o&&(0,l.jsx)(n.kn,{variant:`body`,children:o}),s&&(0,l.jsx)(n.kn,{variant:`caption`,color:`danger`,className:`dynamic-popup__error`,children:s})]})}function ZO({footerNote:e}){return e?(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,className:`dynamic-popup__footer-note`,children:e}):null}function QO(e,t){return e.replace(/\{(\w+)\}/g,(e,n)=>t?.[n]??``).trim()}function $O(e){return String(e).replace(/\(\s*\)/g,``).replace(/\s+/g,` `).replace(/(^|\s)([-–—·|])(?=\s*\2)/g,``).replace(/^[\s\-–—·|]+/,``).replace(/[\s\-–—·|]+$/,``).trim()}function ek(e){if(!e)return!1;let t=new Date(e).getTime();return Number.isNaN(t)||t<=0?!1:t<=Date.now()+864e5}function tk(e){if(!ek(e))return``;let t=new Date(e),n=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=new Date,i=Math.round((n(r)-n(t))/864e5);if(i<=0)return`Today`;if(i===1)return`Yesterday`;if(i<=30)return`${i} days ago`;let a=(r.getFullYear()-t.getFullYear())*12+(r.getMonth()-t.getMonth());if(r.getDate()<t.getDate()&&--a,a=Math.max(1,a),a<12)return`${a} month${a===1?``:`s`} ago`;let o=Math.floor(a/12);return`${o} year${o===1?``:`s`} ago`}function nk(e){let t=Array.isArray(e?.submissionHistory)?e.submissionHistory:[],n=[e?.lastSubmittedAt,e?.submittedAt,e?.updatedAt,...t.map(e=>e?.submittedAt||e?.updatedAt)].filter(Boolean);return n.length?n.reduce((e,t)=>new Date(t)>new Date(e)?t:e):null}function rk(e){let t=Array.isArray(e?.submissionHistory)?e.submissionHistory:[],n=[e?.lastSubmittedAt,e?.submittedAt,...t.map(e=>e?.submittedAt)].filter(Boolean);return n.length?n.reduce((e,t)=>new Date(t)>new Date(e)?t:e):null}function ik(e,t){if(typeof e==`string`)return{label:e,value:e};if(e?.label!==void 0&&e?.value!==void 0&&!t?.labelTemplate&&!t?.valueKey)return e;let{labelKey:n,valueKey:r,labelTemplate:i}=t??{},a=i?.includes(`{lastdate}`)?{...e,lastdate:tk(nk(e))}:e,o=(i?$O(QO(i,a)):null)||(n?e?.[n]:null)||e?.name||e?.fullName||e?.candidateName||e?.title||e?.displayName||e?.text||e?.applicantReferenceId||e?.applicantRefrenceId||String(Object.values(e||{})[0]??``),s=(r?e?.[r]:null)??e?.id??e?._id??e?.applicantReferenceId??e?.applicantRefrenceId??String(Object.values(e||{})[0]??``),c=e?.disabled===!0||e?.disable===!0,l=String(e?.optionNote??``).trim(),u={label:l?`${String(o)} — ${l}`:String(o),value:String(s),_raw:e};if(c&&(u.disabled=!0),l&&(u.title=l),e?.isSubmitted===!0||e?.alreadySubmitted===!0){u.alreadySubmitted=!0,u.existingSubmissionId=String(e?.existingSubmissionId??e?.jobSubmissionId??e?.submissionId??``);let t=e?.submittedAt||rk(e);t&&(u.submittedAt=t)}if(e?.isFromSubmission===!0&&e?.submissionId){u.isFromSubmission=!0,u.priorSubmissionId=String(e.submissionId);let t=e?.lastSubmittedAt||rk(e);t&&(u.priorSubmittedAt=t)}return u}function ak(e,t){return(t?.[e.optionsKey]??e.defaultOptions??[]).map(t=>ik(t,e))}function ok(e={}){return{selectedIds:[],selectedRecords:[],moduleName:``,removedIds:[],...e}}var sk=`DD MMM YYYY`,ck=`DD MMM YYYY, h:mm A`;function lk(e,t){if(e==null||e===``)return``;let n=(0,u.default)(e);return n.isValid()?t===`relative`?tk(e)||(ek(e)?n.format(sk):`Not updated`):ek(e)?n.format(sk):``:String(e)}function uk(e,t){return e?String(e).includes(`{`)?$O(QO(e,t)):String(t?.[e]??e).trim():``}function dk(e){if(e?.alreadySubmitted){let t=e?.submittedAt?(0,u.default)(e.submittedAt):null;return{tone:`blocked`,tooltip:t?.isValid()?`Already submitted to this job on ${t.format(ck)}`:`Already submitted to this job — a candidate can only be submitted once per job`}}if(e?.isFromSubmission){let t=e?.priorSubmittedAt?(0,u.default)(e.priorSubmittedAt):null;return{tone:`history`,tooltip:t?.isValid()?`Previously submitted on ${t.format(ck)} — this form will prefill from it`:`Submitted to another job before — this form will prefill from it`}}return null}function fk(e,t){return e?.alreadySubmitted||!e?.disabled?``:String(t?.message??e?.title??``).trim()}function pk({meta:e}){return(0,l.jsx)(`div`,{className:`dynamic-popup__option-dates`,children:e.map(e=>(0,l.jsxs)(o.Fragment,{children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-date-label`,children:e.label}),(0,l.jsx)(`span`,{className:`dynamic-popup__option-date-value`,children:e.text})]},e.label))})}function mk({option:e,layout:t}){let n=e?._raw??e??{},r=uk(t.id,n),i=uk(t.title,n)||String(e?.label??``),a=uk(t.subtitle,n),o=uk(t.titleAccent?.key,n),u=uk(t.titleAccent?.toneKey,n),d=t.titleAccent?.prefix??``,f=(t.meta??[]).map(e=>({label:e.label,text:lk(n?.[e.key],e.type)})).filter(e=>e.text),p=fk(e,n),m=dk(e);return(0,l.jsxs)(`div`,{className:`dynamic-popup__option`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-tick${m?` dynamic-popup__option-tick--${m.tone}`:``}`,children:m&&(0,l.jsx)(s.Tooltip,{title:m.tooltip,placement:`topLeft`,children:(0,l.jsx)(c.CheckCircleFilled,{"aria-label":m.tooltip})})}),(0,l.jsxs)(`div`,{className:`dynamic-popup__option-main`,children:[(0,l.jsxs)(`div`,{className:`dynamic-popup__option-head`,children:[r&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-id`,children:r}),(0,l.jsxs)(`span`,{className:`dynamic-popup__option-title`,children:[(0,l.jsx)(`span`,{className:`dynamic-popup__option-title-text`,children:i}),o&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-title-accent${u?` dynamic-popup__option-title-accent--${u}`:``}`,children:`${d}${o}`})]}),p&&(0,l.jsx)(`span`,{className:`dynamic-popup__option-flag`,children:p})]}),a&&(0,l.jsx)(`div`,{className:`dynamic-popup__option-sub`,children:a})]}),e?.alreadySubmitted?(0,l.jsx)(`span`,{className:`dynamic-popup__option-onjob`,children:`On this job`}):f.length>0&&(0,l.jsx)(pk,{meta:f})]})}var{Text:hk}=s.Typography,{TextArea:gk}=s.Input,_k=[{label:`$`,value:`$`},{label:`EUR`,value:`EUR`},{label:`GBP`,value:`GBP`},{label:`INR`,value:`INR`}],vk=[{label:`Hourly`,value:`Hourly`},{label:`Daily`,value:`Daily`},{label:`Weekly`,value:`Weekly`},{label:`Monthly`,value:`Monthly`},{label:`Yearly`,value:`Yearly`}];function yk(e=[]){return e.map(e=>{if(!e||typeof e!=`object`)return e;let t=[e.value,e.user_id,e.userId,e.USER_ID,e.legacyUserId,e.id,e._id].find(e=>e!=null&&String(e).trim()!==``),n=t==null?``:String(t).trim();return{...e,value:n}}).filter(e=>typeof e!=`object`||!e||String(e.value??``).trim()!==``)}function bk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.Input,{value:t,onChange:n,placeholder:e.placeholder,maxLength:e.maxLength,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function xk({field:e,value:t,onChange:n}){return(0,l.jsx)(gk,{value:t,onChange:n,rows:e.rows??5,placeholder:e.placeholder,maxLength:e.maxLength,showCount:!!e.maxLength})}function Sk({field:e,options:t,value:n,onChange:r}){let i=yk(t);return(0,l.jsx)(s.Select,{showSearch:!0,value:n,onChange:r,options:i,placeholder:e.placeholder,className:`dynamic-popup__field-select`,optionFilterProp:`label`,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function Ck({field:e,options:t,value:n,onChange:r}){let i=yk(t);return(0,l.jsx)(s.Select,{mode:`multiple`,showSearch:!0,value:n,onChange:r,options:i,placeholder:e.placeholder,className:`dynamic-popup__field-select`,optionFilterProp:`label`,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function wk({field:e,options:t,onSearch:n,value:r,onChange:i,popupContext:a}){let o=yk(t),u=e.optionLayout,d=new Map(o.map(e=>[String(e?.value??``),e]));async function f(t,n){if(e.multiple){i?.(Array.isArray(t)?t:[]);return}let r=n??d.get(String(t??``));(typeof e.onSelectGuard!=`function`||await e.onSelectGuard({value:t,option:r,field:e,popupContext:a,confirm:s.Modal.confirm})!==!1)&&i?.(t)}return(0,l.jsx)(s.Select,{mode:e.multiple?`multiple`:void 0,showSearch:!0,filterOption:!1,notFoundContent:e.notFoundContent??null,value:r,onChange:f,options:o,placeholder:e.placeholder,onSearch:n,className:`dynamic-popup__field-select${u?` dynamic-popup__field-select--rich`:``}`,popupClassName:u?`dynamic-popup__option-dropdown`:void 0,listHeight:u?340:void 0,optionLabelProp:`label`,optionRender:u?e=>(0,l.jsx)(mk,{option:e?.data??e,layout:u}):void 0,prefix:(0,l.jsx)(c.CrownOutlined,{})})}function Tk({field:e,mentionOpts:t,onMentionSearch:n,value:r,onChange:i}){let a=Number(e.maxLength)>0?Number(e.maxLength):void 0,o=String(r??``).length;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Mentions,{value:r,onChange:i,rows:e.rows??5,placeholder:e.placeholder,prefix:`@`,options:t,onSearch:n,maxLength:a,className:`dynamic-popup__mention-textarea`}),a?(0,l.jsxs)(`div`,{className:`dynamic-popup__char-count`,style:{textAlign:`right`,fontSize:12,marginTop:4,color:o>a*.9?`#b45309`:`#8c8c8c`},children:[o,` / `,a]}):null]})}function Ek({field:e={},value:t={},onChange:n}){let r=t.period??`Hourly`,i=t.isRange??!1;function a(e){n?.({...t,...e})}(0,o.useEffect)(()=>{let e={};t.currency??(e.currency=`$`),t.period??(e.period=`Hourly`),Object.keys(e).length&&n?.({...t,...e})},[]);let c=Number(i?t.maxAmount:t.amount),u=i&&t.minAmount!=null&&t.maxAmount!=null&&Number(t.maxAmount)<=Number(t.minAmount),d=e.rateCeiling!=null&&Number.isFinite(c)&&c>Number(e.rateCeiling);return(0,l.jsxs)(`div`,{children:[(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[i?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`From`,value:t.minAmount,onChange:e=>a({minAmount:e}),style:{flex:1}}),(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`To`,value:t.maxAmount,onChange:e=>a({maxAmount:e}),style:{flex:1}})]}):(0,l.jsx)(s.InputNumber,{controls:!1,placeholder:`0`,value:t.amount,onChange:e=>a({amount:e}),style:{flex:2}}),(0,l.jsx)(s.Select,{value:t.currency??`$`,options:_k,onChange:e=>a({currency:e}),style:{width:80}}),(0,l.jsx)(s.Select,{value:r,options:vk,onChange:e=>a({period:e}),style:{width:110}})]}),(u||d)&&(0,l.jsxs)(`div`,{style:{marginTop:4},children:[u&&(0,l.jsx)(hk,{type:`danger`,style:{fontSize:12,display:`block`},children:`To rate must be greater than From rate.`}),d&&(0,l.jsxs)(hk,{type:`danger`,style:{fontSize:12,display:`block`},children:[`Rate must not exceed the client rate (`,e.rateCeiling,`).`]})]}),(0,l.jsxs)(s.Space,{size:`small`,style:{marginTop:8},children:[(0,l.jsx)(s.Switch,{checked:i,onChange:e=>a({isRange:e})}),(0,l.jsx)(`span`,{children:`Range`})]})]})}function Dk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.DatePicker,{value:t,onChange:n,placeholder:e.placeholder??`Select date`,style:{width:`100%`},format:`YYYY-MM-DD`})}function Ok({field:e,checked:t,onChange:n}){return(0,l.jsx)(s.Checkbox,{checked:t,onChange:n,children:e.checkboxLabel})}function kk({field:e,value:t,onChange:n}){return(0,l.jsx)(s.InputNumber,{value:t,onChange:n,min:e.min,max:e.max,placeholder:e.placeholder,style:{width:`100%`}})}function Ak({options:e,value:t,onChange:n}){return(0,l.jsx)(s.Radio.Group,{value:t,onChange:n,options:e})}var jk={input:bk,text:bk,textarea:xk,select:Sk,"multi-select":Ck,"search-select":wk,"mention-textarea":Tk,"candidate-rate":Ek,"priority-checkbox":Ok,"date-picker":Dk,number:kk,radio:Ak};function Mk(e){return e===`priority-checkbox`?{valuePropName:`checked`}:{}}var Nk=new Set([`input`,`text`,`textarea`,`mention-textarea`]);function Pk({form:e,fields:t,initialValues:r,dynamicOptions:i,popupContext:a,extraData:o,removedIds:c,setRemovedIds:u,showAlreadyAssigned:d,onValuesChange:f,getSearchHandler:p,getMentionSearchHandler:m,mentionOptions:h}){let g=(o?.recruitersData??[]).filter(e=>{let t=String(e?.user_id??e?.id??e?.userId??``);return t&&!c.includes(t)}),_=d&&o,v=new Set(d?g.map(e=>String(e?.user_id??e?.id??e?.userId??``).trim()).filter(Boolean):[]),y=e=>v.size===0||!Array.isArray(e)?e:e.filter(e=>!v.has(String((e&&typeof e==`object`?e.value??e.id:e)??``).trim()));return!t.length&&!_?null:(0,l.jsxs)(l.Fragment,{children:[_&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`div`,{className:`dynamic-popup__already-assigned`,children:[(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,children:`Already Assigned People`}),(0,l.jsx)(`div`,{style:{marginTop:6,display:`flex`,flexWrap:`wrap`,gap:6},children:g.length===0?(0,l.jsx)(n.kn,{variant:`caption`,color:`secondary`,children:`No one is currently assigned to this job.`}):g.map(e=>{let t=String(e?.user_id??e?.id??e?.userId??``),n=e?.name??e?.user_name??e?.userName??e?.email??`Assigned user`;return(0,l.jsx)(s.Tag,{closable:!0,onClose:()=>{t&&u(e=>Array.from(new Set([...e,t])))},children:n},t||n)})})]}),(0,l.jsx)(s.Divider,{style:{margin:`12px 0`}})]}),t.length>0&&(0,l.jsx)(s.Form,{form:e,layout:`vertical`,initialValues:r,onValuesChange:(e,t)=>f(t),children:Fk(t).map(e=>Ik(e,e=>{let t=y(i[e.name]??ak(e,a)),r=p(e),o=m(e),c=h[e.name]??[],u=Mk(e.type),d=jk[e.type],f=[];return e.required&&f.push({required:!0,message:`${e.label||`This field`} is required`}),typeof e.validator==`function`&&f.push({validator:(t,n)=>{let r=e.validator(n,a);return r?Promise.reject(Error(r)):Promise.resolve()}}),Nk.has(e.type)&&f.push(n.cn({label:e.label,field:e.name,type:e.type,maxLength:e.maxLength})),(0,l.jsx)(s.Form.Item,{name:e.name,label:e.label,rules:f,...u,children:d?(0,l.jsx)(d,{field:e,options:t,onSearch:r,mentionOpts:c,onMentionSearch:o,popupContext:a}):null},e.name)}))})]})}function Fk(e){let t=[];for(let n of e){let e=t[t.length-1];n.inlineRow&&e?.inlineRow===n.inlineRow?e.fields.push(n):t.push({inlineRow:n.inlineRow,fields:[n]})}return t.map(e=>e.fields)}function Ik(e,t){return e.length===1?t(e[0]):(0,l.jsx)(`div`,{style:{display:`flex`,gap:8,alignItems:`flex-start`},children:e.map((e,n)=>(0,l.jsx)(`div`,{style:{flex:n===0?2:1,minWidth:0},children:t(e)},e.name))},`row-${e.map(e=>e.name).join(`-`)}`)}function Lk(e){return[`select`,`multi-select`,`search-select`,`radio`].includes(e?.type)&&e?.dataSource===`master`&&e?.masterName}function Rk(e){let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.data)?t.data:Array.isArray(t?.items)?t.items:Array.isArray(t?.rows)?t.rows:Array.isArray(t?.records)?t.records:[]}function zk(e){let t=String(e?.masterName??``).trim().toLowerCase();return t===`clientsubmissions`||t===`clientsubmissionstatus`}function Bk(e){if(e==null)return null;if(typeof e==`string`){let t=e.trim();return t?{label:t,value:t,_raw:{name:t}}:null}let t=String(e?.name??e?.clientSubmissionStatusText??e?.label??e?.text??``).trim();if(!t)return null;let n=Number(e?.id??e?.uniqueId??e?.clientSubmissionStatusId??e?.value??0)||0;return{label:t,value:t,_raw:{...e,...n>0?{id:n,uniqueId:n}:{},name:t,type:String(e?.type??e?.clientSubmissionStatusType??``).trim(),isInitialStatus:e?.isInitialStatus===!0,isTerminalStatus:e?.isTerminalStatus===!0,allowedNextStatusIds:Array.isArray(e?.allowedNextStatusIds)?e.allowedNextStatusIds.map(Number).filter(e=>Number.isInteger(e)&&e>0):[]}}}function Vk(e,t){return zk(t)?Bk(e):ik(e,t)}function Hk(e){let t=e?.clientSubmissionStatus,n=Number((t&&typeof t==`object`?t?.clientSubmissionStatusId??t?.id??t?.uniqueId:void 0)??e?.clientSubmissionStatusId??e?.clientStatusId??e?.[`clientSubmissionStatus.clientSubmissionStatusId`]??0)||0,r=t&&typeof t==`object`?t?.clientSubmissionStatusText??t?.name??t?.text??t?.label:t;return{id:n,text:String(r??e?.clientSubmissionStatusText??e?.clientStatus??e?.clientStatusText??e?.[`clientSubmissionStatus.clientSubmissionStatusText`]??``).trim()}}function Uk(e){let t=Number(e?.id??0)||0,n=String(e?.text??``).trim();return n&&n.toLowerCase()===`not submitted`?!0:t<=0&&!n}function Wk(e){return Number(e?._raw?.id??e?._raw?.uniqueId??0)||0}function Gk(e){let t=e?._raw?.allowedNextStatusIds;return Array.isArray(t)?t.map(Number).filter(e=>Number.isInteger(e)&&e>0):[]}function Kk(e){let t=e?.data??e;return t?Array.isArray(t)?t[0]??null:t?.record&&typeof t.record==`object`?t.record:t?.data&&typeof t.data==`object`&&!Array.isArray(t.data)?t.data:typeof t==`object`?t:null:null}function qk(e){return(Array.isArray(e?.selectedRecords)?e.selectedRecords.filter(Boolean):[]).some(e=>!Uk(Hk(e)))?!0:!Uk(Hk(e??{}))}async function Jk(e,n){if(qk(e))return e;let r=e?.selectedIds?.[0]??e?.selectedRecords?.[0]?._id??e?.selectedRecords?.[0]?.id;if(!r)return e;let i=String(e?.moduleName??`submissions`).trim()||`submissions`,a=new URLSearchParams({module:i,id:String(r)});n&&a.set(`app_id`,n);try{let r=Kk(await t.o(t.x,`/module-data-detail?${a.toString()}`,{headers:n?{"X-App-Id":n}:void 0}));if(!r)return e;let i=Array.isArray(e?.selectedRecords)?e.selectedRecords:[];return{...e,selectedRecords:i.length?i.map((e,t)=>t===0?{...e,...r}:e):[r]}}catch(t){return console.warn(`[DynamicPopup] Could not load selected submission detail for client status transition:`,t),e}}function Yk(e,t){if(!Array.isArray(e)||!e.length)return[];if(!e.some(e=>e?._raw?.isInitialStatus===!0||e?._raw?.isTerminalStatus===!0||Array.isArray(e?._raw?.allowedNextStatusIds)))return e;let n=Array.isArray(t?.selectedRecords)?t.selectedRecords.filter(Boolean):[],r={clientSubmissionStatus:t?.clientSubmissionStatus,clientSubmissionStatusId:t?.clientSubmissionStatusId,clientSubmissionStatusText:t?.clientSubmissionStatusText,clientStatus:t?.clientStatus,clientStatusId:t?.clientStatusId,clientStatusText:t?.clientStatusText,"clientSubmissionStatus.clientSubmissionStatusId":t?.[`clientSubmissionStatus.clientSubmissionStatusId`],"clientSubmissionStatus.clientSubmissionStatusText":t?.[`clientSubmissionStatus.clientSubmissionStatusText`]},i=n.length?n:[r];return e.filter(t=>i.every(n=>{let i=Hk(n);if(Uk(i)){let e=Hk(r);Uk(e)||(i=e)}if(Uk(i))return t?._raw?.isInitialStatus===!0;let a=e.find(e=>{let t=Wk(e),n=String(e?.label??``).trim();return i.id>0&&t===i.id||i.text&&n.toLowerCase()===i.text.toLowerCase()});return!a||a?._raw?.isTerminalStatus===!0?!1:Gk(a).includes(Wk(t))}))}function Xk({open:e,config:n,api:r,fields:i,popupContext:a,formValues:s}){let[c,l]=(0,o.useState)({}),[u,d]=(0,o.useState)(null);return(0,o.useEffect)(()=>{e||(l({}),d(null))},[e]),(0,o.useEffect)(()=>{if(!e||!n||!r.getOptions)return;let t=new AbortController;return i.forEach(e=>{!e.fetchOptionsKey||e.fetchOptionsParamKey||Promise.resolve(r.getOptions(e,void 0,a)).then(n=>{t.signal.aborted||l(t=>({...t,[e.name]:n}))}).catch(n=>{t.signal.aborted||console.error(`[DynamicPopup] Failed to load options for field "${e.name}":`,n)})}),()=>t.abort()},[e,r,n,i,a]),(0,o.useEffect)(()=>{if(!e||!n)return;let r=i.filter(Lk);if(!r.length)return;let o=new AbortController;return r.forEach(e=>{let n=new URLSearchParams({masterName:e.masterName,offset:`0`,limit:String(e.limit??50)}),r=String(t.b??``).trim();r&&n.set(`app_id`,r),t.o(t.x,`/masters/dropdown?${n.toString()}`,{headers:r?{"X-App-Id":r}:void 0}).then(async t=>{if(o.signal.aborted)return;let n=Rk(t).map(t=>Vk(t,e)).filter(Boolean),i=a;if(zk(e)&&(i=await Jk(a,r)),o.signal.aborted)return;let s=zk(e)?Yk(n,i):n;l(t=>({...t,[e.name]:s}))}).catch(t=>{o.signal.aborted||console.error(`[DynamicPopup] Failed to load master options for field "${e.name}":`,t)})}),()=>o.abort()},[e,n,i,a]),(0,o.useEffect)(()=>{if(!e||!n||!r.getOptions)return;let t=i.filter(e=>e.fetchOptionsKey&&e.fetchOptionsParamKey);if(!t.length)return;let o=new AbortController;return t.forEach(e=>{let t=s[e.fetchOptionsParamKey]??a[e.fetchOptionsParamKey],n={[e.fetchOptionsParamKey]:t};Promise.resolve(r.getOptions(e,n,a)).then(t=>{o.signal.aborted||l(n=>({...n,[e.name]:t}))}).catch(t=>{o.signal.aborted||console.error(`[DynamicPopup] Failed to load param-dependent options for "${e.name}":`,t)})}),()=>o.abort()},[e,r,n,i,s,a]),(0,o.useEffect)(()=>{if(!e||!n||!r.loadExtraData)return;let t=new AbortController;return Promise.resolve(r.loadExtraData(a)).then(e=>{t.signal.aborted||d(e)}).catch(e=>{t.signal.aborted||(console.error(`[DynamicPopup] Failed to load extra data:`,e),d(null))}),()=>t.abort()},[e,r,n,a]),{dynamicOptions:c,setDynamicOptions:l,extraData:u}}var Zk=500,Qk=3;function $k({api:e,open:t,fields:n=[],popupContext:r,setDynamicOptions:i}){let[a,s]=(0,o.useState)({}),c=(0,o.useRef)({}),l=(0,o.useRef)({}),u=(0,o.useRef)({}),d=(0,o.useCallback)((t,n)=>{let a=e.searchOptions??e.searchFetcher;if(typeof a!=`function`)return;l.current[t.name]?.abort();let o=new AbortController;return l.current[t.name]=o,Promise.resolve(a(t,n,r)).then(e=>{if(o.signal.aborted)return;let n=Array.isArray(e)?e:e?.items??e?.list??[];i(e=>({...e,[t.name]:n.map(e=>ik(e,t))}))}).catch(e=>{o.signal.aborted||console.error(`[DynamicPopup] Search failed for field "${t.name}":`,e)}),o},[e,r,i]),f=n.filter(e=>(e.searchFetchKey||e.searchFetcher)&&e.preloadOptions!==!1),p=f.map(e=>e.name).join(`|`),m=(0,o.useRef)({runSearch:d,preloadFields:f});(0,o.useEffect)(()=>{m.current={runSearch:d,preloadFields:f}}),(0,o.useEffect)(()=>{if(!t||!p)return;let{runSearch:e,preloadFields:n}=m.current,r=n.map(t=>e(t,``)).filter(Boolean);return()=>r.forEach(e=>e.abort())},[t,p]);function h(t){if(!t.searchFetchKey&&!t.searchFetcher||typeof(e.searchOptions??e.searchFetcher)!=`function`)return;let n=t.searchMinLength??Qk;return e=>{clearTimeout(c.current[t.name]);let r=e.length<n?``:e;c.current[t.name]=setTimeout(()=>{d(t,r)},Zk)}}function g(t){let n=e.getMentionOptions??e.mentionFetcher;if(typeof n==`function`)return e=>{u.current[t.name]?.abort();let i=new AbortController;u.current[t.name]=i,Promise.resolve(n(t,e,r)).then(e=>{if(i.signal.aborted)return;let n=Array.isArray(e)?e:e?.items??e?.list??[];s(e=>({...e,[t.name]:n.map(e=>({value:e.user_name??e.userName??e.username??String(e),label:e.user_name??e.userName??e.username??String(e)}))}))}).catch(e=>{i.signal.aborted||console.error(`[DynamicPopup] Mention search failed for field "${t.name}":`,e)})}}return{mentionOptions:a,getSearchHandler:h,getMentionSearchHandler:g}}function eA({form:e,config:t,api:n,popupContext:r,resolvedIds:i,dynamicOptions:a,extraData:c,removedIds:l,removalOnlySubmit:u=!1,fields:d,onClose:f,onSubmit:p}){let[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(null);async function v(e){let t={resolvedIds:i,dynamicOptions:a,extraData:c,removedIds:l};if(typeof n.submit==`function`)return n.submit(e,r,t);if(typeof p==`function`)return p(e,r,t)}function y(){if(t){if(!d.length){if(t.mode===`delete`&&typeof n.deleteItems==`function`){h(!0),_(null),Promise.resolve(n.deleteItems(i,r)).then(()=>{s.message.success(t.successMessage||`Deleted successfully`),f({success:!0})}).catch(e=>{let t=e?.message||`Delete failed. Please try again.`;_(t),h(!1),s.message.error(t)});return}if(typeof n.onOk==`function`){h(!0),Promise.resolve(n.onOk(r)).then(()=>f({success:!0})).catch(e=>{let t=e?.message||`Failed. Please try again.`;s.message.error(t),h(!1)});return}if(typeof n.submit==`function`){h(!0),Promise.resolve(v({})).then(e=>{e?.cancelled||e?.navigated||(s.message.success(t.successMessage||`Saved successfully`),f({success:!0}))}).catch(e=>{s.message.error(e?.message||`Failed. Please try again.`)}).finally(()=>h(!1));return}f();return}if(u){h(!0),Promise.resolve(v(e.getFieldsValue())).then(e=>{e?.cancelled||e?.navigated||(s.message.success(t.successMessage||`Saved successfully`),f({success:!0}))}).catch(e=>{s.message.error(e?.message||`Failed. Please try again.`)}).finally(()=>h(!1));return}e.validateFields().then(async e=>{h(!0);try{let n=await v(e);if(n?.cancelled||n?.navigated)return;s.message.success(t.successMessage||`Saved successfully`),f({success:!0})}catch(e){s.message.error(e?.message||`Failed. Please try again.`)}finally{h(!1)}}).catch(()=>{})}}function b(){h(!1),_(null)}return{handleOk:y,confirming:m,deleteError:g,resetSubmitState:b}}function tA({open:e=!0,config:t,context:n={},onClose:r,onSubmit:i,api:a={}}){let[c]=s.Form.useForm(),[d,f]=(0,o.useState)({}),[p,m]=(0,o.useState)([]),h=s.Form.useWatch([],c,{preserve:!0})??{},g=(0,o.useMemo)(()=>ok(n),[n]),{selectedIds:_=[],selectedRecords:v=[],moduleName:y=``}=g,b=(0,o.useMemo)(()=>_.map((e,t)=>{let n=v[t];return n?.id??n?._id??e}),[_,v]),x=(0,o.useMemo)(()=>t?typeof t.getFields==`function`?t.getFields(g):t.fields??[]:[],[t,g]),S=(0,o.useMemo)(()=>{let e={};return x.forEach(t=>{let n=g[t.initialValueKey];!t.initialValueKey||n===void 0||(e[t.name]=t.type===`date-picker`?(0,u.default)(n):n)}),e},[x,g]),{dynamicOptions:C,setDynamicOptions:w,extraData:T}=Xk({open:e,config:t,api:a,fields:x,popupContext:g,formValues:d}),{mentionOptions:E,getSearchHandler:D,getMentionSearchHandler:O}=$k({api:a,open:e,fields:x,popupContext:g,setDynamicOptions:w});function k(e){typeof r==`function`&&r(e)}let A=x.filter(e=>e.required),j=A.every(e=>{let t=h[e.name];return!(t==null||t===``||Array.isArray(t)&&t.length===0||typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).length===0)}),M=(g.removedIds??[]).length,N=p.length>M,P=A.some(e=>{let t=h[e.name];return!(t==null||t===``||Array.isArray(t)&&t.length===0)}),{handleOk:F,confirming:I,deleteError:L,resetSubmitState:R}=eA({form:c,config:t,api:a,popupContext:g,resolvedIds:b,dynamicOptions:C,extraData:T,removedIds:p,removalOnlySubmit:!!t?.allowRemovalOnlySubmit&&N&&!P,fields:x,onClose:k,onSubmit:i});(0,o.useEffect)(()=>{e&&(c.resetFields(),f(S??{}),m(g.removedIds??[]),R())},[e,S]);let z=!!t?.autoSubmitWhenNoFields&&x.length===0;(0,o.useEffect)(()=>{!e||!z||F()},[e,z]);let B=_.length,V=String(y).replace(/s$/i,``),H=B===1?V:y,ee=v[0]??{},U=t?.getTitleText?t.getTitleText(B,H,ee,g):t?.title,te=B===1?ee.jobTitle??ee.title??ee.name??ee.fullName??ee.candidateName??null:null,ne=t?.getBodyText?t.getBodyText(B,V,H,te,g):t?.bodyText??null,re=typeof t?.getNote==`function`?t.getNote(g):t?.note,ie=t?.disabledUntilFilled&&!j&&!N;if(!t||!e||z)return null;let ae=t.component;return ae?(0,l.jsx)(s.Modal,{open:e,title:t.title||t.getTitleText?(0,l.jsx)(YO,{titleText:U,titleIcon:t.titleIcon}):null,footer:null,width:t.width??760,centered:!0,maskClosable:!1,onCancel:()=>k(),className:`dynamic-popup${t.className?` ${t.className}`:``}`,children:(0,l.jsx)(ae,{context:g,selectedIds:b,selectedRecords:v,moduleName:y,onClose:k})}):(0,l.jsxs)(s.Modal,{open:e,title:(0,l.jsx)(YO,{titleText:U,titleIcon:t.titleIcon}),okText:t.okText||`OK`,cancelText:t.cancelText??`Cancel`,onOk:F,onCancel:()=>k(),okButtonProps:{danger:t.okButtonDanger,disabled:ie,loading:I},cancelButtonProps:{disabled:I},closable:!I,maskClosable:!1,width:t.width??480,centered:!0,className:`dynamic-popup${t.className?` ${t.className}`:``}`,children:[(0,l.jsx)(XO,{note:re,description:t.description,showSelectedCount:t.showSelectedCount,count:B,itemLabel:H,bodyText:ne,deleteError:L}),(0,l.jsx)(ZO,{footerNote:t.footerNote}),(0,l.jsx)(Pk,{form:c,fields:x,initialValues:S,dynamicOptions:C,popupContext:g,extraData:T,removedIds:p,setRemovedIds:m,showAlreadyAssigned:t.showAlreadyAssigned,onValuesChange:f,getSearchHandler:D,getMentionSearchHandler:O,mentionOptions:E})]})}var nA={mode:`delete`,getTitleText:(e,t)=>`Delete ${e>0?`${e} `:``}${t}`,titleIcon:`delete`,okText:`Delete`,okButtonDanger:!0,width:420,getBodyText:(e,t,n,r)=>r?`Are you sure you want to delete the ${r} ${t}?`:e>1?`Are you sure you want to delete ${e} selected ${n}?`:`Are you sure you want to delete this ${t}?`,footerNote:`This action cannot be undone.`,fields:[]},rA={deleteItems:async(e,t)=>{await re(t.moduleName,e)}},iA=new Map;async function aA(e){return e?(iA.has(e)||iA.set(e,a.r({module:e}).catch(t=>(iA.delete(e),console.warn(`[in-progress gate] could not read ${e} form groups:`,t),[]))),iA.get(e)):[]}function oA(e=[],t){return e.some(e=>{let r=n.C(e,t);return r&&r.severity!==`allow`})}async function sA({targetModule:e,sourceModule:t,recordId:r,region:i}={}){let o={severity:`allow`,message:``,group:null};if(!e||!t||!r)return o;let s=i??n.Un().region;try{let i=await aA(e);if(!oA(i,s))return o;let c=await a.r({module:t,id:r}),l={};for(let e of c){let t=e?.payloadKey||e?.name;t&&Array.isArray(e?.rows)&&(l[t]=e.rows)}return n.D(i,s,l)}catch(e){return console.warn(`[in-progress gate] check skipped:`,e),o}}var cA=`Already submitted`,lA=`submissions`,uA=`candidates`,dA=864e5,fA=90,pA=`This candidate was created or last updated more than 90 days ago. Only candidates created or updated within the last 90 days can be selected. Please update this candidate first.`,mA=[`createdAt`,`createdDate`,`dateCreated`,`created_on`,`createdOn`],hA=[`updatedAt`,`updatedDate`,`lastUpdatedAt`,`lastUpdatedDate`,`modifiedAt`,`modifiedDate`];function gA(e,t){for(let n of t){let t=e?.[n];if(!t)continue;let r=new Date(t);if(!Number.isNaN(r.getTime()))return r}return null}function _A(e){return gA(e,mA)}function vA(e){return gA(e,hA)}function yA(e){if(!(e instanceof Date)||Number.isNaN(e.getTime()))return null;let t=e=>new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();return Math.max(0,Math.floor((t(new Date)-t(e))/dA))}function bA(e){return e===null?``:e<=14?`green`:e<=89?`yellow`:`red`}function xA(e,t=fA){if(!e)return!1;let n=Date.now()-t*dA,r=_A(e),i=vA(e),a=r&&r.getTime()>=n,o=i&&i.getTime()>=n;return!a&&!o}function SA(e){let t=_A(e);if(!t)return{createdAgo:``,createdAgoTone:``};let n=tk(t);return n?{createdAgo:n,createdAgoTone:bA(yA(t))}:{createdAgo:``,createdAgoTone:``}}function CA(e){return{...e,...SA(e),isStaleCandidate:xA(e)}}function wA(e){return String(e?.applicantId??e?._id??e?.id??``)}var TA=null;async function EA(){return TA||=n.zr(uA).then(e=>e?.strategies?.duplicateCheck?.editRoute??``).catch(()=>``),TA}async function DA(e){let t=wA(e);if(!t)return``;let n=await EA();return n?n.replace(/:(_?id)\b/g,encodeURIComponent(t)):``}async function OA({option:e,popupContext:t,confirm:n}){let r=e?._raw??e??{},i=wA(r);if(i){let e=await sA({targetModule:lA,sourceModule:uA,recordId:i});if(e.severity===`block`)return new Promise(t=>{n({title:`This candidate cannot be submitted`,content:e.message,okText:`Pick someone else`,cancelText:`Close`,onOk:()=>t(!1),onCancel:()=>t(!1)})})}if(!xA(r))return!0;let a=t?.navigate;return!a||!i?!1:new Promise(e=>{n({title:`Candidate update required`,content:pA,okText:`OK`,cancelText:`Cancel`,onOk:async()=>{let t=await DA(r);t&&a(t),e(!1)},onCancel:()=>e(!1)})})}function kA(e,t,n){return{...e,label:`${e.label} - ${cA}`,disabled:!0,title:`${cA}${t?` (submission ${t})`:``}`,alreadySubmitted:!0,existingSubmissionId:t||``,...n?{submittedAt:n}:{}}}var AA={searchOptions:async(e,t,n)=>{if(e.searchFetchKey===`quickSubmitJobList`){let e=n.selectedRecords?.[0]??{},r=e.id??e._id??n.selectedIds?.[0],i,a=!0;try{i=await Ce({searchQuery:t,candidateId:r})}catch{a=!1;let e=await Ln({searchQuery:t,candidateId:r});i=Array.isArray(e?.data)?e.data:[]}let o=i.map(e=>({label:[e.jobReferenceId??e.clientJobReferenceId,e.jobTitle].filter(Boolean).join(` - `)||String(e._id??``),value:e._id??``,_raw:e}));if(a)return o.map(e=>{if(e._raw?.isSubmitted||e._raw?.alreadySubmitted)return kA(e,e._raw?.jobSubmissionId||``,e._raw?.submittedAt||``);if(e._raw?.disable){let t=String(e._raw?.message??``).trim();return{...e,disabled:!0,label:t?`${e.label} - ${t}`:e.label,title:t}}return e});let s=await Te({applicantId:r,jobIds:o.map(e=>e.value)}).catch(()=>new Map);return o.map(e=>{let t=s.get(String(e.value));return t?kA(e,t.submissionId,t.submittedAt):e})}if(e.searchFetchKey===`quickSubmitCandidates`){let e=n.selectedRecords?.[0]??{},r=n.jobId??e.jobId??e.id??e._id??n.selectedIds?.[0],i,a=new Map;try{i=await we({search:t,jobId:r})}catch{let e=await is({isFromSubmission:n.isFromSubmission,jobId:r,submissionId:n.submissionId,search:t});i=Array.isArray(e)?e:[],a=await Te({jobId:r,applicantIds:i.map(wA)}).catch(()=>new Map)}return i.map(e=>CA(e)).map(e=>{let t=a.get(wA(e));if(!(t||e?.isSubmitted===!0||e?.alreadySubmitted===!0))return e;let n=t?.submissionId||e?.jobSubmissionId||``,r=t?.submittedAt||e?.submittedAt||``;return{...e,disabled:!0,optionNote:cA,isSubmitted:!0,alreadySubmitted:!0,existingSubmissionId:n,...r?{submittedAt:r}:{}}})}return[]},submit:async(e,t,n)=>{let{navigate:r,selectedRecords:i=[],selectedIds:a=[],moduleName:o}=t,s=i[0]??{},c,l;t.jobId?(c=t.jobId,l=s.id??s._id??a[0]??``):o===`candidate`?(c=e.jobId??``,l=s.id??s._id??a[0]??``):(c=s.jobId??s.id??s._id??a[0]??``,l=e.candidate??``);let u=n?.dynamicOptions?.candidate?.find(e=>wA(e?._raw)===String(l)),d=n?.dynamicOptions?.jobId?.find(e=>String(e?.value)===String(c)),f=u?._raw?.isSubmitted||u?._raw?.alreadySubmitted||d?.alreadySubmitted||d?._raw?.isSubmitted||d?._raw?.alreadySubmitted;if(!c||!l)throw Error(`Select both a job and a candidate to quick submit.`);if(xA(u?._raw))throw Error(pA);let p=await sA({targetModule:lA,sourceModule:uA,recordId:l});if(p.severity===`block`)throw Error(p.message);let m=f,h=u?._raw?.existingSubmissionId||u?._raw?.jobSubmissionId||d?.existingSubmissionId||d?._raw?.jobSubmissionId||``;try{let e=await Se({jobId:c,applicantId:l});m||=!!e?.exists,h=e?.submissionId||h}catch(e){throw Error(`Could not verify existing submissions (${e?.message??`request failed`}). Please try again.`,{cause:e})}if(m)throw Error(`This candidate is already submitted for this job${h?` (submission ${h})`:``}.`);let g=new URLSearchParams;l&&g.set(`candidateId`,l);let _=u?.priorSubmissionId||u?._raw?.submissionId||d?.priorSubmissionId||d?._raw?.submissionId||``;_?(g.set(`submissionId`,String(_)),g.set(`isFromSubmission`,`true`)):g.set(`isFromSubmission`,`false`);let v=ts(rs({jobId:c,applicantId:l}).catch(()=>[]));return r(`/submission-create/${c}?${g.toString()}`,{state:{relevantSkillsToken:v}}),{navigated:!0}}},jA={title:`Submit`,okText:`Submit`,width:640,disabledUntilFilled:!0,autoSubmitWhenNoFields:!0,getNote:e=>e.moduleName===`candidate`?`Note: Select a job to submit this candidate.`:`Note: Select a candidate to submit for this job`,getFields:e=>e.jobId?[]:e.moduleName===`candidate`?[{name:`jobId`,label:`Job list`,type:`search-select`,required:!0,placeholder:`Search Job ID / job name - or pick a recent job`,searchFetchKey:`quickSubmitJobList`,optionLayout:{id:`{jobReferenceId}`,title:`{jobTitle}`,subtitle:`{clientJobReferenceId}`,meta:[{label:`Created`,key:`createdAt`,type:`date`},{label:`Updated`,key:`updatedAt`,type:`relative`}]}}]:[{name:`candidate`,label:`Candidate`,type:`search-select`,required:!0,placeholder:`Search candidate name / email - or pick a recent candidate`,optionsKey:`candidateOptions`,searchFetchKey:`quickSubmitCandidates`,labelTemplate:`{applicantRefrenceId} - {firstName} {lastName} - {createdAgo}`,valueKey:`applicantId`,optionLayout:{id:`{applicantRefrenceId}`,title:`{firstName} {lastName}`,titleAccent:{key:`createdAgo`,toneKey:`createdAgoTone`,prefix:` - `},subtitle:`{designation} - {email}`,meta:[{label:`Created`,key:`createdAt`,type:`date`},{label:`Updated`,key:`updatedAt`,type:`relative`}]},onSelectGuard:OA}]},MA={title:`Add Notes & Share`,okText:`Save & Share`,width:480,fields:[{name:`notes`,label:`Notes`,type:`mention-textarea`,required:!0,rows:5,maxLength:2e3,placeholder:`Add your notes on the job. Use '@' to mention someone.`,mentionFetchKey:`mentionUsers`}]},NA=e=>e?.data??e;async function PA({relatedId:e,notes:n,title:r,notesFor:i}){return NA(await yn(t.x,`/notes`,{method:`POST`,body:JSON.stringify({relatedId:e,notes:n,title:r,notesFor:i})}))}var FA={getMentionOptions:async(e,t)=>ae(t),submit:async(e,t)=>{let n=Array.isArray(t.selectedIds)?t.selectedIds[0]:t.selectedIds;if(!n)throw Error(`Please select a record before adding a note.`);await PA({relatedId:String(n),notes:e.notes,notesFor:t.moduleName})}},IA={name:`jobId`,label:`Job Title / ID`,type:`search-select`,multiple:!0,required:!0,placeholder:`Minimum 3 characters`,searchFetchKey:`tagToJobJobList`,valueKey:`_id`,labelTemplate:`{jobReferenceId} - {jobTitle}`},LA={name:`hiringStage`,label:`Hiring stage`,type:`select`,required:!0,optionsKey:`hiringStageOptions`,defaultOptions:[{label:`Shortlisted`,value:`shortlisted`},{label:`Pipeline`,value:`pipeline`}],initialValueKey:`hiringStage`},RA={title:`Tag to Job`,okText:`Tag`,width:480,disabledUntilFilled:!0,autoSubmitWhenNoFields:!0,getFields:e=>e.jobId&&e.hiringStage?[]:e.jobId?[LA]:[IA,LA]},zA=e=>e?.data??e;function BA(e){return Array.isArray(e)&&e.every(e=>e&&typeof e==`object`&&`Key`in e)?e.reduce((e,{Key:t,Value:n})=>(e[t]=n,e),{}):e}function VA(e){return e?Array.isArray(e.data)?e.data.map(BA):e.stage&&Array.isArray(e.stage.data)?e.stage.data.map(BA):Array.isArray(e)?e.map(BA):[]:[]}async function HA(e=1,n=10){let r=await t.o(t.x,`/workflow/list/all?page=${e}&limit=${n}`),i=zA(r),a=Array.isArray(i)?i:i?.data??[];return{items:a,total:Number(r?.total??i?.total)||a.length,page:e,limit:n}}async function UA(e,n){let r=zA(await t.o(t.x,`/workflow/${e}/stage/${n}`));return Array.isArray(r)?{data:r}:r}async function WA(e,n){if(!e||!n)return null;try{let r=new URLSearchParams({module:e,limit:`1`,offset:`0`,scope:`allJobs`,filters:JSON.stringify([{field:`_id`,op:`in`,values:[String(n)],operator:`and`}])}),i=zA(await t.o(t.x,`/module-data-list?${r}`));if(Array.isArray(i))return i[0]??null;if(i?.data&&Array.isArray(i.data))return i.data[0]??null;let a=i?.rows??i?.records??i?.items??i?.list;return Array.isArray(a)?a[0]??null:i??null}catch(t){return console.error(`[getModuleRecordById] failed: ${e}/${n}`,t),null}}async function GA(e){return zA(await t.o(t.C,`/source/workflow-instance`,{method:`POST`,body:JSON.stringify(e)}))}var KA={pipeline:`pipeline`,goodfited:`goodfited`,contacted:`contacted`,submitted:`submitted`,shortlisted:`shortlisted`,interviewinprogress:`interviewInprogress`,selected:`selected`},qA=`Already submitted`;function JA(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&t!==``)return t}}function YA(e){let t=String(e??``).trim();return t?KA[t.toLowerCase()]??t:``}function XA(e,t=``){return String(JA(e,`candidateId`,`candidate_id`,`applicantId`,`applicantID`,`applicantReferenceId`,`applicantRefrenceId`,`_id`,`id`)??t??``)}function ZA(e){return String(JA(e,`_id`,`id`,`candidateId`,`candidate_id`,`applicantId`,`applicantID`)??``)}function QA(e,t,n){let r=String(e.jobTitle??``).trim();return{...e,jobTitle:r?`${r} (${qA})`:`(${qA})`,disabled:!0,title:qA,alreadySubmitted:!0,existingSubmissionId:t||``,...n?{submittedAt:n}:{}}}function $A(e,t){let n=String(t??``).trim();return n?/already submitted/i.test(n)?`${e} (${qA})`:/fulfilled/i.test(n)?`${e} (Fullfilled)`:`${e} (${n})`:e}function ej(e){let t=String(e.jobReferenceId??e.clientJobReferenceId??``).trim(),n=String(e.jobTitle??``).trim();return{...e,jobReferenceId:t,jobTitle:n}}function tj(e){return rj(e).map(e=>e.id)}function nj(e,t=``){return(JA(e,`candidateName`,`candidate_name`,`fullName`,`name`)??[JA(e,`firstName`,`first_name`),JA(e,`lastName`,`last_name`)].filter(Boolean).join(` `)??t)||`Unknown candidate`}function rj(e){let t=Array.isArray(e?.selectedIds)?e.selectedIds:[],n=Array.isArray(e?.selectedRecords)?e.selectedRecords:[],r=[],i=new Set,a=Math.max(t.length,n.length);for(let e=0;e<a;e+=1){let a=n[e]??{},o=t[e]?String(t[e]):``,s=XA(a,o);!s||i.has(s)||(i.add(s),r.push({id:s,name:nj(a,o),record:a,selectedId:o||s}))}return r}function ij(e,t){return Array.isArray(e?.jobId)?e.jobId.map(String).filter(Boolean):e?.jobId?[String(e.jobId)]:Array.isArray(t?.jobId)?t.jobId.map(String).filter(Boolean):t?.jobId?[String(t.jobId)]:[]}function aj(e,t=``){let n=String(e?.jobTitle??e?._raw?.jobTitle??``).trim();if(n)return n;let r=String(e?.label??e?._raw?.label??``).trim();return r.includes(` - `)?r.split(` - `).slice(1).join(` - `).trim():r||String(t??``)}function oj(e,t=``){return aj(e,t)}function sj(e,t,n){let r=[...new Set(ij(e,t))],i=Array.isArray(n?.dynamicOptions?.jobId)?n.dynamicOptions.jobId:[],a=new Map(i.map(e=>[String(e?._id??e?.value??``),e]));return r.map(e=>{let t=a.get(String(e))??{};return{id:String(e),label:oj(t,e),record:t}})}function cj(e){return e.filter(e=>e.blockedCandidates.length>0).map(e=>`${e.job.label} - ${e.blockedCandidates.map(e=>e.name).join(`, `)}`).join(` | `)}function lj(e){return e.filter(e=>e.allowedCandidates.length>0).map(e=>`${e.job.label} - ${e.allowedCandidates.map(e=>e.name).join(`, `)}`).join(` | `)}function uj(e,t){let n=ZA(e);if(!n)return null;let r=nj(e,t)||void 0,i={candidateId:String(n),candidateName:r,phone:JA(e,`phone`,`phoneNumber`,`phone_number`,`mobile`,`mobileNumber`,`mobile_number`),source:JA(e,`source`,`sourceType`,`candidateSource`,`profileSource`),submittedAt:JA(e,`submittedAt`,`lastSubmittedAt`,`updatedAt`),remarks:JA(e,`remarks`,`comment`,`comments`,`notes`),assignedRecruiter:JA(e,`assignedRecruiter`,`recruiterName`,`ownerName`,`assignedToName`),screeningStatus:JA(e,`screeningStatus`,`screening.status`,`screeningResult`),screeningScore:JA(e,`screeningScore`,`screening.score`,`score`),assignedDate:JA(e,`assignedDate`,`assignedAt`,`createdAt`)};return Object.fromEntries(Object.entries(i).filter(([,e])=>e!=null&&e!==``))}var dj={searchOptions:async(e,t,n)=>{if(e.searchFetchKey===`tagToJobJobList`){let e=tj(n),r=e.length===1?e[0]:``,i,a=!1;if(r)try{i=await Ce({searchQuery:t,candidateId:r}),a=!0}catch{a=!1}Array.isArray(i)||(i=await ie(t));let o=i.map(ej);if(a)return o.map(e=>{if(e?.isSubmitted||e?.alreadySubmitted)return QA(e,e?.jobSubmissionId||e?.submissionId||``,e?.submittedAt||``);if(e?.disable){let t=String(e?.message??``).trim();return{...e,jobTitle:e.jobTitle?$A(e.jobTitle,t):`(${t})`,disabled:!0,optionNote:t,title:t}}return e});if(!r)return o;let s=await Te({applicantId:r,jobIds:o.map(e=>e._id).filter(Boolean)}).catch(()=>new Map);return o.map(e=>{let t=s.get(String(e._id));return t?QA(e,t.submissionId,t.submittedAt):e})}return[]},submit:async(e,t,r)=>{let i=YA(e.hiringStage??t.hiringStage),a=rj(t),o=sj(e,t,r);if(!o.length||!a.length)return{cancelled:!0};let s=[];for(let e of o){let t=await Te({jobId:e.id,applicantIds:a.map(e=>e.id)}).catch(()=>new Map);s.push({job:e,blockedCandidates:a.filter(e=>t.has(String(e.id))),allowedCandidates:a.filter(e=>!t.has(String(e.id)))})}let c=cj(s),l=lj(s),u=s.filter(e=>e.allowedCandidates.length>0);if(!u.length)return await n.Wt({tone:`duplicate`,title:`Selected candidates are already submitted`,body:`Every selected candidate is already submitted to the selected jobs. Choose different jobs to continue.`,facts:[{label:`Blocked combinations`,value:c}],okText:`Close`}),{cancelled:!0};if(s.some(e=>e.blockedCandidates.length>0)&&!await n.Ut({tone:`duplicate`,title:`Some candidate-job combinations are already submitted`,body:`Those combinations will be skipped. Continue tagging the remaining valid combinations?`,facts:[{label:`Will be skipped`,value:c},{label:`Will be tagged`,value:l}],okText:`Tag remaining`,cancelText:`Cancel`,footnote:`Already submitted combinations will be left unchanged.`}))return{cancelled:!0};for(let e of u){for(let t of e.allowedCandidates){let n=uj(t.record??{},t.selectedId);await GA({jobId:e.job.id,module:`jobs`,currentStage:i,...n?{candidateDetails:n}:{}})}await ce({jobId:e.job.id,candidateIds:e.allowedCandidates.map(e=>e.selectedId||e.id),hiringStage:i})}}},fj={title:`Change Status`,okText:`Apply`,width:420,showSelectedCount:!0,fields:[{name:`status`,label:`New Status`,type:`select`,required:!0,placeholder:`Select a status`,dataSource:`master`,masterName:`clientSubmissions`,labelKey:`name`,valueKey:`name`,initialValueKey:`currentStatus`,defaultOptions:[{label:`Active`,value:`active`},{label:`Inactive`,value:`inactive`},{label:`Pending`,value:`pending`},{label:`Closed`,value:`closed`}]}]};function pj(e,t){let n=String(e??``).trim().toLowerCase();return(Array.isArray(t?.status)?t.status:[]).find(e=>String(e?.value??``).trim().toLowerCase()===n||String(e?.label??``).trim().toLowerCase()===n||String(e?._raw?.name??``).trim().toLowerCase()===n)??null}var mj={submit:async(e,t,n)=>{let r=pj(e.status,n?.dynamicOptions),i=r?._raw??{},a={clientSubmissionStatusText:String(i.name??r?.label??e.status??``).trim(),clientSubmissionStatusId:Number(i.id??i.uniqueId??0)||0,clientSubmissionStatusType:String(i.type??``).trim()};await ne(t.moduleName,t.selectedIds,a)}},hj={getTitleText:e=>`Remove ${e>1?`${e} Candidates`:`Candidate`} from Shortlist`,titleIcon:`delete`,okText:`Remove`,okButtonDanger:!0,width:420,getBodyText:e=>e>1?`Are you sure you want to remove ${e} selected candidates from the shortlist?`:`Are you sure you want to remove this candidate from the shortlist?`,footerNote:`The candidate will be moved back to the pipeline.`,fields:[]},gj={onOk:async e=>{await Ee({jobId:e.jobId??e.selectedIds[0],candidateIds:e.selectedIds})}},_j={title:`Add to Groups`,description:`Select a group to add the selected candidate(s) to`,okText:`Add to Group`,width:480,disabledUntilFilled:!0,fields:[{name:`groupId`,label:`Group`,type:`select`,required:!0,placeholder:`Select a group`,fetchOptionsKey:`candidateGroups`}]},vj={getOptions:async e=>e.fetchOptionsKey===`candidateGroups`?le():[],submit:async(e,t,{dynamicOptions:n})=>{let r=(n.groupId??[]).find(t=>String(t.value)===String(e.groupId));await ue({candidateIds:t.selectedIds,groupId:e.groupId,groupName:r?.label??``})}},yj=[{title:`Name`,key:`name`,render:(e,t)=>t.name||`${t.first_name??``} ${t.last_name??``}`.trim()||t.user_name||`Assigned user`},{title:`Role`,dataIndex:`role_name`,key:`role`,render:e=>e||`-`},{title:`Reporting`,dataIndex:`reporting_name`,key:`reporting`,render:e=>e||`-`}];function bj({selectedIds:e,onClose:t}){let n=e?.[0],[r,i]=(0,o.useState)(!0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)({assignedUsers:[],totalSubmissions:0,message:``}),[p,m]=(0,o.useState)([]);(0,o.useEffect)(()=>{let e=!1;return i(!0),Promise.all([G(n).catch(t=>(e||s.message.error(t?.message??`Failed to load self-assign details`),{assignedUsers:[],totalSubmissions:0,message:``})),me(n).catch(()=>({recruitersData:[]}))]).then(([t,n])=>{e||(f(t),m(Array.isArray(n?.recruitersData)?n.recruitersData:[]))}).finally(()=>{e||i(!1)}),()=>{e=!0}},[n]);let h=async()=>{u(!0);try{await de({jobIds:[n]}),s.message.success(`Job assigned successfully`),t?.({success:!0})}catch(e){s.message.error(e?.message??`Failed to assign job`)}finally{u(!1)}};if(r)return(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})});let g=p.map(e=>({user_id:e.recruiterId??e.id??e.user_id,name:e.name??``,role_name:e.role_name??e.roleName??``,reporting_name:e.reporting_name??e.reportingName??``})),_=new Map(g.map(e=>[String(e.user_id??``),e])),v=(d.assignedUsers?.length??0)>0?d.assignedUsers.map(e=>{let t=e.user_id??e.userId??e.recruiterId??e.id,n=_.get(String(t??``))??{};return{...e,user_id:t,name:n.name||e.name||``,role_name:n.role_name||e.role_name||e.roleName||``,reporting_name:n.reporting_name||e.reporting_name||e.reportingName||``}}):g,y=v.length>0;return(0,l.jsxs)(`div`,{className:`self-assign-popup-body`,children:[y?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{style:{fontWeight:700,marginBottom:8},children:`Team Members Allocated`}),(0,l.jsx)(s.Table,{columns:yj,dataSource:v,pagination:!1,rowKey:e=>e.user_id??`${e.first_name}-${e.last_name}`,size:`small`,className:`mb-3 no-header-bg`,scroll:{y:200}}),(0,l.jsxs)(`div`,{className:`warning-card`,style:{display:`flex`,alignItems:`center`,gap:8,marginTop:12},children:[(0,l.jsx)(c.ExclamationCircleFilled,{style:{color:`#faad14`,fontSize:18}}),(0,l.jsx)(`div`,{style:{fontSize:13},children:`These users are already assigned to this job. Do you still want to assign yourself as well?`})]})]}):(0,l.jsx)(`div`,{style:{padding:`8px 0`},children:d.message||`No one is currently assigned to this job. Do you want to assign yourself?`}),(0,l.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:12,marginTop:24},children:[(0,l.jsx)(s.Button,{size:`small`,onClick:()=>t?.(),disabled:a,children:`No`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,onClick:h,loading:a,children:`Yes`})]})]})}bj.propTypes={selectedIds:f.default.array,onClose:f.default.func};var xj={title:`Self Assign`,width:480,className:`self-assign-modal`,component:bj},Sj={submit:async()=>{}};function Cj(e={}){let t=Array.isArray(e.jobPayDetails)?e.jobPayDetails[e.jobPayDetails.length-1]:e.jobPayDetails??e.clientBudget??{},n=Number(t.clientBudgetEnd),r=Number(t.clientBudgetStart);return Number.isFinite(n)&&n>0?n:Number.isFinite(r)&&r>0?r:null}var wj={getTitleText:(e,t,n)=>{let r=n?.jobTitle||n?.title||``;return r?`Assign - ${r}`:`Assign`},okText:`Assign`,width:520,disabledUntilFilled:!0,showAlreadyAssigned:!0,allowRemovalOnlySubmit:!0,getFields:e=>(Cj(e?.selectedRecords?.[0]??{}),[{name:`assignToUserId`,label:`Assign to`,type:`multi-select`,required:!0,placeholder:`Select recruiter(s)`,fetchOptionsKey:`assignToUsers`}])},Tj={getOptions:async e=>e.fetchOptionsKey===`assignToUsers`?pe():[],loadExtraData:async e=>me(e.selectedIds[0]),submit:async(e,t,{removedIds:n,extraData:r})=>{await ve({jobIds:t.selectedIds,userId:e.assignToUserId,removedIds:n,existingRecruiters:r?.recruitersData})}},Ej={title:`Add Sticky Notes`,getTitleText:(e,t,n,r)=>r.editingNoteId?`Edit Sticky Notes`:`Add Sticky Notes`,okText:`Save`,width:480,fields:[{name:`heading`,label:`Heading`,type:`input`,required:!0,placeholder:`Enter heading`,initialValueKey:`editingHeading`},{name:`targetDate`,label:`Target Date`,type:`date-picker`,required:!1,initialValueKey:`editingTargetDate`},{name:`comments`,label:`Comments`,type:`mention-textarea`,required:!0,rows:5,placeholder:`Enter your note here... Use '@' to mention someone.`,mentionFetchKey:`mentionUsers`,initialValueKey:`editingComments`}]},Dj={getMentionOptions:async(e,t)=>ae(t),submit:async(e,t)=>{let n=e.targetDate?e.targetDate.toISOString():``;t.editingNoteId?await oe(t.editingNoteId,{title:e.heading,targetDate:n,notes:e.comments}):await W({relatedIds:t.selectedIds,module:t.moduleName,title:e.heading,targetDate:n,notes:e.comments}),window.dispatchEvent(new Event(`sticky-notes:refresh`))}},Oj={title:`Move to Onboarding`,bodyText:`Are you sure you want to move this candidate to onboarding?`,okText:`Yes`,cancelText:`No`,width:420,successMessage:`Moved to onboarding successfully`,successNavigate:`/onboarding`,fields:[{name:`sendOnboardingEmail`,type:`priority-checkbox`,checkboxLabel:`Send Onboarding Email`}]},kj={submit:async(e,t)=>{await ye({submissionId:t.selectedRecords?.[0]?.submissionId,isMail:e.sendOnboardingEmail})}};function Aj(e){return Array.isArray(e)?e[e.length-1]??{}:e&&typeof e==`object`?e:{}}var jj={USD:`$`,INR:`₹`,EUR:`€`,GBP:`£`};function Mj(e,t,n){let r=Aj(e?.[t])[n];if(r!=null&&r!==``)return r;let i=e?.[`${t}.${n}`];return i!=null&&i!==``?i:void 0}function Nj(e){let t=e.selectedRecords?.[0]??{},n=Mj(t,`candidateRate`,`candidateAcceptedRate`)??Mj(t,`candidateBudget`,`candidateBudgetStart`);if(n===void 0||Number(n)===0)return null;let r=Mj(t,`candidateRate`,`candidateAcceptedCurrency`)??Mj(t,`candidateBudget`,`candidateBudgetCurrency`);return{amount:n,symbol:Mj(t,`candidateRate`,`candidateAcceptedCurrencySymbol`)??Mj(t,`candidateBudget`,`candidateBudgetCurrencySymbol`)??jj[String(r??``).toUpperCase()]??(r||`$`),unit:Mj(t,`candidateRate`,`candidateAcceptedPayUnit`)??Mj(t,`candidateBudget`,`candidateBudgetUnit`)??``}}var Pj={title:`Approve Rate`,okText:`Approve`,width:520,className:`medium-modal`,successMessage:`Rate approved`,getBodyText:(e,t,n,r,i)=>{let a=Nj(i);return`Candidate Rate: ${a?`${a.symbol}${a.amount}${a.unit?`/${a.unit}`:``}`:`-`}`},fields:[{name:`candidateProposedRate`,label:`Proposed Rate`,type:`number`,required:!0,placeholder:`Amount`,min:0,inlineRow:`proposedRate`,validator:(e,t)=>{if(e==null||e===``)return;let n=Nj(t);if(n&&Number(e)<=Number(n.amount))return`Proposed rate must be greater than Candidate Rate`}},{name:`candidateProposedRateCurrency`,label:`Currency`,type:`select`,required:!0,inlineRow:`proposedRate`,defaultOptions:[{label:`$ USD`,value:`$`},{label:`₹ INR`,value:`₹`},{label:`€ EUR`,value:`€`}]},{name:`candidateProposedRateUnit`,label:`Unit`,type:`select`,required:!0,inlineRow:`proposedRate`,defaultOptions:[{label:`Year`,value:`yr`},{label:`Month`,value:`mo`},{label:`Week`,value:`wk`},{label:`Hour`,value:`hr`},{label:`Daily`,value:`day`}]},{name:`submitVia`,label:`Submit Via`,type:`radio`,required:!0,defaultOptions:[{label:`Mail`,value:`Mail`},{label:`VMS`,value:`VMS`}]}]},Fj={submit:async(e,t)=>{let n=t.selectedIds[0];if(await be(n,{candidateProposedRate:e.candidateProposedRate,candidateProposedRateCurrency:e.candidateProposedRateCurrency,candidateProposedRateUnit:e.candidateProposedRateUnit,submitVia:e.submitVia}),e.submitVia===`VMS`)try{await xe(n)}catch{s.message.warning(`Approved. VMS notification could not be sent — use Send Mail to notify the client.`)}else s.message.info(`Approved — use Send Mail to notify the client.`)}};async function Ij(e,n={}){let r=t.u();if(!r){let e=Error(`Authentication required`);throw e.status=401,e}let i=await fetch(`${t.T}${e}`,{...n,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${r}`,...n.headers}});if(i.status===401&&t.h(),!i.ok){let e=Error(`API ${i.status}: ${i.statusText}`);throw e.status=i.status,e}return i.json()}async function Lj(e){let t=await Ij(`/mail-form?${new URLSearchParams({submissionId:e,submissionType:`manager`}).toString()}`);return t.data??t}function Rj(e){return Array.isArray(e)?e[e.length-1]:e}function zj(e={}){let t=Rj(e?.proposedRate)?.candidateProposedRate??e?.candidateProposedRate??e?.proposedRateValue,n=Number(t);return Number.isFinite(n)?n:0}function Bj(e,t={}){let n=Rj((e?.record?.job??e?.job??t?.job??{})?.jobPayDetails)??{},r=e?.record?.submission??t??{},i=Rj(r?.clientBudget)??r?.clientBudget??{},a=n?.clientBudgetEnd??n?.clientBudgetStart??i?.clientBudgetEnd??i?.clientBudgetStart,o=Number(a);return Number.isFinite(o)?o:0}function Vj(e={}){let t=String(e?.currencyRaw??``).trim().toUpperCase(),n=String(e?.currency??``).trim();return n&&!/^[A-Z]{3}$/i.test(n)?n:t===`USD`||n.toUpperCase()===`USD`?`$`:t===`INR`||n.toUpperCase()===`INR`?`₹`:t===`EUR`||n.toUpperCase()===`EUR`?`€`:t===`GBP`||n.toUpperCase()===`GBP`?`£`:n||t}function Hj(e={}){return String(e?.rateUnit??`hr`).trim().replace(/^\/+/,``)||`hr`}function Uj(e,t={}){let n=Number(e);return Number.isFinite(n)?`${Vj(t)}${n}/${Hj(t)}`:``}function Wj(e,t,n){if(n==null||n===``)return String(e??``);let r=String(e??``),i=String(n),a=!1,o=RegExp(`(<(?:td|th)[^>]*>[\\s\\S]*?${t}[\\s\\S]*?</(?:td|th)>\\s*<(?:td|th)[^>]*>)([\\s\\S]*?)(</(?:td|th)>)`,`gi`);r=r.replace(o,(e,t,n,r)=>(a=!0,`${t}${i}${r}`));let s=RegExp(`(<(?:strong|b)[^>]*>\\s*${t}\\s*:?\\s*</(?:strong|b)>\\s*)([\\s\\S]*?)(?=</(?:li|p|div)>)`,`gi`);if(r=r.replace(s,(e,t)=>(a=!0,`${t}${i}`)),!a){let e=RegExp(`(${t}\\s*:?[ \\t]*)([^<\\r\\n]*)`,`gi`);r=r.replace(e,(e,t)=>`${t}${i}`)}return r}function Gj(e,t,n,r,i){let a=Number(n?.proposedRate),o=Number.isFinite(a)?a:zj(t),s=Number(n?.clientJobRate),c=Number.isFinite(s)&&s>0?s:Bj(r,i),l={proposedRate:o,jobBillRate:c},u=String(e??``).replace(/{{\.?((?:proposedRate)|(?:jobBillRate))}}/g,(e,t)=>{let n=l[t];return n==null?e:String(n)});return u=Wj(u,`(?:Proposed\\s*Rate|Pay\\s*Rate)`,Uj(o,n)),u=Wj(u,`(?:Job\\s*)?Bill\\s*Rate`,Uj(c,n)),u}function Kj(...e){return e.map(e=>e==null?``:String(e).trim()).find(Boolean)??``}var qj=(e,t)=>!!e&&e.toLowerCase()===Kj(t).toLowerCase();function Jj(e,t,n){let r=Kj(t.submittedBy);return Kj(qj(r,n)||qj(r,e.submitSource)||qj(r,e.supplierName)||qj(r,e.source)||qj(r,e.candidateSource)?``:r,e.signatureEmail)}function Yj(e,t={}){let n=t.employerName??e.supplierName??e.submitSource;return{client:t.clientName??e.clientName,role:t.jobTitle??e.jobTitle??e.designation,reqId:t.reqId??e.jobClientRefrenceId??e.mspReqId??e.submissionId,name:t.candidateName||[e.firstName,e.lastName].filter(Boolean).join(` `)||e.candidateFullName,location:t.jobLocation??e.city??e.currentLocation??e.jobLocation,vendor:n,submittedBy:Jj(e,t,n),submittedAt:t.createdAt??e.createdAt,email:t.email??e.email,employerLocation:t.employerLocation,employerName:t.employerName}}function Xj(e){let t=e?.$oid??e?._id?.$oid??e?._id??e?.id?.$oid??e?.id??e;if(t==null||typeof t==`object`)return``;let n=String(t).trim();return/^[a-f\d]{24}$/i.test(n)?n:``}function Zj(...e){for(let t of e){let e=[t?.jobId,t?.JobId,t?.job_id,t?.jobDetails?._id,t?.jobDetails?.id,t?.job?._id,t?.job?.id,t?.submission?.jobId,t?.submission?.JobId,t?.submission?.job_id,t?.submission?.jobDetails?._id,t?.submission?.jobDetails?.id,t?.submission?.job?._id,t?.submission?.job?.id,t?.recordMeta?.jobId,t?.recordMeta?.JobId,t?.recordMeta?.job_id,t?.submission?.recordMeta?.jobId,t?.submission?.recordMeta?.JobId,t?.submission?.recordMeta?.job_id].map(Xj).find(Boolean);if(e)return e}return``}function Qj(e){if(!e?.referralId)return{};let t=Number(e.referralRate??e.referalRate??0)||0,n=String(e.referralType??e.referalType??`RECURRING`).trim()||`RECURRING`,r=e.referralId??e.referalId;return{referralId:r,referalId:r,referralRate:t,referalRate:t,referralType:n,referalType:n,referralEnabled:!0,referalEnabled:!0,isReferralApplicable:!0,referralDetails:{referralId:r,referalId:r,referralRate:t,referalRate:t,referralType:n,referalType:n,referralEnabled:!0,referalEnabled:!0,isReferralApplicable:!0}}}function $j(e=``){return String(e??``).replace(/map\[[^\]]*(?:resume|document|attachment|file)[^\]]*\]/gi,``).replace(/<p>\s*<\/p>/gi,``).replace(/(?:<br\s*\/?>\s*){3,}/gi,`<br><br>`).trim()}function eM(...e){for(let t of e){let e=[t?.candidateId,t?.applicantId,t?.candidate?._id,t?.candidate?.id,t?.submission?.candidateId,t?.submission?.applicantId,t?.recordMeta?.candidateId,t?.recordMeta?.applicantId].map(Xj).find(Boolean);if(e)return e}return``}async function tM(e){let t=e?.fileUrl??e?.downloadUrl??e?.url;if(!t)return null;let n=await fetch(t);if(!n.ok)throw Error(`Unable to load ${e?.fileName||`resume`}`);let r=await n.blob(),i=e?.fileName??e?.uploadedFileName??e?.originalName??e?.uniqueName??`resume`;return new File([r],i,{type:e?.contentType||r.type||`application/octet-stream`})}async function nM(e,r,i){let a=[],o=await n.yn(`submissions`,e,`resume`).catch(()=>({data:[]}));a.push(...o?.data??[]);let s=eM(r?.record?.submission,i,r?.record);if(!s){let n=await t.o(t.x,`/module/list?module=submissions&id=${encodeURIComponent(e)}`).catch(()=>({})),r=n?.data??n??{};s=eM((Array.isArray(r?.data)?r.data:Array.isArray(r)?r:[])[0])}if(s){let e=await n.yn(`candidates`,s,`resume`).catch(()=>({data:[]}));a.push(...e?.data??[])}let c=(await Promise.all(a.map(tM))).filter(Boolean),l=new Set;return c.filter(e=>{let t=`${e.name}:${e.size}:${e.type}`;return!l.has(t)&&(l.add(t),!0)})}function rM(e={}){return{to:(e.to??e.To??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),cc:(e.cc??e.Cc??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),bcc:(e.bcc??e.Bcc??[]).map(e=>e.email??e.Email??e).filter(Boolean).join(`, `),subject:e.subject??e.Subject??``,contents:$j(e.content?.value??e.Content?.Value??e.contents??e.body??``)}}function iM({context:e,selectedIds:t,selectedRecords:n,moduleName:r,onClose:i}){let a=n?.[0]??{},c=t?.[0]??xv(a),[u,d]=(0,o.useState)(null),[f,p]=(0,o.useState)(!0),[m,h]=(0,o.useState)([]),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(`vms`),[b,x]=(0,o.useState)(null),[S,C]=(0,o.useState)(null),[w,T]=(0,o.useState)(!1),[E,D]=(0,o.useState)(!1),[O,k]=(0,o.useState)(!1),[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)({to:``,cc:``,bcc:``,subject:``,contents:``,attachments:[],showCc:!1,showBcc:!1});(0,o.useEffect)(()=>{let e=!1;return cy(c,a).then(t=>{e||d(t)}).catch(t=>{e||(s.message.error(t?.message??`Unable to load finance details`),d({record:{submission:a},lookups:{},display:{}}))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[c]),(0,o.useEffect)(()=>{let e=!1;return _y().then(t=>{e||h(t)}).catch(()=>{}),()=>{e=!0}},[]);let P=async()=>{if(b){if(v===`mail`){_(!1),D(!0),k(!0);try{let[e,t]=await Promise.all([Lj(c).then(rM),nM(c,u,a).catch(e=>(console.warn(`Unable to resolve resume attachment:`,e),[]))]),n=u?.record?.submission??a;N({to:Gj(e.to,n,b,u,a),cc:Gj(e.cc,n,b,u,a),bcc:Gj(e.bcc,n,b,u,a),subject:Gj(e.subject,n,b,u,a),contents:Gj(e.contents,n,b,u,a),attachments:t,showCc:!!e.cc,showBcc:!!e.bcc})}catch(e){s.message.error(e?.message??`Unable to prepare approval mail`)}finally{k(!1)}return}T(!0);try{await be(c,{candidateProposedRate:b.proposedRate,candidateProposedRateCurrency:b.currencyRaw??b.currency,candidateProposedRateUnit:b.rateUnit,submitVia:`VMS`,...Qj(S)}),s.message.success(`Submission approved`),_(!1),x(null),C(null),i?.({success:!0})}catch(e){s.message.error(e?.message??`Unable to approve submission`)}finally{T(!1)}}},F=!O&&FD(M.to).length>0&&ID(M.to)&&ID(M.cc)&&ID(M.bcc)&&M.subject.trim()&&M.contents.trim(),I=async()=>{if(!b||!F||A)return;j(!0);let e={candidateProposedRate:b.proposedRate,candidateProposedRateCurrency:b.currencyRaw??b.currency,candidateProposedRateUnit:b.rateUnit};try{await be(c,{...e,submitVia:`VMS`,...Qj(S)});let t=Zj(u?.record,a);if(!t)s.message.warning(`Submission approved, but job details were not available to send mail`);else try{await pn({jobId:t,toMail:FD(M.to),ccMail:FD(M.cc),bccMail:FD(M.bcc),subject:M.subject,contents:M.contents,attachments:M.attachments??[]}),s.message.success(`Approval mail sent and submission approved`)}catch(e){s.message.warning(e?.message?`Submission approved, but mail was not sent: ${e.message}`:`Submission approved, but mail was not sent`)}D(!1),x(null),C(null),i?.({success:!0})}catch(e){s.message.error(e?.message??`Unable to send approval mail`)}finally{j(!1)}},L=(0,o.useMemo)(()=>({submissionApprove:async({computed:e,referral:t})=>{x(e),C(t??null),y(`vms`),_(!0)},submissionReject:async()=>{e?.navigate?.(`/popup/reject`,{replace:!0,state:{background:e?.background??null,selectedIds:t,selectedRecords:n,moduleName:r}})}}),[e,t,n,r]);return f||!u?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Zv,{type:Y_,record:u.record,lookups:u.lookups,identity:Yj(a,u.display),referralOptions:m,onAddReferral:()=>e?.navigate?.(`/referrals-create`),currentUserId:typeof localStorage<`u`?localStorage.getItem(`userId`)??void 0:void 0,actions:L,onClose:()=>i?.(),variant:`popup`}),(0,l.jsx)(s.Modal,{title:`Choose approval method`,open:g,okText:`Approve`,confirmLoading:w,onOk:P,onCancel:()=>{w||(_(!1),x(null),C(null))},children:(0,l.jsxs)(s.Radio.Group,{value:v,onChange:e=>y(e.target.value),style:{display:`grid`,gap:12},children:[(0,l.jsx)(s.Radio,{value:`vms`,children:`Via VMS`}),(0,l.jsx)(s.Radio,{value:`mail`,children:`Via Mail`})]})}),(0,l.jsx)(s.Drawer,{open:E,placement:`right`,onClose:()=>{A||D(!1)},closable:!1,rootClassName:`mail-popup`,width:620,maskClosable:!1,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>D(!1),disabled:A,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:A,disabled:!F,onClick:I,children:`Send`})]}),children:O?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsx)(YD,{value:M,onChange:N,moduleName:`submissions`,ready:!O,title:`Submit Via Mail`,contextRecords:[u.record?.submission??a]})})]})}iM.propTypes={context:f.default.object,selectedIds:f.default.array,selectedRecords:f.default.array,moduleName:f.default.string,onClose:f.default.func};var aM={title:`Manager Approve`,width:780,className:`fa-modal manager-approve-modal`,component:iM},oM={submit:async()=>{}};function sM(...e){return e.map(e=>e==null?``:String(e).trim()).find(Boolean)??``}var cM=(e,t)=>!!e&&e.toLowerCase()===sM(t).toLowerCase();function lM(e,t,n){let r=sM(t.submittedBy);return sM(cM(r,n)||cM(r,e.submitSource)||cM(r,e.supplierName)||cM(r,e.source)||cM(r,e.candidateSource)?``:r,e.signatureEmail)}function uM(e,t={}){let n=t.employerName??e.supplierName??e.submitSource;return{client:t.clientName??e.clientName,role:t.jobTitle??e.jobTitle??e.designation,reqId:t.reqId??e.jobClientRefrenceId??e.mspReqId??e.submissionId,name:t.candidateName||[e.firstName,e.lastName].filter(Boolean).join(` `)||e.candidateFullName,location:t.jobLocation??e.city??e.currentLocation??e.jobLocation,vendor:n,submittedBy:lM(e,t,n),submittedAt:t.createdAt??e.createdAt,email:t.email??e.email,employerLocation:t.employerLocation,employerName:t.employerName}}function dM(e){let t=Array.isArray(e)?e:[];for(let e=t.length-1;e>=0;--e)if(String(t[e]?.activityType??``).trim().toLowerCase()===`cfo rejected`)return t[e];return null}function fM(e){return String(e??``).toLowerCase().replace(/\b\w/g,e=>e.toUpperCase())}function pM({selectedIds:e,selectedRecords:t,onClose:r}){let i=t?.[0]??{},a=e?.[0]??xv(i),[c,u]=(0,o.useState)(null),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(!0);(0,o.useEffect)(()=>{let e=!1;return m(!0),Promise.all([cy(a,i),n.pn(`submission`,a).catch(()=>[])]).then(([t,n])=>{if(e)return;let r=dM(n);f(xv(t?.meta?.workforceEngagementId??i?.onboarding?.workforceEngagementId??i?.workforceEngagementId));let a=t?.meta?.rejectReasonComments||r?.activityComments||``;u({...t,record:{...t.record,submission:{...t.record.submission,cfoRejectionReason:a?fM(a):``,cfoRejectedAt:t?.meta?.rejectedAt??r?.activityTime??null}}})}).catch(t=>{e||(s.message.error(t?.message??`Unable to load finance details`),u({record:{submission:i},lookups:{},display:{}}))}).finally(()=>{e||m(!1)}),()=>{e=!0}},[a]);let h=(0,o.useMemo)(()=>({submissionReapproveSend:async({computed:e})=>{await K(d,{submissionId:a,billRate:e.proposedRate,payRate:e.employerRate,currency:e.currencyRaw??e.currency,rateUnit:e.rateUnit,vmsPercent:e.clientVmsPercent}),await be(a,{candidateProposedRate:e.proposedRate,candidateProposedRateCurrency:e.currencyRaw??e.currency,candidateProposedRateUnit:e.rateUnit,submitVia:`Mail`,context:`resend`}),s.message.success(`Re-approved and sent for CFO approval`),r?.({success:!0})}}),[a,d,r]);return p||!c?(0,l.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,padding:48},children:(0,l.jsx)(s.Spin,{size:`large`})}):(0,l.jsx)(Zv,{type:$_,record:c.record,lookups:c.lookups,identity:uM(i,c.display),currentUserId:typeof localStorage<`u`?localStorage.getItem(`userId`)??void 0:void 0,actions:h,onClose:()=>r?.(),variant:`popup`})}pM.propTypes={selectedIds:f.default.array,selectedRecords:f.default.array,onClose:f.default.func};var mM={title:`Re-Approve`,width:780,className:`fa-modal manager-approve-modal`,component:pM},hM={submit:async()=>{}},gM=[{id:1,name:`Re-Submission`},{id:2,name:`Candidate doesn't fit into the profile`},{id:3,name:`Incomplete candidate details - (Re-Submission)`}],_M={title:`Reject`,okText:`Reject`,okButtonDanger:!0,width:480,successMessage:`Submission rejected successfully`,fields:[{name:`rejectReason`,label:`Rejection Reasons`,type:`select`,required:!0,placeholder:`Select rejection reasons`,defaultOptions:gM.map(e=>({label:e.name,value:e.id}))},{name:`rejectReasonComments`,label:`Comments`,type:`textarea`,required:!0,rows:4}]},vM={submit:async(e,t)=>{let n=gM.find(t=>String(t.id)===String(e.rejectReason));await q({submissionId:t.selectedIds[0],rejectReasonId:e.rejectReason,rejectReason:n?.name??``,rejectReasonComments:e.rejectReasonComments})}},yM={title:`Request Document Edit`,okText:`Submit Request`,cancelText:`Cancel`,width:480,successMessage:`Edit request submitted successfully.`,fields:[{name:`reason`,label:`Reason for Edit`,type:`textarea`,required:!0,rows:4,maxLength:1e3,placeholder:`Enter the reason for requesting changes to this document`}]},bM=`documents`,xM={submit:async(e,t)=>{let n=await ke({module:t.moduleName||bM,documentIds:t.selectedIds??[],reason:String(e.reason??``).trim()}),r=Number(n?.failedCount)||0;if(r>0){let e=Number(n?.createdCount)||0,t=n?.failures?.find(e=>e?.error)?.error;s.message.warning(`${e} of ${e+r} edit requests raised${t?` — ${t}`:``}.`)}}},SM={title:`Reject Edit Request`,okText:`Reject`,cancelText:`Cancel`,okButtonDanger:!0,width:480,successMessage:`Edit request rejected successfully.`,fields:[{name:`rejectionReason`,label:`Rejection Reason`,type:`textarea`,required:!0,rows:4,maxLength:1e3,placeholder:`Explain why this edit request is being rejected`}]},CM={submit:async(e,t)=>{let n=t.selectedIds??[],r=await Ae({ids:n,rejectionReason:String(e.rejectionReason??``).trim()}),i=Number(r?.rejectedCount)||0,a=Number(r?.failedCount)||0;if(i===0)throw Error(n.length>1?`None of the selected requests could be rejected — they are no longer pending or are outside your review scope.`:`This request could not be rejected — it is no longer pending or is outside your review scope.`);a>0&&s.message.warning(`${i} of ${i+a} edit requests rejected — the rest are no longer pending or are outside your review scope.`)}},wM={delete:nA,"quick-submit":jA,"add-notes":MA,"tag-to-job":RA,"change-status":fj,"remove-from-shortlist":hj,"add-to-groups":_j,"self-assign":xj,"others-assign":wj,"sticky-notes":Ej,"move-to-onboarding":Oj,"approve-rate":Pj,"manager-approve":aM,"manager-reapprove":mM,reject:_M,"document-edit-request":yM,"document-edit-reject":SM},TM={delete:rA,"quick-submit":AA,"add-notes":FA,"tag-to-job":dj,"change-status":mj,"remove-from-shortlist":gj,"add-to-groups":vj,"self-assign":Sj,"others-assign":Tj,"sticky-notes":Dj,"move-to-onboarding":kj,"approve-rate":Fj,"manager-approve":oM,"manager-reapprove":hM,reject:vM,"document-edit-request":xM,"document-edit-reject":CM};function EM(e){let t=e?.data??e;return Array.isArray(t)?t:t?.data??t?.rows??t?.records??t?.items??t?.list??[]}function DM(e,...t){for(let n of t){let t=String(n).split(`.`).reduce((e,t)=>e?.[t],e);if(t!=null&&t!==``)return t}return``}function OM(e){let t=String(DM(e,`isDeleted`,`deleted`)).toLowerCase(),n=String(DM(e,`assignmentStatus`,`status`)).toLowerCase();return t!==`true`&&t!==`1`&&![`removed`,`inactive`,`deleted`].includes(n)}function kM(e){let t=DM(e,`candidateName`,`candidate_name`,`fullName`,`name`);return t?String(t):[DM(e,`firstName`,`first_name`),DM(e,`lastName`,`last_name`)].filter(Boolean).join(` `)||`Unnamed candidate`}function AM(e){return String(DM(e,`candidateId`,`candidate_id`,`candidate._id`,`candidate.id`))}function jM(e){return String(DM(e,`workforceEngagementId`,`engagementId`,`_id`,`id`))}function MM(e){return String(DM(e,`batchName`,`name`,`title`,`batch_name`))}function NM({open:e=!0,context:r={},onClose:i}){let[a,c]=(0,o.useState)([]),[u,d]=(0,o.useState)([]),[f,p]=(0,o.useState)(``),[m,h]=(0,o.useState)(!0),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(``),[b,x]=(0,o.useState)(new Map),S=String(r.selectedIds?.[0]??r.selectedRecords?.[0]?._id??r.selectedRecords?.[0]?.id??r.batchId??``);(0,o.useEffect)(()=>{if(!e)return;let t=!1;return Promise.resolve().then(()=>(t||h(!0),Promise.all([n.Sn(`onboarding`,200,0),n.Sn(`batchCandidates`,1e3,0).catch(()=>[])]))).then(([e,n])=>{t||(c(EM(e)),x(new Map(EM(n).filter(OM).map(e=>[String(DM(e,`candidateId`,`candidate_id`)),e]).filter(([e])=>e))))}).catch(e=>{t||y(e.message||`Unable to load onboarding candidates`)}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e]);let C=(0,o.useMemo)(()=>{let e=f.trim().toLowerCase();return e?a.filter(t=>[kM(t),DM(t,`email`,`candidateEmail`,`candidate_email`),DM(t,`status`,`onboardingStatus`,`onboarding_status`)].some(t=>String(t).toLowerCase().includes(e))):a},[a,f]);async function w(){if(!S){y(`Select a batch before adding candidates`);return}let e=a.filter(e=>u.includes(jM(e)));if(!e.length)return;let o=e.map(e=>({record:e,assignment:b.get(AM(e))})).filter(e=>e.assignment);if(o.length){let e=o.map(({record:e})=>kM(e)).join(`, `);y(`${e} ${o.length===1?`is`:`are`} already added to a batch. Each candidate can be added to only one batch.`);return}_(!0),y(``);try{let{userId:a}=t.s(),o=MM(r.selectedRecords?.[0])||MM(r);await Promise.all(e.map(e=>n.er(`batchCandidates`,{schemaVersion:1,batchId:S,batchName:o,candidateId:AM(e),workforceEngagementId:jM(e),source:`ONBOARDING`,assignmentStatus:`ASSIGNED`,assignedAt:new Date().toISOString(),assignedBy:a??0,isDeleted:!1}))),s.message.success(`${e.length} candidate${e.length===1?``:`s`} added to the batch`),i?.({refresh:!0})}catch(e){y(e.message||`Unable to add candidates to the batch`)}finally{_(!1)}}return(0,l.jsxs)(s.Modal,{open:e,title:`Add Candidate to Batch`,okText:`Add`,onOk:w,onCancel:()=>i?.(),okButtonProps:{disabled:u.length===0||!S,loading:g},cancelButtonProps:{disabled:g},closable:!g,maskClosable:!1,width:760,centered:!0,children:[v&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:v,style:{marginBottom:12}}),(0,l.jsx)(s.Input.Search,{allowClear:!0,placeholder:`Search onboarding candidates`,value:f,onChange:e=>p(e.target.value),style:{marginBottom:12}}),(0,l.jsx)(s.Table,{rowKey:e=>jM(e),columns:[{title:`Candidate`,key:`candidate`,render:(e,t)=>kM(t)},{title:`Email`,key:`email`,render:(e,t)=>DM(t,`email`,`candidateEmail`,`candidate_email`)||`—`},{title:`Onboarding status`,key:`status`,render:(e,t)=>DM(t,`status`,`onboardingStatus`,`onboarding_status`)||`—`}],dataSource:C,loading:m,size:`small`,pagination:{pageSize:10,showSizeChanger:!1},rowSelection:{selectedRowKeys:u,onChange:d,getCheckboxProps:e=>{let t=b.get(AM(e));return{disabled:!AM(e)||!jM(e)||!!t,title:t?`Candidate is already added to a batch`:void 0}}},locale:{emptyText:m?`Loading candidates…`:`No onboarding candidates found`}})]})}var PM={text:`input`,string:`input`,textarea:`textarea`,date:`date-picker`,datepicker:`date-picker`,multiselect:`multi-select`,lookup:`search-select`};function FM(e){if(!e)return null;let t=[...e.groups??[]].sort((e,t)=>Number(e.order??0)-Number(t.order??0)).flatMap(e=>[...e.fields??[]].filter(e=>e.show!==0&&e.show!==!1).sort((e,t)=>Number(e.order??0)-Number(t.order??0)).map(e=>({...e,name:e.name??e.field,label:e.label??e.field,type:PM[String(e.type??`text`).toLowerCase()]??e.type??`input`,required:e.required??e.req===1,options:(e.options??[]).map(e=>({label:e.label??e.name??e.value,value:e.value??e.id??e.label}))}))),n=IM(e.successNavigate);return{title:e.label,fields:t,...n?{successNavigate:n}:{}}}function IM(e){let t=String(e??``).trim();return!t||!t.startsWith(`/`)||t.startsWith(`//`)||/^[a-z][a-z0-9+.-]*:/i.test(t)?null:t}function LM(e,t=[]){if(!e||!Array.isArray(t)||!t.length)return e;let n=new Map(t.filter(e=>e?.name).map(e=>[String(e.name),e]));return n.size?{...e,fields:(e.fields??[]).map(r=>{let i=n.get(String(r.name))??n.get(String(r.label))??(n.size===1&&(e.fields??[]).length===1?t[0]:null);if(!i)return r;let{name:a,...o}=i;return{...r,...o}})}:e}function RM({apiMap:e={},extraConfigs:r={}}){let i=(0,o.useMemo)(()=>({...TM,...e}),[e]),a=(0,o.useMemo)(()=>{let e={...wM};return Object.entries(r).forEach(([t,n])=>{e[t]={...e[t]??{},...n}}),e},[r]),{popupKey:s}=(0,d.useParams)(),c=(0,d.useNavigate)(),{state:u={}}=(0,d.useLocation)(),[f,p]=(0,o.useState)({key:``,config:null});(0,o.useEffect)(()=>{let e=!1;if(!s||!u.moduleName)return;let t=`${u.moduleName}:${s}`;return n.Dr(u.moduleName,`popup`,s).then(n=>{e||p({key:t,config:FM(n[0])})}).catch(()=>{e||p({key:t,config:null})}),()=>{e=!0}},[s,u.moduleName]);let m=(0,o.useMemo)(()=>{let e=a[s],t=`${u.moduleName}:${s}`,n=f.key===t?f.config:null;return LM(n?{...e,...n}:e,u.popupAction?.popupFieldOverrides)},[f,a,s,u.moduleName,u.popupAction?.popupFieldOverrides]),h=(0,o.useMemo)(()=>({selectedIds:u.selectedIds??[],selectedRecords:u.selectedRecords??[],moduleName:u.moduleName??``,navigate:c,background:u.background??null,...u.popupContext??{}}),[c,u.selectedIds,u.selectedRecords,u.moduleName,u.popupContext,u.background]),g=(0,o.useMemo)(()=>{let e=u.popupAction;return e?.apiPath?{submit:(n,r)=>{let i=String(e.apiMethod||`POST`).toUpperCase();return t.o(t.x,e.apiPath.startsWith(`/`)?e.apiPath:`/${e.apiPath}`,{method:i,body:[`GET`,`DELETE`].includes(i)?void 0:JSON.stringify({...n,selectedIds:r.selectedIds,selectedRecords:r.selectedRecords,moduleName:r.moduleName})})}}:{}},[u.popupAction]),_=e=>{let t=u.background;if(e?.success&&m?.successNavigate){c(m.successNavigate,{replace:!0,state:{refreshTimestamp:Date.now()}});return}if(e?.success&&t?.pathname){c(`${t.pathname}${t.search??``}`,{replace:!0,state:{...t.state??{},refreshTimestamp:Date.now()}});return}c(-1)};return s===`add-batch-candidate`?(0,l.jsx)(NM,{open:!0,context:h,onClose:_}):(0,l.jsx)(tA,{open:!0,config:m,context:h,onClose:_,api:{...i[s]??{},...g}})}var zM={title:`Vendor Share`,maxVendorSelect:1e3,defaultTab:`myVendor`,defaultPageSize:10,vendorTabs:[{key:`myVendor`,label:`My Vendors`},{key:`allVendor`,label:`All Vendors`}],vendorColumns:[{title:`Vendor Name`,dataIndex:`vendorName`,key:`vendorName`},{title:`Email`,dataIndex:`vendorEmail`,key:`vendorEmail`},{title:`Location`,dataIndex:`vendorLocation`,key:`vendorLocation`},{title:`Updated On`,dataIndex:`updatedOn`,key:`updatedOn`}]},BM={getVendorList:({jobId:e,limit:t,offset:n,type:r})=>un({jobId:e,limit:t,offset:n,sortBy:`new`,type:r}),getMailDetails:e=>dn(e),submit:({jobId:e,toMail:t,ccMail:n,bccMail:r,subject:i,contents:a})=>pn({jobId:e,toMail:t,ccMail:n,bccMail:r,subject:i,contents:a})},VM=zM.vendorColumns.map(e=>({...e,render:e=>e||`-`}));function HM(){let e=(0,d.useNavigate)(),t=(0,d.useLocation)(),{selectedIds:n=[],selectedRecords:r=[],recipients:i=[],subject:a=``,onSend:u,moduleName:f=``,popupAction:p={}}=t.state??{},m=n[0]??r[0]?._id??r[0]?.id,[h,g]=(0,o.useState)({to:i.join(`, `),cc:``,bcc:``,subject:a,contents:``,showCc:!1,showBcc:!1}),[_,v]=(0,o.useState)(!m),[y,b]=(0,o.useState)(zM.defaultTab),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)([]),[T,E]=(0,o.useState)(0),[D,O]=(0,o.useState)(0),[k,A]=(0,o.useState)(0),[j,M]=(0,o.useState)(1),[N,P]=(0,o.useState)(zM.defaultPageSize),[F,I]=(0,o.useState)(!1),[L,R]=(0,o.useState)([]);(0,o.useEffect)(()=>{if(!m)return;let e=!1;I(!0);let t=x?100:N,n=x?0:(j-1)*N;return BM.getVendorList({jobId:m,limit:t,offset:n,type:y}).then(t=>{if(e)return;let n=t?.data?.vendorList??t?.data??[],r=t?.data?.myVendorCount??0,i=t?.data?.allVendorCount??0;w(Array.isArray(n)?n:[]),E(r),O(i),A(y===`myVendor`?r:i)}).catch(()=>{e||(w([]),A(0))}).finally(()=>{e||I(!1)}),()=>{e=!0}},[m,y,j,N,x]),(0,o.useEffect)(()=>{m&&BM.getMailDetails(m).then(e=>g(t=>({...t,subject:e.subject||t.subject,contents:e.contents||t.contents,to:e.toMail?.length?Array.isArray(e.toMail)?e.toMail.join(`, `):String(e.toMail):t.to,cc:e.ccMail?.length?Array.isArray(e.ccMail)?e.ccMail.join(`, `):String(e.ccMail):t.cc}))).catch(()=>{}).finally(()=>v(!0))},[m]);let z=(0,o.useMemo)(()=>L.map(e=>C.find(t=>t.vendorId===e)?.vendorEmail??``).filter(Boolean),[L,C]),B=(0,o.useMemo)(()=>({...h,bcc:[...new Set([...FD(h.bcc),...z])].join(`, `),showBcc:h.showBcc||z.length>0}),[h,z]);function V(e){let t=new Set(z);g({...e,bcc:FD(e.bcc).filter(e=>!t.has(e)).join(`, `)})}let H=(FD(B.to).length||FD(B.bcc).length)&&ID(B.to)&&ID(B.cc)&&ID(B.bcc)&&B.subject.trim(),ee=e=>e===`myVendor`?T:D;function U(){e(-1)}function te(){H&&BM.submit({jobId:m,toMail:FD(B.to),ccMail:FD(B.cc),bccMail:FD(B.bcc),subject:B.subject,contents:B.contents}).then(t=>{t?.status===!0?(s.message.success(t?.data||`Mail sent successfully.`),typeof u==`function`&&u({...B,message:B.contents,selectedIds:n}),e(-1)):s.message.error(t?.message||t?.data||`Failed to send mail. Please try again.`)}).catch(e=>{s.message.error(e?.message||`Failed to send mail. Please try again.`)})}let ne=(0,o.useMemo)(()=>{if(!x)return C;let e=x.toLowerCase();return C.filter(t=>(t.vendorName??``).toLowerCase().includes(e)||(t.vendorEmail??``).toLowerCase().includes(e)||(t.vendorLocation??``).toLowerCase().includes(e))},[C,x]);return(0,l.jsx)(s.Drawer,{open:!0,placement:`right`,onClose:U,closable:!1,rootClassName:`vendor-share`,width:`95%`,footer:(0,l.jsxs)(`div`,{className:`vendor-share__footer`,children:[(0,l.jsx)(s.Button,{onClick:U,children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,disabled:!H,onClick:te,children:`Send`})]}),children:(0,l.jsxs)(`div`,{className:`vendor-share__body`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__left`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__vendor-header`,children:[(0,l.jsxs)(`div`,{className:`vendor-share__vendor-header-row`,children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.CloseOutlined,{}),onClick:U,size:`small`,style:{marginRight:8}}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-icon-box`,children:(0,l.jsx)(c.TeamOutlined,{})}),(0,l.jsx)(`span`,{className:`dynamic-popup__header-label`,children:`Vendor List`}),(0,l.jsxs)(`div`,{className:`vendor-share__vendor-search`,children:[(0,l.jsx)(c.SearchOutlined,{className:`vendor-share__search-icon`}),(0,l.jsx)(s.Input,{variant:`borderless`,placeholder:`Search vendor`,value:x,onChange:e=>{S(e.target.value),M(1)},className:`vendor-share__search-input`})]})]}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-tabs`,children:zM.vendorTabs.map(e=>(0,l.jsxs)(`span`,{className:`vendor-share__vendor-tab${y===e.key?` vendor-share__vendor-tab--active`:``}`,onClick:()=>{b(e.key),M(1),R([])},children:[e.label,` (`,ee(e.key),`)`]},e.key))})]}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-table-wrapper`,children:(0,l.jsx)(s.Table,{rowKey:e=>e.vendorId,columns:VM,dataSource:ne,loading:F,pagination:!1,size:`small`,rowSelection:{selectedRowKeys:L,onChange:e=>{e.length>zM.maxVendorSelect||R(e)}},scroll:{y:`calc(100vh - 340px)`}})}),(0,l.jsx)(`div`,{className:`vendor-share__vendor-footer`,children:(0,l.jsx)(Be,{current:j,pageSize:N,total:k,onChange:e=>M(e),onPageSizeChange:e=>P(e)})})]}),(0,l.jsx)(`div`,{className:`vendor-share__right`,children:(0,l.jsx)(YD,{value:B,onChange:V,moduleName:f,defaultTemplateId:p.defaultTemplateId??t.state?.defaultTemplateId??``,ready:_,contextRecords:r,title:`Share`,hint:`Select vendors or add email addresses`,bccHint:`Vendor emails are added automatically`,afterBcc:L.length>0?(0,l.jsxs)(`div`,{className:`vendor-share__selected-count`,children:[L.length,` / `,zM.maxVendorSelect,` Vendors selected`]}):null})})]})})}function UM(e){return e?.data??e}async function WM(e){let n=String(e??``).trim();if(!n)throw Error(`Invoice id is required`);return UM(await t.o(t.x,`/payments/invoice/${encodeURIComponent(n)}`))}function GM(...e){for(let t of e){let e=String(t??``).trim();if(e&&e!==`undefined`&&e!==`null`)return e}return``}async function KM(e,t,n){if(!e)return null;let r=await fetch(e);if(!r.ok)throw Error(`Unable to load invoice attachment`);let i=await r.blob();return new File([i],t||`payment-invoice.html`,{type:n||i.type||`text/html`})}function qM(e){let t=GM(e?.courseName,`your course`),n=GM(e?.invoiceNumber,e?.invoiceFileName,e?.transactionId);return{subject:`Payment invoice - ${t}`,contents:`<p>Hello ${GM(e?.recipientName,`Student`)},</p><p>Please find attached the invoice for your successful payment${n?` (${n})`:``}.</p><p>Thank you.</p>`}}function JM(){let e=(0,d.useNavigate)(),{id:t}=(0,d.useParams)(),[r,i]=(0,o.useState)(null),[a,u]=(0,o.useState)(``),[f,p]=(0,o.useState)(!0),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)({to:``,cc:``,bcc:``,subject:``,contents:``,attachments:[],showCc:!1,showBcc:!1}),b=(0,o.useMemo)(()=>r?.invoiceUrl?[{id:r.invoiceS3Key||r.invoiceUrl,name:r.invoiceFileName||`payment-invoice.html`,url:r.invoiceUrl,type:r.invoiceContentType||`html`}]:[],[r]);(0,o.useEffect)(()=>{let e=!1;async function n(){p(!0);try{let n=await WM(t);if(e)return;i(n);let r=qM(n),a=await KM(n?.invoiceUrl,n?.invoiceFileName,n?.invoiceContentType).catch(()=>null),o={to:GM(n?.recipientEmail),cc:``,bcc:``,subject:r.subject,contents:r.contents,attachments:a?[a]:[],showCc:!1,showBcc:!1},s=(await Xw({module:`payments`,action:`invoice`}).catch(()=>[]))[0];if(!s?._id){y(o);return}u(String(s._id));let c=await Zw(s._id).catch(()=>null);if(!c){y(o);return}y({...o,to:GM(o.to,...(c.toMail??[]).map(e=>JD(e,c.placeholders,n))),cc:(c.ccMail??[]).map(e=>JD(e,c.placeholders,n)).filter(Boolean).join(`, `),bcc:(c.bccMail??[]).map(e=>JD(e,c.placeholders,n)).filter(Boolean).join(`, `),subject:GM(JD(c.subject,c.placeholders,n),o.subject),contents:GM(JD(c.body,c.placeholders,n),o.contents),showCc:!!c.ccMail?.length,showBcc:!!c.bccMail?.length})}catch(t){e||s.message.error(t?.message||`Unable to load invoice`)}finally{e||p(!1)}}return n(),()=>{e=!0}},[t]);let x=FD(v.to).length>0&&ID(v.to)&&ID(v.cc)&&ID(v.bcc)&&v.subject.trim()&&v.contents.trim();async function S(){if(!(!x||g)){_(!0);try{await pn({jobId:``,toMail:FD(v.to),ccMail:FD(v.cc),bccMail:FD(v.bcc),subject:v.subject,contents:v.contents,attachments:v.attachments}),s.message.success(`Invoice mail sent successfully`),h(!1)}catch(e){s.message.error(e?.message||`Failed to send invoice mail`)}finally{_(!1)}}}return(0,l.jsxs)(s.Drawer,{open:!0,placement:`right`,onClose:()=>e(-1),width:`min(1040px, 96vw)`,title:`Payment Invoice`,extra:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.MailOutlined,{}),onClick:()=>h(!0),disabled:!r,children:`Send Mail`}),destroyOnClose:!0,children:[(0,l.jsx)(s.Spin,{spinning:f,tip:`Loading invoice...`,children:!f&&!b.length?(0,l.jsx)(s.Alert,{type:`warning`,message:`Invoice document is not available for this payment.`,showIcon:!0}):(0,l.jsx)(`div`,{style:{height:`calc(100vh - 140px)`},children:(0,l.jsx)(n.En,{documents:b,inline:!0})})}),(0,l.jsx)(s.Drawer,{open:m,placement:`right`,onClose:()=>h(!1),width:620,rootClassName:`mail-popup`,destroyOnClose:!0,footer:(0,l.jsxs)(`div`,{className:`mail-popup__footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>h(!1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:g,disabled:!x,onClick:S,children:`Send`})]}),children:(0,l.jsx)(YD,{value:v,onChange:y,moduleName:`payments`,defaultTemplateId:a,contextRecords:r?[r]:[],title:`Invoice Mail`,hint:`Customer email and invoice attachment are prefilled.`})})]})}var YM={EMAIL:/^[a-zA-Z0-9._%+-]+@[a-zA-Z][a-zA-Z-]*\.[a-zA-Z]{2,}$/,PHONE:/^[0-9]{10}$/,PASSWORD:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,ALPHABETS:/^[A-Za-z ]+$/,ALPHANUMERIC:/^(?!\s)[A-Za-z0-9 ]+$/,NUMBER:/^[0-9]+$/,URL:/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+(com|org|net|in|co|io|gov|edu)(\/[^\s]*)?$/i,CANDIDATE_ID:/^[A-Za-z0-9-]+$/,REMARKS:/^[A-Za-z0-9\s.,'"\-()!?/@#$%&]*$/,DESIGNATION:/^[a-zA-Z0-9\s,.\-&()]{2,100}$/,DOB:/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/\d{4}$/,COMPANY_NAME:/^[A-Za-z0-9\s&.,'()-]+$/,FIRST_NAME:/^[A-Z][a-zA-Z]*$/,FULL_NAME:/^[A-Z][a-zA-Z]*(?: [A-Z][a-zA-Z]*)*$/,NO_SPACES:/^\S+$/,STARTS_WITH_CAPITAL:/^[A-Z].*$/},XM={SINGLE_FILE_COUNT:1,MULTI_FILE_COUNT:5,MAX_FILE_SIZE:2,ALLOWED_FILE_TYPES:[`image/jpeg`,`image/png`,`application/pdf`]},ZM={REQUIRED:e=>`Mandatory Field`,INVALID_EMAIL:`Please enter a valid email address.`,INVALID_PHONE:`Phone number must contain exactly 10 digits.`,INVALID_PASSWORD:`Password must contain uppercase, lowercase, number, special character and minimum 8 characters.`,INVALID_ALPHABETS:`Only alphabets and spaces are allowed.`,INVALID_ALPHANUMERIC:`Only letters, numbers and spaces are allowed.`,INVALID_NUMBER:`Only numbers are allowed.`,INVALID_URL:`Please enter a valid URL.`,INVALID_CANDIDATE_ID:e=>`${e} can contain only letters, numbers and hyphens.`,INVALID_REMARKS:`Remarks contain invalid characters.`,INVALID_DESIGNATION:`Designation contains invalid characters.`,INVALID_DOB:`DOB must be in MM/DD/YYYY format.`,INVALID_LINKEDIN:`Please enter a valid LinkedIn URL.`,INVALID_COMPANY_NAME:`Company name contains invalid characters.`,INVALID_FIRST_NAME:`First letter must be capital and spaces are not allowed.`,INVALID_FULL_NAME:`Each word must start with a capital letter.`,NO_SPACES_ALLOWED:`Spaces are not allowed.`,MUST_START_WITH_CAPITAL:`First letter must be capital.`,INVALID_FILE_TYPE:`Only JPG, PNG and PDF files are allowed.`,INVALID_FILE_SIZE:`File upload must be ${XM.MAX_FILE_SIZE} MB below.`,INVALID_FILE_TYPE:`Only JPG, PNG and PDF files are allowed.`,SINGLE_FILE_ONLY:`Only one file can be uploaded.`},QM={FIRST_NAME_MIN:3,FIRST_NAME_MAX:30},$M={REMARKS_MIN:10,REMARKS_MAX:250},eN={removeSpaces:(e=``)=>e.replace(/\s/g,``),capitalizeFirstLetter:(e=``)=>e.charAt(0).toUpperCase()+e.slice(1),capitalizeWords:(e=``)=>e.replace(/\b\w/g,e=>e.toUpperCase()),removeExtraSpaces:(e=``)=>e.replace(/\s+/g,` `).trim(),firstNameFormatter:(e=``)=>e.replace(/\s+/g,` `).trimStart().replace(/\b\w/g,e=>e.toUpperCase()),fullNameFormatter:(e=``)=>e.replace(/\s+/g,` `).trimStart().replace(/\b\w/g,e=>e.toUpperCase()),phoneFormatter:(e=``)=>e.replace(/\D/g,``).slice(0,10),dobFormatter:(e=``)=>{let t=e.replace(/\D/g,``);return t.length<=2?t:t.length<=4?`${t.slice(0,2)}/${t.slice(2)}`:`${t.slice(0,2)}/${t.slice(2,4)}/${t.slice(4,8)}`}},tN={required:(e=`Field`)=>({required:!0,message:ZM.REQUIRED(e)}),email:()=>({pattern:YM.EMAIL,message:ZM.INVALID_EMAIL}),phone:()=>({pattern:YM.PHONE,message:ZM.INVALID_PHONE}),password:()=>({pattern:YM.PASSWORD,message:ZM.INVALID_PASSWORD}),alphabets:()=>({pattern:YM.ALPHABETS,message:ZM.INVALID_ALPHABETS}),alphanumeric:()=>({pattern:YM.ALPHANUMERIC,message:ZM.INVALID_ALPHANUMERIC}),number:()=>({pattern:YM.NUMBER,message:ZM.INVALID_NUMBER}),url:()=>({pattern:YM.URL,message:ZM.INVALID_URL}),candidateId:(e=`ID`)=>({pattern:YM.CANDIDATE_ID,message:ZM.INVALID_CANDIDATE_ID(e)}),remarks:()=>({pattern:YM.REMARKS,message:ZM.INVALID_REMARKS,REMARKS_MIN:`Remarks must be at least ${$M.REMARKS_MIN} characters.`,REMARKS_MAX:`Remarks must not exceed ${$M.REMARKS_MAX} characters.`}),designation:()=>({pattern:YM.DESIGNATION,message:ZM.INVALID_DESIGNATION}),dob:(e=!0)=>({validator:(t,n)=>{if(!n)return e?Promise.reject(Error(`Date of Birth is required.`)):Promise.resolve();if(!YM.DOB.test(n))return Promise.reject(Error(ZM.INVALID_DOB));let r=(0,u.default)(n,`MM/DD/YYYY`,!0);if(!r.isValid())return Promise.reject(Error(ZM.INVALID_DOB));let i=(0,u.default)().endOf(`day`);return r.isAfter(i)?Promise.reject(Error(`Date of Birth cannot be a future date.`)):i.diff(r,`year`)<21?Promise.reject(Error(`Age must be at least 21 years.`)):Promise.resolve()}}),linkedin:()=>({pattern:YM.LINKEDIN,message:ZM.INVALID_LINKEDIN}),companyName:()=>({pattern:YM.COMPANY_NAME,message:ZM.INVALID_COMPANY_NAME}),firstName:()=>({pattern:YM.FIRST_NAME,message:ZM.INVALID_FIRST_NAME,FIRST_NAME_MIN:`First Name must be at least ${QM.FIRST_NAME_MIN} characters.`,FIRST_NAME_MAX:`First Name must not exceed ${QM.FIRST_NAME_MAX} characters.`}),firstNameMinLength:()=>({min:QM.FIRST_NAME_MIN,message:ZM.FIRST_NAME_MIN}),firstNameMaxLength:()=>({max:QM.FIRST_NAME_MAX,message:ZM.FIRST_NAME_MAX}),remarksMinLength:()=>({min:$M.REMARKS_MIN,message:ZM.REMARKS_MIN}),remarksMaxLength:()=>({max:$M.REMARKS_MAX,message:ZM.REMARKS_MAX}),fullName:()=>({pattern:YM.FULL_NAME,message:ZM.INVALID_FULL_NAME}),noSpaces:()=>({pattern:YM.NO_SPACES,message:ZM.NO_SPACES_ALLOWED}),startsWithCapital:()=>({pattern:YM.STARTS_WITH_CAPITAL,message:ZM.MUST_START_WITH_CAPITAL}),fileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();for(let e of t){let t=e.originFileObj||e;if(!(t.size/1024/1024<=XM.MAX_FILE_SIZE))return s.message.error(ZM.INVALID_FILE_SIZE),Promise.reject(Error(ZM.INVALID_FILE_SIZE));if(!XM.ALLOWED_FILE_TYPES.includes(t.type))return Promise.reject(Error(ZM.INVALID_FILE_TYPE))}return Promise.resolve()}}),singleFileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();if(t.length>XM.SINGLE_FILE_COUNT)return Promise.reject(Error(ZM.SINGLE_FILE_ONLY));let n=t[0];return n.size/1024/1024<XM.MAX_FILE_SIZE?XM.ALLOWED_FILE_TYPES.includes(n.type)?Promise.resolve():Promise.reject(Error(ZM.INVALID_FILE_TYPE)):Promise.reject(Error(ZM.INVALID_FILE_SIZE))}}),multiFileUpload:()=>({validator:(e,t)=>{if(!t||t.length===0)return Promise.resolve();if(t.length>XM.MULTI_FILE_COUNT)return Promise.reject(Error(ZM.INVALID_FILE_COUNT));for(let e of t){if(!(e.size/1024/1024<XM.MAX_FILE_SIZE))return Promise.reject(Error(ZM.INVALID_FILE_SIZE));if(!XM.ALLOWED_FILE_TYPES.includes(e.type))return Promise.reject(Error(ZM.INVALID_FILE_TYPE))}return Promise.resolve()}})},nN={beforeUpload:e=>[`image/jpeg`,`image/png`,`application/pdf`].includes(e.type)?e.size/1024/1024<=2?!1:(s.message.error(`File upload must be 2 MB below.`),s.Upload.LIST_IGNORE):(s.message.error(`Only JPG, PNG and PDF files are allowed.`),s.Upload.LIST_IGNORE)},rN=()=>{let[e]=s.Form.useForm();return(0,l.jsx)(`div`,{style:{padding:24},children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,onFinish:e=>{console.log(`Form Values:`,e)},autoComplete:`off`,children:[(0,l.jsxs)(s.Row,{gutter:16,children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Email`,name:`email`,rules:[tN.required(`Email`),tN.email()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Phone Number`,name:`phone`,rules:[tN.required(`Phone Number`),tN.phone()],validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,onChange:t=>{e.setFieldsValue({phone:eN.phoneFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Password`,name:`password`,rules:[tN.required(`Password`),tN.password()],children:(0,l.jsx)(s.Input.Password,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Full Name`,name:`fullName`,rules:[tN.required(`Full Name`),tN.alphabets(),tN.firstNameMinLength(),tN.firstNameMaxLength()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({fullName:eN.firstNameFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Username`,name:`username`,rules:[tN.required(`Username`),tN.alphanumeric()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({username:eN.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Website URL`,name:`website`,rules:[tN.required(`Website URL`),tN.url()],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({website:eN.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`MSP Req ID`,name:`mspreqID`,rules:[tN.required(`MSP Req ID`),tN.candidateId(`MSP Req ID`)],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({mspreqID:eN.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Candidate ID`,name:`candidateId`,rules:[tN.required(`Candidate ID`),tN.candidateId(`Candidate ID`)],children:(0,l.jsx)(s.Input,{onChange:t=>{e.setFieldsValue({candidateId:eN.removeExtraSpaces(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:24,children:(0,l.jsx)(s.Form.Item,{label:`Remarks`,name:`remarks`,rules:[tN.required(`Remarks`),tN.remarks(),tN.remarksMinLength(),tN.remarksMaxLength()],children:(0,l.jsx)(s.Input.TextArea,{rows:4})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Designation`,name:`designation`,rules:[tN.required(`Designation`),tN.designation()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Date of Birth`,name:`dob`,rules:[tN.dob()],children:(0,l.jsx)(s.Input,{placeholder:`MM/DD/YYYY`,maxLength:10,onChange:t=>{e.setFieldsValue({dob:eN.dobFormatter(t.target.value)})}})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Company Name`,name:`companyName`,rules:[tN.required(`Company Name`),tN.companyName()],children:(0,l.jsx)(s.Input,{})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{name:`contractType`,label:`Contract Type`,children:(0,l.jsxs)(s.Select,{showSearch:!0,allowClear:!0,filterOption:(e,t)=>(t?.label??``).toLowerCase().includes(e.toLowerCase()),children:[(0,l.jsx)(s.Select.Option,{value:`C2C`,label:`C2C`,children:`C2C`}),(0,l.jsx)(s.Select.Option,{value:`W2-Contract`,label:`W2-Contract`,children:`W2-Contract`}),(0,l.jsx)(s.Select.Option,{value:`W2-Fulltime`,label:`W2-Fulltime`,children:`W2-Fulltime`}),(0,l.jsx)(s.Select.Option,{value:`1099`,label:`1099`,children:`1099`})]})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{name:`candidateProposedRateCurrency`,label:`Currency`,children:(0,l.jsxs)(s.Select,{showSearch:!0,allowClear:!0,children:[(0,l.jsx)(s.Select.Option,{value:`$`,children:`$`}),(0,l.jsx)(s.Select.Option,{value:`₹`,children:`₹`}),(0,l.jsx)(s.Select.Option,{value:`€`,children:`€`}),(0,l.jsx)(s.Select.Option,{value:`zł`,children:`zł`}),(0,l.jsx)(s.Select.Option,{value:`£`,children:`£`}),(0,l.jsx)(s.Select.Option,{value:`kr`,children:`kr`}),(0,l.jsx)(s.Select.Option,{value:`Fr`,children:`Fr`}),(0,l.jsx)(s.Select.Option,{value:`kr`,children:`kr`})]})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Resume new`,name:`resume`,children:(0,l.jsx)(s.Upload,{beforeUpload:nN.beforeUpload,maxCount:1,children:(0,l.jsx)(s.Button,{children:`Upload Resume`})})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Documents`,name:`documents`,valuePropName:`fileList`,getValueFromEvent:e=>e?.fileList,rules:[tN.multiFileUpload()],children:(0,l.jsx)(s.Upload,{multiple:!0,beforeUpload:nN.beforeUpload,children:(0,l.jsx)(s.Button,{children:`Upload Documents`})})})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{label:`Upload File`,name:`file`,valuePropName:`fileList`,getValueFromEvent:e=>e?.fileList,rules:[tN.fileUpload()],children:(0,l.jsx)(s.Upload,{beforeUpload:nN.beforeUpload,maxCount:1,children:(0,l.jsx)(s.Button,{children:`Upload`})})})})]}),(0,l.jsx)(s.Row,{children:(0,l.jsx)(s.Form.List,{name:`users`,children:(e,{add:t,remove:n})=>(0,l.jsxs)(l.Fragment,{children:[e.map(({key:e,name:t,...r})=>(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsx)(s.Form.Item,{required:!0,...r,rules:[{required:!0,message:`First name is requried`}],name:[t,`first`],children:(0,l.jsx)(s.Input,{placeholder:`First Name`})})}),(0,l.jsx)(s.Col,{span:11,children:(0,l.jsx)(s.Form.Item,{...r,required:!0,name:[t,`last`],children:(0,l.jsx)(s.Input,{placeholder:`Last Name`})})}),(0,l.jsx)(s.Col,{span:1,children:(0,l.jsx)(c.MinusCircleOutlined,{onClick:()=>n(t)})})]})),(0,l.jsx)(s.Form.Item,{children:(0,l.jsx)(s.Button,{type:`dashed`,onClick:()=>t(),block:!0,icon:(0,l.jsx)(c.PlusOutlined,{}),children:`Add field`})})]})})}),(0,l.jsxs)(s.Form.Item,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,children:`Submit`}),(0,l.jsx)(s.Button,{style:{marginLeft:10},onClick:()=>e.resetFields(),children:`Reset`})]})]})})};function iN(e){return(0,l.jsx)(Pb,{children:(0,l.jsx)(AD,{...e})})}var{Text:aN}=s.Typography,oN=[{label:`Total Jobs`,value:1697,icon:`fileText`},{label:`Active Jobs`,value:1685,icon:`checkCircle`},{label:`My Jobs`,value:600,icon:`user`}],sN={fileText:(0,l.jsx)(c.FileTextOutlined,{}),checkCircle:(0,l.jsx)(c.CheckCircleOutlined,{}),user:(0,l.jsx)(c.UserOutlined,{}),filter:(0,l.jsx)(c.FilterOutlined,{})};function cN({stats:e=oN}){return(0,l.jsx)(s.Card,{children:(0,l.jsx)(s.Row,{gutter:[12,12],children:e.map(e=>(0,l.jsx)(s.Col,{xs:24,sm:24,md:8,lg:8,xl:8,children:(0,l.jsxs)(s.Card,{className:`stats-inner-card`,children:[(0,l.jsxs)(s.Space,{align:`center`,children:[sN[e.icon]??sN.fileText,(0,l.jsx)(aN,{children:e.label})]}),(0,l.jsx)(s.Statistic,{value:e.value})]})},e.label))})})}var{Text:lN}=s.Typography;function uN(e){return e?.USER_NAME??e?.user_name??e?.username??e?.name??e?.full_name??e?.fullName??e?.email??`User ${e?.USER_ID??e?.user_id??`?`}`}function dN(e){return{...e,key:e.USER_ID??e.user_id??e.userId??e.id??e._id,_name:uN(e),_email:e.email??e.EMAIL??e.user_email??``,_role:e.role_name??e.roleName??e.ROLE_NAME??``,_rawRef:e}}function fN(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(0),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(1),[p,m]=(0,o.useState)(10),[h,g]=(0,o.useState)(``),_=(0,o.useCallback)(async({offset:e,limit:r,searchQuery:a}={})=>{u(!0);try{let o=await n.yr({offset:e,limit:r,searchQuery:a??``}),s=(o.users??[]).map(dN);t(s),i(o.total??s.length)}catch{s.message.error(`Failed to load users`)}finally{u(!1)}},[]);return(0,o.useEffect)(()=>{queueMicrotask(()=>{_({offset:(d-1)*p,limit:p,searchQuery:h})})},[_,d,p,h]),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.TeamOutlined,{}),title:`Users`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Users`,dataSource:e,fields:[{label:`Name`,value:`_name`,width:220,render:(e,t)=>(0,l.jsxs)(`div`,{children:[(0,l.jsx)(lN,{strong:!0,style:{fontSize:13},children:e}),t._email&&(0,l.jsx)(`div`,{style:{fontSize:11,color:`var(--color-text-muted)`},children:t._email})]})},{label:`Role`,value:`_role`,width:180}],loading:a,total:r,current:d,pageSize:p,onPageChange:e=>f(e),onPageSizeChange:e=>{m(e),f(1)},onSearch:e=>{g(e),f(1)}})})}var{Text:pN}=s.Typography,mN=[{key:`job`,label:`Jobs`},{key:`candidate`,label:`Candidates`},{key:`submissions`,label:`Submissions`}],hN=[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`}];function gN({field:e,index:t,onToggle:n,onReorder:r}){let i=(0,o.useRef)(null),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(!1);function p(e){i.current=t,e.dataTransfer.effectAllowed=`move`,f(!0)}function m(){f(!1),u(!1)}function h(e){e.preventDefault(),u(!0)}function g(){u(!1)}function _(e){e.preventDefault(),u(!1),i.current!==null&&i.current!==t&&r(i.current,t),i.current=null}return(0,l.jsxs)(`div`,{draggable:!0,onDragStart:p,onDragEnd:m,onDragOver:h,onDragLeave:g,onDrop:_,className:`uss-field-row with-edit${a?` drag-over`:``}${d?` dragging`:``}`,children:[(0,l.jsx)(`span`,{className:`uss-drag-handle`,children:(0,l.jsx)(c.HolderOutlined,{})}),(0,l.jsxs)(`span`,{className:`uss-field-name`,children:[e.fieldName,(0,l.jsx)(`span`,{className:`uss-field-key`,children:e.fieldKey})]}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:e.isVisible,onChange:e=>n(t,`isVisible`,e)})}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:!!e.isEditable,onChange:e=>n(t,`isEditable`,e)})}),(0,l.jsx)(`span`,{className:`uss-toggle-cell`,children:(0,l.jsx)(s.Switch,{size:`small`,checked:!!e.ismandatory,onChange:e=>n(t,`ismandatory`,e)})})]})}function _N({team:e,configType:t}){let[r,i]=(0,o.useState)({}),[a,c]=(0,o.useState)(!1),[u,d]=(0,o.useState)({}),[f,p]=(0,o.useState)(`job`);(0,o.useEffect)(()=>{e&&(c(!0),n.Qr(e,t).then(i).catch(()=>s.message.error(`Failed to load field config`)).finally(()=>c(!1)))},[e,t]);let m=r[f]??[];function h(e,t){i(n=>({...n,[e]:typeof t==`function`?t(n[e]??[]):t}))}function g(e,t,n){h(f,r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))}function _(e,t){h(f,n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r.map((e,t)=>({...e,order:t}))})}async function v(){let r=f;d(e=>({...e,[r]:!0}));try{await n.Ti(e,r,m,t),s.message.success(`Saved`)}catch{s.message.error(`Save failed`)}finally{d(e=>({...e,[r]:!1}))}}return(0,l.jsxs)(s.Spin,{spinning:a,children:[(0,l.jsx)(s.Tabs,{size:`small`,activeKey:f,onChange:p,items:mN.map(e=>({key:e.key,label:e.label}))}),(0,l.jsxs)(`div`,{className:`uss-field-header with-edit`,children:[(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{children:`Field`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Visible`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Editable`}),(0,l.jsx)(`span`,{style:{textAlign:`center`},children:`Mandatory`})]}),(0,l.jsxs)(`div`,{className:`uss-field-list`,children:[m.length===0&&!a&&(0,l.jsx)(`div`,{className:`uss-empty`,children:`No fields found.`}),m.map((e,t)=>(0,l.jsx)(gN,{field:e,index:t,onToggle:g,onReorder:_},e.fieldKey??t))]}),(0,l.jsx)(`div`,{className:`uss-modal-footer`,children:(0,l.jsxs)(s.Button,{type:`primary`,size:`small`,loading:u[f],onClick:v,children:[`Save `,mN.find(e=>e.key===f)?.label]})})]})}function vN(){let[e,t]=(0,o.useState)(null),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(!1),[d,f]=(0,o.useState)(`listView`),[p,m]=(0,o.useState)([]),[h,g]=(0,o.useState)(0),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(``),[x,S]=(0,o.useState)(!1),C=(0,o.useCallback)(async()=>{v(!0);try{let e=await n.vr();m(e.teams),g(e.total)}catch{s.message.error(`Failed to load teams`)}finally{v(!1)}},[]);(0,o.useEffect)(()=>{C()},[C]);function w(e){t(e),f(`listView`),i(!0)}function T(e){t(e),b(e.teamName??``),u(!0)}async function E(){if(!y.trim()){s.message.warning(`Team name is required`);return}S(!0);try{await n.wi(e,{teamName:y.trim(),managerId:e.managerId,memberIds:e.memberIds}),s.message.success(`Team updated`),u(!1),C()}catch{s.message.error(`Failed to update team`)}finally{S(!1)}}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.TeamOutlined,{}),title:`Teams`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Teams`,dataSource:p,fields:[{label:`Team Name`,value:`teamName`,width:200},{label:`Manager`,value:`manager`,width:200},{label:`Members`,value:`memberCount`,width:90,sorter:!1},{label:`Actions`,value:`_actions`,width:160,sorter:!1,render:(e,t)=>(0,l.jsxs)(`div`,{style:{display:`flex`,gap:4},children:[(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>T(t),children:`Edit`}),(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>w(t),children:`Configure`})]})}],loading:_,total:h})}),(0,l.jsx)(s.Modal,{open:a,onCancel:()=>u(!1),title:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.TeamOutlined,{style:{color:`var(--color-brand)`,marginRight:6}}),`Edit Team`]}),width:420,footer:null,destroyOnClose:!0,children:(0,l.jsxs)(`div`,{className:`uss-edit-team-body`,style:{paddingTop:12},children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`uss-edit-team-label`,children:`Team Name`}),(0,l.jsx)(s.Input,{value:y,onChange:e=>b(e.target.value),onPressEnter:E,placeholder:`Enter team name`})]}),(0,l.jsxs)(`div`,{className:`uss-modal-footer`,children:[(0,l.jsx)(s.Button,{onClick:()=>u(!1),children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,loading:x,onClick:E,children:`Save`})]})]})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,open:r,onCancel:()=>i(!1),title:(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.TeamOutlined,{style:{color:`var(--color-brand)`}}),(0,l.jsxs)(`span`,{children:[`Configure: `,e?.teamName]})]}),width:720,footer:null,destroyOnClose:!0,children:[(0,l.jsx)(`div`,{style:{marginBottom:12},children:(0,l.jsx)(`div`,{className:`uss-config-toggle`,children:hN.map(e=>(0,l.jsx)(`button`,{className:`uss-config-btn${d===e.key?` active`:``}`,onClick:()=>f(e.key),children:e.label},e.key))})}),e&&(0,l.jsx)(_N,{team:e,configType:d},`${e?.teamId}-${d}`)]})]})}var yN=[`view`,`add`,`edit`,`delete`],bN={view:`View`,add:`Add`,edit:`Edit`,delete:`Delete`,sourcing:`Sourcing`,assign:`Assign`,share:`Share`,change_status:`Status`,my_jobs:`My Jobs`,all_jobs:`All Jobs`,po_msa:`PO MSA`,reApprove:`ReApprove`,sendApprove:`Send Approve`};function xN(e){return bN[e]??e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function SN(e){let t=yN.filter(t=>e.includes(t)),n=e.filter(e=>!yN.includes(e)).sort();return[...t,...n]}function CN(e){let t=new Set;return Object.values(e).forEach(({permissions:e})=>Object.keys(e??{}).forEach(e=>t.add(e))),SN([...t])}function wN(e){let t=0,n=0;return Object.entries(e).forEach(([e,{permissions:r}])=>{Object.entries(r??{}).forEach(([r,{value:i}])=>{Kx(e,r)&&(n++,i===`1`&&t++)})}),{enabled:t,total:n}}function TN(e={}){if(!e||typeof e!=`object`)return e;let t=Object.keys(e).find(e=>String(e).trim().toLowerCase()===`onboarding`);if(!t)return e;let n=e[t]??{},r={...n.permissions??{}};for(let e of[`sendApprove`,`reApprove`])Object.keys(r).some(t=>t.toLowerCase()===e.toLowerCase())||(r[e]={id:0,value:`0`});return{...e,[t]:{...n,permissions:r}}}function EN({value:e,onSave:t,className:n}){let[r,i]=(0,o.useState)(!1),[a,s]=(0,o.useState)(e);(0,o.useEffect)(()=>{s(e)},[e]);function u(){i(!1);let n=a.trim();n&&n!==e?t(n):s(e)}return r?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-inline-input${n?` ${n}`:``}`,value:a,style:{width:Math.max(48,a.length*8)},onChange:e=>s(e.target.value),onBlur:u,onKeyDown:t=>{t.key===`Enter`&&u(),t.key===`Escape`&&(i(!1),s(e)),t.stopPropagation()},onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`span`,{className:`perm-editable-name${n?` ${n}`:``}`,onDoubleClick:e=>{e.stopPropagation(),i(!0)},children:[e,(0,l.jsx)(c.EditOutlined,{className:`perm-name-edit-icon`})]})}function DN({entry:e,label:t,onToggle:n,onLabelSave:r}){let[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(t),f=e?.value===`1`,p=!!e;(0,o.useEffect)(()=>{d(t)},[t]);function m(){a(!1);let e=u.trim();e&&e!==t?r(e):d(t)}return(0,l.jsx)(s.Tooltip,{title:p?f?`Click to disable`:`Click to enable`:`Not applicable for this module`,children:(0,l.jsxs)(`div`,{className:`perm-action-pill${f?` on`:``}${p?``:` na`}`,onClick:()=>{!i&&p&&n()},children:[(0,l.jsx)(`span`,{className:`perm-action-pill-dot${f?` on`:``}`}),i?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-pill-input`,value:u,style:{width:Math.max(36,u.length*7)},onChange:e=>d(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&(a(!1),d(t)),e.stopPropagation()},onClick:e=>e.stopPropagation()}):(0,l.jsx)(`span`,{className:`perm-action-pill-label`,onDoubleClick:e=>{e.stopPropagation(),a(!0)},children:t}),f&&!i&&(0,l.jsx)(c.CheckOutlined,{className:`perm-action-pill-check`})]})})}function ON({menuName:e,menuData:t,permKeys:n,onChange:r,displayName:i,actionLabels:a,onModuleLabelSave:o,onActionLabelSave:s}){let c=t?.permissions??{},u=n.filter(t=>Kx(e,t)),d=u.filter(e=>c[e]?.value===`1`).length,f=u.filter(e=>c[e]).length,p=f>0&&d===f;return(0,l.jsxs)(`div`,{className:`perm-module-card${p?` all-on`:d>0&&!p?` some-on`:``}`,children:[(0,l.jsxs)(`div`,{className:`perm-module-card-header`,children:[(0,l.jsx)(EN,{value:i,onSave:t=>o(e,t),className:`perm-module-card-name`}),f>0&&(0,l.jsxs)(`span`,{className:`perm-module-card-badge${d>0?` active`:``}`,children:[d,`/`,f]})]}),(0,l.jsx)(`div`,{className:`perm-module-card-body`,children:u.map(t=>(0,l.jsx)(DN,{entry:c[t],label:a[t]??xN(t),onToggle:()=>r(e,t),onLabelSave:e=>s(t,e)},t))})]})}function kN({role:e,moduleLabels:t={},actionLabels:r={},onModuleLabelSave:i=()=>{},onActionLabelSave:a=()=>{}}){let[u,d]=(0,o.useState)({}),[f,p]=(0,o.useState)({}),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)(!1),b=n.qr(e);(0,o.useEffect)(()=>{b&&(h(!0),y(!1),n.Xr(b).then(e=>{let t=TN(e);d(t),p(t)}).catch(()=>s.message.error(`Failed to load permissions`)).finally(()=>h(!1)))},[b]);function x(e,t){y(!0),p(n=>{let r=n[e]??{menuId:u[e]?.menuId??0,permissions:{}},i=r.permissions?.[t]??{id:0,value:`0`};return{...n,[e]:{...r,permissions:{...r.permissions,[t]:{...i,value:i.value===`1`?`0`:`1`}}}}})}async function S(){_(!0);try{await n.Si(b,f),d(f),y(!1),s.message.success(`Permissions saved`)}catch(e){s.message.error(e?.message||`Save failed`)}finally{_(!1)}}let C=(0,o.useMemo)(()=>Object.keys(f).sort(),[f]),w=(0,o.useMemo)(()=>CN(f),[f]),{enabled:T,total:E}=(0,o.useMemo)(()=>wN(f),[f]);return(0,l.jsxs)(s.Spin,{spinning:m,children:[(0,l.jsxs)(`div`,{className:`perm-panel-header`,children:[(0,l.jsxs)(`div`,{className:`perm-panel-title`,children:[(0,l.jsx)(c.LockOutlined,{style:{color:`var(--color-brand)`,marginRight:6}}),(0,l.jsx)(`span`,{children:e?.roleName}),!m&&E>0&&(0,l.jsxs)(s.Tag,{color:`blue`,style:{marginLeft:8,fontSize:11},children:[T,`/`,E,` enabled`]})]}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.UnlockOutlined,{}),loading:g,disabled:!v,onClick:S,children:`Save Changes`})]}),(0,l.jsxs)(`div`,{className:`perm-hint`,children:[(0,l.jsx)(c.InfoCircleOutlined,{className:`perm-hint-icon`}),(0,l.jsxs)(`span`,{children:[`Click a pill to toggle. `,(0,l.jsx)(`strong`,{children:`Double-click`}),` a module name or action label to rename it — labels are saved locally.`]})]}),C.length===0&&!m?(0,l.jsx)(`div`,{className:`perm-empty`,children:`No permission entries found for this role.`}):(0,l.jsx)(`div`,{className:`perm-cards-grid`,children:C.map(e=>(0,l.jsx)(ON,{menuName:e,menuData:f[e],permKeys:w,onChange:x,displayName:t[e]??e,actionLabels:r,onModuleLabelSave:i,onActionLabelSave:a},e))})]})}var{Text:AN}=s.Typography,jN=[{key:`listView`,label:`List View`},{key:`filter`,label:`Filter`},{key:`form`,label:`Form`},{key:`permissions`,label:`Permissions`}];function MN(e){return String(e||``).replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()).trim()}function NN(e){return String(e||``).trim().toLowerCase()}function PN(e){return e?.key||e?.collectionName||e?.value||``}function FN(e=[],t=[]){let n=[],r=new Set,i=new Set,a=new Set;return e.forEach(e=>{let t=PN(e);if(!t)return;let o=NN(e.key||t),s=NN(e.collectionName);e.seeded&&(i.add(o),s&&i.add(s)),s&&a.add(s),r.add(t),n.push({label:e.label||MN(t),value:t,disabled:!!e.seeded})}),t.forEach(e=>{let t=String(e||``).trim();if(!t||r.has(t))return;let o=NN(t);a.has(o)||i.has(o)||(r.add(t),n.push({label:MN(t),value:t,disabled:!1}))}),n}function IN(){let[e,t]=(0,o.useState)(null),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(`listView`),[d,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(0),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)([]),[x,S]=(0,o.useState)(!1),[C,w]=(0,o.useState)(!1),T=(0,o.useMemo)(()=>_.filter(e=>!e.disabled),[_]),E=!x&&T.length===0,D=(0,o.useCallback)(async()=>{g(!0);try{let e=await n._r();f(e.roles),m(e.total)}catch{s.message.error(`Failed to load roles`)}finally{g(!1)}},[]),O=(0,o.useCallback)(async()=>{S(!0);try{let[e,t]=await Promise.all([n.Ar(),n.xr()]),r=FN(e.modules,t),i=new Set(r.filter(e=>!e.disabled).map(e=>e.value));v(r),b(e=>e.filter(e=>i.has(e)))}catch{s.message.error(`Failed to load seed status`)}finally{S(!1)}},[]);(0,o.useEffect)(()=>{D()},[D]),(0,o.useEffect)(()=>{O()},[O]);async function k(){if(y.length===0){s.message.warning(E?`All modules already seeded.`:`Select at least one module to seed.`);return}w(!0);try{await n.pi(y),s.message.success(`Role field config seeded`),b([]),await O()}catch(e){s.message.error(e?.message||`Seed failed`)}finally{w(!1)}}function A(e,n=`listView`){t(e),u(n),i(!0)}return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Field Config Seed`,style:{marginBottom:12},children:[(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:12,flexWrap:`wrap`},children:[(0,l.jsx)(`div`,{style:{minWidth:320,flex:1},children:(0,l.jsx)(s.Select,{mode:`multiple`,allowClear:!0,showSearch:!0,value:y,options:_,placeholder:E?`All modules already seeded`:`Select modules or collections to seed`,disabled:x||C||E,loading:x,onChange:b,style:{width:`100%`}})}),(0,l.jsx)(s.Button,{type:`primary`,loading:C,disabled:x||y.length===0,onClick:k,children:`Seed Field Config`})]}),(0,l.jsx)(AN,{type:`secondary`,style:{display:`block`,marginTop:8,fontSize:12},children:E?`Seed is disabled because all configured modules already have role field config data.`:`Already seeded modules are disabled. New modules or collections can still be seeded.`})]}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.SafetyOutlined,{}),title:`Roles`,style:{marginBottom:0},bodyStyle:{padding:0},children:(0,l.jsx)($m,{listName:`Roles`,dataSource:d,fields:[{label:`Role Name`,value:`roleName`,width:200},{label:`Description`,value:`description`,width:240},{label:`Users`,value:`userCount`,width:70,sorter:!1},{label:`Actions`,value:`_configure`,width:200,sorter:!1,render:(e,t)=>(0,l.jsxs)(s.Space,{size:2,children:[(0,l.jsx)(s.Button,{size:`small`,type:`link`,onClick:()=>A(t),children:`Configure`}),(0,l.jsx)(s.Button,{size:`small`,type:`link`,icon:(0,l.jsx)(c.LockOutlined,{}),onClick:()=>A(t,`permissions`),children:`Permissions`})]})}],loading:h,total:p})}),(0,l.jsxs)(s.Modal,{className:`uss-modal`,open:r,onCancel:()=>i(!1),title:(0,l.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.SafetyOutlined,{style:{color:`var(--color-brand)`}}),(0,l.jsxs)(`span`,{children:[`Configure: `,e?.roleName]})]}),width:720,footer:null,destroyOnClose:!0,children:[(0,l.jsx)(`div`,{style:{marginBottom:12},children:(0,l.jsx)(`div`,{className:`uss-config-toggle`,children:jN.map(e=>(0,l.jsx)(`button`,{className:`uss-config-btn${a===e.key?` active`:``}`,onClick:()=>u(e.key),children:e.label},e.key))})}),e&&(a===`permissions`?(0,l.jsx)(kN,{role:e},e?.roleId):(0,l.jsx)(lS,{role:e,configType:a},`${e?.roleId}-${a}`))]})]})}var LN=`perm-module-labels`,RN=`perm-action-labels`;function zN(e){try{return JSON.parse(localStorage.getItem(e)??`{}`)}catch{return{}}}function BN(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}function VN({label:e,onSave:t,onDelete:n,loading:r}){let[i,a]=(0,o.useState)(!1),[u,d]=(0,o.useState)(e);function f(){a(!1);let n=u.trim();n&&n!==e?t(n):d(e)}return(0,l.jsxs)(`div`,{className:`perm-manage-row`,children:[i?(0,l.jsx)(`input`,{autoFocus:!0,className:`perm-inline-input`,value:u,style:{flex:1,minWidth:0},onChange:e=>d(e.target.value),onBlur:f,onKeyDown:t=>{t.key===`Enter`&&f(),t.key===`Escape`&&(a(!1),d(e))}}):(0,l.jsx)(`span`,{className:`perm-manage-row-label`,children:e}),(0,l.jsxs)(`div`,{className:`perm-manage-row-actions`,children:[(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>{d(e),a(!0)},loading:r}),(0,l.jsx)(s.Popconfirm,{title:`Delete this item?`,onConfirm:n,okText:`Delete`,cancelText:`Cancel`,okType:`danger`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{}),danger:!0})})]})]})}function HN({open:e,onClose:t}){let[r,i]=(0,o.useState)(`modules`),[a,u]=(0,o.useState)([]),[d,f]=(0,o.useState)(!1),[p,m]=(0,o.useState)(``),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(``),[C,w]=(0,o.useState)(``),[T,E]=(0,o.useState)(!1);(0,o.useEffect)(()=>{e&&(D(),O())},[e]);async function D(){f(!0);try{u(await n.Lr())}catch{s.message.error(`Failed to load modules`)}finally{f(!1)}}async function O(){b(!0);try{v(await n.Ir())}catch{s.message.error(`Failed to load actions`)}finally{b(!1)}}async function k(){let e=p.trim();if(!e){s.message.warning(`Enter a module name`);return}g(!0);try{let t=await n.Qn({menuName:e});u(e=>[...e,t]),m(``),s.message.success(`Module added`)}catch{s.message.error(`Failed to add module`)}finally{g(!1)}}async function A(e,t){try{await n.vi(e,{menuName:t}),u(n=>n.map(n=>n.MENUID===e?{...n,MENUNAME:t}:n))}catch{s.message.error(`Failed to update module`)}}async function j(e){try{await n.sr(e),u(t=>t.filter(t=>t.MENUID!==e)),s.message.success(`Module deleted`)}catch{s.message.error(`Failed to delete module`)}}async function M(){let e=x.trim(),t=C.trim().toLowerCase().replace(/\s+/g,`_`);if(!e||!t){s.message.warning(`Enter both name and key`);return}E(!0);try{let r=await n.Zn({permissionName:e,permissionKey:t});v(e=>[...e,r]),S(``),w(``),s.message.success(`Action added`)}catch(e){s.message.error(e?.message?.includes(`409`)||e?.status===409?`Permission key already exists`:`Failed to add action`)}finally{E(!1)}}async function N(e,t){try{await n._i(e,{permissionName:t}),v(n=>n.map(n=>n.permissionId===e?{...n,permissionName:t}:n))}catch{s.message.error(`Failed to update action`)}}async function P(e){try{await n.or(e),v(t=>t.filter(t=>t.permissionId!==e)),s.message.success(`Action deleted`)}catch{s.message.error(`Failed to delete action`)}}let F=[{key:`modules`,label:`Modules`,children:(0,l.jsxs)(s.Spin,{spinning:d,children:[(0,l.jsxs)(`div`,{className:`perm-manage-add-row`,children:[(0,l.jsx)(s.Input,{placeholder:`Module name`,value:p,onChange:e=>m(e.target.value),onPressEnter:k,style:{flex:1},size:`small`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),loading:h,onClick:k,children:`Add`})]}),(0,l.jsxs)(`div`,{className:`perm-manage-list`,children:[a.length===0&&!d&&(0,l.jsx)(`div`,{className:`perm-empty`,style:{paddingTop:24},children:`No modules found`}),a.map(e=>(0,l.jsx)(VN,{label:e.MENUNAME,onSave:t=>A(e.MENUID,t),onDelete:()=>j(e.MENUID)},e.MENUID))]})]})},{key:`actions`,label:`Actions`,children:(0,l.jsxs)(s.Spin,{spinning:y,children:[(0,l.jsxs)(`div`,{className:`perm-manage-add-row`,children:[(0,l.jsx)(s.Input,{placeholder:`Action name (e.g. Approve)`,value:x,onChange:e=>S(e.target.value),style:{flex:1},size:`small`}),(0,l.jsx)(s.Input,{placeholder:`Key (e.g. approve)`,value:C,onChange:e=>w(e.target.value),onPressEnter:M,style:{width:140},size:`small`}),(0,l.jsx)(s.Button,{type:`primary`,size:`small`,icon:(0,l.jsx)(c.PlusOutlined,{}),loading:T,onClick:M,children:`Add`})]}),(0,l.jsxs)(`div`,{className:`perm-manage-list`,children:[_.length===0&&!y&&(0,l.jsx)(`div`,{className:`perm-empty`,style:{paddingTop:24},children:`No actions found`}),_.map(e=>(0,l.jsx)(VN,{label:`${e.permissionName} (${e.permissionKey})`,onSave:t=>N(e.permissionId,t),onDelete:()=>P(e.permissionId)},e.permissionId))]})]})}];return(0,l.jsx)(s.Modal,{open:e,onCancel:t,title:(0,l.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,l.jsx)(c.SettingOutlined,{style:{color:`var(--color-brand)`}}),`Manage Modules & Actions`]}),width:520,footer:null,destroyOnClose:!0,children:(0,l.jsx)(s.Tabs,{activeKey:r,onChange:i,size:`small`,items:F})})}function UN(){let[e,t]=(0,o.useState)([]),[r,i]=(0,o.useState)(!1),[a,u]=(0,o.useState)(null),[d,f]=(0,o.useState)(``),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(()=>zN(LN)),[_,v]=(0,o.useState)(()=>zN(RN)),y=(0,o.useCallback)((e,t)=>{g(n=>{let r={...n,[e]:t};return BN(LN,r),r})},[]),b=(0,o.useCallback)((e,t)=>{v(n=>{let r={...n,[e]:t};return BN(RN,r),r})},[]);function x(){g({}),v({}),BN(LN,{}),BN(RN,{}),s.message.success(`Labels reset to defaults`)}let S=(0,o.useCallback)(async()=>{i(!0);try{let{roles:e}=await n._r();t(e),e.length>0&&u(e[0])}catch{s.message.error(`Failed to load roles`)}finally{i(!1)}},[]);(0,o.useEffect)(()=>{S()},[S]);let C=(0,o.useMemo)(()=>{let t=d.trim().toLowerCase();return t?e.filter(e=>e.roleName.toLowerCase().includes(t)):e},[e,d]),w=Object.keys(h).length>0||Object.keys(_).length>0;return(0,l.jsxs)(`div`,{className:`perm-page`,children:[(0,l.jsxs)(Z,{className:`perm-left-card`,icon:(0,l.jsx)(c.SafetyOutlined,{}),title:`Roles`,bodyStyle:{padding:0},children:[(0,l.jsx)(`div`,{className:`perm-role-search`,children:(0,l.jsx)(s.Input,{prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search roles…`,allowClear:!0,size:`small`,value:d,onChange:e=>f(e.target.value)})}),(0,l.jsx)(s.Spin,{spinning:r,children:(0,l.jsxs)(`div`,{className:`perm-role-list`,children:[C.length===0&&!r&&(0,l.jsx)(`div`,{className:`perm-role-empty`,children:`No roles found`}),C.map(e=>{let t=a?.roleId===e.roleId,n=e.description&&e.description!==`N/A`?e.description:e.roleType===0?`Default role`:`Custom role`;return(0,l.jsxs)(`div`,{className:`perm-role-item${t?` active`:``}`,onClick:()=>u(e),children:[(0,l.jsx)(`div`,{className:`perm-role-item-name`,children:e.roleName}),(0,l.jsx)(`div`,{className:`perm-role-item-desc`,children:n})]},e.roleId)})]})})]}),(0,l.jsx)(Z,{className:`perm-right-card`,icon:(0,l.jsx)(c.LockOutlined,{}),title:`Module Permissions`,extra:(0,l.jsxs)(`span`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[w&&(0,l.jsx)(`button`,{className:`perm-reset-btn`,onClick:x,children:`Reset labels`}),(0,l.jsx)(s.Button,{size:`small`,icon:(0,l.jsx)(c.SettingOutlined,{}),onClick:()=>m(!0),children:`Manage`})]}),bodyStyle:{padding:`12px 16px`},children:a?(0,l.jsx)(kN,{role:a,moduleLabels:h,actionLabels:_,onModuleLabelSave:y,onActionLabelSave:b},a.roleId):(0,l.jsx)(`div`,{className:`perm-empty`,children:`Select a role from the left to manage its permissions.`})}),(0,l.jsx)(HN,{open:p,onClose:()=>m(!1)})]})}var{Title:WN,Text:GN}=s.Typography,KN=[{label:`In Progress`,value:107,sub:`Under review`,color:`blue`},{label:`Hired`,value:2,sub:`Onboarded`,color:`green`},{label:`Project Completed`,value:2,sub:`Project cycle closed`,color:`purple`},{label:`Archive`,value:2,sub:`No longer active`,color:`peach`}];function qN({items:e=KN}){return(0,l.jsx)(s.Card,{className:`onboarding-card`,title:(0,l.jsx)(WN,{level:5,children:`Onboarding`}),extra:(0,l.jsx)(s.Button,{type:`link`,children:`View all`}),children:(0,l.jsx)(s.Row,{gutter:[12,12],children:e.map(e=>(0,l.jsx)(s.Col,{xs:12,sm:6,md:6,lg:12,xl:12,children:(0,l.jsxs)(`div`,{className:`onboarding-item ${e.color}`,children:[(0,l.jsx)(GN,{className:`onboarding-item-label`,children:e.label}),(0,l.jsx)(s.Statistic,{value:e.value,className:`onboarding-stat`}),(0,l.jsx)(`div`,{className:`onboarding-item-footer`,children:(0,l.jsx)(GN,{className:`onboarding-item-sub`,children:e.sub})})]})},e.label))})})}var{Text:JN,Title:YN}=s.Typography,XN=[{group:`Dashboard`,items:[{id:`dashboard`,label:`Admin Dashboard`,icon:(0,l.jsx)(c.DashboardOutlined,{})}]},{group:`Settings`,items:[{id:`org`,label:`Organization`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Organization Settings`,desc:`Manage your company profile and location details`,cards:[{label:`Company Information`,icon:(0,l.jsx)(c.BankOutlined,{}),desc:`Manage company profile, address and business details.`},{label:`Location`,icon:(0,l.jsx)(c.BuildOutlined,{}),desc:`Manage office locations, branches and regions.`}]},{id:`users`,label:`Users`,icon:(0,l.jsx)(c.UserOutlined,{}),heading:`Users`,desc:`Manage platform users and configure their field views.`,component:`users`},{id:`teams`,label:`Teams`,icon:(0,l.jsx)(c.TeamOutlined,{}),heading:`Teams`,desc:`Organize users into teams and configure field visibility per team.`,component:`teams`},{id:`roles`,label:`Roles`,icon:(0,l.jsx)(c.SafetyOutlined,{}),heading:`Roles`,desc:`Control permissions and configure field visibility per role.`,component:`roles`},{id:`permissions`,label:`Permissions`,icon:(0,l.jsx)(c.LockOutlined,{}),heading:`Permissions`,desc:`Manage module-wise action permissions (view, add, edit, delete, and more) per role.`,component:`permissions`},{id:`templates`,label:`Templates`,icon:(0,l.jsx)(c.FileTextOutlined,{}),heading:`Templates`,desc:`Email and signature templates for communications`,component:`templates`},{id:`ai-services`,label:`AI Services`,icon:(0,l.jsx)(c.ThunderboltOutlined,{}),heading:`AI Services`,desc:`Register the AI/automation backends (base URL + auth) that admin-configured AI Actions call.`,component:`ai-services`},{id:`bgc-integration`,label:`Integrations`,icon:(0,l.jsx)(c.SafetyOutlined,{}),heading:`Integrations`,desc:`Manage manual and API integrations used across application workflows.`,component:`bgc-integration`}]},{group:`Clients`,items:[{id:`clients`,label:`Clients`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Clients`,desc:`Manage client accounts and settings`,cards:[{label:`Clients`,icon:(0,l.jsx)(c.BankOutlined,{}),desc:`Manage client companies and account details.`}]}]},{group:`Forms`,items:[{id:`form-groups`,label:`Form Groups`,icon:(0,l.jsx)(c.AppstoreAddOutlined,{}),heading:`Form Groups`,desc:`Define field groups for module add/edit forms with validations and dropdown sources.`,component:`form-groups`},{id:`detail-groups`,label:`Detail Groups`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),heading:`Detail Groups`,desc:`Customize the detail view per module: labels, prefix/suffix, colour, capitalization, reference lookups and merged fields.`,component:`detail-groups`},{id:`row-actions`,label:`Actions`,icon:(0,l.jsx)(c.ToolOutlined,{}),heading:`Actions`,desc:`Configure which action buttons appear per row in each module's list view, scoped per role.`,component:`row-actions`}]},{group:`Master`,items:[{id:`jobs`,label:`Jobs`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),heading:`Jobs Master`,desc:`Configure job sources and status types`,cards:[{label:`Sources`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Manage job source master values.`},{label:`Job Status`,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),desc:`Configure job workflow status.`}]},{id:`candidates`,label:`Candidates`,icon:(0,l.jsx)(c.UserOutlined,{}),heading:`Candidates Master`,desc:`Skills, sources and work authorization settings`,cards:[{label:`Sources`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Manage candidate source values.`},{label:`Skills`,icon:(0,l.jsx)(c.SettingOutlined,{}),desc:`Manage skill master data.`},{label:`Work Authorization`,icon:(0,l.jsx)(c.SafetyOutlined,{}),desc:`Manage visa and authorization types.`}]},{id:`submissions`,label:`Submissions`,icon:(0,l.jsx)(c.FileTextOutlined,{}),heading:`Submissions Master`,desc:`Rejection reasons and submission status configuration`,cards:[{label:`Rejection Reasons`,icon:(0,l.jsx)(c.FileTextOutlined,{}),desc:`Manage common rejection reasons.`},{label:`Client Submission Status`,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),desc:`Manage client submission statuses.`}]},{id:`clientmaster`,label:`Client Master`,icon:(0,l.jsx)(c.BankOutlined,{}),heading:`Client Master`,desc:`Payment terms, client types and contact types`,cards:[{label:`Payment Terms`,icon:(0,l.jsx)(c.FileTextOutlined,{}),desc:`Manage billing and payment terms.`},{label:`Client Type`,icon:(0,l.jsx)(c.AppstoreOutlined,{}),desc:`Classify client business types.`},{label:`Client Contact Type`,icon:(0,l.jsx)(c.TeamOutlined,{}),desc:`Manage client contact categories.`}]}]}],ZN=[{label:`Sourced`,count:312,color:`#378ADD`,pct:35},{label:`Screened`,count:223,color:`#7F77DD`,pct:25},{label:`Interview`,count:161,color:`#1D9E75`,pct:18},{label:`Offered`,count:107,color:`#EF9F27`,pct:12},{label:`Rejected`,count:89,color:`#E24B4A`,pct:10}],QN=[{name:`Tcs`,jobs:14,candidates:86},{name:`Empasis`,jobs:9,candidates:64},{name:`NovaSystems`,jobs:7,candidates:51},{name:`Brightwave`,jobs:5,candidates:38}],$N=[{text:`New candidate Ravi Kumar added to Java Developer role`,time:`2 min ago`,color:`#378ADD`},{text:`Submission approved by Acme Corp for Sr. React Dev`,time:`18 min ago`,color:`#1D9E75`},{text:`User Priya S. added to Recruiters team`,time:`1 hr ago`,color:`#7F77DD`},{text:`Job Data Analyst — TechFlow moved to archived`,time:`3 hr ago`,color:`#EF9F27`},{text:`Candidate rejected — work authorization mismatch`,time:`5 hr ago`,color:`#E24B4A`}];function eP(){return(0,l.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:16},children:[(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.DashboardOutlined,{}),title:`Admin Dashboard`,children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(YN,{level:5,children:`Admin Dashboard`}),(0,l.jsx)(JN,{type:`secondary`,children:`Overview of jobs, candidates, onboarding and recent activity`})]}),(0,l.jsx)(`div`,{className:`admin-dashboard-stats`,children:(0,l.jsx)(cN,{stats:[{label:`Total Jobs`,value:1697,icon:`fileText`},{label:`Active Jobs`,value:1685,icon:`checkCircle`},{label:`My Jobs`,value:600,icon:`user`},{label:`Total Candidates`,value:4320,icon:`team`},{label:`Submissions`,value:892,icon:`fileText`}]})}),(0,l.jsxs)(`div`,{className:`admin-dashboard-mid-row`,children:[(0,l.jsx)(qN,{}),(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Candidate Pipeline`,children:[(0,l.jsx)(JN,{type:`secondary`,style:{fontSize:12},children:`By stage (892 total)`}),(0,l.jsx)(`div`,{className:`admin-pipeline-bar`,children:ZN.map(e=>(0,l.jsx)(`div`,{className:`admin-pipeline-seg`,style:{width:`${e.pct}%`,background:e.color}},e.label))}),(0,l.jsx)(`div`,{className:`admin-pipeline-legend`,children:ZN.map(e=>(0,l.jsxs)(`div`,{className:`admin-pipeline-legend-item`,children:[(0,l.jsx)(`span`,{className:`admin-pipeline-dot`,style:{background:e.color}}),e.label,` `,e.count]},e.label))}),(0,l.jsx)(`div`,{className:`admin-divider`}),(0,l.jsx)(JN,{strong:!0,style:{fontSize:12},children:`Submission status`}),(0,l.jsxs)(`div`,{className:`admin-sub-status-list`,style:{marginTop:6},children:[(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(JN,{style:{fontSize:13},children:`Pending client review`}),(0,l.jsx)(`span`,{className:`admin-badge warn`,children:`312`})]}),(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(JN,{style:{fontSize:13},children:`Client approved`}),(0,l.jsx)(`span`,{className:`admin-badge success`,children:`248`})]}),(0,l.jsxs)(`div`,{className:`admin-sub-status-item`,children:[(0,l.jsx)(JN,{style:{fontSize:13},children:`Rejected`}),(0,l.jsx)(`span`,{className:`admin-badge danger`,children:`89`})]})]})]})]}),(0,l.jsxs)(`div`,{className:`admin-dashboard-bottom-row`,children:[(0,l.jsx)(Z,{icon:(0,l.jsx)(c.BankOutlined,{}),title:`Top Clients`,extra:(0,l.jsx)(s.Button,{type:`link`,size:`small`,children:`View all`}),children:QN.map(e=>(0,l.jsxs)(`div`,{className:`admin-client-row`,children:[(0,l.jsxs)(`div`,{className:`admin-client-left`,children:[(0,l.jsx)(`div`,{className:`admin-client-icon`,children:(0,l.jsx)(c.BankOutlined,{})}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`admin-client-name`,children:e.name}),(0,l.jsxs)(`div`,{className:`admin-client-sub`,children:[e.jobs,` open jobs`]})]})]}),(0,l.jsxs)(`div`,{className:`admin-client-right`,children:[(0,l.jsx)(`div`,{className:`admin-client-val`,children:e.candidates}),(0,l.jsx)(`div`,{className:`admin-client-sub`,children:`candidates`})]})]},e.name))}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.BellOutlined,{}),title:`Recent Activity`,children:$N.map((e,t)=>(0,l.jsxs)(`div`,{className:`admin-activity-row`,children:[(0,l.jsx)(`div`,{className:`admin-activity-dot`,style:{background:e.color}}),(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`div`,{className:`admin-activity-text`,children:e.text}),(0,l.jsx)(`div`,{className:`admin-activity-time`,children:e.time})]})]},t))})]}),(0,l.jsx)(Z,{icon:(0,l.jsx)(c.SettingOutlined,{}),title:`Admin Configuration Overview`,extra:(0,l.jsx)(s.Button,{type:`link`,size:`small`,children:`Manage`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(JN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`Settings`}),[[`Organization`,2],[`User Settings`,4],[`Templates`,2]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(JN,{style:{fontSize:12},children:e}),(0,l.jsxs)(`span`,{className:`admin-badge info`,children:[t,` items`]})]},e))]}),(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(JN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`Master`}),[[`Jobs`,2],[`Candidates`,3],[`Submissions`,2]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(JN,{style:{fontSize:12},children:e}),(0,l.jsxs)(`span`,{className:`admin-badge info`,children:[t,` items`]})]},e))]}),(0,l.jsxs)(s.Col,{span:8,children:[(0,l.jsx)(JN,{type:`secondary`,style:{fontSize:12,fontWeight:500},children:`System`}),[[`Total Groups`,4],[`Total Modules`,9],[`Config Items`,19]].map(([e,t])=>(0,l.jsxs)(`div`,{className:`admin-cfg-overview-row`,children:[(0,l.jsx)(JN,{style:{fontSize:12},children:e}),(0,l.jsx)(JN,{strong:!0,style:{fontSize:12},children:t})]},e))]})]})})]})}function tP({activeSection:e,activeGroup:t,filteredCards:n,searchText:r,setSearchText:i,allItems:a,handleNav:o}){return(0,l.jsxs)(s.Row,{gutter:[16,16],children:[(0,l.jsx)(s.Col,{span:24,children:(0,l.jsxs)(Z,{icon:e?.icon,title:e?.heading,extra:(0,l.jsx)(s.Input,{className:`admin-search`,prefix:(0,l.jsx)(c.SearchOutlined,{}),placeholder:`Search settings…`,allowClear:!0,value:r,onChange:e=>i(e.target.value)}),children:[(0,l.jsx)(`div`,{className:`admin-accent-bar`}),(0,l.jsx)(YN,{level:5,children:e?.heading}),(0,l.jsx)(JN,{type:`secondary`,children:e?.desc})]})}),(0,l.jsx)(s.Col,{xs:24,xl:16,style:{alignSelf:`flex-start`},children:(0,l.jsx)(Z,{icon:(0,l.jsx)(c.AppstoreOutlined,{}),title:`Configuration Items`,extra:(0,l.jsxs)(JN,{type:`secondary`,children:[n.length,` item`,n.length===1?``:`s`]}),children:(0,l.jsx)(s.Row,{gutter:[14,14],children:n.length>0?n.map(e=>(0,l.jsx)(s.Col,{xs:24,sm:12,xl:8,children:(0,l.jsxs)(`div`,{className:`admin-config-item`,children:[(0,l.jsx)(`div`,{className:`admin-config-top-bar`}),(0,l.jsxs)(`div`,{className:`admin-config-body`,children:[(0,l.jsx)(`div`,{className:`admin-config-icon`,children:e.icon}),(0,l.jsxs)(`div`,{className:`admin-config-text`,children:[(0,l.jsx)(`span`,{className:`admin-config-label`,children:e.label}),(0,l.jsx)(`span`,{className:`admin-config-desc`,children:e.desc})]})]}),(0,l.jsx)(`div`,{className:`admin-config-divider`}),(0,l.jsx)(s.Button,{type:`link`,size:`small`,className:`admin-config-manage`,icon:(0,l.jsx)(c.RightOutlined,{}),iconPosition:`end`,children:`Manage`})]})},e.label)):(0,l.jsx)(s.Col,{span:24,children:(0,l.jsx)(`div`,{className:`admin-config-empty`,children:(0,l.jsx)(s.Empty,{description:`No settings found`,image:s.Empty.PRESENTED_IMAGE_SIMPLE})})})})})}),(0,l.jsx)(s.Col,{xs:24,xl:8,style:{alignSelf:`flex-start`},children:(0,l.jsxs)(Z,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`Section Overview`,children:[(0,l.jsx)(`div`,{className:`admin-overview-list`,children:XN.filter(e=>e.group!==`Dashboard`).map(e=>{let n=e.group===t?.group;return(0,l.jsxs)(`div`,{className:`admin-overview-item${n?` active`:``}`,onClick:()=>{let t=e.items[0];t&&o(t.id)},children:[(0,l.jsxs)(`div`,{className:`admin-overview-left`,children:[(0,l.jsx)(`div`,{className:`admin-overview-icon`,children:e.items[0]?.icon}),(0,l.jsxs)(`div`,{className:`admin-overview-text`,children:[(0,l.jsx)(`span`,{className:`admin-overview-name`,children:e.group}),(0,l.jsxs)(`span`,{className:`admin-overview-sub`,children:[e.items.length,` module`,e.items.length===1?``:`s`]})]})]}),(0,l.jsx)(`span`,{className:`admin-overview-count${n?` active`:``}`,children:e.items.length})]},e.group)})}),(0,l.jsxs)(`div`,{className:`admin-overview-footer`,children:[(0,l.jsx)(`span`,{className:`admin-overview-footer-label`,children:`Total configuration items`}),(0,l.jsx)(`span`,{className:`admin-overview-footer-value`,children:a.filter(e=>e.cards).reduce((e,t)=>e+t.cards.length,0)})]})]})})]})}function nP(){let[e,t]=(0,o.useState)(`dashboard`),[n,r]=(0,o.useState)(``),i=(0,o.useMemo)(()=>XN.flatMap(e=>e.items),[]),a=(0,o.useMemo)(()=>i.find(t=>t.id===e),[i,e]),u=(0,o.useMemo)(()=>XN.find(t=>t.items.some(t=>t.id===e)),[e]),d=(0,o.useMemo)(()=>{if(!a?.cards)return[];let e=n.trim().toLowerCase();return e?a.cards.filter(t=>t.label.toLowerCase().includes(e)||t.desc.toLowerCase().includes(e)):a.cards},[a,n]),f=(0,o.useMemo)(()=>XN.map(e=>({key:e.group,type:`group`,label:e.group,children:e.items.map(e=>({key:e.id,icon:e.icon,label:e.label}))})),[]),p=e=>{t(e),r(``)};return e===`dashboard`||a?.heading,(0,l.jsxs)(`main`,{className:`admin-page`,children:[(0,l.jsx)(`div`,{className:`admin-breadcrumb`,children:(0,l.jsx)(s.Breadcrumb,{items:[{title:(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(c.HomeOutlined,{}),` Home`]})},{title:`Admin`}]})}),(0,l.jsxs)(s.Row,{gutter:[16,16],className:`admin-wrapper`,children:[(0,l.jsx)(s.Col,{xs:24,lg:6,xl:5,children:(0,l.jsxs)(Z,{title:`Admin Console`,icon:(0,l.jsx)(c.SettingOutlined,{}),children:[(0,l.jsxs)(`div`,{className:`admin-sidebar-banner`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-banner-title`,children:`Admin Panel`}),(0,l.jsx)(`span`,{className:`admin-sidebar-banner-sub`,children:`Configuration Center`}),(0,l.jsxs)(s.Row,{gutter:[8,0],children:[(0,l.jsx)(s.Col,{span:12,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-pill`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-pill-label`,children:`Groups`}),(0,l.jsx)(`span`,{className:`admin-sidebar-pill-value`,children:XN.length})]})}),(0,l.jsx)(s.Col,{span:12,children:(0,l.jsxs)(`div`,{className:`admin-sidebar-pill`,children:[(0,l.jsx)(`span`,{className:`admin-sidebar-pill-label`,children:`Modules`}),(0,l.jsx)(`span`,{className:`admin-sidebar-pill-value`,children:i.length})]})})]})]}),(0,l.jsx)(s.Menu,{mode:`inline`,selectedKeys:[e],items:f,onClick:({key:e})=>p(e),className:`admin-sidebar-menu`})]})}),(0,l.jsx)(s.Col,{xs:24,lg:18,xl:19,children:e===`dashboard`?(0,l.jsx)(eP,{}):a?.component===`form-groups`?(0,l.jsx)(ow,{}):a?.component===`detail-groups`?(0,l.jsx)(Vw,{}):a?.component===`row-actions`?(0,l.jsx)(AT,{}):a?.component===`users`?(0,l.jsx)(fN,{}):a?.component===`teams`?(0,l.jsx)(vN,{}):a?.component===`roles`?(0,l.jsx)(IN,{}):a?.component===`permissions`?(0,l.jsx)(UN,{}):a?.component===`templates`?(0,l.jsx)(HT,{}):a?.component===`ai-services`?(0,l.jsx)(KT,{}):a?.component===`bgc-integration`?(0,l.jsx)(QT,{}):(0,l.jsx)(tP,{activeSection:a,activeGroup:u,filteredCards:d,searchText:n,setSearchText:r,allItems:i,handleNav:p})})]})]})}var{Title:rP}=s.Typography;function iP(){let e=(0,d.useNavigate)(),{state:t}=(0,d.useLocation)(),n=t?.moduleName||`stickyNotes`,r=t?.title||`Sticky Notes`,i={...t?.request,params:{...t?.request?.params,limit:200,offset:0}};return(0,l.jsxs)(`div`,{children:[(0,l.jsx)(s.Button,{type:`text`,icon:(0,l.jsx)(c.ArrowLeftOutlined,{}),onClick:()=>e(-1),style:{marginBottom:12},children:`Back`}),(0,l.jsx)(Rt,{moduleName:n,title:r,columns:4,request:i,viewAll:!1})]})}var{Text:aP,Title:oP}=s.Typography,sP=10485760,cP=`/templates/test_cases_flow_template.base64.txt`,lP=`test_cases_flow_template.xlsx`,uP=`module | subModule | step_order | description | actions | key | value | expected | scenario`,dP={idle:0,module_set:1,encoding:1,validating:2,preview:3,inserting:3,done:4,error:1},fP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Bulk upload`,href:`/bulk-upload`}];function pP(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result).split(`,`)[1]),r.onerror=n,r.readAsDataURL(e)})}function mP(e){return e.filter(e=>e.row_status===`valid`).map(e=>{let t={...e};return delete t.row_status,delete t.errors,t})}function hP(e){return e.flatMap(e=>(e.errors??[]).map(t=>({id:e.id,...t})))}function gP({errors:e}){return(0,l.jsx)(`div`,{className:`bulk-tooltip-errors`,children:(e??[]).map((e,t)=>(0,l.jsx)(`div`,{children:e.message},`${e.field}-${t}`))})}function _P({errors:e,expanded:t,onToggle:n,onSummaryClick:r}){return e.length===0?null:(0,l.jsxs)(`div`,{className:`bulk-error-banner`,children:[(0,l.jsxs)(`div`,{className:`bulk-error-summary`,children:[(0,l.jsxs)(`button`,{type:`button`,className:`bulk-error-summary-main`,onClick:r,"aria-label":`Scroll to first invalid row`,children:[(0,l.jsx)(c.ExclamationCircleOutlined,{className:`bulk-error-icon`}),(0,l.jsxs)(`span`,{children:[e.length,` validation error(s) found`]})]}),(0,l.jsx)(s.Button,{type:`link`,onClick:n,"aria-expanded":t,children:t?`Hide Errors`:`View Errors`})]}),t&&(0,l.jsx)(`div`,{className:`bulk-error-list`,role:`region`,"aria-label":`Validation error details`,children:e.map((e,t)=>(0,l.jsxs)(`div`,{className:`bulk-error-line`,children:[(0,l.jsxs)(`span`,{className:`bulk-row-chip`,children:[`Row `,e.id]}),(0,l.jsx)(`span`,{children:e.message})]},`${e.id}-${e.field}-${t}`))})]})}function vP({rows:e,view:t,onViewChange:n,onConfirm:r,onReset:i,saving:a,firstInvalidRowId:o,firstInvalidRowRef:u}){let d=e.filter(e=>e.row_status===`invalid`),f=t===`errors`?d:e,p=d.length>0||a;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(s.Row,{justify:`space-between`,align:`middle`,gutter:[16,16],className:`bulk-table-toolbar`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space.Compact,{children:[(0,l.jsx)(s.Button,{type:t===`all`?`primary`:`default`,onClick:()=>n(`all`),children:`All rows`}),(0,l.jsx)(s.Button,{type:t===`errors`?`primary`:`default`,onClick:()=>n(`errors`),children:`Errors only`})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsxs)(aP,{type:`secondary`,children:[e.length,` row(s)`]})})]}),(0,l.jsx)(`div`,{className:`bulk-table-wrap`,children:(0,l.jsxs)(`table`,{className:`bulk-preview-table`,children:[(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{children:[(0,l.jsx)(`th`,{className:`bulk-col-row`,children:`Row`}),(0,l.jsx)(`th`,{className:`bulk-col-flow`,children:`Submodule`}),(0,l.jsx)(`th`,{className:`bulk-col-description`,children:`Description`}),(0,l.jsx)(`th`,{className:`bulk-col-keyword`,children:`Action`}),(0,l.jsx)(`th`,{className:`bulk-col-target`,children:`Key`}),(0,l.jsx)(`th`,{className:`bulk-col-status`,children:`Status`}),(0,l.jsx)(`th`,{className:`bulk-col-error`,children:`Error`})]})}),(0,l.jsx)(`tbody`,{children:f.map(e=>{let t=e.errors??[],n=e.row_status===`invalid`;return(0,l.jsxs)(`tr`,{ref:n&&e.id===o?u:null,className:n?`bulk-row-invalid`:``,children:[(0,l.jsx)(`td`,{children:e.id}),(0,l.jsx)(`td`,{title:e.submodule,children:e.submodule}),(0,l.jsx)(`td`,{title:e.description,children:e.description?e.description:(0,l.jsx)(`span`,{className:`bulk-empty-text`,children:`-empty-`})}),(0,l.jsx)(`td`,{children:(0,l.jsx)(`code`,{className:`bulk-code-chip`,children:e.actions})}),(0,l.jsx)(`td`,{title:e.key,children:e.key}),(0,l.jsx)(`td`,{children:n?(0,l.jsx)(s.Tag,{color:`red`,children:`Error`}):(0,l.jsx)(s.Tag,{color:`green`,children:`Valid`})}),(0,l.jsx)(`td`,{children:n?(0,l.jsx)(s.Tooltip,{title:(0,l.jsx)(gP,{errors:t}),placement:`left`,children:(0,l.jsxs)(`button`,{type:`button`,className:`bulk-error-info`,"aria-label":`View ${t.length} error(s) for row ${e.id}`,children:[(0,l.jsx)(c.InfoCircleOutlined,{}),(0,l.jsx)(s.Badge,{count:t.length,size:`small`})]})}):(0,l.jsx)(`span`,{className:`bulk-error-none`,children:`-`})})]},`${e.id}-${e.step_order}`)})})]})}),(0,l.jsxs)(s.Space,{className:`bulk-actions`,children:[(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:i,children:`Reset`}),(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.SaveOutlined,{}),loading:a,disabled:p,onClick:r,children:d.length>0?`Fix ${d.length} error(s) to proceed`:`Save to database`})]})]})}function yP(){let e=(0,d.useNavigate)(),r=(0,o.useMemo)(()=>t.l(),[]),i=(0,o.useRef)(null),a=(0,o.useRef)(null),[u,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(``),[h,g]=(0,o.useState)(`idle`),[_,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(null),[x,S]=(0,o.useState)([]),[C,w]=(0,o.useState)(`all`),[T,E]=(0,o.useState)(null),[D,O]=(0,o.useState)(null),[k,A]=(0,o.useState)(!1),j=u.map(e=>({value:e.modulename,label:e.modulename})),M=hP(x),N=h===`encoding`||h===`validating`,P=!!p&&!N,F=dP[h]??0,I=x.find(e=>e.row_status===`invalid`)?.id,L=(0,o.useCallback)(()=>{m(``),g(`idle`),v(!1),b(null),S([]),w(`all`),E(null),O(null),i.current&&(i.current.value=``)},[]);(0,o.useEffect)(()=>{async function e(){try{let e=await Zb({project:r?.name??``,activeOnly:!0});f(e?.items??[])}catch(e){console.error(e),s.message.error(`Unable to load modules.`)}}e()},[r?.name]);let R=e=>{m(e??``),S([]),O(null),E(null),b(null),A(!1),g(e?`module_set`:`idle`)},z=async e=>{if(!e||!P)return;let t=e.name.split(`.`).pop()?.toLowerCase();if(![`xlsx`,`csv`].includes(t)){g(`module_set`),E({message:`Invalid file type. Please upload an Excel .xlsx or CSV .csv file.`});return}if(e.size>sP){g(`module_set`),E({message:`File must be 10 MB or smaller.`});return}E(null),S([]),O(null),b({name:e.name,size:e.size}),g(`encoding`);try{let n=await pP(e);g(`validating`);let i=await Kb({filename:e.name,project:r?.name??``,module:p,file_base64:n,file_type:t});S(i?.rows??[]),w(`all`),g(`preview`)}catch(e){console.error(e),E(e.payload??{code:`NETWORK_ERROR`,message:e.message||`Could not reach the server.`}),g(`error`)}},B=async()=>{try{let e=await fetch(cP);if(!e.ok)throw Error(`Template file not found (${e.status})`);let t=(await e.text()).trim(),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);let i=new Blob([r],{type:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=lP,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a),s.message.success(`Sample template downloaded.`)}catch(e){console.error(e),s.message.error(`Unable to download sample template.`)}},V=async()=>{g(`inserting`),E(null);try{let t=await qb({project:r?.name??``,module:p,uploaded_by:localStorage.getItem(`user_Email`)??``,rows:mP(x)});O(t),g(`done`),s.message.success(`Bulk upload saved. Redirecting to view test cases...`),window.setTimeout(()=>e(`/viewTestCase`),900)}catch(e){console.error(e),E(e.payload??{code:`NETWORK_ERROR`,message:e.message||`Could not reach the server.`}),g(`preview`)}},H=(0,o.useCallback)(()=>{a.current?.scrollIntoView({behavior:`smooth`,block:`center`})},[]),ee=[`bulk-dropzone`,_?`bulk-dropzone-dragging`:``,y?`bulk-dropzone-has-file`:``,T&&h!==`preview`?`bulk-dropzone-error`:``,p?``:`bulk-dropzone-disabled`].filter(Boolean).join(` `);return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:fP})}),r?.name&&(0,l.jsx)(s.Col,{children:(0,l.jsx)(aP,{strong:!0,children:r.name})})]}),(0,l.jsxs)(`div`,{className:`zt-page zt-page-wide bulk-page`,children:[(0,l.jsxs)(`div`,{className:`bulk-header`,children:[(0,l.jsx)(oP,{level:3,children:`Bulk upload test cases`}),(0,l.jsxs)(s.Space,{direction:`vertical`,size:4,children:[(0,l.jsx)(aP,{type:`secondary`,children:uP}),(0,l.jsx)(aP,{type:`secondary`,children:`Use the sample template for the required columns. Uploaded rows are saved as Active by default.`})]})]}),(0,l.jsx)(`div`,{className:`bulk-stepbar`,children:[`Select`,`Upload`,`Validate`,`Save`].map((e,t)=>(0,l.jsxs)(`span`,{className:t<F?`bulk-step-active`:``,children:[t+1,` `,e]},e))}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:`1. Module selector`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,className:`bulk-module-select`,placeholder:`Choose a module`,options:j,value:p||void 0,onChange:R})}),p&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`2. File upload`,extra:(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.DownloadOutlined,{}),onClick:B,children:`Download Sample Template`}),children:[(0,l.jsx)(s.Alert,{type:`info`,showIcon:!0,message:`First time uploading?`,description:`Download the sample template, keep the column names unchanged, fill your test steps, and upload either .xlsx or .csv.`,className:`bulk-inline-alert`}),(0,l.jsxs)(`button`,{type:`button`,className:ee,disabled:!P,onClick:()=>i.current?.click(),onDragOver:e=>{e.preventDefault(),P&&v(!0)},onDragLeave:()=>v(!1),onDrop:e=>{e.preventDefault(),v(!1),z(e.dataTransfer.files?.[0])},children:[(0,l.jsx)(c.CloudUploadOutlined,{className:`bulk-upload-icon`}),y?(0,l.jsxs)(`span`,{className:`bulk-file-chip`,children:[y.name,` - `,Math.ceil(y.size/1024),` KB`]}):(0,l.jsx)(`span`,{children:`Drag & drop here, or click to browse`})]}),(0,l.jsx)(`input`,{ref:i,hidden:!0,type:`file`,accept:`.xlsx,.csv`,onChange:e=>z(e.target.files?.[0])}),N&&(0,l.jsx)(s.Progress,{percent:h===`encoding`?45:82,showInfo:!1,size:`small`}),T&&h!==`preview`&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:T.message,className:`bulk-inline-alert`})]}),x.length>0&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`3. Validation result`,children:[(0,l.jsx)(_P,{errors:M,expanded:k,onToggle:()=>A(e=>!e),onSummaryClick:H}),T&&h===`preview`&&(0,l.jsx)(s.Alert,{type:`error`,showIcon:!0,message:T.message,className:`bulk-inline-alert`}),(0,l.jsx)(vP,{rows:x,view:C,onViewChange:w,onConfirm:V,onReset:L,saving:h===`inserting`,firstInvalidRowId:I,firstInvalidRowRef:a})]}),D&&h===`done`&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:`4. Upload complete`,children:[(0,l.jsxs)(s.Row,{gutter:[16,16],className:`bulk-metrics`,children:[(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(aP,{children:`Total`}),(0,l.jsx)(`strong`,{children:x.length})]})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(aP,{children:`Inserted`}),(0,l.jsx)(`strong`,{children:D.inserted??0})]})}),(0,l.jsx)(s.Col,{xs:24,md:8,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(aP,{children:`Failed`}),(0,l.jsx)(`strong`,{children:D.failed??0})]})})]}),(0,l.jsx)(s.Alert,{type:`success`,showIcon:!0,icon:(0,l.jsx)(c.CheckCircleOutlined,{}),message:`${D.inserted??0} test cases saved to database - module: ${p}`,className:`bulk-inline-alert`}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:L,children:`Upload another file`})]})]})]})}var bP=[{value:`navigate`,label:`Navigate`},{value:`fill`,label:`Fill`},{value:`click`,label:`Click`},{value:`select`,label:`Select`},{value:`press_key`,label:`Press Key`},{value:`type_and_select`,label:`Type and Select`},{value:`type_and_select_modal`,label:`Type and Select (Modal)`},{value:`upload_file`,label:`Upload File`},{value:`check_checkbox`,label:`Check Checkbox`},{value:`check_filter_checkbox`,label:`Check Filter Checkbox`},{value:`select_page_size`,label:`Select Page Size`},{value:`check_n_checkboxes`,label:`Check N Checkboxes`},{value:`store_text`,label:`Store Text`},{value:`reset_session`,label:`Reset Session`},{value:`switch_to_new_tab`,label:`Switch To New Tab`},{value:`close_tab`,label:`Close Tab`},{value:`assert_visible`,label:`Assert Visible`},{value:`assert_hidden`,label:`Assert Hidden`},{value:`assert_text`,label:`Assert Text`},{value:`assert_url`,label:`Assert URL`},{value:`assert_body_contains`,label:`Assert Body Contains`},{value:`assert_button_disabled`,label:`Assert Button Disabled`},{value:`assert_field_error`,label:`Assert Field Error`},{value:`assert_field_accepted`,label:`Assert Field Accepted`},{value:`assert_children_disabled`,label:`Assert Children Disabled`},{value:`assert_children_visible`,label:`Assert Children Visible`},{value:`assert_element_count`,label:`Assert Element Count`},{value:`assert_toast`,label:`Assert Toast`},{value:`assert_toast_success`,label:`Assert Toast Success`},{value:`assert_toast_error`,label:`Assert Toast Error`},{value:`wait_for_visible`,label:`Wait For Visible`},{value:`wait_for_hidden`,label:`Wait For Hidden`},{value:`wait_for_text`,label:`Wait For Text`}],{Text:xP}=s.Typography,SP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/test-cases`}],CP={tags:`regression`,active:1},wP={module:{dbName:`Modules`,formField:`module`,label:`Module`}};function TP(e=[]){return e.map(e=>({value:e,label:e}))}function EP(e=``){return String(e??``).trim()}function DP(e=``){return EP(e).toLowerCase()}function OP(e=[]){let t=new Map;return e.forEach(e=>{let n=EP(e?.flow),r=n.toLowerCase();n&&!t.has(r)&&t.set(r,n)}),Array.from(t.values()).map(e=>({value:e,label:e}))}function kP(e=[],t,n){let r=EP(t).toLowerCase(),i=EP(n).toLowerCase();return e.reduce((e,t)=>{let n=EP(t?.module).toLowerCase(),a=EP(t?.flow).toLowerCase();if(n!==r||a!==i)return e;let o=Number(t?.step_order)||0;return Math.max(e,o)},0)+1}function AP({icon:e,title:t}){return(0,l.jsxs)(s.Space,{size:10,align:`center`,children:[(0,l.jsx)(`div`,{className:`v1-section-icon-box`,children:e}),(0,l.jsx)(xP,{strong:!0,className:`v1-section-label`,children:t})]})}function jP(){let[e]=s.Form.useForm(),[t]=s.Form.useForm(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)([]),[f,p]=(0,o.useState)([]),[m,h]=(0,o.useState)(!1),[g,_]=(0,o.useState)(!1),[v,y]=(0,o.useState)({open:!1,typeKey:`module`}),[b,x]=(0,o.useState)(!1),[S,C]=(0,o.useState)(!1),[w,T]=(0,o.useState)(!1),E=(0,d.useNavigate)(),D=wP[v.typeKey],O=(0,o.useMemo)(()=>TP(r),[r]),k=s.Form.useWatch(`module`,e),A=s.Form.useWatch(`flow`,e),j=!!EP(k),M=!!EP(A),N=!j,P=!j||!M,F=(e,t=[])=>{e===`module`&&i(t)},I=async()=>{h(!0);try{let e=await Vb(wP.module.dbName);i(e?.items??[])}catch(e){console.error(`Unable to load testing options:`,e),s.message.error(`Unable to load testing options.`)}finally{h(!1)}},L=(0,o.useCallback)(async t=>{let n=EP(t);if(u([]),p([]),e.setFieldsValue({step_order:void 0}),n){_(!0);try{let e=await Gb({limit:1e4,offset:0,module:n}),t=Array.isArray(e?.items)?e.items:[];u(t),p(OP(t))}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{_(!1)}}},[e]),R=(0,o.useCallback)(async(t,n,r)=>{let i=EP(t),a=EP(n);if(!i||!a){e.setFieldsValue({step_order:void 0});return}C(!0);try{e.setFieldsValue({step_order:kP(r,i,a)})}catch(e){console.error(`Unable to load step order:`,e),s.message.error(`Unable to load step order.`)}finally{C(!1)}},[e]);(0,o.useEffect)(()=>{Promise.resolve().then(I)},[]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>L(k))},[L,k]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>R(k,A,a))},[a,R,A,k]);let z=async t=>{let n={module:EP(t.module),flow:EP(t.flow),step_order:Number(t.step_order),description:EP(t.description),keyword:DP(t.keyword),target:EP(t.target),value:EP(t.value),expected:EP(t.expected),tags:t.tags?EP(t.tags):CP.tags,active:Number(t.active)};T(!0);try{await Wb(n),s.message.success(`Test case details saved successfully.`),e.resetFields(),u([]),p([])}catch(e){console.error(`Unable to save test case:`,e),s.message.error(`Unable to save test case.`)}finally{T(!1)}},B=(t,n)=>{e.setFieldsValue({[t]:EP(n)})},V=t=>{e.setFieldsValue({module:EP(t),flow:void 0,step_order:void 0,keyword:void 0,description:void 0,target:void 0,tags:CP.tags,value:void 0,expected:void 0})},H=t=>{e.setFieldsValue({flow:EP(t),step_order:void 0})},ee=e=>{let n=wP[e];y({open:!0,typeKey:e}),t.setFieldsValue({name:``,type:n.label})},U=()=>{y(e=>({...e,open:!1})),t.resetFields()},te=async()=>{try{let n=EP((await t.validateFields()).name),r=await Hb({name:n,type:D.dbName});F(v.typeKey,r?.items??[]),e.setFieldsValue({[D.formField]:n}),s.message.success(`${D.label} added successfully.`),U()}catch(e){if(e?.errorFields)return;console.error(`Unable to save testing option:`,e),s.message.error(`Unable to add ${D.label.toLowerCase()}.`)}finally{x(!1)}};return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:SP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>E(`/zinnext-home`),children:`View Table`})})]}),(0,l.jsx)(`div`,{className:`v1-page`,children:(0,l.jsxs)(`div`,{className:`v1-page-inner`,children:[(0,l.jsx)(`div`,{className:`v1-page-header`,children:(0,l.jsxs)(s.Space,{align:`center`,size:10,children:[(0,l.jsx)(c.ProfileOutlined,{className:`v1-outer-icon`}),(0,l.jsx)(`div`,{children:(0,l.jsx)(xP,{strong:!0,style:{fontSize:16},children:`Add Test Case`})})]})}),(0,l.jsx)(Z,{children:(0,l.jsxs)(s.Form,{form:e,className:`v1-form`,layout:`vertical`,colon:!1,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),initialValues:CP,onFinish:z,autoComplete:`off`,children:[(0,l.jsx)(s.Card,{className:`v1-card`,title:(0,l.jsx)(AP,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`Test Case Details`}),extra:(0,l.jsx)(xP,{type:`secondary`,className:`v1-card-subtitle`,children:`Module, flow, step order and execution data`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,style:{flex:1},children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:m,optionFilterProp:`label`,placeholder:`Select module`,options:O,onChange:V})}),(0,l.jsx)(s.Button,{"aria-label":`Add module`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:30},onClick:()=>ee(`module`)})]})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Flow`,name:`flow`,children:(0,l.jsx)(s.AutoComplete,{maxLength:100,allowClear:!0,disabled:N,options:f,placeholder:g?`Loading flows`:`Enter flow`,onChange:H,filterOption:(e,t)=>t?.value?.toLowerCase().includes(e.toLowerCase())})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,disabled:!0,placeholder:S?`Loading step order`:`Step order`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`keyword`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,disabled:P,optionFilterProp:`label`,placeholder:`Select action`,options:bP,onChange:t=>e.setFieldsValue({keyword:DP(t)})})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3,maxLength:255,disabled:P,placeholder:`Enter description`,showCount:!0,onBlur:e=>B(`description`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`target`,children:(0,l.jsx)(s.Input,{maxLength:255,disabled:P,placeholder:`Enter target`,onBlur:e=>B(`target`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Tags`,name:`tags`,children:(0,l.jsx)(s.Input,{maxLength:200,disabled:P,placeholder:`Enter tags`,prefix:(0,l.jsx)(c.TagsOutlined,{className:`v1-input-icon`}),onBlur:e=>B(`tags`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:P,placeholder:`Enter value`,onBlur:e=>B(`value`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:P,placeholder:`Enter expected result`,onBlur:e=>B(`expected`,e.target.value)})})})]})}),(0,l.jsx)(`div`,{className:`v1-form-actions`,children:(0,l.jsx)(s.Form.Item,{children:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:w,disabled:P,children:`Submit`}),(0,l.jsx)(s.Button,{onClick:()=>{e.resetFields(),u([]),p([])},children:`Reset`})]})})})]})}),(0,l.jsx)(s.Modal,{title:`Add ${D.label}`,open:v.open,confirmLoading:b,okText:`Add`,onCancel:U,onOk:()=>{x(!0),te()},destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:t,layout:`vertical`,colon:!1,className:`v1-form`,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),children:[(0,l.jsx)(s.Form.Item,{label:`Name`,name:`name`,children:(0,l.jsx)(s.Input,{maxLength:100,placeholder:`Enter ${D.label.toLowerCase()} name`,onBlur:e=>{t.setFieldsValue({name:EP(e.target.value)})}})}),(0,l.jsx)(s.Form.Item,{label:`Type`,name:`type`,children:(0,l.jsx)(s.Input,{disabled:!0})})]})})]})})]})}var{Text:MP}=s.Typography,NP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`}];function PP(e=``){return String(e??``).trim()}function FP(e=[],t){return e.map(e=>({value:e.id,label:e[t]}))}var IP=[{label:`Step`,value:`step_order`,width:70},{label:`Action`,value:`actions`,width:140},{label:`Key`,value:`key`,width:160,ellipsis:!0},{label:`Value`,value:`value`,ellipsis:!0},{label:`Description`,value:`description`,ellipsis:!0},{label:`Scenario`,value:`scenario`,width:110,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`green`,children:`Positive`}):(0,l.jsx)(s.Tag,{color:`red`,children:`Negative`})}],LP={key:!1,value:!1,expected:!1};function RP(e,t){return t?e[t]??LP:LP}function zP(e,t){e.setFields(t.map(e=>({name:e,errors:[]})))}function BP(){let[e]=s.Form.useForm(),r=(0,d.useNavigate)(),[i]=(0,d.useSearchParams)(),a=i.get(`edit`),u=!!a,f=(0,o.useMemo)(()=>t.l(),[]),[p,m]=(0,o.useState)([]),[h,g]=(0,o.useState)([]),[_,v]=(0,o.useState)([]),[y,b]=(0,o.useState)(bP),[x,S]=(0,o.useState)({}),[C,w]=(0,o.useState)(!1),[T,E]=(0,o.useState)(!1),[D,O]=(0,o.useState)(!1),[k,A]=(0,o.useState)(!1),[j,M]=(0,o.useState)(!1),N=s.Form.useWatch(`module`,e),P=s.Form.useWatch(`submodule`,e),F=s.Form.useWatch(`actions`,e),I=!!N,L=!!P,R=(0,o.useMemo)(()=>RP(x,F),[x,F]),z=(0,o.useMemo)(()=>FP(p,`modulename`),[p]),B=(0,o.useMemo)(()=>FP(h,`submodulename`),[h]),V=(0,o.useMemo)(()=>p.find(e=>e.id===N)?.modulename??``,[p,N]),H=(0,o.useMemo)(()=>h.find(e=>e.id===P)?.submodulename??``,[P,h]),ee=(0,o.useCallback)(async()=>{try{let e=await Ub();Array.isArray(e?.options)&&e.options.length>0&&b(e.options),e?.rules&&typeof e.rules==`object`&&S(e.rules)}catch(e){console.error(`Unable to load action field rules:`,e),s.message.error(`Unable to load action validation rules.`)}},[]),U=(0,o.useCallback)(async e=>{if(!e){m([]);return}w(!0);try{let t=await Zb({project:e,activeOnly:!0});m(t?.items??[])}catch(e){console.error(`Unable to load modules:`,e),s.message.error(`Unable to load modules.`)}finally{w(!1)}},[]),te=(0,o.useCallback)(async(e,t)=>{if(!e||!t){g([]);return}E(!0);try{let n=await ex({project:e,module:t,activeOnly:!0});g(n?.items??[])}catch(e){console.error(`Unable to load submodules:`,e),s.message.error(`Unable to load submodules.`)}finally{E(!1)}},[]),ne=(0,o.useCallback)(async(t,n,r,i=``)=>{if(!t||!n||!r){v([]),e.setFieldsValue({step_order:void 0});return}O(!0);try{let[a,o]=await Promise.all([rx({product_parent_ID:t,module_parent_ID:n,submodule_parent_ID:r,actions:i,limit:1e3}),ox({product_parent_ID:t,module_parent_ID:n,submodule_parent_ID:r})]);v(a?.items??[]),e.setFieldsValue({step_order:o?.step_order??1})}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{O(!1)}},[e]),re=(0,o.useCallback)(async(e=``)=>{if(!(!f?.id||!N||!P)){O(!0);try{let t=await rx({product_parent_ID:f.id,module_parent_ID:N,submodule_parent_ID:P,actions:e,limit:1e3});v(t?.items??[])}catch(e){console.error(`Unable to load action flows:`,e),s.message.error(`Unable to load action steps.`)}finally{O(!1)}}},[f?.id,N,P]),ie=(0,o.useCallback)(async()=>{if(!(!a||!f?.name)){M(!0);try{let t=await ax(a);await te(f.name,t.module);let n=await rx({product_parent_ID:t.product_parent_ID,module_parent_ID:t.module_parent_ID,submodule_parent_ID:t.submodule_parent_ID,limit:1e3});v(n?.items??[]),e.setFieldsValue({module:t.module_parent_ID,submodule:t.submodule_parent_ID,step_order:t.step_order,actions:t.actions,key:t.key,value:t.value,expected:t.expected,description:t.description,scenario:t.scenario===1,active:Number(t.active)!==0})}catch(e){console.error(`Unable to load test flow:`,e),s.message.error(`Unable to load test flow for edit.`),r(`/viewTestCase`)}finally{M(!1)}}},[a,e,te,r,f?.name]);return(0,o.useEffect)(()=>{if(!f){r(`/select-project`,{replace:!0});return}Promise.resolve().then(async()=>{await ee(),await U(f.name),a&&await ie()})},[f,r,ee,U,a,ie]),f?(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:NP})}),(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(MP,{strong:!0,children:f.name})]})})]}),(0,l.jsx)(`div`,{className:`zt-page`,children:(0,l.jsxs)(s.Form,{form:e,layout:`vertical`,colon:!1,className:`v1-form`,initialValues:{scenario:!0,active:!0},onFinish:async t=>{let n={product_parent_ID:Number(f?.id),module_parent_ID:Number(t.module),submodule_parent_ID:Number(t.submodule),description:PP(t.description),actions:PP(t.actions),key:PP(t.key),value:PP(t.value),expected:PP(t.expected),scenario:+!!t.scenario,active:+!!t.active};A(!0);try{if(u){await sx(a,{...n,step_order:Number(t.step_order)}),s.message.success(`Test case updated successfully.`),r(`/viewTestCase`);return}await ix(n),s.message.success(`Step saved (#${t.step_order}).`),e.setFieldsValue({actions:void 0,key:void 0,value:void 0,expected:void 0,description:void 0}),await ne(n.product_parent_ID,n.module_parent_ID,n.submodule_parent_ID)}catch(e){console.error(`Unable to save test case:`,e),s.message.error(u?`Unable to update test case.`:`Unable to save step.`)}finally{A(!1)}},autoComplete:`off`,disabled:j,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:8,className:`zt-section-title`,children:[(0,l.jsx)(`span`,{className:`zt-step-tag`,children:`1`}),(0,l.jsx)(`span`,{children:`Module & Submodule`})]}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],align:`bottom`,children:[(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,loading:C,placeholder:`Select module`,options:z,onChange:t=>{let n=p.find(e=>e.id===t)?.modulename??``;e.setFieldsValue({module:t,submodule:void 0,step_order:void 0,actions:void 0,key:void 0,value:void 0,expected:void 0}),zP(e,[`actions`,`key`,`value`,`expected`]),g([]),v([]),te(f?.name,n)}})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Submodule`,name:`submodule`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,disabled:!I,loading:T,placeholder:I?`Select submodule`:`Select module first`,options:B,onChange:t=>{e.setFieldsValue({submodule:t,actions:void 0,key:void 0,value:void 0,expected:void 0}),zP(e,[`actions`,`key`,`value`,`expected`]),ne(f?.id,N,t)}})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Scenario`,name:`scenario`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{disabled:!L,checkedChildren:`Positive`,unCheckedChildren:`Negative`})})}),(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Active`,name:`active`,valuePropName:`checked`,children:(0,l.jsx)(s.Switch,{checkedChildren:`Active`,unCheckedChildren:`Inactive`})})})]})}),L&&(0,l.jsxs)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:8,className:`zt-section-title`,children:[(0,l.jsx)(`span`,{className:`zt-step-tag`,children:`2`}),(0,l.jsx)(c.FileTextOutlined,{}),(0,l.jsx)(`span`,{children:`Step Details`})]}),extra:(0,l.jsxs)(MP,{type:`secondary`,children:[V,` / `,H]}),children:[(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:6,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,children:(0,l.jsx)(s.Input,{disabled:!0,placeholder:D?`Loading…`:`Auto`})})}),(0,l.jsx)(s.Col,{xs:24,md:18,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`actions`,rules:[{required:!0,message:`Mandatory Field`}],children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,optionFilterProp:`label`,placeholder:`Select action`,options:y,onChange:t=>{let n=RP(x,t);e.setFieldsValue({actions:t,key:n.key?e.getFieldValue(`key`):void 0,value:n.value?e.getFieldValue(`value`):void 0,expected:n.expected?e.getFieldValue(`expected`):void 0}),zP(e,[`key`,`value`,`expected`]),re(t||``)}})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`key`,rules:[{required:R.key,message:`Key is required for this action`}],children:(0,l.jsx)(s.Input,{maxLength:255,disabled:F&&!R.key,placeholder:F?R.key?`Required — Enter selector / locator`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,rules:[{required:R.value,message:`Value is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:1,autoSize:{minRows:1,maxRows:4},disabled:F&&!R.value,placeholder:F?R.value?`Required — Enter value`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,rules:[{required:R.expected,message:`Expected result is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:2,disabled:F&&!R.expected,placeholder:F?R.expected?`Required — Enter expected result`:`Not needed for this action`:`Select an action first`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:2,maxLength:255,showCount:!0,placeholder:`Enter description`})})})]}),(0,l.jsxs)(s.Space,{className:`zt-actions`,children:[(0,l.jsx)(s.Button,{onClick:()=>{if(u){r(`/viewTestCase`);return}e.resetFields(),g([]),v([]),E(!1),O(!1)},children:`Cancel`}),(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:k||j,children:u?`Update Test Case`:`Save & Continue`})]})]},`${N}-${P}`),L&&(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.TableOutlined,{}),(0,l.jsx)(`span`,{children:`Added Steps`})]}),extra:(0,l.jsx)(s.Tag,{children:F?`${_.length} ${F} step(s)`:`${_.length} step(s)`}),children:(0,l.jsx)($m,{listName:`Added Steps`,loading:D,fields:IP,dataSource:_,current:1,pageSize:Math.max(_.length,1),total:_.length,rowSelection:!1,className:`zt-list-plain zt-list-static`})})]})})]}):null}var{Text:VP}=s.Typography,HP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Manage Modules`,href:`/manageModules`}];function UP(){let e=(0,d.useNavigate)(),r=(0,o.useMemo)(()=>t.l(),[]),[i,a]=(0,o.useState)([]),[u,f]=(0,o.useState)({}),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)(``),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),T=(0,o.useCallback)(async e=>{if(!e){a([]);return}m(!0);try{let[t,n]=await Promise.all([Zb({project:e}),ex({project:e})]);a(t?.items??[]);let r={};(n?.items??[]).forEach(e=>{let t=e.modulename;r[t]=(r[t]??0)+1}),f(r)}catch(e){console.error(e),s.message.error(`Unable to load modules.`)}finally{m(!1)}},[]);(0,o.useEffect)(()=>{if(!r){e(`/select-project`,{replace:!0});return}Promise.resolve().then(()=>T(r.name))},[r,e,T]);let E=async(e,t)=>{try{await $b(e.id,+!!t),a(n=>n.map(n=>n.id===e.id?{...n,active:+!!t}:n)),s.message.success(`Module ${t?`activated`:`deactivated`}.`)}catch(e){console.error(e),s.message.error(`Unable to update module status.`)}},D=async()=>{let e=_.trim();if(!e){s.message.warning(`Enter a module name.`);return}b(!0);try{await Qb({project:r.name,modulename:e}),s.message.success(`Module added.`),g(!1),v(``),S(1),T(r.name)}catch(e){console.error(e),s.message.error(`Unable to add module (maybe it already exists).`)}finally{b(!1)}},O=t=>{e(`/test-cases/zinnext/submodules?module=${encodeURIComponent(t.modulename)}`)};return r?(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:HP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/addTestCase`),children:`Back to Form`})})]}),(0,l.jsxs)(`div`,{className:`zt-page`,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-bar`,children:(0,l.jsxs)(s.Row,{gutter:[16,16],align:`middle`,justify:`space-between`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(`span`,{children:`Project:`}),(0,l.jsx)(VP,{strong:!0,children:r.name})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>g(!0),children:`Add Module`})})]})}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Modules`})]}),children:(0,l.jsx)($m,{listName:`Modules`,loading:p,fields:[{label:`Module`,value:`modulename`},{label:`Submodules`,value:`submoduleCount`,width:140,render:(e,t)=>(0,l.jsxs)(s.Button,{type:`link`,className:`zt-count-link`,onClick:()=>O(t),children:[u[t.modulename]??0,` submodule(s)`]})},{label:`Active`,value:`active`,width:120,render:(e,t)=>(0,l.jsx)(s.Switch,{checked:e===1,checkedChildren:`On`,unCheckedChildren:`Off`,onChange:e=>E(t,e)})}],dataSource:i,current:x,pageSize:C,total:i.length,onPageChange:S,onPageSizeChange:e=>{S(1),w(e)},rowSelection:!1,className:`zt-list-plain`})})]}),(0,l.jsx)(s.Modal,{title:`Add Module`,open:h,confirmLoading:y,okText:`Add`,onOk:D,onCancel:()=>{g(!1),v(``)},destroyOnHidden:!0,children:(0,l.jsxs)(s.Space,{direction:`vertical`,className:`zt-modal-stack`,children:[(0,l.jsxs)(VP,{type:`secondary`,children:[`Project: `,(0,l.jsx)(`b`,{children:r.name})]}),(0,l.jsx)(s.Input,{placeholder:`Enter module name`,maxLength:100,value:_,onChange:e=>v(e.target.value),onPressEnter:D})]})})]}):null}var{Text:WP}=s.Typography,GP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Manage Modules`,href:`/manageModules`},{label:`Manage Submodules`,href:`/test-cases/zinnext/submodules`}];function KP(){let e=(0,d.useNavigate)(),[r]=(0,d.useSearchParams)(),i=(0,o.useMemo)(()=>t.l(),[]),a=r.get(`module`)??``,[u,f]=(0,o.useState)([]),[p,m]=(0,o.useState)(!1),[h,g]=(0,o.useState)(!1),[_,v]=(0,o.useState)(``),[y,b]=(0,o.useState)(!1),[x,S]=(0,o.useState)(1),[C,w]=(0,o.useState)(10),T=(0,o.useCallback)(async(e,t)=>{if(!e||!t){f([]);return}m(!0);try{let n=await ex({project:e,module:t});f(n?.items??[])}catch(e){console.error(e),s.message.error(`Unable to load submodules.`)}finally{m(!1)}},[]);(0,o.useEffect)(()=>{if(!i){e(`/select-project`,{replace:!0});return}if(!a){e(`/manageModules`,{replace:!0});return}Promise.resolve().then(()=>T(i.name,a))},[i,a,e,T]);let E=async(e,t)=>{try{await nx(e.id,+!!t),f(n=>n.map(n=>n.id===e.id?{...n,active:+!!t}:n)),s.message.success(`Submodule ${t?`activated`:`deactivated`}.`)}catch(e){console.error(e),s.message.error(`Unable to update submodule status.`)}},D=async()=>{let e=_.trim();if(!e){s.message.warning(`Enter a submodule name.`);return}b(!0);try{await tx({project:i.name,modulename:a,submodulename:e}),s.message.success(`Submodule added.`),g(!1),v(``),S(1),T(i.name,a)}catch(e){console.error(e),s.message.error(`Unable to add submodule (maybe it already exists).`)}finally{b(!1)}};return!i||!a?null:(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:GP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/manageModules`),children:`Back to Modules`})})]}),(0,l.jsxs)(`div`,{className:`zt-page`,children:[(0,l.jsx)(s.Card,{className:`v1-card zt-bar`,children:(0,l.jsxs)(s.Row,{gutter:[16,16],align:`middle`,justify:`space-between`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsxs)(s.Space,{size:16,wrap:!0,className:`zt-section-title`,children:[(0,l.jsxs)(s.Space,{size:6,children:[(0,l.jsx)(c.ProjectOutlined,{}),(0,l.jsx)(`span`,{children:`Project:`}),(0,l.jsx)(WP,{strong:!0,children:i.name})]}),(0,l.jsxs)(s.Space,{size:6,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Module:`}),(0,l.jsx)(WP,{strong:!0,children:a})]})]})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`primary`,icon:(0,l.jsx)(c.PlusOutlined,{}),onClick:()=>g(!0),children:`Add Submodule`})})]})}),(0,l.jsx)(s.Card,{className:`v1-card zt-fall`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.AppstoreOutlined,{}),(0,l.jsx)(`span`,{children:`Submodules`})]}),children:(0,l.jsx)($m,{listName:`Submodules`,loading:p,fields:[{label:`Submodule`,value:`submodulename`},{label:`Active`,value:`active`,width:120,render:(e,t)=>(0,l.jsx)(s.Switch,{checked:e===1,checkedChildren:`On`,unCheckedChildren:`Off`,onChange:e=>E(t,e)})}],dataSource:u,current:x,pageSize:C,total:u.length,onPageChange:S,onPageSizeChange:e=>{S(1),w(e)},rowSelection:!1,className:`zt-list-plain`})})]}),(0,l.jsx)(s.Modal,{title:`Add Submodule`,open:h,confirmLoading:y,okText:`Add`,onOk:D,onCancel:()=>{g(!1),v(``)},destroyOnHidden:!0,children:(0,l.jsxs)(s.Space,{direction:`vertical`,className:`zt-modal-stack`,children:[(0,l.jsxs)(WP,{type:`secondary`,children:[`Project: `,(0,l.jsx)(`b`,{children:i.name}),` \xA0|\xA0 Module: `,(0,l.jsx)(`b`,{children:a})]}),(0,l.jsx)(s.Input,{placeholder:`Enter submodule name`,maxLength:100,value:_,onChange:e=>v(e.target.value),onPressEnter:D})]})})]})}var{Text:qP}=s.Typography,JP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/addTestCase`},{label:`Table`,href:`/viewTestCase`}];function YP(){let e=(0,d.useNavigate)(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)(0),[f,p]=(0,o.useState)(!1),m=(0,o.useMemo)(()=>t.l(),[]),[h,g]=(0,o.useState)(``),[_,v]=(0,o.useState)(1),[y,b]=(0,o.useState)(20),[x,S]=(0,o.useState)(null),C=(0,o.useCallback)(async(e={})=>{p(!0);try{let t=await rx({product_parent_ID:e.project??m?.id??``,search:e.search??h??``,limit:e.pageSize??y,offset:((e.page??_)-1)*(e.pageSize??y)});i(t?.items??[]),u(t?.total??0)}catch(e){console.error(e),s.message.error(`Unable to load test flows.`)}finally{p(!1)}},[m?.id,h,_,y]),w=e=>{s.Modal.confirm({title:`Delete Test Case`,icon:(0,l.jsx)(c.ExclamationCircleOutlined,{}),content:`Are you sure you want to delete this test case?`,okText:`Delete`,okButtonProps:{danger:!0,loading:x===e.id},cancelText:`Cancel`,async onOk(){S(e.id);try{await cx(e.id),s.message.success(`Test case deleted successfully.`);let t=r.length===1&&_>1?_-1:_;v(t),await C({page:t})}catch(e){throw console.error(`Unable to delete test flow:`,e),s.message.error(`Unable to delete test case.`),e}finally{S(null)}}})};return(0,o.useEffect)(()=>{Promise.resolve().then(()=>{if(!m?.id){e(`/select-project`,{replace:!0});return}C({page:1})})},[]),(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:JP})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>e(`/addTestCase`),children:`Back to Form`})})]}),(0,l.jsx)(`div`,{className:`zt-page zt-page-wide`,children:(0,l.jsxs)(s.Card,{className:`v1-card`,title:(0,l.jsxs)(s.Space,{size:6,className:`zt-section-title`,children:[(0,l.jsx)(c.TableOutlined,{}),(0,l.jsx)(`span`,{children:`Test Flows`})]}),extra:(0,l.jsxs)(qP,{type:`secondary`,children:[a,` row(s)`]}),children:[(0,l.jsxs)(s.Space,{wrap:!0,className:`zt-toolbar`,children:[(0,l.jsx)(s.Input.Search,{allowClear:!0,className:`zt-search-filter`,placeholder:`Search module / key / description`,value:h,onChange:e=>g(e.target.value),onSearch:()=>{v(1),C({page:1})}}),(0,l.jsx)(s.Button,{icon:(0,l.jsx)(c.ReloadOutlined,{}),onClick:()=>C(),children:`Refresh`})]}),(0,l.jsx)($m,{listName:`Test Flows`,loading:f,fields:[{label:`Actions`,value:`rowActions`,width:112,fixed:`left`,sorter:!1,render:(t,n)=>(0,l.jsxs)(s.Space,{size:4,className:`zt-row-actions`,children:[(0,l.jsx)(s.Tooltip,{title:`Edit`,children:(0,l.jsx)(s.Button,{type:`text`,size:`small`,icon:(0,l.jsx)(c.EditOutlined,{}),onClick:()=>e(`/addTestCase?edit=${n.id}`)})}),(0,l.jsx)(s.Tooltip,{title:`Delete`,children:(0,l.jsx)(s.Button,{danger:!0,type:`text`,size:`small`,icon:(0,l.jsx)(c.DeleteOutlined,{}),loading:x===n.id,onClick:()=>w(n)})})]})},{label:`ID`,value:`id`,width:70,fixed:`left`},{label:`Project`,value:`project`,width:130},{label:`Module`,value:`module`,width:130},{label:`Submodule`,value:`submodule`,width:140},{label:`Step`,value:`step_order`,width:70},{label:`Action`,value:`actions`,width:140},{label:`Key`,value:`key`,width:160,ellipsis:!0},{label:`Value`,value:`value`,width:200,ellipsis:!0},{label:`Expected`,value:`expected`,width:180,ellipsis:!0},{label:`Description`,value:`description`,width:180,ellipsis:!0},{label:`Scenario`,value:`scenario`,width:110,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`green`,children:`Positive`}):(0,l.jsx)(s.Tag,{color:`red`,children:`Negative`})},{label:`Active`,value:`active`,width:90,render:e=>e===1?(0,l.jsx)(s.Tag,{color:`blue`,children:`Active`}):(0,l.jsx)(s.Tag,{children:`Inactive`})}],dataSource:r,current:_,pageSize:y,total:a,onPageChange:e=>{v(e),C({page:e})},onPageSizeChange:e=>{v(1),b(e),C({page:1,pageSize:e})},rowSelection:!1,className:`zt-list-plain`})]})})]})}var XP=[{label:`Home`,href:`/`},{label:`Test Cases`,href:`/test-cases`}];function ZP(){return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsx)(n.t,{items:XP}),(0,l.jsx)(Qo,{moduleName:`test-flows`,rowKey:`id`})]})}var{Text:QP}=s.Typography,$P=[{label:`Home`,href:`/`},{label:`LMS Cases`,href:`/lms-cases`}],eF={tags:`regression`,active:1},tF={module:{dbName:`Modules`,formField:`module`,label:`Module`}},nF={key:!1,value:!1,expected:!1};function rF(e,t){return t?e[t]??nF:nF}function iF(e,t){e.setFields(t.map(e=>({name:e,errors:[]})))}function aF(e=[]){return e.map(e=>({value:e,label:e}))}function oF(e=``){return String(e??``).trim()}function sF(e=[]){let t=new Map;return e.forEach(e=>{let n=oF(e?.flow),r=n.toLowerCase();n&&!t.has(r)&&t.set(r,n)}),Array.from(t.values()).map(e=>({value:e,label:e}))}function cF(e=[],t,n){let r=oF(t).toLowerCase(),i=oF(n).toLowerCase();return e.reduce((e,t)=>{let n=oF(t?.module).toLowerCase(),a=oF(t?.flow).toLowerCase();if(n!==r||a!==i)return e;let o=Number(t?.step_order)||0;return Math.max(e,o)},0)+1}function lF({icon:e,title:t}){return(0,l.jsxs)(s.Space,{size:10,align:`center`,children:[(0,l.jsx)(`div`,{className:`v1-section-icon-box`,children:e}),(0,l.jsx)(QP,{strong:!0,className:`v1-section-label`,children:t})]})}function uF(){let[e]=s.Form.useForm(),[t]=s.Form.useForm(),[r,i]=(0,o.useState)([]),[a,u]=(0,o.useState)([]),[f,p]=(0,o.useState)([]),[m,h]=(0,o.useState)(bP),[g,_]=(0,o.useState)({}),[v,y]=(0,o.useState)(!1),[b,x]=(0,o.useState)(!1),[S,C]=(0,o.useState)({open:!1,typeKey:`module`}),[w,T]=(0,o.useState)(!1),[E,D]=(0,o.useState)(!1),[O,k]=(0,o.useState)(!1),A=(0,d.useNavigate)(),j=tF[S.typeKey],M=(0,o.useMemo)(()=>aF(r),[r]),N=s.Form.useWatch(`module`,e),P=s.Form.useWatch(`flow`,e),F=s.Form.useWatch(`keyword`,e),I=!!oF(N),L=!!oF(P),R=!I,z=!I||!L,B=(0,o.useMemo)(()=>rF(g,F),[g,F]),V=(e,t=[])=>{e===`module`&&i(t)},H=async()=>{y(!0);try{let e=await Vb(tF.module.dbName);i(e?.items??[])}catch(e){console.error(`Unable to load testing options:`,e),s.message.error(`Unable to load testing options.`)}finally{y(!1)}},ee=async()=>{try{let e=await Ub();Array.isArray(e?.options)&&e.options.length>0&&h(e.options),e?.rules&&typeof e.rules==`object`&&_(e.rules)}catch(e){console.error(`Unable to load action field rules:`,e),s.message.error(`Unable to load action validation rules.`)}},U=(0,o.useCallback)(async t=>{let n=oF(t);if(u([]),p([]),e.setFieldsValue({step_order:void 0}),n){x(!0);try{let e=await Yb({limit:1e4,offset:0,module:n}),t=Array.isArray(e?.items)?e.items:[];u(t),p(sF(t))}catch(e){console.error(`Unable to load flows:`,e),s.message.error(`Unable to load flows.`)}finally{x(!1)}}},[e]),te=(0,o.useCallback)(async(t,n,r)=>{let i=oF(t),a=oF(n);if(!i||!a){e.setFieldsValue({step_order:void 0});return}D(!0);try{e.setFieldsValue({step_order:cF(r,i,a)})}catch(e){console.error(`Unable to load step order:`,e),s.message.error(`Unable to load step order.`)}finally{D(!1)}},[e]);(0,o.useEffect)(()=>{Promise.resolve().then(async()=>{await Promise.all([H(),ee()])})},[]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>U(N))},[U,N]),(0,o.useEffect)(()=>{Promise.resolve().then(()=>te(N,P,a))},[a,te,P,N]);let ne=async t=>{let n={module:oF(t.module),flow:oF(t.flow),step_order:Number(t.step_order),description:oF(t.description),keyword:oF(t.keyword),target:oF(t.target),value:oF(t.value),expected:oF(t.expected),tags:t.tags?oF(t.tags):eF.tags,active:Number(t.active)};k(!0);try{await Jb(n),s.message.success(`LMS case details saved successfully.`),e.resetFields(),u([]),p([])}catch(e){console.error(`Unable to save LMS case:`,e),s.message.error(`Unable to save LMS case.`)}finally{k(!1)}},re=(t,n)=>{e.setFieldsValue({[t]:oF(n)})},ie=t=>{e.setFieldsValue({module:oF(t),flow:void 0,step_order:void 0,keyword:void 0,description:void 0,target:void 0,tags:eF.tags,value:void 0,expected:void 0}),iF(e,[`keyword`,`target`,`value`,`expected`])},ae=t=>{e.setFieldsValue({flow:oF(t),step_order:void 0,keyword:void 0,target:void 0,value:void 0,expected:void 0}),iF(e,[`keyword`,`target`,`value`,`expected`])},W=t=>{let n=rF(g,t);e.setFieldsValue({keyword:oF(t),target:n.key?e.getFieldValue(`target`):void 0,value:n.value?e.getFieldValue(`value`):void 0,expected:n.expected?e.getFieldValue(`expected`):void 0}),iF(e,[`target`,`value`,`expected`])},oe=e=>{let n=tF[e];C({open:!0,typeKey:e}),t.setFieldsValue({name:``,type:n.label})},se=()=>{C(e=>({...e,open:!1})),t.resetFields()},ce=async()=>{try{let n=oF((await t.validateFields()).name),r=await Hb({name:n,type:j.dbName});V(S.typeKey,r?.items??[]),e.setFieldsValue({[j.formField]:n}),s.message.success(`${j.label} added successfully.`),se()}catch(e){if(e?.errorFields)return;console.error(`Unable to save testing option:`,e),s.message.error(`Unable to add ${j.label.toLowerCase()}.`)}finally{T(!1)}};return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsxs)(s.Row,{align:`middle`,justify:`space-between`,className:`breadcrumb-action-wrapper`,children:[(0,l.jsx)(s.Col,{children:(0,l.jsx)(n.t,{items:$P})}),(0,l.jsx)(s.Col,{children:(0,l.jsx)(s.Button,{type:`link`,onClick:()=>A(`/lms-home`),children:`View Table`})})]}),(0,l.jsx)(`div`,{className:`v1-page`,children:(0,l.jsxs)(`div`,{className:`v1-page-inner`,children:[(0,l.jsx)(`div`,{className:`v1-page-header`,children:(0,l.jsxs)(s.Space,{align:`center`,size:10,children:[(0,l.jsx)(c.ProfileOutlined,{className:`v1-outer-icon`}),(0,l.jsx)(`div`,{children:(0,l.jsx)(QP,{strong:!0,style:{fontSize:16},children:`Add LMS Case`})})]})}),(0,l.jsx)(Z,{children:(0,l.jsxs)(s.Form,{form:e,className:`v1-form`,layout:`vertical`,colon:!1,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),initialValues:eF,onFinish:ne,autoComplete:`off`,children:[(0,l.jsx)(s.Card,{className:`v1-card`,title:(0,l.jsx)(lF,{icon:(0,l.jsx)(c.FileTextOutlined,{}),title:`LMS Case Details`}),extra:(0,l.jsx)(QP,{type:`secondary`,className:`v1-card-subtitle`,children:`Module, flow, step order and execution data`}),children:(0,l.jsxs)(s.Row,{gutter:[24,0],children:[(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsxs)(s.Space.Compact,{style:{width:`100%`},children:[(0,l.jsx)(s.Form.Item,{label:`Module`,name:`module`,style:{flex:1},children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,loading:v,optionFilterProp:`label`,placeholder:`Select module`,options:M,onChange:ie})}),(0,l.jsx)(s.Button,{"aria-label":`Add module`,icon:(0,l.jsx)(c.PlusOutlined,{}),style:{marginTop:30},onClick:()=>oe(`module`)})]})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Flow`,name:`flow`,children:(0,l.jsx)(s.AutoComplete,{maxLength:100,allowClear:!0,disabled:R,options:f,placeholder:b?`Loading flows`:`Enter flow`,onChange:ae,filterOption:(e,t)=>t?.value?.toLowerCase().includes(e.toLowerCase())})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Step Order`,name:`step_order`,validateTrigger:[`onBlur`,`onChange`],children:(0,l.jsx)(s.Input,{maxLength:10,disabled:!0,placeholder:E?`Loading step order`:`Step order`})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Action`,name:`keyword`,children:(0,l.jsx)(s.Select,{allowClear:!0,showSearch:!0,disabled:z,optionFilterProp:`label`,placeholder:`Select action`,options:m,onChange:W})})}),(0,l.jsx)(s.Col,{xs:24,children:(0,l.jsx)(s.Form.Item,{label:`Description`,name:`description`,children:(0,l.jsx)(s.Input.TextArea,{rows:3,maxLength:255,disabled:z,placeholder:`Enter description`,showCount:!0,onBlur:e=>re(`description`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Key`,name:`target`,rules:[{required:B.key,message:`Key is required for this action`}],children:(0,l.jsx)(s.Input,{maxLength:255,disabled:z||!!F&&!B.key,placeholder:z?`Select module and flow first`:F?B.key?`Required — Enter selector / locator`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`target`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Tags`,name:`tags`,children:(0,l.jsx)(s.Input,{maxLength:200,disabled:z,placeholder:`Enter tags`,prefix:(0,l.jsx)(c.TagsOutlined,{className:`v1-input-icon`}),onBlur:e=>re(`tags`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Value`,name:`value`,rules:[{required:B.value,message:`Value is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:z||!!F&&!B.value,placeholder:z?`Select module and flow first`:F?B.value?`Required — Enter value`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`value`,e.target.value)})})}),(0,l.jsx)(s.Col,{xs:24,md:12,children:(0,l.jsx)(s.Form.Item,{label:`Expected`,name:`expected`,rules:[{required:B.expected,message:`Expected result is required for this action`}],children:(0,l.jsx)(s.Input.TextArea,{rows:4,disabled:z||!!F&&!B.expected,placeholder:z?`Select module and flow first`:F?B.expected?`Required — Enter expected result`:`Not needed for this action`:`Select an action first`,onBlur:e=>re(`expected`,e.target.value)})})})]})}),(0,l.jsx)(`div`,{className:`v1-form-actions`,children:(0,l.jsx)(s.Form.Item,{children:(0,l.jsxs)(s.Space,{children:[(0,l.jsx)(s.Button,{type:`primary`,htmlType:`submit`,loading:O,disabled:z,children:`Submit`}),(0,l.jsx)(s.Button,{onClick:()=>{e.resetFields(),u([]),p([])},children:`Reset`})]})})})]})}),(0,l.jsx)(s.Modal,{title:`Add ${j.label}`,open:S.open,confirmLoading:w,okText:`Add`,onCancel:se,onOk:()=>{T(!0),ce()},destroyOnHidden:!0,children:(0,l.jsxs)(s.Form,{form:t,layout:`vertical`,colon:!1,className:`v1-form`,requiredMark:(e,{required:t})=>(0,l.jsxs)(l.Fragment,{children:[e,t&&(0,l.jsx)(`span`,{className:`v1-required-mark`,children:` *`})]}),children:[(0,l.jsx)(s.Form.Item,{label:`Name`,name:`name`,children:(0,l.jsx)(s.Input,{maxLength:100,placeholder:`Enter ${j.label.toLowerCase()} name`,onBlur:e=>{t.setFieldsValue({name:oF(e.target.value)})}})}),(0,l.jsx)(s.Form.Item,{label:`Type`,name:`type`,children:(0,l.jsx)(s.Input,{disabled:!0})})]})})]})})]})}var dF=[{label:`Home`,href:`/`},{label:`LMS Cases`,href:`/lms-cases`}];function fF(){return(0,l.jsxs)(`main`,{className:`jobs-list-page`,children:[(0,l.jsx)(n.t,{items:dF}),(0,l.jsx)(Qo,{moduleName:`lms-flows`,rowKey:`id`})]})}var pF=[`referenceId`,`ReferenceId`,`candidateId`,`CandidateId`,`entityId`,`EntityId`,`id`,`Id`,`_id`];function mF(e=pF){return function(t){if(!t||typeof t!=`object`)return``;for(let n of e){let e=t[n];if(e!=null&&e!==``)return String(e)}return``}}function hF(e,t=pF){if(!e||typeof e!=`object`)return[];let n=[];for(let r of t){let t=e[r];t!=null&&t!==``&&n.push(String(t))}return n}var gF=mF();function _F(e){return typeof e==`function`?e:typeof e==`string`?mF([e]):Array.isArray(e)?mF(e):gF}function vF(e,t,n){return!t||typeof t!=`object`?e:{...t,...e,id:e?.id??t?.id??n}}function yF(e,t,n={}){return{status:`success`,total:t,data:{data:e,...n}}}var bF=[`fields`,`fieldConfig`,`tabs`,`tabField`,`actionRules`,`actions`,`columnActions`];function xF(e){let t=e?.data??e,n={};for(let r of bF){let i=e?.[r]??t?.[r];i==null||Array.isArray(i)&&i.length===0||(n[r]=i)}return n}var SF=e=>String(e??``).replace(/[^a-zA-Z0-9]/g,``).toLowerCase();function CF(e,t,n){let r=(Array.isArray(n)?n:[n]).map(SF).filter(Boolean),i=r.length?e.findIndex(e=>r.includes(SF(e?.value))||r.includes(SF(e?.label))):-1;if(i===-1)return[...e,...t];let a=Number(e[i]?.order),o=Number.isFinite(a)?t.map((e,n)=>e.order==null||e.order===``?{...e,order:a+(n+1)/(t.length+1)}:e):t;return[...e.slice(0,i+1),...o,...e.slice(i+1)]}var wF=(e,t)=>_i(e,t).rows,TF=(e,t)=>{let{rows:n,total:r}=_i(e,t);return{rows:n,total:r}};function EF(e,t){return function(n,r,i,a={}){return e(t??n,r,i,a)}}function DF(e){return!e||typeof e!=`object`||typeof(e.fetchByKeys??e.fetch??e.function)!=`function`?null:{...e,fetchByKeys:typeof e.fetchByKeys==`function`?e.fetchByKeys:null,fetch:typeof e.fetch==`function`?e.fetch:null,function:typeof e.function==`function`?e.function:null,extractRows:typeof e.extractRows==`function`?e.extractRows:wF,mergeRow:typeof e.mergeRow==`function`?e.mergeRow:vF,fetchById:typeof e.fetchById==`function`?e.fetchById:null}}function OF({fetchSecondaryByKeys:e,fetchSecondary:t,extractSecondaryRows:n,fetchSecondaryById:r,secondaryKey:i,mergeRow:a,secondaryFetchLimit:o}){return!e&&!t&&!r?[]:[DF({key:i,fetchByKeys:e?(t,n,r)=>e(t,n,r):null,function:t?({moduleName:e,options:n})=>t(e,o,0,n):null,extractRows:n,fetchById:r,mergeRow:a})].filter(Boolean)}function kF(e){if(typeof e==`function`)return t=>{let n=e(t);return n==null||n===``?[]:[String(n)]};let t=typeof e==`string`?[e]:Array.isArray(e)&&e.length?e:pF;return e=>hF(e,t)}function AF(e,t){let n=new Map;return e.forEach(e=>{for(let r of t(e))n.has(r)||n.set(r,e)}),n}function jF({moduleName:e,limit:t,offset:n,options:r,keys:i,primaryResponse:a,primaryRows:o,pageRows:s,total:c,source:l}){return{moduleName:e,limit:t,offset:n,options:r,keys:i,primaryResponse:a,primaryRows:o,pageRows:s,total:c,source:l}}async function MF(e,t){if(typeof e.args==`function`){let n=e.args(t);return(e.fetch??e.function??e.fetchByKeys)(...Array.isArray(n)?n:[n])}if(Array.isArray(e.args))return(e.fetch??e.function??e.fetchByKeys)(...e.args);if(e.fetchByKeys&&Array.isArray(t.keys))return e.fetchByKeys(t.moduleName,t.keys,t.options,t);let n=e.fetch??e.function;return typeof n==`function`?n(t):null}function NF({fetchPrimaryPage:e,extractPrimaryPage:t=TF,fetchSecondaryByKeys:n,joinSources:r=[],fetchPrimary:i,extractPrimaryRows:a=wF,fetchSecondary:o,extractSecondaryRows:s=wF,fetchSecondaryById:c,primaryKey:l,secondaryKey:u,mergeRow:d=vF,secondaryFetchLimit:f=200,extraFields:p=[],extraFieldsAfter:m}){let h=Array.isArray(r)&&r.length?r.map(DF).filter(Boolean):OF({fetchSecondaryByKeys:n,fetchSecondary:o,extractSecondaryRows:s,fetchSecondaryById:c,secondaryKey:u,mergeRow:d,secondaryFetchLimit:f}),g=0;async function _(e,t,n,r){if(!e.fetchById||!r)return null;try{let i=await e.fetchById(n,r);return i&&t(i).includes(String(r))?i:null}catch(e){return console.error(`[mergedListApi] per-id join lookup failed for "${r}"`,e),null}}async function v(e,t,n,r,i){if(!n)return e;let a=t.extractRows(n,r)??[],o=_F(t.primaryKey??l),s=kF(t.key),c=AF(a,s);return Promise.all(e.map(async e=>{let n=o(e),a=c.get(n)??(i()?null:await _(t,s,r,n));return t.mergeRow(e,a,n)}))}async function y(e,t,n,r){let i=e;for(let e of t)i=await v(i,e.source,e.response,n,r);return i}function b(e,t,n){let r={};for(let e of n){if(!e)continue;let t=xF(e);for(let e of Object.keys(t))r[e]??(r[e]=t[e])}return p.length&&(r.fields=CF(r.fields??[],p,m)),yF(e,t,r)}async function x({moduleName:e,limit:t,offset:n,options:r,primaryResponse:i,primaryRows:a,pageRows:o,total:s}){return Promise.all(h.map(async c=>{try{let u=_F(c.primaryKey??l),d=[...new Set(o.map(u).filter(Boolean))];return c.fetchByKeys&&d.length===0?{source:c,response:null}:{source:c,response:await MF(c,jF({moduleName:e,limit:t,offset:n,options:r,keys:d,primaryResponse:i,primaryRows:a,pageRows:o,total:s,source:c}))}}catch(e){return console.error(`[mergedListApi] join fetch failed — rendering page without that join`,e),{source:c,response:null}}}))}async function S(n,r,i,a,o){let s=await e(n,r,i,a),c=t(s,n)??{},l=Array.isArray(c.rows)?c.rows:[],u=Number.isFinite(Number(c.total))?Number(c.total):l.length,d=await x({moduleName:n,limit:r,offset:i,options:a,primaryResponse:s,primaryRows:l,pageRows:l,total:u});return b(await y(l,d,n,o),u,[s,...d.map(e=>e.response)])}async function C(e,t,n,r,o){let s=await i(e,t,n,r),c=a(s,e)??[],l=c.length,u=c.slice(n,n+t),d=await x({moduleName:e,limit:t,offset:n,options:r,primaryResponse:s,primaryRows:c,pageRows:u,total:l});return b(await y(u,d,e,o),l,[s,...d.map(e=>e.response)])}return async function(t,n=10,r=0,i={}){let a=++g,o=()=>a!==g;return e?S(t,n,r,i,o):C(t,n,r,i,o)}}function PF(e,t,n={}){return NF({fetchPrimary:()=>UA(e,t),extractPrimaryRows:VA,fetchSecondary:Dn,fetchSecondaryById:WA,secondaryFetchLimit:n.moduleFetchLimit??200})}function FF(e){let t=String(e??``).trim().split(/[^a-zA-Z0-9]+/).filter(Boolean);return t.length?`${t.map((e,t)=>t===0?e.toLowerCase():e[0].toUpperCase()+e.slice(1).toLowerCase()).join(``)}Count`:``}function IF(e){let t=Array.isArray(e?.stages)?e.stages:[];if(!t.length)return e;let n={};for(let e of t){let t=FF(e?.stageName);t&&(n[t]=Number(e?.count)||0)}return{...n,...e}}var LF=e=>{let t=Number(e?.targetSubmission??e?.targetSubmissions);return Number.isFinite(t)&&t>0?t:null};function RF({submittedCountField:e=`submittedCount`,progressField:t=`targetSubmissionProgress`}={}){return function(n,r,i){let a=vF(n,r,i),o=LF(a);return o!=null&&(a[t]=`${Number(a?.[e])||0} of ${o}`),a}}function zF(e={}){let t=RF();return NF({primaryKey:`_id`,extraFields:e.extraFields,extraFieldsAfter:e.extraFieldsAfter,fetchPrimaryPage:Dn,joinSources:[{key:`entityId`,fetchByKeys:(e,t,n,r)=>{let i=Math.max(1,Number(r?.limit)||10);return HA(Math.floor((Number(r?.offset)||0)/i)+1,i)},extractRows:e=>(e?.items??[]).map(IF),mergeRow:(e,n,r)=>{let i=t(e,n,r);return n?._id&&(i.workflowId=n._id),i}}]})}async function BF(e,t=10,n=0,r={},i={}){return _i(await zF(i)(e,t,n,r),e)}async function VF(e,t,n,r=10,i=0,a={}){return _i(await PF(e,t)(n,r,i,a),n)}typeof window<`u`&&(window.__CORE_THEME_BUILD__=`2026-10-22T10:03:19.043Z`);var HF=iN,UF=dx(nP),WF=dx(iP),GF=dx(yP),KF=dx(jP),qF=dx(BP),JF=dx(UP),YF=dx(KP),XF=dx(YP),ZF=dx(ZP),QF=dx(uF),$F=dx(fF);exports.ADMIN_API_URL=t.v,exports.ADMIN_APP_ID=t.y,exports.APP_ID=t.b,exports.AUTH_URL=t.x,exports.ActivityNotesCard=qc,exports.ActivityTab=Hc,exports.AddBatchCandidatePopup=NM,exports.AddFormV1=Tc,exports.AdminDashboard=iN,exports.AdminDashboardContent=AD,exports.AdminPage=HF,exports.AppAlert=Ec,exports.AppButton=n.ft,exports.AppShell=Pb,exports.ApprovalActionBar=U_,exports.AssigneeAvatars=Jc,exports.AuthGuard=Db,exports.BILLING_STATUS_FLOW=wf,exports.BOOLEAN_API_KEYS=kg,exports.BOOLEAN_PARSEABLE_API_KEYS=mh,exports.BULK_UPLOAD_DEFAULT_ACCEPT=Yc,exports.BULK_UPLOAD_DEFAULT_MAX_SIZE_MB=Xc,exports.Breadcrumb=n.t,exports.BulkUploadPage=GF,exports.BulkUploadPanel=il,exports.CANDIDATES_URL=t.S,exports.CONTRACT_C2C=pv,exports.CONTRACT_W2=fv,exports.CURRENCY_SYMBOLS=Du,exports.CalendarCard=A,exports.CoreThemeAdminApp=PD,exports.CoreThemeAdminRoutes=ND,exports.CustomPagination=Be,exports.DEFAULT_HOURS_POLICY=d_,exports.DEFAULT_RESULTS_VIEW=Tg,exports.DayLogModal=F_,exports.DescriptionBlock=_l,exports.DetailHeaderCard=Ep,exports.DetailViewPage=Np,exports.DetailViewV1=Sd,exports.DocumentViewer=n.En,exports.DynamicCards=Rt,exports.DynamicPopup=tA,exports.DynamicPopupRoute=RM,exports.DynamicTabs=P,exports.EditFormV1=jm,exports.FIELD_TYPE_REGISTRY=Yh,exports.FINANCE_APPROVAL_CONFIG=iv,exports.FINANCE_TYPE_CFO=Z_,exports.FINANCE_TYPE_ONBOARDING_MANAGER=X_,exports.FINANCE_TYPE_ONBOARDING_MANAGER_REAPPROVE=ev,exports.FINANCE_TYPE_ONLY_FINANCE=Q_,exports.FINANCE_TYPE_SUBMISSION_MANAGER=Y_,exports.FINANCE_TYPE_SUBMISSION_MANAGER_REAPPROVE=$_,exports.FileListCard=vy,exports.FinanceApprovalPanel=Zv,exports.FinanceAvatar=ap,exports.FinanceBadge=lp,exports.FinanceDayCell=G_,exports.FinanceDivider=Zf,exports.FinanceEmployeeCell=op,exports.FinanceEmptyState=Jf,exports.FinanceEquation=Qf,exports.FinanceHistoryTimeline=np,exports.FinanceHoursGrid=qf,exports.FinanceKpiRow=Kf,exports.FinanceLine=Xf,exports.FinanceListToolbar=u_,exports.FinanceMarginBadge=up,exports.FinanceMoneyCell=cp,exports.FinanceRecordsTable=pp,exports.FinanceRowChevron=dp,exports.FinanceSection=Yf,exports.FinanceStatusPill=Gf,exports.FinanceTextCell=sp,exports.FinanceTimesheetAnalysis=q_,exports.FinanceWorkflowSteps=$f,exports.HOURS_MESSAGES=f_,exports.Header=qy,exports.HierarchyUserFilter=Ut,exports.JOBS_URL=t.C,exports.LegacyAdminPage=UF,exports.ListView=Qo,exports.LmsHomePage=$F,exports.LmsTestForm=QF,exports.Login=Fb,exports.MailPopup=dO,exports.ManageModules=JF,exports.ManageSubmodules=YF,exports.ModuleRowActions=Bm,exports.NotesPanel=H_,exports.NotesTab=Kc,exports.OPEN_AS_OPTIONS=gg,exports.PAYROLL_STATUS_FLOW=Tf,exports.POPUP_CONFIGS=wM,exports.ParamCardView=qm,exports.ParamListView=$m,exports.PaymentInvoicePopup=JM,exports.PeriodBadgeTag=w_,exports.PreviewPopup=HO,exports.ProjectSelect=ux,exports.ProofUploadPreview=V_,exports.QuickLogBar=R_,exports.QuickLogSelectionBar=I_,exports.RESULTS_VIEW_OPTIONS=wg,exports.RejectionReasonModal=L_,exports.SUBMISSIONS_URL=t.T,exports.SearchBuilderV1=t_,exports.Sidebar=Cb,exports.StatusBadge=r_,exports.StatusBadgeTag=C_,exports.StickyNotesFullPage=WF,exports.StylishDynamicTabs=a_,exports.TemplateEditor=s_,exports.TestForm=KF,exports.TestingHomePage=ZF,exports.TimelineGroups=Pc,exports.TimesheetDayCell=M_,exports.TipTapEditor=n.On,exports.UserForm=rN,exports.VendorShareDrawer=HM,exports.ViewSummaryWidget=Ui,exports.WizardPopup=JO,exports.ZinnextTableView=XF,exports.ZinnextTestForm=qF,exports.appNow=n.Mn,exports.applyIntegrationStatus=n.Jn,exports.approveSubmission=be,exports.buildAcceptAttr=tl,exports.buildBooleanRequest=Pg,exports.buildCsv=zf,exports.buildDailyRows=Nf,exports.buildDayGradient=A_,exports.buildRateHistoryEntries=Rv,exports.buildWeeklyRollup=If,exports.clearSelectedProject=t.i,exports.colors=n.jn,exports.computeFinance=Av,exports.computeHoursPolicy=v_,exports.computeMarginBand=Lf,exports.conditionMatches=n.i,exports.configureCoreTheme=t.E,exports.configuredFieldLabel=n.a,exports.createAllWorkflowsListFetcher=zF,exports.createMergedListFetcher=NF,exports.createModuleListFetchAdapter=EF,exports.createWorkflowStageListFetcher=PF,exports.currencySymbol=Ou,exports.defaultMergeRow=vF,exports.deleteIntegrationConfig=n.ar,exports.deriveDayStats=Mf,exports.describeCapacity=b_,exports.downloadCsv=Uf,exports.evaluateShowIfWith=n.o,exports.findEmployerRow=wv,exports.flattenGroups=Sv,exports.formatAmount=Pu,exports.formatApp=n.Nn,exports.formatAppDateTime=n.Pn,exports.formatFileSize=el,exports.formatFinanceMoney=zv,exports.formatHours=hf,exports.formatMoney=Fu,exports.formatPercent=_f,exports.formatRate=Iu,exports.getActivity=n.pn,exports.getAllWorkflowsModuleList=BF,exports.getAppTimeZone=n.Fn,exports.getApprovalDate=xf,exports.getBgcIntegrationConfig=n.Cr,exports.getBgcIntegrationSummary=n.wr,exports.getBillingActionStates=Ef,exports.getBooleanEligibleTypes=tg,exports.getCurrentRoleName=t.c,exports.getFieldLabel=Vf,exports.getFieldType=Zh,exports.getFileExtension=$c,exports.getFinanceApprovalConfig=lv,exports.getFormGroupsRaw=sy,exports.getIntegrationConfig=n.jr,exports.getIntegrationConfigs=n.Mr,exports.getIntegrationSummary=n.Nr,exports.getModuleConfig=Le,exports.getModuleDataDetail=n.hn,exports.getPayrollActionStates=Df,exports.getPeriodBadgeConfig=ze,exports.getSearchPopup=pg,exports.getSelectedProject=t.l,exports.getStoredToken=t.u,exports.getStoredUser=t.d,exports.getUserRoles=t.f,exports.getVMSApprove=xe,exports.getValueStyle=Hf,exports.getWorkflowStageModuleList=VF,exports.getWorkflowSteps=Of,exports.humanizeEvent=bf,Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Cs}}),exports.indexFieldConfig=Bf,exports.initialsOf=vf,exports.insertTokenAtCursor=vh,exports.isBooleanEligible=Qh,exports.isBooleanParsable=gh,exports.isTester=t.p,exports.logout=t.h,exports.marginIncludesReferral=dv,exports.matchLocationTax=kv,Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Vp}}),exports.normalizeContract=Ev,Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return al}}),exports.rateUnitLabel=Au,exports.rateUnitShort=Mu,exports.readActionButtons=bg,exports.reconcileHours=y_,exports.registerFieldType=Xh,exports.registerSearchPopup=fg,exports.rejectSubmission=q,exports.resolveActivityMeta=zc,exports.resolveAndCompute=jv,exports.resolveDayKind=g_,exports.resolveFinanceInputs=Ov,exports.resolveMergeKey=gF,exports.resolveMergedListKey=gF,exports.resolveOpenAs=vg,exports.resolveRejectionReason=uv,exports.resolveResultsSearchPlaceholder=Og,exports.resolveResultsView=Dg,exports.resolveSubmissionFinance=cy,exports.saveBgcIntegrationConfig=n.ri,exports.saveIntegrationConfig=n.si,exports.setSelectedProject=t._,exports.showIfConditions=n.c,exports.stageCountKey=FF,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Ib}}),exports.testIntegrationConnection=n.mi,exports.toApp=n.Ln,exports.toNumber=Nu,exports.tzLabel=n.Rn,exports.tzShortLabel=n.zn,exports.unregisterSearchPopup=mg,exports.useDropdownFields=Un,exports.useDropdownValues=Wi,exports.useEditForm=yy,exports.useFieldConfig=Wn,exports.useFilterFields=Gn,exports.useMenuPermission=sr,exports.useModuleActions=Nm,exports.useRecordRefresh=Ap,exports.validateBooleanQuery=_h,exports.validateBulkFile=nl,exports.withAdminAppId=t.D,exports.withAppId=t.O,exports.withAuthGuard=dx;
23
23
  //# sourceMappingURL=index.cjs.map