1import{ak as ee,u as te,r as l,a4 as ae,j as e,q as _,F as L,L as se,t as f,al as ie,ac as ne,z as j,B as le,w as C,I as w,p as x}from"./index-CfXbMZ_V.js";import{D as re,a as oe,b as ce,c as de,d as me}from"./dialog-D3H816yE.js";import{S as xe}from"./StatusBadge-C2JqdlP4.js";import{O as ue,W as pe}from"./workflowBoard-DyyHEBsQ.js";import{F as ge}from"./FinleyCopilotDock-DhThWcBO.js";import{C as he}from"./chevron-left-BFeklwt6.js";import{A as fe}from"./archive-restore-C_Z0fNFm.js";import{U as je}from"./user-Bu76TeJk.js";import{D as $}from"./dollar-sign-DSCUPVwl.js";import"./info-CA90EpkY.js";import"./shield-alert-5vZM3RqD.js";import"./calendar-range-_it7bbsU.js";import"./trending-down-_wkW26nB.js";import"./zap-BSTqYc_A.js";function b(o){if(!o)return"â";const r=new Date(o);return isNaN(r)?"â":r.toLocaleDateString("en-AU",{day:"numeric",month:"short",year:"numeric"})}function ve(o){const r=new Date(o.last_activity_date||o.updated_date||o.created_date||0);return r.getTime()?Math.floor((Date.now()-r.getTime())/864e5):0}function Ie(){const{jobId:o}=ee(),r=te(),[a,u]=l.useState(null),[p,T]=l.useState(null),[U,S]=l.useState(!0),[B,F]=l.useState(!1),[R,v]=l.useState(!1),[D,z]=l.useState(""),[g,h]=l.useState(!1),[y,A]=l.useState(""),[N,J]=l.useState(""),[O,k]=l.useState(!1),[q,E]=l.useState(!1),[I,P]=l.useState(!1),{toast:i}=ae(),M=t=>{if(t==="request_documents"||t==="request_signature"||t==="generate_tax_summary"||t==="compare_fy")if(p){const n=t==="request_signature"?"signatures":t==="generate_tax_summary"||t==="compare_fy"?"summary":null;r(`/staff/clients/${p.id}${n?`?tab=${n}`:""}`)}else i({title:"Open the client to action this"});else t!=="open_job"&&t!=="none"&&i({title:"Finley suggestion noted"})},W=async()=>{var t,n;S(!0);try{const[s,d]=await Promise.all([x.functions.invoke("manageJobs",{action:"get",job_id:o}),x.auth.me().catch(()=>null)]),c=((t=s==null?void 0:s.data)==null?void 0:t.job)||null;u(c),T(((n=s==null?void 0:s.data)==null?void 0:n.client)||null),E((d==null?void 0:d.role)==="admin"||(d==null?void 0:d.role)==="super_admin"),A((c==null?void 0:c.amount_invoiced)!=null?String(c.amount_invoiced):""),J((c==null?void 0:c.amount_paid)!=null?String(c.amount_paid):"")}catch(s){i({title:"Could not load job",description:s.message,variant:"destructive"})}finally{S(!1)}},Y=async()=>{k(!0);try{const t={amount_invoiced:Number(y)||0,amount_paid:Number(N)||0};await x.entities.Job.update(a.id,t),u({...a,...t}),i({title:"Financials saved"})}catch(t){i({title:"Could not save",description:t.message,variant:"destructive"})}finally{k(!1)}};l.useEffect(()=>{W()},[o]);const G=t=>{const n=/FY(\d{4})/i.exec(t||"");return n?`FY${parseInt(n[1],10)+1}`:"FY2027"},H=async t=>{if(!a||t===a.status)return;const n=a,s=new Date().toISOString(),d={status:t,last_activity_date:s};t==="Completed"&&(d.completed_at=s),t==="Lodged"&&(d.lodged_at=s),u({...a,...d}),F(!0);try{await x.functions.invoke("manageJobs",{action:"updateStatus",job_id:a.id,status:t}),i({title:`Moved to ${t}`})}catch(c){u(n),i({title:"Could not update status",description:c.message,variant:"destructive"})}finally{F(!1)}},K=()=>{z(G(a.financial_year)),v(!0)},Q=async()=>{var t,n;h(!0);try{const s=await x.functions.invoke("manageJobs",{action:"duplicate",job_id:a.id,financial_year:D});i({title:"Job duplicated"}),v(!1),(n=(t=s==null?void 0:s.data)==null?void 0:t.job)!=null&&n.id&&r(`/staff/jobs/${s.data.job.id}`)}catch(s){i({title:"Could not duplicate",description:s.message,variant:"destructive"})}finally{h(!1)}},V=async()=>{h(!0);try{await x.functions.invoke("manageJobs",{action:"archive",job_ids:[a.id]}),u({...a,archived:!0}),i({title:"Job archived"})}catch(t){i({title:"Failed",description:t.message,variant:"destructive"})}finally{h(!1)}},X=async()=>{h(!0);try{await x.functions.invoke("manageJobs",{action:"restore",job_id:a.id}),u({...a,archived:!1}),i({title:"Job restored"})}catch(t){i({title:"Failed",description:t.message,variant:"destructive"})}finally{h(!1)}};if(U)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(_,{className:"w-7 h-7 text-gray-400 animate-spin"})});if(!a)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 px-6 text-center",children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Job not found"}),e.jsx("button",{onClick:()=>r("/staff/workflow"),className:"mt-6 px-5 py-2.5 bg-gray-900 text-white rounded-xl text-sm font-medium",children:"Back to board"})]});const Z=ve(a);return e.jsxs("div",{className:`space-y-4 pb-24 transition-all ${I?"lg:pr-[420px]":""}`,children:[e.jsxs("button",{onClick:()=>r(-1),className:"flex items-center gap-1 text-sm text-gray-500 hover:text-gray-800",children:[e.jsx(he,{size:18})," Back"]}),e.jsxs("div",{className:"bg-gradient-to-r from-slate-800 to-slate-700 rounded-2xl p-5 text-white",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-300 text-xs",children:[e.jsx(L,{size:13})," Engagement / Job"]}),e.jsx("h1",{className:"text-xl font-bold mt-1",children:a.title}),p&&e.jsxs(se,{to:`/staff/clients/${p.id}`,className:"text-slate-200 text-sm hover:text-white hover:underline",children:["Client: ",p.full_name]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[e.jsx(xe,{status:a.status,small:!0}),a.review_required&&e.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-amber-500/20 text-amber-200 border border-amber-400/30",children:"Review type"}),a.archived&&e.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded-full bg-slate-500/20 text-slate-200 border border-slate-400/30",children:"Archived"}),e.jsxs("span",{className:"text-[11px] text-slate-300",children:[Z," day(s) in current stage"]})]})]}),e.jsxs("div",{className:"bg-white border border-gray-100 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Outstanding action"}),e.jsx("p",{className:"text-sm font-semibold text-gray-900 mt-0.5",children:ue[a.status]||"â"})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("select",{value:a.status,onChange:t=>H(t.target.value),disabled:B||a.archived,className:"h-9 text-sm border border-gray-200 rounded-md bg-white px-2 text-gray-800 disabled:opacity-50",children:pe.map(t=>e.jsx("option",{value:t,children:t},t))})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(f,{variant:"outline",size:"sm",onClick:K,disabled:g,className:"h-8 text-xs",children:[e.jsx(ie,{size:14})," Duplicate to new period"]}),a.archived?e.jsxs(f,{variant:"outline",size:"sm",onClick:X,disabled:g,className:"h-8 text-xs text-emerald-700",children:[e.jsx(fe,{size:14})," Restore"]}):e.jsxs(f,{variant:"outline",size:"sm",onClick:V,disabled:g,className:"h-8 text-xs text-gray-600",children:[e.jsx(ne,{size:14})," Archive job"]})]})]}),e.jsxs("div",{className:"bg-white border border-gray-100 rounded-xl p-4",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Job details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsx(m,{icon:e.jsx(L,{size:14}),label:"Job type",value:a.job_type}),e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Financial year",value:a.financial_year||a.reporting_period||"â"}),e.jsx(m,{icon:e.jsx(je,{size:14}),label:"Assigned to",value:a.assigned_accountant||"Unassigned"}),e.jsx(m,{icon:e.jsx(le,{size:14}),label:"Office",value:a.office_name||"â"}),e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Priority",value:a.priority}),e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Created",value:b(a.created_date)}),a.lodged_at&&e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Lodged",value:b(a.lodged_at)}),a.completed_at&&e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Completed",value:b(a.completed_at)}),a.archived_at&&e.jsx(m,{icon:e.jsx(j,{size:14}),label:"Archived",value:b(a.archived_at)})]}),a.notes&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Notes"}),e.jsx("p",{className:"text-sm text-gray-800 mt-1 whitespace-pre-wrap",children:a.notes})]})]}),q&&e.jsxs("div",{className:"bg-white border border-gray-100 rounded-xl p-4",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wide mb-3 flex items-center gap-1",children:[e.jsx($,{size:14})," Financials"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(C,{className:"text-xs text-gray-500",children:"Amount invoiced ($)"}),e.jsx(w,{type:"number",min:"0",step:"0.01",value:y,onChange:t=>A(t.target.value),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-xs text-gray-500",children:"Amount paid ($)"}),e.jsx(w,{type:"number",min:"0",step:"0.01",value:N,onChange:t=>J(t.target.value),className:"mt-1"})]})]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:["Outstanding: ",e.jsxs("span",{className:"font-semibold text-gray-900",children:["$",Math.max(0,(Number(y)||0)-(Number(N)||0)).toLocaleStr
1ing("en-AU",{minimumFractionDigits:2})]})]}),e.jsxs(f,{size:"sm",onClick:Y,disabled:O,className:"mt-3 bg-emerald-600 hover:bg-emerald-700",children:[O?e.jsx(_,{size:14,className:"animate-spin"}):e.jsx($,{size:14})," Save financials"]})]}),e.jsx(re,{open:R,onOpenChange:v,children:e.jsxs(oe,{className:"max-w-sm",children:[e.jsx(ce,{children:e.jsx(de,{children:"Duplicate to new period"})}),e.jsxs("p",{className:"text-sm text-gray-600",children:["Create a new ",a.job_type," for a new period. Status starts at New."]}),e.jsxs("div",{children:[e.jsx(C,{className:"text-xs text-gray-500",children:"Financial year / period"}),e.jsx(w,{value:D,onChange:t=>z(t.target.value),className:"mt-1"})]}),e.jsxs(me,{children:[e.jsx(f,{variant:"outline",onClick:()=>v(!1),disabled:g,children:"Cancel"}),e.jsx(f,{onClick:Q,disabled:g,className:"bg-emerald-600 hover:bg-emerald-700",children:g?e.jsx(_,{size:16,className:"animate-spin"}):"Duplicate"})]})]})}),e.jsx(ge,{open:I,onOpenChange:P,client:p||{id:a.client_id,full_name:a.client_name},jobId:a.id,onAction:M})]})}function m({icon:o,label:r,value:a}){return e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] text-gray-400 flex items-center gap-1",children:[o," ",r]}),e.jsx("p",{className:"text-sm font-medium text-gray-900 mt-0.5",children:a})]})}export{Ie 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.