1import{j as a,a9 as k,ab as v,a7 as m,T as u,q as B,af as N,ag as j,ah as S,z as O,ae as P}from"./mui-CRsYZxVY.js";import{b as w}from"./vendor-Dwao9eNC.js";import{u as Q,w as z,y as M,bx as L,by as W,z as T,b as V,eE as H,C as K,F as Y,D as b,Q as G}from"./index-TALscxEc.js";import{u as U,d as X}from"./useFreeShipping-DzZ_rItv.js";import{a as J,b as Z}from"./query-8ViTdhdk.js";import{H as ee}from"./HelperText-CbfuMRy9.js";import{C as ae}from"./CheckoutRequirementAlert-CTmXyGW6.js";import{S as re}from"./ShippingMethodLayout-ymqQcyVo.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./lab-DSem1Osk.js";import"./HelpOutline-7HiWCqx6.js";import"./useWebCatalogSettingsSave-Byg91ItV.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};o.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var o=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new o.Error().stack;
1n&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[n]="c51e3164-189c-4796-abc2-15f52e79579d",o._sentryDebugIdIdentifier="sentry-dbid-c51e3164-189c-4796-abc2-15f52e79579d")})()}catch{}const oe=()=>{const o=J(),{user:n}=Q(),c=n==null?void 0:n.id;return Z({mutationFn:async r=>{if(!c)throw new Error("Not authenticated");const{data:s}=await z.from("configuracao_frete_gratis").select("id").eq("user_id",c).single();if(s){const{data:e,error:d}=await z.from("configuracao_frete_gratis").update({habilitado:r.habilitado,valor_minimo:r.valor_minimo,abrangencia:r.abrangencia,prazo_entrega:r.prazo_entrega||null,ocultar_outras_opcoes:r.ocultar_outras_opcoes,atualizado_em:new Date().toISOString()}).eq("id",s.id).select().single();if(d)throw d;return e}else{const{data:e,error:d}=await z.from("configuracao_frete_gratis").insert({user_id:c,habilitado:r.habilitado,valor_minimo:r.valor_minimo,abrangencia:r.abrangencia,prazo_entrega:r.prazo_entrega||null,ocultar_outras_opcoes:r.ocultar_outras_opcoes}).select().single();if(d)throw d;return e}},onMutate:async r=>{await o.cancelQueries({queryKey:["freeShipping"]});const s=o.getQueryData(["freeShipping"]);return s?o.setQueryData(["freeShipping"],{...s,...r,atualizado_em:new Date().toISOString()}):o.setQueryData(["freeShipping"],{id:-1,...r,prazo_entrega:r.prazo_entrega||null,criado_em:new Date().toISOString(),atualizado_em:new Date().toISOString()}),{previousConfig:s}},onError:(r,s,e)=>{e!=null&&e.previousConfig&&o.setQueryData(["freeShipping"],e.previousConfig)},onSettled:()=>{o.invalidateQueries({queryKey:["freeShipping"]})}})},te=M().shape({habilitado:L().required(),valor_minimo:W().transform(o=>isNaN(o)?0:o).min(0,"O valor mÃnimo deve ser maior ou igual a zero").required("O valor mÃnimo é obrigatório"),abrangencia:T().oneOf(["todos","cidade","estado"],"Abrangência inválida").required("A abrangência é obrigatória"),prazo_entrega:T().transform(o=>{if(!o)return o;const n=o.trim();return/^\d+$/.test(n)?`${n} dias úteis`:n}).max(25,"Prazo de entrega deve ter no máximo 25 caracteres").optional(),ocultar_outras_opcoes:L().required()}),x={fontWeight:600,color:"text.secondary",fontSize:"0.8rem",display:"block",mb:.75},be=()=>{const o=V(),[n,c]=w.useState(null),{data:r,isLoading:s}=H(),{data:e,isLoading:d}=U(),g=oe(),{control:p,handleSubmit:A,watch:y,reset:f,formState:{errors:h}}=K({resolver:Y(te),defaultValues:{habilitado:(e==null?void 0:e.habilitado)||!1,abrangencia:(e==null?void 0:e.abrangencia)||"todos",valor_minimo:Number(e==null?void 0:e.valor_minimo)||void 0,prazo_entrega:(e==null?void 0:e.prazo_entrega)||"",ocultar_outras_opcoes:(e==null?void 0:e.ocultar_outras_opcoes)||!1}});w.useEffect(()=>{e&&f({habilitado:e.habilitado,valor_minimo:e.valor_minimo,abrangencia:e.abrangencia,prazo_entrega:e.prazo_entrega||"",ocultar_outras_opcoes:e.ocultar_outras_opcoes})},[e,f]);const l=y(),E=l.habilitado,_=l.abrangencia,D=!!r,q=_==="cidade"||_==="estado",F=w.useMemo(()=>e?Number(l.valor_minimo??0)!==Number(e.valor_minimo??0)||(l.abrangencia??"todos")!==(e.abrangencia??"todos")||(l.prazo_entrega??"")!==(e.prazo_entrega??"")||!!l.ocultar_outras_opcoes!=!!e.ocultar_outras_opcoes:!1,[l,e]),R=async t=>{try{c(null),await g.mutateAsync(t),f(t)}catch(i){c(i instanceof Error?i.message:"Erro ao salvar configurações")}},$=async t=>{const i={...y(),habilitado:t};try{c(null),await g.mutateAsync(i),f(i)}catch(I){c(I instanceof Error?I.message:"Erro ao atualizar configuração")}},C=(()=>{const t=Number(y("valor_minimo"))||0,i=_==="cidade"?(r==null?void 0:r.localidade)||"sua cidade":_==="estado"?(r==null?void 0:r.uf)||"seu estado":"todo o Brasil";return t>0?`Acima de ${t.toLocaleString("pt-BR",{style:"currency",currency:"BRL"})} para ${i}`:`Para ${i}`})();return a.jsxs(re,{title:"Frete grátis",description:"Ofereça entrega sem custo a partir de um valor de compra",icon:a.jsx(X,{sx:{fontSize:24}}),enabled:E,onToggle:$,isToggling:g.isPending,enabledSummary:C,requiresAddress:q,hasAddress:D,error:n,isLoading:s||d,onSave:A(R),isSaving:g.isPending,isDirty:F,children:[E&&q&&a.jsx(ae,{requirement:"cep",children:"Você limitou o frete grátis por região. à o CEP que identifica a cidade e o estado do cliente, então deixá-lo obrigatório no checkout faz a regra valer para todos os clientes."}),a.jsx(k,{sx:{p:2},children:a.jsxs(v,{spacing:3,children:[a.jsx(b,{name:"valor_minimo",control:p,render:({field:t})=>{var i;return a.jsxs(m,{children:[a.jsx(u,{sx:x,children:"Valor mÃnimo do pedido"}),a.jsx(G,{fullWidth:!0,variant:"outlined",error:!!h.valor_minimo,helperText:(i=h.valor_minimo)==null?void 0:i.message,InputProps:{startAdornment:a.jsx(B,{position:"start",children:"R$"})},placeholder:"0,00",...t})]})}}),a.jsxs(m,{children:[a.jsx(u,{sx:x,children:"Região de entrega"}),a.jsx(b,{name:"abrangencia",control:p,render:({field:t})=>
1a.jsxs(N,{...t,sx:{"& .MuiFormControlLabel-root":{marginY:.25}},children:[a.jsx(j,{value:"todos",control:a.jsx(S,{}),label:"Todo o Brasil"}),a.jsx(j,{value:"cidade",control:a.jsx(S,{}),label:r!=null&&r.localidade?`Apenas para minha cidade (${r.localidade})`:"Apenas para minha cidade"}),a.jsx(j,{value:"estado",control:a.jsx(S,{}),label:r!=null&&r.uf?`Apenas para meu estado (${r.uf})`:"Apenas para meu estado"})]})}),!D&&a.jsxs(u,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:.5},children:["Configure o"," ",a.jsx(m,{component:"span",onClick:()=>o("/profile/shipping/address"),sx:{color:"primary.main",fontWeight:600,cursor:"pointer",textDecoration:"underline"},children:"endereço de origem"})," ","para limitar por cidade ou estado."]})]}),a.jsxs(m,{children:[a.jsxs(v,{direction:"row",alignItems:"center",spacing:.5,children:[a.jsx(u,{sx:x,children:"Prazo de entrega (opcional)"}),a.jsx(ee,{text:'Ex: "2 a 3 dias úteis", "Até 5 dias", "24 horas". Deixe em branco se não quiser especificar um prazo.'})]}),a.jsx(b,{name:"prazo_entrega",control:p,render:({field:t})=>{var i;return a.jsx(O,{...t,fullWidth:!0,placeholder:'Ex: "2 a 3 dias úteis"',error:!!h.prazo_entrega,helperText:(i=h.prazo_entrega)==null?void 0:i.message,inputProps:{maxLength:25}})}})]}),a.jsxs(m,{children:[a.jsxs(v,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:1,children:[a.jsx(u,{sx:{...x,mb:0},children:"Ocultar outras opções de frete"}),a.jsx(b,{name:"ocultar_outras_opcoes",control:p,render:({field:t})=>a.jsx(P,{checked:t.value,onChange:i=>t.onChange(i.target.checked),color:"primary"})})]}),a.jsx(u,{variant:"caption",color:"text.secondary",children:"Quando o pedido tem direito a frete grátis, mostramos só o frete grátis no checkout. A retirada na loja continua aparecendo quando disponÃvel."})]})]})})]})};export{be 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.