import{n as e,o as t}from"./utils-Dac180Gn.js";import{r as n}from"./api-NMlTtVre.js";import{t as r}from"./circle-check-big-uPKjaU7L.js";import{t as i}from"./send--6w2f5b6.js";import{Fo as a,Io as o,ga as s,ko as c}from"./index-BP3TYB4i.js";import{t as l}from"./page-content-DDtdeMxM.js";import{t as u}from"./card-BVFw-jgA.js";import{t as d}from"./approval-actions-LKMeSekL.js";import{t as f}from"./audit-info-DYjRd8rp.js";import{t as p}from"./workflow-status-badge-B5qOWo7t.js";import{R as m,T as h,V as g}from"./serviceApi-BlxU9Cj1.js";var _=t();function v(){let{id:t}=o(),v=a(),{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)(s,{variant:`ghost`,size:`icon`,onClick:()=>v(`/service-settlements`),children:(0,_.jsx)(c,{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)(s,{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)(s,{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};