1import{r as h,s as v,ar as k,j as e,Q as te,aE as ge,b5 as be,b4 as ye,B as E,k as U,_ as we,ah as je,ai as ve,X as _e,aj as Ne,ak as Ce,al as Ae,am as Se,an as ke,ao as Ee,ap as Le,H as De,I as Ie,J as M,K as P,R as se,Z as Te,as as ze,$ as Re,a0 as He,a1 as Fe,a2 as qe}from"./index-BwaMfbd5.js";import{u as Me,T as Pe,L as Be,a as Oe,b as ae}from"./useLandingState-DAfEq_8l.js";import{L as Ue}from"./LandingHeatmapOverlay-ZUjWS9Hv.js";import{B as $e}from"./BrandDNAPanel-CvtKSAMl.js";import{u as Ke}from"./useWorkflow-CRCfSxkQ.js";import"./collapsible-Dzz_RMfm.js";import"./index-Cf4kKkZM.js";import"./flowbiteBlocks-B5l8pmZ7.js";import"./sanitize-mOuzlfho.js";import"./purify.es-pMfg-Su5.js";import"./index-isXfml2n.js";import"./puzzle-DSVdDzKi.js";import"./image-C5Jyz2ta.js";import"./upload-CtZ0_UDc.js";import"./undo-2-B8FYf-GK.js";import"./italic-D3BnvP73.js";import"./link-Bgtcjvrg.js";import"./list-CLBLDXqs.js";import"./scroll-area-DokqGbPN.js";import"./separator-bC_gpdbC.js";import"./switch-UgFKJqFV.js";import"./slider-CFaxvbXf.js";import"./accordion-DXkIl98Y.js";import"./paintbrush-Cw2rjOzl.js";import"./move-DyZQqNpm.js";import"./dollar-sign-AcsFX6va.js";import"./hash-a_t6bXM5.js";import"./star-CVksT-3A.js";import"./quote-CFOTwTU4.js";import"./tag-_yoyEXiO.js";import"./align-left-Bpt9yq05.js";import"./heading-CNz0t5cT.js";import"./minus-hVnJca4B.js";import"./mouse-pointer-tRr9E-Gm.js";import"./type-CfpVrT6l.js";import"./panel-left-Dl8hbVjm.js";import"./code-CuiaRzmN.js";import"./checkbox-Cmcn3Vex.js";import"./folder-open-CBoyqsFK.js";import"./file-up-BUcQEwTQ.js";import"./LandingCustomDomains-CfYaoWeg.js";import"./index-CimhTtbs.js";import"./jspdf.es.min-mTOC62qQ.js";import"./download-CIy4X3xv.js";import"./paperclip-BbndRCw8.js";import"./circle-check-big-BgY6TOzv.js";import"./mouse-pointer-click-CXMIhW8N.js";import"./calendar-BSmI-3yV.js";import"./parseICPProfiles-CAZE-I2g.js";import"./chevron-left-Dbex25-N.js";(function(){try{var w=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},c=new w.Error().stack;c&&(w._sentryDebugIds=w._sentryDebugIds||{},w._sentryDebugIds[c]="811c6f34-581b-4c1f-80de-6d8220d925c6",w._sentryDebugIdIdentifier="sentry-dbid-811c6f34-581b-4c1f-80de-6d8220d925c6")}catch{}})();const Ve=[{id:"desktop",icon:be},{id:"tablet",icon:Pe},{id:"mobile",icon:ye}];function Ut({canonicalId:w}){const{sections:c,setSections:C,landingConfig:b,setLandingConfig:ie,currentLandingId:A,projectId:p,isSaving:$,isLoading:ne,publishedUrl:_,setPublishedUrlForCurrent:re,saveLanding:K,loadLanding:V,deleteLanding:oe}=Me(),{fireEvent:le}=Ke(),G=h.useRef(null),[B,ce]=h.useState("desktop"),[de,me]=h.useState("editor"),[Q,W]=h.useState(!1),[pe,L]=h.useState(!1),[N,T]=h.useState(""),[z,R]=h.useState(!1),[H,J]=h.useState({primaryColor:"#6366F1"}),[he,O]=h.useState(!1),[ue,X]=h.useState(!1);h.useEffect(()=>{let s=!0;return O(!1),X(!1),(async()=>{const{data:l,error:a}=await v.from("landing_wireframes").select("*").eq("id",w).maybeSingle();if(s){if(a||!l){X(!0),O(!0);return}V(l),O(!0)}})(),()=>{s=!1}},[w,V]),h.useEffect(()=>{if(!p){J({primaryColor:"#6366F1"});return}(async()=>{var F,q,Y,ee;const[{data:s},{data:l},{data:a}]=await Promise.all([v.from("projects").select("brand_name, account_id").eq("id",p).single(),v.from("brand_assets").select("asset_type, file_url, metadata").eq("project_id",p),v.from("brand_dna").select("logo_url, brand_colors, colors, font_headline, font_body, fonts").eq("project_id",p).maybeSingle()]),j=l==null?void 0:l.find(o=>["logo_positive","logo_negative"].includes(o.asset_type)),y=(l==null?void 0:l.filter(o=>o.asset_type==="color_palette"))||[],u=new Set,i=[];y.forEach(o=>{const g=o.metadata,m=g==null?void 0:g.hex;if(!m||u.has(m.toLowerCase()))return;u.add(m.toLowerCase());const x=((g==null?void 0:g.name)||"").toLowerCase();let S=(g==null?void 0:g.role)||null;S||(x.includes("primari")?S="primary":x.includes("accent")?S="accent":x.includes("secundari")&&(S="secondary")),S!=="background"&&i.push({hex:m,role:S})});const n=(a==null?void 0:a.brand_colors)||(a==null?void 0:a.colors);if(n&&typeof n=="object"){const o={primario:"primary",primary:"primary",principal:"primary",secundario:"secondary",secondary:"secondary",acento:"accent",accent:"accent"},g=(m,x)=>{!m||u.has(m.toLowerCase())||(u.add(m.toLowerCase()),i.push({hex:m,role:x}
1))};Array.isArray(n)?n.forEach(m=>g(m.hex||m.value||m.color,o[(m.name||"").toLowerCase()]||null)):Object.entries(n).forEach(([m,x])=>g(typeof x=="string"?x:(x==null?void 0:x.hex)||(x==null?void 0:x.value),o[m.toLowerCase()]||null))}const t=i.find(o=>o.role==="primary")||i[0],r=i.find(o=>o.role==="secondary")||i.filter(o=>o.hex!==(t==null?void 0:t.hex))[0],d=i.find(o=>o.role==="accent")||i.filter(o=>o.hex!==(t==null?void 0:t.hex)&&o.hex!==(r==null?void 0:r.hex))[0],f=(a==null?void 0:a.font_headline)||(Array.isArray(a==null?void 0:a.fonts)?a.fonts[0]:null)||((q=(F=l==null?void 0:l.find(o=>o.asset_type==="typography"))==null?void 0:F.metadata)==null?void 0:q.font_name)||null,D=(a==null?void 0:a.font_body)||(Array.isArray(a==null?void 0:a.fonts)&&a.fonts.length>1?a.fonts[1]:null)||((ee=(Y=l==null?void 0:l.find(o=>o.asset_type==="typography"))==null?void 0:Y.metadata)==null?void 0:ee.font_name)||null;let I=(j==null?void 0:j.file_url)||(a==null?void 0:a.logo_url)||null;if(!I&&(s!=null&&s.account_id)){const{data:o}=await v.from("accounts").select("logo_url").eq("id",s.account_id).single();I=(o==null?void 0:o.logo_url)||null}J({logoUrl:I,primaryColor:(t==null?void 0:t.hex)||"#6366F1",secondaryColor:(r==null?void 0:r.hex)||null,accentColor:(d==null?void 0:d.hex)||null,fontFamily:D,headingFont:f,accountName:(s==null?void 0:s.brand_name)||null})})()},[p]);const Z=h.useCallback(async()=>{var j;if(!p||c.length===0||!N.trim())return;L(!1),R(!0);const s=N.trim(),a=/\b(agrega|agregar|crear|crea|nueva|nuevo|añade|añadir|inserta|insertar|add|create|insert)\b/i.test(s);try{if(a){const y={testimonial:"testimonials",testimonio:"testimonials",faq:"faq",preguntas:"faq",precio:"pricing_toggle",pricing:"pricing_toggle",feature:"features_checklist",caracteristica:"features_checklist",hero:"hero_centered",banner:"hero_centered",cta:"cta_lead_form",contacto:"cta_lead_form",footer:"footer_simple",about:"about",nosotros:"about",stats:"stats",estadistica:"stats",benefits:"benefits",beneficio:"benefits",comparison:"comparison",comparacion:"comparison",logo:"logos_marquee"};let u="features_checklist";for(const[d,f]of Object.entries(y))if(s.toLowerCase().includes(d)){u=f;break}const i=c.findIndex(d=>d.type.includes("footer")),n=i>=0?i:c.length,{data:t,error:r}=await v.functions.invoke("generate-landing-full-v2",{body:{project_id:p,wizard_state:{sections_order:[{block_type:u,order:0}],offer:s,pain_point:"",landing_type:"custom",persuasion_angle:""}}});if(r)throw r;if(((j=t==null?void 0:t.sections)==null?void 0:j.length)>0){const d=t.sections.filter(f=>!f.type.includes("footer")&&!f.type.includes("navbar")).map((f,D)=>({...f,id:crypto.randomUUID(),order:n+D}));d.length>0&&(C(f=>{const D=f.slice(0,n),I=f.slice(n).map((F,q)=>({...F,order:n+d.length+q}));return[...D,...d,...I]}),k({title:"⨠Secciones creadas",description:`${d.length} nueva(s) sección(es) agregada(s).`}))}}else{const y=c.filter(t=>{var r;return!["navbar","footer"].includes(t.type)&&((r=t.content)==null?void 0:r.__html)}).slice(0,5),u=c.slice(0,3).map(t=>{var r;return((r=t.content)==null?void 0:r.__html)||""}).filter(Boolean),i=await Promise.allSettled(y.map(async t=>{var f;const{data:r,error:d}=await v.functions.invoke("landing-section-copilot-v2",{body:{project_id:p,section_html:((f=t.content)==null?void 0:f.__html)||"",block_type:t.type,instruction:s,other_sections_html:u}});if(d)throw d;return{sectionId:t.id,html:r==null?void 0:r.html}})),n=new Map;i.forEach(t=>{t.status==="fulfilled"&&t.value.html&&n.set(t.value.sectionId,t.value.html)}),n.size>0?(C(t=>t.map(r=>{const d=n.get(r.id);return d?{...r,content:{...r.content,__html:d}}:r})),k({title:"⨠Edición aplicada",description:`${n.size} secciones actualizadas.`})):k({title:"Sin cambios",description:"No se pudieron aplicar los cambios."})}T("")}catch(y){console.error("Refine landing error:",y),k({title:"Error",description:y.message||"No se pudieron aplicar los cambios.",variant:"destructive"})}finally{R(!1)}},[p,c,N,C]),fe=h.useCallback(()=>{L(!0),T("Aplica los colores y tipografÃas de la marca a TODAS las secciones (botones, headings, body, backgrounds de acento).")},[]),xe=h.useMemo(()=>({seoTitle:b.seoTitle,seoDescription:b.seoDescription,ogImage:b.ogImage,customCss:b.customCss}),[b]);return he?ue||!A?e.jsxs("div",{className:"flex h-[60vh] flex-col items-center justify-center gap-2 px-6 text-center text-white/45",children:[e.jsx("p",{className:"text-[13px]",children:"No se encontró la landing."}),e.jsx("p",{className:"text-[11px] text-white/30",children:w.slice(0,8)})]}):e.jsxs("div",{className:"flex h-full flex-col overflow-x-hidden",children:[e.jsxs("div",{className:"shrink-0 space-y-3 px-5 pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-[13px] font-medium text-white/85",children:b.name||"Landing"}),e.jsxs("p",{className:"text-[11.5px] text-white/45",children:[_?"Publicada":"Borrador"," · ",c.length," secciones"]})]}),_&&e.jsxs("a",{href:_,target:"_blank",rel:"noreferrer",className:"inline-flex shrink-0 items-center gap-1 rounded-lg border border-white/10 bg-white/5 px-2.5 py-1 text-[11px] text-white/75 hover:bg-white/10",title:"Abrir preview",children:[e.jsx(ge,{className:"h-3 w-3"})," Ver"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"inline-flex items-center gap-1 rounded-lg border border-white/10 bg-white/5 p-0.5",children:Ve.map(({id:s,icon:l})=>e.jsx("button",{type:"button",onClick:()=>ce(s),className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition ${B===s?"bg-white/15 text-white":"text-white/45 hover:text-white/70"}`,title:s,children:e.jsx(l,{className:"h-3.5 w-3.5"})},s))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(E,{variant:"outline",size:"sm",className:"h-7 text-[11px]",onClick:()=>L(!0),disabled:z,children:[e.jsx(U,{className:"mr-1 h-3 w-3"})," Refinar IA"]}),e.jsx(Be,{canvasRef:G,landingName:b.name,sections:c,projectId:p,brandStyles:H,seoConfig:xe,currentLandingId:A,publishedUrl:_,onPublished:s=>{re(s),le("landing_builder.completed",{published_url:s})},onSaveLanding:K,onApplyRecommendations:async s=>{if(!(!p||c.length===0)){R(!0);try{const l=s.join(` 2`),a=c.filter(i=>!["navbar","footer"].includes(i.type)).slice(0,5),j=c.slice(0,3).map(i=>{var n;return((n=i.content)==null?void 0:n.__html)||""}
2).filter(Boolean),y=await Promise.allSettled(a.map(async i=>{var r;const{data:n,error:t}=await v.functions.invoke("landing-section-copilot-v2",{body:{project_id:p,section_html:((r=i.content)==null?void 0:r.__html)||"",block_type:i.type,instruction:l,other_sections_html:j}});if(t)throw t;return{sectionId:i.id,html:n==null?void 0:n.html}})),u=new Map;y.forEach(i=>{i.status==="fulfilled"&&i.value.html&&u.set(i.value.sectionId,i.value.html)}),u.size>0&&(C(i=>i.map(n=>{const t=u.get(n.id);return t?{...n,content:{...n.content,__html:t}}:n})),k({title:"⨠Sugerencias aplicadas",description:`${u.size} secciones optimizadas.`}))}catch(l){k({title:"Error",description:l.message||"No se pudieron aplicar las sugerencias.",variant:"destructive"})}finally{R(!1)}}}}),e.jsxs(E,{size:"sm",className:"h-7 text-[11px]",onClick:K,disabled:$,children:[e.jsx(we,{className:"mr-1 h-3 w-3"}),$?"Guardando...":"Guardar"]}),e.jsxs(je,{children:[e.jsx(ve,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon",className:"h-7 w-7 text-white/55 hover:text-red-400",children:e.jsx(_e,{className:"h-3.5 w-3.5"})})}),e.jsxs(Ne,{children:[e.jsxs(Ce,{children:[e.jsx(Ae,{children:"¿Eliminar esta landing?"}),e.jsxs(Se,{children:['Esta acción es permanente y no se puede deshacer. Se eliminará "',b.name||"Landing",'" y todo su contenido.']})]}),e.jsxs(ke,{children:[e.jsx(Ee,{children:"Cancelar"}),e.jsx(Le,{onClick:()=>A&&oe(A),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Eliminar"})]})]})]})]})]})]}),e.jsxs(De,{value:de,onValueChange:s=>me(s),className:"mt-3 flex min-h-0 flex-1 flex-col",children:[e.jsxs(Ie,{className:"mx-5 grid h-8 w-[calc(100%-2.5rem)] grid-cols-4 bg-white/5 p-0.5",children:[e.jsx(M,{value:"editor",className:"h-7 text-[11px]",children:"Editor"}),e.jsx(M,{value:"preview",className:"h-7 text-[11px]",children:"Preview"}),e.jsx(M,{value:"refine",className:"h-7 text-[11px]",children:"Refinar IA"}),e.jsx(M,{value:"heatmap",disabled:!_,className:"h-7 text-[11px]",title:_?"Heatmap":"Publicá primero la landing",children:"Heatmap"})]}),e.jsx(P,{value:"editor",className:"mt-3 min-h-0 flex-1 overflow-hidden border-t border-white/5",children:e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{className:"relative flex-1 min-h-0",children:[ne&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-background/60",children:e.jsx(te,{className:"h-5 w-5 animate-spin text-white/60"})}),e.jsx(Oe,{ref:G,sections:c,onSectionsChange:C,config:b,onConfigChange:ie,brandStyles:H,projectId:p,onApplyTheme:fe,isApplyingTheme:!1,onEditWithAI:()=>L(!0)})]}),e.jsx($e,{projectId:p||null})]})}),e.jsx(P,{value:"preview",className:"mt-3 min-h-0 flex-1 overflow-hidden border-t border-white/5",children:e.jsx(ae,{sections:c,brandStyles:H,seoConfig:b,previewDevice:B})}),e.jsx(P,{value:"refine",className:"mt-3 min-h-0 flex-1 space-y-3 overflow-auto border-t border-white/5 px-5 pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[12px] text-white/75",children:"Editar landing con IA"}),e.jsxs("p",{className:"text-[11px] text-white/45",children:['Describe el cambio. Si escribes "agrega", "crea" o "nueva sección" se genera un bloque nuevo; de lo contrario se refinan las secciones existentes vÃa'," ",e.jsx("code",{className:"rounded bg-white/10 px-1",children:"landing-section-copilot-v2"}),"."]}),e.jsx(se,{value:N,onChange:s=>T(s.target.value),placeholder:"Ej: Hazlo más minimalista, agrega una sección de testimonios, cambia los CTAs a urgencia...",className:"min-h-[140px] text-[12px]"}),e.jsx(E,{onClick:Z,disabled:N.trim().length<5||z||!p||c.length===0,className:"w-full",size:"sm",children:z?e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"mr-2 h-3.5 w-3.5 animate-spin"})," Aplicando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"mr-2 h-3.5 w-3.5"})," Aplicar cambios"]})})]})}),e.jsx(P,{value:"heatmap",className:"mt-3 min-h-0 flex-1 overflow-hidden border-t border-white/5",children:_&&A?e.jsxs("div",{className:"relative h-full",children:[e.jsxs(E,{variant:"outline",size:"sm",className:"absolute right-3 top-3 z-50 h-7 text-[11px]",onClick:()=>W(s=>!s),children:[e.jsx(ze,{className:"mr-1 h-3 w-3"})," ",Q?"Ocultar overlay":"Mostrar overlay"]}),e.jsx(ae,{sections:c,brandStyles:H,seoConfig:b,previewDevice:B}),Q&&e.jsx(Ue,{landingId:A,onClose:()=>W(!1)})]}):e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-[12px] text-white/45",children:"Publica la landing para ver el heatmap de clicks y scroll."})})]}),e.jsx(Re,{open:pe,onOpenChange:L,children:e.jsxs(He,{className:"sm:max-w-lg",children:[e.jsx(Fe,{children:e.jsx(qe,{children:"Editar Landing con IA"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(se,{value:N,onChange:s=>T(s.target.value),placeholder:"Ej: Hazlo más minimalista, agrega una sección de testimonios, crea FAQ, cambia los CTAs a urgencia...",className:"min-h-[120px] text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'La IA puede ajustar secciones existentes o crear nuevas. Escribe "agrega", "crea" o "nueva sección" para agregar bloques.'}),e.jsxs(E,{className:"w-full",disabled:N.trim().length<5||z,onClick:Z,children:[e.jsx(U,{className:"mr-2 h-4 w-4"})," Aplicar cambios"]})]})]})})]}):e.jsx("div",{className:"flex h-[60vh] items-center justify-center text-white/40",children:e.jsx(te,{className:"h-6 w-6 animate-spin"})})}
2export{Ut as default}; 3//# sourceMappingURL=LandingSheet-D1aE2T-7.js.map
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.