1import{j as e}from"./vendor-query-CniT1WJL.js";import{r as l,k as Ge,u as We,L as Ce}from"./vendor-react-69GsFwrV.js";import{G as P,t as q,f as j,S as ie,b as ne,c as le,d as ce,e as G,V as A,m as de,P as Ee,c6 as ze,at as be,u as He,b1 as Ye,F as he}from"./index-KjAD5lCC.js";import{P as pe}from"./PartnerNav-CPlF75u7.js";import{e as Qe,i as Ae,R as Ke,j as ve,k as Je,l as Xe,F as v,m as ae,d as re,b as Y,n as Ze,f as je,q as et,r as tt,u as st,P as at,p as ge,T as rt,t as $e,O as it,o as De}from"./shared-GtdCyG23.js";import{a5 as Oe,g as W,bR as nt,a6 as lt,V as ct,d as oe,aj as me,bT as Se,bU as dt,bV as ot,D as _e,am as mt,b7 as ut,T as xt,_ as Pe,au as ht,b6 as pt,aO as ft,X as bt}from"./vendor-ui-Ad3ANzF6.js";import{S as jt}from"./StatusPill-vvYW-7Fj.js";import"./vendor-forms-q6h4WU-p.js";const gt=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function fe({label:t,used:s,budget:n}){const r=n>0?Math.min(100,s/n*100):0,i=Math.max(0,n-s);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium text-ink-2 dark:text-white/70",children:t}),e.jsxs("span",{className:"text-ink dark:text-white",children:[i," left"]})]}),e.jsx("div",{className:"mt-1.5 h-2 overflow-hidden rounded-pill bg-muted",children:e.jsx("div",{className:"h-full rounded-pill bg-primary/70 transition-all",style:{width:`${r}%`}})})]})}function vt(t){return{hasPoints:t.pointsBudget!=null,hasCredit:t.storeCreditBudgetCents!=null}}function Nt({vidaCode:t}){const s=t.status==="disabled"?"Code disabled":t.redeemed?"Redeemed":"Unredeemed",n=t.status==="disabled"?"bg-muted text-ink-2 border-card-border":t.redeemed?"bg-green-100 text-green-700 border-green-200":"bg-amber-100 text-amber-700 border-amber-200";return e.jsx("span",{className:j("inline-flex shrink-0 items-center rounded-full border px-2 py-0.5 text-[11px] font-semibold",n),children:s})}function yt({reward:t}){const s=t.rewardType==="store_credit"?q(t.storeCreditCents):t.rewardType==="points"?`${t.points??0} points`:"Product";return e.jsxs("li",{className:"flex items-center justify-between gap-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate font-medium text-ink dark:text-white",children:t.prizeLabel||Ke[t.rewardType]}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[s,t.recipient?` · ${t.recipient}`:""," · ",ve(t.createdAt)]}),t.vidaCode&&t.recipient&&e.jsxs("p",{className:"mt-1 flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["VidaCode sent to ",t.recipient]}),e.jsx(Nt,{vidaCode:t.vidaCode})]})]}),e.jsx("span",{className:j("inline-flex shrink-0 items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold",Xe[t.status]??"bg-muted text-ink-2 border-card-border"),children:Je[t.status]??t.status})]})}function kt({promotionId:t,prizeStructure:s,onProposed:n}){const{toast:r}=de(),i=s?.tiers??[],[c,a]=l.useState("custom"),[o,u]=l.useState("store_credit"),[f,p]=l.useState(""),[m,h]=l.useState(""),[g,N]=l.useState(null),[C,z]=l.useState(""),[T,O]=l.useState(""),[$,_]=l.useState(""),[w,S]=l.useState(""),[B,D]=l.useState(!1);function U(x){if(a(x),x==="custom"){N(null);return}const k=i[Number(x)];k&&(u(k.rewardType==="product"?"product":k.rewardType),z(k.label),N(k.productId??null),k.rewardType==="store_credit"&&p(ae(k.amountCents)),k.rewardType==="points"&&h(k.points!=null?String(k.points):""))}async function I(){if(!gt.test(T.trim())){r({title:"Enter a valid recipient email",variant:"destructive"});return}const x={rewardType:o,recipientEmail:T.trim()};if(o==="store_credit"){const R=re(f);if(R==null||R<=0){r({title:"Enter a VidaCredit amount",variant:"destructive"});return}x.storeCreditCents=R}else if(o==="points"){const R=Y(m);if(R==null||R<=0){r({title:"Enter a points amount",variant:"destructive"});return}x.points=R}else if(o==="product"){if(g==null){r({title:"Pick a product prize tier for a product reward",variant:"destructive"});return}x.productId=g}C.trim()&&(x.prizeLabel=C.trim());const k=Y($);k!=null&&(x.orderId=k),w.trim()&&(x.reason=w.trim()),D(!0);try{const R=await fetch(`/api/partners/promotions/${t}/rewards/propose`,{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify(x)});if(R.status===201){r({title:"Winner proposed",description:"The VidaPeps team will review it shortly."}),O(""),_(""),S(""),n();return}const b=await R.json().catch(()=>({}));b.error==="self_award_blocked"?r({title:"You cannot award a prize to yourself",description:b.message,variant:"destructive"}
1):b.error==="invalid_status"?r({title:"Prizes can only be proposed while the promotion is active.",variant:"destructive"}):b.error==="validation_error"?r({title:"Check the prize details and try again.",variant:"destructive"}):r({title:"Could not propose this winner. Please try again.",variant:"destructive"})}catch{r({title:"Could not propose this winner. Please try again.",variant:"destructive"})}finally{D(!1)}}return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl border border-vida-green-800/15 bg-vida-mint-soft p-3",children:e.jsx("p",{className:"text-sm font-medium text-vida-green-800",children:"All prizes require VidaPeps approval before they are issued."})}),i.length>0&&e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Prize tier"}),e.jsxs(ie,{value:c,onValueChange:U,children:[e.jsx(ne,{"aria-label":"Prize tier",className:j(v,"mt-1"),children:e.jsx(le,{})}),e.jsxs(ce,{children:[i.map((x,k)=>e.jsx(G,{value:String(k),children:Ae(x)},`${x.label}-${k}`)),e.jsx(G,{value:"custom",children:"Custom prize"})]})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Prize type"}),e.jsxs(ie,{value:o,onValueChange:x=>u(x),disabled:c!=="custom",children:[e.jsx(ne,{"aria-label":"Prize type",className:j(v,"mt-1",c!=="custom"&&"opacity-60"),children:e.jsx(le,{})}),e.jsxs(ce,{children:[e.jsx(G,{value:"store_credit",children:"VidaCredit"}),e.jsx(G,{value:"points",children:"Vida Points"}),g!=null&&e.jsx(G,{value:"product",children:"Product"})]})]})]}),o==="store_credit"&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"VidaCredit (dollars)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:f,onChange:x=>p(x.target.value),disabled:c!=="custom",className:j(v,"mt-1",c!=="custom"&&"opacity-60")})]}),o==="points"&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Vida Points"}),e.jsx("input",{type:"number",min:0,value:m,onChange:x=>h(x.target.value),disabled:c!=="custom",className:j(v,"mt-1",c!=="custom"&&"opacity-60")})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Prize label"}),e.jsx("input",{type:"text",value:C,onChange:x=>z(x.target.value),maxLength:120,placeholder:"Grand prize",className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Recipient email"}),e.jsx("input",{type:"email",value:T,onChange:x=>O(x.target.value),placeholder:"[email protected]",className:j(v,"mt-1")})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Order number (optional)"}),e.jsx("input",{type:"number",min:0,value:$,onChange:x=>_(x.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Reason (optional)"}),e.jsx("input",{type:"text",value:w,onChange:x=>S(x.target.value),maxLength:280,placeholder:"Why this winner?",className:j(v,"mt-1")})]})]}),e.jsxs(A,{onClick:I,disabled:B,children:[B?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(Oe,{className:"size-4"}),"Propose winner"]})]})}function wt({promotionId:t,kit:s,live:n,onRefresh:r}){const i=s?.prizeStructure??null,c=s?.budget??null,a=n?.rewards??[],o=c?vt(c):{hasPoints:!1,hasCredit:!1};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{className:"size-5 text-primary"}),e.jsx("h2",{className:"font-display text-lg font-bold text-ink dark:text-white",children:"Giveaway"})]}),e.jsxs(P,{tone:"solid",className:"space-y-4",children:[i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Prize structure"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:Qe[i.mode]??i.mode})]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:i.tiers.map((u,f)=>e.jsx("div",{className:"rounded-xl border border-card-border bg-muted/40 p-3",children:e.jsx("p",{className:"text-sm font-medium text-ink dark:text-white",children:Ae(u)})},`${u.label}-${f}`))}),i.notes&&e.jsx("p",{className:"text-sm text-muted-foreground",children:i.notes})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your prize structure is being prepared by the VidaPeps team."}),c&&(o.hasPoints||o.hasCredit||(c.discountBudgetCents??0)>0)&&e.jsxs("div",{className:"space-y-3 border-t border-card-border pt-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-ink dark:text-white",children:"Prize budget remaining"}),o.hasCredit&&e.jsx(fe,{label:"VidaCredit",used:c.storeCreditUsedCents/100,budget:(c.storeCreditBudgetCents??0)/100}),o.hasPoints&&e.jsx(fe,{label:"Vida Points",used:c.pointsUsed,budget:c.pointsBudget??0}),(c.discountBudgetCents??0)>0&&e.jsx(fe,{label:"Code discounts",used:c.discountUsedCents/100,budget:(c.discountBudgetCents??0)/100})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"VidaCredit and points prizes have no cash value."})]}),a.length>0&&e.jsxs(P,{tone:"solid",children:[e.jsx("h3",{className:"mb-1 text-sm font-semibold text-ink dark:text-white",children:"Prizes"}),e.jsx("ul",{className:"divide-y divide-card-border",children:a.map(u=>e.jsx(yt,{reward:u},u.id))})]}),e.jsxs(P,{tone:"solid",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold text-ink dark:text-white",children:"Propose a winner"}),e.jsx(kt,{promotionId:t,prizeStructure:i,onProposed:r})]})]})}const Ct="Paid partnership with VidaPeps. Research use only.";function J({value:t,label:s="Copy",className:n}){const[r,i]=l.useState(!1);async function c(){try{await navigator.clipboard.writeText(t),i(!0),setTimeout(()=>i(!1),2e3)}catch{}}return e.jsx("button",{type:"button",onClick:c,className:j("inline-flex shrink-0 items-center gap-1.5 rounded-pill border border-card-border px-3 py-1.5 text-xs font-semibold text-ink-2 transition-colors hover:border-primary/30 hover:text-primary dark:text-white/70",n),"aria-label":s,children:r?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"size-3.5 text-green-600"}),"Copied"]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"size-3.5"}),s]})})}function St({value:t,size:s=220}){const n=l.useRef(null);return l.useEffect(()=>{const r=n.current;!r||!t||ze.toCanvas(r,t,{width:s*2,margin:1,errorCorrectionLevel:"M",color:{dar
1k:"#000000",light:"#ffffff"}}).catch(()=>{})},[t,s]),e.jsx("canvas",{ref:n,className:"rounded-lg bg-white p-2",style:{width:s,height:s},role:"img","aria-label":`QR code for ${t}`})}function ee({label:t,value:s}){return e.jsxs("div",{className:"rounded-xl border border-card-border bg-card p-3 text-center",children:[e.jsx("p",{className:"font-display text-2xl font-bold text-ink dark:text-white",children:s}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:t})]})}function te({label:t,entry:s,format:n}){const r=Math.min(100,Math.max(0,s.pct)),i=s.goal>0&&s.actual>=s.goal;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium text-ink-2 dark:text-white/70",children:t}),e.jsxs("span",{className:"flex items-center gap-2 text-ink dark:text-white",children:[n(s.actual)," / ",n(s.goal),i&&e.jsx(Ee,{variant:"mint",className:"px-2 py-0.5",children:"Goal reached"})]})]}),e.jsx("div",{className:"mt-1.5 h-2 overflow-hidden rounded-pill bg-muted",children:e.jsx("div",{className:j("h-full rounded-pill transition-all",i?"bg-vida-gold-500":"bg-primary/70"),style:{width:`${r}%`}})})]})}function Pt({kit:t,live:s,loading:n}){const r=t?.codes.find(m=>m.isPrimary)??t?.codes.find(m=>m.enabled)??null,i=t?.links[0]??null,c=typeof window<"u"?window.location.origin:"https://vidapeps.com",a=i?`${c}${i.shortPath}`:null,o=t?.requiredDisclosure?.trim()||Ct,u=r?Ze(r):"a discount",f=l.useCallback(()=>{const m=a??"vidapeps.com",h=r?` - code ${r.code} for ${u}`:"";return`Research supplies at ${m}${h}. ${o}`},[a,r,u,o]),p=r?`Use code ${r.code} at vidapeps.com for ${u} on research supplies.`:"Shop research supplies at vidapeps.com.";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(P,{tone:"solid",className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nt,{className:"size-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Share while you go live"})]}),r?e.jsxs("div",{className:"rounded-xl border border-card-border bg-muted/40 p-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Your code"}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("span",{className:"font-display text-4xl font-bold tracking-tight text-ink dark:text-white sm:text-5xl",children:r.code}),e.jsx(J,{value:r.code,label:"Copy code"})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:u})]}):e.jsx("div",{className:"rounded-xl border border-card-border bg-muted/40 p-4 text-sm text-muted-foreground",children:"Your code kit is being prepared by the VidaPeps team."}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-[1fr_auto] sm:items-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Your link"}),a?e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"break-all text-sm font-medium text-ink dark:text-white",children:a}),e.jsx(J,{value:a,label:"Copy link"})]}):e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Your tracked link is being prepared by the VidaPeps team."})]}),a&&e.jsx("div",{className:"flex justify-center sm:justify-end",children:e.jsx(St,{value:a})})]})]}),e.jsxs(P,{tone:"solid",className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Copy-paste scripts"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Pinned comment"}),e.jsx(J,{value:f()})]}),e.jsx("p",{className:"mt-1 rounded-xl bg-muted/50 p-3 text-sm text-ink dark:text-white",children:f()})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Verbal opener"}),e.jsx(J,{value:p})]}),e.jsx("p",{className:"mt-1 rounded-xl bg-muted/50 p-3 text-sm text-ink dark:text-white",children:p})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Required disclosure (always include)"}),e.jsx(J,{value:o})]}),e.jsx("p",{className:"mt-1 rounded-xl bg-muted/50 p-3 text-sm text-ink dark:text-white",children:o})]})]})]}),e.jsxs(P,{tone:"solid",className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Live stats"}),n&&!s?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Loading..."}):e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"size-2 animate-pulse rounded-full bg-green-500","aria-hidden":"true"}
1),"Updating live"]})]}),s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(ee,{label:"Clicks",value:String(s.metrics.clicks)}),e.jsx(ee,{label:"Orders",value:String(s.metrics.paidOrders)}),e.jsx(ee,{label:"Revenue",value:q(s.metrics.revenueCents)}),e.jsx(ee,{label:"New customers",value:String(s.metrics.newCustomers)})]}),(()=>{const m=[],h=s.goalProgress;return h.sales&&m.push(e.jsx(te,{label:"Sales",entry:h.sales,format:g=>String(g)},"sales")),h.revenueCents&&m.push(e.jsx(te,{label:"Revenue",entry:h.revenueCents,format:g=>q(g)},"revenue")),h.newCustomers&&m.push(e.jsx(te,{label:"New customers",entry:h.newCustomers,format:g=>String(g)},"newCustomers")),h.clicks&&m.push(e.jsx(te,{label:"Clicks",entry:h.clicks,format:g=>String(g)},"clicks")),m.length>0?e.jsx("div",{className:"space-y-3",children:m}):null})()]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Live stats will appear here once your promotion starts getting activity."})]}),s&&s.codes.length>0&&e.jsxs(P,{tone:"solid",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(lt,{className:"size-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Code usage"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs uppercase tracking-wide text-muted-foreground",children:[e.jsx("th",{className:"pb-2 font-medium",children:"Code"}),e.jsx("th",{className:"pb-2 text-right font-medium",children:"Redemptions"}),e.jsx("th",{className:"pb-2 text-right font-medium",children:"Revenue"})]})}),e.jsx("tbody",{className:"divide-y divide-card-border",children:s.codes.map(m=>e.jsxs("tr",{children:[e.jsxs("td",{className:"py-2.5",children:[e.jsx("span",{className:"font-medium text-ink dark:text-white",children:m.code}),m.displayLabel&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:m.displayLabel})]}),e.jsx("td",{className:"py-2.5 text-right tabular-nums text-ink dark:text-white",children:m.redemptions}),e.jsx("td",{className:"py-2.5 text-right tabular-nums text-ink dark:text-white",children:q(m.revenueCents)})]},m.code))})]})})]}),s&&s.customers.length>0&&e.jsxs(P,{tone:"solid",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(ct,{className:"size-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Who's buying"})]}),e.jsx("ul",{className:"divide-y divide-card-border",children:s.customers.map((m,h)=>e.jsxs("li",{className:"flex items-center justify-between gap-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"truncate text-ink dark:text-white",children:[m.firstName,m.maskedEmail?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",m.maskedEmail]}):null]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ve(m.placedAt)})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[m.isNewCustomer&&e.jsx(Ee,{variant:"mint",className:"px-2 py-0.5",children:"New"}),e.jsx("span",{className:"font-medium text-ink dark:text-white",children:q(m.totalCents)})]})]},`${m.maskedEmail??"anon"}-${m.placedAt}-${h}`))})]})]})}function Tt({promotionId:t,initialOverlayUrl:s}){const{toast:n}=de(),[r,i]=l.useState(s),[c,a]=l.useState(!1),[o,u]=l.useState(!1);async function f(){a(!0);try{const h=await fetch(`/api/partners/promotions/${t}/overlay`,{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:"{}"});if(!h.ok)throw new Error("failed");const g=await h.json();i(g.overlayUrl),n({title:"Overlay enabled"})}catch{n({title:"Could not enable the overlay. Please try again.",variant:"destructive"})}finally{a(!1)}}async function p(){a(!0);try{if(!(await fetch(`/api/partners/promotions/${t}/overlay`,{method:"DELETE",credentials:"include"})).ok)throw new Error("failed");i(null),n({title:"Overlay disabled"})}catch{n({title:"Could not disable the overlay. Please try again.",variant:"destructive"})}finally{a(!1)}}async function m(){if(r)try{await navigator.clipboard.writeText(r),u(!0),setTimeout(()=>u(!1),2e3)}catch{}}return e.jsx("div",{className:"rounded-2xl border border-card-border bg-card p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Se,{className:"mt-0.5 size-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-ink dark:text-white",children:"Live overlay"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"A transparent scoreboard for your stream. Add it as a browser source in OBS or TikTok Live Studio and it updates itself while you go live."}),r?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{readOnly:!0,value:r,onFocus:h=>h.currentTarget.select(),className:"min-w-0 flex-1 rounded-xl border border-card-border bg-muted/50 px-3 py-2 text-sm text-ink dark:text-white"}),e.jsx("button",{type:"button",onClick:m,className:"shrink-0 rounded-pill border border-card-border p-2 text-muted-foreground hover:border-primary/30 hover:text-primary","aria-label":"Copy overlay URL",children:o?e.jsx(oe,{className:"size-4 text-green-600"}):e.jsx(me,{className:"size-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"In OBS: Sources â add a Browser source â paste this URL, set it to 1920 à 1080, and keep the background transparent."}
1),e.jsxs(A,{variant:"ghost",onClick:p,disabled:c,className:"text-red-600",children:[c?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(dt,{className:"size-4"}),"Disable overlay"]})]}):e.jsxs(A,{onClick:f,disabled:c,className:j("mt-3"),children:[c?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(Se,{className:"size-4"}),"Enable overlay"]})]})]})})}const E={evergreen:"#0C2A1F",evergreenDeep:"#081C15",mint:"#9CDCBE",gold:"#F0C868",bone:"#F4EFE6",boneDim:"rgba(244, 239, 230, 0.72)"},Be={portrait:{w:1080,h:1350,label:"Portrait 4:5"},story:{w:1080,h:1920,label:"Story 9:16"}},Rt={announcement:"Announcement",countdown:"Countdown",winner:"Winner"};function M(t,s=700){return`${s} ${t}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`}function se(t,s,n){const r=s.trim().split(/\s+/).filter(Boolean);if(r.length===0)return[];const i=[];let c=r[0];for(let a=1;a<r.length;a++){const o=`${c} ${r[a]}`;t.measureText(o).width<=n?c=o:(i.push(c),c=r[a])}return i.push(c),i}function Te(t,s,n,r,i,c){const a=Math.min(c,i/2,r/2);t.beginPath(),t.moveTo(s+a,n),t.arcTo(s+r,n,s+r,n+i,a),t.arcTo(s+r,n+i,s,n+i,a),t.arcTo(s,n+i,s,n,a),t.arcTo(s,n,s+r,n,a),t.closePath()}function Lt(t,s,n,r){const{w:i,h:c}=Be[n];t.width=i,t.height=c;const a=t.getContext("2d");if(!a)return;const o=a.createLinearGradient(0,0,i,c);o.addColorStop(0,E.evergreen),o.addColorStop(1,E.evergreenDeep),a.fillStyle=o,a.fillRect(0,0,i,c);const u=a.createRadialGradient(i/2,c*.16,0,i/2,c*.16,i*.75);u.addColorStop(0,"rgba(240, 200, 104, 0.18)"),u.addColorStop(1,"rgba(240, 200, 104, 0)"),a.fillStyle=u,a.fillRect(0,0,i,c),a.strokeStyle="rgba(156, 220, 190, 0.4)",a.lineWidth=4,Te(a,40,40,i-80,c-80,44),a.stroke();const f=i/2,p=i-200;a.textAlign="center",a.textBaseline="alphabetic",a.fillStyle=E.gold,a.font=M(38,800),a.fillText("VIDAPEPS",f,c*.14);const m=s==="announcement"?"NOW LIVE":s==="countdown"?"COMING SOON":"WE HAVE A WINNER";a.fillStyle=E.mint,a.font=M(26,700),a.fillText(m,f,c*.2);const h=s==="countdown"?r.startsLabel||(r.window?r.window:"Starting soon"):s==="winner"?"Congratulations!":r.title;a.fillStyle=E.gold;const g=n==="story"?92:84;a.font=M(g,800);const N=se(a,h,p).slice(0,4),C=g*1.12,z=c*.42-(N.length-1)*C/2;N.forEach((w,S)=>{a.fillText(w,f,z+S*C)});let T=z+N.length*C+20;if(a.fillStyle=E.bone,a.font=M(40,600),s==="winner"?se(a,r.title,p).slice(0,2).forEach(S=>{a.fillText(S,f,T),T+=52}):r.window&&(a.fillStyle=E.mint,a.fillText(r.window,f,T),T+=60),s==="announcement"&&r.code){a.font=M(46,800);const w=r.code.toUpperCase(),S=a.measureText(w).width,D=Math.min(S+44*2,i-160),U=96,I=f-D/2,x=c*.62;a.fillStyle=E.gold,Te(a,I,x,D,U,U/2),a.fill(),a.fillStyle=E.evergreenDeep,a.textBaseline="middle",a.fillText(w,f,x+U/2+2),a.textBaseline="alphabetic",a.fillStyle=E.boneDim,a.font=M(30,600),a.fillText("Use code at checkout",f,x+U+46)}a.fillStyle=E.mint,a.font=M(38,700);const O=s==="winner"?"Thank you for joining the drop":"Shop at vidapeps.com";a.fillText(O,f,c*.82),a.fillStyle=E.boneDim,a.font=M(24,500);const $=[];r.disclosure&&$.push(...se(a,r.disclosure,i-160).slice(0,2)),$.push(...se(a,"For research use only. Not for human consumption. Rewards have no cash value.",i-160).slice(0,2));const _=c-110-($.length-1)*32;$.forEach((w,S)=>{a.fillText(w,f,_+S*32)})}function Et(t,s){t.toBlob(n=>{if(!n)return;const r=URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=s,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)},"image/png")}const zt=["announcement","countdown","winner"],At=["portrait","story"];function $t({data:t,slug:s}){const n=l.useRef(null),[r,i]=l.useState("announcement"),[c,a]=l.useState("portrait");l.useEffect(()=>{n.current&&Lt(n.current,r,c,t)},[r,c,t]);function o(){n.current&&Et(n.current,`vidapeps-${s}-${r}-${c}.png`)}return e.jsx("div",{className:"rounded-2xl border border-card-border bg-card p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ot,{className:"mt-0.5 size-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-ink dark:text-white",children:"Share graphics"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"Ready-to-post cards built from this promotion. Download and share to your feed or story."}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:zt.map(u=>e.jsx("button",{type:"button",onClick:()=>
1i(u),className:j("rounded-pill border px-3 py-1.5 text-sm font-medium transition-colors",u===r?"border-primary bg-primary text-primary-foreground":"border-card-border bg-card text-ink-2 hover:bg-muted dark:text-white/70"),children:Rt[u]},u))}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:At.map(u=>e.jsx("button",{type:"button",onClick:()=>a(u),className:j("rounded-pill border px-3 py-1.5 text-xs font-medium transition-colors",u===c?"border-primary/60 bg-vida-mint-soft text-vida-green-800":"border-card-border bg-card text-ink-2 hover:bg-muted dark:text-white/70"),children:Be[u].label},u))}),e.jsxs("div",{className:"mt-4 flex flex-col items-start gap-3 sm:flex-row sm:items-end",children:[e.jsx("div",{className:"w-full max-w-[220px] overflow-hidden rounded-xl border border-card-border",children:e.jsx("canvas",{ref:n,className:"block h-auto w-full"})}),e.jsxs(A,{onClick:o,children:[e.jsx(_e,{className:"size-4"}),"Download PNG"]})]})]})]})})}function Dt({linkUrl:t,copyRows:s}){const n=l.useRef(null),[r,i]=l.useState(null);l.useEffect(()=>{!t||!n.current||ze.toCanvas(n.current,t,{width:320,margin:2,color:{dark:E.evergreen,light:E.bone},errorCorrectionLevel:"M"}).catch(()=>{})},[t]);function c(){const o=n.current;o&&o.toBlob(u=>{if(!u)return;const f=URL.createObjectURL(u),p=document.createElement("a");p.href=f,p.download="vidapeps-promo-qr.png",document.body.appendChild(p),p.click(),p.remove(),setTimeout(()=>URL.revokeObjectURL(f),1e3)},"image/png")}async function a(o){try{await navigator.clipboard.writeText(o),i(o),setTimeout(()=>i(null),2e3)}catch{}}return e.jsx("div",{className:"rounded-2xl border border-card-border bg-card p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(mt,{className:"mt-0.5 size-5 shrink-0 text-primary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"text-sm font-semibold text-ink dark:text-white",children:"QR code & links"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"Print the QR on packaging or flash it on stream. Every scan and click attributes to you."}),t?e.jsxs("div",{className:"mt-4 flex flex-col items-start gap-3 sm:flex-row sm:items-end",children:[e.jsx("div",{className:"overflow-hidden rounded-xl border border-card-border",children:e.jsx("canvas",{ref:n,className:"block h-40 w-40"})}),e.jsxs(A,{onClick:c,children:[e.jsx(_e,{className:"size-4"}),"Download QR"]})]}):e.jsx("p",{className:"mt-3 rounded-xl bg-muted/50 p-3 text-xs text-muted-foreground",children:"A tracking link is added when your promotion is approved. Your QR code will appear here once it is ready."}),s.length>0&&e.jsx("div",{className:"mt-4 space-y-2",children:s.map(o=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-24 shrink-0 text-xs font-medium text-muted-foreground",children:o.label}),e.jsx("input",{readOnly:!0,value:o.url,onFocus:u=>u.currentTarget.select(),className:"min-w-0 flex-1 rounded-xl border border-card-border bg-muted/50 px-3 py-2 text-sm text-ink dark:text-white"}),e.jsx("button",{type:"button",onClick:()=>a(o.url),className:"shrink-0 rounded-pill border border-card-border p-2 text-muted-foreground hover:border-primary/30 hover:text-primary","aria-label":`Copy ${o.label} link`,children:r===o.url?e.jsx(oe,{className:"size-4 text-green-600"}):e.jsx(me,{className:"size-4"})})]},o.label))})]})]})})}function Ot({promotion:t,kit:s}){const[n,r]=l.useState(null);l.useEffect(()=>{let p=!0;return(async()=>{try{const m=await fetch("/api/users/me/referral",{credentials:"include"});if(!m.ok)return;const h=await m.json();p&&r(h.alias??h.code??null)}catch{}})(),()=>{p=!1}},[]);const i=typeof window<"u"?window.location.origin:"https://vidapeps.com",c=l.useMemo(()=>s?s.codes.find(p=>p.isPrimary)?.code??s.codes[0]?.code??null:null,[s]),a=l.useMemo(()=>!s||s.links.length===0?null:s.links[0].shortPath.replace(/^\/p\//,""),[s]),o=t.promotionType==="giveaway"||(s?.prizeStructure??null)!=null,u={title:t.title,window:je(t.startsAt,t.endsAt),code:c,startsLabel:t.startsAt?je(t.startsAt,null):null,disclosure:t.requiredDisclosure},f=[];return a&&f.push({label:"Tracking",url:`${i}/p/${a}`}),o&&f.push({label:"Giveaway",url:`${i}/g/${t.slug}`}),n&&f.push({label:"Link in bio",url:`${i}/l/${n}`}),e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"mt-10",overline:"Promo Kit",title:"Share your promotion"}),s&&s.participants.length>=2&&e.jsxs("div",{className:"mt-4 rounded-xl border border-card-border bg-card p-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-ink dark:text-white",children:"Hosts and commission split"}),e.jsx("ul",{className:"mt-2 space-y-1",children:s.participants.map(p=>e.jsxs("li",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:[p.displayName??`Host #${p.partnerId}`,p.role==="owner"?" (owner)":""]}),e.jsxs("span",{className:"font-medium text-ink dark:text-white",children:[(p.splitBps/100).toFixed(2).replace(/\.00$/,""),"%"]})]},p.partnerId))}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Each attributed order splits commission between hosts at these shares."})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx(Tt,{promotionId:t.id,initialOverlayUrl:s?.overlayUrl??null}),e.jsx($t,{data:u,slug:t.slug}),e.jsx(Dt,{linkUrl:a?`${i}/p/${a}`:null,copyRows:f})]})]})}const _t=12e3;function Bt(t,s){const[n,r]=l.useState(null),[i,c]=l.useState(null),[a,o]=l.useState(!0),[u,f]=l.useState(!1),p=l.useRef(!1),m=l.useCallback(async()=>
1{if(t!=null)try{const N=await fetch(`/api/partners/promotions/${t}/kit`,{credentials:"include"});if(!N.ok)throw new Error("kit_failed");r(await N.json()),p.current=!0}catch{f(!0)}},[t]),h=l.useCallback(async()=>{if(t!=null)try{const N=await fetch(`/api/partners/promotions/${t}/live`,{credentials:"include"});if(!N.ok)throw new Error("live_failed");c(await N.json())}catch{}},[t]),g=l.useCallback(async()=>{await Promise.all([m(),h()])},[m,h]);return l.useEffect(()=>{!s||t==null||p.current||m()},[s,t,m]),l.useEffect(()=>{if(!s||t==null){o(!1);return}let N=!0;const C=async()=>{document.hidden||await h()};(async()=>(await h(),N&&o(!1)))();const z=setInterval(()=>{C()},_t);return()=>{N=!1,clearInterval(z)}},[s,t,h]),{kit:n,live:i,loading:a,error:u,refresh:g}}const Ut=new Set(["approved","scheduled","live","paused","completed"]);function Re(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const n=r=>String(r).padStart(2,"0");return`${s.getFullYear()}-${n(s.getMonth()+1)}-${n(s.getDate())}T${n(s.getHours())}:${n(s.getMinutes())}`}function Le(t){if(!t.trim())return;const s=new Date(t);return Number.isNaN(s.getTime())?void 0:s.toISOString()}function V({label:t,value:s}){return e.jsxs("div",{className:"flex flex-col gap-0.5 border-b border-card-border py-2.5 last:border-0 sm:flex-row sm:gap-4",children:[e.jsx("span",{className:"w-44 shrink-0 text-sm font-medium text-muted-foreground",children:t}),e.jsx("span",{className:"text-sm text-ink dark:text-white",children:s})]})}function Vt({promotion:t}){const s=je(t.startsAt,t.endsAt),n=[t.goalSalesCount!=null&&`${t.goalSalesCount} sales`,t.goalRevenueCents!=null&&`${q(t.goalRevenueCents)} revenue`,t.goalNewCustomers!=null&&`${t.goalNewCustomers} new customers`,t.goalClicks!=null&&`${t.goalClicks} clicks`].filter(Boolean).join(" · "),r=[t.budgetDiscountCents!=null&&`${q(t.budgetDiscountCents)} discount`,t.budgetPoints!=null&&`${t.budgetPoints} points`,t.budgetStoreCreditCents!=null&&`${q(t.budgetStoreCreditCents)} VidaCredit`].filter(Boolean).join(" · "),i=t.complianceSelfCheck;return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(P,{tone:"solid",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Plan"}),e.jsxs("div",{className:"mt-2",children:[e.jsx(V,{label:"Type",value:$e(t.promotionType)}),e.jsx(V,{label:"Objective",value:De(t.objective)}),e.jsx(V,{label:"Platforms",value:t.platforms.map(ge).join(", ")||"None"}),t.primaryPlatform&&e.jsx(V,{label:"Primary",value:ge(t.primaryPlatform)}),s&&e.jsx(V,{label:"Window",value:s}),t.liveUrl&&e.jsx(V,{label:"Link",value:t.liveUrl})]})]}),e.jsxs(P,{tone:"solid",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Goals & incentives"}),e.jsxs("div",{className:"mt-2",children:[e.jsx(V,{label:"Goals",value:n||"None set"}),e.jsx(V,{label:"Incentive requests",value:r||"None requested"}),t.incentiveRequest&&e.jsx(V,{label:"Notes",value:t.incentiveRequest}),e.jsx(V,{label:"Compliance self-check",value:i&&[i.ftcDisclosure&&"FTC disclosure",i.ruoSafe&&"Research-use-only",i.noMedicalClaims&&"No medical claims"].filter(
1Boolean).join(" · ")||"Not confirmed"})]}),t.budgetPoints!=null||t.budgetStoreCreditCents!=null?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Points and VidaCredit are account rewards subject to VidaPeps approval and never have a cash value."}):null]})]})}function It({promotion:t,onSaved:s,onCancel:n}){const{toast:r}=de(),[i,c]=l.useState(t.title),[a,o]=l.useState(t.description??""),[u,f]=l.useState(t.platforms),[p,m]=l.useState(t.primaryPlatform??""),[h,g]=l.useState(t.promotionType),[N,C]=l.useState(t.objective),[z,T]=l.useState(Re(t.startsAt)),[O,$]=l.useState(Re(t.endsAt)),[_,w]=l.useState(t.liveUrl??""),[S,B]=l.useState(t.goalSalesCount!=null?String(t.goalSalesCount):""),[D,U]=l.useState(ae(t.goalRevenueCents)),[I,x]=l.useState(t.goalNewCustomers!=null?String(t.goalNewCustomers):""),[k,R]=l.useState(t.goalClicks!=null?String(t.goalClicks):""),[b,X]=l.useState(ae(t.budgetDiscountCents)),[L,Z]=l.useState(t.budgetPoints!=null?String(t.budgetPoints):""),[y,Q]=l.useState(ae(t.budgetStoreCreditCents)),[K,F]=l.useState(t.incentiveRequest??""),[ue,Ue]=l.useState(t.complianceSelfCheck?.ftcDisclosure??!1),[Ne,Ve]=l.useState(t.complianceSelfCheck?.ruoSafe??!1),[ye,Ie]=l.useState(t.complianceSelfCheck?.noMedicalClaims??!1),[xe,ke]=l.useState(!1);function Fe(d){f(H=>{const we=H.includes(d)?H.filter(qe=>qe!==d):[...H,d];return p&&!we.includes(p)&&m(""),we})}async function Me(){if(i.trim().length<3){r({title:"Title must be at least 3 characters",variant:"destructive"});return}if(u.length===0){r({title:"Pick at least one platform",variant:"destructive"});return}const d={title:i.trim(),description:a.trim(),objective:N,promotionType:h,platforms:u,primaryPlatform:p||null,startsAt:Le(z)??null,endsAt:Le(O)??null,liveUrl:_.trim(),goalSalesCount:Y(S),goalRevenueCents:re(D),goalNewCustomers:Y(I),goalClicks:Y(k),budgetDiscountCents:re(b),budgetPoints:Y(L),budgetStoreCreditCents:re(y),incentiveRequest:K.trim(),complianceSelfCheck:{ftcDisclosure:ue,ruoSafe:Ne,noMedicalClaims:ye}};ke(!0);try{if(!(await fetch(`/api/partners/promotions/${t.id}`,{method:"PATCH",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify(d)})).ok)throw new Error("save_failed");r({title:"Changes saved"}),s()}catch{r({title:"Could not save your changes. Please try again.",variant:"destructive"})}finally{ke(!1)}}return e.jsxs(P,{tone:"solid",className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Edit your plan"}),e.jsx("button",{type:"button",onClick:n,className:"rounded-pill p-1.5 text-muted-foreground hover:bg-muted","aria-label":"Close editor",children:e.jsx(bt,{className:"size-4"})})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Title"}),e.jsx("input",{type:"text",value:i,onChange:d=>c(d.target.value),maxLength:120,className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Description"}),e.jsx("textarea",{value:a,onChange:d=>o(d.target.value),rows:3,className:j(v,"mt-1")})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Platforms"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:at.map(d=>{const H=u.includes(d);return e.jsx("button",{type:"button",onClick:()=>Fe(d),className:j("rounded-pill border px-3 py-1.5 text-sm font-medium transition-colors",H?"border-primary bg-primary text-primary-foreground":"border-card-border bg-card text-ink-2 hover:bg-muted dark:text-white/70"),children:ge(d)},d)})})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Type"}),e.jsxs(ie,{value:h,onValueChange:d=>g(d),children:[e.jsx(ne,{"aria-label":"Type",className:j(v,"mt-1"),children:e.jsx(le,{})}),e.jsx(ce,{children:rt.map(d=>e.jsx(G,{value:d,children:$e(d)},d))})]})]}),e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Objective"}),e.jsxs(ie,{value:N,onValueChange:d=>C(d),children:[e.jsx(ne,{"aria-label":"Objective",className:j(v,"mt-1"),children:e.jsx(le,{})}),e.jsx(ce,{children:it.map(d=>e.jsx(G,{value:d,children:De(d)},d))})]})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Starts"}),e.jsx("input",{type:"datetime-local",value:z,onChange:d=>T(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Ends"}),e.jsx("input",{type:"datetime-local",value:O,onChange:d=>$(d.target.value),className:j(v,"mt-1")})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Live or content URL"}
1),e.jsx("input",{type:"url",value:_,onChange:d=>w(d.target.value),placeholder:"https://...",className:j(v,"mt-1")})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Goals"}),e.jsxs("div",{className:"mt-2 grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Sales (count)"}),e.jsx("input",{type:"number",min:0,value:S,onChange:d=>B(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Revenue (dollars)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:D,onChange:d=>U(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"New customers"}),e.jsx("input",{type:"number",min:0,value:I,onChange:d=>x(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Link clicks"}),e.jsx("input",{type:"number",min:0,value:k,onChange:d=>R(d.target.value),className:j(v,"mt-1")})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Incentive requests"}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:"All incentives are requests subject to VidaPeps approval."}),e.jsxs("div",{className:"mt-2 grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Discount (dollars)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:b,onChange:d=>X(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"VidaCredit (dollars)"}),e.jsx("input",{type:"number",min:0,step:"0.01",value:y,onChange:d=>Q(d.target.value),className:j(v,"mt-1")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Vida Points"}),e.jsx("input",{type:"number",min:0,value:L,onChange:d=>Z(d.target.value),className:j(v,"mt-1")})]})]}),e.jsxs("label",{className:"mt-4 block",children:[e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"Notes (optional)"}),e.jsx("textarea",{value:K,onChange:d=>F(d.target.value),rows:3,maxLength:2e3,className:j(v,"mt-1")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Compliance"}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border border-card-border p-2.5",children:[e.jsx("input",{type:"checkbox",checked:ue,onChange:d=>Ue(d.target.checked),className:"mt-0.5 size-4 rounded border-ink/30 text-vida-green-700 focus:ring-vida-green-700"}),e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"I will clearly disclose my VidaPeps partnership."})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border border-card-border p-2.5",children:[e.jsx("input",{type:"checkbox",checked:Ne,onChange:d=>Ve(d.target.checked),className:"mt-0.5 size-4 rounded border-ink/30 text-vida-green-700 focus:ring-vida-green-700"}),e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"I will keep messaging research-use-only."})]}),e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border border-card-border p-2.5",children:[e.jsx("input",{type:"checkbox",checked:ye,onChange:d=>Ie(d.target.checked),className:"mt-0.5 size-4 rounded border-ink/30 text-vida-green-700 focus:ring-vida-green-700"}),e.jsx("span",{className:"text-sm text-ink-2 dark:text-white/70",children:"I will not make medical, dosing, or treatment claims."})]})]}),e.jsxs("div",{className:"flex gap-2 border-t border-card-border pt-4",children:[e.jsxs(A,{onClick:Me,disabled:xe,children:[xe?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(oe,{className:"size-4"}),"Save changes"]}),e.jsx(A,{variant:"ghost",onClick:n,disabled:xe,children:"Cancel"})]})]})}function Kt(){const{isAuthenticated:t,isLoading:s}=He(),[,n]=Ge("/partners/promotions/:id"),[,r]=We(),{toast:i}=de(),c=Ye(),a=n?.id,[o,u]=l.useState(!0),[f,p]=l.useState(null),[m,h]=l.useState(null),[g,N]=l.useState(!1),[C,z]=l.useState(!1),[T,O]=l.useState(""),[$,_]=l.useState(!1),w=l.useCallback(async()=>
1{if(a)try{const y=await fetch(`/api/partners/promotions/${a}`,{credentials:"include"});if(!y.ok)throw new Error("Failed to load promotion");const Q=await y.json();h(Q)}catch(y){p(y instanceof Error?y.message:"Failed to load promotion")}finally{u(!1)}},[a]);l.useEffect(()=>{if(!s){if(!t){r(`/login?redirect=/partners/promotions/${a??""}`);return}w()}},[t,s,r,w,a]);const S=!!m&&Ut.has(m.promotion.status),{kit:B,live:D,loading:U,refresh:I}=Bt(a,S);async function x(y,Q){if(a){z(!0);try{const K=await fetch(`/api/partners/promotions/${a}/${y}`,{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify(Q??{})});if(K.ok){i({title:{submit:"Submitted for review",cancel:"Promotion cancelled",start:"Your promotion is live",complete:"Promotion marked complete"}[y]}),O(""),await w(),N(!1);return}const F=await K.json().catch(()=>({}));F.error==="not_ready_for_review"&&Array.isArray(F.problems)?i({title:"Not ready for review yet",description:F.problems.join(" "),variant:"destructive"}):F.error==="window_closed"?i({title:"This promotion's end date has passed. Update it, or contact the team.",variant:"destructive"}):F.error==="invalid_transition"?(i({title:"That action is not available right now.",variant:"destructive"}),await w()):F.error==="not_editable"?(i({title:"This plan can no longer be edited.",variant:"destructive"}),await w()):i({title:"Something went wrong. Please try again.",variant:"destructive"})}catch{i({title:"Something went wrong. Please try again.",variant:"destructive"})}finally{z(!1)}}}async function k(){await c({title:"Cancel this promotion?",description:"Its link stops working right away and this cannot be undone.",confirmLabel:"Cancel promotion",cancelLabel:"Keep it running",destructive:!0})&&x("cancel")}async function R(y){try{await navigator.clipboard.writeText(y),_(!0),setTimeout(()=>_(!1),2e3)}catch{}}if(o)return e.jsxs(e.Fragment,{children:[e.jsx(pe,{}),e.jsx(he,{className:"py-8 md:py-12",children:e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 w-64 rounded bg-muted"}),e.jsx("div",{className:"h-24 w-full rounded bg-muted"}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsx("div",{className:"h-48 rounded bg-muted"}),e.jsx("div",{className:"h-48 rounded bg-muted"})]})]})})})]});if(f||!m)return e.jsxs(e.Fragment,{children:[e.jsx(pe,{}),e.jsx(he,{className:"py-12",children:e.jsxs("div",{className:"mx-auto max-w-md text-center",children:[e.jsx("p",{className:"text-red-600",children:f??"Failed to load promotion"}),e.jsx(A,{asChild:!0,variant:"light",className:"mt-4",children:e.jsx(Ce,{href:"/partners/promotions",children:"Back to Promotion Hub"})})]})})]});const{promotion:b,events:X}=m,L=et(b.status),Z=b.status==="changes_requested";return e.jsxs(e.Fragment,{children:[e.jsx(pe,{}),e.jsx(he,{className:"py-8 md:py-12",children:e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx(jt,{status:b.status}),e.jsx(be,{as:"h1",className:"mt-3",title:b.title}),b.description&&e.jsx("p",{className:"mt-2 max-w-xl text-sm text-muted-foreground",children:b.description})]}),L.canEdit&&!g&&e.jsxs(A,{variant:"light",onClick:()=>N(!0),className:"shrink-0",children:[e.jsx(ut,{className:"size-4"}),"Edit plan"]})]}),e.jsx(P,{tone:"solid",className:"mt-6",children:e.jsx("p",{className:"text-sm text-ink-2 dark:text-white/70",children:tt[b.status]})}),b.status==="changes_requested"&&b.adminReviewNotes&&e.jsx(P,{tone:"solid",className:"mt-4 border-amber-300 bg-amber-50",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(xt,{className:"mt-0.5 size-5 shrink-0 text-amber-600"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-amber-900",children:"The VidaPeps team asked for changes"}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-sm text-amber-800",children:b.adminReviewNotes})]})]})}),b.status==="denied"&&b.adminReviewNotes&&e.jsxs(P,{tone:"solid",className:"mt-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Review notes"}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-sm text-muted-foreground",children:b.adminReviewNotes})]}
1),b.requiredDisclosure&&(b.status==="approved"||b.status==="scheduled"||b.status==="live")&&e.jsxs(P,{tone:"solid",className:"mt-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-ink dark:text-white",children:"Required disclosure"}),e.jsx("p",{className:"mt-1 text-sm text-ink-2 dark:text-white/70",children:"Include this wherever you promote."})]}),e.jsx("button",{type:"button",onClick:()=>R(b.requiredDisclosure??""),className:"shrink-0 rounded-pill border border-card-border p-2 text-muted-foreground hover:border-primary/30 hover:text-primary","aria-label":"Copy disclosure",children:$?e.jsx(Pe,{className:"size-4 text-green-600"}):e.jsx(me,{className:"size-4"})})]}),e.jsx("p",{className:"mt-2 rounded-xl bg-muted/50 p-3 text-sm text-ink dark:text-white",children:b.requiredDisclosure})]}),(L.canSubmit||L.canStart||L.canComplete||L.canCancel)&&!g&&e.jsxs(P,{tone:"solid",className:"mt-4 space-y-3",children:[L.canSubmit&&Z&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-ink-2 dark:text-white/70",children:"Revision note for the team (optional)"}),e.jsx("textarea",{value:T,onChange:y=>O(y.target.value),rows:2,placeholder:"What did you change?",className:j(v,"mt-1")})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[L.canSubmit&&e.jsxs(A,{onClick:()=>x("submit",T.trim()?{partnerRevisionNotes:T.trim()}:{}),disabled:C,children:[C?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(ht,{className:"size-4"}),Z?"Resubmit for review":"Submit for review"]}),L.canStart&&e.jsxs(A,{onClick:()=>x("start"),disabled:C,children:[C?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(pt,{className:"size-4"}),"Start promotion"]}),L.canComplete&&e.jsxs(A,{onClick:()=>x("complete"),disabled:C,children:[C?e.jsx(W,{className:"size-4 animate-spin"}):e.jsx(Pe,{className:"size-4"}),"Complete promotion"]}),L.canCancel&&e.jsx(A,{variant:"destructive",onClick:k,disabled:C,children:"Cancel promotion"})]})]}),e.jsx("div",{className:"mt-6",children:g&&L.canEdit?e.jsx(It,{promotion:b,onSaved:()=>{N(!1),w()},onCancel:()=>N(!1)}):e.jsx(Vt,{promotion:b})}),S&&!g&&e.jsx("div",{className:"mt-6",children:e.jsx(Pt,{kit:B,live:D,loading:U})}),S&&!g&&(B?.prizeStructure!=null||b.promotionType==="giveaway"||b.promotionType==="milestone_challenge")&&e.jsx("div",{className:"mt-8",children:e.jsx(wt,{promotionId:b.id,kit:B,live:D,onRefresh:()=>{I()}})}),S&&!g&&e.jsx(Ot,{promotion:b,kit:B}),X.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"mt-10",overline:"History",title:"Activity"}),e.jsx(P,{tone:"solid",className:"mt-4",children:e.jsx("ol",{className:"space-y-4",children:X.map(y=>e.jsxs("li",{className:"flex gap-3",children:[e.jsx("div",{className:"mt-1 flex flex-col items-center",children:e.jsx("span",{className:"size-2 rounded-full bg-primary","aria-hidden":"true"})}),e.jsxs("div",{className:"flex-1 border-b border-card-border pb-3 last:border-0",children:[e.jsx("p",{className:"text-sm font-medium text-ink dark:text-white",children:st(y.eventType)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[ve(y.createdAt),y.actorName?` · ${y.actorName}`:""]})]})]},y.id))})})]}),e.jsx("div",{className:"mt-10 border-t border-card-border pt-6",children:e.jsxs(Ce,{href:"/partners/promotions",className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(ft,{className:"size-4"}),"Back to Promotion Hub"]})})]})})]})}export{Kt 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.