import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{r}from"./api-NMlTtVre.js";import{t as i}from"./list-table-dcNbCPvq.js";import{t as a}from"./funnel-BDsPorMA.js";import{t as o}from"./plus-VCCEyniC.js";import{n as s,t as c}from"./filter-sheet-Baado-aR.js";import{Fo as l,W as u,et as d,ga as f,kr as p}from"./index-BP3TYB4i.js";import{t as m}from"./page-content-DDtdeMxM.js";import{t as h}from"./badge-Crg76WQE.js";import{t as g}from"./record-actions-DSw1sDLk.js";import{t as _}from"./list-page-header-48VsPegf.js";import{t as v}from"./use-server-pagination-CjwQ90IL.js";import{t as y}from"./auth-status-badge-pVqOsTb5.js";var b=e(t(),1),x=n();function S(){let e=l(),[t,n]=(0,b.useState)(``),[S,C]=(0,b.useState)(`all`),[w,T]=(0,b.useState)(`all`),[E,D]=(0,b.useState)(!1),O=v(),k={};S!==`all`&&(k.status=S),w!==`all`&&(k.scope_level=w),t&&(k.search=t);let{data:A,isLoading:j,refetch:M}=d(O.buildParams(Object.keys(k).length?k:void 0)),N=O.getItems(A),{data:P=[]}=p(),[F]=u(),I=()=>{C(`all`),T(`all`)},L=[S,w].filter(e=>e!==`all`).length;return(0,x.jsxs)(m,{children:[(0,x.jsx)(_,{title:`Margin Thresholds`,description:`Configure minimum margin requirements`,searchPlaceholder:`Search thresholds...`,searchValue:t,onSearchChange:e=>{n(e),O.setPage(1)},action:(0,x.jsxs)(f,{onClick:()=>e(`/masters/margin-thresholds/new`),size:`sm`,children:[(0,x.jsx)(o,{className:`mr-2 h-4 w-4`}),` Add Threshold`]}),filter:(0,x.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>D(!0),className:`relative`,children:[(0,x.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,L>0&&(0,x.jsx)(h,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:L})]})}),(0,x.jsx)(i,{data:N,columns:[{key:`code`,label:`Code`,render:e=>(0,x.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,x.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`scope_level`,label:`Scope Level`,render:e=>(0,x.jsx)(`span`,{className:`capitalize`,children:e.scope_level})},{key:`branch_name`,label:`Branch`,render:e=>e.branch_name||`—`},{key:`minimum_margin_percentage`,label:`Min Margin %`,className:`text-center`,render:e=>(0,x.jsxs)(`span`,{className:`font-mono`,children:[e.minimum_margin_percentage,`%`]})},{key:`escalation_required`,label:`Escalation`,render:e=>e.escalation_required?(0,x.jsx)(h,{children:`Yes`}):(0,x.jsx)(h,{variant:`secondary`,children:`No`})},{key:`status`,label:`Status`,render:e=>(0,x.jsx)(h,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Approval Status`,render:e=>(0,x.jsx)(y,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,x.jsx)(g,{approval:{entityType:`MarginThreshold`,objectId:t.id,contentTypeId:r.MARGIN_THRESHOLD,authorizedStatus:t.authorized_status??1,onApprovalChange:()=>M()},onView:()=>e(`/masters/margin-thresholds/${t.id}/edit`),onEdit:()=>e(`/masters/margin-thresholds/${t.id}/edit`),onDelete:()=>F(t.id)})}],isLoading:j,rowKey:e=>e.id,emptyMessage:`No margin thresholds found`,...O.tableProps(A)}),(0,x.jsxs)(s,{open:E,onOpenChange:D,onClear:I,children:[(0,x.jsx)(c,{label:`Status`,value:S,onChange:C,placeholder:`All Status`,options:[{value:`active`,label:`Active`},{value:`inactive`,label:`Inactive`}]}),(0,x.jsx)(c,{label:`Scope Level`,value:w,onChange:T,placeholder:`All Scopes`,options:[{value:`company`,label:`Company`},{value:`branch`,label:`Branch`},{value:`project`,label:`Project`}]})]})]})}export{S as default};