1import{b1 as L,a as F,r as v,aA as i,y as c,j as e,L as D,S as E,ai as I}from"./index-DelWp-6b.js";import{u as q}from"./useQuery-B9eAwr7I.js";import{u}from"./useMutation-CwYdRQCa.js";import{p as o}from"./pricing.service-DoMmq53q.js";import{P as A,a as R,p as l,b as n,c as $}from"./PricingShell-C3jfPTD5.js";import{P as b}from"./pricing.types-DzR9kvvl.js";import{T as N}from"./tags-CRXuPLAM.js";import{P as k}from"./plus-BjX2r5pd.js";import{L as K}from"./list-ordered-TIy73ifE.js";import"./unwrap-CuJafpqD.js";import"./paging-BO6Zj7Ff.js";const h={code:"",name:"",listType:b.Sales,currency:"SAR",priceIncludesTax:!1,priority:0,isDefault:!1};function J(){var j,f;const C=L(),w=F(),[t,d]=v.useState(h),[P,m]=v.useState(!1),a=q({queryKey:["pricing","price-lists"],queryFn:o.list}),p=()=>C.invalidateQueries({queryKey:["pricing","price-lists"]}),x=u({mutationFn:()=>o.create(t),onSuccess:()=>{i.success("Price list created"),d(h),m(!1),p()},onError:s=>i.error(c(s,"Could not create the price list."))}),g=u({mutationFn:s=>o.makeDefault(s),onSuccess:()=>{i.success("Default updated"),p()},onError:s=>i.error(c(s,"Could not set the default."))}),y=u({mutationFn:s=>o.remove(s),onSuccess:()=>{i.success("Price list deleted"),p()},onError:s=>i.error(c(s,"Could not delete the price list."))}),r=(s,T)=>d(S=>({...S,[s]:T}));return e.jsx(A,{title:"Pricing & Promotions",subtitle:"What a product costs, and every rule that changes it",actions:e.jsxs("button",{type:"button",onClick:()=>m(s=>!s),className:"shrink-0 inline-flex items-center gap-2 px-4 py-2 rounded-xl text-[13px] font-semibold text-white transition",style:{background:"var(--primary-600)"},children:[e.jsx(k,{className:"w-4 h-4"}),"New price list"]}),children:e.jsxs("div",{className:"space-y-5",children:[P&&e.jsxs(R,{icon:N,title:"New price list",desc:"Code and name are required; everything else has a working default.",children:[e.jsxs("div",{className:"grid sm:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:l,htmlFor:"code",children:"Code *"}),e.jsx("input",{id:"code",className:n,value:t.code,onChange:s=>r("code",s.target.value),placeholder:"RETAIL-2026"})]}),e.jsxs("div",{children:[e.jsx("label",{className:l,htmlFor:"name",children:"Name *"}),e.jsx("input",{id:"name",className:n,value:t.name,onChange:s=>r("name",s.target.value),placeholder:"Retail 2026"})]}),e.jsxs("div",{children:[e.jsx("label",{className:l,htmlFor:"currency",children:"Currency"}),e.jsx("input",{id:"currency",className:n,value:t.currency,maxLength:3,onChange:s=>r("currency",s.target.value.toUpperCase())})]}),e.jsxs("div",{children:[e.jsx("label",{className:l,htmlFor:"type",children:"Type"}),e.jsxs("select",{id:"type",className:n,value:t.listType,onChange:s=>r("listType",Number(s.target.value)),children:[e.jsx("option",{value:b.Sales,children:"Sales"}),e.jsx("option",{value:b.Purchase,children:"Purchase"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:l,htmlFor:"priority",children:"Priority"}),e.jsx("input",{id:"priority",type:"number",className:n,value:t.priority,onChange:s=>r("priority",Number(s.target.value))}),e.jsx("p",{className:"mt-1 text-[11px] text-slate-500",children:"Higher wins when two lists cover the same SKU."})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-[13px]",children:[e.jsx("input",{type:"checkbox",checked:t.priceIncludesTax,onChange:s=>r("priceIncludesTax",s.target.checked)}),"Prices include VAT"]})})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsxs("button",{type:"button",onClick:()=>x.mutate(),disabled:!t.code.trim()||!t.name.trim()||x.isPending,className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-[13px] font-semibold text-white disabled:opacity-40",style:{background:"var(--primary-600)"},children:[x.isPending?e.jsx(D,{className:"w-4 h-4 animate-spin"}):e.jsx(k,{className:"w-4 h-4"}),"Create"]}),e.jsx("button",{type:"button",onClick:()=>{m(!1),d(h)},className:"px-4 py-2.5 rounded-xl text-[13px] font-semibold border border-slate-200 dark:border-slate-700",children:"Cancel"})]})]}),a.isError&&e.jsx($,{message:c(a.error,"Could not load price lists."),onRetry:()=>a.refetch()}),a.isLoading&&e.jsx("div",{className:"space-y-3",children:[0,1,2].map(s=>
1e.jsx("div",{className:"h-20 rounded-2xl bg-slate-100 dark:bg-slate-800 animate-pulse"},s))}),((j=a.data)==null?void 0:j.length)===0&&!a.isLoading&&e.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-300 dark:border-slate-700 p-10 text-center",children:[e.jsx(K,{className:"w-10 h-10 mx-auto mb-3 text-slate-400"}),e.jsx("h2",{className:"font-bold text-sm mb-1",children:"No price lists"}),e.jsx("p",{className:"text-[13px] text-slate-500 max-w-md mx-auto",children:"Without one, every till falls back to each item's standard price â which the quote reports honestly, but which nobody can manage centrally."})]}),!!((f=a.data)!=null&&f.length)&&e.jsx("div",{className:"space-y-3",children:a.data.map(s=>e.jsxs("div",{className:"rounded-2xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800/50 p-4 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shrink-0",style:{background:"rgba(var(--primary-rgb),0.12)",color:"var(--primary-600)"},children:e.jsx(N,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-bold text-sm",children:s.name}),e.jsx("span",{className:"font-mono text-[11px] text-slate-500",children:s.code}),s.isDefault&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-300",children:[e.jsx(E,{className:"w-3 h-3"})," Default"]}),s.priceIncludesTax&&e.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full bg-slate-100 dark:bg-slate-700 text-slate-600 dark:text-slate-300",children:"VAT-inclusive"})]}),e.jsxs("div",{className:"text-[12px] text-slate-500 mt-0.5",children:[s.currency," · priority ",s.priority,typeof s.lineCount=="number"&&` · ${s.lineCount} line(s)`,s.validFrom&&` · from ${new Date(s.validFrom).toLocaleDateString()}`]})]}),e.jsx("button",{type:"button",onClick:()=>w(`/pricing/price-lists/${s.id}`),className:"shrink-0 px-3 py-1.5 rounded-lg text-[12px] font-semibold border border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-700 transition",children:"Prices"}),!s.isDefault&&e.jsx("button",{type:"button",onClick:()=>g.mutate(s.id),disabled:g.isPending,className:"shrink-0 px-3 py-1.5 rounded-lg text-[12px] font-semibold border border-slate-200 dark:border-slate-700 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-40 transition",children:"Make default"}),e.jsx("button",{type:"button",onClick:()=>y.mutate(s.id),disabled:y.isPending,className:"shrink-0 w-8 h-8 rounded-lg hover:bg-rose-100 dark:hover:bg-rose-500/15 text-slate-400 hover:text-rose-500 flex items-center justify-center disabled:opacity-40 transition","aria-label":`Delete ${s.name}`,children:e.jsx(I,{className:"w-4 h-4"})})]},s.id))})]})})}export{J as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.