import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{s as n}from"./utils-BO1RPuol.js";import{r}from"./api-46eXiUHP.js";import{t as i}from"./list-table-D-0FOE41.js";import{t as a}from"./funnel-CzLimyxu.js";import{t as o}from"./plus-BEDg_66Y.js";import{n as s,t as c}from"./filter-sheet-Cko6eldy.js";import{G as l,Hr as u,os as d,tt as f,za as p}from"./index-B4NicEaS.js";import{t as m}from"./page-content-DdXVZwik.js";import{t as h}from"./badge-DLCseWie.js";import{t as g}from"./record-actions-BOLlEOQM.js";import{t as _}from"./list-page-header-7ncCnVWg.js";import{t as v}from"./use-server-pagination-BC4JB9I3.js";import{t as y}from"./auth-status-badge-C6fBtAs6.js";var b=e(t(),1),x=n();function S(){let e=d(),[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 A=O.buildParams(Object.keys(k).length?k:void 0),{data:j,isLoading:M,refetch:N}=f(A),P=O.getItems(j),{data:F=[]}=u(),[I]=l(),L=()=>{C(`all`),T(`all`)},R=[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)(p,{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)(p,{variant:`outline`,size:`sm`,onClick:()=>D(!0),className:`relative`,children:[(0,x.jsx)(a,{className:`mr-2 h-4 w-4`}),` Filters`,R>0&&(0,x.jsx)(h,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:R})]})}),(0,x.jsx)(i,{data:P,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:()=>N()},onView:()=>e(`/masters/margin-thresholds/${t.id}/edit`),onEdit:()=>e(`/masters/margin-thresholds/${t.id}/edit`),onDelete:()=>I(t.id)})}],isLoading:M,rowKey:e=>e.id,emptyMessage:`No margin thresholds found`,...O.tableProps(j)}),(0,x.jsxs)(s,{open:E,onOpenChange:D,onClear:L,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};