import{_ as x,a as L,n as U,Q as h,I as v,f as d,i as k,r as l,o as u,b as a,t as m,w as A,e as B,v as N,c as _,g as f,x as R}from"./index-FeGPXkd3.js";import{A as E}from"./AdminLayout-lK_UH-Ij.js";import{E as M}from"./ErrorMessage-ChK9yrNJ.js";import{L as O}from"./LoadingSpinner-Pr3eqcHT.js";import"./LogoutButton-B5z6lFv-.js";const V={class:"card settings-card"},C={class:"settings-grid"},D={class:"preview-box"},P=["src","alt"],F={class:"preview-name"},G={class:"input-group"},I={class:"input-group"},q={key:0,class:"success-text"},z=["disabled"],J={key:1},Q={__name:"AjustesView",setup(T){const g=L(),n=l(!1),r=l(""),c=l(""),t=l("Barbería San Ramón"),i=l("/logo.png"),p=l(null),o=l(""),b=R(()=>o.value||i.value||"/logo.png");U(async()=>{await y()}),h(()=>{o.value&&URL.revokeObjectURL(o.value)});const y=async()=>{n.value=!0,r.value="";try{const s=await v.getSettings();t.value=s.data.business_name||"Barbería San Ramón",i.value=s.data.logo_url||"/logo.png",g.applySettings({business_name:t.value,logo_url:i.value})}catch(s){r.value=s.response?.data?.message||"No se pudieron cargar los ajustes."}finally{n.value=!1}},w=s=>{const e=s.target.files?.[0]||null;p.value=e,o.value&&(URL.revokeObjectURL(o.value),o.value=""),e&&(o.value=URL.createObjectURL(e))},S=async()=>{n.value=!0,r.value="",c.value="";try{const s=new FormData;s.append("business_name",t.value),p.value&&s.append("logo",p.value);const e=await v.updateSettings(s);c.value=e.data?.message||"Ajustes actualizados correctamente.",i.value=e.data?.settings?.logo_url||i.value,t.value=e.data?.settings?.business_name||t.value,g.applySettings(e.data?.settings||{}),p.value=null}catch(s){const e=s.response?.data?.errors?Object.values(s.response.data.errors)?.[0]?.[0]:"";r.value=e||s.response?.data?.message||"No se pudieron guardar los ajustes."}finally{n.value=!1}};return(s,e)=>(u(),d(E,null,{default:k(()=>[e[3]||(e[3]=a("h2",{style:{margin:"0 0 20px 0"}},"Ajustes App",-1)),e[4]||(e[4]=a("p",{class:"title-sm",style:{"margin-top":"0"}},"Nombre del negocio e imagen principal",-1)),a("div",V,[a("div",C,[a("div",D,[a("img",{src:b.value,alt:t.value,class:"logo-preview"},null,8,P),a("p",F,m(t.value),1)]),a("form",{class:"settings-form",onSubmit:A(S,["prevent"])},[a("div",G,[e[1]||(e[1]=a("label",{for:"business_name"},"Nombre del negocio",-1)),B(a("input",{id:"business_name","onUpdate:modelValue":e[0]||(e[0]=j=>t.value=j),type:"text",class:"input-control",maxlength:"120",required:""},null,512),[[N,t.value]])]),a("div",I,[e[2]||(e[2]=a("label",{for:"logo"},"Logo (JPG/PNG/WEBP, máx 2MB)",-1)),a("input",{id:"logo",type:"file",class:"input-control",accept:"image/png,image/jpeg,image/webp",onChange:w},null,32)]),c.value?(u(),_("p",q,m(c.value),1)):f("",!0),r.value?(u(),d(M,{key:1,message:r.value},null,8,["message"])):f("",!0),a("button",{type:"submit",class:"btn btn-gold",disabled:n.value},[n.value?(u(),d(O,{key:0})):(u(),_("span",J,"Guardar cambios"))],8,z)],32)])])]),_:1}))}},Z=x(Q,[["__scopeId","data-v-19d17ea8"]]);export{Z as default};
