import{s as w,a as i,b as x,c as B}from"./index-aOv36DCp.js";import{_ as N,O as h,P as S,G as U,c as A,a as s,e as l,u as t,y as n,w as u,Q as E,H as m,A as c,o as D,t as L}from"./index-0UBdiff-.js";import{s as b}from"./index-CUzG0H3y.js";const I={class:"page module-accent",style:{"--accent-color":"var(--module-product-groups)"}},O={class:"page-header"},T={class:"card-block"},j={class:"mono"},q={class:"field"},H={class:"field"},K={class:"field"},M={class:"field"},Q={__name:"ProductGroups",setup(R){const p=h(),C=S(),g=c([]),f=c(!0),r=c(!1),v=c(!1),V=["Active","Inactive"],o=c({id:null,code:"",name:"",brand:"",status:"Active"});async function y(){f.value=!0;const{data:d}=await m.getProductGroups();g.value=d,f.value=!1}function G(){v.value=!1,o.value={id:null,code:"",name:"",brand:"",status:"Active"},r.value=!0}function P(d){v.value=!0,o.value={...d},r.value=!0}async function $(){var d,e;try{v.value?(await m.updateProductGroup(o.value),p.add({severity:"success",summary:"Updated",detail:`${o.value.code} saved`,life:3e3})):(await m.createProductGroup(o.value),p.add({severity:"success",summary:"Created",detail:`${o.value.code} added`,life:3e3})),r.value=!1,y()}catch(a){p.add({severity:"error",summary:"Error",detail:((e=(d=a.response)==null?void 0:d.data)==null?void 0:e.error)||"Save failed",life:4e3})}}function _(d){C.require({message:`Delete product group ${d.code}? This cannot be undone.`,header:"Confirm deletion",icon:"pi pi-exclamation-triangle",acceptLabel:"Delete",rejectLabel:"Cancel",acceptClass:"p-button-danger",accept:async()=>{await m.deleteProductGroup(d.id),p.add({severity:"info",summary:"Deleted",detail:`${d.code} removed`,life:3e3}),y()}})}return U(y),(d,e)=>(D(),A("div",I,[s("div",O,[e[6]||(e[6]=s("div",null,[s("h1",null,"Product Groups"),s("p",{class:"page-subtitle"},"Brands and product groups that styles roll up under.")],-1)),l(t(n),{label:"New Product Group",icon:"pi pi-plus",onClick:G})]),s("div",T,[l(t(w),{value:g.value,loading:f.value,dataKey:"id",stripedRows:"",responsiveLayout:"scroll"},{empty:u(()=>[...e[7]||(e[7]=[s("div",{class:"empty-state"},"No product groups yet. Create one to get started.",-1)])]),default:u(()=>[l(t(i),{field:"code",header:"Code"},{body:u(({data:a})=>[s("span",j,L(a.code),1)]),_:1}),l(t(i),{field:"name",header:"Name"}),l(t(i),{field:"brand",header:"Brand"}),l(t(i),{field:"style_count",header:"Styles"}),l(t(i),{field:"status",header:"Status"},{body:u(({data:a})=>[l(t(x),{value:a.status,severity:a.status==="Active"?"success":"secondary"},null,8,["value","severity"])]),_:1}),l(t(i),{header:"",style:{width:"110px"}},{body:u(({data:a})=>[l(t(n),{icon:"pi pi-pencil",text:"",rounded:"",onClick:k=>P(a)},null,8,["onClick"]),l(t(n),{icon:"pi pi-trash",text:"",rounded:"",severity:"danger",onClick:k=>_(a)},null,8,["onClick"])]),_:1})]),_:1},8,["value","loading"])]),l(t(E),{visible:r.value,"onUpdate:visible":e[5]||(e[5]=a=>r.value=a),modal:"",header:v.value?"Edit Product Group":"New Product Group",style:{width:"420px"}},{footer:u(()=>[l(t(n),{label:"Cancel",text:"",onClick:e[4]||(e[4]=a=>r.value=!1)}),l(t(n),{label:"Save",onClick:$})]),default:u(()=>[s("div",q,[e[8]||(e[8]=s("label",null,"Code",-1)),l(t(b),{modelValue:o.value.code,"onUpdate:modelValue":e[0]||(e[0]=a=>o.value.code=a),fluid:"",placeholder:"PG-005"},null,8,["modelValue"])]),s("div",H,[e[9]||(e[9]=s("label",null,"Name",-1)),l(t(b),{modelValue:o.value.name,"onUpdate:modelValue":e[1]||(e[1]=a=>o.value.name=a),fluid:"",placeholder:"Product Group 5"},null,8,["modelValue"])]),s("div",K,[e[10]||(e[10]=s("label",null,"Brand",-1)),l(t(b),{modelValue:o.value.brand,"onUpdate:modelValue":e[2]||(e[2]=a=>o.value.brand=a),fluid:"",placeholder:"Brand 1"},null,8,["modelValue"])]),s("div",M,[e[11]||(e[11]=s("label",null,"Status",-1)),l(t(B),{modelValue:o.value.status,"onUpdate:modelValue":e[3]||(e[3]=a=>o.value.status=a),options:V,fluid:""},null,8,["modelValue"])])]),_:1},8,["visible","header"])]))}},W=N(Q,[["__scopeId","data-v-73016c88"]]);export{W as default};
