import{_ as x,a as L,n as U,Q as h,I as g,f as d,i as k,r as n,o as i,b as a,t as v,w as A,e as B,v as N,c as m,g as _,x as R}from"./index-CQUb2PNT.js";import{A as E}from"./AdminLayout-DulJktjC.js";import{E as M}from"./ErrorMessage--UUueNY-.js";import{L as O}from"./LoadingSpinner-LvNw1Abo.js";import"./LogoutButton-Bjoa3U8D.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 f=L(),l=n(!1),r=n(""),u=n(""),t=n("Barbería San Ramón"),c=n("/logo.png"),p=n(null),o=n(""),b=R(()=>o.value||c.value||"/logo.png");U(async()=>{await y()}),h(()=>{o.value&&URL.revokeObjectURL(o.value)});const y=async()=>{l.value=!0,r.value="";try{const s=await g.getSettings();t.value=s.data.business_name||"Barbería San Ramón",c.value=s.data.logo_url||"/logo.png"}catch(s){r.value=s.response?.data?.message||"No se pudieron cargar los ajustes."}finally{l.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()=>{l.value=!0,r.value="",u.value="";try{const s=new FormData;s.append("business_name",t.value),p.value&&s.append("logo",p.value);const e=await g.updateSettings(s);u.value=e.data?.message||"Ajustes actualizados correctamente.",c.value=e.data?.settings?.logo_url||c.value,t.value=e.data?.settings?.business_name||t.value,f.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{l.value=!1}};return(s,e)=>(i(),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,v(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)]),u.value?(i(),m("p",q,v(u.value),1)):_("",!0),r.value?(i(),d(M,{key:1,message:r.value},null,8,["message"])):_("",!0),a("button",{type:"submit",class:"btn btn-gold",disabled:l.value},[l.value?(i(),d(O,{key:0})):(i(),m("span",J,"Guardar cambios"))],8,z)],32)])])]),_:1}))}},Z=x(Q,[["__scopeId","data-v-56565c5c"]]);export{Z as default};
