import{r as e,s as t}from"./utils-BO1RPuol.js";import{r as n}from"./api-CycUopBp.js";import{t as r}from"./circle-check-big-BvblFhCH.js";import{t as i}from"./send-BH6nmgfj.js";import{es as a,os as o,ss as s,za as c}from"./index-CsuVxiRQ.js";import{t as l}from"./page-content-DdXVZwik.js";import{t as u}from"./card-CBaLHc_f.js";import{t as d}from"./approval-actions-CkNc5EP7.js";import{t as f}from"./audit-info-B4AWyeNJ.js";import{t as p}from"./workflow-status-badge-BdRZ0is7.js";import{R as m,T as h,V as g}from"./serviceApi-RIObRUm3.js";var _=t();function v(){let{id:t}=s(),v=o(),{data:y,isLoading:b,refetch:x}=h(t),[S,{isLoading:C}]=m(),[w,{isLoading:T}]=g();return b?(0,_.jsx)(`div`,{className:`text-center py-8`,children:`Loading...`}):y?(0,_.jsxs)(l,{children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,_.jsx)(c,{variant:`ghost`,size:`icon`,onClick:()=>v(`/service-settlements`),children:(0,_.jsx)(a,{className:`h-4 w-4`})}),(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h1`,{className:`text-3xl font-bold`,children:y.code}),(0,_.jsx)(`p`,{className:`text-muted-foreground`,children:y.employee_name})]}),(0,_.jsx)(p,{status:y.status})]}),y.status===`pending`&&(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(d,{entityType:`ExpenseSettlement`,objectId:t,contentTypeId:n.EXPENSE_SETTLEMENT,authorizedStatus:y.authorized_status??1,onApprovalChange:()=>x()}),y.authorized_status!==1&&(0,_.jsxs)(c,{size:`sm`,onClick:async()=>{try{await w(t).unwrap(),x()}catch{}},disabled:T,children:[(0,_.jsx)(i,{className:`mr-1 h-4 w-4`}),` Submit for Approval`]}),(0,_.jsxs)(c,{size:`sm`,onClick:async()=>{try{await S(t).unwrap(),x()}catch{}},disabled:C,children:[(0,_.jsx)(r,{className:`mr-1 h-4 w-4`}),` Settle`]})]})]}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,_.jsxs)(u,{className:`p-6 space-y-3`,children:[(0,_.jsx)(`h2`,{className:`font-semibold text-lg`,children:`Settlement Details`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-y-2 text-sm`,children:[(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Employee:`}),(0,_.jsx)(`span`,{children:y.employee_name}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Service Request:`}),(0,_.jsx)(`span`,{className:`font-mono`,children:y.service_request_code||`—`}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Branch:`}),(0,_.jsx)(`span`,{children:y.branch_name}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Period:`}),(0,_.jsxs)(`span`,{children:[y.period_from,` to `,y.period_to]}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Total Amount:`}),(0,_.jsx)(`span`,{className:`font-mono font-semibold`,children:Number(y.total_amount).toLocaleString()})]}),y.remarks&&(0,_.jsxs)(`div`,{className:`text-sm`,children:[(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Remarks:`}),` `,y.remarks]})]}),(0,_.jsxs)(u,{className:`p-6 space-y-3`,children:[(0,_.jsx)(`h2`,{className:`font-semibold text-lg`,children:`Settlement Info`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-y-2 text-sm`,children:[(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Settled By:`}),(0,_.jsx)(`span`,{children:y.settled_by_name||`—`}),(0,_.jsx)(`span`,{className:`text-muted-foreground`,children:`Settlement Date:`}),(0,_.jsx)(`span`,{children:e(y.settlement_date)})]}),(0,_.jsx)(f,{createdByName:y.created_by_name,createdAt:y.created_at,asCard:!1})]})]}),(0,_.jsxs)(u,{className:`p-6 space-y-4`,children:[(0,_.jsxs)(`h2`,{className:`font-semibold text-lg`,children:[`Settlement Items (`,y.items?.length||0,`)`]}),(0,_.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,_.jsx)(`thead`,{children:(0,_.jsxs)(`tr`,{className:`border-b bg-muted/10`,children:[(0,_.jsx)(`th`,{className:`text-left p-3`,children:`#`}),(0,_.jsx)(`th`,{className:`text-left p-3`,children:`Expense Type`}),(0,_.jsx)(`th`,{className:`text-center p-3`,children:`Amount`})]})}),(0,_.jsx)(`tbody`,{children:(y.items||[]).length===0?(0,_.jsx)(`tr`,{children:(0,_.jsx)(`td`,{colSpan:3,className:`text-center py-8 text-muted-foreground`,children:`No items`})}):y.items.map((e,t)=>(0,_.jsxs)(`tr`,{className:`border-b hover:bg-muted/50`,children:[(0,_.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:t+1}),(0,_.jsx)(`td`,{className:`p-3`,children:e.expense_master_name}),(0,_.jsx)(`td`,{className:`p-3 text-center font-mono`,children:Number(e.amount).toLocaleString()})]},e.id))})]})]})]}):(0,_.jsx)(`div`,{className:`text-center py-8`,children:`Expense Settlement not found`})}export{v as default};