PageSourceSearch

https://slantapp.ai/assets/ChainDetail-Dlg14U3m.js

js slantapp.ai collected 2026-10-05 15:05:31 UTC 191,226 bytes, 22 lines download raw bytes

1import{aq as Dt,c as we,r as p,F as ae,q as V,Q,j as e,$ as Ne,a0 as ye,a1 as $e,a2 as Ae,Z as he,i as qe,af as _t,a4 as re,S as Vt,a5 as Ua,B as w,ap as Oa,W as O,L as Y,C as z,K as Z,N as X,aa as ce,a as K,O as T,aB as Ma,aN as qa,ac as zt,au as Is,X as Pe,f as Qe,ae as Da,c3 as _a,b8 as at,aP as Ft,M as se,U as _e,I as He,am as Kt,aC as Hs,_ as Tt,P as Ye,G as Va,c4 as Ys,p as Bt,aM as mt,c5 as za,z as Ve,b_ as xt,o as be,d as Gt,aY as Js,at as Et,E as Ka,ax as Ba,c6 as Ga,b6 as Wa,aA as xe,b as Zs,n as et,ad as Qa,a3 as Wt,ao as Ha,A as rt,aO as Ya,T as Xs,aL as ea,v as it,w as nt,x as lt,u as Ja,c7 as ta,J as Za,an as Xa}from"./index-tc5-nNLC.js";import{C as er}from"./CampaignOfferPanel-DCzIYjFg.js";import{L as W}from"./label-MwGx_WS4.js";import{T as Pt}from"./textarea-DN2rY_yY.js";import{S as ze,a as Ke,b as Be,c as Ge,d as oe}from"./select-Bsa-6vNv.js";import{A as Ts,a as Ps,b as $s,c as As,d as Rs,e as Ls,f as Fs,g as Es}from"./alert-dialog-BhS3-18U.js";import{C as tr,S as sr}from"./ChainSmsJoinCard-Da34ke89.js";import{S as sa}from"./switch-B37nBmXq.js";import{S as ar}from"./settings-2-CKQWlrE-.js";import{I as rr}from"./info-yYpYmMbQ.js";import{B as ir}from"./bell-off-BIWBf8w9.js";import{M as ot}from"./message-square-BbWo1nY5.js";import{A as nr}from"./arrow-down-CHdaY5Vj.js";import{u as aa}from"./useResilientWebSocket-DLEs5bEM.js";import{W as lr}from"./wifi-D0nQ3Vrl.js";import{C as Qt}from"./chevron-up-1gTexUQn.js";import{C as Ht}from"./chevron-down-DOFZ7rzv.js";import{E as Ut}from"./eye-7YOw3q0i.js";import{P as ct}from"./progress-CJIgvptw.js";import{S as tt}from"./shield-check-LwYRIJhL.js";import{T as or}from"./trending-down-Dsd0TGG8.js";import{T as ra}from"./timer-DhqFX9ZZ.js";import{L as cr}from"./lightbulb-BBExVgZ9.js";import{D as dr}from"./DirectBookingPanel-Dz0l1Q8a.js";import{C as mr}from"./ChainCreateModal-DzbH-Ue8.js";import{O as Us}from"./ObjectUploader-CHjzmTJQ.js";import{A as xr}from"./index-CdNioXUL.js";import{m as me}from"./proxy-DEMj9hzd.js";import{P as hr}from"./party-popper-GuyWa3aC.js";import{V as ur}from"./VoiceCommandTrigger-C43pwYgz.js";import{C as pr}from"./ChainGroupChat-BtvPYw6B.js";import{S as ia}from"./shirt-DrRASvnL.js";import{P as gr}from"./package-AjRnjGip.js";import{C as na}from"./circle-check-B8vEXYAG.js";import{C as Os}from"./chainCapabilities-B-1iRMBp.js";import{E as ie}from"./external-link-wMXh6D17.js";import{E as fr}from"./EmergencyButton-B9I0ZUBw.js";import{S as br}from"./StopMedia-BwH1jfND.js";import{G as la}from"./gift-CcGpxH7x.js";import{A as De}from"./award-C2MYBTvh.js";import{C as jr}from"./chevron-left-ObYy0wWc.js";import{C as We}from"./coins-B0XOg3gp.js";import{C as vr}from"./copy-Bquar6tk.js";import{D as $t}from"./download-DtCkiRGd.js";import{I as oa}from"./image-CUhS0kqX.js";import{L as Ms}from"./link-BigN4W0t.js";import{N as dt}from"./network-BEQEgBu7.js";import{G as Ot}from"./git-branch-BtAfSLNp.js";import{G as At}from"./globe-CrY5Q3gB.js";import{F as qs}from"./file-check-DNqLAA85.js";import{H as Nr}from"./hash-B1pZho-G.js";import{P as Mt}from"./play-DZhwD__F.js";import{B as yr}from"./bus-C1fQ2ti_.js";import{S as wr}from"./ship-OnXFWfok.js";import{C as kr}from"./car-1fd8vI3H.js";import{T as Cr}from"./tram-front-Bt1F7iED.js";import{P as Sr}from"./pencil-C45dJbNG.js";import"./format-D3jHS6VA.js";import"./differenceInCalendarDays-YJe1lx93.js";import"./stopMedia-Bh_Afahl.js";import"./sliders-horizontal-cT5PL8wM.js";import"./key-round-DDB3NZDv.js";import"./badge-check-CTqMqkJP.js";import"./index-C-y5wYFI.js";import"./checkbox-DUKovseV.js";import"./popover-Xcb99LU7.js";import"./circle-check-big-CUgqPmz6.js";import"./flightPassengerValidation-Kk4zx05c.js";import"./react-stripe.esm-xOU6hUO5.js";import"./index-Bf1HScv8.js";import"./credit-card-B0XDcUdX.js";import"./tabs-D2OfY7RH.js";import"./bookingProviderLabels-sk8eXM4M.js";import"./hotel-BRZfVFiM.js";import"./utensils-crossed-Bhs6Ah8Z.js";import"./types-BkAQ3Jcx.js";import"./zod-Bu1KJ1kD.js";import"./form-BdD-KO2h.js";import"./radio-group-DyfPIJZB.js";import"./TrackingDisclosure-78Mp8TTf.js";import"./alert-DfCdUCbk.js";import"./index-DL2Sqs6c.js";import"./lock-CWiCoas5.js";import"./throttle-BDyZMAVR.js";import"./RecommendationWizard-OoPlwljz.js";import"./arrow-left-kYemJdx8.js";import"./log-in-DrADV0ef.js";import"./send-B0Xv9vwc.js";import"./pin-CfN4v5O6.js";import"./phone-DkyZOs2j.js";import"./shield-alert-Bj33tRge.js";/**
2 * @license lucide-react v0.453.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ir=Dt("CirclePause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]);/**
7 * @license lucide-react v0.453.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Tr=Dt("Footprints",[["path",{d:"M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0Z",key:"1dudjm"}],["path",{d:"M20 20v-2.38c0-2.12 1.03-3.12 1-5.62-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0Z",key:"l2t8xc"}],["path",{d:"M16 17h4",key:"1dejxt"}],["path",{d:"M4 13h4",key:"1bwh8b"}]]);/**
12 * @license lucide-react v0.453.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const st=Dt("HeartHandshake",[["path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z",key:"c3ymky"}],["path",{d:"M12 5 9.04 7.96a2.17 2.17 0 0 0 0 3.08c.82.82 2.13.85 3 .07l2.07-1.9a2.82 2.82 0 0 1 3.79 0l2.96 2.66",key:"4oyue0"}],["path",{d:"m18 15-2-2",key:"60u0ii"}],["path",{d:"m15 18-2-2",key:"6p76be"}]]),Pr=[{value:"discount",label:"Discount"},{value:"giveaway",label:"Giveaway"},{value:"drop",label:"Drop (chain-completion reward)"},{value:"affiliate",label:"Affiliate"},{value:"experience",label:"Experience"},{value:"voucher",label:"Voucher"}],Ds={title:"",description:"",offerType:"discount",partnerName:"",discountValue:"",discountUnit:"percent",validFrom:"",validUntil:"",locationLat:"",locationLng:"",stopAssignment:"",slotPosition:"standard",poolContributionCents:"",mediaUrl:"",redemptionInstructions:"",termsAndConditions:"",maxClaimsTotal:""},Rt="partner_offer_draft";function $r({open:t,onOpenChange:a,chainId:o,cashDropEnabled:c=!1}){const{toast:m}=we(),[i,r]=p.useState({...Ds}),[h,f]=p.useState(1);p.useEffect(()=>{if(t)try{const n=sessionStorage.getItem(Rt);if(n){const k=JSON.parse(n);k.chainId===o&&k.form&&(r(k.form),sessionStorage.removeItem(Rt))}}catch{}}
16,[t,o]);const d=(n,k)=>r(b=>({...b,[n]:k})),l=ae({mutationFn:async n=>{const k=await Q("POST",`/api/chains/${o}/offers`,n);if(!k.ok){const b=await k.json();if(b.error==="TOP_SLOT_TAKEN")throw new Error("Top slot is already occupied. Choose Standard slot or wait for the current offer to expire.");if(b.errors){const j=Object.values(b.errors)[0];throw new Error(j)}throw new Error(b.error||"Failed to create offer")}return k.json()},onSuccess:()=>{V.invalidateQueries({queryKey:["/api/chains",o,"offers"]}),V.invalidateQueries({queryKey:["/api/chains",o]}),m({title:"Partner offer created",description:"The offer is now live on this chain."}),a(!1),r({...Ds}),f(1)},onError:n=>{if(n.message.includes("401")||n.message.toLowerCase().includes("unauthorized")){try{sessionStorage.setItem(Rt,JSON.stringify({chainId:o,form:i}))}catch{}window.location.href=`/api/login?returnTo=${encodeURIComponent(window.location.pathname+window.location.search)}`;return}m({title:"Failed to create offer",description:n.message,variant:"destructive"})}}),N=()=>{const n={title:i.title.trim(),description:i.description.trim()||void 0,offerType:i.offerType,partnerName:i.partnerName.trim()||void 0,slotPosition:i.slotPosition,poolContributionCents:i.poolContributionCents?parseInt(i.poolContributionCents):0,stopAssignment:i.stopAssignment.trim()||void 0,redemptionInstructions:i.redemptionInstructions.trim()||void 0,termsAndConditions:i.termsAndConditions.trim()||void 0,mediaUrl:i.mediaUrl.trim()||void 0,validFrom:i.validFrom||void 0,validUntil:i.validUntil||void 0,maxClaimsTotal:i.maxClaimsTotal?parseInt(i.maxClaimsTotal):void 0};i.discountValue&&(n.discountValue=parseFloat(i.discountValue),n.discountUnit=i.discountUnit),i.locationLat&&i.locationLng&&(n.locationLat=parseFloat(i.locationLat),n.locationLng=parseFloat(i.locationLng)),l.mutate(n)},g=i.title.trim().length>=2&&i.offerType.length>0&&(!i.redemptionInstructions.trim()||i.redemptionInstructions.trim().length>=10)&&!(i.validFrom&&i.validUntil&&i.validUntil<=i.validFrom);return e.jsx(Ne,{open:t,onOpenChange:a,children:e.jsxs(ye,{className:"max-w-2xl max-h-[90vh] flex flex-col p-0 overflow-hidden",children:[e.jsxs($e,{className:"p-6 border-b shrink-0",children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(he,{className:"w-5 h-5 text-primary"}),"Add Partner Offer — Step ",h," of 2"]}),e.jsx("div",{className:"flex gap-1 mt-3",children:[1,2].map(n=>e.jsx("div",{className:qe("h-1 flex-1 rounded-full transition-colors",n<=h?"bg-primary":"bg-muted")},n))})]}),e.jsxs(_t,{className:"flex-1 p-6",children:[h===1&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(W,{htmlFor:"po-title",children:["Offer Title ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{id:"po-title",value:i.title,onChange:n=>d("title",n.target.value),placeholder:"e.g., 20% off at The Merch Stand",maxLength:255,"data-testid":"input-po-title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-description",children:"Description"}),e.jsx(Pt,{id:"po-description",value:i.description,onChange:n=>d("description",n.target.value),placeholder:"What does the fan get?",maxLength:1e3,rows:3,"data-testid":"input-po-description"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(W,{children:["Offer Type ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(ze,{value:i.offerType,onValueChange:n=>d("offerType",n),children:[e.jsx(Ke,{"data-testid":"select-po-offer-type",children:e.jsx(Be,{})}),e.jsx(Ge,{children:Pr.map(n=>e.jsx(oe,{value:n.value,children:n.label},n.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-partner-name",children:"Partner / Brand Name"}),e.jsx(re,{id:"po-partner-name",value:i.partnerName,onChange:n=>d("partnerName",n.target.value),placeholder:"e.g., Nike, Marriott",maxLength:120,"data-testid":"input-po-partner-name"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-discount-value",children:"Discount Value"}),e.jsx(re,{id:"po-discount-value",type:"number",min:"0",step:"0.01",value:i.discountValue,onChange:n=>d("discountValue",n.target.value),placeholder:"e.g., 20","data-testid":"input-po-discount-value"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:"Discount Unit"}),e.jsxs(ze,{value:i.discountUnit,onValueChange:n=>d("discountUnit",n),children:[e.jsx(Ke,{"data-testid":"select-po-discount-unit",children:e.jsx(Be,{})}),e.jsxs(Ge,{children:[e.jsx(oe,{value:"percent",children:"Percent (%)"}),e.jsx(oe,{value:"currency",children:"Fixed ($)"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-stop",children:"Stop Assignment"}),e.jsx(re,{id:"po-stop",value:i.stopAssignment,onChange:n=>d("stopAssignment",n.target.value),placeholder:"Node ID or stop n
16ame this offer is pinned to","data-testid":"input-po-stop-assignment"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Link this offer to a specific stop on the chain."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-valid-from",children:"Valid From"}),e.jsx(re,{id:"po-valid-from",type:"datetime-local",value:i.validFrom,min:new Date().toISOString().slice(0,16),onChange:n=>d("validFrom",n.target.value),onClick:n=>{try{n.currentTarget.showPicker()}catch{}},"data-testid":"input-po-valid-from"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-valid-until",children:"Valid Until"}),e.jsx(re,{id:"po-valid-until",type:"datetime-local",value:i.validUntil,min:i.validFrom||new Date().toISOString().slice(0,16),onChange:n=>d("validUntil",n.target.value),onClick:n=>{try{n.currentTarget.showPicker()}catch{}},"data-testid":"input-po-valid-until"})]})]}),i.validFrom&&i.validUntil&&i.validUntil<=i.validFrom&&e.jsx("p",{className:"text-xs text-destructive","data-testid":"text-po-date-error",children:"Valid Until must be after Valid From"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-max-claims",children:"Max Claims (0 = unlimited)"}),e.jsx(re,{id:"po-max-claims",type:"number",min:"0",value:i.maxClaimsTotal,onChange:n=>d("maxClaimsTotal",n.target.value),placeholder:"0","data-testid":"input-po-max-claims"})]})]}),h===2&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{className:"text-base font-semibold",children:"Slot Position"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Top slot is the highest-visibility placement on the chain detail page."}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{value:"top",label:"Top Slot",desc:"Hero banner. One per chain.",icon:Vt,color:"border-amber-500 text-amber-500"},{value:"standard",label:"Standard",desc:"Grid placement.",icon:he,color:"border-slate-500 text-slate-400"}].map(n=>{const k=n.icon,b=i.slotPosition===n.value;return e.jsxs("button",{type:"button",onClick:()=>d("slotPosition",n.value),"data-testid":`button-slot-${n.value}`,className:qe("flex items-start gap-3 w-full text-left rounded-lg border-2 p-4 transition-colors",b?"border-primary bg-primary/10":"border-border hover:border-muted-foreground bg-muted/30"),children:[e.jsx(k,{className:qe("w-5 h-5 shrink-0 mt-0.5",b?"text-primary":n.color)}),e.jsxs("div",{children:[e.jsx("div",{className:qe("text-sm font-semibold",b?"text-primary":""),children:n.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:n.desc})]})]},n.value)})}),i.slotPosition==="top"&&e.jsx("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3 text-xs text-amber-800 dark:text-amber-200","data-testid":"alert-top-slot",children:"If another active offer already holds the top slot on this chain, creation will fail with a conflict error."})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-pool",children:"Pool Contribution (cents)"}),e.jsx(re,{id:"po-pool",type:"number",min:"0",value:i.poolContributionCents,onChange:n=>d("poolContributionCents",n.target.value),placeholder:"e.g., 5000 = $50.00","data-testid":"input-po-pool-contribution"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i.poolContributionCents&&parseInt(i.poolContributionCents)>0?`$${(parseInt(i.poolContributionCents)/100).toFixed(2)} added to chain prize pool`:"Amount in cents that will be added to this chain's prize pool."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-media",children:"Media URL"}),e.jsx(re,{id:"po-media",type:"url",value:i.mediaUrl,onChange:n=>d("mediaUrl",n.target.value),placeholder:"https://cdn.example.com/banner.jpg","data-testid":"input-po-media-url"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-redemption",children:"Redemption Instructions"}),e.jsx(Pt,{id:"po-redemption",value:i.redemptionInstructions,onChange:n=>d("redemptionInstructions",n.target.value),placeholder:"How does the fan redeem this offer? Min 10 characters.",maxLength:300,rows:3,"data-testid":"input-po-redemption"}),i.redemptionInstructions.trim().length>0&&i.redemptionInstructions.trim().length<10&&e.jsx("p",{className:"text-xs text-destructive",children:"Must be at least 10 characters."}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.redemptionInstructions.length,"/300"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-tnc",children:"Terms & Conditions"}),e.jsx(Pt,{id:"po-tnc",value:i.termsAndConditions,onChange:n=>d("termsAndConditions",n.target.value),placeholder:"Optional. Legal terms for this offer.",maxLength:1e3,rows:3,"data-testid":"input-po-terms"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-lat",children:"Location Latitude"}),e.jsx(re,{id:"po-lat",type:"number",step:"any",value:i.locationLat,onChange:n=>d("locationLat",n.target.value),placeholder:"e.g., 40.7580","data-testid":"input-po-lat"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"po-lng",children:"Location Longitude"}),e.jsx(re,{id:"po-lng",type:"number",step:"any",value:i.locationLng,onChange:n=>d("locationLng",n.target.value),placeholder:"e.g., -73.9855","data-testid":"input-po-lng"})]})]})]})]}),e.jsx(Ua,{className:"p-6 border-t shrink-0 flex-row justify-between gap-2",children:h===1?e.jsxs(e.Fragment,{children:[e.jsx(w,{variant:"outline",onClick:()=>a(!1),"data-testid":"button-po-cancel",children:"Cancel"}),e.jsx(w,{onClick:()=>f(2),disabled:!g,"data-testid":"button-po-next",children:"Next →"})]}):e.jsxs(e.Fragment,{children:[e.jsx(w,{variant:"outline",onClick:()=>f(1),"data-testid":"button-po-back",children:"← Back"}),e.jsx(w,{onClick:N,disabled:l.isPending,"data-testid":"button-po-create",children:l.isPending?"Creating…":"Create Offer"})]})})]})})}const Ar=[{value:"all",label:"All updates",description:"Get every text from every chain you join.",icon:e.jsx(Ma,{className:"h-4 w-4 text-green-500"})},{value:"critical_only",label:"Critical only",description:"Only urgent messages get texted. Routine updates go to the app.",icon:e.jsx(qa,{className:"h-4 w-4 text-yellow-500"})},{value:"none",label:"Off",description:"No texts. All updates are in the app only.",icon:e.jsx(ir,{className:"h-4 w-4 text-muted-foreground"})}],Rr=[{category:"Event",high:"All",medium:"All",low:"Critical only",cap:"5/day"},{category:"Travel",high:"All",medium:"All",low:"Critical only",cap:"5/day"},{category:"Activation",high:"All",medium:"Critical only",low:"Critical only",cap:"2/day"},{category:"Community",high:"Critical only",medium:"Critical only",low:"Off",cap:"1/day"},{category:"Content",high:"Off",medium:"Off",low:"Off",cap:"0/day"}];function Lr({memberIdentityId:t,onClose:a}){var f,d;const{toast:o}=we(),c=Oa(),m=O({queryKey:["/api/sms/membership/defaults",t],queryFn:()=>fetch(`/api/sms/membership/defaults?memberIdentityId=${t}`).then(l=>l.json()),enabled:!!t,staleTime:3e4}),i=ae({mutationFn:l=>Q("PATCH","/api/sms/membership/defaults",{memberIdentityId:t,...l}),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/sms/membership/defaults",t]}),o({title:"Signal preferences saved"})},onError:l=>{o({title:"Failed to save",description:l.message,variant:"destructive"})}}),r=((f=m.data)==null?void 0:f.signalDefaultMode)??"critical_only",h=((d=m.data)==null?void 0:d.signalAutoEnable)??!0;return m.isLoading?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Y,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6","data-testid":"signal-defaults-screen",children:[e.jsxs(z,{children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(ar,{className:"h-4 w-4"}),"Signal Auto-Enable"]}),e.jsx(ce,{children:"When you join a new chain, Slant Signal is automatically activated using the recommended delivery mode for that chain type."})]}),e.jsx(K,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(W,{htmlFor:"signal-auto-enable",className:"flex flex-col gap-1 cursor-pointer",children:[e.jsx("span",{className:"font-medium",children:"Auto-enable for new chains"}),e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:h?"Texts are on by default when you join":"You must manually enable texts per chain"})]}),e.jsx(sa,{id:"signal-auto-enable","data-testid":"toggle-signal-auto-enable",checked:h,disabled:i.isPending,onCheckedChange:l=>i.mutate({signalAutoEnable:l})})]})})]}),h&&e.jsxs(z,{children:[e.jsxs(Z,{className:"pb-3",children:[e.jsx(X,{className:"text-base",children:"Default delivery mode"}),e.jsx(ce,{children:"This is your baseline. Individual chains may get a different recommended mode based on their type and urgency — you can always override per chain."})]}),e.jsx(K,{className:"space-y-2",children:Ar.map(l=>{const N=l.value===r;return e.jsxs("button",{"data-testid":`signal-default-mode-${l.value}`,onClick:()=>i.mutate({signalDefaultMode:l.value}),disabled:i.isPending||N,className:qe("w-full flex items-start gap-3 rounded-lg border-2 p-3 text-left transition-colors",N?"border-primary bg-primary/5":"border-transparent bg-muted/40 hover:border-muted-foreground
16/30"),children:[e.jsx("div",{className:"mt-0.5",children:l.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:l.label}),N&&e.jsx(T,{variant:"default",className:"text-[10px] h-4",children:"Active"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:l.description})]}),i.isPending&&i.variables&&"signalDefaultMode"in i.variables&&i.variables.signalDefaultMode===l.value&&e.jsx(Y,{className:"h-4 w-4 animate-spin mt-0.5"})]},l.value)})})]}),e.jsxs(z,{children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(rr,{className:"h-4 w-4 text-muted-foreground"}),"How the policy works"]}),e.jsx(ce,{children:"When you join a chain, Slant Signal picks a recommended mode based on the chain's type and urgency. Your baseline above applies on top of these defaults."})]}),e.jsxs(K,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs","data-testid":"signal-policy-table",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-1.5 pr-3 font-medium text-muted-foreground",children:"Chain type"}),e.jsx("th",{className:"text-center py-1.5 px-2 font-medium text-green-600",children:"High"}),e.jsx("th",{className:"text-center py-1.5 px-2 font-medium text-yellow-600",children:"Medium"}),e.jsx("th",{className:"text-center py-1.5 px-2 font-medium text-muted-foreground",children:"Low"}),e.jsx("th",{className:"text-right py-1.5 pl-2 font-medium text-muted-foreground",children:"Cap"})]})}),e.jsx("tbody",{children:Rr.map(l=>e.jsxs("tr",{className:"border-b last:border-0","data-testid":`policy-row-${l.category.toLowerCase()}`,children:[e.jsx("td",{className:"py-1.5 pr-3 font-medium",children:l.category}),e.jsx("td",{className:"text-center py-1.5 px-2 text-green-700 dark:text-green-400",children:l.high}),e.jsx("td",{className:"text-center py-1.5 px-2 text-yellow-700 dark:text-yellow-400",children:l.medium}),e.jsx("td",{className:"text-center py-1.5 px-2 text-muted-foreground",children:l.low}),e.jsx("td",{className:"text-right py-1.5 pl-2 text-muted-foreground",children:l.cap})]},l.category))})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-2",children:"Critical messages bypass mode restrictions and respect a higher daily cap (2× the chain cap). Operators can mark messages as critical."})]})]}),a&&e.jsx(w,{"data-testid":"button-signal-defaults-close",variant:"outline",className:"w-full",onClick:a,children:"Done"})]})}function Fr({chainId:t,memberIdentityId:a}){const{toast:o}=we(),[c,m]=p.useState(!1),[i,r]=p.useState(!1),[h,f]=p.useState(!1),[d,l]=p.useState(!1),N=O({queryKey:["/api/sms/status",t,a],queryFn:()=>fetch(`/api/sms/status?chainId=${t}${a?`&memberIdentityId=${a}`:""}`).then(I=>I.json()),enabled:!!t,staleTime:3e4}),g=ae({mutationFn:()=>Q("POST","/api/sms/membership/pause",{memberIdentityId:a,days:30}),onSuccess:()=>{o({title:"Texts paused for 30 days"}),V.invalidateQueries({queryKey:["/api/sms/status",t]}),V.invalidateQueries({queryKey:["/api/sms/membership/status"]}),m(!1)},onError:I=>{o({title:"Pause failed",description:I.message,variant:"destructive"})}}),n=ae({mutationFn:()=>Q("POST","/api/sms/membership/downgrade",{memberIdentityId:a}),onSuccess:()=>{o({title:"Downgraded to Essentials"}),V.invalidateQueries({queryKey:["/api/sms/status",t]}),V.invalidateQueries({queryKey:["/api/sms/membership/status"]}),l(!1),m(!1)},onError:I=>{o({title:"Downgrade failed",description:I.message,variant:"destructive"})}}),k=ae({mutationFn:()=>Q("POST","/api/sms/membership/cancel",{memberIdentityId:a}),onSuccess:()=>{o({title:"Signal membership canceled"}),V.invalidateQueries({queryKey:["/api/sms/status",t]}),V.invalidateQueries({queryKey:["/api/sms/membership/status"]}),f(!1),m(!1)},onError:I=>{o({title:"Cancel failed",description:I.message,variant:"destructive"})}}),b=N.data;if(N.isLoading)return null;if(!(b!=null&&b.subscribed))return e.jsx("div",{className:"mt-4","data-testid":"chain-sms-join-section",children:e.jsx(tr,{chainId:t})});const j=b.tier==="pro"?"Signal Pro":"Signal Essentials",v=b.tier==="pro"?e.jsx(Vt,{className:"h-3 w-3"}):e.jsx(he,{className:"h-3 w-3"}),S=b.status==="active"?"default":b.status==="paused"?"secondary":"destructive",A=a;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-muted/40","data-testid":"chain-sms-status-banner",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(ot,{className:"h-4 w-4 text-blue-500"}),e.jsxs(T,{variant:S,className:"flex items-center gap-1",children:[v,j]}),b.status==="past_due"&&e.jsx(T,{variant:"destructive",className:"text-xs",children:"Payment due"}),b.status==="paused"&&e.jsx(T,{variant:"outline",className:"text-xs",children:"Paused"}),b.status==="suppressed"&&e.jsx(T,{variant:"outline",className:"text-xs",children:"Stopped"}),A&&e.jsx(sr,{chainId:t,memberIdentityId:A})]}),e.jsxs(Ne,{open:c,onOpenChange:m,children:[e.jsx(zt,{asChild:!0,children:e.jsxs(w,{"data-testid":"button-manage-sms",variant:"ghost",size:"sm",className:"h-7 gap-1",children:[e.jsx(Is,{className:"h-3.5 w-3.5"}),"Manage"]})}),e.jsxs(ye,{className:"max-w-sm",children:[e.jsx($e,{children:e.jsx(Ae,{children:"Manage Signal"})}),i&&A?e.jsx(Lr,{memberIdentityId:A,onClose:()=>r(!1)}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg bg-muted p-3 text-sm space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium",children:j}),e.jsx(T,{variant:b.status==="active"?"default":"secondary",className:"text-xs capitalize",children:b.status})]}),b.renewsAt&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:["Renews ",new Date(b.renewsAt).toLocaleDateString()]})]}),e.jsxs(w,{"data-testid":"button-signal-defaults",variant:"outline",size:"sm",className:"w-full",onClick:()=>r(!0),children:[e.jsx(Is,{className:"h-3.5 w-3.5 mr-2"}),"Signal defaults & policy"]}),b.status==="active"&&e.jsxs(w,{"data-testid":"button-pause-sms",variant:"outline",size:"sm",className:"w-full",onClick:()=>g.mutate(),disabled:g.isPending,children:[g.isPending?e.jsx(Y,{className:"h-3.5 w-3.5 animate-spin mr-2"}):e.jsx(Ir,{className:"h-3.5 w-3.5 mr-2"}),"Pause texts for 30 days"]}),b.tier==="pro"&&b.status==="active"&&e.jsxs(w,{"data-testid":"button-downgrade-sms",variant:"outline",size:"sm",className:"w-full text-yellow-600",onClick:()=>l(!0),children:[e.jsx(nr,{className:"h-3.5 w-3.5 mr-2"}),"Switch to Essentials ($4.99/mo)"]}),e.jsxs(w,{"data-testid":"button-cancel-sms",variant:"ghost",size:"sm",className:"w-full text-destructive hover:text-destructive",onClick:()=>f(!0),children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-2"}),"Cancel subscription"]})]})]})]})]}),e.jsx(Ts,{open:d,onOpenChange:l,children:e.jsxs(Ps,{children:[e.jsxs($s,{children:[e.jsx(As,{children:"Switch to Essentials?"}),e.jsx(Rs,{children:"You'll lose Pro features like MENU commands and VIP token delivery. Your rate drops to $4.99/month at next renewal."})]}),e.jsxs(Ls,{children:[e.jsx(Fs,{"data-testid":"button-downgrade-cancel",children:"Keep Pro"}),e.jsxs(Es,{"data-testid":"button-downgrade-confirm",onClick:()=>n.mutate(),disabled:n.isPending,children:[n.isPending&&e.jsx(Y,{className:"h-4 w-4 animate-spin mr-2"}),"Switch to Essentials"]})]})]})}),e.jsx(Ts,{open:h,onOpenChange:f,children:e.jsxs(Ps,{children:[e.jsxs($s,{children:[e.jsx(As,{children:"Cancel Signal membership?"}),e.jsx(Rs,{children:"You'll stop receiving SMS updates from all your chains. You can resubscribe anytime."})]}),e.jsxs(Ls,{children:[e.jsx(Fs,{"data-testid":"button-cancel-confirm-back",children:"Keep Signal"}),e.jsxs(Es,{"data-testid":"button-cancel-confirm",onClick:()=>k.mutate(),disabled:k.isPending,className:"bg-destructive hover:bg-destructive/90",children:[k.isPending&&e.jsx(Y,{className:"h-4 w-4 animate-spin mr-2"}),"Cancel subscription"]})]})]})})]})}function Er({chainId:t,campaignId:a,campaignName:o}){var I,L,P,$,M;const[c,m]=p.useState(!1),[i,r]=p.useState(!1),{user:h}=Qe(),f=p.useCallback(U=>{(U==null?void 0:U.type)==="live_kpi_update"&&V.invalidateQueries({queryKey:["/api/presale/kpi/live",{chainId:t}]})},[t]),{send:d,isConnected:l,isAuthenticated:N}=aa({userId:h==null?void 0:h.id,onMessage:f});p.useEffect(()=>{const U=l&&N;r(U),U&&d({type:"join_room",roomId:t,roomType:"chain_live"})},[l,N,t,d]);const{data:g,isLoading:n,isError:k,dataUpdatedAt:b}=O({queryKey:["/api/presale/kpi/live",{chainId:t}],enabled:c,refetchInterval:c&&!i?3e4:!1}),j=g==null?void 0:g.kpis,v=()=>{V.invalidateQueries({queryKey:["/api/presale/kpi/live",{chainId:t}]})},S=j?((I=j.irlProofConversion.redemptions)==null?void 0:I.total)??0:0,A=j?(((L=j.irlProofConversion.dwellTime)==null?void 0:L.avgSeconds)??0)/60:0;return e.jsxs(z,{className:"bg-slate-900/80 border-slate-700 backdrop-blur-sm","data-testid":"chain-live-report",children:[e.jsx(Z,{className:"cursor-pointer select-none",onClick:()=>m(!c),children:e.jsxs(X,{className:"flex items-center justify-between text-white",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Da,{className:"w-5 h-5 text-emerald-400"}),e.jsx("span",{children:"Live Report"}),o&&e.jsx(T,{variant:"outline",className:"text-xs text-amber-300 border-amber-500/40",children:o}),c&&j&&e.jsxs(T,{className:"bg-emerald-500/20 text-emerald-300 border-emerald-500/40 text-xs gap-1",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-emerald-500"})]}),i?"Live":"Live · 30s"]}),c&&(i?e.jsxs(T,{className:"bg-slate-700/60 text-slate-300 border-slate-600/40 text-xs gap-1","data-testid":"ws-status-connected",children:[e.jsx(lr,{className:"w-2.5 h-2.5 text-emerald-400"}),"Push"]}):e.jsxs(T,{className:"bg-slate-700/60 text-slate-400 border-slate-600/40 text-xs gap-1","data-testid":"ws-status-polling",children:[e.jsx(_a,{className:"w-2.5 h-2.5"}),"Polling"]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx(w,{variant:"ghost",size:"sm",onClick:U=>{U.stopPropagation(),v()},className:"text-slate-400 hover:text-white h-7 px-2","data-testid":"button-refresh-live-report",children:e.jsx(at,{className:"w-3.5 h-3.5"})}),c?e.jsx(Qt,{className:"w-5 h-5 text-slate-400"}):e.jsx(Ht,{className:"w-5 h-5 text-slate-400"})]})]})}),c&&e.jsx(K,{className:"space-y-4 pt-0",children:n?e.jsxs("div",{className:"flex items-center justify-center py-8","data-testid":"live-report-loading",children:[e.jsx(Y,{className:"w-6 h-6 text-amber-500 animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-slate-400",children:"Loading live data..."})]}):k?e.jsxs("div",{className:"flex items-center justify-center py-6 gap-3","data-testid":"live-report-error",children:[e.jsx("span",{className:"text-sm text-red-400",children:"Failed to load live data."}),e.jsxs(w,{variant:"outline",size:"sm",onClick:v,className:"text-xs","data-testid":"button-retry-live-report",children:[e.jsx(at,{className:"w-3 h-3 mr-1"})," Retry"]})]}
16):j?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3","data-testid":"live-report-awareness",children:[e.jsx(ve,{icon:Ft,value:((P=j.awarenessReach.qrScans)==null?void 0:P.total)??0,label:"QR Scans",variant:"amber",testId:"kpi-qr-scans"}),e.jsx(ve,{icon:Ut,value:j.awarenessReach.landingViews??0,label:"Page Views",variant:"blue",testId:"kpi-page-views"}),e.jsx(ve,{icon:se,value:(($=j.irlProofConversion.geofenceEntries)==null?void 0:$.total)??0,label:"Check-ins",variant:"emerald",testId:"kpi-checkins"}),e.jsx(ve,{icon:_e,value:((M=j.irlProofConversion.geofenceEntries)==null?void 0:M.unique)??0,label:"Unique Visitors",variant:"purple",testId:"kpi-unique-visitors"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3","data-testid":"live-report-engagement",children:[e.jsx(ve,{icon:He,value:`${A.toFixed(1)}m`,label:"Avg Dwell Time",variant:"teal",testId:"kpi-dwell-time"}),e.jsx(ve,{icon:Kt,value:`${((j.efficiencyQuality.scanToVisitRate??0)*100).toFixed(1)}%`,label:"Scan → Visit",variant:"amber",testId:"kpi-scan-to-visit"}),e.jsx(ve,{icon:Hs,value:S,label:"Redemptions",variant:"emerald",testId:"kpi-redemptions"})]}),b&&e.jsxs("p",{className:"text-xs text-slate-500 text-right","data-testid":"live-report-timestamp",children:["Updated ",new Date(b).toLocaleTimeString(),i?" · push enabled":" · polling every 30s"]})]}):e.jsx("div",{className:"text-center py-6 text-sm text-slate-500","data-testid":"live-report-empty",children:"No live data available for this chain yet. Activity will appear as users interact with the campaign."})})]})}const Ur={amber:{bg:"bg-amber-500/10 border-amber-500/20",icon:"text-amber-400",value:"text-amber-200"},blue:{bg:"bg-blue-500/10 border-blue-500/20",icon:"text-blue-400",value:"text-blue-200"},emerald:{bg:"bg-emerald-500/10 border-emerald-500/20",icon:"text-emerald-400",value:"text-emerald-200"},purple:{bg:"bg-purple-500/10 border-purple-500/20",icon:"text-purple-400",value:"text-purple-200"},teal:{bg:"bg-teal-500/10 border-teal-500/20",icon:"text-teal-400",value:"text-teal-200"}};function ve({icon:t,value:a,label:o,variant:c,testId:m}){const i=Ur[c];return e.jsxs("div",{className:`rounded-lg p-3 border ${i.bg}`,"data-testid":m,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(t,{className:`w-4 h-4 ${i.icon}`}),e.jsx("span",{className:"text-xs text-slate-400",children:o})]}),e.jsx("div",{className:`text-xl font-bold ${i.value}`,children:a})]})}function Or({chainId:t,campaignId:a,campaignName:o,creatorId:c}){var M,U;const[m,i]=p.useState(!1),[r,h]=p.useState(null),[f,d]=p.useState(!1),{toast:l}=we(),{user:N}=Qe(),g=p.useCallback(y=>{(y==null?void 0:y.type)==="live_kpi_update"&&d(!0)},[]),{send:n,isConnected:k,isAuthenticated:b}=aa({userId:N==null?void 0:N.id,onMessage:g});p.useEffect(()=>{k&&b&&n({type:"join_room",roomId:t,roomType:"chain_live"})},[k,b,t,n]);const{data:j}=O({queryKey:["/api/impact/portfolio",c],enabled:!!c}),v=ae({mutationFn:async()=>{d(!1);const y=new Date,B=new Date(y.getTime()-30*24*60*60*1e3);return(await Q("POST","/api/presale/kpi/majority-report",{campaignId:a,startDate:B.toISOString(),endDate:y.toISOString()})).json()},onSuccess:y=>{h(y.report||y),l({title:"Majority Report updated",description:"Report has been regenerated with the latest data."})},onError:()=>{l({title:"Report generation failed",description:"Please try again.",variant:"destructive"})}}),S={high:"bg-emerald-500/20 text-emerald-300 border-emerald-500/40",medium:"bg-amber-500/20 text-amber-300 border-amber-500/40",low:"bg-red-500/20 text-red-300 border-red-500/40"},A=r==null?void 0:r.majorityProof,I=r==null?void 0:r.liftVsBaseline,L=r==null?void 0:r.funnelConversion,P=r==null?void 0:r.settlementPreview,$=r==null?void 0:r.dwellTimeAnalytics;return e.jsxs(z,{className:"bg-slate-900/80 border-slate-700 backdrop-blur-sm","data-testid":"chain-majority-report",children:[e.jsx(Z,{className:"cursor-pointer select-none",onClick:()=>i(!m),children:e.jsxs(X,{className:"flex items-center justify-between text-white",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Tt,{className:"w-5 h-5 text-purple-400"}),e.jsx("span",{children:"Majority Report"}),o&&e.jsx(T,{variant:"outline",className:"text-xs text-amber-300 border-amber-500/40",children:o})]}),m?e.jsx(Qt,{className:"w-5 h-5 text-slate-400"}):e.jsx(Ht,{className:"w-5 h-5 text-slate-400"})]})}),m&&e.jsxs(K,{className:"space-y-4 pt-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!a,title:a?void 0:"Link a campaign to this chain to generate a report",className:"border-purple-500/50 text-purple-300 hover:bg-purple-500/10","data-testid":"button-generate-majority-report",children:[v.isPending?e.jsx(Y,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(at,{className:"w-3.5 h-3.5 mr-1.5"}),r?"Update Report":"Generate Report"]}),(r==null?void 0:r.generatedAt)&&e.jsxs("span",{className:"text-xs text-slate-500","data-testid":"majority-report-timestamp",children:["Last generated: ",new Date(r.generatedAt).toLocaleStr
16ing()]})]}),f&&r&&e.jsxs("div",{className:"flex items-center justify-between gap-2 bg-amber-500/10 border border-amber-500/30 rounded-lg px-3 py-2","data-testid":"majority-report-new-data-banner",children:[e.jsxs("span",{className:"text-xs text-amber-300 flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),"New activity detected — data has changed since this report was generated."]}),e.jsxs(w,{size:"sm",variant:"ghost",onClick:()=>v.mutate(),disabled:v.isPending||!a,className:"h-6 px-2 text-xs text-amber-300 hover:text-amber-100 hover:bg-amber-500/20 shrink-0","data-testid":"button-refresh-report-from-banner",children:[e.jsx(at,{className:"w-3 h-3 mr-1"}),"Refresh"]})]}),v.isPending&&!r?e.jsxs("div",{className:"flex items-center justify-center py-8","data-testid":"majority-report-loading",children:[e.jsx(Y,{className:"w-6 h-6 text-purple-500 animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-slate-400",children:"Generating report..."})]}):r?e.jsxs("div",{className:"space-y-4",children:[r.executiveSummary&&e.jsxs("div",{className:"bg-gradient-to-r from-purple-500/10 to-indigo-500/10 rounded-lg p-4 border border-purple-500/20","data-testid":"majority-executive-summary",children:[r.executiveSummary.headline&&e.jsx("h4",{className:"text-white font-semibold text-sm mb-2",children:r.executiveSummary.headline}),r.executiveSummary.narrative&&e.jsx("p",{className:"text-sm text-slate-300 mb-3",children:r.executiveSummary.narrative}),r.executiveSummary.keyMetrics&&r.executiveSummary.keyMetrics.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3",children:r.executiveSummary.keyMetrics.map((y,B)=>e.jsxs("div",{className:"bg-slate-800/60 rounded-md px-3 py-1.5 border border-slate-700/50",children:[e.jsx("span",{className:"text-xs text-slate-400",children:y.label}),e.jsx("div",{className:"text-sm font-bold text-white","data-testid":`metric-value-${B}`,children:y.value})]},B))})]}),r.arrivalWaypoints&&r.arrivalWaypoints.length>0&&e.jsxs("div",{className:"bg-gradient-to-r from-sky-500/10 to-indigo-500/10 rounded-lg p-4 border border-sky-500/25","data-testid":"majority-arrival-waypoints",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ye,{className:"w-4 h-4 text-sky-300"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Arrival Waypoints"}),e.jsxs(T,{variant:"outline",className:"text-xs text-sky-300 border-sky-500/40",children:[r.arrivalWaypoints.length," confirmed"]})]}),e.jsx("div",{className:"space-y-3",children:r.arrivalWaypoints.map((y,B)=>e.jsxs("div",{className:"rounded-lg border border-slate-700/60 bg-slate-900/55 p-3","data-testid":`arrival-waypoint-${B}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-sky-300",children:y.travelerLabel}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white",children:y.name})]}),e.jsx(T,{className:"bg-sky-500/15 text-sky-200 border border-sky-500/25",children:y.route})]}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:y.segments.map((D,ue)=>e.jsxs("div",{className:"rounded-md bg-slate-800/70 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsxs("span",{className:"font-semibold text-slate-100",children:[D.origin," → ",D.destination]}),e.jsxs("span",{className:"text-sky-300",children:[D.carrier," ",D.flightNumber]})]}),e.jsxs("p",{className:"mt-1 text-[11px] text-slate-400",children:[D.departureLocal," → ",D.arrivalLocal]})]},`${D.flightNumber}-${ue}`))})]},`${y.route}-${y.arrivalAt}-${B}`))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[A&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-proof-card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(tt,{className:"w-4 h-4 text-purple-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Attribution Proof"}),A.confidenceLevel&&e.jsx(T,{className:`text-xs ${S[A.confidenceLevel]||S.low}`,children:A.confidenceLevel})]}),A.claim&&e.jsx("p",{className:"text-sm text-slate-300 mb-2",children:A.claim}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-lg font-bold text-purple-300","data-testid":"proof-movement",children:[(A.movementPercentage??0).toFixed(1),"%"]}),e.jsx("div",{className:"text-xs text-slate-500",children:"Movement"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-bold text-blue-300","data-testid":"proof-ex
16posed",children:A.totalExposed??0}),e.jsx("div",{className:"text-xs text-slate-500",children:"Exposed"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-bold text-emerald-300","data-testid":"proof-visited",children:A.totalVisited??0}),e.jsx("div",{className:"text-xs text-slate-500",children:"Visited"})]})]})]}),I&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-lift-card",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[(((M=I.earlyVsLateComparison)==null?void 0:M.growthPercent)??0)>=0?e.jsx(Kt,{className:"w-4 h-4 text-emerald-400"}):e.jsx(or,{className:"w-4 h-4 text-red-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:I.hasBaseline?"Lift vs Baseline":"Campaign Trend"})]}),I.metrics&&I.metrics.length>0&&e.jsx("div",{className:"space-y-2",children:I.metrics.map((y,B)=>{var D;return e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-slate-400",children:y.metricName}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-white font-medium",children:((D=y.campaignValue)==null?void 0:D.toLocaleString())??0}),y.liftPercent!==void 0&&e.jsxs("span",{className:y.liftPercent>=0?"text-emerald-400 text-xs":"text-red-400 text-xs",children:[y.liftPercent>=0?"+":"",y.liftPercent.toFixed(1),"%"]})]})]},B)})}),I.earlyVsLateComparison&&e.jsxs("div",{className:"mt-2 text-xs text-slate-400",children:["Early→Late growth: ",I.earlyVsLateComparison.growthPercent.toFixed(1),"%"]})]})]}),(L==null?void 0:L.stages)&&L.stages.length>0&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-funnel",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Hs,{className:"w-4 h-4 text-amber-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Conversion Funnel"})]}),L.overallConversionRate!==void 0&&e.jsxs(T,{variant:"outline",className:"text-xs text-amber-300 border-amber-500/40",children:[L.overallConversionRate.toFixed(1),"% overall"]})]}),e.jsx("div",{className:"space-y-2",children:L.stages.map((y,B)=>{var de;const D=((de=L.stages[0])==null?void 0:de.count)||1,ue=Math.max(5,y.count/D*100);return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-slate-400 w-24 text-right shrink-0",children:y.stage}),e.jsxs("div",{className:"flex-1 bg-slate-700/30 rounded-full h-6 relative overflow-hidden",children:[e.jsx("div",{className:"h-full bg-gradient-to-r from-amber-500/60 to-amber-400/40 rounded-full transition-all duration-500",style:{width:`${ue}%`}}),e.jsx("span",{className:"absolute inset-0 flex items-center px-2 text-xs text-white font-medium",children:y.count.toLocaleString()})]}),y.dropoffFromPrevious!==void 0&&y.dropoffFromPrevious>0&&e.jsxs("span",{className:"text-xs text-red-400 w-14 shrink-0",children:["-",y.dropoffFromPrevious.toFixed(0),"%"]})]},B)})})]}),$&&$.totalMeasured>0&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-dwell-time",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{className:"w-4 h-4 text-cyan-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Dwell Time Analytics"})]}),e.jsxs(T,{variant:"outline",className:"text-xs text-cyan-300 border-cyan-500/40",children:[$.totalMeasured," measured"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"bg-slate-900/60 rounded-md p-3 text-center border border-slate-700/30",children:[e.jsx("div",{className:"text-2xl font-bold text-cyan-300","data-testid":"dwell-avg-minutes",children:$.avgMinutes.toFixed(1)}),e.jsx("div",{className:"text-xs text-slate-500",children:"Avg Minutes"})]}),e.jsxs("div",{className:"bg-slate-900/60 rounded-md p-3 text-center border border-slate-700/30",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5",children:[e.jsx(ra,{className:"w-4 h-4 text-slate-400"}),e.jsxs("span",{className:"text-2xl font-bold text-white","data-testid":"dwell-avg-seconds",children:[Math.round($.avgSeconds),"s"]})]}),e.jsx("div",{className:"text-xs text-slate-500",children:"Avg Seconds"})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"text-xs text-slate-400 mb-2",children:"Duration Distribution"}),e.jsx("div",{className:"space-y-1.5",children:[{label:"< 30s",value:$.distribution.under30s,color:"bg-red-400/60"}
16,{label:"30s – 2m",value:$.distribution.under2m,color:"bg-amber-400/60"},{label:"2m – 5m",value:$.distribution.under5m,color:"bg-yellow-400/60"},{label:"5m – 15m",value:$.distribution.under15m,color:"bg-emerald-400/60"},{label:"15m+",value:$.distribution.over15m,color:"bg-cyan-400/60"}].map(y=>{const B=Math.max($.distribution.under30s,$.distribution.under2m,$.distribution.under5m,$.distribution.under15m,$.distribution.over15m,1),D=Math.max(3,y.value/B*100);return e.jsxs("div",{className:"flex items-center gap-2","data-testid":`dwell-bucket-${y.label}`,children:[e.jsx("span",{className:"text-xs text-slate-400 w-16 text-right shrink-0",children:y.label}),e.jsxs("div",{className:"flex-1 bg-slate-700/30 rounded-full h-4 relative overflow-hidden",children:[e.jsx("div",{className:`h-full ${y.color} rounded-full transition-all duration-500`,style:{width:`${D}%`}}),e.jsx("span",{className:"absolute inset-0 flex items-center px-2 text-[10px] text-white font-medium",children:y.value})]})]},y.label)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-slate-400 mb-2",children:"Visit Quality"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{className:"bg-slate-900/60 rounded-md p-2 border border-slate-700/30",children:[e.jsx("div",{className:"text-sm font-bold text-red-300","data-testid":"dwell-quality-passthrough",children:$.visitQuality.passThrough}),e.jsx("div",{className:"text-[10px] text-slate-500",children:"Pass-through"}),e.jsx("div",{className:"text-[10px] text-slate-600",children:"< 3 min"})]}),e.jsxs("div",{className:"bg-slate-900/60 rounded-md p-2 border border-slate-700/30",children:[e.jsx("div",{className:"text-sm font-bold text-amber-300","data-testid":"dwell-quality-visit",children:$.visitQuality.visit}),e.jsx("div",{className:"text-[10px] text-slate-500",children:"Visit"}),e.jsx("div",{className:"text-[10px] text-slate-600",children:"3 – 20 min"})]}),e.jsxs("div",{className:"bg-slate-900/60 rounded-md p-2 border border-slate-700/30",children:[e.jsx("div",{className:"text-sm font-bold text-emerald-300","data-testid":"dwell-quality-engaged",children:$.visitQuality.engaged}),e.jsx("div",{className:"text-[10px] text-slate-500",children:"Engaged"}),e.jsx("div",{className:"text-[10px] text-slate-600",children:"20+ min"})]})]})]})]}),P&&(P.totalRevenue??0)>0&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-settlement",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Va,{className:"w-4 h-4 text-emerald-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Settlement Preview"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-slate-400",children:"Total Revenue"}),e.jsxs("span",{className:"text-emerald-300 font-bold","data-testid":"settlement-total",children:["$",(P.totalRevenue??0).toLocaleString(void 0,{minimumFractionDigits:2})]})]}),(U=P.byRecipient)==null?void 0:U.filter(y=>y.amount>0).map((y,B)=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-slate-400",children:[y.recipientName," ",e.jsxs("span",{className:"text-xs",children:["(",y.rule,")"]})]}),e.jsxs("span",{className:"text-white",children:["$",y.amount.toLocaleString(void 0,{minimumFractionDigits:2})]})]},B))]})]}),j&&j.goals.length>0&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-pink-700/40","data-testid":"majority-impact-attribution",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(st,{className:"w-4 h-4 text-pink-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Impact Attribution"}),e.jsxs(T,{variant:"outline",className:"text-xs text-pink-300 border-pink-500/40",children:[j.totalGoals," goal",j.totalGoals!==1?"s":""]})]}),e.jsx("p",{className:"text-xs text-slate-400 mb-3",children:"Economic value from this campaign flows toward the creator's philanthropic goals"}),e.jsx("div",{className:"space-y-3",children:j.goals.map(y=>e.jsxs("div",{className:"bg-slate-900/50 rounded-lg p-3 border border-slate-700/30",children:[e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"text-sm font-medium text-white",children:y.title}),e.jsx("p",{className:"text-xs text-slate-400",children:y.beneficiaryName})]}),e.jsxs("span",{className:"text-sm font-bold text-pink-400 shrink-0 ml-2","data-testid":`impact-goal-raised-${y.id}
16`,children:["$",(y.summary.totalRaisedCents/100).toLocaleString(void 0,{minimumFractionDigits:2})]})]}),y.targetAmountCents&&y.summary.progressPercent!==null&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsxs("span",{className:"text-slate-500",children:["Target: $",(y.targetAmountCents/100).toLocaleString()]}),e.jsxs("span",{className:"text-pink-300",children:[y.summary.progressPercent,"%"]})]}),e.jsx(ct,{value:y.summary.progressPercent,className:"h-1.5"})]})]},y.id))}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-700/50 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"Total Impact Generated"}),e.jsxs("span",{className:"text-sm font-bold text-pink-300","data-testid":"impact-total-in-report",children:["$",(j.totalImpactCents/100).toLocaleString(void 0,{minimumFractionDigits:2})]})]})]}),r.recommendations&&r.recommendations.length>0&&e.jsxs("div",{className:"bg-slate-800/50 rounded-lg p-4 border border-slate-700/50","data-testid":"majority-recommendations",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(cr,{className:"w-4 h-4 text-amber-400"}),e.jsx("h4",{className:"text-white font-medium text-sm",children:"Recommendations"})]}),e.jsx("div",{className:"space-y-2",children:r.recommendations.map((y,B)=>e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(T,{variant:"outline",className:"text-xs shrink-0 mt-0.5 text-slate-400 border-slate-600",children:y.category}),e.jsx("span",{className:"text-slate-300",children:y.suggestion})]},B))})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"ghost",size:"sm",className:"text-slate-400 hover:text-white text-xs",onClick:()=>window.open(`/reports?tab=majority&campaign=${a}`,"_blank"),"data-testid":"button-view-full-report",children:[e.jsx(Ys,{className:"w-3.5 h-3.5 mr-1"}),"View Full Report in Reports Hub"]})})]}):e.jsxs("div",{className:"text-center py-6","data-testid":"majority-report-empty",children:[e.jsx(Tt,{className:"w-8 h-8 text-slate-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-slate-500 mb-3",children:"No majority report generated yet. Generate one to see attribution proof, lift analysis, and settlement preview."}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>v.mutate(),disabled:v.isPending||!a,title:a?void 0:"Link a campaign to this chain to generate a report",className:"border-purple-500/50 text-purple-300 hover:bg-purple-500/10","data-testid":"button-generate-first-report",children:[v.isPending?e.jsx(Y,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(Tt,{className:"w-3.5 h-3.5 mr-1.5"}),"Generate Majority Report"]})]})]})]})}function Mr(t){const{enabled:a,intervalMs:o=3e4,onEntry:c,onExit:m}=t,[i,r]=p.useState([]),[h,f]=p.useState(null),[d,l]=p.useState(!1),[N,g]=p.useState(null),n=p.useRef(null),k=p.useRef(c),b=p.useRef(m);k.current=c,b.current=m;const j=p.useCallback(async()=>{if(!navigator.geolocation)return g("Geolocation not supported"),null;try{const S=await new Promise((M,U)=>{navigator.geolocation.getCurrentPosition(M,U,{enableHighAccuracy:!0,timeout:15e3,maximumAge:1e4})}),{latitude:A,longitude:I,accuracy:L}=S.coords,$=await(await Q("POST","/api/location/check-in",{latitude:A,longitude:I,accuracy:L})).json();return f(new Date),g(null),$.entered.length>0&&$.entered.forEach(M=>{var U;return(U=k.current)==null?void 0:U.call(k,M)}),$.exited.length>0&&$.exited.forEach(M=>{var U;return(U=b.current)==null?void 0:U.call(b,M)}),r([...$.entered,...$.stillInside]),$}catch(S){return S instanceof GeolocationPositionError?S.code===S.PERMISSION_DENIED?g("Location permission denied"):S.code===S.POSITION_UNAVAILABLE?g("Location unavailable"):g("Location timeout"):g(S instanceof Error?S.message:"Check-in failed"),null}},[]);p.useEffect(()=>{if(!a){n.current&&(clearInterval(n.current),n.current=null),l(!1);return}return l(!0),j(),n.current=setInterval(j,o),()=>{n.current&&(clearInterval(n.current),n.current=null),l(!1)}},[a,o,j]);const v=p.useCallback(async()=>j(),[j]);return{activeFences:i,lastCheckTime:h,isPolling:d,error:N,manualCheckIn:v}}function qr({chainId:t,mapInstance:a,showOverlay:o=!0,onToggleOverlay:c}){const[m,i]=p.useState(o),[r,h]=p.useState(!1),f=p.useRef([]),d=p.useRef([]),{data:l}=O({queryKey:["/api/chains",t,"expression"],enabled:!!t,retry:!1}),{data:N}=O({queryKey:["/api/chains",t,"expression","validate"],enabled:!!t&&!!l,refetchInterval:(l==null?void 0:l.status)==="in_progress"?1e4:!1}),g=p.useCallback(()=>{const b=window.google;if(!b||!a||!(l!=null&&l.patternGeometry))return;f.current.forEach(v=>v.setMap(null)),f.current=[];const j=l.patternGeometry.coordinates.map(v=>({lat:v[1],lng:v[0]}));if(l.patternGeometry.type==="LineString"){const v=new b.maps.Polyline({path:j,geodesic:!0,strokeColor:l.patternColor,strokeOpacity:m?.5:0,strokeWeight:l.patternStrokeWidth+6,icons:[{icon:{path:"M 0,-1 0,1",strokeOpacity:.8,scale:3},offset:"0",repeat:"20px"}],zIndex:100});v.setMap(a),f.current.push(v)}else if(l.patternGeometry.type==="Polygon"){const v=new b.maps.Polygon({paths:j,strokeColor:l.patternColor,strokeOpacity:m?.6:0,strokeWeight:l.patternStrokeWidth,fillColor:l.patternColor,fillOpacity:m?.15:0,zIndex:100});v.setMap(a),f.current.push(v)}},[a,l,m]),n=p.useCallback(()=>{const b=window.google;!b||!a||!(N!=null&&N.points)||(d.current.forEach(j=>
16j.setMap(null)),d.current=[],m&&N.points.forEach((j,v)=>{const S=j.isMatched?"#22c55e":(l==null?void 0:l.patternColor)||"#6366f1",A=j.isMatched?1:.6,I=new b.maps.Marker({position:{lat:j.latitude,lng:j.longitude},map:a,title:j.label||`Target ${v+1}`,icon:{path:b.maps.SymbolPath.CIRCLE,scale:j.isMatched?12:10,fillColor:S,fillOpacity:A,strokeColor:"white",strokeWeight:2},zIndex:j.isMatched?150:110,opacity:m?1:0});if(j.label){const L=new b.maps.Marker({position:{lat:j.latitude,lng:j.longitude},map:a,icon:{url:"data:image/svg+xml;charset=UTF-8,"+encodeURIComponent(`
17              <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
18                <text x="12" y="8" text-anchor="middle" font-size="10" font-weight="bold" fill="${j.isMatched?"#166534":"#4338ca"}">${j.sequence}</text>
19              </svg>
20            `),anchor:new b.maps.Point(12,12)},zIndex:160,opacity:m?1:0});d.current.push(L)}d.current.push(I)}))},[a,N,l,m]);p.useEffect(()=>(a&&l&&(g(),n()),()=>{f.current.forEach(b=>b.setMap(null)),d.current.forEach(b=>b.setMap(null))}),[a,l,g,n]),p.useEffect(()=>{N!=null&&N.isComplete&&(l==null?void 0:l.status)!=="completed"&&(h(!0),_r((l==null?void 0:l.celebrationAnimation)||"confetti"))},[N==null?void 0:N.isComplete,l==null?void 0:l.status,l==null?void 0:l.celebrationAnimation]);const k=()=>{const b=!m;i(b),c==null||c(b),f.current.forEach(j=>{var v;j.setOptions&&j.setOptions({strokeOpacity:b?((v=l==null?void 0:l.patternGeometry)==null?void 0:v.type)==="Polygon"?.6:.5:0,fillOpacity:b?.15:0})}),d.current.forEach(j=>{j.setOpacity(b?1:0)})};return l?e.jsxs(e.Fragment,{children:[e.jsxs(z,{className:"mb-4","data-testid":"chain-expression-card",children:[e.jsxs(Z,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(X,{className:"text-lg flex items-center gap-2",children:[e.jsx(Bt,{className:"w-5 h-5 text-indigo-500"}),"Chain Expression"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(W,{htmlFor:"show-pattern",className:"text-sm text-muted-foreground",children:"Show Pattern"}),e.jsx(sa,{id:"show-pattern",checked:m,onCheckedChange:k,"data-testid":"toggle-pattern-overlay"})]})]}),e.jsx(ce,{children:l.title})]}),e.jsx(K,{children:e.jsxs("div",{className:"space-y-4",children:[l.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:l.description}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(T,{variant:l.status==="completed"?"default":"secondary",className:l.status==="completed"?"bg-green-600":"",children:[l.status==="completed"?e.jsx(mt,{className:"w-3 h-3 mr-1"}):e.jsx(Ys,{className:"w-3 h-3 mr-1"}),l.status]}),e.jsxs(T,{variant:"outline",className:"text-indigo-600",children:[e.jsx(Vt,{className:"w-3 h-3 mr-1"}),l.pointsReward," points"]})]}),N&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Progress"}),e.jsxs("span",{className:"font-medium",children:[N.matchedPoints," / ",N.totalPoints," targets"]})]}),e.jsx(ct,{value:N.percentComplete,className:"h-2","data-testid":"expression-progress"}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[N.percentComplete,"% complete"]})]}),(N==null?void 0:N.isComplete)&&l.messageText&&e.jsx("div",{className:"p-4 bg-gradient-to-r from-indigo-50 to-purple-50 dark:from-indigo-950/50 dark:to-purple-950/50 rounded-lg border border-indigo-200 dark:border-indigo-800",children:e.jsxs("p",{className:"text-center font-medium text-indigo-700 dark:text-indigo-300",children:['"',l.messageText,'"']})})]})})]}),e.jsx(xr,{children:r&&e.jsx(Dr,{expression:l,validation:N,onClose:()=>h(!1)})})]}):null}function Dr({expression:t,validation:a,onClose:o}){return p.useEffect(()=>{const c=setTimeout(()=>{o()},1e4);return()=>clearTimeout(c)},[o]),e.jsx(me.div,{initial:{opacity:0}
20,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:o,"data-testid":"expression-celebration-modal",children:e.jsx(me.div,{initial:{scale:.5,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.5,opacity:0},transition:{type:"spring",damping:15},className:"bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 p-1 rounded-2xl shadow-2xl max-w-md mx-4",onClick:c=>c.stopPropagation(),children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-xl p-6 relative overflow-hidden",children:[e.jsx(w,{variant:"ghost",size:"icon",className:"absolute top-2 right-2",onClick:o,children:e.jsx(Pe,{className:"w-4 h-4"})}),e.jsxs("div",{className:"text-center",children:[e.jsx(me.div,{initial:{rotate:-10},animate:{rotate:[0,-5,5,-5,0]},transition:{repeat:1/0,duration:2},className:"inline-block mb-4",children:e.jsx("div",{className:"w-20 h-20 rounded-full bg-gradient-to-br from-yellow-400 to-orange-500 flex items-center justify-center shadow-lg",children:e.jsx(hr,{className:"w-10 h-10 text-white"})})}),e.jsx(me.h2,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.2},className:"text-2xl font-bold bg-gradient-to-r from-indigo-600 to-purple-600 bg-clip-text text-transparent mb-2",children:"Expression Complete!"}),e.jsx(me.p,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3},className:"text-lg text-muted-foreground mb-4",children:t.title}),t.messageText&&e.jsx(me.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.4},className:"p-4 bg-indigo-50 dark:bg-indigo-950/50 rounded-lg mb-4",children:e.jsxs("p",{className:"font-medium text-indigo-700 dark:text-indigo-300 italic",children:['"',t.messageText,'"']})}),e.jsxs(me.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.5},className:"flex items-center justify-center gap-4 mb-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-3xl font-bold text-yellow-500",children:["+",t.pointsReward]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Points Earned"})]}),e.jsx("div",{className:"h-10 w-px bg-border"}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-3xl font-bold text-green-500",children:(a==null?void 0:a.totalPoints)||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Targets Hit"})]})]}),e.jsxs(me.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.6},className:"flex gap-3 justify-center",children:[e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>{var c;(c=navigator.share)==null||c.call(navigator,{title:`I completed ${t.title}!`,text:t.messageText||"Completed a chain expression on Slant!",url:window.location.href})},"data-testid":"share-expression-button",children:[e.jsx(Ve,{className:"w-4 h-4 mr-2"}),"Share"]}),e.jsx(w,{size:"sm",onClick:o,"data-testid":"close-celebration-button",children:"Continue"})]})]}),e.jsx(me.div,{className:"absolute inset-0 pointer-events-none",initial:{opacity:0}
20,animate:{opacity:[0,1,0]},transition:{duration:3,repeat:1/0},children:[...Array(20)].map((c,m)=>e.jsx(me.div,{className:"absolute w-2 h-2 rounded-full",style:{background:["#fbbf24","#8b5cf6","#ec4899","#22c55e"][m%4],left:`${Math.random()*100}%`,top:`${Math.random()*100}%`},initial:{scale:0,opacity:0},animate:{scale:[0,1,0],opacity:[0,1,0],y:[-20,20]},transition:{duration:2,repeat:1/0,delay:m*.1}},m))})]})})})}async function _r(t){if(typeof window>"u")return;const o=(await za(()=>import("./confetti.module-BJU5BvJN.js"),[])).default,m=Date.now()+3e3,i=["#fbbf24","#8b5cf6","#ec4899","#22c55e","#3b82f6"];switch(t){case"fireworks":(function f(){o({particleCount:30,spread:100,origin:{x:Math.random(),y:Math.random()*.6},colors:i,startVelocity:45}),Date.now()<m&&requestAnimationFrame(f)})();break;case"glow":o({particleCount:100,spread:70,origin:{y:.6},colors:i,shapes:["circle"]});break;case"pulse":let r=1;const h=setInterval(()=>{o({particleCount:20*r,spread:50*r,origin:{y:.5,x:.5},colors:i}),r+=.5,r>3&&clearInterval(h)},300);break;case"confetti":default:o({particleCount:150,spread:100,origin:{y:.6},colors:i}),setTimeout(()=>{o({particleCount:75,angle:60,spread:55,origin:{x:0},colors:i}),o({particleCount:75,angle:120,spread:55,origin:{x:1},colors:i})},500);break}}function Vr(t){const{data:a,isLoading:o}=O({queryKey:["/api/chains",t,"expression"],enabled:!!t,retry:!1}),{data:c,isLoading:m}=O({queryKey:["/api/chains",t,"expression","validate"],enabled:!!t&&!!a});return{expression:a,validation:c,isLoading:o||m,hasExpression:!!a,isComplete:(c==null?void 0:c.isComplete)||!1,progress:(c==null?void 0:c.percentComplete)||0}}const _s=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t/100);function zr({chainId:t}){var r,h;const{data:a,isLoading:o}=O({queryKey:["/api/credits/balance"],staleTime:6e4,retry:!1,throwOnError:!1});if(o)return null;const c=((r=a==null?void 0:a.balance)==null?void 0:r.availableCents)??0,m=((h=a==null?void 0:a.balance)==null?void 0:h.pendingCents)??0,i=c>0||m>0;return e.jsxs("div",{className:`rounded-xl border px-4 py-3 flex items-center gap-3 ${i?"bg-amber-50 border-amber-200 dark:bg-amber-950/20 dark:border-amber-800/40":"bg-gray-50 border-gray-200 dark:bg-gray-900/40 dark:border-gray-700/50"}`,"data-testid":"chain-credits-banner",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center shrink-0 ${i?"bg-amber-100 dark:bg-amber-900/40":"bg-gray-100 dark:bg-gray-800"}`,children:i?e.jsx(xt,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"}):e.jsx(Bt,{className:"w-4 h-4 text-gray-500 dark:text-gray-400"})}),e.jsx("div",{className:"flex-1 min-w-0",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-300 leading-tight",children:[_s(c)," in Slant Credits available"]}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-500 mt-0.5",children:["Apply up to 50% off your next booking in this chain",m>0&&` · ${_s(m)} pending`]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200 leading-tight",children:"Earn Slant Credits on every booking"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"You get 50% of Slant's commission back as travel credits — redeemable on future bookings"})]})}),e.jsx(be,{href:"/slant-wallet",children:e.jsxs("a",{className:`flex items-center gap-1 text-xs font-semibold shrink-0 ${i?"text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"}`,"data-testid":"link-chain-credits-wallet",children:[i?"Apply":"Learn more",e.jsx(Gt,{className:"w-3.5 h-3.5"})]})})]})}const Kr={jersey:"bg-blue-500/10 text-blue-600 border-blue-300 dark:border-blue-700 dark:text-blue-400",hoodie:"bg-purple-500/10 text-purple-600 border-purple-300 dark:border-purple-700 dark:text-purple-400",shirt:"bg-green-500/10 text-green-600 border-green-300 dark:border-green-700 dark:text-green-400",sweatshirt:"bg-orange-500/10 text-orange-600 border-orange-300 dark:border-orange-700 dark:text-orange-400",polo:"bg-teal-500/10 text-teal-600 border-teal-300 dark:border-teal-700 dark:text-teal-400"};function Br(t,a,o){return o!=null&&o.length?o.some(c=>c.size===t&&(!a||c.color===a)&&c.available):!0}function Gr(t,a,o){return o!=null&&o.length?o.some(c=>c.color===t&&(!a||c.size===a)&&c.available):!0}function Wr({product:t,chainId:a,activationSlug:o,open:c,onClose:m}){const{toast:i}=we(),{user:r}
20=Qe(),[h,f]=p.useState(""),[d,l]=p.useState(""),[N,g]=p.useState(!1),[n,k]=p.useState(null),b=ae({mutationFn:async()=>{const v=h&&d?`${h} / ${d}`:h||d||"Default Title";return(await Q("POST",`/api/chains/${a}/merch/cart`,{productHandle:t.handle,productTitle:t.title,variantTitle:v,priceCents:Math.round(t.priceUsd*100),activationSlug:o})).json()},onSuccess:v=>{v!=null&&v.checkoutUrl?(window.open(v.checkoutUrl,"_blank","noopener,noreferrer"),k(v.returnUrl??null),g(!0)):(i({title:"Merch checkout coming soon",description:(v==null?void 0:v.message)??"Shopify connection is being configured."}),m())},onError:()=>i({title:"Checkout failed",description:"Please try again.",variant:"destructive"})}),j=(t.sizes.length===0||!!h)&&(t.colors.length===0||!!d);return N?e.jsx(Ne,{open:c,onOpenChange:v=>!v&&m(),children:e.jsx(ye,{className:"max-w-sm mx-auto rounded-2xl",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 py-4 text-center",children:[e.jsx(He,{className:"w-10 h-10 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-base",children:"Complete your purchase"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Shopify checkout opened in a new tab. Finish your order there, then return here to see your credits."})]}),n&&e.jsx(w,{className:"w-full",variant:"outline",onClick:()=>{window.location.href=n},"data-testid":"button-return-to-adventure",children:"Return to Your Adventure"}),e.jsx("button",{onClick:m,className:"text-xs text-muted-foreground underline underline-offset-2","data-testid":"button-close-merch-sheet",children:"Close"})]})})}):e.jsx(Ne,{open:c,onOpenChange:v=>!v&&m(),children:e.jsxs(ye,{className:"max-w-sm mx-auto rounded-2xl",children:[e.jsx($e,{children:e.jsx(Ae,{className:"text-base font-bold",children:t.title})}),e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"aspect-[4/3] rounded-xl overflow-hidden bg-muted",children:e.jsx("img",{src:t.imageUrl,alt:t.title,className:"w-full h-full object-cover",loading:"lazy"})}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:t.description}),t.sizes.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:["Size ",h&&e.jsxs("span",{className:"text-foreground",children:["· ",h]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sizes.map(v=>{const S=Br(v,d,t.availableVariants);return e.jsx("button",{onClick:()=>S&&f(v),disabled:!S,"data-testid":`size-btn-${v}`,"aria-disabled":!S,className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors
21                        ${S?h===v?"border-primary bg-primary text-primary-foreground":"border-border bg-background hover:border-primary/50":"border-border bg-muted text-muted-foreground opacity-40 cursor-not-allowed line-through"}`,children:v},v)})})]}),t.colors.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:["Color ",d&&e.jsxs("span",{className:"text-foreground",children:["· ",d]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.colors.map(v=>{const S=Gr(v,h,t.availableVariants);return e.jsx("button",{onClick:()=>S&&l(v),disabled:!S,"data-testid":`color-btn-${v.replace(/\s+/g,"-").toLowerCase()}`,"aria-disabled":!S,className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors
22                        ${S?d===v?"border-primary bg-primary text-primary-foreground":"border-border bg-background hover:border-primary/50":"border-border bg-muted text-muted-foreground opacity-40 cursor-not-allowed line-through"}`,children:v},v)})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Bt,{className:"w-3 h-3 text-amber-500"}),"Earn 5% back in Slant Credits on every merch order"]}),r?e.jsxs(w,{className:"w-full",disabled:!j||b.isPending,onClick:()=>b.mutate(),"data-testid":"button-order-merch",children:[b.isPending?e.jsx(Y,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(Js,{className:"w-4 h-4 mr-2"}),"Order · $",t.priceUsd.toFixed(0)]}):e.jsx(w,{className:"w-full",variant:"outline",onClick:()=>{m(),window.location.href="/api/auth/login"},"data-testid":"button-merch-signin",children:"Sign in to order"}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center",children:"Fulfilled by ArringtonRose · Ships directly to you · No returns on custom items"})]})]})})}function Qr({orderId:t}){return e.jsx(z,{className:"border-green-300 dark:border-green-700 bg-green-50 dark:bg-green-950/30 mb-4","data-testid":"merch-order-confirmation",children:e.jsxs(K,{className:"p-4 flex items-center gap-3",children:[e.jsx(na,{className:"w-8 h-8 text-green-600 dark:text-green-400 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm text-green-800 dark:text-green-300",children:"Your gear is on the way!"}),e.jsxs("p",{className:"text-xs text-green-700 dark:text-green-400 mt-0.5",children:["Order #",t," · Fulfilled by ArringtonRose · Slant Credits earned"]})]})]})})}function Hr(){return e.jsx(z,{className:"border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-950/30 mb-4","data-testid":"merch-pending-banner",children:e.jsxs(K,{className:"p-4 flex items-center gap-3",children:[e.jsx(He,{className:"w-8 h-8 text-amber-600 dar
22k:text-amber-400 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-sm text-amber-800 dark:text-amber-300",children:"Order submitted!"}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400 mt-0.5",children:"ArringtonRose will confirm by email when your order is in production. Slant Credits will appear in your wallet once payment clears."})]})]})})}function Yr({chainId:t}){const[a,o]=p.useState(null),{data:c,isLoading:m}=O({queryKey:["/api/chains",t,"merch"],queryFn:()=>fetch(`/api/chains/${t}/merch`,{credentials:"include"}).then(d=>d.json()),enabled:!!t,staleTime:5*6e4}),i=new URLSearchParams(window.location.search),r=i.get("order_id")??i.get("orderId"),h=i.get("merch_pending")==="1",f=(c==null?void 0:c.products)??[];return m?e.jsx("div",{className:"flex items-center justify-center py-10","data-testid":"merch-loading",children:e.jsx(Y,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):f.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground","data-testid":"merch-empty",children:[e.jsx(ia,{className:"w-10 h-10 mb-3 opacity-30"}),e.jsx("p",{className:"text-sm font-medium",children:"No merch for this chain yet"}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Check back soon — ArringtonRose drop-ship coming."})]}):e.jsxs("div",{"data-testid":"chain-merch-tab",children:[r&&e.jsx(Qr,{orderId:r}),!r&&h&&e.jsx(Hr,{}),!(c!=null&&c.shopifyConfigured)&&e.jsx("div",{className:"mb-4 px-3 py-2 rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 text-xs text-amber-700 dark:text-amber-400",children:"Merch preview — checkout will be available once the ArringtonRose Shopify store is connected."}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:f.map(d=>{const l=Kr[d.productType]??"bg-slate-100 text-slate-600 border-slate-200 dark:bg-slate-800 dark:text-slate-400 dark:border-slate-700";return e.jsxs(z,{className:"overflow-hidden cursor-pointer hover:shadow-md transition-shadow active:scale-[0.98]",onClick:()=>o(d),"data-testid":`merch-card-${d.handle}`,children:[e.jsx("div",{className:"aspect-square bg-muted overflow-hidden",children:e.jsx("img",{src:d.imageUrl,alt:d.title,className:"w-full h-full object-cover",loading:"lazy"})}),e.jsxs(K,{className:"p-3 pt-2.5",children:[e.jsx(T,{variant:"outline",className:`text-[10px] px-1.5 py-0 mb-1.5 capitalize font-medium ${l}`,children:d.productType}),e.jsx("p",{className:"text-xs font-bold leading-snug line-clamp-2",children:d.title}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsxs("span",{className:"text-sm font-black",children:["$",d.priceUsd.toFixed(0)]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:N=>{N.stopPropagation(),o(d)},"data-testid":`button-get-${d.handle}`,children:"Get It"})]})]})]},d.handle)})}),e.jsxs("p",{className:"text-center text-[10px] text-muted-foreground mt-4 flex items-center justify-center gap-1",children:[e.jsx(gr,{className:"w-3 h-3"}),"Made to order · Drop-shipped by ArringtonRose"]}),a&&e.jsx(Wr,{product:a,chainId:t,activationSlug:(c==null?void 0:c.activationSlug)??"",open:!!a,onClose:()=>o(null)})]})}const Jr={discover:Ba,plan:Ka,book:Js,chat:ot,wallet:xt},Vs={discover:{bg:"bg-emerald-50 dark:bg-emerald-950/20",border:"border-emerald-200 dark:border-emerald-800/40",badge:"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-400",icon:"text-emerald-600 dark:text-emerald-400"},plan:{bg:"bg-blue-50 dark:bg-blue-950/20",border:"border-blue-200 dark:border-blue-800/40",badge:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-400",icon:"text-blue-600 dark:text-blue-400"},book:{bg:"bg-violet-50 dark:bg-violet-950/20",border:"border-violet-200 dark:border-violet-800/40",badge:"bg-violet-100 text-violet-700 dark:bg-violet-900/40 dark:text-violet-400",icon:"text-violet-600 dark:text-violet-400"},chat:{bg:"bg-sky-50 dark:bg-sky-950/20",border:"border-sky-200 dark:border-sky-800/40",badge:"bg-sky-100 text-sky-700 dark:bg-sky-900/40 dark:text-sky-400",icon:"text-sky-600 dark:text-sky-400"},wallet:{bg:"bg-amber-50 dark:bg-amber-950/20",border:"border-amber-200 dark:border-amber-800/40",badge:"bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400",icon:"text-amber-600 dar
22k:text-amber-400"}},Lt="slant_capabilities_panel_dismissed";function Zr({group:t,defaultOpen:a=!1}){const[o,c]=p.useState(a),m=Jr[t.id]??Et,i=Vs[t.id]??Vs.discover;return e.jsxs("div",{className:`rounded-xl border ${i.border} overflow-hidden`,children:[e.jsxs("button",{type:"button",onClick:()=>c(r=>!r),className:`w-full flex items-center gap-3 px-4 py-3 text-left transition-colors hover:opacity-90 ${i.bg}`,"aria-expanded":o,"data-testid":`capabilities-group-${t.id}`,children:[e.jsx("span",{className:"text-xl leading-none",children:t.emoji}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-semibold text-sm leading-tight",children:t.title}),e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:t.subtitle})]}),o?e.jsx(Qt,{className:"w-4 h-4 text-muted-foreground shrink-0"}):e.jsx(Ht,{className:"w-4 h-4 text-muted-foreground shrink-0"})]}),o&&e.jsx("ul",{className:"divide-y divide-border",children:t.items.map(r=>e.jsxs("li",{className:"px-4 py-3 flex items-start gap-3",children:[e.jsx(m,{className:`w-4 h-4 mt-0.5 shrink-0 ${i.icon}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center flex-wrap gap-2 mb-0.5",children:[e.jsx("span",{className:"text-sm font-medium leading-snug",children:r.title}),r.externalProvider&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] font-semibold px-1.5 py-0.5 rounded border border-muted-foreground/30 text-muted-foreground leading-none",children:[e.jsx(ie,{className:"w-2.5 h-2.5"}),r.externalProvider]})]}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r.description})]})]},r.id))})]})}function Xr({groups:t}){const[a,o]=p.useState(()=>{try{return sessionStorage.getItem(Lt)!=="1"}catch{return!0}}),c=()=>{try{sessionStorage.setItem(Lt,"1")}catch{}o(!1)},m=()=>{try{sessionStorage.removeItem(Lt)}catch{}o(!0)},i=t?Os.filter(r=>t.includes(r.id)):Os;return a?e.jsxs("div",{className:"mb-6 rounded-2xl border border-border bg-muted/20 overflow-hidden","data-testid":"chain-capabilities-panel",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-background/60",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Et,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold",children:"Everything you can do on this chain"})]}),e.jsx("button",{type:"button",onClick:c,className:"text-xs text-muted-foreground hover:text-foreground transition-colors","data-testid":"capabilities-dismiss","aria-label":"Dismiss capabilities panel",children:"Got it"})]}),e.jsx("div",{className:"p-3 space-y-2",children:i.map((r,h)=>e.jsx(Zr,{group:r,defaultOpen:h===0},r.id))}),e.jsxs("div",{className:"px-4 py-2.5 border-t border-border bg-background/40 text-[10px] text-muted-foreground leading-relaxed",children:["Items marked ",e.jsx(ie,{className:"inline w-2.5 h-2.5 mx-0.5"})," open an external provider for payment or fulfilment — you stay signed in to Slant throughout."]})]}):e.jsx("div",{className:"mb-4 flex justify-start","data-testid":"capabilities-reopen-button",children:e.jsxs(w,{variant:"ghost",size:"sm",onClick:m,className:"gap-1.5 text-muted-foreground hover:text-foreground h-7 px-2 text-xs",children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),"What can I do here?"]})})}const zs=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(t/100);function ei(t){const a=new Date(t).getTime()-Date.now();if(a<=0)return"revealed";const o=Math.floor(a/864e5),c=Math.floor(a%864e5/36e5);if(o>60)return`${Math.ceil(o/30)}mo`;if(o>0)return`${o}d ${c}h`;const m=Math.floor(a%36e5/6e4);return`${c}h ${m}m`}const ti=[{initials:"JD",color:"bg-amber-500"},{initials:"MK",color:"bg-blue-500"},{initials:"SR",color:"bg-emerald-500"},{initials:"TL",color:"bg-purple-500"},{initials:"RV",color:"bg-rose-500"}];function si({campaignId:t,stopsHit:a=0,totalStops:o=5,crewSize:c=5,userCutPercent:m=15,crewAvatars:i=ti}){Qe();const{data:r}=O({queryKey:["/api/cash-drops/campaign",t],queryFn:()=>fetch(`/api/cash-drops/campaign/${t}`,{credentials:"include"}).then(n=>n.ok?n.json():[]),staleTime:6e4,retry:!1,throwOnError:!1}),h=r==null?void 0:r[0];if(!h||(h.currentPoolCents??0)===0)return null;const f=h.currentPoolCents??0,d=f-f*(a/o),l=h.status==="claimed",N=h.status==="revealed"||l,g=Math.round(a/o*100);return e.jsxs("div",{className:"rounded-2xl overflow-hidden border border-amber-400/30 bg-gradient-to-br from-slate-900 via-slate-800 to-amber-950/40","data-testid":"crew-jackpot-banner",children:[e.jsxs("div",{className:"px-4 pt-4 pb-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-500/20 border border-amber-400/30 flex items-center justify-center",children:e.jsx(mt,{className:"w-4 h-4 text-amber-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-amber-400 uppercase tracking-wider",children:"Crew Jackpot"}),e.jsx("p",{className:"text-xs text-slate-400",children:h.pinLabel})]})]}),!N&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-slate-400",title:`Drops at ${Ga(h.pinDropsAt)}`,"data-testid":"text-crew-jackpot-countdown",children:[e.jsx(ra,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:ei(h.pinDropsAt)})]}),l&&e.jsx("span",{className:"text-xs font-semibold text-emerald-400",children:"Claimed ✓"})]}),e.jsxs("div",{className:"px-4 pb-3 flex items-baseline gap-2",children:[e.jsx("span",{className:"text-3xl font-black text-white tabular-nums",children:zs(f)}),e.jsx("span",{className:"text-sm text-amber-400 font-medium",children:N?"revealed":"and growing"})]}),e.jsxs("div",{className:"px-4 pb-3",children:[e.jsxs("div",{className:"flex justify-between text-xs text-slate-400 mb-1",children:[e.jsxs("span",{children:[a," of ",o," stops hit"]}),e.jsxs("span",{children:[zs(d)," still on the table"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-slate-700 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-amber-500 to-orange-400 transition-all duration-700",style:{width:`${g}%`}})})]}),e.jsxs("div",{className:"px-4 pb-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex -sp
22ace-x-2",children:i.slice(0,5).map((n,k)=>e.jsx("div",{className:`w-7 h-7 rounded-full border-2 border-slate-800 flex items-center justify-center text-[10px] font-bold text-white ${n.color}`,title:n.initials,children:n.initials},k))}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-slate-300",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-slate-400"}),e.jsxs("span",{children:[c," in crew"]}),e.jsx("span",{className:"text-slate-600",children:"·"}),e.jsx("span",{className:"text-slate-500",children:"invite more"})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-slate-400",children:"Your cut"}),e.jsxs("p",{className:"text-lg font-black text-amber-400",children:[m,"%"]})]})]}),N&&h.smsKeyword&&e.jsxs("div",{className:"mx-4 mb-4 rounded-xl bg-amber-500/10 border border-amber-500/20 px-3 py-2.5 flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4 text-amber-400 shrink-0"}),e.jsxs("p",{className:"text-xs text-amber-300",children:["Text ",e.jsx("strong",{className:"text-amber-200",children:h.smsKeyword})," to claim your share of the pot."]})]}),e.jsxs("div",{className:"border-t border-slate-700/60 px-4 py-2.5 flex items-center gap-1.5",children:[e.jsx(se,{className:"w-3.5 h-3.5 text-slate-500"}),e.jsx("p",{className:"text-xs text-slate-400",children:"YOUR CHAIN — TAP A STOP TO CHECK IN"})]})]})}const ai=.15;function ri({chainId:t,bookingId:a,bookingValueCents:o,onAdopted:c,onSkipped:m,affiliateClickId:i,isGuestMode:r=!1,isWaitingForReturn:h=!1,autoAdopt:f=!1,onFunnelEvent:d}){var P,$;const[l,N]=p.useState(!1),g=p.useRef(!1),{data:n,isLoading:k}=O({queryKey:["/api/chains",t],enabled:!!t}),j=(Math.floor(o*ai)/100).toFixed(2);(o/100).toFixed(2);const v=ae({mutationFn:async M=>(await Q("POST",`/api/chains/${t}/orbit-booking-type`,{bookingId:a,orbitBookingType:M,...i?{affiliateClickId:i}:{}})).json()}),S=async()=>{if(d==null||d("cta_tap"),r){c();return}await v.mutateAsync("chain_attributed"),d==null||d("adoption_complete"),c()},A=async()=>{if(d==null||d("offer_skipped"),r){N(!0),m();return}await v.mutateAsync("affiliate_only"),N(!0),m()};if(p.useEffect(()=>{!f||r||g.current||(g.current=!0,S())},[f,r]),p.useEffect(()=>{l||d==null||d("card_view")},[]),l||!t)return null;const I=n==null?void 0:n.thread,L=((n==null?void 0:n.nodes)??[]).slice(0,4).map(M=>M.node??M);return e.jsxs("div",{className:"rounded-2xl border border-amber-400/30 overflow-hidden",style:{background:"linear-gradient(135deg, rgba(217,119,6,0.12) 0%, rgba(146,64,14,0.12) 100%)"},"data-testid":"post-booking-chain-offer",children:[e.jsxs("div",{className:"flex items-start justify-between px-4 pt-4 pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-amber-500/20 flex items-center justify-center",children:e.jsx(la,{className:"w-4 h-4 text-amber-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-white font-bold text-sm leading-tight",children:h?"Did you book?":"Add the Going"}),e.jsx("p",{className:"text-amber-300/80 text-xs",children:h?"If your booking is confirmed, tap below to add the Going":"Unlock your adventure"})]})]}),e.jsx("button",{onClick:A,className:"text-white/30 hover:text-white/60 transition-colors p-1","aria-label":"Dismiss","data-testid":"button-skip-chain-offer",children:e.jsx(Pe,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"mx-4 mb-3 rounded-xl px-3 py-2.5 flex items-center gap-3",style:{background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.25)"},children:[e.jsx(he,{className:"w-4 h-4 text-amber-400 shrink-0"}),e.jsx("div",{className:"flex-1",children:o>0?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-amber-200 text-sm font-bold leading-tight",children:["Earn $",j," in Slant Credits"]}),e.jsx("p",{className:"text-amber-300/60 text-xs",children:i?"Your joining reward — issued once your Going is confirmed":"Your reward for joining this Going — redeemable on any future stop"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-amber-200 text-sm font-bold leading-tight",children:"Earn 15% in Slant Credits when you Add the Going"}),e.jsx("p",{className:"text-amber-300/60 text-xs",children:i?"Your joining reward — issued once your Going is confirmed":"Your reward for joining — redeemable on any future stop"})]})})]}),k?e.jsx("div",{className:"px-4 pb-3 space-y-1.5",children:[...Array(3)].map((M,U)=>e.jsx("div",{className:"h-6 rounded bg-white/5 animate-pulse"},U))}):e.jsxs("div",{className:"px-4 pb-3",children:[(I==null?void 0:I.title)&&e.jsx("p",{className:"text-white/80 text-xs font-semibold mb-2 uppercase tracking-wider",children:I.title}),e.jsxs("div",{className:"space-y-1",children:[L.map((M,U)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"w-3 h-3 text-amber-400/60 shrink-0"}),e.jsx("span",{className:"text-white/70 text-xs truncate",children:M.locationName})]},M.id??U)),(((P=n==null?void 0:n.nodes)==null?void 0:P.length)??0)>4&&e.jsxs("p",{className:"text-white/40 text-xs ml-5",children:["+",((($=n==null?void 0:n.nodes)==null?void 0:$.length)??0)-4," more stops"]})]})]}),e.jsxs("div",{className:"px-4 pb-4 flex gap-2",children:[e.jsx(w,{className:"flex-1 bg-amber-500 hover:bg-amber-400 text-black font-bold h-10",onClick:S,disabled:v.isPending,"data-testid":"button-add-the-going",children:v.isPending?e.jsx(Y,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:["Add the Going ",e.jsx(Gt,{className:"w-4 h-4 ml-1"})]})}),e.jsx(w,{variant:"ghost",className:"text-white/40 hover:text-white/60 text-xs h-10 px-3",onClick:A,disabled:v.isPending,"data-testid":"button-skip-going",children:"Skip"})]})]})}function ii(){const t=p.useRef(null);return p.useEffect(()=>{const a=t.current;if(!a)return;const o=a.getContext("2d");if(!o)return;a.width=window.innerWidth,a.height=window.innerHeight;const c=["#f59e0b","#fbbf24","#ffffff","#fde68a","#d97706"],m=Array.from({length:120},()=>({x:Math.random()*a.width,y:-10-Math.random()*60,r:4+Math.random()*6,color:c[Math.floor(Math.random()*c.length)],vy:1.5+Math.random()*3,vx:(Math.random()-.5)*2,alpha:1,decay:.005+Math.random()*.005,angle:Math.random()*Math.PI*2,av:(Math.random()-.5)*.1}));let i;function r(){if(!o||!a)return;o.clearRect(0,0,a.width,a.height);let f=!1;for(const d of m)d.y+=d.vy,d.x+=d.vx,d.angle+=d.av,d.y<a.height&&(d.alpha-=d.decay,f=!0),!(d.alpha<=0)&&(o.save(),o.globalAlpha=Math.max(0,d.alpha),o.fillStyle=d.color,o.translate(d.x,d.y),o.rotate(d.angle),o.fillRect(-d.r/2,-d.r/2,d.r,d.r*.5),o.restore(
22));f&&(i=requestAnimationFrame(r))}i=requestAnimationFrame(r);const h=()=>{a&&(a.width=window.innerWidth,a.height=window.innerHeight)};return window.addEventListener("resize",h),()=>{cancelAnimationFrame(i),window.removeEventListener("resize",h)}},[]),e.jsx("canvas",{ref:t,className:"pointer-events-none absolute inset-0 w-full h-full","aria-hidden":!0})}function ni({certificate:t,rewardCredits:a=0,gifted:o=!1,onGift:c,onDismiss:m}){var g;const[i,r]=p.useState(!1),[h,f]=p.useState(""),d=`/certificate/${t.certificateId}`,l=((g=t.stopsJson)==null?void 0:g.length)??0;function N(){var b;const n=`${window.location.origin}${d}`,k=`I just completed the ${t.chainTitle} Going on Slant — all ${l} stops verified!`;navigator.share?navigator.share({title:k,url:n}):((b=navigator.clipboard)==null||b.writeText(n),alert("Certificate link copied to clipboard!"))}return p.useEffect(()=>{const n=k=>{k.key==="Escape"&&m()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[m]),e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden",style:{background:"rgba(0,0,0,0.88)"},onClick:n=>{n.target===n.currentTarget&&m()},children:[e.jsx(ii,{}),e.jsxs("div",{className:"relative z-10 max-w-sm w-full mx-4 rounded-2xl overflow-hidden",style:{background:"#0d1117",border:"1px solid #f59e0b55"},children:[e.jsx("div",{className:"h-1 bg-amber-400 w-full"}),e.jsx("button",{onClick:m,className:"absolute top-3 right-3 text-slate-500 hover:text-white transition-colors","aria-label":"Close",children:e.jsx(Pe,{className:"w-5 h-5"})}),e.jsxs("div",{className:"px-6 pt-8 pb-6 text-center",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-20 h-20 rounded-full bg-amber-400/10 border-2 border-amber-400/40 mb-5 animate-bounce",children:e.jsx(De,{className:"w-10 h-10 text-amber-400"})}),e.jsx("p",{className:"text-amber-400 text-xs tracking-[0.25em] uppercase font-semibold mb-2",children:"Journey Complete"}),e.jsx("h2",{className:"text-white text-2xl font-bold mb-1",children:t.chainTitle}),e.jsxs("p",{className:"text-slate-400 text-sm mb-4",children:["You did it, ",t.fanDisplayName,"! All ",l," stop",l!==1?"s":""," verified."]}),l>0&&l<=8&&e.jsx("div",{className:"flex items-center justify-center gap-1 mb-5",children:Array.from({length:l}).map((n,k)=>e.jsx(na,{className:"w-5 h-5 text-amber-400"},k))}),e.jsx("p",{className:"text-slate-500 text-xs mb-6",children:"Your certificate has been issued and is ready to share."}),a>0&&e.jsxs("div",{className:"rounded-xl border border-emerald-400/30 bg-emerald-400/10 p-4 mb-5 text-left",children:[e.jsxs("p",{className:"text-emerald-300 font-semibold text-base","data-testid":"completion-reward-message",children:["You earned ",a.toLocaleString()," Slant credits"]}),e.jsx("p",{className:"text-emerald-200/70 text-xs mt-1",children:"They are in your Slant wallet and ready for bookings, experiences, or transfers."}),e.jsxs("div",{className:"flex flex-col gap-2 mt-3",children:[e.jsx(be,{href:"/slant-wallet",children:e.jsxs(w,{variant:"outline",className:"w-full border-emerald-400/40 text-emerald-200 hover:bg-emerald-400/10",children:[e.jsx(xt,{className:"w-4 h-4 mr-2"})," Open Slant wallet"]})}),c&&!o&&e.jsxs(w,{variant:"ghost",className:"w-full text-emerald-200 hover:text-white hover:bg-emerald-400/10",disabled:i,"data-testid":"button-gift-completion-reward",onClick:async()=>{r(!0),f("");try{await c()}catch(n){f((n==null?void 0:n.message)||"Unable to gift credits.")}finally{r(!1)}},children:[i?e.jsx(Y,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(la,{className:"w-4 h-4 mr-2"}),"Gift reward to organizer"]}),o&&e.jsx("p",{className:"text-center text-emerald-300 text-xs",children:"Reward gifted to the organizer."}),h&&e.jsx("p",{className:"text-center text-red-300 text-xs",children:h})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsxs(w,{className:"w-full bg-amber-500 hover:bg-amber-400 text-black font-semibold",children:[e.jsx(ie,{className:"w-4 h-4 mr-2"}),"View Certificate"]})}),e.jsxs(w,{variant:"outline",className:"w-full border-slate-700 text-slate-300 hover:text-white",onClick:N,children:[e.jsx(Ve,{className:"w-4 h-4 mr-2"}),"Share Achievement"]}),e.jsx("button",{onClick:m,className:"text-slate-600 text-sm hover:text-slate-400 mt-1 transition-colors",children:"Maybe later"})]})]}),e.jsx("div",{className:"h-1 bg-amber-400 w-full"})]})]})}const li={flight:Ye,train:Cr,car:kr,boat:wr,walking:Tr,bus:yr},oi={open:"bg-green-100 text-green-700 border-green-300 dark:bg-green-900/30 dark:text-green-400",accepted:"bg-blue-100 text-blue-700 border-blue-300 dark:bg-blue-900/30 dark:text-blue-400",completed:"bg-gray-100 text-gray-700 border-gray-300 dark:bg-gray-800 dark:text-gray-400",expired:"bg-red-100 text-red-700 border-red-300 dark:bg-red-900/30 dark:text-red-400"},Ks=new Map;function ci(t){return new Promise((a,o)=>{const c=new oa;c.crossOrigin="anonymous",c.onload=()=>a(c),c.onerror=()=>o(new Error("image load failed")),c.src=t})}function di(t,a,o=64,c){const m=`${t}|${a}|${o}|${c||""}`;let i=Ks.get(m);
22return i||(i=(async()=>{const r=await ci(t),h=document.createElement("canvas");h.width=o,h.height=o;const f=h.getContext("2d");if(!f)throw new Error("no canvas context");const d=o/2,l=Math.max(3,Math.round(o/16));f.save(),f.beginPath(),f.arc(d,d,d-l/2,0,Math.PI*2),f.closePath(),f.clip();const N=r.width/r.height;let g=0,n=0,k=r.width,b=r.height;if(N>1?(k=r.height,g=(r.width-k)/2):N<1&&(b=r.width,n=(r.height-b)/2),f.drawImage(r,g,n,k,b,0,0,o,o),f.restore(),f.beginPath(),f.arc(d,d,d-l/2,0,Math.PI*2),f.lineWidth=l,f.strokeStyle=a,f.stroke(),c){const j=Math.max(7,Math.round(o/4.2)),v=o-j*.75,S=o-j*.75;f.beginPath(),f.arc(v,S,j,0,Math.PI*2),f.fillStyle=a,f.fill(),f.lineWidth=Math.max(1.5,j/6),f.strokeStyle="white",f.stroke(),f.fillStyle="white",f.font=`bold ${Math.round(j*1.15)}px sans-serif`,f.textAlign="center",f.textBaseline="middle",f.fillText(c,v,S+1)}return h.toDataURL("image/png")})(),Ks.set(m,i),i)}function qt(t,a,o,c,m=64,i){o&&di(o,c,m,i).then(r=>{t.setIcon({url:r,scaledSize:new a.maps.Size(m*.8,m*.8),anchor:new a.maps.Point(m*.8/2,m*.8/2)}),t.setLabel(null)}).catch(()=>{})}function mi({chainPath:t,onNodeClick:a,selectedNodeId:o,onMapReady:c}){const m=p.useRef(null),[i,r]=p.useState(!1),h=p.useRef(null),f=p.useRef([]),d=p.useRef([]),l=p.useCallback(()=>{const g=window.google;if(!m.current||!g||h.current)return;const n=t.nodes.filter(j=>j.latitude&&j.longitude);if(n.length===0)return;const k=new g.maps.LatLngBounds;n.forEach(j=>{k.extend({lat:parseFloat(j.latitude),lng:parseFloat(j.longitude)})});const b=new g.maps.Map(m.current,{center:k.getCenter(),zoom:4,styles:[{featureType:"poi",stylers:[{visibility:"off"}]},{featureType:"transit",stylers:[{visibility:"off"}]}],mapTypeControl:!1,streetViewControl:!1,fullscreenControl:!0});b.fitBounds(k,{padding:50}),h.current=b,r(!0),c==null||c(b),n.forEach((j,v)=>{const S=j.status==="open"?"#22c55e":j.status==="accepted"?"#3b82f6":"#6b7280",A=new g.maps.Marker({position:{lat:parseFloat(j.latitude),lng:parseFloat(j.longitude)},map:b,title:j.locationName,label:{text:String(j.nodeOrder),color:"white",fontWeight:"bold"},icon:{path:g.maps.SymbolPath.CIRCLE,scale:20,fillColor:S,fillOpacity:1,strokeColor:"white",strokeWeight:3}});A.addListener("click",()=>{a==null||a(j)}),f.current.push(A),qt(A,g,j.coverImageUrl,S,64,String(j.nodeOrder))});for(let j=0;j<n.length-1;j++){const v=n[j],S=n[j+1];if(!v.latitude||!v.longitude||!S.latitude||!S.longitude)continue;const A=t.links.find(L=>L.fromNodeId===v.id&&L.toNodeId===S.id),I=new g.maps.Polyline({path:[{lat:parseFloat(v.latitude),lng:parseFloat(v.longitude)},{lat:parseFloat(S.latitude),lng:parseFloat(S.longitude)}],geodesic:!0,strokeColor:(A==null?void 0:A.status)==="completed"?"#6b7280":"#3b82f6",strokeOpacity:.8,strokeWeight:3,icons:[{icon:{path:g.maps.SymbolPath.FORWARD_CLOSED_ARROW,scale:3,strokeColor:(A==null?void 0:A.status)==="completed"?"#6b7280":"#3b82f6"},offset:"50%"}]});I.setMap(b),d.current.push(I)}},[t,a,c]);return p.useEffect(()=>{if(window.googleMapsLoaded)l();else{const g=()=>l();return window.addEventListener("googleMapsReady",g),()=>window.removeEventListener("googleMapsReady",g)}return()=>{f.current.forEach(g=>g.setMap(null)),d.current.forEach(g=>g.setMap(null)),f.current=[],d.current=[]}},[l]),p.useEffect(()=>{if(o&&h.current){const g=t.nodes.find(n=>n.id===o);g!=null&&g.latitude&&(g!=null&&g.longitude)&&h.current.panTo({lat:parseFloat(g.latitude),lng:parseFloat(g.longitude)})}},[o,t.nodes]),t.nodes.some(g=>g.latitude&&g.longitude)?e.jsx("div",{ref:m,className:"h-[400px] rounded-lg overflow-hidden border","data-testid":"chain-path-map"}):e.jsx("div",{className:"h-[400px] bg-muted rounded-lg flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(se,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No location data available for map visualization"})]})})}function xi({spiderPath:t,onBranchClick:a,selectedBranchId:o,onMapReady:c}){var l,N;const m=p.useRef(null),i=p.useRef(null),r=p.useRef([]),h=p.useRef([]),f=p.useCallback(()=>{var j,v,S,A;const g=window.google;if(!m.current||!g||i.current)return;const n=[];if((j=t.hub)!=null&&j.latitude&&((v=t.hub)!=null&&v.longitude)&&n.push({lat:parseFloat(t.hub.latitude),lng:parseFloat(t.hub.longitude)}
22),t.branches.forEach(({nodes:I})=>{I.forEach(L=>{L.latitude&&L.longitude&&n.push({lat:parseFloat(L.latitude),lng:parseFloat(L.longitude)})})}),n.length===0)return;const k=new g.maps.LatLngBounds;n.forEach(I=>k.extend(I));const b=new g.maps.Map(m.current,{center:k.getCenter(),zoom:4,styles:[{featureType:"poi",stylers:[{visibility:"off"}]},{featureType:"transit",stylers:[{visibility:"off"}]}],mapTypeControl:!1,streetViewControl:!1,fullscreenControl:!0});if(b.fitBounds(k,{padding:50}),i.current=b,c==null||c(b),(S=t.hub)!=null&&S.latitude&&((A=t.hub)!=null&&A.longitude)){const I=new g.maps.Marker({position:{lat:parseFloat(t.hub.latitude),lng:parseFloat(t.hub.longitude)},map:b,title:t.hub.locationName+" (Hub)",icon:{path:g.maps.SymbolPath.CIRCLE,scale:30,fillColor:"#8b5cf6",fillOpacity:1,strokeColor:"white",strokeWeight:4},zIndex:1e3});qt(I,g,t.hub.coverImageUrl,"#8b5cf6",80,"H");const L=new g.maps.Marker({position:{lat:parseFloat(t.hub.latitude),lng:parseFloat(t.hub.longitude)},map:b,icon:{url:"data:image/svg+xml;charset=UTF-8,"+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="2"/><path d="m12 2 0 4"/><path d="m12 18 0 4"/><path d="m2 12 4 0"/><path d="m18 12 4 0"/></svg>'),scaledSize:new g.maps.Size(24,24),anchor:new g.maps.Point(12,12)},zIndex:1001});r.current.push(I,L)}t.branches.forEach(({branch:I,nodes:L})=>{var y,B;const P=I.color||"#3b82f6",$=o===I.id;let U=(y=t.hub)!=null&&y.latitude&&((B=t.hub)!=null&&B.longitude)?{lat:parseFloat(t.hub.latitude),lng:parseFloat(t.hub.longitude)}:null;
22L.forEach((D,ue)=>{if(!D.latitude||!D.longitude)return;const de={lat:parseFloat(D.latitude),lng:parseFloat(D.longitude)},ke=new g.maps.Marker({position:de,map:b,title:`${D.locationName} (${I.label})`,label:{text:String(ue+1),color:"white",fontWeight:"bold",fontSize:"11px"},icon:{path:g.maps.SymbolPath.CIRCLE,scale:$?16:14,fillColor:P,fillOpacity:$?1:.8,strokeColor:"white",strokeWeight:2}});if(ke.addListener("click",()=>a==null?void 0:a(I.id)),r.current.push(ke),qt(ke,g,D.coverImageUrl,P,$?56:48,String(ue+1)),U){const Je=new g.maps.Polyline({path:[U,de],geodesic:!0,strokeColor:P,strokeOpacity:$?1:.6,strokeWeight:$?4:3,icons:[{icon:{path:g.maps.SymbolPath.FORWARD_CLOSED_ARROW,scale:2,strokeColor:P},offset:"50%"}]});Je.setMap(b),h.current.push(Je)}U=de})})},[t,a,o,c]);return p.useEffect(()=>{if(window.googleMapsLoaded)f();else{const g=()=>f();return window.addEventListener("googleMapsReady",g),()=>window.removeEventListener("googleMapsReady",g)}return()=>{r.current.forEach(g=>g.setMap(null)),h.current.forEach(g=>g.setMap(null)),r.current=[],h.current=[]}},[f]),((l=t.hub)==null?void 0:l.latitude)&&((N=t.hub)==null?void 0:N.longitude)?e.jsx("div",{ref:m,className:"h-[400px] rounded-lg overflow-hidden border","data-testid":"spider-chain-path-map"}):e.jsx("div",{className:"h-[400px] bg-muted rounded-lg flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(dt,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No location data available for spider chain visualization"})]})})}function hi({branch:t,nodeCount:a,isSelected:o,onClick:c}){var i,r,h,f,d;const m=(l,N)=>`${(l==null?void 0:l[0])||""}${(N==null?void 0:N[0])||""}`.toUpperCase()||"?";return e.jsxs(z,{className:`min-w-[240px] cursor-pointer transition-all ${o?"ring-2 ring-primary shadow-lg":"hover:shadow-md"}`,onClick:c,"data-testid":`branch-card-${t.id}`,style:{borderLeftColor:t.color||"#3b82f6",borderLeftWidth:"4px"},children:[e.jsx(Z,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(it,{className:"w-8 h-8",children:[e.jsx(nt,{src:((i=t.participant)==null?void 0:i.profileImageUrl)||void 0}),e.jsx(lt,{className:"text-xs",children:m((r=t.participant)==null?void 0:r.firstName,(h=t.participant)==null?void 0:h.lastName)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(X,{className:"text-sm truncate",children:t.label}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(f=t.participant)==null?void 0:f.firstName," ",(d=t.participant)==null?void 0:d.lastName]})]})]})}),e.jsx(K,{className:"pt-0",children:e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(se,{className:"w-3 h-3"}),e.jsxs("span",{children:[a," locations"]})]}),e.jsx(T,{variant:t.status==="active"?"default":"secondary",className:"text-[10px] px-1.5",children:t.status})]})})]})}function ui({spiderPath:t,selectedBranchId:a,onBranchSelect:o}){var c,m,i;return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 rounded-lg border-2 border-purple-400 bg-purple-50 dark:bg-purple-950/30",children:[e.jsx(dt,{className:"w-5 h-5 text-purple-600 dark:text-purple-400"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-sm",children:((c=t.hub)==null?void 0:c.locationName)||"Hub"}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[(m=t.hub)==null?void 0:m.city,", ",(i=t.hub)==null?void 0:i.country]})]})]}),e.jsxs("div",{className:"flex-1 flex items-center",children:[e.jsx("div",{className:"h-0.5 flex-1 bg-gradient-to-r from-purple-400 to-transparent"}),e.jsx(Ot,{className:"w-4 h-4 text-muted-foreground mx-2"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t.branches.length," branches"]})]})]}),e.jsxs(_t,{className:"w-full whitespace-nowrap pb-4",children:[e.jsx("div",{className:"flex gap-4 p-2",children:t.branches.map(({branch:r,nodes:h})=>e.jsx(hi,{branch:r,nodeCount:h.length,isSelected:a===r.id,onClick:()=>o(r.id)},r.id))}),e.jsx(ta,{orientation:"horizontal"})]}),a&&e.jsx("div",{className:"mt-4 p-4 rounded-lg border bg-muted/30",children:(()=>{const r=t.branches.find(h=>h.branch.id===a);return r?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:r.branch.color||"#3b82f6"}}),e.jsx("span",{className:"font-semibold",children:r.branch.label}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["• ",r.nodes.length," locations"]})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2",children:r.nodes.map((h,f)=>e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex flex-col items-center min-w-[100px] p-2 rounded bg-background border",children:[e.jsxs(T,{variant:"outline",className:"text-xs mb-1",children:["#",f+1]}),e.jsx("span",{className:"text-xs font-medium text-center truncate max-w-[90px]",children:h.locationName}),h.city&&e.jsx("span",{className:"text-[10px] text-muted-foreground truncate max-w-[90px]",children:h.city})]}),f<r.nodes.length-1&&e.jsx(rt,{className:"w-4 h-4 text-muted-foreground mx-1 flex-shrink-0"})]}
22,h.id))})]}):null})()})]})}async function Bs(){return{method:"PUT",url:(await(await fetch("/api/objects/upload",{method:"POST",credentials:"include"})).json()).uploadURL}}async function Gs(t){const a=await fetch("/api/objects/finalize",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({uploadURL:t,visibility:"public"})});if(!a.ok)throw new Error("Failed to finalize upload");return(await a.json()).path}function pi({node:t}){const[a,o]=p.useState(!1),[c,m]=p.useState(null),{toast:i}=we(),r=ae({mutationFn:async d=>(await Q("PATCH",`/api/chains/nodes/${t.id}/media`,d)).json(),onSuccess:()=>{V.invalidateQueries({queryKey:["/api/chains"]})},onError:()=>{i({title:"Update failed",description:"Could not update stop media. Please try again.",variant:"destructive"})}}),h=async d=>{var N;const l=(N=d.successful)==null?void 0:N[0];if(l!=null&&l.uploadURL){m("photo");try{const g=await Gs(l.uploadURL);await r.mutateAsync({coverImageUrl:g}),i({title:"Photo updated",description:"This stop now shows your new cover photo."})}catch{i({title:"Upload failed",description:"Could not process your photo. Please try again.",variant:"destructive"})}finally{m(null)}}},f=async d=>{var N;const l=(N=d.successful)==null?void 0:N[0];if(l!=null&&l.uploadURL){m("video");try{const g=await Gs(l.uploadURL);await r.mutateAsync({videoUrl:g}),i({title:"Video updated",description:"Fans will now see this video on hover."})}catch{i({title:"Upload failed",description:"Could not process your video. Please try again.",variant:"destructive"})}finally{m(null)}}};return e.jsxs(Ne,{open:a,onOpenChange:o,children:[e.jsx(zt,{asChild:!0,children:e.jsx(w,{size:"icon",variant:"secondary",className:"absolute top-2 right-2 h-7 w-7 bg-black/50 hover:bg-black/70 border-white/30 backdrop-blur-sm",onClick:d=>d.stopPropagation(),"data-testid":`button-edit-stop-media-${t.id}`,children:e.jsx(Sr,{className:"w-3.5 h-3.5 text-white"})})}),e.jsxs(ye,{onClick:d=>d.stopPropagation(),"data-testid":`dialog-edit-stop-media-${t.id}`,children:[e.jsxs($e,{children:[e.jsx(Ae,{children:"Edit stop media"}),e.jsxs(Wt,{children:['Update the cover photo or hover video for "',t.locationName,'".']})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Za,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:"Cover photo"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.coverImageUrl&&e.jsx(w,{size:"sm",variant:"ghost",disabled:r.isPending,onClick:()=>r.mutate({coverImageUrl:null}),"data-testid":`button-remove-cover-${t.id}`,children:e.jsx(Pe,{className:"w-3.5 h-3.5"})}),e.jsx(Us,{maxNumberOfFiles:1,maxFileSize:10485760,allowedFileTypes:["image/*"],onGetUploadParameters:Bs,onComplete:h,buttonVariant:"outline",children:c==="photo"?e.jsx(Y,{className:"w-3.5 h-3.5 animate-spin"}):t.coverImageUrl?"Replace":"Upload"})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Xa,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:"Hover video"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.videoUrl&&e.jsx(w,{size:"sm",variant:"ghost",disabled:r.isPending,onClick:()=>r.mutate({videoUrl:null}),"data-testid":`button-remove-video-${t.id}`,children:e.jsx(Pe,{className:"w-3.5 h-3.5"})}),e.jsx(Us,{maxNumberOfFiles:1,maxFileSize:52428800,allowedFileTypes:["video/*"],onGetUploadParameters:Bs,onComplete:f,buttonVariant:"outline",children:c==="video"?e.jsx(Y,{className:"w-3.5 h-3.5 animate-spin"}):t.videoUrl?"Replace":"Upload"})]})]})]})]})]})}function gi({node:t,isSelected:a,onClick:o,currentUserId:c}){var r,h,f,d,l,N,g,n;const m=(k,b)=>`${(k==null?void 0:k[0])||""}${(b==null?void 0:b[0])||""}`.toUpperCase()||"?",i=k=>k?new Date(k).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"";return e.jsxs(z,{className:`min-w-[280px] cursor-pointer transition-all ${a?"ring-2 ring-primary shadow-lg":"hover:shadow-md"}`,onClick:o,"data-testid":`node-card-${t.id}`,children:[e.jsx(br,{imageUrl:t.coverImageUrl,videoUrl:t.videoUrl,alt:t.locationName,fallbackSeed:t.id,aspect:"wide",rounded:"rounded-none rounded-t-xl","data-testid":`stop-media-node-${t.id}`,overlay:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-2 left-2 flex items-center gap-2",children:[e.jsxs(T,{variant:"outline",className:"text-xs bg-black/50 text-white border-white/30 backdrop-blur-sm",children:["#",t.nodeOrder]}),e.jsxs(T,{className:oi[t.status],children:[t.status==="open"&&e.jsx(Mt,{className:"w-3 h-3 mr-1"}),t.status==="accepted"&&e.jsx(Y,{className:"w-3 h-3 mr-1 animate-spin"}),t.status==="completed"&&e.jsx(et,{className:"w-3 h-3 mr-1"}),t.status]})]}),c&&((r=t.user)==null?void 0:r.id)===c&&e.jsx(pi,{node:t})]})}),e.jsxs(Z,{className:"pb-2",children:[e.jsx(X,{className:"text-base line-clamp-1",children:t.challengeTitle}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(se,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:t.locationName}),t.country&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-1",children:"·"}),e.jsx("span",{children:t.country})]})]})]}),e.jsxs(K,{className:"pt-0",children:[t.storyContent&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2 mb-3",children:t.storyContent}),t.contextType==="booking"&&t.challengeRequirements&&e.jsxs("div",{className:"flex gap-2 mb-3",onClick:k=>k.stopPropagation(),children:[e.jsx("a",{href:t.challengeRequirements.flightSearchUrl||"/flights",target:"_blank",rel:"noopener noreferrer",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"skyscanner",partnerName:"Skyscanner",bookingType:"flight",chainId,nodeId:t.id,destination:t.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{size:"sm",variant:"default",className:"flex-1 text-xs","data-testid":`book-flights-${t.id}`,children:[e.jsx(Ye,{className:"w-3 h-3 mr-1"}),t.challengeRequirements.flightCta||"Search Flights"]})}),e.jsx("a",{href:t.challengeRequirements.hotelsUrl||`/bookings?tab=live-search&city=${encodeURIComponent(t.city||t.locationName||"")}`,target:"_blank",rel:"noopener noreferrer",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"hotels",partnerName:"Hotels",bookingType:"hotel",chainId,nodeId:t.id,destination:t.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{size:"sm",variant:"outline",className:"flex-1 text-xs","data-testid":`book-hotels-${t.id}`,children:[e.jsx(ea,{className:"w-3 h-3 mr-1"}),t.challengeRequirements.hotelCta||"Find Hotels"]})})]}),((h=t.challengeRequirements)==null?void 0:h.isEventStop)&&e.jsx("div",{className:"mb-3",onClick:k=>k.stopPropagation(),children:e.jsx("a",{href:t.challengeRequirements.ticketUrl?`${t.challengeRequirements.ticketUrl}?utm_source=slant&utm_medium=chain&utm_campaign=${chainId}
22&slant_chain=${chainId}&slant_stop=${t.id}`:`/wallet?tab=tickets&chain=${chainId}&stop=${t.id}`,target:t.challengeRequirements.ticketUrl?"_blank":"_self",rel:"noopener noreferrer",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"ticket_partner",partnerName:t.challengeRequirements.ticketProvider||"Ticket Partner",bookingType:"ticket",chainId,nodeId:t.id,destination:t.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{size:"sm",className:"w-full text-xs bg-amber-500 hover:bg-amber-400 text-black font-semibold","data-testid":`get-ticket-${t.id}`,children:[e.jsx(Xs,{className:"w-3 h-3 mr-1.5"}),t.challengeRequirements.ticketCta||"Get Ticket",e.jsx(ie,{className:"w-3 h-3 ml-1 opacity-70"})]})})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(it,{className:"w-6 h-6",children:[e.jsx(nt,{src:((f=t.user)==null?void 0:f.profileImageUrl)||void 0}),e.jsx(lt,{className:"text-xs",children:m(((d=t.user)==null?void 0:d.firstName)||((l=t.user)==null?void 0:l.alias),(N=t.user)==null?void 0:N.lastName)})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:((g=t.user)==null?void 0:g.firstName)||((n=t.user)==null?void 0:n.alias)||"Slant member"})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i(t.postedAt)})]})]})]})}function Ws({chainId:t}){const{data:a}=O({queryKey:["/api/give-back/fund",t],enabled:!!t}),o=m=>
22new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(m/100);if(!a)return null;const c=a.balance??0;return c<=0?null:c<5e3?e.jsxs("div",{className:"mb-4 p-3 rounded-lg bg-gray-50 border border-gray-200 flex items-center justify-between gap-2","data-testid":"going-fund-counter",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(We,{className:"w-4 h-4 text-gray-400 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold text-gray-400 uppercase tracking-wide leading-none",children:"Building…"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Built by this chain's travelers. For this chain's travelers."})]})]}),e.jsx("span",{className:"text-xs font-bold text-gray-400 shrink-0",children:o(c)})]}):c>5e4?e.jsxs("div",{className:"mb-4 p-3 rounded-xl bg-amber-50 border border-amber-300 shadow-[0_0_12px_0_rgba(245,158,11,0.25)] flex items-center justify-between gap-3","data-testid":"going-fund-counter",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-100 flex items-center justify-center",children:e.jsx(We,{className:"w-4 h-4 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black text-amber-900",children:o(c)}),e.jsx("p",{className:"text-[10px] text-amber-600",children:"Built by this chain's travelers. For this chain's travelers."})]})]}),e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500 animate-pulse shrink-0"})]}):e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-amber-50 border border-amber-100 flex items-center justify-between gap-3","data-testid":"going-fund-counter",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(We,{className:"w-4 h-4 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-amber-900",children:o(c)}),e.jsx("p",{className:"text-[10px] text-amber-600",children:"Built by this chain's travelers. For this chain's travelers."})]})]})})}function fi({chainPath:t,selectedNodeId:a,onNodeSelect:o,currentUserId:c,chainId:m}){return t.nodes.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground","data-testid":"chain-timeline-empty",children:[e.jsx(Ws,{chainId:m}),e.jsx(se,{className:"w-10 h-10 mb-3 opacity-30"}),e.jsx("p",{className:"text-sm font-medium",children:"No stops added yet"}),e.jsx("p",{className:"text-xs mt-1 opacity-70",children:"Add your first stop to build this adventure"})]}):e.jsxs("div",{className:"relative",children:[e.jsx(Ws,{chainId:m}),e.jsxs(_t,{className:"w-full whitespace-nowrap pb-4",children:[e.jsx("div",{className:"flex gap-4 p-2",children:t.nodes.map((i,r)=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(gi,{node:i,isSelected:a===i.id,onClick:()=>o(i),currentUserId:c}),r<t.nodes.length-1&&e.jsxs("div",{className:"flex items-center mx-2 min-w-[60px]",children:[e.jsx("div",{className:"flex-1 h-0.5 bg-border"}),(()=>{const h=t.links.find(d=>d.fromNodeId===i.id),f=h!=null&&h.travelMethod?li[h.travelMethod]||rt:rt;return e.jsxs("div",{className:"flex flex-col items-center mx-2",children:[e.jsx(f,{className:"w-5 h-5 text-muted-foreground"}),(h==null?void 0:h.distanceKm)&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[h.distanceKm,"km"]})]})})(),e.jsx("div",{className:"flex-1 h-0.5 bg-border"})]})]},i.id))}),e.jsx(ta,{orientation:"horizontal"})]})]})}function bi({chainId:t,city:a}){var f,d,l,N,g;const[o,c]=p.useState(!1),{data:m,isLoading:i}=O({queryKey:["/api/chains",t,"offers"],enabled:!!t,staleTime:3e4,refetchInterval:3e4}),r=(m==null?void 0:m.topSlot)??((f=m==null?void 0:m.offers)==null?void 0:f.find(n=>n.slotPosition==="top"||n.resolvedSlot==="top"));if(i)return e.jsx(xe,{className:"h-24 w-full mb-6 rounded-xl"});if(!r)return null;const h=r.source??"partner";if(h==="discovery_prompt")return e.jsxs("div",{className:"mb-6 p-4 rounded-xl border border-dashed border-muted-foreground/30 flex items-center gap-3 bg-muted/20","data-testid":"top-slot-discovery-prompt",children:[e.jsx(se,{className:"w-5 h-5 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium",children:["Explore ",r.destinationCity??"this destination"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No partner offer yet — check back soon."})]})]});if(h==="viator"||h==="gyg"){const n=((d=r.metadata)==null?void 0:d.affiliateUrl)??((l=r.metadata)==null?void 0:l.gygUrl);return e.jsx("a",{href:n??"#",target:"_blank",rel:"noopener noreferrer","data-testid":"top-slot-affiliate",className:"block mb-6",children:e.jsxs("div",{className:"p-4 rounded-xl border border-amber-200 dark:border-amber-800 bg-gradient-to-r from-amber-50 to-orange-50 dark:from-amber-950/30 dark:to-orange-950/30 flex items-center gap-3 hover:shadow-md transition-shadow",children:[e.jsx(mt,{className:"w-6 h-6 text-amber-600 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx(T,{className:"text-[10px] bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300 border-amber-200","data-testid":"badge-top-slot",children:"Top Pick"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:h==="viator"?"via Viator":"via GetYourGuide"})]}),e.jsx("p",{className:"text-sm font-semibold truncate",children:r.title}),r.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:r.description})]}),e.jsx(ie,{className:"w-4 h-4 text-muted-foreground shrink-0"})]})})}return((N=r.metadata)==null?void 0:N.bookingProvider)==="liteapi"&&((g=r.metadata)==null?void 0:g.category)==="flight"?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>c(!0),"data-testid":"top-slot-flights",className:"block w-full mb-6 text-left",children:e.jsxs("div",{className:"p-4 rounded-xl border border-blue-200 dark:border-blue-800 bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-950/30 dark:to-indigo-950/30 flex items-center gap-3 hover:shadow-md transition-shadow",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-100 dar
22k:bg-blue-900/40 flex items-center justify-center shrink-0",children:e.jsx(Ye,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx(T,{className:"text-[10px] bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300 border-blue-200","data-testid":"badge-flights-top-slot",children:"Book Flights"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Direct booking · all airlines"}),r.discountValue&&e.jsxs(T,{variant:"outline",className:"text-[10px] text-green-700 dark:text-green-400 border-green-300",children:[r.discountValue,"% Slant Credits"]})]}),e.jsx("p",{className:"text-sm font-semibold truncate",children:r.title}),r.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1 mt-0.5",children:r.description})]}),e.jsx(Gt,{className:"w-4 h-4 text-muted-foreground shrink-0"})]})}),e.jsx(Ne,{open:o,onOpenChange:c,children:e.jsxs(ye,{className:"max-w-3xl w-full p-0 overflow-hidden","data-testid":"dialog-flights",children:[e.jsxs($e,{className:"sr-only",children:[e.jsx(Ae,{children:"Book Flights"}),e.jsx(Wt,{children:"Search and book flights directly on Slant"})]}),e.jsx(dr,{defaultTab:"flights",chainId:t,city:a??""})]})})]}):e.jsx("div",{className:"mb-6 p-4 rounded-xl border border-primary/30 bg-gradient-to-r from-primary/5 to-transparent","data-testid":"top-slot-partner",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(he,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(T,{className:"text-[10px] bg-primary/10 text-primary border-primary/20","data-testid":"badge-partner-top-slot",children:"Partner Offer"}),r.partnerName&&e.jsx("span",{className:"text-xs text-muted-foreground",children:r.partnerName}),r.discountValue&&e.jsx(T,{variant:"outline",className:"text-[10px] text-green-700 dark:text-green-400 border-green-300",children:r.discountUnit==="percent"?`${r.discountValue}% off`:`$${r.discountValue} off`})]}),e.jsx("p",{className:"text-sm font-semibold",children:r.title}),r.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-0.5",children:r.description}),r.redemptionInstructions&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 italic",children:['"',r.redemptionInstructions,'"']})]})]})})}function Qs(){const[,t]=Ja(),[a,o]=p.useState(5);return p.useEffect(()=>{const c=setInterval(()=>{o(m=>m<=1?(clearInterval(c),t("/chains"),0):m-1)},1e3);return()=>clearInterval(c)},[t]),e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center","data-testid":"chain-not-found",children:[e.jsx(Zs,{className:"w-16 h-16 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Chain not found"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"This chain may have been removed or you don't have access to it."}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4","data-testid":"redirect-countdown",children:["Redirecting to chains in ",a,"s…"]}),e.jsx(be,{href:"/chains",children:e.jsx(w,{"data-testid":"button-back-to-chains",children:"Back to Chain Explorer"})})]})})}function il(){var hs,us,ps,gs,fs,bs,js,vs,Ns,ys,ws,ks,Cs,Ss;const[,t]=Wa("/chains/:id"),a=t==null?void 0:t.id,[o,c]=p.useState(),[m,i]=p.useState(),[r,h]=p.useState(!1),[f,d]=p.useState(),[l,N]=p.useState(null),[g,n]=p.useState(!1),[k,b]=p.useState(""),[j,v]=p.useState("explore"),[S,A]=p.useState(""),[I,L]=p.useState(""),[P,$]=p.useState(null),[M,U]=p.useState(0),[y,B]=p.useState(!1),[D,ue]=p.useState(!1),[de,ke]=p.useState(!1),[Je,Yt]=p.useState(!1),[ne,Ce]=p.useState(null),[ca,Jt]=p.useState(!1),[Zt,Xt]=p.useState(null),[es,da]=p.useState(!1),[ht,ut]=p.useState(!1),{toast:q}=we(),{user:E}=Qe(),{hasExpression:ma}=Vr(a||"");p.useEffect(()=>{if(window.location.hash==="#chat"){const s=()=>{const u=document.getElementById("chat");u?u.scrollIntoView({behavior:"smooth",block:"start"}):setTimeout(s,200)};setTimeout(s,400)}},[]);const{data:C,isLoading:pt,isError:xa}=O({queryKey:["/api/chains",a],enabled:!!a});p.useEffect(()=>{var F;const s=C==null?void 0:C.thread;if(!s||s.entryMode!=="booking_first")return;
22if(new URLSearchParams(window.location.search).get("surface")==="booking"&&s.bookingAffiliateUrl){const J=s.id,le=((F=crypto==null?void 0:crypto.randomUUID)==null?void 0:F.call(crypto))??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,Ze=s.bookingAffiliateUrl.includes("?")?"&":"?";window.open(`${s.bookingAffiliateUrl}${Ze}slant_click=${le}`,"_blank","noopener,noreferrer"),localStorage.setItem(`slant-outbound-${J}`,JSON.stringify({chainId:J,timestamp:Date.now(),clickId:le})),fetch(`/api/chains/${J}/outbound-click`,{method:"POST",credentials:"include"}).catch(()=>{}),Ce({bookingId:"pending",bookingValueCents:0,adopted:!1,isWaitingForReturn:!0,affiliateClickId:le});const Me=new URLSearchParams(window.location.search);Me.delete("surface");const Xe=Me.toString();window.history.replaceState({},"",window.location.pathname+(Xe?`?${Xe}`:""))}},[C]),p.useEffect(()=>{if(!a)return;const s=localStorage.getItem(`slant-outbound-${a}`);if(s)try{const{timestamp:u,clickId:R}=JSON.parse(s),F=7*24*60*60*1e3;Date.now()-u<F?Ce(J=>J??{bookingId:"pending",bookingValueCents:0,adopted:!1,isWaitingForReturn:!0,affiliateClickId:R??void 0}):localStorage.removeItem(`slant-outbound-${a}`)}catch{localStorage.removeItem(`slant-outbound-${a}`)}},[a]),p.useEffect(()=>{const s=()=>{document.visibilityState==="visible"&&(Jt(!0),setTimeout(()=>Jt(!1),2500),a&&fetch(`/api/chains/${a}/funnel-event`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({eventType:"tab_return"})}).catch(()=>{}))};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[]),p.useEffect(()=>{const s=new URLSearchParams(window.location.search),u=s.get("surface"),R=s.get("bookingId"),F=parseInt(s.get("bookingValueCents")??"0",10);if(u==="post_booking"&&R){const J=s.get("click")??void 0,le=s.get("adopt")==="1";Ce({bookingId:R,bookingValueCents:isNaN(F)?0:F,adopted:!1,affiliateClickId:J,autoAdopt:le});const Ze=new URLSearchParams(window.location.search);["surface","bookingId","bookingValueCents","click","adopt"].forEach(Xe=>Ze.delete(Xe));const Me=Ze.toString();window.history.replaceState({},"",window.location.pathname+(Me?`?${Me}`:""))}},[]);const H=((hs=C==null?void 0:C.thread)==null?void 0:hs.chainType)==="spider",{data:gt}=O({queryKey:["/api/chains",a,"discover-related"],enabled:!!a&&!!C}),{data:te,isLoading:ha,isError:ua}=O({queryKey:["/api/chains",a,"path"],enabled:!!a&&!H&&C!==void 0}),{data:_,isLoading:pa,isError:ga}=O({queryKey:["/api/chains",a,"spider-path"],enabled:!!a&&H}),{data:pe,refetch:ji}=O({queryKey:["/api/chains",a,"participants"],enabled:!!a}),{data:Re,isLoading:fa}=O({queryKey:["/api/chains",a,"activation-content"],enabled:!!a&&!!E,retry:!1});p.useEffect(()=>{var R;if(!(pe!=null&&pe.participants)||!E)return;const s=((R=E==null?void 0:E.claims)==null?void 0:R.sub)||(E==null?void 0:E.id),u=pe.participants.some(F=>{var J,le;return(F.userId??((J=F.participant)==null?void 0:J.userId)??((le=F.user)==null?void 0:le.id))===s});B(u)},[pe,E]);const{data:ee}=O({queryKey:["/api/chains",a,"campaign-info"],enabled:!!a}),{data:ft}=O({queryKey:["/api/safety/chain/active"],enabled:!!E,staleTime:3e4}),ge=(ft==null?void 0:ft.chain)??null,bt=ae({mutationFn:()=>{var s,u;return Q("POST","/api/safety/chain",{destination:((s=C==null?void 0:C.thread)==null?void 0:s.destinationCity)||((u=C==null?void 0:C.thread)==null?void 0:u.title),routeId:a,checkinIntervalMinutes:30})},onSuccess:()=>{V.invalidateQueries({queryKey:["/api/safety/chain/active"]}),q({title:"Safety mode is on",description:"Your location is being shared with your emergency contacts."})},onError:()=>{q({title:"Safety mode unavailable",description:"Add a trusted contact in Safety Settings to enable tracking.",variant:"destructive"})}});p.useEffect(()=>{if(!E||!(C!=null&&C.thread)||ge||es)return;const s=C.thread,u=Date.now(),R=s.bookingWindowStart?new Date(s.bookingWindowStart).getTime():null,F=s.bookingWindowEnd?new Date(s.bookingWindowEnd).getTime():null;if((R&&F?u>=R&&u<=F:!1)&&!ht){const le=`safety-prompted-${a}`;sessionStorage.getItem(le)||(sessionStorage.setItem(le,"1"),ut(!0))}},[E,C,ge,es,a,ht]);const ts=!!((us=C==null?void 0:C.thread)!=null&&us.campaignId&&(ee!=null&&ee.hasActiveCampaign)),{activeFences:ss,isPolling:ba,manualCheckIn:ja,error:as}=Mr({enabled:ts&&!!E,intervalMs:3e4,onEntry:s=>{q({title:`You've arrived at ${s.name}!`,description:"Checking offers..."}),V.invalidateQueries({queryKey:["/api/offers"]})},onExit:s=>{q({title:`You've left ${s.name}`,variant:"default"})}}),{data:rs=[]}=O({queryKey:["/api/creator/brand-kits"],enabled:!!E}),{data:is=[]}=O({queryKey:["/api/creator/assets"],enabled:!!E}),Le=(ps=C==null?void 0:C.thread)==null?void 0:ps.creatorId,{data:je}=O({queryKey:["/api/impact/portfolio",Le],enabled:!!Le}),{data:G}=O({queryKey:["/api/chains",a,"pin-status"],queryFn:()=>fetch(`/api/chains/${a}/pin-status`).then(s=>s.json()),enabled:!!a&&!!((gs=C==null?void 0:C.thread)!=null&&gs.pinEligibleCount)}),{data:jt}=O({queryKey:["/api/chain-certificates/mine",a],queryFn:async()=>{const s=await fetch(`/api/chain-certificates/mine/${a}`,{credentials:"include"});return s.ok?s.json():null},enabled:!!a&&!!E,retry:!1}),Fe=(jt==null?void 0:jt.certificate)??null,{data:Se}=O({queryKey:["/api/chains",a,"reward-status"],queryFn:async()=>{const s=await fetch(`/api/chains/${a}/reward-status`,{credentials:"include"});return s.ok?s.json():null},enabled:!!a&&!!E&&!!Fe,retry:!1}),va=pt||!H&&!pt&&ha||H&&pa,Na=!H&&ua||H&&ga,vt=ae({mutationFn:async()=>Q("POST",`/api/chains/${a}/follow`),onSuccess:s=>{B(!0),V.invalidateQueries({queryKey:["/api/chains",a,"participants"]}),V.invalidateQueries({queryKey:["/api/chains",a]}),V.invalidateQueries({queryKey:["/api/chains"]}),q({title:"Following chain",description:"You will receive updates about this chain."})},onError:s=>{q({title:"Error",description:s.message||"Failed to follow chain",variant:"destructive"})}}),Nt=ae({mutationFn:async()=>(await Q("POST",`/api/chains/${a}/pin-count/recalibrate`)).json(),onSuccess:s=>{V.invalidateQueries({queryKey:["/api/chains",a,"pin-status"]}),V.invalidateQueries({queryKey:["/api/chains",a]}),q({title:"Pin count recalibrated",description:`Slant Brain set X to ${s.count} — ${s.reasoning}`})},onError:()=>{q({title:"Recalibration failed",variant:"destructive"})}}),yt=ae({mutationFn:async s=>{const u=x!=null&&x.slug?`${window.location.origin}/c/${x.slug}`:`${window.location.origin}/c/${a}`;return(await Q("POST","/api/qr-registry/qr-codes",{label:s.label||`Chain: ${x==null?void 0:x.title}`,intent:s.intent,surface:"social",chainThreadId:a,targetUrl:u,brandKitId:s.brandKitId||void 0})).json()},onSuccess:s=>{const u=s==null?void 0:s.qrCode;if(!(u!=null&&u.id)){q({title:"Error",description:"QR code was created but the response was incomplete. Refresh and try again.",variant:"destructive"});return}$({id:u.id,code:u.shortCode,shareUrl:s.shareUrl,brandedAssetId:u.brandedAssetId||void 0}),u.brandedAssetId&&L(u.brandedAssetId),q({title:"QR Code Generated",description:"Your chain QR code is ready to share!"}),V.invalidateQueries({queryKey:["/api/qr-registry/qr-codes"]})},onError:s=>{q({title:"Error",description:s.message||"Failed to generate QR code",variant:"destructive"})}}),wt=ae({mutationFn:async s=>(await Q("POST","/api/creator/assets/generate",{templateId:"promo-card",
22name:s.name,format:"png",headline:(x==null?void 0:x.title)||"Join the Chain",subheadline:(x==null?void 0:x.description)||"Scan to explore",callToAction:"Scan to Join",qrCodeId:s.qrCodeId,qrCodeDataUrl:s.qrCodeDataUrl,brandKitId:S||void 0,campaignId:a})).json(),onSuccess:()=>{q({title:"Branded Asset Created",description:"Your branded promotional asset is ready! View it in Creator Studio."}),V.invalidateQueries({queryKey:["/api/creator/assets"]})},onError:s=>{q({title:"Error",description:s.message||"Failed to create branded asset",variant:"destructive"})}}),kt=ae({mutationFn:async({qrCodeId:s,assetId:u})=>(await Q("PATCH",`/api/qr-registry/qr-codes/${s}/asset`,{brandedAssetId:u})).json(),onSuccess:(s,u)=>{const R=!u.assetId;q({title:R?"Asset Unlinked":"Asset Linked",description:R?"Branded asset has been removed from this QR code.":"Branded asset has been linked to this QR code."}),P&&$({...P,brandedAssetId:u.assetId||void 0}),L(u.assetId||"")},onError:s=>{q({title:"Error",description:s.message||"Failed to link asset",variant:"destructive"})}}),ya=()=>{if(P){const s=`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(P.shareUrl)}`;wt.mutate({qrCodeId:P.id,qrCodeDataUrl:s,name:`${(x==null?void 0:x.title)||"Chain"} - Promo Card`})}},wa=()=>{P&&kt.mutate({qrCodeId:P.id,assetId:I||null})},x=C==null?void 0:C.thread,Ee=(E==null?void 0:E.id)===(x==null?void 0:x.creatorId),ka=(E==null?void 0:E.role)==="admin",Ct=Ee||ka,{data:Ie}=O({queryKey:["/api/chains",a,"integrity"],enabled:!!a&&Ct}),{data:fe,refetch:Ca}=O({queryKey:["/api/chains",a,"settlement-certificate"],enabled:!!a&&Ct,retry:!1}),St=ae({mutationFn:()=>Q("POST",`/api/chains/${a}/settle`),onSuccess:()=>{q({title:"Chain settled",description:"Settlement certificate generated and signed."}),V.invalidateQueries({queryKey:["/api/chains",a]}),Ca()},onError:()=>q({title:"Settlement failed",variant:"destructive"})}),Sa=()=>{if(!fe)return;const s=new Blob([JSON.stringify(fe,null,2)],{type:"application/json"}),u=URL.createObjectURL(s),R=document.createElement("a");R.href=u,R.download=`slant-settlement-${a==null?void 0:a.slice(0,8)}.json`,R.click(),URL.revokeObjectURL(u)},Ia=()=>{yt.mutate({label:k,intent:j,brandKitId:S||void 0})},ns=()=>{P!=null&&P.shareUrl&&(navigator.clipboard.writeText(P.shareUrl),q({title:"Copied!",description:"Share URL copied to clipboard"}))},ls=s=>{c(s.id)},Ta=s=>s?new Date(s).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}):"",os=s=>{d(s),h(!0)};if(va)return e.jsx("div",{className:"min-h-screen bg-background p-4",children:e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsx(xe,{className:"h-8 w-48 mb-4"}),e.jsx(xe,{className:"h-[400px] w-full rounded-lg mb-8"}),e.jsx("div",{className:"flex gap-4 overflow-hidden",children:[1,2,3].map(s=>e.jsx(xe,{className:"h-48 w-72 flex-shrink-0"},s))})]})});if(xa||!(C!=null&&C.thread)&&!pt)return e.jsx(Qs,{});if(Na)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(Zs,{className:"w-16 h-16 text-red-400 mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Error loading chain data"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"There was a problem loading the chain path. Please try again."}),e.jsxs("div",{className:"flex gap-2 justify-center",children:[e.jsx(w,{onClick:()=>window.location.reload(),children:"Retry"}),e.jsx(be,{href:"/chains",children:e.jsx(w,{variant:"outline",children:"Back to Chains"})})]})]})});const Pa=(te==null?void 0:te.nodes)||[];te!=null&&te.links;const $a=(te==null?void 0:te.totalDistance)||0,Aa=(te==null?void 0:te.countriesVisited)||[],Ra=((fs=_==null?void 0:_.branches)==null?void 0:fs.flatMap(s=>s.nodes))||[];_!=null&&_.links;const La=((bs=_==null?void 0:_.stats)==null?void 0:bs.totalDistance)||0,Fa=((js=_==null?void 0:_.stats)==null?void 0:js.countriesVisited)||[],Ue=H?Ra:Pa,Ea=H?La:$a,It=H?Fa:Aa,cs=((pe==null?void 0:pe.participants)||[]).map(s=>{const u=(s==null?void 0:s.participant)??s,R=(s==null?void 0:s.user)??(u==null?void 0:u.user)??null;return{id:(u==null?void 0:u.id)??(s==null?void 0:s.id),role:(u==null?void 0:u.role)??(s==null?void 0:s.role),participant:u,user:R}}).filter(s=>!!s.id),Oe=cs.filter(s=>s.role==="contributor"||s.role==="challenger"),Te=cs.filter(s=>s.role==="observer"||s.role==="member"),ds=Ue.filter(s=>s.status==="open"||s.status==="active"),ms=Ue.filter(s=>s.status==="completed"),xs=Ue.length>0?Math.round(ms.length/Ue.length*100):0;return x?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-background/95 backdrop-blur border-b",children:e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-3 flex items-center justify-between",children:[e.jsx(be,{href:"/chains",children:e.jsxs(w,{variant:"ghost",size:"sm","data-testid":"back-button",children:[e.jsx(jr,{className:"w-4 h-4 mr-1"}),"Back to Chains"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[!y&&(x==null?void 0:x.tripCreditValueCents)&&x.tripCreditValueCents>0&&e.jsxs("div",{className:"flex items-center gap-1 px-2.5 py-1 rounded-lg bg-amber-50 border border-amber-200 dark:bg-amber-950/20 dark:border-amber-800/40","data-testid":"chain-credit-earn-badge",children:[e.jsx(We,{className:"w-3.5 h-3.5 text-amber-600 dar
22k:text-amber-400 shrink-0"}),e.jsxs("span",{className:"text-xs font-semibold text-amber-800 dark:text-amber-300",children:["Earn $",(x.tripCreditValueCents/100).toLocaleString(void 0,{minimumFractionDigits:0,maximumFractionDigits:0})," in credits"]})]}),!y&&(G==null?void 0:G.active)&&(G.slotsRemaining??0)>0&&!G.userEarned&&e.jsxs("div",{className:"flex items-center gap-1 px-2.5 py-1 rounded-lg bg-purple-50 border border-purple-200 dark:bg-purple-950/20 dark:border-purple-800/40","data-testid":"chain-pin-eligible-badge",children:[e.jsx(se,{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400 shrink-0"}),e.jsxs("span",{className:"text-xs font-semibold text-purple-800 dark:text-purple-300",children:[G.slotsRemaining," eligibility spot",G.slotsRemaining!==1?"s":""," left"]})]}),(G==null?void 0:G.userEarned)&&e.jsxs("div",{className:"flex items-center gap-1 px-2.5 py-1 rounded-lg bg-purple-50 border border-purple-200 dark:bg-purple-950/20 dark:border-purple-800/40","data-testid":"chain-pin-earned-badge",children:[e.jsx(se,{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400 shrink-0"}),e.jsxs("span",{className:"text-xs font-semibold text-purple-800 dark:text-purple-300",children:["Pin eligible #",G.userRank]})]}),e.jsxs(w,{variant:y?"secondary":"outline",size:"sm",onClick:()=>{y||vt.mutate()},disabled:vt.isPending||y,"data-testid":"follow-chain-button",children:[vt.isPending?e.jsx(Y,{className:"w-4 h-4 mr-1 animate-spin"}):y?e.jsx(et,{className:"w-4 h-4 mr-1"}):e.jsx(Qa,{className:"w-4 h-4 mr-1"}),y?"Following":"Follow Chain"]}),e.jsxs(w,{variant:"outline",size:"sm","data-testid":"share-chain-button",onClick:()=>{const s=x!=null&&x.slug?`${window.location.origin}/c/${x.slug}`:`${window.location.origin}/chains/${a}`,u={title:(x==null?void 0:x.title)||"Slant Chain",text:(x==null?void 0:x.description)||"Check out this journey on Slant!",url:s};navigator.share&&navigator.canShare&&navigator.canShare(u)?navigator.share(u).catch(R=>{(R==null?void 0:R.name)!=="AbortError"&&navigator.clipboard.writeText(s).then(()=>{q({title:"Link copied!",description:"Chain link copied to clipboard."})}).catch(()=>{})}):navigator.clipboard.writeText(s).then(()=>{q({title:"Link copied!",description:"Chain link copied to clipboard."})}).catch(()=>{q({title:"Share",description:s})})},children:[e.jsx(Ve,{className:"w-4 h-4 mr-1"}),"Share"]}),(ge==null?void 0:ge.shareToken)&&e.jsxs(w,{variant:"outline",size:"sm","data-testid":"share-live-location-button",onClick:()=>{const s=`${window.location.origin}/safety/monitor/${ge.shareToken}`;navigator.clipboard.writeText(s).then(()=>{q({title:"Live location link copied!",description:"Share this private link so contacts can follow your journey."})}).catch(()=>{q({title:"Share Live Location",description:s})})},className:"border-blue-400/40 text-blue-300 hover:bg-blue-500/10",children:[e.jsx(tt,{className:"w-4 h-4 mr-1"}),"Share Live Location"]}),Ee&&e.jsxs(Ne,{open:g,onOpenChange:s=>{n(s),s||($(null),b(""),v("explore"),A(""),L(""))},children:[e.jsx(zt,{asChild:!0,children:e.jsxs(w,{variant:"default",size:"sm","data-testid":"generate-chain-qr-button",children:[e.jsx(Ft,{className:"w-4 h-4 mr-1"}),"Generate QR"]})}),e.jsxs(ye,{className:"sm:max-w-md",children:[e.jsxs($e,{children:[e.jsx(Ae,{children:"Generate Chain QR Code"}),e.jsx(Wt,{children:"Create a QR code that links directly to this chain. Share it to invite people to join."})]}),P?e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsx("div",{className:"flex justify-center p-4 bg-white rounded-lg",children:e.jsx("img",{src:`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(P.shareUrl)}`,alt:"Chain QR Code",className:"w-48 h-48","data-testid":"img-generated-qr"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:"Share URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(re,{value:P.shareUrl,readOnly:!0,className:"font-mono text-sm","data-testid":"input-share-url"}),e.jsx(w,{variant:"outline",size:"icon",onClick:ns,"data-testid":"button-copy-share-url",children:e.jsx(vr,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{variant:"outline",className:"flex-1",onClick:()=>{const s=document.createElement("a");s.href=`https://api.qrserver.com/v1/create-qr-code/?size=400x400&data=${encodeURIComponent(P.shareUrl)}`,s.download=`slant-qr-${P.code||a}.png`,s.target="_blank",s.click(),q({title:"QR downloading",description:"Save to your photos so you can share anytime."})},"data-testid":"button-download-qr-image",children:[e.jsx($t,{className:"w-4 h-4 mr-1"}),"Save QR Image"]}),e.jsxs(w,{variant:"outline",className:"flex-1",onClick:()=>{navigator.share?navigator.share({title:x.title,text:`Join ${x.title} on Slant`,url:P.shareUrl}):ns()},"data-testid":"button-share-qr-native",children:[e.jsx(Ve,{className:"w-4 h-4 mr-1"}),"Share"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(w,{variant:"outline",className:"flex-1",onClick:()=>{$(null),b("")},"data-testid":"button-generate-another",children:"Generate Another"}),e.jsx(w,{className:"flex-1",onClick:()=>n(!1),"data-testid":"button-done",children:"Done"})]}),e.jsx(Ha,{className:"my-2"}),e.jsx(w,{variant:"outline",className:"w-full",onClick:ya,disabled:wt.isPending,"data-testid":"button-create-branded-asset",children:wt.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating Asset..."]}
22):e.jsxs(e.Fragment,{children:[e.jsx(oa,{className:"w-4 h-4 mr-2"}),"Create Branded Promo Card"]})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Generate a branded promotional image with this QR code"}),is.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx(W,{htmlFor:"link-existing-asset",children:"Or link existing asset"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(ze,{value:I,onValueChange:L,children:[e.jsx(Ke,{className:"flex-1","data-testid":"select-existing-asset",children:e.jsx(Be,{placeholder:"Select an existing asset"})}),e.jsxs(Ge,{children:[e.jsx(oe,{value:"none",children:"No asset"}),is.map(s=>e.jsx(oe,{value:s.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[s.thumbnailUrl&&e.jsx("img",{src:s.thumbnailUrl,alt:"",className:"w-6 h-6 rounded object-cover"}),e.jsx("span",{children:s.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.assetType," - ",s.format.toUpperCase(),")"]})]})},s.id))]})]}),e.jsx(w,{variant:"outline",onClick:wa,disabled:kt.isPending||I===""&&!(P!=null&&P.brandedAssetId),"data-testid":"button-link-asset",children:kt.isPending?e.jsx(Y,{className:"w-4 h-4 animate-spin"}):I===""&&(P!=null&&P.brandedAssetId)?e.jsx("span",{className:"text-xs",children:"Unlink"}):e.jsx(Ms,{className:"w-4 h-4"})})]}),P!=null&&P.brandedAssetId?e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:'Asset linked - select "No asset" to unlink'}):I&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click the link button to attach this asset"})]})]}):e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"qr-label",children:"Label (optional)"}),e.jsx(re,{id:"qr-label",placeholder:`Chain: ${x.title}`,value:k,onChange:s=>b(s.target.value),"data-testid":"input-qr-label"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"qr-intent",children:"Intent"}),e.jsxs(ze,{value:j,onValueChange:v,children:[e.jsx(Ke,{"data-testid":"select-qr-intent",children:e.jsx(Be,{placeholder:"Select intent"})}),e.jsxs(Ge,{children:[e.jsx(oe,{value:"explore",children:"Explore Chain"}),e.jsx(oe,{value:"follow_roster",children:"Follow Roster"}),e.jsx(oe,{value:"presale",children:"Presale Registration"}),e.jsx(oe,{value:"register",children:"Register"})]})]})]}),rs.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"qr-brand-kit",children:"Brand Kit (optional)"}),e.jsxs(ze,{value:S,onValueChange:A,children:[e.jsx(Ke,{"data-testid":"select-qr-brand-kit",children:e.jsx(Be,{placeholder:"Select brand kit for styling"})}),e.jsxs(Ge,{children:[e.jsx(oe,{value:"none",children:"No brand kit"}),rs.map(s=>e.jsx(oe,{value:s.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full border",style:{backgroundColor:s.primaryColor}}),s.name,s.isDefault&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(Default)"})]})},s.id))]})]})]}),e.jsx(w,{onClick:Ia,disabled:yt.isPending,className:"w-full","data-testid":"button-generate-qr-submit",children:yt.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{className:"w-4 h-4 mr-2"}),"Generate QR Code"]})})]})]})]})]})]})}),e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-6",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("div",{className:"flex items-start justify-between gap-4 mb-4",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(T,{variant:x.status==="active"?"default":"secondary",children:x.status}),H&&e.jsxs(T,{className:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",children:[e.jsx(dt,{className:"w-3 h-3 mr-1"}),"Spider Chain"]}),x.theme&&e.jsx(T,{variant:"outline",children:x.theme}),je&&je.goals.length>0&&e.jsxs(T,{className:"bg-pink-100 text-pink-700 dark:bg-pink-900/30 dark:text-pink-400","data-testid":"badge-impact-goal",children:[e.jsx(st,{className:"w-3 h-3 mr-1"}),"Impact"]})]}),e.jsx("h1",{className:"text-2xl md:text-3xl font-bold mb-2","data-testid":"chain-title",children:x.title}),x.description&&e.jsx("p",{className:"text-muted-foreground max-w-2xl",children:x.description})]})}),x.entryMode==="booking_first"&&x.bookingAffiliateUrl&&!ne&&e.jsxs("div",{className:"mb-4 rounded-2xl border border-amber-400/40 bg-gradient-to-br from-amber-500/10 to-amber-700/10 p-4","data-testid":"book-and-join-banner",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 shrink-0 rounded-full bg-amber-500/20 flex items-center justify-center mt-0.5",children:e.jsx(ie,{className:"w-4 h-4 text-amber-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-amber-200 leading-tight",children:"Book first, then add the Going"}),e.jsx("p",{className:"text-xs text-amber-300/70 mt-0.5",children:"Complete your booking via our partner, then come back here to join the adventure and earn 15% back in Slant Credits."})]})]}),e.jsxs(w,{className:"w-full mt-3 bg-amber-500 hover:bg-amber-400 text-black font-bold h-10","data-testid":"button-book-and-join",onClick:()=>{var F;const s=x.bookingAffiliateUrl,u=((F=crypto==null?void 0:crypto.randomUUID)==null?void 0:F.call(crypto))??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;localStorage.setItem(`slant-outbound-${a}`,JSON.stringify({chainId:a,timestamp:Date.now(),clickId:u})),fetch(`/api/chains/${a}/outbound-click`,{method:"POST",credentials:"include"}).catch(()=>{});const R=s.includes("?")?"&":"?";window.open(`${s}${R}slant_click=${u}&return=chain&chainId=${a}&source=slant`,"_blank","noopener,noreferrer"),Ce({bookingId:"pending",bookingValueCents:0,adopted:!1,isWaitingForReturn:!0,affiliateClickId:u})},children:[e.jsx(ie,{className:"w-4 h-4 mr-2"}),"Book + Join"]})]}),ne&&!ne.adopted&&a&&e.jsx("div",{className:`mb-4 transition-all duration-700 ${ca&&ne.isWaitingForReturn?"ring-2 ring-amber-400 ring-offset-2 ring-offset-background rounded-2xl":""}`,"data-testid":"post-booking-offer-container",children:e.jsx(ri,{chainId:a,bookingId:ne.bookingId,bookingValueCents:ne.bookingValueCents,isWaitingForReturn:ne.isWaitingForReturn,affiliateClickId:ne.affiliateClickId,autoAdopt:ne.autoAdopt,onFunnelEvent:s=>{fetch(`/api/chains/${a}/funnel-event`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({eventType:s,affiliateClickId:ne.affiliateClickId,bookingId:ne.bookingId})}).catch(()=>{})},onAdopted:()=>{Ce(s=>s?{...s,adopted:!0}:null),B(!0),localStorage.removeItem(`slant-outbound-${a}
22`),q({title:"You've joined the Going!",description:"Welcome to the adventure. Your Slant Credits will appear shortly."})},onSkipped:()=>{Ce(null),localStorage.removeItem(`slant-outbound-${a}`)}})}),a&&e.jsx(Fr,{chainId:a}),e.jsxs("div",{className:"flex items-center gap-4 mb-4","data-testid":"chain-progress",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(et,{className:"w-5 h-5 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"font-semibold text-lg","data-testid":"progress-text",children:H&&_?`${_.stats.totalNodes} locations across ${_.stats.branchCount} branches`:`${ms.length}/${Ue.length} cities complete`})]}),!H&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 max-w-xs",children:e.jsx(ct,{value:xs,className:"h-2"})}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[xs,"%"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[H&&_&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ot,{className:"w-4 h-4 text-purple-500"}),e.jsxs("span",{children:[_.stats.branchCount," branches"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(At,{className:"w-4 h-4"}),e.jsxs("span",{children:[H&&_?_.stats.countriesVisited.length:It.length," countries"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(rt,{className:"w-4 h-4"}),e.jsxs("span",{children:[H&&_?_.stats.totalDistance.toLocaleString():Ea.toLocaleString()," km traveled"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(_e,{className:"w-4 h-4"}),e.jsxs("span",{children:[Oe.length," contributors"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Ut,{className:"w-4 h-4"}),e.jsxs("span",{children:[Te.length," followers"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(He,{className:"w-4 h-4"}),e.jsxs("span",{children:["Started ",Ta(x.startedAt)]})]})]})]}),e.jsxs("div",{className:"mb-4 flex items-center gap-3 text-sm text-muted-foreground","data-testid":"native-geofence-status",children:[ts&&ba&&e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2.5 w-2.5 bg-green-500"})]}),"Location Active"]}),ss.length>0&&e.jsxs(T,{variant:"secondary","data-testid":"badge-inside-fence",children:["Inside: ",ss.map(s=>s.name).join(", ")]}),e.jsxs(w,{variant:D?"secondary":"outline",size:"sm",onClick:async()=>{ke(!0);try{await ja(),ue(!0),q({title:"Checked in!",description:"Your location has been recorded."})}catch{q({title:"Check-in failed",description:"Could not record your location. Try again.",variant:"destructive"})}finally{ke(!1)}},disabled:D||de,"data-testid":"button-manual-checkin",children:[de?e.jsx(Y,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):D?e.jsx(et,{className:"w-3.5 h-3.5 mr-1"}):e.jsx(se,{className:"w-3.5 h-3.5 mr-1"}),D?"Checked In":de?"Checking In…":"Check In"]}),as&&e.jsx("span",{className:"text-xs text-destructive",children:as})]}),e.jsx(Xr,{}),((vs=C==null?void 0:C.thread)==null?void 0:vs.campaignId)&&C.thread.cashDropEnabled&&e.jsx("div",{className:"mb-6","data-testid":"crew-jackpot-section",children:e.jsx(si,{campaignId:C.thread.campaignId})}),x&&(x.eventName||x.bookingWindowStart||(x.activeTravelerCount??0)>0||(x.tripCreditValueCents??0)>0||(x.pinEligibleCount??0)>0||x.cashDropEnabled&&((x.poolValueCents??0)>0||x.pinDropStatus))&&e.jsxs(z,{className:"mb-6 border-primary/20 bg-gradient-to-br from-primary/5 to-transparent","data-testid":"chain-spec-panel",children:[e.jsx(Z,{className:"pb-3",children:e.jsxs(X,{className:"text-sm font-semibold flex items-center gap-2 text-primary",children:[e.jsx(mt,{className:"w-4 h-4"}),"Chain Details"]})}),e.jsxs(K,{className:"grid grid-cols-2 md:grid-cols-4 gap-4 pt-0",children:[(x.tripCreditValueCents??0)>0&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-amber-50/80 border border-amber-200 dark:bg-amber-950/20 dark:border-amber-800/40","data-testid":"chain-trip-credit-value",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(xt,{className:"w-4 h-4 text-amber-600 dar
22k:text-amber-400"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Credits on Join"})]}),e.jsxs("div",{className:"text-xl font-bold text-amber-600 dark:text-amber-400",children:["$",(x.tripCreditValueCents/100).toLocaleString(void 0,{minimumFractionDigits:0})]}),x.tripCreditDescription&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:x.tripCreditDescription})]}),(x.pinEligibleCount??0)>0&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-purple-50/80 border border-purple-200 dark:bg-purple-950/20 dark:border-purple-800/40","data-testid":"chain-pin-eligible-tile",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(se,{className:"w-4 h-4 text-purple-600 dark:text-purple-400"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Pin Eligible"}),(G==null?void 0:G.pinCountSource)==="slant_brain"&&e.jsx("span",{className:"text-[10px] font-semibold px-1 py-0.5 rounded bg-purple-200 dark:bg-purple-800/60 text-purple-700 dark:text-purple-300 ml-0.5",children:"AI"})]}),G?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xl font-bold text-purple-600 dark:text-purple-400",children:G.userEarned?`#${G.userRank}`:(G.slotsRemaining??0)>0?`${G.slotsRemaining} left`:"Full"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:G.userEarned?"You are pin eligible":`of ${G.slotsTotal} travelers`})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xl font-bold text-purple-600 dark:text-purple-400",children:x.pinEligibleCount}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"eligibility spots"})]}),Ee&&(G==null?void 0:G.pinCountSource)==="slant_brain"&&e.jsx("button",{onClick:Nt.mutate,disabled:Nt.isPending,className:"mt-2 text-[10px] font-medium text-purple-600 dark:text-purple-400 underline underline-offset-2 hover:text-purple-800 dark:hover:text-purple-200 disabled:opacity-50","data-testid":"button-recalibrate-pin",children:Nt.isPending?"Recalibrating...":"Recalibrate"})]}),x.cashDropEnabled&&(x.poolValueCents??0)>0&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-pool-value",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(We,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Prize Pool"})]}),e.jsxs("div",{className:"text-xl font-bold text-amber-600 dark:text-amber-400",children:["$",(x.poolValueCents/100).toLocaleString(void 0,{minimumFractionDigits:2})]})]}),x.eventName&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-event-name",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(De,{className:"w-4 h-4 text-purple-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Event"})]}),e.jsx("div",{className:"text-sm font-semibold truncate",children:x.eventName})]}),x.bookingWindowStart&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-booking-window",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(Ya,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Booking Window"})]}),e.jsxs("div",{className:"text-xs font-medium",children:[new Date(x.bookingWindowStart).toLocaleDateString(),x.bookingWindowEnd&&` – ${new Date(x.bookingWindowEnd).toLocaleDateString()}`]})]}),(x.activeTravelerCount??0)>0&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-traveler-count",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(_e,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Active Travelers"})]}),e.jsx("div",{className:"text-xl font-bold",children:x.activeTravelerCount.toLocaleString()})]}),(x.pointsRequired??0)>0&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-points-required",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(he,{className:"w-4 h-4 text-yellow-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Points Required"})]}),e.jsx("div",{className:"text-xl font-bold",children:x.pointsRequired.toLocaleStr
22ing()})]}),x.cashDropEnabled&&x.pinDropStatus&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-pin-status",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(se,{className:"w-4 h-4 text-red-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Pin Drop"})]}),e.jsx(T,{variant:"outline",className:"text-xs capitalize",children:x.pinDropStatus})]}),x.smsChainCategory&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-sms-category",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(ot,{className:"w-4 h-4 text-blue-400"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Signal Type"})]}),e.jsx(T,{variant:"secondary",className:"text-xs capitalize",children:x.smsChainCategory})]}),x.urgencyLevel&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-urgency-level",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(he,{className:"w-4 h-4 text-orange-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Urgency"})]}),e.jsx(T,{variant:"outline",className:"text-xs capitalize",children:x.urgencyLevel})]}),x.locationRequired&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-location-required",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(Navigation,{className:"w-4 h-4 text-teal-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"GPS Required"})]}),e.jsx(T,{className:"text-xs bg-teal-500/10 text-teal-600 border-teal-400",children:"Required"})]}),(x.smsStartsAt||x.smsEndsAt)&&e.jsxs("div",{className:"text-center p-3 rounded-lg bg-background/80 border","data-testid":"chain-sms-window",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1 mb-1",children:[e.jsx(Bell,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Signal Window"})]}),e.jsxs("div",{className:"text-xs font-medium",children:[x.smsStartsAt?new Date(x.smsStartsAt).toLocaleDateString():"—",x.smsEndsAt?` – ${new Date(x.smsEndsAt).toLocaleDateString()}`:""]})]})]})]}),Ee&&a&&e.jsxs("div",{className:"mb-6 flex items-center justify-between gap-3 p-4 rounded-lg border border-dashed border-primary/40 bg-primary/5","data-testid":"partner-offer-cta",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Add a Partner Offer"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Attach a sponsor deal, drop reward, or affiliate placement to this chain."})]}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>Yt(!0),"data-testid":"button-add-partner-offer",children:[e.jsx(he,{className:"w-4 h-4 mr-1"}),"Add Offer"]})]}),a&&e.jsx(bi,{chainId:a,city:((Ns=C==null?void 0:C.thread)==null?void 0:Ns.destinationCity)??""}),(C==null?void 0:C.thread)&&e.jsx("div",{className:"mb-8",children:e.jsx(er,{campaignId:C.thread.campaignId,chainId:C.thread.id})}),E&&a&&e.jsx("div",{className:"mb-6",children:e.jsx(zr,{chainId:a})}),E&&a&&(Re!=null&&Re.unlocked)&&((ys=Re.assets)!=null&&ys.length)?e.jsxs(z,{className:"mb-8 border-emerald-200 dark:border-emerald-800","data-testid":"activation-content-section",children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"flex items-center gap-2 text-base",children:[e.jsx(qs,{className:"w-5 h-5 text-emerald-600"}),"Ferrol activation content",e.jsx(T,{variant:"secondary",className:"ml-auto",children:"Unlocked"})]}),e.jsx(ce,{children:"Tournament schedule and supplied Meninas de Canido artist profiles for chain members."})]}),e.jsx(K,{className:"space-y-3",children:Re.assets.map(s=>e.jsxs("div",{className:"rounded-lg border p-3","data-testid":`activation-asset-${s.assetKey}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.fileName})]}),e.jsx("a",{href:s.downloadUrl,download:!0,children:e.jsxs(w,{size:"sm",variant:"outline",children:[e.jsx($t,{className:"w-3.5 h-3.5 mr-1"}),"Download"]})})]}),s.content&&e.jsxs("details",{className:"mt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-medium text-primary",children:"Read profile"}),e.jsx("pre",{className:"mt-2 max-h-80 overflow-auto whitespace-pre-wrap font-sans text-xs text-muted-foreground",children:s.content})]})]},s.id))})]}):fa&&E?e.jsx(z,{className:"mb-8","data-testid":"activation-content-loading",children:e.jsx(K,{className:"py-6",children:e.jsx(xe,{className:"h-5 w-48"})})}):null,a&&e.jsxs(z,{className:"mb-8","data-testid":"chain-merch-section",children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"flex items-center gap-2 text-base",children:[e.jsx(ia,{className:"w-5 h-5 text-primary"}),"Merch"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"On-demand fan gear — ordered here, drop-shipped by ArringtonRose directly to you"})]}),e.jsx(K,{children:e.jsx(Yr,{chainId:a})})]}),je&&je.goals.length>0&&e.jsxs(z,{className:"mb-8 border-pink-200 dark:border-pink-800 bg-gradient-to-br from-pink-50/50 to-purple-50/50 dark:from-pink-950/20 dark:to-purple-950/20","data-testid":"chain-impact-section",children:[e.jsxs(Z,{children:[e.jsxs(X,{className:"flex items-center gap-2 text-pink-700 dark:text-pink-400",children:[e.jsx(st,{className:"w-5 h-5"}),"Philanthropic Impact"]}),e.jsx(ce,{children:"The creator of this chain is driving economic value toward meaningful causes"})]}),e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-2",children:[e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-white/60 dark:bg-slate-800/60 border","data-testid":"impact-total-value",children:[e.jsxs("div",{className:"text-2xl font-bold text-pink-600 dark:text-pink-400",children:["$",(je.totalImpactCents/100).toLocaleStr
22ing(void 0,{minimumFractionDigits:2})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Impact Generated"})]}),e.jsxs("div",{className:"text-center px-4 py-2 rounded-lg bg-white/60 dark:bg-slate-800/60 border",children:[e.jsx("div",{className:"text-2xl font-bold text-purple-600 dark:text-purple-400","data-testid":"impact-goal-count",children:je.totalGoals}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Active Goals"})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:je.goals.map(s=>e.jsxs("div",{className:"rounded-lg border bg-white/80 dark:bg-slate-800/40 p-4","data-testid":`impact-goal-card-${s.id}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-semibold text-sm truncate",children:s.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.beneficiaryName," · ",s.beneficiaryType.replace("_"," ")]})]}),s.isActive&&e.jsx(T,{variant:"outline",className:"text-xs text-green-600 border-green-300 dark:text-green-400 dark:border-green-700 shrink-0 ml-2",children:"Active"})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mb-2 line-clamp-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1 text-pink-600 dark:text-pink-400",children:[e.jsx(Kt,{className:"w-3 h-3"}),e.jsxs("span",{className:"font-medium",children:["$",(s.summary.totalRaisedCents/100).toLocaleString(void 0,{minimumFractionDigits:2})]}),e.jsx("span",{className:"text-muted-foreground",children:"raised"})]}),e.jsxs("span",{className:"text-muted-foreground",children:[s.summary.entryCount," transactions"]})]}),s.targetAmountCents&&s.summary.progressPercent!==null&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Progress"}),e.jsxs("span",{className:"font-medium",children:[s.summary.progressPercent,"%"]})]}),e.jsx(ct,{value:s.summary.progressPercent,className:"h-1.5"})]})]},s.id))}),Le&&e.jsx("div",{className:"flex justify-end",children:e.jsx(be,{href:`/impact/${Le}`,children:e.jsxs(w,{variant:"ghost",size:"sm",className:"text-pink-600 dark:text-pink-400 hover:text-pink-700 dark:hover:text-pink-300","data-testid":"link-view-impact-portfolio",children:[e.jsx(st,{className:"w-3.5 h-3.5 mr-1"}),"View Full Impact Portfolio"]})})})]})]}),e.jsxs(z,{className:"mb-8",id:"chat","data-testid":"chain-chat-section",children:[e.jsxs(Z,{className:"pb-2",children:[e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(ot,{className:"w-4 h-4"}),x!=null&&x.title?`${x.title} Member Chat`:"Chain Member Chat",M>0&&e.jsx(T,{className:"bg-red-500 text-white text-xs px-1.5 py-0.5 min-w-[20px] text-center animate-pulse","data-testid":"badge-chat-unread",children:M>99?"99+":M})]}),e.jsxs(ce,{children:["An exclusive closed network for ",(x==null?void 0:x.title)??"this chain"," participants — connect with fellow members to discuss your journey and experience. No account required.",M>0&&e.jsxs("button",{className:"ml-2 text-primary underline text-xs font-medium",onClick:()=>{var s;return(s=document.getElementById("chat"))==null?void 0:s.scrollIntoView({behavior:"smooth"})},"data-testid":"button-scroll-to-chat",children:[M," new message",M!==1?"s":""]})]})]}),e.jsx(K,{className:"p-0 pt-0",children:a&&x&&e.jsx(pr,{chainId:a,chainTitle:x.title,onUnreadCount:U})})]}),Fe&&e.jsxs(z,{className:"mb-8 border-amber-300 dark:border-amber-700 bg-gradient-to-br from-amber-50/60 to-transparent dark:from-amber-950/20","data-testid":"fan-certificate-section",children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"}),"Certificate of Completion"]}),e.jsx(ce,{children:"You've completed all stops on this Going. Your verified certificate is ready to view and share."})]}),e.jsxs(K,{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx(be,{href:`/certificate/${Fe.certificateId}`,className:"flex-1",children:e.jsxs(w,{className:"w-full bg-amber-500 hover:bg-amber-400 text-black font-semibold gap-2","data-testid":"button-view-certificate",children:[e.jsx(De,{className:"w-4 h-4"}),"View Certificate",e.jsx(ie,{className:"w-3.5 h-3.5 ml-auto opacity-70"})]})}),e.jsxs(w,{variant:"outline",className:"flex-1 sm:flex-none gap-2 border-amber-400/60 text-amber-700 dark:text-amber-400 hover:bg-amber-50 dark:hover:bg-amber-950/30","data-testid":"button-share-certificate",onClick:()=>{var u;const s=`${window.location.origin}/certificate/${Fe.certificateId}`;navigator.share?navigator.share({title:`I completed ${Fe.chainTitle} · Slant`,url:s}):((u=navigator.clipboard)==null||u.writeText(s),q({title:"Link copied!",description:"Certificate link copied to clipboard."}))},children:[e.jsx(Ve,{className:"w-4 h-4"}),"Share"]})]})]}),Ct&&Ie&&e.jsxs(z,{className:"mb-8 border-emerald-200 dark:border-emerald-800","data-testid":"settlement-certificate-section",children:[e.jsxs(Z,{className:"pb-3",children:[e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4 text-emerald-600 dark:text-emerald-400"}),"Attribution Certificate"]}
22),e.jsx(ce,{children:"Cryptographically signed record of every interaction on this chain. Independently verifiable by any party."})]}),e.jsxs(K,{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-1.5",children:[e.jsx(Nr,{className:"w-3.5 h-3.5"}),"State hash"]}),e.jsx("code",{className:"font-mono text-xs bg-background px-2 py-0.5 rounded border truncate max-w-[220px]","data-testid":"text-state-hash",children:Ie.stateHash?`${Ie.stateHash.slice(0,24)}…`:"No hash yet"})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Events recorded"}),e.jsx("span",{className:"font-medium","data-testid":"text-event-count",children:Ie.eventCount??0})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Integrity"}),e.jsx(T,{variant:"outline",className:(ws=Ie.integrity)!=null&&ws.valid?"border-emerald-500 text-emerald-600 dark:text-emerald-400":"border-red-500 text-red-600 dark:text-red-400","data-testid":"badge-integrity-status",children:(ks=Ie.integrity)!=null&&ks.valid?"✓ Intact":"⚠ Tampered"})]})]}),fe?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-200 dark:border-emerald-800 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-emerald-700 dark:text-emerald-400 font-medium text-sm",children:[e.jsx(De,{className:"w-4 h-4"}),"Settlement Certificate Issued"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{className:"bg-background rounded p-2",children:[e.jsx("div",{className:"text-lg font-bold","data-testid":"cert-total-scans",children:fe.stats.totalScans}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Scans"})]}),e.jsxs("div",{className:"bg-background rounded p-2",children:[e.jsx("div",{className:"text-lg font-bold","data-testid":"cert-total-claims",children:fe.stats.totalClaims}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Claims"})]}),e.jsxs("div",{className:"bg-background rounded p-2",children:[e.jsx("div",{className:"text-lg font-bold","data-testid":"cert-total-redemptions",children:fe.stats.totalRedemptions}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Redemptions"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Settled ",new Date(fe.settledAt).toLocaleDateString()," · ",fe.platform]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{size:"sm",variant:"outline",onClick:Sa,"data-testid":"button-download-cert",className:"flex-1",children:[e.jsx($t,{className:"w-3.5 h-3.5 mr-1.5"}),"Download Certificate"]}),e.jsxs(w,{size:"sm",variant:"ghost",onClick:()=>window.open(`/api/chains/${a}/verify-certificate`,"_blank"),"data-testid":"button-verify-cert",children:[e.jsx(ie,{className:"w-3.5 h-3.5 mr-1.5"}),"Verify"]})]})]}):Ee?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Settling closes the chain and generates a signed certificate you can share with partners, brands, or auditors as proof of attribution."}),e.jsx(w,{size:"sm",onClick:()=>St.mutate(),disabled:St.isPending||(x==null?void 0:x.status)==="completed","data-testid":"button-settle-chain",className:"w-full",children:St.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Generating certificate…"]}):e.jsxs(e.Fragment,{children:[e.jsx(qs,{className:"w-3.5 h-3.5 mr-1.5"}),"Settle Chain & Issue Certificate"]})})]}):null]})]}),(ee==null?void 0:ee.hasActiveCampaign)&&ee.campaignId&&a&&e.jsxs("div",{className:"mb-8 space-y-4","data-testid":"chain-reports-section",children:[e.jsx(Er,{chainId:a,campaignId:ee.campaignId,campaignName:ee.campaignName}),e.jsx(Or,{chainId:a,campaignId:ee.campaignId,campaignName:ee.campaignName,creatorId:Le||void 0})]}),e.jsxs(z,{className:"mb-8",children:[e.jsxs(Z,{children:[e.jsx(X,{className:"flex items-center gap-2",children:H?e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"w-5 h-5 text-purple-600"}),"Spider Chain Hub"]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"w-5 h-5"}),"Chain Journey Map"]})}),e.jsx(ce,{children:H?"View the hub-and-spoke pattern with branches radiating from the central location":"Follow the path this chain has traveled across the world"})]}),e.jsx(K,{children:H?_?e.jsx(xi,{spiderPath:_,selectedBranchId:m,onBranchClick:i,onMapReady:N}):e.jsx(xe,{className:"h-[400px] w-full rounded-lg"}):te?e.jsx(mi,{chainPath:te,selectedNodeId:o,onNodeClick:ls,onMapReady:N}):e.jsx(xe,{className:"h-[400px] w-full rounded-lg"})})]}),ma&&a&&l&&e.jsx(qr,{chainId:a,mapInstance:l}),e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-xl font-semibold mb-4 flex items-center gap-2",children:H?e.jsxs(e.Fragment,{children:[e.jsx(Ot,{className:"w-5 h-5"}),"Branch Journeys"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ms,{className:"w-5 h-5"}),"Chain Timeline"]})}),H?_?e.jsx(ui,{spiderPath:_,selectedBranchId:m,onBranchSelect:i}):e.jsx(xe,{className:"h-48 w-full rounded-lg"}):te?e.jsx(fi,{chainPath:te,selectedNodeId:o,onNodeSelect:ls,currentUserId:E==null?void 0:E.id,chainId:a||""}):e.jsx(xe,{className:"h-48 w-full rounded-lg"})]}),ds.length>0&&e.jsxs(z,{className:"mb-8 border-green-200 dark:border-green-800 bg-green-50/50 dark:bg-green-950/20",children:[e.jsxs(Z,{children:[e.jsxs(X,{className:"flex items-center gap-2 text-green-700 dark:text-green-400",children:[e.jsx(Mt,{className:"w-5 h-5"}),"Open Challenges"]}),e.jsx(ce,{children:"These challenges are waiting for someone to accept and continue the journey"})]}),e.jsx(K,{children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:ds.map(s=>{var u,R;return e.jsxs(z,{className:"border-green-200 dark:border-green-800",children:[e.jsxs(Z,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(T,{className:"bg-green-100 text-green-700",children:[e.jsx(Mt,{className:"w-3 h-3 mr-1"}),"Open"]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["#",s.nodeOrder]})]}),e.jsx(X,{className:"text-lg",children:s.challengeTitle}),e.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[e.jsx(se,{className:"w-3.5 h-3.5"}),s.locationName,s.country&&`, ${s.country}`]})]}),e.jsxs(K,{children:[s.storyContent&&e.jsx("p",{className:"text-sm text-muted-foreground mb-4 line-clamp-3",children:s.storyContent}),((u=s.challengeRequirements)==null?void 0:u.cityType)==="world_cup_host"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:s.challengeRequirements.note}),s.challengeRequirements.stops.map((F,J)=>e.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/30 px-3 py-2.5","data-testid":`stop-card-${s.id}-${J}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium leading-tight line-clamp-1",children:F.name}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 mt-0.5",children:F.description})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1 shrink-0",children:[e.jsx("span",{className:`text-xs font-semibold px-1.5 py-0.5 rounded ${F.providerType==="free"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":F.providerType==="getyourguide"?"bg-orange-500/10 text-orange-600 dar
22k:text-orange-400":F.providerType==="bookingcom"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-muted text-muted-foreground"}`,children:F.priceDisplay}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:F.provider})]})]}),F.affiliateUrl&&e.jsxs("a",{href:F.affiliateUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-2 flex items-center gap-1 text-xs text-primary hover:underline","data-testid":`stop-book-${s.id}-${J}`,children:["Book now ",e.jsx(ie,{className:"w-3 h-3"})]})]},J)),e.jsxs(w,{className:"w-full mt-2","data-testid":`checkin-city-${s.id}`,onClick:()=>os(s.id),children:[e.jsx(se,{className:"w-4 h-4 mr-2"}),"Check In at ",s.challengeRequirements.hostCity]})]}):(R=s.challengeRequirements)!=null&&R.isEventStop?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.challengeRequirements.note||"Get your ticket for this event stop. It will be saved in your wallet."}),e.jsx("a",{href:s.challengeRequirements.ticketUrl?`${s.challengeRequirements.ticketUrl}?utm_source=slant&utm_medium=chain&utm_campaign=${a}&slant_chain=${a}&slant_stop=${s.id}`:`/wallet?tab=tickets&chain=${a}&stop=${s.id}`,target:s.challengeRequirements.ticketUrl?"_blank":"_self",rel:"noopener noreferrer",className:"block",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"ticket_partner",partnerName:s.challengeRequirements.ticketProvider||"Ticket Partner",bookingType:"ticket",chainId:a,nodeId:s.id,destination:s.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{className:"w-full bg-amber-500 hover:bg-amber-400 text-black font-semibold","data-testid":`get-ticket-detail-${s.id}`,children:[e.jsx(Xs,{className:"w-4 h-4 mr-2"}),s.challengeRequirements.ticketCta||"Get Ticket",e.jsx(ie,{className:"w-3 h-3 ml-2 opacity-70"})]})}),s.challengeRequirements.ticketProvider&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:["via ",s.challengeRequirements.ticketProvider]})]}):s.contextType==="booking"&&s.challengeRequirements?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.challengeRequirements.note||"Book your travel for this event."}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("a",{href:s.challengeRequirements.flightSearchUrl||"/flights",target:"_blank",rel:"noopener noreferrer",className:"block",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"skyscanner",partnerName:"Skyscanner",bookingType:"flight",chainId:a,nodeId:s.id,destination:s.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{className:"w-full","data-testid":`book-flights-detail-${s.id}`,children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),s.challengeRequirements.flightCta||"Search Flights"]})}),e.jsx("a",{href:s.challengeRequirements.hotelsUrl||`/bookings?tab=live-search&city=${encodeURIComponent(s.city||s.locationName||"")}`,target:"_blank",rel:"noopener noreferrer",className:"block",onClick:()=>{Q("POST","/api/affiliate/record-booking",{partnerId:"hotels",partnerName:"Hotels",bookingType:"hotel",chainId:a,nodeId:s.id,destination:s.locationName,clickedAt:new Date().toISOString()}).catch(()=>{})},children:e.jsxs(w,{variant:"outline",className:"w-full","data-testid":`book-hotels-detail-${s.id}`,children:[e.jsx(ea,{className:"w-4 h-4 mr-2"}),s.challengeRequirements.hotelCta||"Find Hotels",e.jsx(ie,{className:"w-3 h-3 ml-1 opacity-60"})]})})]})]}):e.jsx(w,{className:"w-full","data-testid":`accept-challenge-${s.id}`,onClick:()=>os(s.id),children:H?"Start Branch Journey":"Accept This Challenge"})]})]},s.id)})})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs(z,{children:[e.jsx(Z,{children:e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(_e,{className:"w-4 h-4"}),"Contributors (",Oe.length,")"]})}),e.jsx(K,{children:e.jsxs("div",{className:"space-y-3",children:[Oe.slice(0,5).map(({id:s,user:u})=>{var R,F,J;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(it,{className:"w-8 h-8",children:[e.jsx(nt,{src:(u==null?void 0:u.profileImageUrl)||void 0}),e.jsxs(lt,{className:"text-xs",children:[((R=u==null?void 0:u.firstName)==null?void 0:R[0])||
22((F=u==null?void 0:u.alias)==null?void 0:F[0])||"?",((J=u==null?void 0:u.lastName)==null?void 0:J[0])||""]})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("p",{className:"text-sm font-medium truncate",children:[(u==null?void 0:u.firstName)||(u==null?void 0:u.alias)||"Slant member",u!=null&&u.lastName?` ${u.lastName}`:""]})})]},s)}),Oe.length>5&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["+",Oe.length-5," more"]})]})})]}),e.jsxs(z,{children:[e.jsx(Z,{children:e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(At,{className:"w-4 h-4"}),"Countries Visited"]})}),e.jsx(K,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[It.map(s=>e.jsx(T,{variant:"secondary",children:s},s)),It.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No countries recorded yet"})]})})]}),e.jsxs(z,{children:[e.jsx(Z,{children:e.jsxs(X,{className:"text-base flex items-center gap-2",children:[e.jsx(Ut,{className:"w-4 h-4"}),"Followers (",Te.length,")"]})}),e.jsxs(K,{children:[e.jsxs("div",{className:"flex -space-x-2 overflow-hidden",children:[Te.slice(0,8).map(({id:s,user:u})=>{var R,F,J;return e.jsxs(it,{className:"w-8 h-8 border-2 border-background",children:[e.jsx(nt,{src:(u==null?void 0:u.profileImageUrl)||void 0}),e.jsxs(lt,{className:"text-xs",children:[((R=u==null?void 0:u.firstName)==null?void 0:R[0])||((F=u==null?void 0:u.alias)==null?void 0:F[0])||"?",((J=u==null?void 0:u.lastName)==null?void 0:J[0])||""]})]},s)}),Te.length>8&&e.jsxs("div",{className:"w-8 h-8 rounded-full bg-muted flex items-center justify-center text-xs border-2 border-background",children:["+",Te.length-8]})]}),Te.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No followers yet"})]})]})]})]}),gt&&gt.chains.length>0&&e.jsxs("div",{className:"px-4 pb-6",children:[e.jsx("h3",{className:"text-base font-semibold mb-3 text-foreground",children:"Other chains you can join"}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 snap-x snap-mandatory scrollbar-hide",children:gt.chains.map(({thread:s,creator:u})=>e.jsx(be,{href:`/chains/${s.id}`,className:"block flex-shrink-0 snap-start",children:e.jsxs("div",{className:"w-48 rounded-xl border border-border bg-card hover:bg-accent transition-colors overflow-hidden",children:[s.coverImageUrl?e.jsx("img",{src:s.coverImageUrl,alt:s.title,className:"w-full h-24 object-cover"}):e.jsx("div",{className:"w-full h-24 bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center",children:e.jsx(At,{className:"w-6 h-6 text-primary/40"})}),e.jsxs("div",{className:"p-2.5",children:[e.jsx("p",{className:"text-xs font-medium text-foreground line-clamp-2 leading-snug",children:s.title}),s.visibility==="unlisted"&&e.jsx("span",{className:"inline-block mt-1 text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:"Unlisted"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:(u==null?void 0:u.firstName)??"Anonymous"})]})]})},s.id))})]}),e.jsx(mr,{open:r,onOpenChange:h,mode:"continue",existingChainId:a,existingNodeId:f,existingChainType:H?"spider":"linear",locationName:(x==null?void 0:x.originLocationName)||void 0,latitude:(x==null?void 0:x.originLatitude)||void 0,longitude:(x==null?void 0:x.originLongitude)||void 0,hasActiveCampaign:ee==null?void 0:ee.hasActiveCampaign,campaignName:ee==null?void 0:ee.campaignName,campaignEndDate:ee==null?void 0:ee.campaignEndDate,onSuccess:async()=>{h(!1),V.invalidateQueries({queryKey:["/api/chains",a]});try{const s=await fetch(`/api/chain-certificates/mine/${a}`,{credentials:"include"});if(s.ok){const u=await s.json();if(u!=null&&u.certificate){Xt(u.certificate),V.setQueryData(["/api/chain-certificates/mine",a],u);const R=await fetch(`/api/chains/${a}/reward-status`,{credentials:"include"});R.ok&&V.setQueryData(["/api/chains",a,"reward-status"],await R.json())}}}catch{}}}),Zt&&e.jsx(ni,{certificate:Zt,rewardCredits:(Se==null?void 0:Se.earnedCredits)??0,gifted:(Se==null?void 0:Se.gifted)??!1,onGift:async()=>{await Q("POST",`/api/chains/${a}/reward/gift`),V.setQueryData(["/api/chains",a,"reward-status"],s=>({...s,gifted:!0}))},onDismiss:()=>Xt(null)}),ht&&!ge&&E&&e.jsx("div",{"data-testid":"safety-auto-prompt",className:"fixed bottom-24 left-4 right-4 max-w-sm mx-auto z-40 bg-[#0d1f3c] border border-blue-500/40 rounded-2xl p-4 shadow-2xl",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-500/20 rounded-lg flex-shrink-0",children:e.jsx(tt,{className:"w-5 h-5 text-blue-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-white font-semibold text-sm",children:"Safety mode available"}),e.jsx("p",{className:"text-gray-400 text-xs mt-0.5 leading-relaxed",children:"This trip is active. Slant can quietly share your location with trusted contacts and alert them if you miss a check-in."}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(w,{size:"sm","data-testid":"button-enable-safety",onClick:()=>{ut(!1),bt.mutate()},disabled:bt.isPending,className:"bg-blue-600 hover:bg-blue-700 text-white text-xs",children:bt.isPending?"Activating…":"Enable Safety Mode"}),e.jsx(w,{size:"sm",variant:"ghost","data-testid":"button-dismiss-safety-prompt",onClick:()=>{ut(!1),da(!0)},className:"text-gray-400 hover:text-white text-xs",children:"Dismiss"})]})]})]})}),ge&&E&&e.jsx("div",{"data-testid":"emergency-button-pill",className:"fixed bottom-6 right-4 z-50 bg-[#0a1628]/90 backdrop-blur border border-white/10 rounded-full px-4 py-2 shadow-xl",children:e.jsx(fr,{currentRoute:{id:a||void 0,destination:((Cs=C==null?void 0:C.thread)==null?void 0:Cs.destinationCity)||
22((Ss=C==null?void 0:C.thread)==null?void 0:Ss.title)||void 0}})}),e.jsx(ur,{chainId:a,variant:"floating",size:"md"}),a&&e.jsx($r,{open:Je,onOpenChange:Yt,chainId:a,cashDropEnabled:(x==null?void 0:x.cashDropEnabled)??!1})]}):e.jsx(Qs,{})}export{il 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.