1import{j as n,a9 as p,F as y,af as w}from"./mui-CRsYZxVY.js";import{r as u}from"./vendor-Dwao9eNC.js";import{d as h}from"./HandshakeOutlined-C4MqcgNd.js";import{u as v,w as m,d as C}from"./index-TALscxEc.js";import{a as _,b as E}from"./query-8ViTdhdk.js";import{S}from"./ShippingMethodLayout-ymqQcyVo.js";import{C as c}from"./ChoiceOption-BeWSmMeY.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./lab-DSem1Osk.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="4ad9a8be-60bc-4adb-92c8-0b5d9ff97a01",e._sentryDebugIdIdentifier="sentry-dbid-4ad9a8be-60bc-4adb-92c8-0b5d9ff97a01")})()}catch{}const j=()=>{const e=_(),{user:r}=v(),i=r==null?void 0:r.id;return E({mutationFn:async a=>{if(!i)throw new Error("Usuário não autenticado");const{data:t,error:o}=await m.from("catalogo_web").select("id").eq("user_id",i).single();if(o||!t)throw new Error((o==null?void 0:o.message)||"Catálogo web não encontrado.");const{data:d,error:l}=await m.from("catalogo_web").update({combinar_entrega_modo:a.modo}).eq("id",t.id).select("id, combinar_entrega_modo").single();if(l)throw l;return d},onMutate:async a=>{await e.cancelQueries({queryKey:["webCatalog"]});const t=e.getQueryData(["webCatalog"]);return t&&e.setQueryData(["webCatalog"],{...t,combinar_entrega_modo:a.modo}),{previousCatalog:t}},onError:(a,t,o)=>{o!=null&&o.previousCatalog&&e.setQueryData(["webCatalog"],o.previousCatalog),console.error("Erro ao atualizar modo de combinar entrega:",a)},onSettled:()=>{e.invalidateQueries({queryKey:["webCatalog"]})}})},R=()=>{const{data:e,isLoading:r}=C(),i=j(),[a,t]=u.useState(null),[o,d]=u.useState(null),[l,f]=u.useState(null);u.useEffect(()=>{if(e){const s=e.combinar_entrega_modo||"automatico";t(s),d(s)}},[e]);const g=async()=>{if(a){f(null);try{await i.mutateAsync({modo:a}),d(a)}catch(s){console.error("Failed to update mode:",s),f("Não foi possÃvel salvar. Verifique sua conexão e tente de novo.")}}},b=a!==o;return n.jsx(S,{title:"Entrega a combinar",description:"Deixa o cliente fechar o pedido e acertar a entrega com você depois",icon:n.jsx(h,{sx:{fontSize:24}}),error:l,isLoading:r,onSave:g,isSaving:i.isPending,isDirty:b&&!!a,children:n.jsx(p,{sx:{p:2},children:n.jsx(y,{component:"fieldset",disabled:i.isPending,children:n.jsxs(w,{value:a??"",onChange:s=>t(s.target.value),children:[n.jsx(c,{value:"automatico",label:"Automático (recomendado)",description:"O cliente só vê 'combinar com o vendedor' se nenhuma das suas formas de entrega servir para ele."}),n.jsx(c,{value:"habilitado",label:"Sempre mostrar",description:"A opção aparece no checkout junto com as outras formas de entrega."}),n.jsx(c,{value:"desabilitado",label:"Nunca mostrar",description:"O cliente só pode escolher entre as formas de entrega que você configurou.",warning:"Se nenhuma delas servir para o endereço dele, ele não consegue finalizar a compra."})]})})})})};export{R as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.