1import{j as e,a7 as o,T as g,ab as T,N as oe,aA as Ee,D as Ce,I as we,aE as _e,z as ke}from"./mui-CRsYZxVY.js";import{r as a}from"./vendor-Dwao9eNC.js";import{t as W,l as D,aK as Re,w as N,u as Le,b as Te,bc as Ge,d as Ae,T as re,cZ as P,cH as Be,aC as We,b3 as De}from"./index-TALscxEc.js";import{S as ae,C as Ne}from"./StoquiGemIcon-BgloFL5v.js";import{u as Oe,s as Fe}from"./useCreditoSaldo-D_DqzDIj.js";import{u as Me}from"./useQuizAnswers-CkTYG8hl.js";import{a as ie,b as qe,u as le}from"./query-8ViTdhdk.js";import{u as Pe}from"./useWebCatalogSettingsSave-Byg91ItV.js";import{F as He}from"./appearanceTokens-DaF_sGil.js";import{L as ne}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./CardGiftcard-B2-0q1Sg.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new t.Error().stack;r&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[r]="ec3774e2-7ede-486c-94ca-b3b4a885fe70",t._sentryDebugIdIdentifier="sentry-dbid-ec3774e2-7ede-486c-94ca-b3b4a885fe70")})()}catch{}async function ze(t){return(await Re.post("/image-studio/generate-logo",t)).data}function Qe(){const t=ie();return qe({mutationFn:ze,onSuccess:(r,n)=>{t.invalidateQueries({queryKey:["creditoSaldo"]}),t.invalidateQueries({queryKey:["imageStudioLogos"]}),W(D.BRAND.LOGO_GENERATE_STARTED,{style:n.style,hasInstructions:!!n.userInstructions,generationId:r.generationId})},onError:(r,n)=>{W(D.BRAND.LOGO_GENERATE_ERROR,{style:n.style,hasInstructions:!!n.userInstructions,error:r.message})}})}const Ke=async t=>{const{data:r,error:n}=await N.from("image_studio_logos").select("*").eq("id",t).single();if(n)throw console.error("[useLogoGenerationStatus] Error fetching status:",n),new Error(n.message);return r};function Ue(t,r={}){var y,w,_,I,k;const{onSuccess:n,onError:m}=r,l=ie(),c=a.useRef(!1),p=a.useRef(n),h=a.useRef(m);a.useEffect(()=>{p.current=n,h.current=m});const i=le({queryKey:["logoGenerationStatus",t],queryFn:()=>Ke(t),enabled:!!t,staleTime:5e3,refetchInterval:f=>{var x;return((x=f.state.data)==null?void 0:x.sucesso)===null?3e3:!1}});return a.useEffect(()=>{var f,x;!i.data||c.current||(i.data.sucesso===!0&&i.data.url_resultado?(c.current=!0,(f=p.current)==null||f.call(p,i.data.url_resultado)):i.data.sucesso===!1&&(c.current=!0,(x=h.current)==null||x.call(h,i.data.erro_mensagem||"Falha ao gerar logo")))},[i.data]),a.useEffect(()=>{if(!t)return;c.current=!1;const f=N.channel(`logo-generation-${t}`).on("postgres_changes",{event:"UPDATE",schema:"public",table:"image_studio_logos",filter:`id=eq.${t}`},()=>{l.invalidateQueries({queryKey:["logoGenerationStatus",t]})}).subscribe();return()=>{N.removeChannel(f)}},[t,l]),{...i,isGenerating:!!t&&((y=i.data)==null?void 0:y.sucesso)===null&&!c.current,isSuccess:((w=i.data)==null?void 0:w.sucesso)===!0,isFailed:((_=i.data)==null?void 0:_.sucesso)===!1,imageUrl:((I=i.data)==null?void 0:I.url_resultado)||null,errorMessage:((k=i.data)==null?void 0:k.erro_mensagem)||null,reset:()=>{c.current=!1}}}const Ve=20,$e=async t=>{const{data:r,error:n}=await N.from("image_studio_logos").select("*").eq("user_id",t).is("deletado_em",null).eq("sucesso",!0).not("url_resultado","is",null).order("criado_em",{ascending:!1}).limit(Ve);if(n)throw console.error("[useImageStudioLogos] Error fetching logos:",n),new Error(n.message);return r||[]},Ye=()=>{const{user:t}=Le(),r=t==null?void 0:t.id;return le({queryKey:["imageStudioLogos",r],queryFn:()=>$e(r),enabled:!!r})},Xe="/assets/moderno-Cr_TQ_t3.png",Ze="/assets/elegante-DNHiXWwk.png",Je="/assets/brincalhao-B-9ag90E.png",et="/assets/forte-DTI6-i8k.png",tt="/assets/vintage-BBTc6Bcw.png",st="/assets/natural-CBcKYDGS.png",H=5,G="#ffffff",ot=[{key:"moderno",label:"Moderno",description:"Limpo e minimalista",demoImg:Xe},{key:"elegante",label:"Elegante",description:"Sofisticado e refinado",demoImg:Ze},{key:"brincalhao",label:"Brincalhão",description:"Divertido e amigável",demoImg:Je},{key:"forte",label:"Forte",description:"Marcante e impactante",demoImg:et},{key:"vintage",label:"Vintage",description:"Clássico e retrô",demoImg:tt},{key:"natural",label:"Natural",description:"Orgânico e suave",demoImg:st}],A=["Esboçando o conceito...","Desenhando o sÃmbolo...","Compondo a tipografia...","Ajustando o equilÃbrio...","Refinando os detalhes...","Limpando o fundo transparente...","Quase pronto...","Quase pronto..."],ht=()=>{var Z,J,ee,te,se;const t=Te(),{isDesktop:r,drawerWidth:n}=Ge(),{data:m}=Oe(),{data:l}=Ae(),{data:c}=Me(),{data:p}=Ye(),{save:h}=Pe(),i=Qe(),y=(m==null?void 0:m.saldo)??0,w=y>=H,_=((Z=l==null?void 0:l.nome_loja)==null?void 0:Z.trim())||"",I=((J=l==null?void 0:l.cor_principal)==null?void 0:J.trim())||He,k=((ee=l==null?void 0:l.descricao)==null?void 0:ee.trim())||"",f=((te=c==null?void 0:c.segmento)==null?void 0:te.trim())||((se=c==null?void 0:c.segment)==null?void 0:se.trim())||"",[x,ce]=a.useState("moderno"),[O,de]=a.useState(""),[z,S]=a.useState(null),[b,R]=a.use
1State(null),[E,j]=a.useState(!1),[ue,v]=a.useState(!1),[ge,L]=a.useState(!1),[Q,C]=a.useState(null),[me,K]=a.useState(A[0]),[pe,U]=a.useState(0),[xe,F]=a.useState(!1),[fe,M]=a.useState(!1),[he,V]=a.useState(!1),[be,$]=a.useState(!1),Y=Ue(z,{onSuccess:async s=>{R(s),S(null),W(D.BRAND.LOGO_GENERATE_SUCCESS,{generationId:z,style:x});const d=new Image;d.src=s,await new Promise(u=>{d.onload=()=>u(),d.onerror=()=>u()}),L(!0),j(!1),v(!1)},onError:s=>{S(null),j(!1),v(!1),C(s)}});a.useEffect(()=>{if(!E){v(!1);return}const s=setTimeout(()=>v(!0),2e4);return()=>clearTimeout(s)},[E]),a.useEffect(()=>{if(!E)return;let s=0,d=0;const u=setInterval(()=>{s+=500;const Se=100*(1-Math.exp(-s/15e3));U(Math.min(Math.round(Se/5)*5,95))},500),q=setInterval(()=>{d=(d+1)%A.length,K(A[d])},3500);return()=>{clearInterval(u),clearInterval(q),U(0),K(A[0])}},[E]);const ye=async()=>{var s,d;if(!w){M(!0),F(!0);return}C(null),R(null),L(!1),j(!0);try{const u=await i.mutateAsync({style:x,userInstructions:O.trim()||void 0});S(u.generationId)}catch(u){j(!1);const q=((d=(s=u==null?void 0:u.response)==null?void 0:s.data)==null?void 0:d.error)||(u instanceof Error&&!u.message.includes("status code")?u.message:"Erro ao gerar logo. Tente novamente.");C(q)}},X=()=>{L(!1),R(null),S(null),j(!1),v(!1),Y.reset(),i.reset()},je=a.useCallback(async()=>{if(b){V(!0);try{await h({logo_url:b},"ai_logo_apply"),W(D.BRAND.LOGO_GENERATE_APPLIED,{url:b}),$(!0),setTimeout(()=>{window.history.length>1?t(-1):t("/profile/store-appearance/brand",{replace:!0})},800)}catch{C("Não foi possÃvel aplicar o logo. Tente novamente.")}finally{V(!1)}}},[b,h,t]),ve=()=>{S(null),j(!1),v(!1),Y.reset(),i.reset()},Ie=s=>{R(s),L(!0)};return ge&&b?e.jsxs(o,{sx:{position:"relative",minHeight:"100%",pb:4},children:[e.jsx(re,{title:"Logo gerado",navigateBack:!0,onBack:X}),e.jsxs(o,{sx:{px:2,py:2},children:[e.jsx(o,{sx:{width:"100%",maxWidth:480,mx:"auto",aspectRatio:"3 / 2",borderRadius:2,bgcolor:G,border:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",p:3},children:e.jsx(o,{component:"img",src:b,alt:"Logo gerado",sx:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"}})}),e.jsx(g,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5},children:"O logo tem fundo transparente - você está vendo ele sobre o branco da sua loja."}),e.jsxs(T,{spacing:1.5,sx:{mt:3,maxWidth:480,mx:"auto"},children:[e.jsx(ne,{variant:"contained",size:"large",loading:he,onClick:je,sx:{borderRadius:2,py:1.5},children:"Usar como logo da loja"}),e.jsxs(oe,{variant:"contained",color:"secondary",size:"large",onClick:X,startIcon:e.jsx(P,{}),sx:{borderRadius:2,py:1.5},children:["Gerar outro (",H," ",e.jsx(o,{component:"span",sx:{display:"inline-flex",alignItems:"center",mx:.5},children:e.jsx(ae,{sx:{fontSize:16}})}),")"]}),e.jsx(oe,{variant:"text",size:"large",component:"a",href:b,download:"logo.png",target:"_blank",startIcon:e.jsx(Be,{}),children:"Baixar PNG"})]})]}),e.jsx(Ee,{open:be,autoHideDuration:2e3,onClose:()=>$(!1),message:"Logo aplicado à sua loja",anchorOrigin:{vertical:"bottom",horizontal:"center"}})]}):E?e.jsxs(o,{sx:{position:"fixed",inset:0,left:r?`${n}px`:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",bgcolor:"background.default",p:3,overflow:"hidden"},children:[e.jsx(Ce,{in:ue,children:e.jsx(we,{onClick:ve,sx:{position:"absolute",top:16,right:16,bgcolor:"grey.100","&:hover":{bgcolor:"grey.200"}},children:e.jsx(We,{})})}),e.jsx(o,{sx:{width:200,height:200,borderRadius:4,mb:3,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:G,border:"3px solid",borderColor:"primary.main",animation:"pulse 2s ease-in-out infinite","@keyframes pulse":{"0%, 100%":{opacity:.7,transform:"scale(0.98)"},"50%":{opacity:1,transform:"scale(1.02)"}}},children:e.jsx(P,{style:{fontSize:60,color:"#8865FE",animation:"spin 2s linear infinite"}})}),e.jsx(g,{variant:"h6",fontWeight:500,gutterBottom:!0,children:me}),e.jsx(o,{sx:{width:"100%",maxWidth:300},children:e.jsx(_e,{variant:"determinate",value:pe,sx:{height:6,borderRadius:3}})}),e.jsx(g,{variant:"caption",color:"text.secondary",sx:{mt:2},children:"Pode levar até 1 minuto."})]}):e.jsxs(o,{sx:{position:"relative",minHeight:"100%",pb:14}
1,children:[e.jsx(re,{title:"Criar logo com IA",navigateBack:!0,children:e.jsxs(o,{onClick:()=>{M(!1),F(!0)},sx:{display:"flex",alignItems:"center",gap:.5,px:1.25,py:.5,borderRadius:999,bgcolor:"rgba(136, 101, 254, 0.1)",cursor:"pointer"},children:[e.jsx(o,{component:"img",src:Fe,alt:"Créditos",sx:{width:20,height:20}}),e.jsx(g,{variant:"body2",fontWeight:700,children:y})]})}),e.jsx(o,{sx:{px:2,py:2},children:e.jsxs(T,{spacing:2,children:[Q&&e.jsx(De,{severity:"error",onClose:()=>C(null),children:Q}),e.jsxs(o,{sx:{bgcolor:"white",borderRadius:2,p:2},children:[e.jsx(g,{variant:"caption",color:"text.secondary",sx:{display:"block",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em",mb:1.5},children:"A IA vai usar estas informações da sua loja"}),e.jsxs(T,{spacing:1.5,children:[e.jsx(B,{label:"Nome",value:_,emptyText:"Não definido"}),e.jsx(B,{label:"Segmento",value:f,emptyText:"Não definido"}),e.jsx(B,{label:"Cor",value:I,colorSwatch:I}),e.jsx(B,{label:"Descrição",value:k,emptyText:"Não definida",multiline:!0})]})]}),e.jsxs(o,{sx:{bgcolor:"white",borderRadius:2,p:2},children:[e.jsx(g,{variant:"body1",sx:{fontWeight:600,mb:1.5},children:"Escolha um estilo"}),e.jsx(T,{spacing:1,children:ot.map(s=>{const d=x===s.key;return e.jsxs(o,{onClick:()=>ce(s.key),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.25,borderRadius:2,cursor:"pointer",bgcolor:d?"primary.50":"grey.50",border:"2px solid",borderColor:d?"primary.main":"transparent",transition:"all 0.15s"},children:[e.jsx(o,{sx:{flexShrink:0,width:120,height:60,bgcolor:G,borderRadius:1,border:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"center",p:.75},children:e.jsx(o,{component:"img",src:s.demoImg,alt:`Exemplo do estilo ${s.label}`,sx:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"}})}),e.jsxs(o,{sx:{minWidth:0,flex:1},children:[e.jsx(g,{variant:"body2",fontWeight:600,children:s.label}),e.jsx(g,{variant:"caption",color:"text.secondary",sx:{display:"block"},children:s.description})]})]},s.key)})})]}),e.jsxs(o,{sx:{bgcolor:"white",borderRadius:2,p:2},children:[e.jsxs(g,{variant:"body1",sx:{fontWeight:600,mb:1.5},children:["Instruções extras"," ",e.jsx(g,{component:"span",variant:"caption",color:"text.secondary",children:"(opcional)"})]}),e.jsx(ke,{fullWidth:!0,size:"small",multiline:!0,rows:3,value:O,onChange:s=>de(s.target.value.slice(0,500)),placeholder:"Ex: prefiro sÃmbolo de pão, evite fontes muito modernas",inputProps:{maxLength:500},helperText:`${O.length}/500`})]}),p&&p.length>0&&e.jsxs(o,{sx:{bgcolor:"white",borderRadius:2,p:2},children:[e.jsx(g,{variant:"body1",sx:{fontWeight:600,mb:1.5},children:"Logos gerados anteriormente"}),e.jsx(o,{sx:{display:"flex",gap:1,overflowX:"auto",pb:1,"&::-webkit-scrollbar":{display:"none"}},children:p.map(s=>s.url_resultado?e.jsx(o,{onClick:()=>Ie(s.url_resultado),sx:{flexShrink:0,width:140,height:90,borderRadius:1.5,bgcolor:G,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",p:1,border:"1px solid",borderColor:"divider"},children:e.jsx(o,{component:"img",src:s.url_resultado,alt:"Logo anterior",sx:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain"}})},s.id):null)})]})]})}),e.jsx(o,{sx:{position:"fixed",bottom:0,left:r?`${n}px`:0,right:0,bgcolor:"white",borderTop:"1px solid",borderColor:"divider",p:1.5,pb:"calc(0.75rem + var(--safe-area-inset-bottom, 0px))",zIndex:5},children:e.jsxs(ne,{variant:"contained",fullWidth:!0,size:"large",loading:i.isPending,onClick:ye,startIcon:e.jsx(P,{}),sx:{borderRadius:2,py:1.5},children:["Gerar logo (",H," ",e.jsx(o,{component:"span",sx:{display:"inline-flex",alignItems:"center",ml:.5},children:e.jsx(ae,{sx:{fontSize:16}})}),")"]})}),e.jsx(Ne,{open:xe,onClose:()=>{F(!1),M(!1)},saldo:y,onViewExtrato:()=>t("/image-studio/credits"),onViewFreeCredits:()=>t("/image-studio/free-credits"),insufficientCredits:fe})]})},B=({label:t,value:r,emptyText:n,colorSwatch:m,multiline:l})=>{const c=!r,p=r||n||"";return e.jsxs(o,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(g,{variant:"body2",sx:{minWidth:84,color:"text.secondary",pt:m?.25:0},children:t}),e.jsxs(o,{sx:{flex:1,display:"flex",alignItems:"center",gap:1,minWidth:0},children:[m&&e.jsx(o,{sx:{width:18,height:18,borderRadius:.5,backgroundColor:m,flexShrink:0,border:"1px solid",borderColor:"divider"}}),e.jsx(g,{variant:"body2",sx:{color:c?"text.disabled":"text.primary",fontWeight:c?400:500,overflow:"hidden",textOverflow:"ellipsis",display:l?"-webkit-box":"block",WebkitLineClamp:l?2:void 0,WebkitBoxOrient:l?"vertical":void 0,whiteSpace:l?"normal":"nowrap",flex:1,minWidth:0},children:p})]})]})};export{ht 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.