import{a as e,t}from"./react-DK-MTtD8.js";import{r as n,s as r}from"./utils-CXcsdpX-.js";import{r as i}from"./api-CC_sFP6f.js";import{t as a}from"./list-table-CF_0QrYo.js";import{t as o}from"./funnel-BT4pjjO7.js";import{t as s}from"./plus-CuMPbIyn.js";import{n as c,t as l}from"./filter-sheet-_WHotb9o.js";import{An as u,Hr as d,Mt as f,qt as p,rs as m,tn as h,za as g}from"./index-CvTTLloU.js";import{t as _}from"./page-content-Bh5Zxb_Y.js";import{t as v}from"./badge-CL1e8lO_.js";import{a as y,i as b,n as x,o as S,t as C}from"./dialog-DrW_2c38.js";import{t as w}from"./list-page-header-D6ls_V1f.js";import{t as T}from"./auth-status-badge-BlJK5R24.js";import{t as ee}from"./row-actions-C-24DtZS.js";var E=e(t(),1),D=r(),O={draft:`secondary`,submitted:`default`,approved:`default`,rejected:`destructive`},k={draft:`Draft`,submitted:`Submitted`,approved:`Approved`,rejected:`Rejected`};function A(){let e=m(),[t,r]=(0,E.useState)(``),[A,j]=(0,E.useState)(`all`),[M,N]=(0,E.useState)(`all`),[P,F]=(0,E.useState)(`all`),[I,L]=(0,E.useState)(`all`),[R,z]=(0,E.useState)(`all`),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)(null),W={};A!==`all`&&(W.pq_status=A),t&&(W.search=t),M!==`all`&&(W.vendor=M),P!==`all`&&(W.branch=P),I!==`all`&&(W.tender=I),R!==`all`&&(W.authorized_status=R);let{data:G=[],isLoading:K,refetch:q}=p(W),{data:J=[]}=h(),{data:Y=[]}=d(),{data:X=[]}=u(),[Z]=f(),Q=async()=>{H&&(await Z(H).unwrap().catch(()=>{}),U(null),q())},te=()=>{j(`all`),N(`all`),F(`all`),L(`all`),z(`all`)},$=[A,M,P,I,R].filter(e=>e!==`all`).length;return(0,D.jsxs)(_,{children:[(0,D.jsx)(w,{title:`Purchase Quotations`,description:`Manage vendor quotations against enquiries`,searchPlaceholder:`Search quotations...`,searchValue:t,onSearchChange:r,action:(0,D.jsxs)(g,{onClick:()=>e(`/purchase/quotations/new`),size:`sm`,children:[(0,D.jsx)(s,{className:`mr-2 h-4 w-4`}),` Create PQ`]}),filter:(0,D.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>V(!0),className:`relative`,children:[(0,D.jsx)(o,{className:`mr-2 h-4 w-4`}),` Filters`,$>0&&(0,D.jsx)(v,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:$})]})}),(0,D.jsx)(a,{data:G,onRowClick:t=>e(`/purchase/quotations/${t.id}`),columns:[{key:`code`,label:`Quotation No`,render:e=>(0,D.jsx)(`span`,{className:`font-mono text-xs whitespace-nowrap`,children:e.code})},{key:`tender_name`,label:`Enquiry`,render:e=>(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`font-medium`,children:e.tender_name}),(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.tender_code})]})},{key:`tender_number`,label:`Tender No.`,render:e=>e.tender_number||`—`},{key:`vendor_name`,label:`Vendor`},{key:`quotation_date`,label:`Date`,render:e=>n(e.quotation_date)},{key:`pq_status`,label:`Status`,render:e=>(0,D.jsx)(v,{variant:O[e.pq_status]||`secondary`,children:k[e.pq_status]||e.pq_status})},{key:`grand_total`,label:`Grand Total`,className:`text-center`,render:e=>(0,D.jsx)(`span`,{className:`font-mono`,children:Number(e.grand_total).toLocaleString()})},{key:`branch_name`,label:`Branch`},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,D.jsx)(T,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,D.jsx)(ee,{onView:()=>e(`/purchase/quotations/${t.id}`),onEdit:()=>e(`/purchase/quotations/${t.id}/edit`),onDelete:()=>U(t.id),approval:{entityType:`PurchaseQuotation`,objectId:t.id,contentTypeId:i.PURCHASE_QUOTATION,authorizedStatus:t.authorized_status??1,onApprovalChange:()=>q()}})}],isLoading:K,rowKey:e=>e.id,emptyMessage:`No purchase quotations found`}),(0,D.jsxs)(c,{open:B,onOpenChange:V,onClear:te,children:[(0,D.jsx)(l,{label:`Status`,value:A,onChange:j,placeholder:`All Status`,options:Object.entries(k).map(([e,t])=>({value:e,label:t}))}),(0,D.jsx)(l,{label:`Vendor`,value:M,onChange:N,placeholder:`All Vendors`,options:J.map(e=>({value:String(e.id),label:e.name}))}),(0,D.jsx)(l,{label:`Branch`,value:P,onChange:F,placeholder:`All Branches`,options:Y.map(e=>({value:String(e.id),label:e.name}))}),(0,D.jsx)(l,{label:`Enquiry`,value:I,onChange:L,placeholder:`All Enquiries`,options:X.map(e=>({value:String(e.id),label:e.name}))}),(0,D.jsx)(l,{label:`Authorization`,value:R,onChange:z,placeholder:`All`,options:[{value:`1`,label:`Pending`},{value:`2`,label:`Approved`},{value:`3`,label:`Rejected`}]})]}),(0,D.jsx)(C,{open:!!H,onOpenChange:e=>{e||U(null)},children:(0,D.jsxs)(x,{className:`sm:max-w-md`,children:[(0,D.jsx)(y,{children:(0,D.jsx)(S,{children:`Delete Purchase Quotation`})}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Are you sure you want to delete this purchase quotation?`}),(0,D.jsxs)(b,{children:[(0,D.jsx)(g,{variant:`outline`,size:`sm`,onClick:()=>U(null),children:`Cancel`}),(0,D.jsx)(g,{variant:`destructive`,size:`sm`,onClick:Q,children:`Delete`})]})]})})]})}export{A as default};