import{s as e}from"./utils-CXcsdpX-.js";import{t}from"./circle-check-big-Cjc8y4E5.js";import{A as n,Zo as r,is as i,rs as a,w as o,za as s}from"./index-Ct5uU080.js";import{t as c}from"./page-content-Bh5Zxb_Y.js";import{t as l}from"./card-CCLQVS9k.js";import{t as u}from"./workflow-status-badge-B4zdc-CO.js";var d=e();function f(){let{id:e}=i(),f=a(),{data:p,isLoading:m,refetch:h}=n(e),[g]=o();if(m)return(0,d.jsx)(`div`,{className:`text-center`,children:`Loading...`});if(!p)return(0,d.jsx)(`div`,{className:`text-center`,children:`Credit Note not found`});let _=p.status===`draft`||p.status===`submitted`;return(0,d.jsxs)(c,{children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,d.jsx)(s,{variant:`ghost`,size:`icon`,onClick:()=>f(`/credit-notes`),children:(0,d.jsx)(r,{className:`h-4 w-4`})}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h1`,{className:`text-3xl font-bold`,children:p.code}),(0,d.jsx)(`p`,{className:`text-muted-foreground`,children:p.client_name})]}),(0,d.jsx)(u,{status:p.status})]}),_&&(0,d.jsxs)(s,{size:`sm`,onClick:async()=>{try{await g(e).unwrap(),h()}catch{}},children:[(0,d.jsx)(t,{className:`mr-1 h-4 w-4`}),` Approve`]})]}),(0,d.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,d.jsxs)(l,{className:`p-6 space-y-3`,children:[(0,d.jsx)(`h2`,{className:`font-semibold text-lg`,children:`Credit Note Details`}),(0,d.jsxs)(`div`,{className:`grid grid-cols-2 gap-y-2 text-sm`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Credit Date:`}),(0,d.jsx)(`span`,{children:p.credit_date}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Credit Type:`}),(0,d.jsx)(`span`,{className:`capitalize`,children:p.credit_type}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Invoice:`}),(0,d.jsx)(`span`,{className:`font-mono`,children:p.sales_invoice_code}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Sales Order:`}),(0,d.jsx)(`span`,{className:`font-mono`,children:p.sales_order_code}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Branch:`}),(0,d.jsx)(`span`,{children:p.branch_name||`—`})]}),(0,d.jsxs)(`div`,{className:`text-sm`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Reason:`}),` `,p.reason]}),p.remarks&&(0,d.jsxs)(`div`,{className:`text-sm`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Remarks:`}),` `,p.remarks]})]}),(0,d.jsxs)(l,{className:`p-6 space-y-3`,children:[(0,d.jsx)(`h2`,{className:`font-semibold text-lg`,children:`Amounts`}),(0,d.jsxs)(`div`,{className:`grid grid-cols-2 gap-y-2 text-sm`,children:[(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Credit Amount:`}),(0,d.jsx)(`span`,{className:`font-mono text-center`,children:Number(p.credit_amount).toLocaleString()}),(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`Tax Adjustment:`}),(0,d.jsx)(`span`,{className:`font-mono text-center`,children:Number(p.tax_adjustment).toLocaleString()})]}),(0,d.jsxs)(`div`,{className:`grid grid-cols-2 gap-y-2 text-sm pt-2 border-t font-semibold`,children:[(0,d.jsx)(`span`,{children:`Net Credit:`}),(0,d.jsx)(`span`,{className:`font-mono text-center`,children:Number(p.net_credit).toLocaleString()})]})]})]}),p.line_items&&p.line_items.length>0&&(0,d.jsxs)(l,{className:`p-6 space-y-4`,children:[(0,d.jsx)(`h2`,{className:`font-semibold text-lg`,children:`Line Items`}),(0,d.jsx)(`div`,{className:`overflow-x-auto`,children:(0,d.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,d.jsx)(`thead`,{children:(0,d.jsxs)(`tr`,{className:`border-b bg-muted/10`,children:[(0,d.jsx)(`th`,{className:`text-left p-3`,children:`#`}),(0,d.jsx)(`th`,{className:`text-center p-3`,children:`Qty`}),(0,d.jsx)(`th`,{className:`text-center p-3`,children:`Rate`}),(0,d.jsx)(`th`,{className:`text-center p-3`,children:`Amount`}),(0,d.jsx)(`th`,{className:`text-center p-3`,children:`Tax Adj`})]})}),(0,d.jsx)(`tbody`,{children:p.line_items.map((e,t)=>(0,d.jsxs)(`tr`,{className:`border-b hover:bg-muted/50`,children:[(0,d.jsx)(`td`,{className:`p-3 text-muted-foreground`,children:t+1}),(0,d.jsx)(`td`,{className:`p-3 text-center font-mono`,children:e.quantity}),(0,d.jsx)(`td`,{className:`p-3 text-center font-mono`,children:Number(e.rate).toLocaleString()}),(0,d.jsx)(`td`,{className:`p-3 text-center font-mono`,children:Number(e.amount).toLocaleString()}),(0,d.jsx)(`td`,{className:`p-3 text-center font-mono`,children:Number(e.tax_adjustment).toLocaleString()})]},e.id))})]})})]})]})}export{f as default};