import{_ as q,r as f,o as B,b as v,c as g,p as F,d as a,T,h,t as r,F as A,s as $,g as j,z as G,a4 as H}from"./main.84523976.js";import{u as L}from"./use-meta.97669149.js";import{g as z,a as E,s as I}from"./SucursalRepository.4adef5c1.js";import{u as U}from"./use-productos-permitidos-macuspana.e9a6cf25.js";const X={class:"layout-px-spacing"},J={class:"row layout-top-spacing"},K={class:"col-xl-10 offset-xl-1 layout-spacing"},O={class:"panel p-4"},Q={class:"d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4"},W=["disabled"],Y={key:0,class:"text-center py-5 text-muted"},Z={key:1,class:"alert alert-warning"},R={class:"alert alert-info py-2 mb-4"},aa={class:"table-responsive"},ea={class:"table table-hover"},sa=["id","value"],ta=["for"],oa={class:"text-end"},la={class:"text-end"},na={key:0,class:"text-danger mb-0"},ua={__name:"productos-macuspana",setup(ra){L({title:"Productos Macuspana"});const{aplicarConfig:w}=U(),N=f(!0),P=f(!1),i=f(""),c=f(null),u=f([]),l=f([]);function D(d){return Number(d||0).toLocaleString("es-MX",{minimumFractionDigits:2,maximumFractionDigits:2})}async function V(){var d,s,o,m,y,x,k,M;N.value=!0,i.value="";try{const e=await z(),t=(s=(d=e==null?void 0:e.data)!=null?d:e)!=null?s:[];if(c.value=t.find(_=>_.tipo_sucursal==="venta_almacen")||null,!((o=c.value)!=null&&o.id))return;const b=await E(c.value.id),p=(m=b==null?void 0:b.data)!=null?m:b;u.value=(y=p==null?void 0:p.productos)!=null?y:[];const n=((x=p==null?void 0:p.producto_ids)!=null?x:[]).map(_=>Number(_)),S=u.value.filter(_=>_.habilitado===!0).map(_=>Number(_.id));l.value=n.length?n:S,w(l.value,u.value)}catch(e){i.value=((M=(k=e==null?void 0:e.response)==null?void 0:k.data)==null?void 0:M.message)||"No se pudo cargar la configuraci\xF3n."}finally{N.value=!1}}async function C(){var d,s,o,m,y,x,k,M;if(!!((d=c.value)!=null&&d.id)){if(!l.value.length){i.value="Debe habilitar al menos un producto.";return}P.value=!0,i.value="";try{const e=await I(c.value.id,l.value.map(n=>Number(n))),t=(s=e==null?void 0:e.data)!=null?s:e;u.value=(o=t==null?void 0:t.productos)!=null?o:u.value;const b=((m=t==null?void 0:t.producto_ids)!=null?m:l.value).map(n=>Number(n)),p=u.value.filter(n=>n.habilitado===!0).map(n=>Number(n.id));l.value=b.length?b:p,w(l.value,u.value)}catch(e){const t=(x=(y=e==null?void 0:e.response)==null?void 0:y.data)==null?void 0:x.errors;t!=null&&t.producto_ids?i.value=Array.isArray(t.producto_ids)?t.producto_ids[0]:t.producto_ids:i.value=((M=(k=e==null?void 0:e.response)==null?void 0:k.data)==null?void 0:M.message)||"No se pudo guardar la configuraci\xF3n."}finally{P.value=!1}}}return B(V),(d,s)=>(v(),g("div",X,[(v(),F(T,{to:"#breadcrumb"},[s[1]||(s[1]=a("ul",{class:"navbar-nav flex-row"},[a("li",null,[a("div",{class:"page-header"},[a("nav",{class:"breadcrumb-one","aria-label":"breadcrumb"},[a("ol",{class:"breadcrumb"},[a("li",{class:"breadcrumb-item"},[a("a",{href:"javascript:;"},"Administraci\xF3n")]),a("li",{class:"breadcrumb-item active","aria-current":"page"},[a("span",null,"Productos Macuspana")])])])])])],-1))])),a("div",J,[a("div",K,[a("div",O,[a("div",Q,[s[2]||(s[2]=a("div",null,[a("h3",{class:"titulo-dorado mb-2"},"Productos habilitados en Macuspana"),a("p",{class:"text-muted mb-0"},[h(" Villahermosa puede vender todo el cat\xE1logo. Aqu\xED elige qu\xE9 productos estar\xE1n disponibles en el "),a("strong",null,"punto de venta"),h(" y en la "),a("strong",null,"caseta de vigilancia"),h(" de Macuspana. ")])],-1)),a("button",{type:"button",class:"btn btn-black",disabled:P.value||N.value||!c.value,onClick:C},r(P.value?"Guardando...":"Guardar cambios"),9,W)]),N.value?(v(),g("div",Y,"Cargando cat\xE1logo...")):c.value?(v(),g(A,{key:2},[a("div",R,[s[3]||(s[3]=h(" Sucursal: ",-1)),a("strong",null,r(c.value.nombre),1),s[4]||(s[4]=h(" \xB7 Seleccionados: ",-1)),a("strong",null,r(l.value.length),1),h(" de "+r(u.value.length)+" productos activos ",1)]),a("div",aa,[a("table",ea,[s[5]||(s[5]=a("thead",null,[a("tr",null,[a("th",{style:{width:"48px"}}),a("th",null,"Producto"),a("th",{class:"text-end"},"Precio"),a("th",{class:"text-end"},"Stock")])],-1)),a("tbody",null,[(v(!0),g(A,null,$(u.value,o=>(v(),g("tr",{key:o.id},[a("td",null,[G(a("input",{id:`prod-${o.id}`,"onUpdate:modelValue":s[0]||(s[0]=m=>l.value=m),class:"form-check-input",type:"checkbox",value:Number(o.id)},null,8,sa),[[H,l.value]])]),a("td",null,[a("label",{for:`prod-${o.id}`,class:"mb-0 cursor-pointer"},r(o.nombre),9,ta)]),a("td",oa,"$"+r(D(o.precio_unitario)),1),a("td",la,r(o.stock_actual)+" "+r(o.unidad_medida||"m3"),1)]))),128))])])]),i.value?(v(),g("p",na,r(i.value),1)):j("",!0)],64)):(v(),g("div",Z," No se encontr\xF3 la sucursal Macuspana. Verifique que est\xE9 activa en el sistema. "))])])])]))}},va=q(ua,[["__scopeId","data-v-5899e6f8"]]);export{va as default};
