1import{a as ge,i as pe,r as d,s as k,j as e,o as K,X as he,b as O,u as xe}from"./index-IZnvRumJ.js";import{c as de}from"./AppLayout-cVkycFLS.js";import{D as X,m as ce,r as ue,R as y}from"./rmLandingDefaults-D56neh4C.js";import{g as fe,R as be}from"./index-92JMiZHI.js";import{A as ve,a as M,b as E,c as q}from"./accordion-CeYNu0QT.js";import{I as oe}from"./input-OGCcGVWJ.js";import{T as je}from"./textarea-DxyUVnlT.js";import{L as Q}from"./label-CoGXWevP.js";import{S as ye,a as we,b as _e,c as Ne,d as Ce}from"./select-Ds0eJjSi.js";import{B as R}from"./button-DcP8iMA9.js";import{A as J,a as Z,b as ee,c as te,d as re,e as se,f as ie,g as ae,h as Se}from"./alert-dialog-BrhGOoeP.js";import{M as me}from"./map-pin-DnrJ1CPl.js";import{V as ke}from"./video-C3g5KoEe.js";import Le from"./MatchupAgencyLanding-CRoE8ftS.js";import{S as Ae,P as Pe}from"./PreviewFrame-Blu2qGA5.js";import{u as Re}from"./useAgencyReportSettings-lO-rLMur.js";import{E as De}from"./external-link-1LE5Lgze.js";import{U as Te}from"./undo-2-q5HSp3wM.js";import{S as $e}from"./save-DfjnIQEE.js";import{R as Ie}from"./rocket-CGVlk8C7.js";import{M as Me}from"./monitor-B-BovwvK.js";import"./sheet-zYE83Wug.js";import"./index-MH1WVYsB.js";import"./skeleton-D7D6JDZR.js";import"./mysteryShopperBrand-BYkn7pdw.js";import"./mysterycallai-logo-dark-BFNFGS3B.js";import"./useTier-BULoQlR6.js";import"./dropdown-menu-DqOrHu2j.js";import"./index-BmRzOyoq.js";import"./index-BlZBv0Jc.js";import"./chevron-right-QiugxkLR.js";import"./check-C2pnSUS4.js";import"./chevron-down-1nMbKwc_.js";import"./chart-column-CsqJFWcn.js";import"./bot-BQdRaamy.js";import"./target-tsid7M2N.js";import"./swords-CyoFjmFq.js";import"./file-pen-line-DkW7k01H.js";import"./calculator-Pwff5vj0.js";import"./phone-call-Dm3n_iYk.js";import"./useQuery-DHnKGTyB.js";import"./users-HfDtNntb.js";import"./circle-x-Bkg0PfRg.js";import"./triangle-alert-B8sOFBAg.js";import"./lpInvoke-Ds_Z-Vno.js";import"./circle-check-CJPteXk5.js";import"./shield-ebKOM8r4.js";import"./building-2-TavQYcI3.js";import"./mail-Rp6evAGI.js";import"./credit-card-Dge_IzRx.js";import"./crown-CGzwbtTd.js";import"./file-text-CZEMuyyH.js";import"./search-9X0la83E.js";import"./trending-up-DZRNf4zr.js";import"./circle-plus-HJRNrV0j.js";import"./eye-BaRUKt7b.js";import"./globe-CwLKkDOx.js";import"./lightbulb-uxg2Rvra.js";import"./graduation-cap-25AkShwK.js";import"./palette-D2KBmLK0.js";import"./layout-dashboard-D4Xc7vFm.js";import"./book-open-C7ggllaI.js";import"./circle-help-LlvxE_IR.js";import"./dialog-RI8CE1mU.js";import"./plus-GBlIdfW8.js";import"./types-C-jxggw2.js";import"./arrow-right-C8S3duny.js";import"./publicUrl-bjBORCqm.js";import"./index-DOilG4jg.js";import"./index-DyIwh2Qx.js";import"./chevron-up-CcQezlK8.js";import"./PublicMatchupWizard-Bpd6H2DW.js";import"./ConfirmStep-dZ8yXLYo.js";import"./card-BWWzAZHh.js";import"./BusinessAutocomplete-DdsHfiVR.js";import"./arrow-left-CTczkdMm.js";import"./link-2-B0o0W-h3.js";import"./star-CwoKc1EO.js";import"./checkbox-BIUDIIoO.js";import"./edgeFunctionErrors-CMGmz3ks.js";import"./PublicProcessingStep-Cj5BagIx.js";import"./sparkles-C4440FS9.js";import"./lock-6mO0Wzd6.js";import"./shield-check-BqO_y0NL.js";import"./usePublicPageView-Dto8ub7a.js";import"./quote-D-ed04DH.js";import"./zap-BJhwTE2I.js";import"./clock-CgINlRZu.js";function Ee(){const{toast:i}=ge(),{agencyId:o,loading:s}
1=pe(),[u,n]=d.useState(!0),[c,b]=d.useState(!1),[t,l]=d.useState(!1),[a,j]=d.useState(null),[g,x]=d.useState(X),[C,m]=d.useState(X),[h,L]=d.useState(null),[_,B]=d.useState(null),[P,W]=d.useState(""),[T,V]=d.useState(null),[$,N]=d.useState(!1),S=d.useCallback(async()=>{if(o){n(!0);try{const{data:r,error:f}=await k.from("report_settings").select("id, rm_landing_copy_draft, rm_landing_copy_published, rm_landing_niche, rm_landing_location, rm_landing_updated_at, matchup_video_url").eq("agency_id",o).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(f)throw f;j((r==null?void 0:r.id)??null);const p=ce((r==null?void 0:r.rm_landing_copy_published)??null),A=ce((r==null?void 0:r.rm_landing_copy_draft)??(r==null?void 0:r.rm_landing_copy_published)??null);m(p),x(A),L((r==null?void 0:r.rm_landing_niche)??null),B((r==null?void 0:r.rm_landing_location)??null),W((r==null?void 0:r.matchup_video_url)??""),V((r==null?void 0:r.rm_landing_updated_at)??null),N(!1)}catch(r){console.error("[useRMLandingEditor] load error",r),i({title:"Failed to load landing page",description:r.message,variant:"destructive"})}finally{n(!1)}}},[o,i]);d.useEffect(()=>{!s&&o&&S()},[o,s,S]);const F=d.useCallback(r=>{x(f=>{const p=r(f);return N(!0),p})},[]),H=d.useCallback(r=>{const f=fe(r);f&&(x(f.copy),L(r),N(!0),i({title:`Applied "${f.label}" template`,description:"Review the changes, then click Publish to make them live."}))},[i]),I=d.useCallback(r=>{B(r),N(!0)},[]),U=d.useCallback(r=>{W(r),N(!0)},[]),Y=d.useCallback(()=>{x(X),L(null),N(!0)},[]),z=d.useCallback(()=>{x(C),N(!1)},[C]),D=d.useCallback(async()=>{if(a)return a;if(!o)return null;const{data:r}=await k.from("report_settings").select("id").eq("agency_id",o).limit(1).maybeSingle();if(r!=null&&r.id)return j(r.id),r.id;const{data:f,error:p}=await k.from("report_settings").insert({agency_id:o}).select("id").single();if(p)throw p;return j(f.id),f.id},[o,a]),v=d.useCallback(async()=>{var f;if(!o)return!1;const r=ue.safeParse(g);if(!r.success)return i({title:"Please fix validation errors",description:((f=r.error.issues[0])==null?void 0:f.message)??"Some fields are too long or empty.",variant:"destructive"}),!1;b(!0);try{const p=await D();if(!p)throw new Error("Could not resolve settings row");const{error:A}=await k.from("report_settings").update({rm_landing_copy_draft:r.data,rm_landing_niche:h,rm_landing_location:_,matchup_video_url:P.trim()||null}).eq("id",p);if(A)throw A;return N(!1),i({title:"Draft saved",description:"Your changes are safe. Nothing on the live page changed."}),!0}catch(p){return console.error("[useRMLandingEditor] saveDraft error",p),i({title:"Save failed",description:p.message,variant:"destructive"}),!1}finally{b(!1)}},[o,g,h,_,P,D,i]),G=d.useCallback(async()=>{var f;if(!o)return!1;const r=ue.safeParse(g);if(!r.success)return i({title:"Cannot publish â validation errors",description:((f=r.error.issues[0])==null?void 0:f.message)??"Fix the highlighted fields.",variant:"destructive"}),!1;l(!0);try{const p=await D();if(!p)throw new Error("Could not resolve settings row");const{data:A}=await k.from("report_settings").select("rm_landing_updated_at").eq("id",p).maybeSingle();if(((A==null?void 0:A.rm_landing_updated_at)??null)!==T)return i({title:"Someone else published first",description:"Reload to see the latest published version before publishing again.",variant:"destructive"}),!1;const ne=new Date().toISOString(),{error:le}=await k.from("report_settings").update({rm_landing_copy_draft:r.data,rm_landing_copy_published:r.data,rm_landing_niche:h,rm_landing_location:_,matchup_video_url:P.trim()||null,rm_landing_updated_at:ne}).eq("id",p);if(le)throw le;return m(r.data),V(ne),N(!1),i({title:"Published",description:"Your landing page is live with the new copy."}),!0}catch(p){return console.error("[useRMLandingEditor] publish error",p),i({title:"Publish failed",description:p.message,variant:"destructive"}),!1}finally{l(!1)}},[o,g,h,_,P,T,D,i]);return{loading:u||s,saving:c,publishing:t,draft:g,published:C,niche:h,location:_,videoUrl:P,dirty:$,updatedAt:T,updateDraft:F,applyNiche:H,updateLocation:I,updateVideoUrl:U,revertToDefault:Y,discardDraft:z,saveDraft:v,publish:G,reload:S}}function w({id:i,label:o,value:s,onChange:u,maxLength:n,multiline:c,rows:b=3}){const t=s.length>n,l=s.length;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx(Q,{htmlFor:i,className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:o}),e.jsxs("span",{className:K("text-[10px] tabular-nums",t?"text-destructive font-semibold":"text-muted-foreground"),children:[l," / ",n]})]}),c?e.jsx(je,{id:i,value:s,onChange:a=>u(a.target.value),rows:b,className:K(t&&"border-destructive focus-visible:ring-destructive")}
1):e.jsx(oe,{id:i,value:s,onChange:a=>u(a.target.value),className:K(t&&"border-destructive focus-visible:ring-destructive")})]})}function qe({draft:i,onUpdate:o}){const s=(t,l)=>o(a=>({...a,hero:{...a.hero,[t]:l}})),u=(t,l)=>o(a=>({...a,howItWorks:{...a.howItWorks,[t]:l}})),n=(t,l)=>o(a=>({...a,valueProps:{...a.valueProps,[t]:l}})),c=(t,l)=>o(a=>({...a,finalCta:{...a.finalCta,[t]:l}})),b=(t,l,a)=>o(j=>({...j,faq:j.faq.map((g,x)=>x===t?{...g,[l]:a}:g)}));return e.jsxs(ve,{type:"multiple",defaultValue:["hero"],className:"space-y-3",children:[e.jsxs(M,{value:"hero",className:"rounded-lg border border-border bg-card px-4",children:[e.jsx(E,{className:"font-semibold",children:"Hero"}),e.jsxs(q,{className:"space-y-4 pt-2",children:[e.jsx(w,{id:"hero-headline",label:"Headline",value:i.hero.headline,onChange:t=>s("headline",t),maxLength:y.heroHeadline,multiline:!0,rows:2}),e.jsx(w,{id:"hero-sub",label:"Subheadline",value:i.hero.subheadline,onChange:t=>s("subheadline",t),maxLength:y.heroSubheadline,multiline:!0,rows:3})]})]}),e.jsxs(M,{value:"hiw",className:"rounded-lg border border-border bg-card px-4",children:[e.jsx(E,{className:"font-semibold",children:"How It Works"}),e.jsx(q,{className:"space-y-4 pt-2",children:[1,2,3].map(t=>e.jsxs("div",{className:"space-y-3 rounded-md border border-border/50 p-3",children:[e.jsxs("div",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground",children:["Step ",t]}),e.jsx(w,{id:`hiw-t${t}`,label:"Title",value:i.howItWorks[`step${t}Title`],onChange:l=>u(`step${t}Title`,l),maxLength:y.stepTitle}),e.jsx(w,{id:`hiw-b${t}`,label:"Body",value:i.howItWorks[`step${t}Body`],onChange:l=>u(`step${t}Body`,l),maxLength:y.stepBody,multiline:!0,rows:2})]},t))})]}),e.jsxs(M,{value:"vp",className:"rounded-lg border border-border bg-card px-4",children:[e.jsx(E,{className:"font-semibold",children:"Value Props (Why It Matters)"}),e.jsxs(q,{className:"space-y-4 pt-2",children:[e.jsx(w,{id:"vp-title",label:"Section title",value:i.valueProps.title,onChange:t=>n("title",t),maxLength:y.valueTitle}),e.jsx(w,{id:"vp-sub",label:"Section subtitle",value:i.valueProps.subtitle,onChange:t=>n("subtitle",t),maxLength:y.valueSubtitle,multiline:!0,rows:2}),[1,2,3,4].map(t=>e.jsxs("div",{className:"space-y-3 rounded-md border border-border/50 p-3",children:[e.jsxs("div",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground",children:["Prop ",t]}),e.jsx(w,{id:`vp-t${t}`,label:"Title",value:i.valueProps[`prop${t}Title`],onChange:l=>n(`prop${t}Title`,l),maxLength:y.propTitle}),e.jsx(w,{id:`vp-b${t}`,label:"Body",value:i.valueProps[`prop${t}Body`],onChange:l=>n(`prop${t}Body`,l),maxLength:y.propBody,multiline:!0,rows:2})]},t))]})]}),e.jsxs(M,{value:"cta",className:"rounded-lg border border-border bg-card px-4",children:[e.jsx(E,{className:"font-semibold",children:"Final CTA"}),e.jsxs(q,{className:"space-y-4 pt-2",children:[e.jsx(w,{id:"cta-h",label:"Headline",value:i.finalCta.headline,onChange:t=>c("headline",t),maxLength:y.ctaHeadline,multiline:!0,rows:2}),e.jsx(w,{id:"cta-s",label:"Subheadline",value:i.finalCta.subheadline,onChange:t=>c("subheadline",t),maxLength:y.ctaSubheadline,multiline:!0,rows:3})]})]}),e.jsxs(M,{value:"faq",className:"rounded-lg border border-border bg-card px-4",children:[e.jsx(E,{className:"font-semibold",children:"FAQ (6 questions)"}),e.jsx(q,{className:"space-y-4 pt-2",children:i.faq.map((t,l)=>e.jsxs("div",{className:"space-y-3 rounded-md border border-border/50 p-3",children:[e.jsxs("div",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground",children:["Question ",l+1]}),e.jsx(w,{id:`faq-q${l}`,label:"Question",value:t.q,onChange:a=>b(l,"q",a),maxLength:y.faqQ}),e.jsx(w,{id:`faq-a${l}`,label:"Answer",value:t.a,onChange:a=>b(l,"a",a),maxLength:y.faqA,multiline:!0,rows:3})]},l))})]})]})}function Be({currentNiche:i,dirty:o,onApply:s,onRevertToDefault:u}){const[n,c]=d.useState(null),[b,t]=d.useState(!1),l=a=>{o?c(a):s(a)};return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold",children:"Niche template"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Rewrites every section for a specific vertical. Loads into your draft â you can edit before publishing."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsxs(ye,{value:i??"",onValueChange:l,children:[e.jsx(we,{className:"w-64",children:e.jsx(_e,{placeholder:"Choose a nicheâ¦"})}),e.jsx(Ne,{children:be.map(a=>e.jsx(Ce,{value:a.key,children:a.label},a.key))})]}),e.jsx(R,{variant:"outline",size:"sm",onClick:()=>t(!0),children:"Revert to default"})]}),e.jsx(J,{open:!!n,onOpenChange:a=>!a&&c(null),children:e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(te,{children:"Replace your draft?"}),e.jsx(re,{children:"You have unsaved changes in your draft. Applying this template will over
1write them. Your published landing page won't change until you click Publish."})]}),e.jsxs(se,{children:[e.jsx(ie,{children:"Cancel"}),e.jsx(ae,{onClick:()=>{n&&s(n),c(null)},children:"Replace draft"})]})]})}),e.jsx(J,{open:b,onOpenChange:t,children:e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(te,{children:"Revert draft to default copy?"}),e.jsx(re,{children:"This clears the draft back to the default landing-page copy. Your published landing page won't change until you click Publish."})]}),e.jsxs(se,{children:[e.jsx(ie,{children:"Cancel"}),e.jsx(ae,{onClick:u,children:"Revert draft"})]})]})})]})}function We({value:i,onChange:o}){const[s,u]=d.useState(""),[n,c]=d.useState(!1),[b,t]=d.useState(!1),[l,a]=d.useState(!1),[j,g]=d.useState([]),x=d.useRef(null);d.useEffect(()=>{if(!s||s.trim().length<2){g([]);return}return x.current&&window.clearTimeout(x.current),x.current=window.setTimeout(async()=>{t(!0);try{const{data:m,error:h}=await k.functions.invoke("places-city-autocomplete",{body:{action:"autocomplete",input:s.trim()}});if(h)throw h;g((m==null?void 0:m.suggestions)??[]),c(!0)}catch(m){console.error("[CityAutocomplete] autocomplete error",m),g([])}finally{t(!1)}},250),()=>{x.current&&window.clearTimeout(x.current)}},[s]);const C=async m=>{c(!1),a(!0);try{const{data:h,error:L}=await k.functions.invoke("places-city-autocomplete",{body:{action:"details",placeId:m.placeId}});if(L)throw L;const _=h==null?void 0:h.location;_&&_.city&&(o(_),u(""),g([]))}catch(h){console.error("[CityAutocomplete] details error",h)}finally{a(!1)}};return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-sm font-semibold",children:"Target location (optional)"}),e.jsxs("p",{className:"text-xs text-muted-foreground -mt-1",children:["Pick a city to auto-fill tokens like ",e.jsx("code",{className:"text-[11px]",children:"{{city}}"}),","," ",e.jsx("code",{className:"text-[11px]",children:"{{region}}"}),", and"," ",e.jsx("code",{className:"text-[11px]",children:"{{inCity}}"})," anywhere in your copy."]}),i?e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-border bg-muted/40 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(me,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-medium truncate",children:[i.city,i.region?`, ${i.region}`:""]}),i.formatted&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:i.formatted})]})]}),e.jsxs(R,{variant:"ghost",size:"sm",onClick:()=>o(null),children:[e.jsx(he,{className:"h-3.5 w-3.5 mr-1"})," Clear"]})]}):e.jsxs("div",{className:"relative",children:[e.jsx(oe,{placeholder:"City, province/state or postal codeâ¦",value:s,onChange:m=>u(m.target.value),onFocus:()=>j.length&&c(!0),onBlur:()=>window.setTimeout(()=>c(!1),150),disabled:l}),(b||l)&&e.jsx(O,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin text-muted-foreground"}),n&&j.length>0&&e.jsx("div",{className:"absolute z-20 mt-1 w-full rounded-md border border-border bg-popover shadow-md overflow-hidden",children:j.map(m=>e.jsxs("button",{type:"button",onMouseDown:h=>h.preventDefault(),onClick:()=>void C(m),className:"flex w-full items-start gap-2 px-3 py-2 text-left text-sm hover:bg-accent",children:[e.jsx(me,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:m.primary||m.text}),m.secondary&&e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:m.secondary})]})]},m.placeId))})]})]})}function Ve(i){const o=i.trim();if(!o)return null;try{const s=new URL(o),u=s.hostname.replace(/^www\./,"");if(u==="youtu.be"){const n=s.pathname.replace(/^\//,"").split("/")[0];if(n)return`https://www.youtube.com/embed/${n}`}if(u.endsWith("youtube.com")||u.endsWith("youtube-nocookie.com")){if(s.pathname.startsWith("/embed/"))return o;if(s.pathname.startsWith("/shorts/")){const c=s.pathname.split("/")[2];if(c)return`https://www.youtube.com/embed/${c}`}const n=s.searchParams.get("v");if(n)return`https://www.youtube.com/embed/${n}`}if(u.endsWith("vimeo.com")){if(u==="player.vimeo.com")return o;
1const n=s.pathname.split("/").filter(Boolean)[0];if(n&&/^\d+$/.test(n))return`https://player.vimeo.com/video/${n}`}if(u.endsWith("loom.com")){const n=s.pathname.split("/").filter(Boolean),c=n.findIndex(t=>t==="share"||t==="embed"),b=c>=0?n[c+1]:n[n.length-1];if(b)return`https://www.loom.com/embed/${b}`}if(u.endsWith("wistia.com")||u.endsWith("wistia.net")){const n=s.pathname.split("/").filter(Boolean).pop();if(n)return`https://fast.wistia.net/embed/iframe/${n}`}}catch{return null}return null}function Fe({value:i,onChange:o}){const s=d.useMemo(()=>Ve(i),[i]),u=i.trim().length>0,n=u&&!s;return e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"rounded-md bg-primary/10 text-primary p-2",children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(Q,{htmlFor:"hero-video-url",className:"text-sm font-semibold",children:"Hero video (optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Paste a YouTube, Vimeo, Loom, or Wistia play URL. Shown between the headline and subheadline on your public landing page. Leave blank to hide."})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(oe,{id:"hero-video-url",type:"url",placeholder:"https://www.youtube.com/watch?v=...",value:i,onChange:c=>o(c.target.value),className:n?"border-destructive focus-visible:ring-destructive":""}),u&&e.jsx(R,{variant:"outline",size:"icon",onClick:()=>o(""),title:"Clear video",children:e.jsx(he,{className:"h-4 w-4"})})]}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"That URL doesn't look like a YouTube, Vimeo, Loom, or Wistia video link."}),s&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"text-[11px] font-bold uppercase tracking-widest text-muted-foreground mb-2",children:"Preview"}),e.jsx("div",{className:"relative aspect-video w-full overflow-hidden rounded-md border border-border bg-slate-900",children:e.jsx("iframe",{src:s,title:"Hero video preview",className:"absolute inset-0 h-full w-full",loading:"lazy",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",allowFullScreen:!0})})]})]})}function Nr(){const i=xe(),{agencyId:o,agency:s,loading:u,userRole:n}=pe(),{settings:c}=Re(),{loading:b,saving:t,publishing:l,draft:a,niche:j,location:g,videoUrl:x,dirty:C,updatedAt:m,updateDraft:h,applyNiche:L,updateLocation:_,updateVideoUrl:B,revertToDefault:P,discardDraft:W,saveDraft:T,publish:V}=Ee(),[$,N]=d.useState({paywall:"free",capture:"live_report"});d.useEffect(()=>{if(!o)return;let z=!1;return k.from("rm_settings").select("default_mode, lead_magnet_enabled, capture_mode").eq("agency_id",o).maybeSingle().then(({data:D})=>{if(z)return;const v=D,G=(v==null?void 0:v.default_mode)==="paid"?"paid":(v==null?void 0:v.default_mode)==="lead_magnet"||(v==null?void 0:v.lead_magnet_enabled)===!0?"lead_magnet":"free";N({paywall:G,capture:(v==null?void 0:v.capture_mode)==="lead_form"?"lead_form":"live_report"})}),()=>{z=!0}},[o]);const[S,F]=d.useState("desktop");d.useEffect(()=>{!u&&!o&&i("/onboarding")},[u,o,i]);const H=d.useMemo(()=>s?{previewAgency:{id:s.id,name:s.name,slug:s.slug,logo_url:s.logo_url??null},previewBranding:{brand_name:(c==null?void 0:c.brand_name)??s.name,brand_color:(c==null?void 0:c.brand_color)??"#2563EB",logo_url:(c==null?void 0:c.logo_url)??s.logo_url??null,matchup_video_url:x||null,landing_copy:a,landing_location:g},previewPaywallMode:$.paywall,previewCaptureMode:$.capture}:null,[s,c,a,g,x,$]);if(b)return e.jsx(de,{userRole:n||"agency_admin",pageTitle:"Landing Page Editor",children:e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(O,{className:"w-6 h-6 animate-spin text-muted-foreground"})})});const I=s==null?void 0:s.slug,U=s==null?void 0:s.custom_domain,Y=I?U?`https://${U.replace(/^https?:\/\//,"").replace(/\/+$/,"")}/${I}/matchup`:`/${I}/matchup`:null;return e.jsx(de,{userRole:n||"agency_admin",pageTitle:"Landing Page Editor",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"ReviewMatchup Landing Page"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Edit on the left â see the live preview on the right. Nothing changes on your public page until you click Publish."}),m&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Last published: ",new Date(m).toLocaleStr
1ing()]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Y&&e.jsx(R,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:Y,target:"_blank",rel:"noopener noreferrer",children:["Open live page ",e.jsx(De,{className:"ml-1.5 h-3.5 w-3.5"})]})}),e.jsxs(R,{variant:"outline",size:"sm",onClick:W,disabled:!C||t||l,children:[e.jsx(Te,{className:"mr-1.5 h-3.5 w-3.5"})," Discard changes"]}),e.jsxs(R,{variant:"secondary",size:"sm",onClick:()=>void T(),disabled:!C||t||l,children:[t?e.jsx(O,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx($e,{className:"mr-1.5 h-3.5 w-3.5"}),"Save draft"]}),e.jsxs(J,{children:[e.jsx(Se,{asChild:!0,children:e.jsxs(R,{size:"sm",disabled:l||t,children:[l?e.jsx(O,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Publish"]})}),e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(te,{children:"Publish landing page changes?"}),e.jsx(re,{children:"Your current draft will replace the copy on your live public landing page. Visitors will see the new version immediately."})]}),e.jsxs(se,{children:[e.jsx(ie,{children:"Cancel"}),e.jsx(ae,{onClick:()=>void V(),children:"Publish now"})]})]})]})]})]}),C&&e.jsx("div",{className:"rounded-md border border-amber-300 bg-amber-50 text-amber-900 text-sm px-3 py-2",children:"You have unsaved changes. The live page hasn't changed yet â click Save draft or Publish."}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[minmax(0,480px)_minmax(0,1fr)] gap-6",children:[e.jsxs("div",{className:"space-y-5 min-w-0",children:[e.jsx(Be,{currentNiche:j,dirty:C,onApply:L,onRevertToDefault:P}),e.jsx("div",{className:"rounded-lg border border-border bg-card p-4",children:e.jsx(We,{value:g,onChange:_})}),e.jsx(Fe,{value:x,onChange:B}),e.jsx(qe,{draft:a,onUpdate:h})]}),e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"sticky top-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"Live preview"}),e.jsxs("div",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-card p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>F("desktop"),className:`inline-flex items-center gap-1.5 rounded px-2 py-1 text-xs font-medium transition-colors ${S==="desktop"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"}`,"aria-pressed":S==="desktop",children:[e.jsx(Me,{className:"h-3.5 w-3.5"})," Desktop"]}),e.jsxs("button",{type:"button",onClick:()=>F("mobile"),className:`inline-flex items-center gap-1.5 rounded px-2 py-1 text-xs font-medium transition-colors ${S==="mobile"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"}`,"aria-pressed":S==="mobile",children:[e.jsx(Ae,{className:"h-3.5 w-3.5"})," Mobile"]})]})]}),e.jsx("div",{className:"rounded-lg border border-border bg-muted/30 overflow-hidden flex justify-center",style:{height:"calc(100vh - 200px)",minHeight:"600px"},children:H&&e.jsx(Pe,{device:S,children:e.jsx("div",{className:"[&_a]:pointer-events-none [&_button]:pointer-events-none [&_form]:pointer-events-none [&_input]:pointer-events-none [&_iframe]:pointer-events-none select-none",children:e.jsx(Le,{...H})})})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Reflects your current draft. Publish to update the live public page."})]})})]})]})})}export{Nr 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.