import{_ as B,a as C,r as i,Q as h,R as f,n as M,S as R,I as k,U as E,f as y,i as P,o as l,b as s,c as p,F as L,s as U,d as _,A as F,V as w,W as V,t as b,w as O,e as G,v as z,g as A,x as H}from"./index-fMk6vrHi.js";import{A as W}from"./AdminLayout-B5eELyPq.js";import{E as q}from"./ErrorMessage-j4vVfFqf.js";import{L as J}from"./LoadingSpinner-Dm7-gPt-.js";import"./LogoutButton-DoDfzffD.js";const Q={class:"card settings-card theme-card"},$={class:"theme-grid",role:"radiogroup","aria-label":"Paleta de colores"},K=["aria-checked","onClick"],X={class:"theme-swatches"},Y={class:"theme-label"},Z={class:"theme-desc"},ee={class:"card settings-card"},se={class:"settings-grid"},ae={class:"preview-box"},te=["src","alt"],oe={class:"preview-name"},le={class:"input-group"},ne={class:"input-group"},ie={key:0,class:"success-text"},re=["disabled"],ue={key:1},ce={__name:"AjustesView",setup(de){const u=C(),c=i(!1),d=i(""),v=i(""),o=i(u.businessName),m=i(u.logoUrl),g=i(null),r=i(""),n=i(f.includes(u.themeId)?u.themeId:h),j=H(()=>r.value||m.value||"/logo.png");function x(a){n.value=a,E(a)}M(async()=>{await T()}),R(()=>{r.value&&URL.revokeObjectURL(r.value)});const T=async()=>{c.value=!0,d.value="";try{const a=await k.getSettings();o.value=a.data.business_name||"Barbería DIAICR",m.value=a.data.logo_url||"/logo.png";const e=a.data.theme_id||h;n.value=f.includes(e)?e:h,E(n.value),u.applySettings({business_name:o.value,logo_url:m.value,theme_id:n.value})}catch(a){d.value=a.response?.data?.message||"No se pudieron cargar los ajustes."}finally{c.value=!1}},D=a=>{const e=a.target.files?.[0]||null;g.value=e,r.value&&(URL.revokeObjectURL(r.value),r.value=""),e&&(r.value=URL.createObjectURL(e))},I=async()=>{c.value=!0,d.value="",v.value="";try{const a=new FormData;a.append("business_name",o.value),a.append("theme_id",n.value),g.value&&a.append("logo",g.value);const e=await k.updateSettings(a);v.value=e.data?.message||"Ajustes actualizados correctamente.",m.value=e.data?.settings?.logo_url||m.value,o.value=e.data?.settings?.business_name||o.value;const t=e.data?.settings||{};t.theme_id&&(n.value=t.theme_id),u.applySettings(t),g.value=null}catch(a){const e=a.response?.data?.errors?Object.values(a.response.data.errors)?.[0]?.[0]:"";d.value=e||a.response?.data?.message||"No se pudieron guardar los ajustes."}finally{c.value=!1}};return(a,e)=>(l(),y(W,null,{default:P(()=>[e[5]||(e[5]=s("h2",{style:{margin:"0 0 20px 0"}},"Ajustes App",-1)),e[6]||(e[6]=s("p",{class:"title-sm",style:{"margin-top":"0"}},"Nombre del negocio e imagen principal",-1)),s("div",Q,[e[1]||(e[1]=s("p",{class:"section-title"},"Paleta de colores",-1)),e[2]||(e[2]=s("p",{class:"section-hint"},"Elegí un tema para toda la app (clientes, barberos y admin). Guardá cambios para aplicarlo en todos los dispositivos.",-1)),s("div",$,[(l(!0),p(L,null,U(_(f),t=>(l(),p("button",{key:t,type:"button",class:F(["theme-option",{selected:n.value===t}]),"aria-checked":n.value===t,role:"radio",onClick:S=>x(t)},[s("span",X,[(l(!0),p(L,null,U(_(w)[t].swatch,(S,N)=>(l(),p("span",{key:N,class:"swatch",style:V({background:S})},null,4))),128))]),s("span",Y,b(_(w)[t].label),1),s("span",Z,b(_(w)[t].description),1)],10,K))),128))])]),s("div",ee,[s("div",se,[s("div",ae,[s("img",{src:j.value,alt:o.value,class:"logo-preview"},null,8,te),s("p",oe,b(o.value),1)]),s("form",{class:"settings-form",onSubmit:O(I,["prevent"])},[s("div",le,[e[3]||(e[3]=s("label",{for:"business_name"},"Nombre del negocio",-1)),G(s("input",{id:"business_name","onUpdate:modelValue":e[0]||(e[0]=t=>o.value=t),type:"text",class:"input-control",maxlength:"120",required:""},null,512),[[z,o.value]])]),s("div",ne,[e[4]||(e[4]=s("label",{for:"logo"},"Logo (JPG/PNG/WEBP, máx 2MB)",-1)),s("input",{id:"logo",type:"file",class:"input-control",accept:"image/png,image/jpeg,image/webp",onChange:D},null,32)]),v.value?(l(),p("p",ie,b(v.value),1)):A("",!0),d.value?(l(),y(q,{key:1,message:d.value},null,8,["message"])):A("",!0),s("button",{type:"submit",class:"btn btn-gold",disabled:c.value},[c.value?(l(),y(J,{key:0})):(l(),p("span",ue,"Guardar cambios"))],8,re)],32)])])]),_:1}))}},be=B(ce,[["__scopeId","data-v-98b3a63d"]]);export{be as default};
