import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{r}from"./api-DcvYaav1.js";import{t as i}from"./list-table-CQD2C7IB.js";import{t as a}from"./funnel-BT4pjjO7.js";import{t as o}from"./plus-CuMPbIyn.js";import{n as s,t as c}from"./filter-sheet-omdfG0qY.js";import{G as l,Hr as u,rs as d,tt as f,za as p}from"./index-Ct5uU080.js";import{t as m}from"./page-content-Bh5Zxb_Y.js";import{t as h}from"./badge-CL1e8lO_.js";import{t as g}from"./record-actions-CTlg0qBJ.js";import{t as _}from"./list-page-header-CePoWpko.js";import{t as v}from"./use-server-pagination-CR_EVf1w.js";import{t as y}from"./auth-status-badge-BlJK5R24.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};