PageSourceSearch

https://etask.myeoffice.in/assets/ConfigPage-DFY_BxQx.js

js myeoffice.in collected 2026-09-24 14:22:59 UTC 131,817 bytes, 32 lines download raw bytes

1import{j as e}from"./ui-vendor-BuIVDC_j.js";import{r as n,u as Ce,R as re,d as Ns,h as Qs,i as pe}from"./react-vendor-CrJEcqUQ.js";import{a as ws,b as Te,h as Vs,p as ks,t as _s,i as Gs}from"./subTaskCacheStore-41DECh9D.js";import{a as Cs,c as Ss,U as ce,C as Ws,A as Hs,b as Ks}from"./CreatePriorityModal-FYOWVYKV.js";import{T as Ee,f as ls,I as Xs}from"./TableSkeleton-N_O5kw7-.js";import{c as Zs,d as te,z as k,f as oe,u as Be,a as xe,M as be,I as se,B as I,U as ae,Y as Es,i as as,Z as Ne,$ as Oe,a0 as Js,a1 as Ds,N as Ts,r as Ke,t as Ms,C as et,A as st,F as we,X as $e,a2 as tt,a3 as os,S as at,a4 as ze}from"./index-KEVldjck.js";import{T as ue}from"./trash-2-D-Ldy6yi.js";import{P as ve}from"./plus-C-yCEgzc.js";import{u as Ls,b as As,s as _e,e as Fs,l as rt}from"./form-vendor-BzHnMruS.js";import{D as ye}from"./download-B7EN0SQy.js";import"./date-vendor-ghIBFdIZ.js";/**
2 * @license lucide-react v0.309.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ye=Zs("Pen",[["path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z",key:"5qss01"}]]),Rs={getClients:s=>te.get("/clients",{params:s}),getClient:s=>te.get(`/clients/${s}`),createClient:s=>te.post("/clients",s),updateClient:(s,a)=>te.put(`/clients/${s}`,a),deleteClient:s=>te.delete(`/clients/${s}`),getClientTasks:s=>te.get(`/clients/${s}/tasks`),getClientInvoices:s=>te.get(`/clients/${s}/invoices`),importClients:(s,a)=>{const o=new FormData;return o.append("file",s),te.post("/clients/import",o,{onUploadProgress:t=>{if(a){const i=t.total||t.loaded,l=Math.round(t.loaded*100/i);a(Math.min(l,99))}}})},exportClients:(s="csv")=>te.get("/clients/export",{params:{format:s},responseType:"blob"}),bulkDeleteClients:s=>te.post("/clients/bulk-delete",{uuids:s})},is=({search:s,onBulkDeleteUpdate:a})=>{const{clients:o=[],loading:t,pagination:i,fetchClients:l,deleteClient:f}=ws(),[u,j]=n.useState(!1),[T,g]=n.useState(null),[b]=n.useState(""),[p,S]=n.useState([]),[L,y]=n.useState(!1),_=Ce(),M=n.useRef(t),F=typeof i.hasMore=="boolean"?i.hasMore:i.page!==void 0&&i.pages!==void 0?i.page<i.pages:!1,m=[{width:"40px",type:"checkbox",align:"center"},{width:"150px",type:"text"},{width:"200px",type:"text"},{width:"120px",type:"text"},{width:"200px",type:"text"},{width:"120px",type:"text"},{width:"80px",type:"actions",align:"right"}];n.useEffect(()=>{y(!1)},[_.pathname]),n.useEffect(()=>{M.current&&!t&&y(!0),M.current=t},[t]),n.useEffect(()=>{l({page:1,search:b,limit:1e3,isActive:!0,append:!1})},[b,l]);const v=P=>{const{scrollTop:G,scrollHeight:$,clientHeight:E}=P.currentTarget;$-G-E<100&&!t&&F&&l({page:(i.page??1)+1,limit:i.limit,append:!0,search:b,isActive:!0}).catch(Y=>{console.error("Failed to load more clients:",Y)})},h=async(P,G)=>{window.confirm(`Are you sure you want to delete ${G}?`)&&await f(P)},C=n.useCallback(async()=>{var P,G,$;if(p.length<=1){k.error("Please select more than 1 client for bulk delete",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${p.length} clients?`))try{const E=await Rs.bulkDeleteClients(p),U=((P=E.data)==null?void 0:P.data)||E.data;U.error_count===0?(k.success(`Successfully deleted ${U.success_count} client${U.success_count>1?"s":""}`,{duration:2e3}),S([]),await l({page:1,limit:1e3,isActive:!0,append:!1})):U.success_count>0?(k.error(`Deleted ${U.success_count} client${U.success_count>1?"s":""}, but ${U.error_count} failed`,{duration:3e3}),U.errors&&U.errors.length>0&&console.error("Delete errors:",U.errors),await l({page:1,limit:1e3,isActive:!0,append:!1})):(k.error(U.message||"Failed to delete clients",{duration:3e3}),U.errors&&U.errors.length>0&&console.error("Delete errors:",U.errors))}catch(E){console.error("Bulk delete error:",E),k.error((($=(G=E.response)==null?void 0:G.data)==null?void 0:$.message)||"Failed to delete clients",{duration:3e3})}},[p,l]),R=P=>{const G=W.filter($=>{if(!s||s.trim()==="")return!0;const E=s.toLowerCase();return Object.values($).some(U=>U!=null&&String(U).toLowerCase().includes(E))});P.target.checked?S(G.map($=>$.uuid||$.id||"")):S([])},J=P=>{S(G=>G.includes(P)?G.filter($=>$!==P):[...G,P])},H=P=>{g(P),j(!0)},B=()=>{j(!1),g(null)},W=n.useMemo(()=>
6{if(!Array.isArray(o))return[];const P=new Set;return o.filter(G=>{const $=G.uuid||G.id||"";return!$||P.has($)?!1:(P.add($),!0)})},[o]),X=n.useMemo(()=>W.filter(P=>{if(!s||s.trim()==="")return!0;const G=s.toLowerCase();return Object.values(P).some($=>$!=null&&String($).toLowerCase().includes(G))}),[W,s]);return n.useEffect(()=>{a&&a(p.length,C)},[p.length,C]),L?e.jsxs("div",{className:"h-full bg-white mx-0 my-0",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"overflow-auto flex-1 relative",onScroll:v,children:[e.jsx("table",{className:"w-full border border-gray-200 border-collapse",children:t?e.jsx(Ee,{columns:m,rows:8}):e.jsxs(e.Fragment,{children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",onChange:R,checked:p.length===X.length&&X.length>0})}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"CLIENT"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"EMAIL ADDRESS"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"PHONE NUMBER"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ADDRESS"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"GST NUMBER"}),e.jsx("th",{className:"w-20 bg-gray-100"})]})}),e.jsx("tbody",{children:L&&X.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"text-center py-8 text-gray-500",children:"No clients found"})}):X.map(P=>e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"px-4 border py-1",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:p.includes(P.uuid||P.id||""),onChange:()=>J(P.uuid||P.id||"")})}),e.jsx("td",{className:"px-4 border py-1 text-sm font-medium text-gray-900",children:P.name}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:P.email||"-"}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:P.phone_number||"-"}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:P.address||"-"}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:P.gst_number||"-"}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx("button",{className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",onClick:()=>H(P),children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M7.6439 2.3999H4.7999C3.4743 2.3999 2.3999 3.4743 2.3999 4.7999V11.1999C2.3999 12.5255 3.4743 13.5999 4.7999 13.5999H11.1999C12.5255 13.5999 13.5999 12.5255 13.5999 11.1999V8.3639",stroke:"#737373",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M6.3999 9.60005L6.7999 7.20005L11.3655 2.64085C11.6783 2.32805 12.1847 2.32805 12.4967 2.64085L13.3655 3.50965C13.6783 3.82245 13.6783 4.32885 13.3655 4.64085L8.7999 9.20005L6.3999 9.60005Z",stroke:"#737373",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),e.jsx("button",{className:"p-1.5 text-red-400 hover:text-red-600 hover:bg-red-50 rounded",onClick:()=>h(P.uuid||P.id||"",P.name),children:e.jsx(ue,{size:16})})]})})]},P.uuid||P.id))})]})}),t&&(i.page??1)>1&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"})}),e.jsx("div",{className:"sticky bottom-0 z-10 px-4 border py-3 border-t border-gray-200 bg-gray-50 flex items-center",children:e.jsxs("div",{className:"text-sm text-gray-600 uppercase",children:["COUNT"," ",e.jsx("span",{className:"ml-4 font-medium",children:(i==null?void 0:i.total)||W.length})]})})]})}),e.jsx(Cs,{isOpen:u,onClose:B,editingClient:T,onClientCreated:()=>l({page:1,search:b,limit:1e3,isActive:!0,append:!1})})]}):e.jsx("div",{className:"h-full bg-white mx-0 my-0",children:e.jsx("div",{className:"h-full flex flex-col",children:e.jsx("div",{className:"overflow-auto flex-1 relative",children:e.jsx("table",{className:"w-full border border-gray-200 border-collapse",children:e.jsx(Ee,{c
6olumns:m,rows:8})})})})})},nt=600,lt=400,Le=({hasMore:s,isLoading:a,onLoadMore:o,rootMargin:t="100px"})=>{const i=n.useRef(null),l=n.useRef(null),f=n.useRef(!1),u=n.useRef(0),j=n.useRef(!1),T=n.useRef(!1);return n.useEffect(()=>{f.current=a,a||(u.current=Date.now())},[a]),n.useEffect(()=>{const g=setTimeout(()=>{T.current=!0},lt);return()=>clearTimeout(g)},[]),n.useEffect(()=>{const g=i.current;if(!g)return;let b=null,p=g.parentElement;for(;p&&p!==document.body;){const y=window.getComputedStyle(p),_=y.overflowY||y.overflow;if(_==="auto"||_==="scroll"){b=p;break}p=p.parentElement}const S=b||window,L=()=>{j.current=!0};return S.addEventListener("scroll",L,{passive:!0}),()=>S.removeEventListener("scroll",L)},[]),n.useEffect(()=>()=>{l.current&&l.current.disconnect()},[]),n.useEffect(()=>{const g=i.current;if(!g||(l.current&&(l.current.disconnect(),l.current=null),!s||a||!T.current))return;let b=null,p=g.parentElement;for(;p&&p!==document.body;){const L=window.getComputedStyle(p),y=L.overflowY||L.overflow;if(y==="auto"||y==="scroll"){b=p;break}p=p.parentElement}const S=b||null;return l.current=new IntersectionObserver(L=>{const[y]=L;if(!y.isIntersecting||!s||f.current)return;const _=Date.now();_-u.current<nt||j.current&&(f.current=!0,u.current=_,o())},{root:S,rootMargin:t||"100px",threshold:.1}),l.current.observe(g),()=>{l.current&&(l.current.disconnect(),l.current=null)}},[s,a,o,t]),i},ot=()=>e.jsx("div",{className:"w-full animate-pulse",children:Array.from({length:10}).map((s,a)=>e.jsxs("div",{className:"flex border-b border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("div",{className:"py-2 px-2",style:{width:"40px"},children:e.jsx("div",{className:"h-4 w-4 bg-gray-200 rounded"})}),e.jsx("div",{className:"py-2 px-2 flex-1",children:e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/2"})}),e.jsx("div",{className:"py-2 px-2",style:{width:"120px"},children:e.jsx("div",{className:"h-4 bg-gray-200 rounded ml-auto w-8"})}),e.jsx("div",{className:"py-2 px-2",style:{width:"80px"},children:e.jsxs("div",{className:"flex justify-center space-x-2",children:[e.jsx("div",{className:"w-6 h-6 bg-gray-200 rounded"}),e.jsx("div",{className:"w-6 h-6 bg-gray-200 rounded"})]})})]},a))}),it=({search:s,onBulkDeleteUpdate:a})=>{const{taskTemplates:o,tasksLoading:t,tasksPagination:i,fetchTaskTemplates:l,createTaskTemplate:f,updateTaskTemplate:u,deleteTaskTemplate:j}=oe(),{canDelete:T}=Be(),[g,b]=n.useState(!1),[p,S]=n.useState(null),[L,y]=n.useState([]),[_,M]=n.useState({name:"",sub_tasks:[{name:"",task_uuid:""}]}),[F,m]=n.useState(!1),v=Ce(),h=n.useRef(t),R=(Array.isArray(o)?o:[]).filter(c=>{if(!s||s.trim()==="")return!0;const D=s.toLowerCase();return Object.values(c).some(q=>q!=null&&String(q).toLowerCase().includes(D))});n.useEffect(()=>{m(!1)},[v.pathname]),n.useEffect(()=>{h.current&&!t&&m(!0),h.current=t},[t]),n.useEffect(()=>{l({page:1,limit:50,append:!1})},[l,v.pathname]);const J=n.useCallback(async()=>{if(t||!(i!=null&&i.hasMore))return;const c=((i==null?void 0:i.page)||1)+1;try{await l({page:c,limit:50,append:!0})}catch(D){console.error("Failed to load more tasks:",D)}},[l,t,i]),H=Le({hasMore:(i==null?void 0:i.hasMore)??!1,isLoading:t,onLoadMore:J}),B=c=>{c.target.checked?y(R.map(D=>D.uuid)):y([])},W=c=>{y(D=>D.includes(c)?D.filter(q=>q!==c):[...D,c])},X=c=>{S(c),M({name:c.name,sub_tasks:c.sub_tasks&&c.sub_tasks.length>0?c.sub_tasks.map(D=>({name:D.name??"",task_uuid:c.uuid,uuid:D.uuid})):[{name:"",task_uuid:c.uuid}]}),b(!0)},P=async(c,D)=>{if(!T()){k.error("You do not have permission to delete tasks",{duration:3e3});return}window.confirm(`Delete task "${D}"?`)&&(await j(c),await l({page:1,limit:50,append:!1}))},G=n.useCallback(async()=>{var c,D,q;if(L.length<=1){k.error("Please select more than 1 task for bulk delete",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${L.length} tasks?`))try{const r=await xe.bulkDeleteTasks(L),x=((c=r.data)==null?void 0:c.data)||r.data;x.error_count===0?(k.success(`Successfully deleted ${x.success_count} task${x.success_count>1?"s":""}`,{duration:2e3}),y([]),await l({page:1,limit:50,append:!1})):x.success_count>0?(k.error(`Deleted ${x.success_count} task${x.success_count>1?"s":""}, but ${x.error_count} failed`,{duration:3e3}),x.errors&&x.errors.length>0&&console.error("Delete errors:",x.errors),await l({page:1,limit:50,append:!1})):(k.error(x.message||"Failed to delete tasks",{duration:3e3}),x.errors&&x.errors.length>0&&console.error("Delete errors:",x.errors))}catch(r){console.error("Bulk delete error:",r),k.error(((q=(D=r.response)==null?void 0:D.data)==null?void 0:q.message)||"Failed to delete tasks",{duration:3e3})}},[L,l]),$=()=>{M(c=>({...c,sub_tasks:[...c.sub_tasks,{name:"",task_uuid:(p==null?void 0:p.uuid)||""}]}))},E=(c,D)=>{const q=[..._.sub_tasks];q[c]={...q[c],name:D},M({..._,sub_tasks:q})},U=c=>{const D=_.sub_tasks.filter((q,r)=>r!==c);M({..._,sub_tasks:D.length>0?D:[{name:"",task_uuid:(p==null?void 0:p.uuid)||""}]})},Y=async()=>{try{const c=_.sub_tasks.filter(D=>D.name.trim()!=="");if(p){const D=c.filter(x=>!x.uuid).map(x=>({name:x.name.trim()})),q=c.filter(x=>!!x.uuid).map(x=>({uuid:x.uuid,name:x.name.trim()}
6)),r={name:_.name};D.length&&(r.sub_tasks_to_create=D),q.length&&(r.sub_tasks_to_update=q),await u(p.uuid,r),await l({page:1,limit:50,append:!1})}else await f({name:_.name,sub_tasks:c.map(D=>({name:D.name.trim()}))});Z()}catch(c){console.error("Error submitting task form:",c)}},Z=()=>{b(!1),S(null),M({name:"",sub_tasks:[{name:"",task_uuid:""}]})},V=R.reduce((c,D)=>c+(D.total_sub_tasks||0),0);return n.useEffect(()=>{a&&a(L.length,G)},[L.length,G,a]),e.jsxs("div",{className:"h-full bg-white",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"flex-1 overflow-auto relative",children:[e.jsxs("table",{className:"w-full border border-gray-200 border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"bg-gray-100 border px-4 py-2 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded",onChange:B,checked:L.length===R.length&&R.length>0})}),e.jsx("th",{className:"bg-gray-100 border px-4 py-2 text-left text-xs font-medium tracking-wide",children:"TASK"}),e.jsx("th",{className:"bg-gray-100 border px-4 py-2 text-right text-xs font-medium tracking-wide w-32",children:"TOTAL SUBTASKS"}),e.jsx("th",{className:"bg-gray-100 border w-20"})]})}),e.jsx("tbody",{children:F?F&&R.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"text-center py-8 text-gray-500 border",children:"No tasks found"})}):R.map(c=>e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"border px-4 py-2 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded",checked:L.includes(c.uuid),onChange:()=>W(c.uuid)})}),e.jsx("td",{className:"border px-4 py-2 text-sm font-medium text-gray-900",children:c.name}),e.jsx("td",{className:"border px-4 py-2 text-sm text-right text-gray-600",children:c.total_sub_tasks||0}),e.jsx("td",{className:"border px-4 py-2 w-20",children:e.jsxs("div",{className:"flex justify-center space-x-2",children:[e.jsx("button",{className:"p-1.5 text-gray-500 hover:text-gray-700",onClick:()=>X(c),children:e.jsx(Ye,{size:16})}),T()&&e.jsx("button",{className:"p-1.5 text-red-500 hover:text-red-700",onClick:()=>P(c.uuid,c.name),children:e.jsx(ue,{size:16})})]})})]},c.uuid)):e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"p-0",children:e.jsx(ot,{})})})})]}),e.jsx("div",{ref:H,className:`h-10 flex items-center justify-center ${i!=null&&i.hasMore?"":"hidden"}`,children:t&&(i==null?void 0:i.hasMore)&&e.jsx("div",{className:"text-sm text-gray-500",children:"Loading more..."})}),e.jsxs("div",{className:"sticky bottom-0 z-10 px-4 py-3 flex justify-between border-t bg-gray-50",children:[e.jsxs("div",{className:"text-sm text-gray-600",children:["COUNT: ",e.jsx("span",{className:"font-medium",children:R.length})]}),e.jsxs("div",{className:"text-sm text-gray-600",children:["SUBTASKS: ",e.jsx("span",{className:"font-medium",children:V})]})]})]})}),e.jsx(be,{isOpen:g,onClose:Z,title:p?"Edit Task":"Add Task",size:"sm",children:e.jsxs("div",{className:"px-4 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm font-medium text-gray-700 mb-1 block",children:["Task ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(se,{value:_.name,onChange:c=>M({..._,name:c.target.value}),placeholder:"Enter task name"})]}),e.jsx("hr",{}),_.sub_tasks.map((c,D)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-gray-700",children:["Sub-task #",D+1]}),D>0&&e.jsx("button",{type:"button",onClick:()=>U(D),className:"text-red-600 hover:bg-red-50 p-1 rounded",children:e.jsx(ue,{size:16})})]}),e.jsx(se,{value:c.name,onChange:q=>E(D,q.target.value),placeholder:"Enter sub-task name"})]},D)),e.jsx("div",{children:e.jsxs(I,{variant:"secondary",size:"sm",onClick:$,children:[e.jsx(ve,{size:14})," Add Sub-task"]})}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4 border-t",children:[e.jsx(I,{variant:"secondary",onClick:Z,children:"Cancel"}),e.jsx(I,{variant:"primary",onClick:Y,disabled:!_.name.trim(),children:p?"Update":"Save"})]})]})})]})},ct=As({name:_e().min(1,"User name is required"),email:_e().email("Invalid email address"),companyUuid:_e().min(1,"Company UUID is required"),role:Fs([ae.ADMIN,ae.TEAM_MEMBER]),password:_e().min(1,"Password is required").optional().or(rt("")),avatar:_e().optional()}),cs=(s,a,o)=>{const t=s.role===ae.ADMIN?"Company Admin":"Employee",i=s.role===ae.ADMIN,l=(o==null?void 0:o.permissions)||{},f=l.is_configuration??l.isConfiguration??!1,u=i?{is_manage_employee:!0,is_manage_company:!0,is_manage_chat:!0,is_manage_assignments:!0,is_manage_reports:!0,is_manage_invoices:!0,is_configuration:a?!!f:!1,is_all_tasks:!1,is_quotation_and_invoice:!1}:{is_manage_employee:!1,is_manage_company:!1,is_manage_chat:!0,is_manage_assignments:!1,is_manage_reports:!1,is_manage_invoices:!1,is_configuration:!1,is_all_tasks:!1,is_quotation_and_invoice:!1},j={name:s.name,email:s.email,role:t,company_uuid:s.companyUuid,avatar:s.avatar||"",permissions:u};return(!a||s.password&&s.password.trim()!=="")&&(j.password=s.password),a&&(j.is_active=(o==null?void 0:o.is_active)??!0),j},Us=({isOpen:s,onClose:a,onUserCreated:o,editingUser:t})=>{var y,_,M;const{createUser:i,updateUser:l}=Te(),{user:f}=Be(),u=!!t,{register:j,handleSubmit:T,formState:{errors:g,isSubmitting:b},reset:p}=Ls({resolver:Es(ct),defaultValues:{name:(t==null?void 0:t.name)||"",email:(t==null?void 0:t.email)||"",companyUuid:(f==null?void 0:f.company_uuid)||(f==null?void 0:f.companyUuid)||"",role:(t==null?void 0:t.role)==="Company Admin"?ae.ADMIN:ae.TEAM_MEMBER,password:"",avatar:(t==null?void 0:t.avatar)||""}}),S=async F=>{try{if(u){const m=cs(F,!0,t);await l(t.uuid||t.id,m)}else{const m=cs(F,!1);await i(m)}p(),a(),o==null||o()}catch(m){console.error(`❌ Error ${u?"updating":"creating"} user:`,m)}},L=()=>{p(),a()};return e.jsxs(be,{isOpen:s,onClose:L,title:u?"Edit User":"Add New User",children:[e.jsx("div",{className:"mb-4 p-3 rounded-lg px-2",children:e.jsx("p",{className:"text-xs text-gray-400",children:u?"Update user details below.":"Add a new user by entering their details below. They will be added to your company."})}),e.jsxs("form",{onSubmit:T(S),className:"space-y-4 px-3",children:[e.jsx(se,{label:"User Name",placeholder:"John Doe",...j("name"),error:(y=g.name)==null?void 0:y.message,required:!0}),e.jsx(se,{label:"Email Address",type:"email",placeholder:"[email protected]",...j("email"),error:(_=g.email)==null?void 0:_.message,required:!0}),e.jsx(se,{label:"Password",type:"password",placeholder:u?"Leave blank to keep current password":"Enter password",...j("password"),error:(M=g.password)==null?void 0:M.message,required:!u}),u&&e.jsx("p",{className:"text-xs text-gray-500 -mt-2",children:"Leave password blank to keep the current password"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Role"}),e.jsxs("div",{className:"flex space-x-4",children:[e.jsxs("label",{className:"inline-flex items-center space-x-2 cursor-pointer",children:[e.jsx("input",{type:"radio",value:ae.TEAM_MEMBER,...j("role"),className:"h-4 w-4 text-blue-600 border-gray-300 focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-900",children:"Employee"})]}),e.jsxs("label",{className:"inline-flex items-center space-x-2 cursor-pointer",children:[e.jsx("input",{type:"radio",value:ae.ADMIN,...j("role"),className:"h-4 w-4 text-blue-600 border-gray-300 focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-900",children:"Company Admin"})]})]}),g.role&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:g.role.message})]}),e.jsx("input",{type:"hidden",...j("companyUuid")}),e.jsx("input",{type:"hidden",...j("avatar")}),e.jsx("p",{className:"text-xs text-gray-500",children:u?"This user will be updated in your company.":"This user will be added to your current company."}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:L,disabled:b,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"submit",disabled:b,loading:b,children:u?"Update User":"Add User"})]})]})]})},dt=As({name:_e().min(1,"User name is required"),email:_e().email("Invalid email address"),role:Fs([ae.ADMIN,ae.TEAM_MEMBER])}),ut=(s,a)=>{const o=s.role===ae.ADMIN?"Company Admin":"Employee",t=s.role===ae.ADMIN,i=(a==null?void 0:a.permissions)||{},l=i.is_configuration??i.isConfiguration??!1,f=t?{is_manage_employee:!0,is_manage_company:!0,is_manage_chat:!0,is_manage_assignments:!0,is_manage_reports:!0,is_manage_invoices:!0,is_configuration:!!l,is_all_tasks:!1,is_quotation_and_invoice:!1}:{is_manage_employee:!1,is_manage_company:!1,is_manage_chat:!0,is_manage_assignments:!1,is_manage_reports:!1,is_manage_invoices:!1,is_configuration:!1,is_all_tasks:!1,is_quotation_and_invoice:!1};return{name:s.name,email:s.email,role:o,is_active:(a==null?void 0:a.is_active)??!0,permissions:f}},ds=s=>({name:(s==null?void 0:s.name)||"",email:(s==null?void 0:s.email)||"",role:(s==null?void 0:s.role)==="Company Admin"?ae.ADMIN:ae.TEAM_MEMBER}),mt=({isOpen:s,onClose:a,user:o,onUserUpdated:t})=>{var p,S;const{updateUser:i}=Te(),{register:l,handleSubmit:f,formState:{errors:u,isSubmitting:j},reset:T}=Ls({resolver:Es(dt),defaultValues:ds(o)});n.useEffect(()=>{s&&o&&T(ds(o))},[o,s,T]);const g=async L=>{try{const y=(o==null?void 0:o.uuid)||(o==null?void 0:o.id);if(y){const _=ut(L,o);await i(y,_),T(),a(),t==null||t()}}catch(y){console.error("Error updating user:",y)}},b=()=>{T(),a()};return e.jsxs(be,{isOpen:s,onClose:b,title:"Edit User",children:[e.jsx("div",{className:"mb-4 p-3 rounded-lg px-2",children:e.jsx("p",{className:"text-xs text-gray-400",children:"Update user details below."})}),e.jsxs("form",{onSubmit:f(g),className:"space-y-4 px-3",children:[e.jsx(se,{label:"User Name",placeholder:"John Doe",...l("name"),error:(p=u.name)==null?void 0:p.message,required:!0}),e.jsx(se,{label:"Email Address",type:"email",placeholder:"[email protected]",...l("email"),error:(S=u.email)==null?void 0:S.message,required:!0}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Role"}),e.jsxs("div",{className:"flex space-x-4",children:[e.jsxs("label",{className:"inline-flex items-center space-x-2 cursor-pointer",children:[e.jsx("input",{type:"radio",value:ae.TEAM_MEMBER,...l("role"),className:"h-4 w-4 text-blue-600 border-gray-300 focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-900",children:"Employee"})]}),e.jsxs("label",{className:"inline-flex items-center space-x-2 cursor-pointer",children:[e.jsx("input",{type:"radio",value:ae.ADMIN,...l("role"),className:"h-4 w-4 text-blue-600 border-gray-300 focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-900",children:"Company Admin"})]})]}),u.role&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:u.role.message})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:b,disabled:j,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"submit",disabled:j,loading:j,children:"Update User"})]})]})]})},xt=({checked:s,onChange:a,disabled:o=!1})=>e.jsx("button",{type:"button",role:"switch","aria-checked":s,disabled:o,onClick:()=>!o&&a(!s),className:`
7        relative inline-flex h-6 w-11 items-center rounded-full transition-colors
8        focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2
9        ${s?"bg-green-500":"bg-gray-300"}
10        ${o?"opacity-50 cursor-not-allowed":"cursor-pointer"}
11      `,children:e.jsx("span",{className:`
12          inline-block h-4 w-4 transform rounded-full bg-white transition-transform
13          ${s?"translate-x-6":"translate-x-1"}
14        `})}),ht=({search:s,onSetActionCallback:a})=>{const{users:o,loading:t,pagination:i,fetchUsers:l,deleteUser:f,updateUser:u}=Te(),{canDelete:j}=Be(),[T,g]=n.useState(!0),[b,p]=n.useState(!1),[S,L]=n.useState(!1),[y,_]=n.useState([]),[M,F]=n.useState(null),m=Ce(),v=n.useRef(t||T),h=[{width:"40px",type:"checkbox",align:"center"},{width:"250px",type:"avatar"},{width:"200px",type:"text"},{width:"120px",type:"badge"},{width:"100px",type:"badge"},{width:"120px",type:"date"},{width:"80px",type:"actions",align:"right"}],C=Array.isArray(o)?o:[],R=C.filter(c=>{if(!s||s.trim()==="")return!0;const D=s.toLowerCase();return[c==null?void 0:c.name,c==null?void 0:c.email,c==null?void 0:c.role,c==null?void 0:c.uuid,c==null?void 0:c.id].filter(r=>r!=null).join(" ").toLowerCase().includes(D)});n.useEffect(()=>{p(!1)},[m.pathname]),n.useEffect(()=>{const c=t||T;v.current&&!c&&p(!0),v.current=c},[t,T]),n.useEffect(()=>{let c=!0;return(async()=>{try{g(!0),await l({page:1,limit:50,append:!1})}catch(D){console.error("Failed to fetch users:",D),k.error("Failed to load users",{duration:3e3})}finally{c&&g(!1)}})(),()=>{c=!1}},[l]);const J=n.useCallback(async()=>
14{if(t||!i.hasMore)return;const c=i.page+1;try{await l({page:c,limit:50,append:!0})}catch(D){console.error("Failed to load more users:",D)}},[l,t,i]),H=Le({hasMore:i.hasMore,isLoading:t,onLoadMore:J});n.useEffect(()=>{a==null||a({add:()=>L(!0)})},[a]);const B=c=>{c.target.checked?_(R.map(D=>D.uuid||D.id||V(D))):_([])},W=c=>{_(D=>D.includes(c)?D.filter(q=>q!==c):[...D,c])},X=c=>{F(c)},P=async(c,D)=>{var q,r;if(!j()){k.error("You do not have permission to delete users",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${D}?`))try{await f(c),await l({page:1,limit:50,append:!1}),k.success("User deleted",{duration:2e3}),_(x=>x.filter(d=>d!==c))}catch(x){console.error("Error deleting user:",x),k.error(((r=(q=x==null?void 0:x.response)==null?void 0:q.data)==null?void 0:r.message)||"Failed to delete user",{duration:3e3})}},G=async(c,D)=>{var q,r;try{const x=!D,d=C.map(w=>V(w)===c?{...w,is_active:x}:w);Te.setState({users:d}),await u(c,{is_active:x}),k.success(`User ${x?"activated":"deactivated"} successfully`,{duration:2e3})}catch(x){console.error("Error toggling user status:",x),k.error(((r=(q=x==null?void 0:x.response)==null?void 0:q.data)==null?void 0:r.detail)||"Failed to update user status",{duration:3e3}),await l({page:i.page,limit:50,append:!1})}},$=c=>{if(typeof c!="string")return"??";try{return c.split(" ").map(D=>D?D[0]:"").join("").toUpperCase().slice(0,2)}catch{return"??"}},E=c=>{const D=["bg-blue-500","bg-green-500","bg-purple-500","bg-red-500","bg-yellow-500"];return D[c%D.length]},U=c=>(c==null?void 0:c.name)||"Unknown User",Y=c=>(c==null?void 0:c.email)||"No email",Z=c=>(c==null?void 0:c.role)||ae.TEAM_MEMBER,V=c=>(c==null?void 0:c.uuid)||(c==null?void 0:c.id)||`user-${Math.random().toString(36).slice(2,9)}`;return e.jsxs("div",{className:"h-full bg-white mx-0 my-0",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"overflow-auto flex-1 relative",children:[b?e.jsxs("table",{className:"w-full border border-gray-200 border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",onChange:B,checked:y.length===R.length&&R.length>0})}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"USER"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"EMAIL ADDRESS"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ROLE"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"STATUS"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ADDED ON"}),e.jsx("th",{className:"w-20 bg-gray-100 border"})]})}),e.jsx("tbody",{children:b&&R.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"text-center py-8 text-gray-500 border",children:"No users found"})}):R.map((c,D)=>{const q=V(c),r=U(c),x=Y(c),d=Z(c),w=c.is_active!==!1;return e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"px-4 border py-1",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:y.includes(q),onChange:()=>W(q)})}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium ${E(D)}`,children:$(r)}),e.jsx("span",{className:"ml-3 text-sm font-medium text-gray-900",children:r})]})}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:x}),e.jsx("td",{className:"px-4 border py-1",children:e.jsx("span",{className:`inline-flex px-2 py-1 text-xs font-medium rounded-full ${d===ae.ADMIN?"bg-purple-100 text-purple-800":"bg-blue-100 text-blue-800"}`,children:d})}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(xt,{checked:w,onChange:()=>G(q,w)}),e.jsx("span",{className:"ml-2 text-xs text-gray-600",children:w?"Active":"Inactive"})]})}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:c.createdAt?as(c.createdAt):"N/A"}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx("button",{className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",onClick:()=>X(c),"aria-label":`Edit ${r}`,children:e.jsx(Ye,{size:16})}),j()&&e.jsx("button",{className:"p-1.5 text-red-400 hover:text-red-600 hover:bg-red-50 rounded",onClick:()=>P(q,r),"aria-label":`Delete ${r}`,children:e.jsx(ue,{size:16})})]})})]},q)})})]}
14):e.jsx(Ee,{columns:h,rows:8}),e.jsx("div",{ref:H,className:`h-10 flex items-center justify-center ${!T&&i.hasMore?"":"hidden"}`,children:t&&i.hasMore&&e.jsx("div",{className:"text-sm text-gray-500",children:"Loading more..."})}),e.jsx("div",{className:"sticky bottom-0 z-10 px-4 border py-3 border-t border-gray-200 bg-gray-50 flex items-center",children:e.jsxs("div",{className:"text-sm text-gray-600 uppercase",children:["COUNT ",e.jsx("span",{className:"ml-4 font-medium",children:R.length})]})})]})}),e.jsx(Us,{isOpen:S,onClose:()=>L(!1),onUserCreated:async()=>{L(!1);try{await l({page:1,limit:50,append:!1}),k.success("User added",{duration:2e3})}catch(c){console.error("Failed to refresh users after add:",c)}}}),M&&e.jsx(mt,{isOpen:!!M,user:M,onClose:()=>F(null),onUserUpdated:async()=>{F(null);try{await l({page:1,limit:50,append:!1})}catch(c){console.error("Failed to refresh users after update:",c)}}})]})},pt=({search:s,onSetActionCallback:a,onBulkDeleteUpdate:o})=>{const{priorities:t=[],prioritiesLoading:i,prioritiesPagination:l,fetchPriorities:f,deletePriority:u}=oe(),[j,T]=n.useState(!1),[g,b]=n.useState(null),[p,S]=n.useState([]),[L,y]=n.useState(!0),[_,M]=n.useState(!1),F=Ce(),m=n.useRef(i||L),v=[{width:"40px",type:"checkbox",align:"center"},{width:"250px",type:"avatar"},{width:"80px",type:"text"},{width:"150px",type:"date"},{width:"80px",type:"actions",align:"right"}];n.useEffect(()=>{M(!1)},[F.pathname]),n.useEffect(()=>{const E=i||L;m.current&&!E&&M(!0),m.current=E},[i,L]),n.useEffect(()=>{let E=!0;return(async()=>{try{y(!0),await f({page:1,limit:50,append:!1})}catch(U){console.error("Failed to fetch priorities:",U),k.error("Failed to load priorities",{duration:3e3})}finally{E&&y(!1)}})(),()=>{E=!1}},[f]);const h=n.useCallback(async()=>{if(i||!l.hasMore)return;const E=l.page+1;try{await f({page:E,limit:50,append:!0})}catch(U){console.error("Failed to load more priorities:",U)}},[f,i,l]),C=Le({hasMore:l.hasMore,isLoading:i,onLoadMore:h});n.useEffect(()=>{a==null||a({add:()=>T(!0)})},[a]);const R=E=>{E.target.checked?S($.filter(U=>!U.is_system).map(U=>U.uuid)):S([])},J=E=>{const U=G.find(Y=>Y.uuid===E);U!=null&&U.is_system||S(Y=>Y.includes(E)?Y.filter(Z=>Z!==E):[...Y,E])},H=()=>{T(!1),b(null)},B=E=>{b(E),T(!0)},W=n.useCallback(async()=>{var E,U,Y;if(p.length<=1){k.error("Please select more than 1 priority for bulk delete",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${p.length} priorities?`))try{const Z=await xe.bulkDeletePriorities(p),V=((E=Z.data)==null?void 0:E.data)||Z.data;V.error_count===0?(k.success(`Successfully deleted ${V.success_count} priorit${V.success_count>1?"ies":"y"}`,{duration:2e3}),S([]),await f({page:1,limit:50,append:!1})):V.success_count>0?(k.error(`Deleted ${V.success_count} priorit${V.success_count>1?"ies":"y"}, but ${V.error_count} failed`,{duration:3e3}),V.errors&&V.errors.length>0&&console.error("Delete errors:",V.errors),await f({page:1,limit:50,append:!1})):(k.error(V.message||"Failed to delete priorities",{duration:3e3}),V.errors&&V.errors.length>0&&console.error("Delete errors:",V.errors))}catch(Z){console.error("Bulk delete error:",Z),k.error(((Y=(U=Z.response)==null?void 0:U.data)==null?void 0:Y.message)||"Failed to delete priorities",{duration:3e3})}},[p,f]),X=async(E,U)=>{var Y,Z;if(window.confirm(`Are you sure you want to delete "${U}" priority?`))try{await u(E),await f({page:1,limit:50,append:!1}),S(V=>V.filter(c=>c!==E))}catch(V){console.error("Error deleting priority:",V),k.error(((Z=(Y=V==null?void 0:V.response)==null?void 0:Y.data)==null?void 0:Z.message)||"Failed to delete priority",{duration:3e3})}},P=E=>E?as(E,"MMM d, yyyy"):"N/A",G=Array.isArray(t)?t:[],$=G.filter(E=>{if(!s||s.trim()==="")return!0;const U=s.toLowerCase();return Object.values(E).some(Y=>Y!=null&&String(Y).toLowerCase().includes(U))});return n.useEffect(()=>{o&&o(p.length,W)},[p.length,W,o]),e.jsxs("div",{className:"h-full bg-white mx-0 my-0",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"overflow-auto flex-1 relative",children:[_?e.jsxs("table",{className:"w-full border border-gray-200 border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",onChange:R,checked:$.filter(E=>!E.is_system).length>0&&p.length===$.filter(E=>!E.is_system).length})}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"PRIORITY"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"LEVEL"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ADDED ON"}),e.jsx("th",{className:"w-20 bg-gray-100 border"})]})}),e.jsx("tbody",{children:_&&$.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-8 text-gray-500 border",children:"No priorities found"})}):$.map(E=>e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"px-4 border py-1",children:!E.is_system&&e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:p.includes(E.uuid),onChange:()=>J(E.uuid)})}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"w-4 h-4 rounded-full mr-3",style:{backgroundColor:E.color||"#E5E7EB"}}),e.jsx("span",{className:"text-sm font-medium",children:E.name})]})}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:E.level??E.order??"—"}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:P(E.created_at)}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx("button",{className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",onClick:()=>B(E),"aria-label":`Edit ${E.name}`,children:e.jsx(Ye,{size:16})}),!E.is_system&&e.jsx("button",{className:"p-1.5 text-red-400 hover:text-red-600 hover:bg-red-50 rounded",onClick:()=>X(E.uuid,E.name),"aria-label":`Delete ${E.name}`,children:e.jsx(ue,{size:16})})]})})]},E.uuid))})]}
14):e.jsx(Ee,{columns:v,rows:8}),e.jsx("div",{ref:C,className:`h-10 flex items-center justify-center ${!L&&l.hasMore?"":"hidden"}`,children:i&&l.hasMore&&e.jsx("div",{className:"text-sm text-gray-500",children:"Loading more..."})}),e.jsx("div",{className:"sticky bottom-0 z-10 px-4 border py-3 border-t border-gray-200 bg-gray-50 flex items-center",children:e.jsxs("div",{className:"text-sm text-gray-600 uppercase",children:["COUNT ",e.jsx("span",{className:"ml-4 font-medium",children:$.length})]})})]})}),e.jsx(Ss,{isOpen:j,onClose:H,editingPriority:g,onPriorityCreated:()=>{T(!1),b(null)}})]})};function Qe(){return(Qe=Object.assign||function(s){for(var a=1;a<arguments.length;a++){var o=arguments[a];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(s[t]=o[t])}return s}).apply(this,arguments)}function Is(s,a){if(s==null)return{};var o,t,i={},l=Object.keys(s);for(t=0;t<l.length;t++)a.indexOf(o=l[t])>=0||(i[o]=s[o]);return i}function Xe(s){var a=n.useRef(s),o=n.useRef(function(t){a.current&&a.current(t)});return a.current=s,o.current}var Me=function(s,a,o){return a===void 0&&(a=0),o===void 0&&(o=1),s>o?o:s<a?a:s},De=function(s){return"touches"in s},Ze=function(s){return s&&s.ownerDocument.defaultView||self},us=function(s,a,o){var t=s.getBoundingClientRect(),i=De(a)?function(l,f){for(var u=0;u<l.length;u++)if(l[u].identifier===f)return l[u];return l[0]}(a.touches,o):a;return{left:Me((i.pageX-(t.left+Ze(s).pageXOffset))/t.width),top:Me((i.pageY-(t.top+Ze(s).pageYOffset))/t.height)}},ms=function(s){!De(s)&&s.preventDefault()},Ps=re.memo(function(s){var a=s.onMove,o=s.onKey,t=Is(s,["onMove","onKey"]),i=n.useRef(null),l=Xe(a),f=Xe(o),u=n.useRef(null),j=n.useRef(!1),T=n.useMemo(function(){var S=function(_){ms(_),(De(_)?_.touches.length>0:_.buttons>0)&&i.current?l(us(i.current,_,u.current)):y(!1)},L=function(){return y(!1)};function y(_){var M=j.current,F=Ze(i.current),m=_?F.addEventListener:F.removeEventListener;m(M?"touchmove":"mousemove",S),m(M?"touchend":"mouseup",L)}return[function(_){var M=_.nativeEvent,F=i.current;if(F&&(ms(M),!function(v,h){return h&&!De(v)}(M,j.current)&&F)){if(De(M)){j.current=!0;var m=M.changedTouches||[];m.length&&(u.current=m[0].identifier)}F.focus(),l(us(F,M,u.current)),y(!0)}},function(_){var M=_.which||_.keyCode;M<37||M>40||(_.preventDefault(),f({left:M===39?.05:M===37?-.05:0,top:M===40?.05:M===38?-.05:0}))},y]},[f,l]),g=T[0],b=T[1],p=T[2];return n.useEffect(function(){return p},[p]),re.createElement("div",Qe({},t,{onTouchStart:g,onMouseDown:g,className:"react-colorful__interactive",ref:i,onKeyDown:b,tabIndex:0,role:"slider"}))}),rs=function(s){return s.filter(Boolean).join(" ")},zs=function(s){var a=s.color,o=s.left,t=s.top,i=t===void 0?.5:t,l=rs(["react-colorful__pointer",s.className]);return re.createElement("div",{className:l,style:{top:100*i+"%",left:100*o+"%"}},re.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:a}}))},ne=function(s,a,o){return a===void 0&&(a=0),o===void 0&&(o=Math.pow(10,a)),Math.round(o*s)/o},ft=function(s){return vt(Je(s))},Je=function(s){return s[0]==="#"&&(s=s.substring(1)),s.length<6?{r:parseInt(s[0]+s[0],16),g:parseInt(s[1]+s[1],16),b:parseInt(s[2]+s[2],16),a:s.length===4?ne(parseInt(s[3]+s[3],16)/255,2):1}:{r:parseInt(s.substring(0,2),16),g:parseInt(s.substring(2,4),16),b:parseInt(s.substring(4,6),16),a:s.length===8?ne(parseInt(s.substring(6,8),16)/255,2):1}},gt=function(s){return jt(bt(s))},yt=function(s){var a=s.s,o=s.v,t=s.a,i=(200-a)*o/100;return{h:ne(s.h),s:ne(i>0&&i<200?a*o/100/(i<=100?i:200-i)*100:0),l:ne(i/2),a:ne(t,2)}},es=function(s){var a=yt(s);return"hsl("+a.h+", "+a.s+"%, "+a.l+"%)"},bt=function(s){var a=s.h,o=s.s,t=s.v,i=s.a;a=a/360*6,o/=100,t/=100;var l=Math.floor(a),f=t*(1-o),u=t*(1-(a-l)*o),j=t*(1-(1-a+l)*o),T=l%6;return{r:ne(255*[t,u,f,f,j,t][T]),g:ne(255*[j,t,t,u,f,f][T]),b:ne(255*[f,f,j,t,t,u][T]),a:ne(i,2)}},qe=function(s){var a=s.toString(16);return a.length<2?"0"+a:a},jt=function(s){var a=s.r,o=s.g,t=s.b,i=s.a,l=i<1?qe(ne(255*i)):"";return"#"+qe(a)+qe(o)+qe(t)+l},vt=function(s){var a=s.r,o=s.g,t=s.b,i=s.a,l=Math.max(a,o,t),f=l-Math.min(a,o,t),u=f?l===a?(o-t)/f:l===o?2+(t-a)/f:4+(a-o)/f:0;return{h:ne(60*(u<0?u+6:u)),s:ne(l?f/l*100:0),v:ne(l/255*100),a:i}},Nt=re.memo(function(s){var a=s.hue,o=s.onChange,t=rs(["react-colorful__hue",s.className]);return re.createElement("div",{className:t},re.createElement(Ps,{onMove:function(i){o({h:360*i.left})},onKey:function(i){o({h:Me(a+360*i.left,0,360)})},"aria-label":"Hue","aria-valuenow":ne(a),"aria-valuemax":"360","aria-valuemin":"
140"},re.createElement(zs,{className:"react-colorful__hue-pointer",left:a/360,color:es({h:a,s:100,v:100,a:1})})))}),wt=re.memo(function(s){var a=s.hsva,o=s.onChange,t={backgroundColor:es({h:a.h,s:100,v:100,a:1})};return re.createElement("div",{className:"react-colorful__saturation",style:t},re.createElement(Ps,{onMove:function(i){o({s:100*i.left,v:100-100*i.top})},onKey:function(i){o({s:Me(a.s+100*i.left,0,100),v:Me(a.v-100*i.top,0,100)})},"aria-label":"Color","aria-valuetext":"Saturation "+ne(a.s)+"%, Brightness "+ne(a.v)+"%"},re.createElement(zs,{className:"react-colorful__saturation-pointer",top:1-a.v/100,left:a.s/100,color:es(a)})))}),qs=function(s,a){if(s===a)return!0;for(var o in s)if(s[o]!==a[o])return!1;return!0},kt=function(s,a){return s.toLowerCase()===a.toLowerCase()||qs(Je(s),Je(a))};function _t(s,a,o){var t=Xe(o),i=n.useState(function(){return s.toHsva(a)}),l=i[0],f=i[1],u=n.useRef({color:a,hsva:l});n.useEffect(function(){if(!s.equal(a,u.current.color)){var T=s.toHsva(a);u.current={hsva:T,color:a},f(T)}},[a,s]),n.useEffect(function(){var T;qs(l,u.current.hsva)||s.equal(T=s.fromHsva(l),u.current.color)||(u.current={hsva:l,color:T},t(T))},[l,s,t]);var j=n.useCallback(function(T){f(function(g){return Object.assign({},g,T)})},[]);return[l,j]}var Ct=typeof window<"u"?n.useLayoutEffect:n.useEffect,St=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0},xs=new Map,Et=function(s){Ct(function(){var a=s.current?s.current.ownerDocument:document;if(a!==void 0&&!xs.has(a)){var o=a.createElement("style");o.innerHTML=`.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`,xs.set(a,o);var t=St();t&&o.setAttribute("nonce",t),a.head.appendChild(o)}},[])},Dt=function(s){var a=s.className,o=s.colorModel,t=s.color,i=t===void 0?o.defaultColor:t,l=s.onChange,f=Is(s,["className","colorModel","color","onChange"]),u=n.useRef(null);Et(u);var j=_t(o,i,l),T=j[0],g=j[1],b=rs(["react-colorful",a]);return re.createElement("div",Qe({},f,{ref:u,className:b}),re.createElement(wt,{hsva:T,onChange:g}),re.createElement(Nt,{hue:T.h,onChange:g,className:"react-colorful__last-control"}))},Tt={defaultColor:"000",toHsva:ft,fromHsva:function(s){return gt({h:s.h,s:s.s,v:s.v,a:1})},equal:kt},Mt=function(s){return re.createElement(Dt,Qe({},s,{colorModel:Tt}))};const Lt=({search:s,onSetActionCallback:a,onBulkDeleteUpdate:o})=>{const{user:t}=Be(),{statuses:i,statusesLoading:l,statusesPagination:f,fetchStatuses:u,createStatus:j,updateStatus:T,deleteStatus:g}=oe(),p=(()=>{const d=(i||[]).map(O=>O.level).filter(O=>O!=null),w=d.length>0?Math.max(...d):1,A=Math.max(w+1,5),Q=[];for(let O=1;O<=A;O++){let K=`Level ${O}`;O===1?K+=" - Highest":O===w&&d.length>0&&w>1?K+=" - Lowest":d.length===0&&O===1&&(K+=" - Highest"),Q.push({value:O,label:K})}return Q})(),[S,L]=n.useState(!0),[y,_]=n.useState(!1),M=Ce(),F=n.useRef(l||S),[m,v]=n.useState(!1),[h,C]=n.useState(null),[R,J]=n.useState({name:"",level:void 0,color:"#3b82f6",company_uuid:(t==null?void 0:t.companyUuid)||""}),[H,B]=n.useState([]),[W,X]=n.useState(!1),P=[{width:"80%",type:"avatar"},{width:"15%",type:"date"},{width:"5%",type:"actions",align:"right"}];n.useEffect(()=>{let d=!0;return(async()=>
14{try{L(!0),await u({page:1,limit:50,append:!1})}catch(w){console.error("Failed to fetch statuses:",w),k.error("Failed to load statuses",{duration:3e3})}finally{d&&L(!1)}})(),()=>{d=!1}},[u]),n.useEffect(()=>{_(!1)},[M.pathname]),n.useEffect(()=>{const d=l||S;F.current&&!d&&_(!0),F.current=d},[l,S]);const G=n.useCallback(async()=>{if(l||!f.hasMore)return;const d=f.page+1;try{await u({page:d,limit:50,append:!0})}catch(w){console.error("Failed to load more statuses:",w)}},[u,l,f]),$=Le({hasMore:f.hasMore,isLoading:l,onLoadMore:G});n.useEffect(()=>{a==null||a({add:()=>v(!0)})},[a]);const E=Array.isArray(i)?i:[],U=E.filter(d=>{if(!s||s.trim()==="")return!0;const w=s.toLowerCase();return Object.values(d).some(A=>A!=null&&String(A).toLowerCase().includes(w))}),Y=d=>{d.target.checked?B(U.filter(w=>!w.is_system).map(w=>w.uuid)):B([])},Z=d=>{const w=E.find(A=>A.uuid===d);w!=null&&w.is_system||B(A=>A.includes(d)?A.filter(Q=>Q!==d):[...A,d])},V=()=>{v(!1),C(null),J({name:"",level:void 0,color:"#3b82f6",company_uuid:(t==null?void 0:t.companyUuid)||""}),X(!1)},c=d=>{C(d),J({name:d.name,level:d.level,color:d.color,company_uuid:d.company_uuid}),v(!0)},D=async()=>{var d;if((d=R.name)!=null&&d.trim()){X(!0);try{const w={name:R.name.trim(),color:R.color,company_uuid:R.company_uuid};R.level!==void 0&&(w.level=R.level),h&&h.uuid?(await T(h.uuid,w),await u({page:1,limit:50,append:!1})):(await j(w),await u({page:1,limit:50,append:!1})),V()}catch(w){console.error("Error saving status:",w),k.error("Failed to save status",{duration:3e3})}finally{X(!1)}}},q=async(d,w)=>{if(window.confirm(`Are you sure you want to delete "${w}" status?`))try{await g(d),await u({page:1,limit:50,append:!1}),B(A=>A.filter(Q=>Q!==d))}catch(A){console.error("Error deleting status:",A),k.error("Failed to delete status",{duration:3e3})}},r=n.useCallback(async()=>{var d,w,A;if(H.length<=1){k.error("Please select more than 1 status for bulk delete",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${H.length} statuses?`))try{const Q=await xe.bulkDeleteStatuses(H),O=((d=Q.data)==null?void 0:d.data)||Q.data;O.error_count===0?(k.success(`Successfully deleted ${O.success_count} status${O.success_count>1?"es":""}`,{duration:2e3}),B([]),await u({page:1,limit:50,append:!1})):O.success_count>0?(k.error(`Deleted ${O.success_count} status${O.success_count>1?"es":""}, but ${O.error_count} failed`,{duration:3e3}),O.errors&&O.errors.length>0&&console.error("Delete errors:",O.errors),await u({page:1,limit:50,append:!1})):(k.error(O.message||"Failed to delete statuses",{duration:3e3}),O.errors&&O.errors.length>0&&console.error("Delete errors:",O.errors))}catch(Q){console.error("Bulk delete error:",Q),k.error(((A=(w=Q.response)==null?void 0:w.data)==null?void 0:A.message)||"Failed to delete statuses",{duration:3e3})}},[H,u]),x=d=>d?as(d,"MMM d, yyyy"):"N/A";return n.useEffect(()=>{o&&o(H.length,r)},[H.length,r,o]),e.jsxs("div",{className:"h-full bg-white mx-0 my-0",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"overflow-auto flex-1 relative",children:[y?e.jsxs("table",{className:"w-full border border-gray-200 border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-[80%]",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"checkbox",className:"rounded border-gray-300 mr-3",onChange:Y,checked:U.filter(d=>!d.is_system).length>0&&H.length===U.filter(d=>!d.is_system).length}),e.jsx("span",{className:"text-xs font-medium text-gray-600 uppercase tracking-wider",children:"STATUS"})]})}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-[15%] text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ADDED ON"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-[5%] text-xs font-medium text-gray-600 uppercase tracking-wider",children:"ACTIONS"})]})}),e.jsx("tbody",{children:y&&U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"text-center py-8 text-gray-500 border",children:"No statuses found"})}):U.map(d=>e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"px-4 border py-1 w-[80%]",children:e.jsxs("div",{className:"flex items-center",children:[!d.is_system&&e.jsx("input",{type:"checkbox",className:"rounded border-gray-300 mr-3",checked:H.includes(d.uuid),onChange:()=>Z(d.uuid)}),e.jsx("div",{className:"w-4 h-4 rounded-full mr-3",style:{backgroundColor:d.color}}),e.jsx("span",{className:"text-sm font-medium",children:d.name})]})}),e.jsx("td",{className:"px-4 border py-1 w-[15%] text-sm text-gray-600",children:x(d.created_at)}),e.jsx("td",{className:"px-4 border py-1 w-[5%]",children:e.jsxs("div",{className:"flex items-center justify-end space-x-1",children:[e.jsx("button",{className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",onClick:()=>c(d),"aria-label":`Edit ${d.name}`,children:e.jsx(Ye,{size:16})}),!d.is_system&&e.jsx("button",{className:"p-1.5 text-red-400 hover:text-red-600 hover:bg-red-50 rounded",onClick:()=>q(d.uuid,d.name),"aria-label":`Delete ${d.name}`,children:e.jsx(ue,{size:16})})]})})]},d.uuid))})]}
14):e.jsx(Ee,{columns:P,rows:8}),e.jsx("div",{ref:$,className:`h-10 flex items-center justify-center ${!S&&f.hasMore?"":"hidden"}`,children:l&&f.hasMore&&e.jsx("div",{className:"text-sm text-gray-500",children:"Loading more..."})}),e.jsx("div",{className:"sticky bottom-0 z-10 px-4 border py-3 border-t border-gray-200 bg-gray-50 flex items-center",children:e.jsxs("div",{className:"text-sm text-gray-600 uppercase",children:["COUNT"," ",e.jsx("span",{className:"ml-4 font-medium",children:U.length})]})})]})}),e.jsx(be,{isOpen:m,onClose:V,title:h?"Edit Status":"Add Status",size:"md",children:e.jsxs("div",{className:"space-y-4 px-4",children:[e.jsx(se,{label:"Status Name",value:R.name,onChange:d=>J({...R,name:d.target.value}),placeholder:"Enter status name",required:!0,autoFocus:!0,disabled:(h==null?void 0:h.is_system)===!0}),(h==null?void 0:h.is_system)===!0&&e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"System status names cannot be modified"}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Status Level ",h?"":"(Optional)"]}),e.jsx(Ne,{value:R.level!==void 0?String(R.level):"",onChange:d=>J({...R,level:d.target.value?Number(d.target.value):void 0}),disabled:W,children:h?p.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value)):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"Auto-increment (default)"}),p.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]})}),!h&&e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"Leave empty to auto-increment, or select a specific level"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Color"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Mt,{color:R.color,onChange:d=>J({...R,color:d}),style:{width:"100%",height:"200px"}}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("div",{className:"w-10 h-10 rounded border border-gray-300",style:{backgroundColor:R.color}}),e.jsx("span",{className:"text-sm text-gray-600 font-mono",children:R.color})]})]})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx(I,{variant:"secondary",onClick:V,disabled:W,children:"Cancel"}),e.jsx(I,{variant:"primary",onClick:D,disabled:!R.name.trim()||W,loading:W,children:h?W?"Updating...":"Update":W?"Saving...":"Save"})]})]})})]})},Os=()=>te.get("/configs",{cache:!1}),Bs=s=>te.put("/configs/general-preferences",s),At=({preferences:s,setPreferences:a,setInitalPreferences:o})=>{const[t,i]=n.useState(!1),[l,f]=n.useState(!1),[u,j]=n.useState([]),T=Ns(),g=Oe(u,"quotation");n.useEffect(()=>{(async()=>{var S,L,y,_;i(!0),f(!1);try{const[M,F]=await Promise.all([Os(),xe.getProductFeatureModules().catch(()=>null)]),v=(F?Js(F.data??F):{modules:[],productUuid:null}).modules;j(v);const C=(S=M.data.data.configs.find(X=>X.config_type==="general_preferences"))==null?void 0:S.config_data,R=((L=C==null?void 0:C.display_preferences)==null?void 0:L.date_format)??((y=C==null?void 0:C.displayPreferences)==null?void 0:y.dateFormat)??s.dateFormat,J=(_=C==null?void 0:C.display_preferences)==null?void 0:_.default_time_unit,H=J?J.charAt(0).toUpperCase()+J.slice(1):void 0,B=Ds(C==null?void 0:C.display_preferences,v),W={...s,dateFormat:R||s.dateFormat,defaultTimeUnit:H??s.defaultTimeUnit,showQuotationTaskWise:B.showQuotationTaskWise,showFrequencyModule:B.showFrequencyModule};try{typeof window<"u"&&W.dateFormat&&window.localStorage.setItem("dateFormat",W.dateFormat)}catch{}o(W),a(W)}catch(M){f(!0),console.error("Failed to fetch company preferences:",M)}finally{i(!1)}})()},[]);const b=(p,S)=>{a(L=>({...L,[p]:S}))};return t?e.jsx("div",{className:"h-full flex items-center justify-center bg-gray-50 py-12",children:e.jsx("p",{className:"text-sm text-gray-600",children:"Loading preferences…"})}):l?e.jsx("div",{className:"h-full flex items-center justify-center bg-gray-50 py-12",children:e.jsx("p",{className:"text-sm text-red-600",children:"Could not load preferences."})}):(Oe(u,"frequency"),e.jsx("div",{className:"h-full bg-gray-50 overflow-y-auto",children:e.jsx("div",{className:"max-w-6xl mx-auto px-8 py-6",children:e.jsx("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8",children:e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{className:"col-span-1",children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Display Preferences"}),e.jsxs("p",{className:"text-sm text-gray-600 mt-2",children:["Set how dates and time units appear across the platform. Quotation tax and terms are configured under"," ",g?e.jsx("button",{type:"button",onClick:()=>T("/configurations/quotation-setup"),className:"font-medium text-blue-600 hover:text-blue-800 underline",children:"Quotation Setup"}):e.jsx("span",{className:"font-medium text-gray-800",children:"Quotation Setup"}),"."]})]}),e.jsx("div",{className:"col-span-1",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Date format"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Choose how dates appear in dashboards, exports, and filters."})]})}),e.jsx("div",{className:"col-span-1",children:e.jsxs(Ne,{value:s.dateFormat,onChange:p=>b("dateFormat",p.target.value),className:"w-full",children:[e.jsx("option",{value:"DD/MM/YYYY",children:"DD/MM/YYYY"}),e.jsx("option",{value:"MM/DD/YYYY",children:"MM/DD/YYYY"}),e.jsx("option",{value:"YYYY-MM-DD",children:"YYYY-MM-DD"})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Default time unit"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Preferred unit for time entries on tasks and reports."})]})}),e.jsx("div",{className:"col-span-1",children:e.jsxs(Ne,{value:s.defaultTimeUnit,onChange:p=>b("defaultTimeUnit",p.target.value),className:"w-full",children:[e.jsx("option",{value:"Minutes",children:"Minutes"}),e.jsx("option",{value:"Hours",children:"Hours"}),e.jsx("option",{value:"Days",children:"Days"})]})})]})]})})})}))},Ft=4,Rt=104,$s={company_address_max_lines:Ft,company_address_max_line_chars:Rt},ss=$s.company_address_max_lines,Ut=$s.company_address_max_line_chars,hs=ss,We=Ut*ss+Math.max(0,ss-1),It={quotationNumberPrefix:"",startingQuotationNumber:"",defaultDueDays:"",defaultTerms:"",showTaskAssignee:!1,companyName:"",companyEmail:"",companyPhone:"",companyAddress:"",accountHolderName:"",bankName:"",branchName:"",accountNumber:"",ifscCode:"",gstNumber:"",companyLogo:"",authorizedStamp:"",country:"India",taxColumn1:"",taxColumn2:"",taxColumn3:"",taxTermsAndConditions:""},ns=s=>s.startsWith("blob:")||s.startsWith("http://")||s.startsWith("https://"),ps=(s,a)=>s?ns(s)?a||void 0:s:"",Pt=s=>!!s.trim()&&!ns(s),fs=(s,a)=>s||(a&&ns(a)?a:""),ts=s=>Pt(s),gs=async(s,a)=>
14{if(ts(s))try{const{data:o}=await a();return URL.createObjectURL(o)}catch{return}},zt=(s,a)=>{var i,l;const o=parseInt(s.startingQuotationNumber,10),t=parseInt(s.defaultDueDays,10);return{general_settings:{invoice_number_prefix:s.quotationNumberPrefix,starting_invoice_number:Number.isFinite(o)&&o>0?o:1,default_due_days:Number.isFinite(t)&&t>0?t:30,default_terms_and_conditions:s.defaultTerms||void 0,show_task_assignee_on_invoice:s.showTaskAssignee},company_details:{company_name:s.companyName,email_address:s.companyEmail,phone_number:s.companyPhone||void 0,address:s.companyAddress||void 0},bank_account_details:{account_holder_name:s.accountHolderName||void 0,bank_name:s.bankName||void 0,branch_name:s.branchName||void 0,account_number:s.accountNumber||void 0,ifsc_code:s.ifscCode||void 0},tax_compliance:{gst_number:s.gstNumber||void 0},branding_personalization:{company_logo:ps(s.companyLogo,(i=a==null?void 0:a.branding_personalization)==null?void 0:i.company_logo),signature_or_authorized_stamp:ps(s.authorizedStamp,(l=a==null?void 0:a.branding_personalization)==null?void 0:l.signature_or_authorized_stamp)},tax_preferences:{country:s.country||void 0,tax_column_1:s.taxColumn1||void 0,tax_column_2:s.taxColumn2||void 0,tax_column_3:s.taxColumn3||void 0,terms_and_conditions:s.taxTermsAndConditions||void 0}}},ys=()=>{const s=oe(r=>{var x;return((x=r.preferences)==null?void 0:x.showQuotationTaskWise)??!1}),a=oe(r=>{var x;return((x=r.preferences)==null?void 0:x.showFrequencyModule)??Ts.ENABLE_FREQUENCY_MODULE}),[o,t]=n.useState(!0),[i,l]=n.useState(!1),[f,u]=n.useState(s),[j,T]=n.useState(a),[g,b]=n.useState({dateFormat:"DD/MM/YYYY",defaultTimeUnit:"hours",frequencyModuleEnabled:!0}),p=oe(r=>r.fetchConfigs),[S,L]=n.useState(null),[y,_]=n.useState(It),[M,F]=n.useState(),[m,v]=n.useState(),[h,C]=n.useState("general"),R=[{id:"general",label:"General Settings"},{id:"company",label:"Company Details"},{id:"bank",label:"Bank Account Details"},{id:"tax",label:"Tax & compliance"},{id:"branding",label:"Branding & Personalization"}],J=r=>{var x,d,w,A,Q,O,K,le,de,je,Ae,Fe,Re,fe,Se,ke,Ue,he,Ie,Pe,N,z;return{quotationNumberPrefix:((x=r.general_settings)==null?void 0:x.invoice_number_prefix)||"",startingQuotationNumber:String(((d=r.general_settings)==null?void 0:d.starting_invoice_number)||""),defaultDueDays:String(((w=r.general_settings)==null?void 0:w.default_due_days)||""),defaultTerms:((A=r.general_settings)==null?void 0:A.default_terms_and_conditions)||"",showTaskAssignee:((Q=r.general_settings)==null?void 0:Q.show_task_assignee_on_invoice)||!1,companyName:((O=r.company_details)==null?void 0:O.company_name)||"",companyEmail:((K=r.company_details)==null?void 0:K.email_address)||"",companyPhone:((le=r.company_details)==null?void 0:le.phone_number)||"",companyAddress:((de=r.company_details)==null?void 0:de.address)||"",accountHolderName:((je=r.bank_account_details)==null?void 0:je.account_holder_name)||"",bankName:((Ae=r.bank_account_details)==null?void 0:Ae.bank_name)||"",branchName:((Fe=r.bank_account_details)==null?void 0:Fe.branch_name)||"",accountNumber:((Re=r.bank_account_details)==null?void 0:Re.account_number)||"",ifscCode:((fe=r.bank_account_details)==null?void 0:fe.ifsc_code)||"",gstNumber:((Se=r.tax_compliance)==null?void 0:Se.gst_number)||"",companyLogo:((ke=r.branding_personalization)==null?void 0:ke.company_logo)||"",authorizedStamp:((Ue=r.branding_personalization)==null?void 0:Ue.signature_or_authorized_stamp)||"",country:((he=r.tax_preferences)==null?void 0:he.country)||"India",taxColumn1:((Ie=r.tax_preferences)==null?void 0:Ie.tax_column_1)||"",taxColumn2:((Pe=r.tax_preferences)==null?void 0:Pe.tax_column_2)||"",taxColumn3:((N=r.tax_preferences)==null?void 0:N.tax_column_3)||"",taxTermsAndConditions:((z=r.tax_preferences)==null?void 0:z.terms_and_conditions)||""}},H=n.useCallback(async(r=!0)=>{var x,d;r&&t(!0);try{try{(x=te)!=null&&x.clearCache&&te.clearCache()}catch{}const w=await xe.getQuotationSetupConfig({cache:!1}),A=((d=w==null?void 0:w.data)==null?void 0:d.data)??(w==null?void 0:w.data)??w;if(A&&typeof A=="object"){const Q=A,O=J(Q);L(Q),_(O);const[K,le]=await Promise.all([gs(O.companyLogo,()=>xe.fetchQuotationCompanyLogo()),gs(O.authorizedStamp,()=>xe.fetchQuotationSignature())]);F(de=>(de&&URL.revokeObjectURL(de),K)),v(de=>(de&&URL.revokeObjectURL(de),le))}}catch(w){if(Ke(w))return;console.error("Failed to fetch quotation setup:",w),k.error("Failed to load quotation setup",{duration:3e3})}finally{r&&t(!1)}},[]);n.useEffect(()=>{u(s),T(a)},[s,a]),n.useEffect(()=>{H()},[H]),n.useEffect(()=>()=>{M&&URL.revokeObjectURL(M),m&&URL.revokeObjectURL(m)},[M,m]),n.useEffect(()=>{(async()=>{var x,d,w;try{const A=await Os(),O=(w=(((d=(x=A==null?void 0:A.data)==null?void 0:x.data)==null?void 0:d.configs)||[]).find(je=>(je==null?void 0:je.config_type)==="general_preferences"))==null?void 0:w.config_data,K=(O==null?void 0:O.display_preferences)||{},le=typeof K.quotation_module_enabled=="boolean"?K.quotation_module_enabled:!1,de=typeof K.frequency_module_enabled=="boolean"?K.frequency_module_enabled:!0;u(le),T(de),b({dateFormat:K.date_format||"DD/MM/YYYY",defaultTimeUnit:String(K.default_time_unit||"hours").toLowerCase(),frequencyModuleEnabled:de}),await p()}catch(A){console.error("Failed to load general preferences:",A)}})()},[p]);const B=(r,x)=>{_(d=>({...d,[r]:x}))},W=r=>{const d=r.target.value.slice(0,We),w=d.split(`
15`),A=w.length>hs?w.slice(0,hs).join(`
16`):d;B("companyAddress",A)},X=async()=>{var r;l(!0);try{const x=zt(y,S),d=oe.getState().configs.find(K=>K.config_type==="general_preferences"),A={...((r=d==null?void 0:d.config_data)==null?void 0:r.display_preferences)??{},date_format:g.dateFormat||"DD/MM/YYYY",default_time_unit:g.defaultTimeUnit||"hours",quotation_module_enabled:f,frequency_module_enabled:j};await Bs({display_preferences:A});const Q=oe.getState(),O=Ds(A,Q.productFeatureModules);oe.setState({configs:Q.configs.map(K=>K.config_type==="general_preferences"?{...K,config_data:{...K.config_data,display_preferences:A}}:K),preferences:{...Q.preferences,dateFormat:A.date_format||Q.preferences.dateFormat,showQuotationTaskWise:O.showQuotationTaskWise,showFrequencyModule:O.showFrequencyModule}}),await xe.updateQuotationSetupConfig(x),p(),k.success("Quotation setup saved successfully",{duration:2e3}),await new Promise(K=>setTimeout(K,100)),await H(!1)}
16catch(x){if(Ke(x))return;console.error("Failed to save quotation setup:",x);const d=Ms(x);k.error(d||"Failed to save quotation setup",{duration:5e3})}finally{l(!1)}},P=async()=>{window.confirm("Are you sure you want to reset to the last saved values?")&&S&&(_(J(S)),k.success("Form reset to last saved values",{duration:2e3}))},G=(r,x)=>{var w;const d=(w=r.target.files)==null?void 0:w[0];d&&$(d,x)},$=async(r,x)=>{try{l(!0);const d=URL.createObjectURL(r);x==="logo"?(M&&URL.revokeObjectURL(M),F(d),await xe.uploadQuotationCompanyLogo(r)):(m&&URL.revokeObjectURL(m),v(d),await xe.uploadQuotationSignature(r)),k.success(x==="logo"?"Company logo uploaded":"Authorized stamp uploaded",{duration:2e3}),await H(!1)}catch(d){console.error("File upload failed:",d),k.error("Failed to upload file",{duration:3e3})}finally{l(!1)}},E=r=>{r==="logo"?(M&&URL.revokeObjectURL(M),F(void 0),B("companyLogo","")):(m&&URL.revokeObjectURL(m),v(void 0),B("authorizedStamp",""))},U=r=>{var x;(x=document.getElementById(r))==null||x.click()},Y=()=>e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{className:"col-span-1",children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"General Settings"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"Define how quotation numbers are prefixed, sequencing, default due days, and standard terms."})]}),e.jsx("div",{className:"col-span-1",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Quotation number prefix"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Add a custom prefix to your quotation numbers."})]})}),e.jsx("div",{className:"col-span-1",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(se,{value:y.quotationNumberPrefix,onChange:r=>B("quotationNumberPrefix",r.target.value),placeholder:"INV-"}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Preview: ",y.quotationNumberPrefix||"INV-",y.startingQuotationNumber||"1001"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Starting quotation number"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Set the number your quotations should start from."})]}),e.jsx("div",{children:e.jsx(se,{value:y.startingQuotationNumber,onChange:r=>B("startingQuotationNumber",r.target.value),placeholder:"1001",type:"number"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Default Due Days"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Default days from the quotation date until payment is due."})]}),e.jsx("div",{children:e.jsx(se,{value:y.defaultDueDays,onChange:r=>B("defaultDueDays",r.target.value),placeholder:"30",type:"number"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Default Terms & Conditions"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Default terms to show at the bottom of quotations when applicable."})]}),e.jsx("div",{children:e.jsx("textarea",{className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm resize-none focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",rows:4,value:y.defaultTerms,onChange:r=>B("defaultTerms",r.target.value),placeholder:"Add any default terms..."})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Show task assignee on quotations"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Display assignee names for tasks included on the quotation."})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>B("showTaskAssignee",!y.showTaskAssignee),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${y.showTaskAssignee?"bg-blue-600":"bg-gray-200"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${y.showTaskAssignee?"translate-x-6":"translate-x-1"}`})})})]})]}),Z=()=>e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Company Details"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"This information appears on quotation headers."})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Company Name"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Enter the official name of your business."})]}),e.jsx("div",{children:e.jsx(se,{value:y.companyName,onChange:r=>B("companyName",r.target.value),placeholder:"Your Company Name"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Email Address"})}),e.jsx("div",{children:e.jsx(se,{value:y.companyEmail,onChange:r=>B("companyEmail",r.target.value),placeholder:"[email protected]",type:"email"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Phone Number"})}),e.jsx("div",{children:e.jsx(se,{value:y.companyPhone,onChange:r=>B("companyPhone",r.target.value),placeholder:"9876543210"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Address"})}),e.jsxs("div",{children:[e.jsx("textarea",{className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm resize-none focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",rows:3,value:y.companyAddress,onChange:W,maxLength:We,placeholder:"Enter your company address"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[y.companyAddress.length," / ",We," ","characters"]})]})]})]}),V=()=>e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Bank Account Details"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"These details appear on quotations for payment instructions."})]}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Account Name"})}),e.jsx("div",{children:e.jsx(se,{value:y.accountHolderName,onChange:r=>B("accountHolderName",r.target.value),placeholder:"ABC Pvt Ltd"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Bank Name"})}),e.jsx("div",{children:e.jsx(se,{value:y.bankName,onChange:r=>B("bankName",r.target.value),placeholder:"HDFC Bank"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Branch 
16Name"})}),e.jsx("div",{children:e.jsx(se,{value:y.branchName,onChange:r=>B("branchName",r.target.value),placeholder:"Main Branch"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Account Number"})}),e.jsx("div",{children:e.jsx(se,{value:y.accountNumber,onChange:r=>B("accountNumber",r.target.value),placeholder:"502000789456123"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"IFSC Code"})}),e.jsx("div",{children:e.jsx(se,{value:y.ifscCode,onChange:r=>B("ifscCode",r.target.value),placeholder:"HDFC0001234"})})]})]}),c=()=>e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Tax & compliance"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"Configure country, tax columns, GST, and terms used on quotations and related documents."})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Country"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Select the country to configure tax structure accordingly."})]}),e.jsx("div",{children:e.jsxs(Ne,{value:y.country,onChange:r=>B("country",r.target.value),className:"w-full",children:[e.jsx("option",{value:"India",children:"India"}),e.jsx("option",{value:"USA",children:"USA"}),e.jsx("option",{value:"UK",children:"UK"}),e.jsx("option",{value:"Other",children:"Other"})]})})]}),y.country==="India"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Tax column #1"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"First tax column label (e.g. CGST, VAT)."})]}),e.jsx("div",{children:e.jsxs(Ne,{value:y.taxColumn1,onChange:r=>B("taxColumn1",r.target.value),className:"w-full",children:[e.jsx("option",{value:"CGST",children:"CGST"}),e.jsx("option",{value:"SGST",children:"SGST"}),e.jsx("option",{value:"IGST",children:"IGST"})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Tax column #2"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Second tax column label (optional)."})]}),e.jsx("div",{children:e.jsxs(Ne,{value:y.taxColumn2,onChange:r=>B("taxColumn2",r.target.value),className:"w-full",children:[e.jsx("option",{value:"SGST",children:"SGST"}),e.jsx("option",{value:"CGST",children:"CGST"}),e.jsx("option",{value:"IGST",children:"IGST"})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Tax column #3"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Third tax column label (optional)."})]}),e.jsx("div",{children:e.jsxs(Ne,{value:y.taxColumn3,onChange:r=>B("taxColumn3",r.target.value),className:"w-full",children:[e.jsx("option",{value:"IGST",children:"IGST"}),e.jsx("option",{value:"CGST",children:"CGST"}),e.jsx("option",{value:"SGST",children:"SGST"})]})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"GST number"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Business GSTIN for compliance-ready quotations where applicable."})]}),e.jsx("div",{children:e.jsx(se,{value:y.gstNumber,onChange:r=>B("gstNumber",r.target.value),placeholder:"24ABCDE1234F1Z5"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900 mb-2",children:"Terms & conditions"}),e.jsx("textarea",{value:y.taxTermsAndConditions||"",onChange:r=>B("taxTermsAndConditions",r.target.value),placeholder:"Enter terms & conditions for quotations...",className:"w-full border border-gray-300 rounded-md p-3 text-sm min-h-[120px] focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]})]}),D=()=>{const r=fs(M,y.companyLogo),x=fs(m,y.authorizedStamp),d=!!(r||ts(y.companyLogo)),w=!!(x||ts(y.authorizedStamp));return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Branding & Personalization"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"Customize how quotations look with your logo and stamp."})]}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Company Logo"})}),e.jsx("div",{children:e.jsxs("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-6 text-center bg-gray-50",children:[r?e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:r,alt:"Company Logo",className:"max-h-24 mx-auto mb-2"}),e.jsx("button",{onClick:()=>E("logo"),className:"text-red-500 text-xs hover:underline",children:"Remove"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mx-auto h-8 w-8 text-gray-400"}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Upload"})]}),e.jsx("input",{type:"file",id:"logo-upload",className:"hidden",accept:"image/*",onChange:A=>G(A,"logo")}),e.jsx(I,{variant:"secondary",className:"mt-2 text-xs",onClick:()=>U("logo-upload"),children:d?"Change Logo":"Upload Logo"})]})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsx("div",{}),e.jsx("div",{children:e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Signature or Authorized Stamp"})}),e.jsx("div",{children:e.jsxs("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-6 text-center bg-gray-50",children:[x?e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:x,alt:"Authorized Stamp",className:"max-h-24 mx-auto mb-2"}),e.jsx("button",{onClick:()=>E("stamp"),className:"text-red-500 text-xs hover:underline",children:"Remove"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"mx-auto h-8 w-8 text-gray-400"}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Upload"})]}),e.jsx("input",{type:"file",id:"stamp-upload",className:"hidden",accept:"image/*",onChange:A=>G(A,"stamp")}),e.jsx(I,{variant:"secondary",className:"mt-2 text-xs",onClick:()=>U("stamp-upload"),children:w?"Change Stamp":"Upload Stamp"})]})})]})]})},q=()=>{if(o)return e.jsx("div",{className:"flex justify-center items-center py-12",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),e.jsx("p",{className:"mt-4 text-sm text-gray-600",children:"Loading quotation setup..."})]})});switch(h){case"general":return Y();case"company":return Z();case"bank":return V();case"tax":return c();case"branding":return D();default:return Y()}};return e.jsxs("div",{className:"h-full flex bg-gray-50",children:[e.jsx("div",{className:"w-64 bg-white border-r border-gray-200",children:e.jsx("nav",{className:"p-4 space-y-1",children:R.map(r=>e.jsx("button",{onClick:()=>C(r.id),className:`w-full text-left px-4 py-2 text-sm font-medium rounded-md transition-colors ${h===r.id?"bg-blue-50 text-blue-700":"text-gray-600 hover:text-gray-900 hover:bg-gray-50"}`,children:r.label},r.id))})}),e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx("div",{className:"max-w-6xl mx-auto px-8 py-6",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-8",children:[e.jsx("div",{className:"pb-6 mb
16-6 border-b border-gray-200 space-y-8",children:e.jsxs("div",{className:"grid grid-cols-3 gap-8",children:[e.jsxs("div",{className:"col-span-1",children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:"Quotation Module"}),e.jsx("p",{className:"text-sm text-gray-600 mt-2",children:"Enable task-wise amount and quotation actions in task tables. Save changes to apply."})]}),e.jsxs("div",{className:"col-span-1",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-900",children:"Enable quotation module"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Shows the Amount column and quotation icon on tasks."})]}),e.jsx("div",{className:"col-span-1 flex items-center",children:e.jsx("button",{type:"button",onClick:()=>u(r=>!r),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?"bg-blue-600":"bg-gray-300"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?"translate-x-6":"translate-x-1"}`})})})]})}),q(),e.jsxs("div",{className:"mt-12 pt-8 border-t border-gray-200 flex justify-end space-x-4",children:[e.jsx(I,{variant:"secondary",onClick:P,disabled:o||i,children:"Reset to Default"}),e.jsx(I,{variant:"primary",onClick:X,loading:i,disabled:o||i,children:i?"Saving...":"Save Changes"})]})]})})})]})},qt=({search:s,onSetActionCallback:a,onBulkDeleteUpdate:o})=>{const{taskTemplates:t=[],subTaskTemplates:i=[],subTasksPagination:l,loading:f,fetchTaskTemplates:u,fetchSubTaskTemplates:j,createSubTaskTemplate:T,updateSubTaskTemplate:g,deleteSubTaskTemplate:b}=oe(),[p,S]=n.useState(!1),[L,y]=n.useState(""),[_,M]=n.useState(""),[F,m]=n.useState(null),[v,h]=n.useState([]),[C,R]=n.useState(!0),[J,H]=n.useState(!1),B=Ce(),W=n.useRef(f||C),X=(Array.isArray(i)?i:[]).filter(r=>{if(!s||s.trim()==="")return!0;const x=s.toLowerCase(),d=Object.values(r).some(Q=>Q!=null&&String(Q).toLowerCase().includes(x)),w=(Array.isArray(t)?t:[]).find(Q=>Q.uuid===r.task_uuid),A=(w==null?void 0:w.name)!=null&&String(w.name).toLowerCase().includes(x);return d||A}),P=[{width:"40px",type:"checkbox",align:"center"},{width:"250px",type:"text"},{width:"200px",type:"text"},{width:"80px",type:"actions",align:"right"}];n.useEffect(()=>{H(!1)},[B.pathname]),n.useEffect(()=>{const r=f||C;W.current&&!r&&H(!0),W.current=r},[f,C]),n.useEffect(()=>{let r=!0;return(async()=>{try{R(!0),console.debug("[SubTasksConfig] fetching tasks + subtasks"),await u({page:1,limit:50,append:!1}),await j({page:1,limit:50,append:!1}),r&&R(!1)}catch(x){console.error("[SubTasksConfig] initial fetch error",x),r&&R(!1)}})(),()=>{r=!1}},[u,j]);const G=n.useCallback(async()=>{if(f||!l.hasMore)return;const r=l.page+1;try{await j({page:r,limit:50,append:!0})}catch(x){console.error("Failed to load more subtasks:",x)}},[j,f,l]),$=Le({hasMore:l.hasMore,isLoading:f,onLoadMore:G});n.useEffect(()=>{a==null||a({add:()=>S(!0)})},[a]);const E=r=>{r.target.checked?h(X.map(x=>x.uuid)):h([])},U=r=>{h(x=>x.includes(r)?x.filter(d=>d!==r):[...x,r])},Y=async()=>{if(!(!L||!_.trim()))try{console.debug("[SubTasksConfig] creating subtask",{task_uuid:L,name:_});const r=await T({name:_.trim(),task_uuid:L});M(""),y(""),S(!1),await j({page:1,limit:50,append:!1}),console.debug("[SubTasksConfig] created subtask and refetched subtasks",{created:r})}catch(r){console.error("Error adding sub-task:",r)}},Z=async()=>{if(!(!F||!_.trim()))try{console.debug("[SubTasksConfig] updating subtask",{uuid:F.uuid,name:_}),await g(F.uuid,{name:_.trim(),task_uuid:F.task_uuid}),m(null),M(""),S(!1),await j({page:1,limit:50,append:!1}),console.debug("[SubTasksConfig] updated subtask and refetched subtasks")}catch(r){console.error("Error updating sub-task:",r)}},V=async(r,x)=>{if(window.confirm(`Are you sure you want to delete "${x}"?`))try{console.debug("[SubTasksConfig] deleting subtask",{uuid:r}),await b(r),await j({page:1,limit:50,append:!1}),h(d=>d.filter(w=>w!==r)),console.debug("[SubTasksConfig] deleted subtask and refetched subtasks")}catch(d){console.error("Error deleting sub-task:",d)}},c=r=>{const x=(Array.isArray(t)?t:[]).find(d=>d.uuid===r);return(x==null?void 0:x.name)||"Unknown Task"},D=r=>{m(r),M(r.name||""),y(r.task_uuid||""),S(!0)},q=n.useCallback(async()=>{var r,x,d;if(v.length<=1){k.error("Please select more than 1 sub-task for bulk delete",{duration:3e3});return}if(window.confirm(`Are you sure you want to delete ${v.length} sub-tasks?`))try{const w=await xe.bulkDeleteSubTasks(v),A=((r=w.data)==null?void 0:r.data)||w.data;A.error_count===0?(k.success(`Successfully deleted ${A.success_count}
16 sub-task${A.success_count>1?"s":""}`,{duration:2e3}),h([]),await j({page:1,limit:50,append:!1})):A.success_count>0?(k.error(`Deleted ${A.success_count} sub-task${A.success_count>1?"s":""}, but ${A.error_count} failed`,{duration:3e3}),A.errors&&A.errors.length>0&&console.error("Delete errors:",A.errors),await j({page:1,limit:50,append:!1})):(k.error(A.message||"Failed to delete sub-tasks",{duration:3e3}),A.errors&&A.errors.length>0&&console.error("Delete errors:",A.errors))}catch(w){console.error("Bulk delete error:",w),k.error(((d=(x=w.response)==null?void 0:x.data)==null?void 0:d.message)||"Failed to delete sub-tasks",{duration:3e3})}},[v,j]);return n.useEffect(()=>{o&&o(v.length,q)},[v.length,q,o]),J?e.jsxs("div",{className:"h-full bg-white mx-0 my-0",children:[e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs("div",{className:"overflow-auto flex-1 relative",children:[e.jsxs("table",{className:"w-full border border-gray-200 border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"border border-gray-200",children:[e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 w-10",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",onChange:E,checked:Array.isArray(i)&&v.length===X.length&&X.length>0})}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"SUB-TASK"}),e.jsx("th",{className:"text-left bg-gray-100 px-4 border py-1 text-xs font-medium text-gray-600 uppercase tracking-wider",children:"TASK"}),e.jsx("th",{className:"w-20 bg-gray-100 border"})]})}),e.jsx("tbody",{children:X.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"text-center py-8 text-gray-500 border",children:"No sub-tasks found"})}):X.map(r=>e.jsxs("tr",{className:"border border-gray-100 hover:bg-blue-50 focus-within:bg-blue-50",children:[e.jsx("td",{className:"px-4 border py-1",children:e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:v.includes(r.uuid),onChange:()=>U(r.uuid)})}),e.jsx("td",{className:"px-4 border py-1 text-sm font-medium text-gray-900",children:r.name}),e.jsx("td",{className:"px-4 border py-1 text-sm text-gray-600",children:c(r.task_uuid)}),e.jsx("td",{className:"px-4 border py-1",children:e.jsxs("div",{className:"flex items-center justify-end space-x-2",children:[e.jsx("button",{className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded",onClick:()=>D(r),children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M7.6439 2.3999H4.7999C3.4743 2.3999 2.3999 3.4743 2.3999 4.7999V11.1999C2.3999 12.5255 3.4743 13.5999 4.7999 13.5999H11.1999C12.5255 13.5999 13.5999 12.5255 13.5999 11.1999V8.3639",stroke:"#737373",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M6.3999 9.60005L6.7999 7.20005L11.3655 2.64085C11.6783 2.32805 12.1847 2.32805 12.4967 2.64085L13.3655 3.50965C13.6783 3.82245 13.6783 4.32885 13.3655 4.64085L8.7999 9.20005L6.3999 9.60005Z",stroke:"#737373",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),e.jsx("button",{className:"p-1.5 text-red-400 hover:text-red-600 hover:bg-red-50 rounded",onClick:()=>V(r.uuid,r.name),children:e.jsx(ue,{size:16})})]})})]},r.uuid))})]}),e.jsx("div",{ref:$,className:`h-10 flex items-center justify-center ${!C&&l.hasMore?"":"hidden"}`,children:f&&l.hasMore&&e.jsx("div",{className:"text-sm text-gray-500",children:"Loading more..."})}),e.jsx("div",{className:"sticky bottom-0 z-10 px-4 border py-3 border-t border-gray-200 bg-gray-50 flex items-center",children:e.jsxs("div",{className:"text-sm text-gray-600 uppercase",children:["COUNT"," ",e.jsx("span",{className:"ml-4 font-medium",children:X.length})]})})]})}),e.jsx(be,{isOpen:p,onClose:()=>{S(!1),m(null),M(""),y("")},title:F?"Edit Sub-task":"Add Sub-task",size:"md",children:e.jsxs("div",{className:"space-y-4",children:[!F&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Select Task ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(Ne,{value:L,onChange:r=>y(r.target.value),children:[e.jsx("option",{value:"",children:"Select a task"}),(Array.isArray(t)?t:[]).map(r=>e.jsx("option",{value:r.uuid,children:r.name},r.uuid))]})]}),F&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Task"}),e.jsx(se,{value:c(F.task_uuid),disabled:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Sub-task Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}
16),e.jsx(se,{value:_,onChange:r=>M(r.target.value),placeholder:"Enter sub-task name"})]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4 border-t",children:[e.jsx(I,{variant:"secondary",onClick:()=>{S(!1),m(null),M(""),y("")},children:"Cancel"}),e.jsx(I,{variant:"primary",onClick:F?Z:Y,disabled:!_.trim()||!F&&!L,children:F?"Update":"Add"})]})]})})]}):e.jsx("div",{className:"h-full bg-white mx-0 my-0",children:e.jsx("div",{className:"h-full flex flex-col",children:e.jsx("div",{className:"overflow-auto flex-1 relative",children:e.jsx("table",{className:"w-full border border-gray-200 border-collapse",children:e.jsx(Ee,{columns:P,rows:8})})})})})},He={daily:"1",alternative:"2",weekly:"7",fortnightly:"15",monthly:"30",biMonthly:"30",quarterly:"30",halfYearly:"30",yearly:"30"},bs=["daily","alternative","weekly","fortnightly","monthly","biMonthly","quarterly","halfYearly","yearly"],js=({search:s=""})=>{const[a,o]=n.useState(He),[t,i]=n.useState(!0),[l,f]=n.useState(!1);re.useEffect(()=>{let g=!1;return(async()=>{try{i(!0);const b=await ls.get();if(g)return;const p={...He};for(const S of bs){const L=b.days[S];p[S]=L!=null?String(L):He[S]}o(p)}catch{g||k.error("Could not load frequency configuration")}finally{g||i(!1)}})(),()=>{g=!0}},[]);const u=[{key:"daily",label:"Daily"},{key:"alternative",label:"Alternate Day"},{key:"weekly",label:"Weekly"},{key:"fortnightly",label:"Fortnightly"},{key:"monthly",label:"Monthly"},{key:"biMonthly",label:"Bi-Monthly"},{key:"quarterly",label:"Quarterly"},{key:"halfYearly",label:"Half-Yearly"},{key:"yearly",label:"Yearly"}],j=n.useMemo(()=>{const g=s.trim().toLowerCase();return g?u.filter(b=>b.label.toLowerCase().includes(g)):u},[s]),T=async()=>{var b;const g={};for(const p of bs){const S=(b=a[p])==null?void 0:b.trim();if(S!==""){if(!/^\d+$/.test(S)){k.error(`Invalid number for ${p}`);return}g[p]=parseInt(S,10)}}try{f(!0),await ls.put(g),k.success("Frequency configuration saved",{duration:2e3})}catch{k.error("Could not save frequency configuration")}finally{f(!1)}};return e.jsx("div",{className:"h-full overflow-auto p-6",children:e.jsxs("div",{className:"max-w-3xl rounded-lg border border-gray-200 bg-white",children:[e.jsxs("div",{className:"border-b border-gray-200 px-5 py-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Frequency Configuration"}),e.jsx("p",{className:"mt-1 text-sm text-gray-600",children:"Set the number of days between auto-generated recurring task instances. Values are stored per company and used by the scheduler."})]}),e.jsx("div",{className:"px-5 py-4",children:t?e.jsx("p",{className:"text-sm text-gray-600",children:"Loading…"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 grid grid-cols-[1fr_180px] gap-3 border-b border-gray-100 pb-2 text-sm font-medium text-gray-700",children:[e.jsx("span",{children:"Frequency Type"}),e.jsx("span",{children:"Days (interval)"})]}),e.jsx("div",{className:"space-y-3",children:j.map(g=>e.jsxs("div",{className:"grid grid-cols-[1fr_180px] items-center gap-3",children:[e.jsx("label",{className:"text-sm font-medium text-gray-800",htmlFor:`frequency-config-${g.key}`,children:g.label}),e.jsx("input",{id:`frequency-config-${g.key}`,type:"number",min:0,placeholder:"e.g. 30",value:a[g.key]??"",onChange:b=>{const p=b.target.value;p!==""&&!/^\d+$/.test(p)||o(S=>
16({...S,[g.key]:p}))},className:"h-9 rounded-md border border-gray-300 px-3 text-sm text-gray-900 outline-none ring-0 transition focus:border-blue-500"})]},g.key))}),e.jsx("div",{className:"mt-6",children:e.jsx(I,{variant:"primary",size:"sm",disabled:l,onClick:()=>void T(),children:l?"Saving…":"Save Configuration"})})]})})]})})},Ot="You can change this under Configurations → Preferences → Display preferences.";function vs({notice:s,hint:a=Ot,children:o}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-gray-50",children:[e.jsx("aside",{className:"mx-4 mt-4 shrink-0 rounded-lg border border-[#E5E5E5] bg-white shadow-sm ring-1 ring-black/[0.04]",children:e.jsxs("div",{className:"flex gap-3 border-l-4 border-[#2B7FFF] px-4 py-3.5",children:[e.jsx("div",{className:"mt-0.5 shrink-0 text-[#2B7FFF]",children:e.jsx(Xs,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-[#737373]",children:"Notice"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-[#171717]",children:s}),e.jsx("p",{className:"mt-2 text-xs leading-snug text-gray-500",children:a})]})]})}),e.jsxs("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 overflow-auto opacity-[0.38] pointer-events-none select-none grayscale-[0.15]",children:o}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-20 bg-gradient-to-t from-gray-50 via-gray-50/80 to-transparent","aria-hidden":!0})]})]})}const Ve=({result:s,downloadFilename:a})=>e.jsxs("div",{className:"mt-4 rounded-lg border border-gray-200 bg-gray-50 p-4",children:[s.resultCsv&&e.jsxs("div",{className:"mb-3",children:[e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ye,{size:16}),onClick:()=>Vs(s.resultCsv,a),children:"Download Result CSV"}),e.jsxs("p",{className:"text-xs text-gray-600 mt-2",children:["Open this file, fix the ",e.jsx("strong",{children:"Query"})," column, then re-upload the same CSV. Rows marked ",e.jsx("strong",{children:"Imported"})," will be skipped automatically."]})]}),e.jsx("p",{className:"text-sm text-gray-700 mb-2",children:s.message}),e.jsxs("div",{className:"flex items-center flex-wrap gap-4 mb-2",children:[s.imported>0&&e.jsxs("div",{className:"flex items-center text-green-600",children:[e.jsx(et,{className:"h-4 w-4 mr-1"}),e.jsxs("span",{className:"text-sm",children:[s.imported," imported"]})]}),s.skipped>0&&e.jsx("div",{className:"flex items-center text-gray-600",children:e.jsxs("span",{className:"text-sm",children:[s.skipped," skipped"]})}),s.failed>0&&e.jsxs("div",{className:"flex items-center text-red-600",children:[e.jsx(st,{className:"h-4 w-4 mr-1"}),e.jsxs("span",{className:"text-sm",children:[s.failed," failed"]})]})]}),s.errors.length>0&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3 max-h-32 overflow-y-auto",children:[e.jsx("p",{className:"text-xs font-medium text-red-800 mb-1",children:"Errors:"}),e.jsx("ul",{className:"text-xs text-red-700 space-y-1",children:s.errors.map((o,t)=>e.jsxs("li",{children:["• ",o]},t))})]})]});function Ge({entityLabel:s,responseData:a,fullSuccessMessage:o,partialSuccessMessage:t,onImportSuccess:i,onFullSuccess:l,onSetResult:f}){const u=ks(a);if(u.isFullSuccess){k.success(o||`Successfully imported ${u.imported} ${s}!`,{duration:2e3}),i==null||i(),l();return}if(u.isPartialSuccess){k.success(t||u.message,{duration:2500}),i==null||i(),f(u);return}if(u.isAllFailed){k.error(u.resultCsv?"Import failed. Download the result CSV below, fix the Query column, and re-upload.":`Failed to import: ${u.failed} error(s)`,{duration:4e3}),f(u);return}k.error(`No ${s} were imported. Please check your CSV file.`,{duration:3e3}),f({...u,errors:u.errors.length>0?u.errors:["No data found in the CSV file or file format is incorrect."],failed:u.failed||1})}const Bt=({isOpen:s,onClose:a,onImportSuccess:o})=>{const[t,i]=n.useState(null),[l,f]=n.useState(!1),[u,j]=n.useState(0),[T,g]=n.useState(null),b=n.useRef(null),p=m=>{var h;const v=(h=m.target.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},S=m=>{var h;m.preventDefault();const v=(h=m.dataTransfer.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},L=m=>{m.preventDefault()},y=()=>{i(null),g(null),b.current&&(b.current.value="")},_=()=>{const v=["Client Name","Client Email","Phone Number","Address","GST Number"].join(",")+`
17`,h=new Blob([v],{type:"text/csv;charset=utf-8;"}),C=document.createElement("a"),R=URL.createObjectURL(h);C.setAttribute("href",R),C.setAttribute("download","sample_clients_import.csv"),C.style.visibility="hidden",document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(R),k.success("Sample CSV file downloaded",{duration:2e3})},M=async()=>{var m,v;if(!t){k.error("Please select a file to import",{duration:3e3});return}f(!0),j(0),g(null);try{const h=await Rs.importClients(t,C=>{j(C)});j(100),Ge({entityLabel:"client(s)",responseData:h.data,onImportSuccess:o,onFullSuccess:()=>{i(null),j(0),g(null),b.current&&(b.current.value=""),a()},onSetResult:g})}catch(h){console.error("Import error:",h);const C=((v=(m=h.response)==null?void 0:m.data)==null?void 0:v.message)||h.message||"Failed to import clients";k.error(C,{duration:3e3}),g({imported:0,failed:1,skipped:0,message:C,errors:[C],resultCsv:null,isFullSuccess:!1,isPartialSuccess:!1,isAllFailed:!0,isEmpty:!1})}finally{f(!1),j(0)}},F=()=>{i(null),g(null),b.current&&(b.current.value=""),a()};return e.jsxs(be,{isOpen:s,onClose:F,title:"Import Clients",children:[e.jsxs("div",{className:"px-6 py-4",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx(I,{variant:"secondary",size:"xs",icon:e.jsx(ye,{size:14}),onClick:_,disabled:l,children:"Download Sample CSV"})}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-colors ${l?"border-blue-300 bg-blue-50":t?"border-green-300 bg-green-50":"border-gray-300 hover:border-blue-400 hover:bg-blue-50"}`,onDrop:l?void 0:S,onDragOver:l?void 0:L,children:[l?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"animate-spin rounded-full h-16 w-16 border-4 border-blue-200 border-t-blue-600"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(we,{className:"h-6 w-6 text-blue-600 animate-pulse"})})]}),e.jsx("span",{className:"mt-3 text-sm font-semibold text-blue-700",children:"Uploading & Processing..."})]}),e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"flex justify-between text-xs text-gray-600 mb-1",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{className:"font-semibold text-blue-600",children:[u,"%"]})]}),e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-blue-600 h-2.5 rounded-full transition-all duration-300 ease-out",style:{width:`${u}%`}})})]}),t&&e.jsxs("p",{className:"text-xs text-gray-500 text-center",children:[t.name," (",(t.size/1024).toFixed(2)," KB)"]})]}):t?e.jsxs("div",{className:"flex items-center justify-center space-x-3",children:[e.jsx(we,{className:"h-8 w-8 text-green-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(t.size/1024).toFixed(2)," KB"]}
17)]}),e.jsx("button",{type:"button",onClick:y,className:"p-1 hover:bg-gray-200 rounded-full",children:e.jsx($e,{className:"h-5 w-5 text-gray-500"})})]}):e.jsxs("div",{children:[e.jsx(ce,{className:"h-10 w-10 text-gray-400 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:"Drag and drop your CSV file here, or"}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=b.current)==null?void 0:m.click()},className:"text-blue-600 hover:text-blue-700 text-sm font-medium",children:"browse to upload"})]}),e.jsx("input",{ref:b,type:"file",accept:".csv",onChange:p,className:"hidden",disabled:l})]}),T&&e.jsx(Ve,{result:T,downloadFilename:"clients_import_result.csv"})]}),e.jsx("div",{className:"mt-6 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"flex justify-end space-x-3 px-6",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:F,disabled:l,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"button",onClick:M,disabled:!t||l,loading:l,icon:e.jsx(ce,{size:16}),children:"Import"})]})})]})},$t=({isOpen:s,onClose:a,onImportSuccess:o})=>{const[t,i]=n.useState(null),[l,f]=n.useState(!1),[u,j]=n.useState(0),[T,g]=n.useState(null),b=n.useRef(null),p=m=>{var h;const v=(h=m.target.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},S=m=>{var h;m.preventDefault();const v=(h=m.dataTransfer.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},L=m=>{m.preventDefault()},y=()=>{i(null),g(null),b.current&&(b.current.value="")},_=()=>{const m=`Task Name,Sub Task
18task name 1,subtask a
19task name 1,subtask b
20task name 1,subtask c
21task name 2,subtask x
22task name 2,
23`,v=new Blob([m],{type:"text/csv;charset=utf-8;"}),h=document.createElement("a"),C=URL.createObjectURL(v);h.setAttribute("href",C),h.setAttribute("download","sample_tasks_template_import.csv"),h.style.visibility="hidden",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(C),k.success("Sample CSV file downloaded",{duration:2e3})},M=async()=>{if(!t){k.error("Please select a file to import",{duration:3e3});return}f(!0),j(0),g(null);try{const m=setInterval(()=>{j(h=>h>=90?(clearInterval(m),90):h+10)},200),v=await _s.importTaskTemplates(t);clearInterval(m),j(100),Ge({entityLabel:"task template row(s)",responseData:v,onImportSuccess:o,onFullSuccess:()=>{i(null),j(0),g(null),b.current&&(b.current.value=""),a()},onSetResult:g})}catch(m){console.error("Import tasks error:",m);const v=m.message||"Failed to import tasks";k.error(v,{duration:3e3}),g({imported:0,failed:1,skipped:0,message:v,errors:[v],resultCsv:null,isFullSuccess:!1,isPartialSuccess:!1,isAllFailed:!0,isEmpty:!1})}finally{f(!1),j(0)}},F=()=>{i(null),g(null),b.current&&(b.current.value=""),a()};return e.jsxs(be,{isOpen:s,onClose:F,title:"Import Tasks",children:[e.jsxs("div",{className:"px-6 py-4",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx(I,{variant:"secondary",size:"xs",icon:e.jsx(ye,{size:14}),onClick:_,disabled:l,children:"Download Sample CSV"})}),e.jsxs("div",{className:`rounded-lg border-2 border-dashed p-6 text-center transition-colors ${l?"border-blue-300 bg-blue-50":t?"border-green-300 bg-green-50":"border-gray-300 hover:border-blue-400 hover:bg-blue-50"}`,onDrop:l?void 0:S,onDragOver:l?void 0:L,children:[l?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"h-16 w-16 animate-spin rounded-full border-4 border-blue-200 border-t-blue-600"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(we,{className:"h-6 w-6 animate-pulse text-blue-600"})})]}),e.jsx("span",{className:"mt-3 text-sm font-semibold text-blue-700",children:"Uploading & Processing..."})]}),e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"mb-1 flex justify-between text-xs text-gray-600",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{className:"font-semibold text-blue-600",children:[u,"%"]})]}),e.jsx("div",{className:"h-2.5 w-full overflow-hidden rounded-full bg-gray-200",children:e.jsx("div",{className:"h-2.5 rounded-full bg-gradient-to-r from-blue-500 to-blue-600 transition-all duration-300 ease-out",style:{width:`${u}%`}})})]}),t&&e.jsxs("p",{className:"text-center text-xs text-gray-500",children:[t.name," (",(t.size/1024).toFixed(2)," KB)"]})]}):t?e.jsxs("div",{className:"flex items-center justify-center space-x-3",children:[e.jsx(we,{className:"h-8 w-8 text-green-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(t.size/1024).toFixed(2)," KB"]}
23)]}),e.jsx("button",{type:"button",onClick:y,className:"rounded-full p-1 hover:bg-gray-200",children:e.jsx($e,{className:"h-5 w-5 text-gray-500"})})]}):e.jsxs("div",{children:[e.jsx(ce,{className:"mx-auto mb-2 h-10 w-10 text-gray-400"}),e.jsx("p",{className:"mb-2 text-sm text-gray-600",children:"Drag and drop your CSV file here, or"}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=b.current)==null?void 0:m.click()},className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:"browse to upload"})]}),e.jsx("input",{ref:b,type:"file",accept:".csv",onChange:p,className:"hidden",disabled:l})]}),T&&e.jsx(Ve,{result:T,downloadFilename:"task_templates_import_result.csv"})]}),e.jsx("div",{className:"mt-6 border-t border-gray-200 pt-4",children:e.jsxs("div",{className:"flex justify-end space-x-3 px-6",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:F,disabled:l,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"button",onClick:M,disabled:!t||l,loading:l,icon:e.jsx(ce,{size:16}),children:"Import"})]})})]})},Yt=({isOpen:s,onClose:a,onImportSuccess:o})=>{const[t,i]=n.useState(null),[l,f]=n.useState(!1),[u,j]=n.useState(0),[T,g]=n.useState(null),b=n.useRef(null),p=m=>{var h;const v=(h=m.target.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},S=m=>{var h;m.preventDefault();const v=(h=m.dataTransfer.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},L=m=>{m.preventDefault()},y=()=>{i(null),g(null),b.current&&(b.current.value="")},_=()=>{const m=`Task Name,Sub Task Name
24Accounting,GST Filing
25Accounting,TDS Return
26Audit,Internal Audit
27`,v=new Blob([m],{type:"text/csv;charset=utf-8;"}),h=document.createElement("a"),C=URL.createObjectURL(v);h.setAttribute("href",C),h.setAttribute("download","sample_sub_tasks_template_import.csv"),h.style.visibility="hidden",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(C),k.success("Sample CSV file downloaded",{duration:2e3})},M=async()=>{var m,v;if(!t){k.error("Please select a file to import",{duration:3e3});return}f(!0),j(0),g(null);try{const h=setInterval(()=>{j(R=>R>=90?(clearInterval(h),90):R+10)},200),C=await _s.importSubTasks(t);clearInterval(h),j(100),Ge({entityLabel:"sub-task(s)",responseData:C,onImportSuccess:o,onFullSuccess:()=>{i(null),j(0),g(null),b.current&&(b.current.value=""),a()},onSetResult:g})}catch(h){console.error("Import sub-tasks error:",h);const C=((v=(m=h.response)==null?void 0:m.data)==null?void 0:v.message)||h.message||"Failed to import sub-tasks";k.error(C,{duration:3e3}),g({imported:0,failed:1,skipped:0,message:C,errors:[C],resultCsv:null,isFullSuccess:!1,isPartialSuccess:!1,isAllFailed:!0,isEmpty:!1})}finally{f(!1),j(0)}},F=()=>{i(null),g(null),b.current&&(b.current.value=""),a()};return e.jsxs(be,{isOpen:s,onClose:F,title:"Import Sub-tasks",children:[e.jsxs("div",{className:"px-6 py-4",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx(I,{variant:"secondary",size:"xs",icon:e.jsx(ye,{size:14}),onClick:_,disabled:l,children:"Download Sample CSV"})}),e.jsxs("div",{className:`rounded-lg border-2 border-dashed p-6 text-center transition-colors ${l?"border-blue-300 bg-blue-50":t?"border-green-300 bg-green-50":"border-gray-300 hover:border-blue-400 hover:bg-blue-50"}`,onDrop:l?void 0:S,onDragOver:l?void 0:L,children:[l?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"h-16 w-16 animate-spin rounded-full border-4 border-blue-200 border-t-blue-600"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(we,{className:"h-6 w-6 animate-pulse text-blue-600"})})]}),e.jsx("span",{className:"mt-3 text-sm font-semibold text-blue-700",children:"Uploading & Processing..."})]}),e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"mb-1 flex justify-between text-xs text-gray-600",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{className:"font-semibold text-blue-600",children:[u,"%"]})]}),e.jsx("div",{className:"h-2.5 w-full overflow-hidden rounded-full bg-gray-200",children:e.jsx("div",{className:"h-2.5 rounded-full bg-gradient-to-r from-blue-500 to-blue-600 transition-all duration-300 ease-out",style:{width:`${u}%`}})})]}),t&&e.jsxs("p",{className:"text-center text-xs text-gray-500",children:[t.name," (",(t.size/1024).toFixed(2)," KB)"]})]}):t?e.jsxs("div",{className:"flex items-center justify-center space-x-3",children:[e.jsx(we,{className:"h-8 w-8 text-green-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(t.size/1024).toFixed(2)," KB"]}
27)]}),e.jsx("button",{type:"button",onClick:y,className:"rounded-full p-1 hover:bg-gray-200",children:e.jsx($e,{className:"h-5 w-5 text-gray-500"})})]}):e.jsxs("div",{children:[e.jsx(ce,{className:"mx-auto mb-2 h-10 w-10 text-gray-400"}),e.jsx("p",{className:"mb-2 text-sm text-gray-600",children:"Drag and drop your CSV file here, or"}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=b.current)==null?void 0:m.click()},className:"text-sm font-medium text-blue-600 hover:text-blue-700",children:"browse to upload"})]}),e.jsx("input",{ref:b,type:"file",accept:".csv",onChange:p,className:"hidden",disabled:l})]}),T&&e.jsx(Ve,{result:T,downloadFilename:"sub_tasks_import_result.csv"})]}),e.jsx("div",{className:"mt-6 border-t border-gray-200 pt-4",children:e.jsxs("div",{className:"flex justify-end space-x-3 px-6",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:F,disabled:l,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"button",onClick:M,disabled:!t||l,loading:l,icon:e.jsx(ce,{size:16}),children:"Import"})]})})]})},Qt=({isOpen:s,onClose:a,onImportSuccess:o})=>{const[t,i]=n.useState(null),[l,f]=n.useState(!1),[u,j]=n.useState(0),[T,g]=n.useState(null),b=n.useRef(null),p=m=>{var h;const v=(h=m.target.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},S=m=>{var h;m.preventDefault();const v=(h=m.dataTransfer.files)==null?void 0:h[0];if(v){if(!v.name.toLowerCase().endsWith(".csv")){k.error("Please select a CSV file",{duration:3e3});return}i(v),g(null)}},L=m=>{m.preventDefault()},y=()=>{i(null),g(null),b.current&&(b.current.value="")},_=()=>{const v=["Employee Name","Employee Email"].join(",")+`
28`,h=new Blob([v],{type:"text/csv;charset=utf-8;"}),C=document.createElement("a"),R=URL.createObjectURL(h);C.setAttribute("href",R),C.setAttribute("download","sample_users_import.csv"),C.style.visibility="hidden",document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(R),k.success("Sample CSV file downloaded",{duration:2e3})},M=async()=>{var m,v;if(!t){k.error("Please select a file to import",{duration:3e3});return}f(!0),j(0),g(null);try{const h=await Gs.importUsers(t,R=>{j(R)});j(100);const C=ks(h.data);Ge({entityLabel:"user(s)",responseData:h.data,fullSuccessMessage:`Imported ${C.imported} user(s). Verification + welcome emails sent.`,partialSuccessMessage:`${C.message}. Emails sent for imported users.`,onImportSuccess:o,onFullSuccess:()=>{i(null),j(0),g(null),b.current&&(b.current.value=""),a()},onSetResult:g})}catch(h){console.error("Import users error:",h);const C=((v=(m=h.response)==null?void 0:m.data)==null?void 0:v.message)||h.message||"Failed to import users";k.error(C,{duration:3e3}),g({imported:0,failed:1,skipped:0,message:C,errors:[C],resultCsv:null,isFullSuccess:!1,isPartialSuccess:!1,isAllFailed:!0,isEmpty:!1})}finally{f(!1),j(0)}},F=()=>{i(null),g(null),j(0),b.current&&(b.current.value=""),a()};return e.jsxs(be,{isOpen:s,onClose:F,title:"Import Users",children:[e.jsxs("div",{className:"px-6 py-4",children:[e.jsxs("div",{className:"mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-medium text-blue-800",children:"CSV Column Headers (must match exactly):"}),e.jsx(I,{variant:"secondary",size:"xs",icon:e.jsx(ye,{size:14}),onClick:_,disabled:l,children:"Download Sample CSV"})]}),e.jsxs("ul",{className:"text-xs text-blue-700 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Employee Name"}),e.jsx("li",{children:"Employee Email"})]})]}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-colors ${l?"border-blue-300 bg-blue-50":t?"border-green-300 bg-green-50":"border-gray-300 hover:border-blue-400 hover:bg-blue-50"}`,onDrop:l?void 0:S,onDragOver:l?void 0:L,children:[l?e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"animate-spin rounded-full h-16 w-16 border-4 border-blue-200 border-t-blue-600"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(we,{className:"h-6 w-6 text-blue-600 animate-pulse"})})]}),e.jsx("span",{className:"mt-3 text-sm font-semibold text-blue-700",children:"Uploading & Processing..."})]}),e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"flex justify-between text-xs text-gray-600 mb-1",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{className:"font-semibold text-blue-600",children:[u,"%"]})]}),e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-blue-600 h-2.5 rounded-full transition-all duration-300 ease-out",style:{width:`${u}%`}})})]}),t&&e.jsxs("p",{className:"text-xs text-gray-500 text-center",children:[t.name," (",(t.size/1024).toFixed(2)," KB)"]})]}):t?e.jsxs("div",{className:"flex items-center justify-center space-x-3",children:[e.jsx(we,{className:"h-8 w-8 text-green-600"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[(t.size/1024).toFixed(2)," KB"]}
28)]}),e.jsx("button",{type:"button",onClick:y,className:"p-1 hover:bg-gray-200 rounded-full",children:e.jsx($e,{className:"h-5 w-5 text-gray-500"})})]}):e.jsxs("div",{children:[e.jsx(ce,{className:"h-10 w-10 text-gray-400 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:"Drag and drop your CSV file here, or"}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=b.current)==null?void 0:m.click()},className:"text-blue-600 hover:text-blue-700 text-sm font-medium",children:"browse to upload"})]}),e.jsx("input",{ref:b,type:"file",accept:".csv",onChange:p,className:"hidden",disabled:l})]}),T&&e.jsx(Ve,{result:T,downloadFilename:"users_import_result.csv"})]}),e.jsx("div",{className:"mt-6 pt-4 border-t border-gray-200",children:e.jsxs("div",{className:"flex justify-end space-x-3 px-6",children:[e.jsx(I,{variant:"secondary",type:"button",onClick:F,disabled:l,children:"Cancel"}),e.jsx(I,{variant:"primary",type:"button",onClick:M,disabled:!t||l,loading:l,icon:e.jsx(ce,{size:16}),children:"Import"})]})})]})},ra=()=>{const s=Ns(),o=Ce().pathname.split("/").pop(),t=oe(N=>{var z;return((z=N.preferences)==null?void 0:z.showQuotationTaskWise)??!1}),i=oe(N=>{var z;return((z=N.preferences)==null?void 0:z.showFrequencyModule)??Ts.ENABLE_FREQUENCY_MODULE}),l=oe(N=>N.productFeatureModules),f=Oe(l,"frequency"),u=Oe(l,"quotation"),j=tt(l,"quotation"),T=!j&&(u||t),[g,b]=n.useState({dateFormat:"",defaultTimeUnit:"",showQuotationTaskWise:t,showFrequencyModule:i}),[p,S]=n.useState({dateFormat:"",defaultTimeUnit:"",showQuotationTaskWise:t,showFrequencyModule:i}),[L,y]=n.useState(!1),[_,M]=n.useState(!1),[F,m]=n.useState(!1),[v,h]=n.useState(!1),[C,R]=n.useState(!1),[J,H]=n.useState(!1),[B,W]=n.useState(!1),[X,P]=n.useState(!1),[G,$]=n.useState(!1),[E,U]=n.useState(!1),[Y,Z]=n.useState(""),[V,c]=n.useState({}),D=n.useMemo(()=>{const N=[{id:"clients",label:"Clients"},{id:"tasks",label:"Tasks"},{id:"sub-tasks",label:"Sub-tasks"},{id:"priority",label:"Priority"},{id:"status",label:"Status"},{id:"users",label:"Users"}];return T&&N.push({id:"quotation-setup",label:"Quotation Setup"}),N.push({id:"frequency",label:"Frequency",disabled:!f||!i},{id:"preferences",label:"Preferences"}),N},[f,T,i]),{fetchClients:q}=ws(),{fetchPriorities:r,fetchStatuses:x,fetchTaskTemplates:d,fetchSubTaskTemplates:w,fetchCompanyPreferences:A,fetchConfigs:Q}=oe(),{fetchUsers:O}=Te();n.useEffect(()=>{Q()},[Q]),n.useEffect(()=>{o==="preferences"&&(b(N=>({...N,showQuotationTaskWise:t,showFrequencyModule:i})),S(N=>({...N,showQuotationTaskWise:t,showFrequencyModule:i})))},[o,t,i]);const K=n.useCallback(()=>{},[]);n.useEffect(()=>(os({setActiveTab:N=>{s(`/configurations/${N}`)},clearFilters:K}),()=>{os({})}),[s,K]);const le=n.useCallback(async N=>{try{try{te.cancelAllRequests()}catch{}try{te.clearCache()}catch{}N&&await N()}catch{}},[]),de=n.useCallback((N,z)=>{c(ee=>({...ee,clients:{selectedCount:N,onBulkDelete:z}}))},[]),je=n.useCallback((N,z)=>{c(ee=>({...ee,tasks:{selectedCount:N,onBulkDelete:z}}))},[]),Ae=n.useCallback((N,z)=>{c(ee=>({...ee,"sub-tasks":{selectedCount:N,onBulkDelete:z}}))},[]),Fe=n.useCallback((N,z)=>{c(ee=>({...ee,priority:{selectedCount:N,onBulkDelete:z}}))},[]),Re=n.useCallback((N,z)=>{c(ee=>({...ee,status:{selectedCount:N,onBulkDelete:z}}))},[]),fe=n.useCallback(async N=>{switch(N||o){case"clients":await le(()=>q({page:1,limit:1e3,append:!1,isActive:!0}));break;case"tasks":await le(()=>d({page:1,limit:50}));break;case"sub-tasks":await le(()=>w({page:1,limit:50}));break;case"priority":await le(r);break;case"status":await le(x);break;case"users":await le(O);break;case"preferences":await le(async()=>{await A()});break;case"frequency":break;case"quotation-setup":break;default:await le(()=>q({page:1,limit:1e3,append:!1,isActive:!0}));break}},[o,q,r,x,d,w,O,A,le]);n.useEffect(()=>{fe(o)},[o]),n.useEffect(()=>{Z("")},[o]),n.useEffect(()=>{(o==="configurations"||o===""||typeof o>"u")&&s("/configurations/clients",{replace:!0})},[o,s]),n.useEffect(()=>{const N=z=>{var ee;try{const ie=z,ge=(ee=ie==null?void 0:ie.detail)==null?void 0:ee.tab;fe(ge)}catch{fe(void 0)}};return window.addEventListener("app:refetch-config",N),window.addEventListener("app:refetch",N),()=>{window.removeEventListener("app:refetch-config",N),window.removeEventListener("app:refetch",N)}},[fe]),n.useEffect(()=>{const N=z=>{var ie,ge,me;
28(me=(ge=(ie=z.detail)==null?void 0:ie.path)==null?void 0:ge.startsWith)!=null&&me.call(ge,"/configurations")&&fe(o)};return window.addEventListener("app:refresh-page",N),()=>window.removeEventListener("app:refresh-page",N)},[fe,o]);const Se=(N,z)=>{const ee=window.URL.createObjectURL(N),ie=document.createElement("a");ie.href=ee,ie.download=z,document.body.appendChild(ie),ie.click(),ie.remove(),window.URL.revokeObjectURL(ee)},ke=async()=>{const N=o;try{switch(N){case"clients":{const z=await te.get("/clients/export",{responseType:"blob",cache:!1});Se(z.data,"clients.csv");break}case"tasks":{const z=await te.get("/tasks/export",{responseType:"blob",cache:!1});Se(z.data,"tasks.csv");break}case"sub-tasks":{const z=await te.get("/sub-tasks/export",{responseType:"blob",cache:!1});Se(z.data,"sub-tasks.csv");break}default:{k.error("Export is only available for clients, tasks, and sub-tasks.",{duration:3e3});break}}}catch(z){console.error("Export failed",z),k.error("Failed to export data",{duration:3e3})}},Ue=()=>{S(g)},he=n.useCallback(()=>{const N=oe.getState().preferences,z={dateFormat:N.dateFormat||"",defaultTimeUnit:N.timeUnit||"",showQuotationTaskWise:N.showQuotationTaskWise??!1,showFrequencyModule:N.showFrequencyModule??!1};b(ee=>({...ee,...z})),S(ee=>({...ee,...z}))},[]),Ie=async()=>{var ie,ge;if(!u&&p.showQuotationTaskWise){k.error(ze(l,"quotation")||"The Quotation module is disabled for this product by the platform administrator. It cannot be enabled until it is turned on for your product.",{duration:7e3});try{await Q(),he()}catch{he()}return}if(!f&&p.showFrequencyModule){k.error(ze(l,"frequency")||"The Frequency module is disabled for this product by the platform administrator. It cannot be enabled until it is turned on for your product.",{duration:7e3});try{await Q(),he()}catch{he()}return}const N=oe.getState().configs.find(me=>me.config_type==="general_preferences"),z=((ie=N==null?void 0:N.config_data)==null?void 0:ie.display_preferences)??{},ee={display_preferences:{...z,date_format:p.dateFormat,default_time_unit:p.defaultTimeUnit?p.defaultTimeUnit.toLowerCase():z.default_time_unit,quotation_module_enabled:!!p.showQuotationTaskWise,frequency_module_enabled:!!p.showFrequencyModule}};try{await Bs(ee);try{typeof window<"u"&&p.dateFormat&&window.localStorage.setItem("dateFormat",p.dateFormat)}catch{}await Q(),b(p),k.success("Preferences updated successfully!",{duration:2e3})}catch(me){if(console.error("Failed to update preferences:",me),Ke(me)){he();return}if(((ge=me==null?void 0:me.response)==null?void 0:ge.status)!==403){const Ys=Ms(me);k.error(Ys||"Preferences could not be saved. Please try again or contact support.",{duration:7e3})}try{await Q(),he()}catch{he()}}},Pe=()=>{const N=V[o||""],z=N&&N.selectedCount>1;switch(o){case"clients":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ce,{size:16}),onClick:()=>m(!0),children:"Import"}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ye,{size:16}),onClick:ke,children:"Export"}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>M(!0),children:"Add Client"})]});case"tasks":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ce,{size:16}),onClick:()=>R(!0),children:"Import"}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ye,{size:16}),onClick:ke,children:"Export"}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>h(!0),children:"Add Task"})]});case"sub-tasks":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ce,{size:16}),onClick:()=>U(!0),children:"Import"}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ye,{size:16}),onClick:ke,children:"Export"}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>$(!0),children:"Add Sub-task"})]});case"priority":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>P(!0),children:"Add Priority"})]});case"status":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>y(!0),children:"Add Status"})]});case"users":return e.jsxs(e.Fragment,{children:[z&&e.jsxs(I,{variant:"danger",size:"sm",icon:e.jsx(ue,{size:16}),onClick:N.onBulkDelete,children:["Bulk Delete (",N.selectedCount,")"]}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ce,{size:16}),onClick:()=>W(!0),children:"Import"}),e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ye,{size:16}),onClick:ke,children:"Export"}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>H(!0),children:"Add User"})]});case"preferences":return e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"secondary",size:"sm",onClick:Ue,children:"Reset Preferences"}),e.jsx(I,{variant:"primary",size:"sm",onClick:Ie,children:"Save Preferences"})]});case"frequency":return null;case"quotation-setup":return null;default:return e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"secondary",size:"sm",icon:e.jsx(ce,{size:16}),onClick:()=>m(!0),children:"Import"}),e.jsx(I,{variant:"primary",size:"sm",icon:e.jsx(ve,{size:16}),onClick:()=>M(!0),children:"Add Client"})]})}};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsx("div",{className:"bg-white border-b border-gray-300",children:e.jsxs("div",{className:"px-6 flex items-center justify-between",children:[e.jsx("div",{className:"flex overflow-x-auto shrink min-w-0",children:D.map(N=>e.jsx("button",{type:"button",onClick:()=>{N.disabled||s(`/configurations/${N.id}`)},className:`
29                  px-4 py-3 text-sm font-medium border-b-2 transition-colors whitespace-nowrap
30                  ${o===N.id?"text-blue-600 border-blue-600":"text-gray-600 border-transparent hover:text-gray-800"}
31                  ${N.disabled?"opacity-55 cursor-not-allowed":""}
32                `,children:N.label},N.id))}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(at,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",value:Y,onChange:N=>Z(N.target.value),placeholder:"Search...",className:"h-7 pl-7 pr-3 text-[12px] border border-[#E5E5E5] rounded-md focus:outline-none focus:ring-1 focus:ring-[#2B7FFF] w-48"})]}),Pe()]})]})}),e.jsx("div",{className:"flex-1 bg-gray-50 overflow-hidden",children:e.jsxs(Qs,{children:[e.jsx(pe,{path:"clients",element:e.jsx(is,{search:Y,onBulkDeleteUpdate:de})}),e.jsx(pe,{path:"tasks",element:e.jsx(it,{search:Y,onBulkDeleteUpdate:je})}),e.jsx(pe,{path:"sub-tasks",element:e.jsx(qt,{search:Y,onBulkDeleteUpdate:Ae})}),e.jsx(pe,{path:"priority",element:e.jsx(pt,{search:Y,onBulkDeleteUpdate:Fe})}),e.jsx(pe,{path:"status",element:e.jsx(Lt,{search:Y,onBulkDeleteUpdate:Re})}),e.jsx(pe,{path:"users",element:e.jsx(ht,{search:Y})}),e.jsx(pe,{path:"frequency",element:f?e.jsx(js,{search:Y}):e.jsx(vs,{notice:ze(l,"frequency")||"This module is not available for your product.",hint:"Your platform administrator controls this for your product. When it is enabled for the product, you can turn it on for your organization under Display preferences.",children:e.jsx(js,{search:Y})})}),e.jsx(pe,{path:"quotation-setup",element:j?e.jsx(vs,{notice:ze(l,"quotation")||"This module is not available for your product.",hint:"Your platform administrator controls this for your product. When it is enabled for the product, you can configure quotation settings here.",children:e.jsx(ys,{})}):e.jsx(ys,{})}),e.jsx(pe,{path:"preferences",element:e.jsx(At,{preferences:p,setPreferences:S,setInitalPreferences:b})}),e.jsx(pe,{path:"*",element:e.jsx(is,{search:Y})})]})}),e.jsx(Ws,{isOpen:L,onClose:()=>y(!1),onStatusCreated:async N=>{y(!1),window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"status"}}))}}),e.jsx(Cs,{isOpen:_,onClose:()=>M(!1),onClientCreated:async()=>{M(!1),window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"clients"}}))}}),e.jsx(Bt,{isOpen:F,onClose:()=>m(!1),onImportSuccess:()=>{window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"clients"}}))}}),e.jsx(Hs,{isOpen:v,onClose:()=>h(!1)}),e.jsx($t,{isOpen:C,onClose:()=>R(!1),onImportSuccess:()=>window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"tasks"}}))}),e.jsx(Ks,{isOpen:G,onClose:()=>$(!1)}),e.jsx(Yt,{isOpen:E,onClose:()=>U(!1),onImportSuccess:()=>window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"sub-tasks"}}))}),e.jsx(Ss,{isOpen:X,onClose:()=>P(!1)}),e.jsx(Us,{isOpen:J,onClose:()=>H(!1),onUserCreated:async()=>{H(!1),window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"users"}}))}}),e.jsx(Qt,{isOpen:B,onClose:()=>W(!1),onImportSuccess:()=>{window.dispatchEvent(new CustomEvent("app:refetch-config",{detail:{tab:"users"}}))}})]})};export{ra as ConfigPage,ra as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.