PageSourceSearch

https://www.carbonarc.ai/assets/exchange-builder-DGwoNE36.js

js carbonarc.ai collected 2026-09-25 18:16:42 UTC 80,985 bytes, 1 lines download raw bytes

1import{r as a,j as e}from"./vendor-react-CF2OuAXi.js";import{b as Ge,g as as,a as os}from"./vendor-router-1lxCfBys.js";import{B as ye}from"./Button-_45-WKGL.js";import{i as Ce,u as is}from"./ExchangeUsernameCard-Dg44cf7G.js";import{b as Ue,u as ls,a as he}from"./vendor-query-Dru8Ryjt.js";import{w as Fe,s as Ae,x as cs,y as it,u as ds,z as us,A as ms,e as gs,j as vt,B as Pe,a as fs,b as xs}from"./utils-CWIC0ptc.js";import{a as ps,E as hs,b as bs}from"./EmptyState-DSMSng6_.js";import{c as He}from"./castArray-BQszfGim.js";import{b as ys}from"./frameworks-DHD0uULy.js";import{_ as Q,f as be,H as wt,a as de,t as js,L as Nt,C as vs,h as $e,P as ws,i as Ns,j as ks,g as Ss,u as _s,b as Cs}from"./index-CQwFLP6K.js";import{p as Es,m as Fs,F as As}from"./signals-0Uk-EUfk.js";import{H as Ps,a as Ms}from"./index-B7nQdxAG.js";import{C as lt}from"./ConfirmModal-DXcH9w9D.js";import{a as Me,e as kt,B as ct,L as St,f as Os,T as Is}from"./vendor-flowbite-BOOFXkYC.js";import"./vendor-datadog-tM0hMiRH.js";import"./vendor-okta-DqkOGBPB.js";import{T as Ds}from"./constants-DdUlFUkc.js";import{u as Ts}from"./useActiveTickers-DCW8E6sI.js";import{C as ke}from"./card-Y19Mh3p_.js";import{T as me}from"./TokenCount-CVBAWPg6.js";import{F as Ls}from"./index-DZUZnGf6.js";import{S as Rs}from"./sliders-horizontal-BRCH5_Fq.js";import{C as $s}from"./chevron-right-nK9qNL-G.js";import{X as Bs}from"./x-lJhSzwDa.js";import{a as zs,E as Us}from"./ExpandableTagContainer-Cw_FYWO_.js";import{C as dt}from"./CarbonArcTokenIcon-CS15NI2n.js";import{R as Hs}from"./index-LRFYptvQ.js";import{T as qs}from"./index-DIqXhkv4.js";import{I as Ws}from"./info-CxKaq-GJ.js";import{E as Ks}from"./eye-BPknMh8C.js";import{A as ut}from"./arrow-left-vV9ujQcc.js";import{T as Gs}from"./trash-2-BKNP0UNb.js";import{S as Qs}from"./save-B0Adjhmi.js";import{A as Vs}from"./arrow-right-DV_ZYJFz.js";import"./loader-circle-BvRstAWX.js";import"./compact-DeU34Yoy.js";import"./user-round-C_TS0Z2-.js";import"./vendor-i18n-D8V0Brmg.js";import"./index-q_BE_MGP.js";import"./popover-BjyErPET.js";import"./Combination-CYOxzfla.js";import"./Table-B0Ps1mIS.js";import"./Skeleton-BRGF7VwU.js";import"./NoDataDisplay-CXnnx2lc.js";import"./triangle-alert-qrivgvDV.js";import"./file-text-Cttx8El0.js";import"./chevron-down-BMfo5y9F.js";import"./map-pin-Br3vNlUM.js";import"./calendar-BGe_Ftr_.js";import"./clock-DNIHwrSo.js";import"./dayjs.min-CcXI944o.js";import"./useUserBalance-5NCzWez8.js";import"./formatters-CRHT1J-5.js";import"./chevron-up-x3gQw7nv.js";const Zs=({urlFrameworkIds:t,isEditMode:n,isResumingDraft:s,tags:l})=>{const[i,c]=a.useState([]),[g,x]=a.useState([]),[F,p]=a.useState(!1),[m,d]=a.useState(1),[f,r]=a.useState([]),[u,h]=a.useState(!0),[b,w]=a.useState(!1),[A,L]=a.useState({}),P=a.useRef(new Set),[S,R]=a.useState(""),[O,$]=a.useState(""),[o,_]=a.useState({}),N=a.useRef(!1),D=a.useRef([]),y=a.useRef(null);a.useEffect(()=>{const k=setTimeout(()=>$(S),300);return()=>clearTimeout(k)},[S]),a.useEffect(()=>{r([]),!n&&!s&&D.current.length>0&&!y.current&&(c(D.current),D.current=[]),d(1),h(!0),w(!1)},[O,n,s]);const{data:I,isLoading:B}=Ue({queryKey:["my-exchange-frameworks-by-ids",t],queryFn:()=>{const k=(t==null?void 0:t.split(",").filter(Boolean))??[];return Fe({notInSignal:!1,page:1,pageSize:Math.max(k.length,5),frameworkIds:k})},enabled:!!t&&t.length>0,staleTime:0,select:k=>{var T;return{...k,items:(T=k==null?void 0:k.items)==null?void 0:T.map(v=>{var z;return{...v,spec:{...v==null?void 0:v.spec,entities:He(((z=v==null?void 0:v.spec)==null?void 0:z.entities)??[])}}})}}}),{data:j,isLoading:M,isFetching:C,isError:E,refetch:q}=Ue({queryKey:["my-exchange-frameworks",F,m,O],queryFn:()=>Fe({notInSignal:F,page:m,pageSize:5,search:O||void 0}),staleTime:0,select:k=>{var T;return{...k,items:(T=k==null?void 0:k.items)==null?void 0:T.map(v=>{var z;return{...v,spec:{...v==null?void 0:v.spec,entities:He(((z=v==null?void 0:v.spec)==null?void 0:z.entities)??[])}}})}}}),{data:re}=ps();a.useEffect(()=>{if(!(j!=null&&j.items))return;const{items:k,total:T}=j;r(v=>{if(m===1)return h(k.length<T),k;const z=new Set(v.map(ae=>ae.framework_id)),U=k.filter(ae=>!z.has(ae.framework_id)),J=U.length>0?[...v,...U]:v;return h(J.length<T),J})},[j,m]),a.useEffect(()=>{C||w(!1)},[C]);const se=a.useMemo(()=>I!=null&&I.items?I.items.map(k=>({...k,purchased_at:""})):[],[I]),Z=a.useMemo(()=>{const k=[...se,...g],T=new Set,v=k.filter(ee=>T.has(ee.framework_id)?!1:(T.add(ee.framework_id),!0)),z=f.filter(ee=>!T.has(ee.framework_id)),U=[...v,...z],J=new Set(U.map(ee=>ee.framework_id)),ae=i.filter(ee=>!J.has(ee)&&o[ee]).map(ee=>o[ee]);return ae.length>0?[...U,...ae]:U},[f,se,g,i,o]);a.useEffect(()=>{i.length!==0&&_(k=>{let T=!1;const v={...k};for(const z of i){if(v[z])continue;const U=Z.find(J=>J.framework_id===z);U&&(v[z]=U,T=!0)}return T?v:k})},[i,Z]);const ge=a.useMemo(()=>Object.keys(A).length===0?Z:Z.map(k=>{const T=A[k.framework_id];return T?{...k,unit_price:T}:k}),[Z,A]);a.useEffect(()=>{const k=P.current,T=Z.filter(v=>Ae(v.unit_price)===0&&!k.has(v.framework_id)).map(v=>v.framework_id);T.length!==0&&(T.forEach(v=>k.add(v)),cs(T).then(v=>{const z={};
1v.items.forEach(U=>{U.price!==null&&(z[U.framework_id]=U.price)}),Object.keys(z).length>0&&L(U=>({...U,...z}))}).catch(v=>{console.error("Failed to recalculate framework prices:",v),T.forEach(z=>k.delete(z))}))},[Z]),a.useEffect(()=>{if(!t){y.current=null;return}if(t===y.current)return;const k=t.split(",").filter(Boolean);k.length>0&&(N.current=!0,c(k),D.current=k,y.current=t)},[t]);const ne=a.useMemo(()=>new Set(i.flatMap(k=>{const T=Z.find(v=>v.framework_id===k);return(T==null?void 0:T.suggested_tags)??[]})),[i,Z]),W=a.useMemo(()=>i.length===0?l:l.filter(k=>ne.has(k)),[l,ne,i.length]),X=a.useMemo(()=>i.length===0?0:i.reduce((k,T)=>{const v=ge.find(z=>z.framework_id===T);return k+Ae(v==null?void 0:v.unit_price)},0),[i,ge]),ie=a.useMemo(()=>{var T;if(i.length===0)return 0;const k=new Set;for(const v of i){const z=Z.find(J=>J.framework_id===v),U=(T=z==null?void 0:z.spec)==null?void 0:T.entities;if(Array.isArray(U))for(const J of U)J.carc_id!=null&&k.add(J.carc_id)}return k.size},[i,Z]),G=a.useMemo(()=>{const k=new Map;for(const T of i){const v=Z.find(z=>z.framework_id===T);if(v!=null&&v.related_dataassets)for(const z of v.related_dataassets){const U=z.dataset_tag||z.dataset_name.toLowerCase().replace(/\s+/g,"-").replace(/[^\w-]/g,"");ne.has(U)&&k.set(U,z.dataset_name)}}return k},[i,Z,ne]),H=a.useMemo(()=>{if(i.length===0)return[];const k=new Set(ne),T=new Map;for(const v of re??[])k.has(v.key)&&T.set(v.key,v.title);for(const[v,z]of G.entries())T.set(v,z);return Array.from(k).map(v=>({key:v,title:T.get(v)??v}))},[ne,re,i.length,G]),le=()=>{w(!0),d(m+1)},Y=a.useCallback((k,T)=>{k.length!==0&&r(v=>{const z=new Map(v.map(V=>[V.framework_id,V])),U=new Map(T.map(V=>[V.framework_id,V])),J=new Set(k.map(V=>V.originalId)),ae=k.map(({originalId:V,newId:fe})=>{const ve=U.get(fe);if(ve)return ve;const xe=z.get(V);return xe?{...xe,framework_id:fe}:null}).filter(V=>V!==null),ee=new Set(ae.map(V=>V.framework_id)),ue=v.filter(V=>!J.has(V.framework_id)&&!ee.has(V.framework_id));return[...ae,...ue]})},[]);return{frameworkIds:i,setFrameworkIds:c,setAccumulatedFrameworks:r,setSeededFrameworks:x,swapReinstatedFrameworks:Y,allFrameworkItems:Z,pricedFrameworkItems:ge,frameworkPage:m,hasMoreFrameworks:u,isLoadingBrowseMore:b,handleBrowseMoreFrameworks:le,isInitialFrameworksLoading:(M||B)&&m===1,isLoadingFrameworks:M,isFetchingFrameworks:C,isFrameworksQueryError:E,isLoadingUrlFrameworks:B,refetchFrameworks:q,excludeListed:F,handleToggleExcludeListed:()=>{p(k=>!k),r([]),d(1),h(!0),w(!1)},searchQuery:S,setSearchQuery:R,frameworkDataCost:X,entityCount:ie,effectiveTags:W,availableTags:H,skipTierResetRef:N}},Xs=({setFrameworkIds:t,swapReinstatedFrameworks:n,skipTierResetRef:s,draftSignalId:l,setHasUnsavedChanges:i})=>{const c=ls(),g=Ge(),x=he({mutationFn:async r=>l?(await it(l,r),ds(l,"active")):us(r),onSuccess:async()=>{Q.success("Signal listed successfully!"),Ce(c),c.invalidateQueries({queryKey:["my-exchange-frameworks"]}),c.invalidateQueries({queryKey:["my-listings"]}),i(!1),g("/exchange")},onError:r=>{Q.error(be(r))}}),F=he({mutationFn:async r=>{var b;const u=[],h=[];for(const w of r)try{const L=(b=(await ys({framework_id:w,repurchase_reason:"reinstate"})).frameworks)==null?void 0:b[0];L?u.push({originalId:w,newId:L}):h.push({originalId:w,error:"No new framework ID returned"})}catch(A){h.push({originalId:w,error:A instanceof Error?A.message:"Unknown error"})}return{successes:u,failures:h}},onSuccess:async({successes:r,failures:u})=>{if(r.length>0){r.forEach(({originalId:w})=>{c.removeQueries({queryKey:["formula-preview",w]})});const h=r.map(({newId:w})=>w);let b=[];try{const w=await Fe({notInSignal:!1,page:1,pageSize:h.length,frameworkIds:h});b=(w==null?void 0:w.items)??[]}catch(w){console.error("Failed to fetch reinstated frameworks:",w)}n(r,b),s.current=!0,t(w=>{let A=[...w];return r.forEach(({originalId:L,newId:P})=>{A=A.map(S=>S===L?P:S)}),A}),c.invalidateQueries({queryKey:["my-exchange-frameworks"],refetchType:"all"}),r.forEach(({newId:w})=>{c.invalidateQueries({queryKey:["exchange-framework-details",w]}),c.invalidateQueries({queryKey:["formula-preview",w]})})}u.length===0?Q.success(`${r.length} framework${r.length>
11?"s":""} reinstated successfully`):r.length===0?Q.error(`Failed to reinstate ${u.length} framework${u.length>1?"s":""}`):Q(`${r.length} of ${r.length+u.length} framework${r.length+u.length>1?"s":""} reinstated successfully. ${u.length} failed.`,{icon:"⚠️"})},onError:r=>{Q.error(be(r))}}),p=he({mutationFn:ms,onSuccess:r=>(Q.success("Draft saved successfully"),Ce(c),c.invalidateQueries({queryKey:["my-listings"]}),i(!1),g("/exchange?tab=my-listings"),r),onError:r=>{Q.error(be(r)||"Failed to save draft")}}),m=he({mutationFn:({listingId:r,payload:u})=>it(r,u),onSuccess:()=>{Q.success("Draft saved successfully"),Ce(c),c.invalidateQueries({queryKey:["my-listings"]}),i(!1),g("/exchange?tab=my-listings")},onError:r=>{Q.error(be(r)||"Failed to save draft")}}),d=he({mutationFn:gs,onSuccess:()=>{Q.success("Draft deleted"),Ce(c),c.invalidateQueries({queryKey:["my-listings"]}),g("/exchange")},onError:r=>{Q.error(be(r)||"Failed to delete draft")}}),f=he({mutationFn:vt,onError:r=>{Q.error(be(r)||"Failed to load draft")}});return{createSignalMutation:x,reinstateMutation:F,createDraftMutation:p,updateDraftMutation:m,deleteDraftMutation:d,loadDraftMutation:f}};function Ys({isEditMode:t,isResumingDraft:n,signalDerivedFrameworkEnabled:s,hasSignalDerivedFrameworkFlag:l,hasFormulaPreviewError:i,isUserInfoFetched:c,navigate:g,frameworkIds:x,formula:F,formulaValidation:p}){const m=s&&l,[d,f]=a.useState(m?null:"collection"),[r,u]=a.useState(m?1:2),[h,b]=a.useState(new Set),w=a.useRef(d);a.useEffect(()=>{if(d===null)return;const j=w.current;j!==null&&j!==d&&b(new Set),w.current=d},[d]),a.useEffect(()=>{b(j=>{if(j.has(r))return j;const M=new Set(j);return M.add(r),M})},[r]);const A=a.useCallback(j=>{b(M=>{let C=!1;const E=new Set;return M.forEach(q=>{q<=j?E.add(q):C=!0}),C?E:M})},[]),L=a.useCallback(j=>{b(M=>{if(M.has(j))return M;const C=new Set(M);return C.add(j),C})},[]);a.useEffect(()=>{t||n||!s||!c||(l?(f(j=>j==="collection"?null:j),u(j=>j===2?1:j)):(f(j=>j===null?"collection":j),u(j=>j===1?2:j)))},[c]);const P=a.useMemo(()=>d==="signal"?["Format","Frameworks","Formula","Listing details"]:["Format","Frameworks","Listing details"],[d]),S=a.useMemo(()=>d==="signal"?["Collection or Signal","Pick frameworks","Write your formula","Name, tags & price"]:["Collection or Signal","Pick frameworks","Name, tags & price"],[d]),R=a.useMemo(()=>m&&!t?P:P.slice(1),[m,t,P]),O=a.useMemo(()=>m&&!t?S:S.slice(1),[m,t,S]),$=a.useMemo(()=>t?d==="collection"?"Update your collection listing details and pricing":"Update your signal listing details and pricing":d==="signal"?"Combine frameworks into a derived signal, then set pricing.":d==="collection"?"Select frameworks for your collection, then set pricing.":"Choose a collection or signal format to get started.",[t,d]),o=a.useMemo(()=>{const j=m&&!t?0:-1,M=new Set;return h.forEach(C=>{const E=C+j;E>=1&&M.add(E)}),M},[h,m,t]),_=r===P.length,N=d==="collection"&&r===3||d==="signal"&&r===4,D=a.useMemo(()=>r===1?d!==null:r===2?x.length>0:r===3&&d==="signal"?F.trim()!==""&&p.errors.length===0&&!i:!0,[r,d,x,F,p,i]);return{listingType:d,setListingType:f,currentStep:r,setCurrentStep:u,derivedFrameworkEnabled:m,steps:R,stepSubtitles:O,pageSubtitle:$,isLastStep:_,isListingDetailsStep:N,canProceed:D,handleNext:()=>{D&&u(j=>j+1)},handleBack:()=>{r===1||!m&&r===2||t&&r===2?g(-1):u(j=>j-1)},handleStepClick:j=>{const M=m&&!t?j:j+1;(M<r||M===r+1&&D||h.has(M)&&D)&&u(M)},completedSteps:o,clearCompletedStepsAfter:A,markStepCompleted:L}}function Js(){return he({mutationFn:t=>Es(t),meta:{suppressGlobalErrorHandler:!0}})}function _t(t){return t.selectedEntityId==null?t.entities??[]:(t.entities??[]).filter(n=>n.id===t.selectedEntityId)}function er(t){return t.reduce((n,s)=>(n[s.alias]={alias:s.alias,frameworkName:s.framework_name,entityCount:_t(s).length},n),{})}function tr(t,n){const s=t.trim(),l=[],i=[];if(!s)return{errors:l,warnings:i};const c=er(n),g=[];for(let d=0;d<s.length;d+=1){const f=s[d];if(f==="("&&g.push(d),f===")"){if(g.length===0){l.push("Unmatched closing parenthesis.");break}g.pop()}}g.length>0&&l.push("Unmatched opening parenthesis."),/@\.[0-9]+|@[A-Za-z]+\.[^0-9\s()+\-*/]|@[A-Za-z]+\.(?:\D|$)/g.test(s)&&l.push("Malformed framework reference. Use @A or @A.1 format."),/@(?![A-Za-z])/.test(s)&&l.push("Incomplete framework reference. Use @A or @A.1 format.");const F=/@([A-Za-z]+)(?:\.(\d+))?/g,p=new Set;let m=F.exec(s);for(;m;){const d=m[0],f=m[1].toUpperCase(),r=m[2],u=`${d}-${m.index}`;if(!p.has(u)){p.add(u);const h=c[f];
1if(!h)l.push(`Unknown framework alias @${f}. Add it first or update the formula.`);else if(r){const b=Number(r);!Number.isInteger(b)||b<1?l.push(`Invalid Entity index in ${d}. Use a positive index.`):b>h.entityCount&&l.push(`${d} is out of range. @${f} has ${h.entityCount} available Entit${h.entityCount===1?"y":"ies"}.`)}else h.entityCount>1&&i.push(`@${f} references all Entities in "${h.frameworkName}". Use @${f}.1 to target a specific Entity.`)}m=F.exec(s)}return{errors:Array.from(new Set(l)),warnings:Array.from(new Set(i))}}const qe={missingValueHandling:"ignore",timeAlignment:"coarsest",divisionByZero:"null"},sr=[{value:"ignore",label:"Ignore",description:"Skip rows where any reference is missing"},{value:"zero",label:"Treat as 0",description:"Substitute 0 where a reference is missing"},{value:"null",label:"Null",description:"Emit null when a reference is missing"},{value:"forward",label:"Forward Fill",description:"Carry forward previous valid values"}],rr=[{value:"coarsest",label:"Coarsest",description:"Align all series to the lowest-frequency framework"},{value:"finest",label:"Finest",description:"Align to the highest-frequency framework (forward-fill)"},{value:"daily",label:"Daily",description:"Force alignment to daily resolution"},{value:"weekly",label:"Weekly",description:"Force alignment to weekly resolution"},{value:"monthly",label:"Monthly",description:"Force alignment to monthly resolution"}],nr=[{value:"null",label:"Null",description:"Emit null when dividing by zero"},{value:"zero",label:"Zero",description:"Emit 0 when dividing by zero"}];function Be({label:t,options:n,value:s,onChange:l,disabled:i}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-1.5",children:t}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1.5",children:n.map(c=>{const g=c.value===s;return e.jsxs("button",{type:"button",onClick:()=>{g||l(c.value)},disabled:i,className:`rounded-md border px-3 py-2 text-left transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${g?"border-ca-signalOrange bg-ca-signalOrange/5":"border-border bg-background hover:bg-muted/40"}`,children:[e.jsx("div",{className:"text-xs font-medium",children:c.label}),e.jsx("div",{className:"text-[10px] text-muted-foreground leading-snug mt-0.5",children:c.description})]},c.value)})})]})}function ar({config:t,onChange:n,disabled:s}){const[l,i]=a.useState(!0);return e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>i(!l),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-muted/40 transition-colors","aria-expanded":l,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{className:`h-4 w-4 text-muted-foreground transition-transform duration-200 ${l?"rotate-0":"-rotate-90"}`}),e.jsx(Ps,{className:"h-4 w-4 text-ca-signalOrange"}),e.jsx("span",{className:"text-sm font-semibold",children:"Execution settings"})]}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"optional"})]}),e.jsx("div",{className:`grid transition-all duration-300 ease-in-out ${l?"grid-rows-[1fr]":"grid-rows-[0fr]"}`,children:e.jsx("div",{className:"overflow-hidden",children:e.jsxs("div",{className:"p-4 flex flex-col gap-5 border-t border-border",children:[e.jsx(Be,{label:"Missing values",options:sr,value:t.missingValueHandling,onChange:c=>n({...t,missingValueHandling:c}),disabled:s}),e.jsx(Be,{label:"Time alignment",options:rr,value:t.timeAlignment,onChange:c=>n({...t,timeAlignment:c}),disabled:s}),e.jsx(Be,{label:"Division by zero",options:nr,value:t.divisionByZero,onChange:c=>n({...t,divisionByZero:c}),disabled:s})]})})})]})}const or="ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");function We(t){var l,i,c,g;if(t.display_name)return t.display_name;const n=((i=(l=t.spec)==null?void 0:l.insight)==null?void 0:i.insight_name)||"Unknown Insight",s=((g=(c=t.spec)==null?void 0:c.entities)==null?void 0:g.map(x=>x.entity_name).join(", "))||"Unknown Entity";return`${n} — ${s}`}function ir({frameworkIds:t,pricedFrameworkItems:n}
1){const[s,l]=a.useState(""),[i,c]=a.useState(""),[g,x]=a.useState(qe),[F,p]=a.useState(null),m=a.useRef(null),[d,f]=a.useState({}),r=Js();a.useEffect(()=>{f(O=>{const $={};for(const o of t)O[o]!==void 0&&($[o]=O[o]);return $})},[t]);const u=a.useMemo(()=>t.slice(0,26).map((O,$)=>{var _,N,D,y,I,B,j;const o=n.find(M=>M.framework_id===O);return{alias:or[$],framework_id:O,framework_name:o?We(o):O,insight:{id:((N=(_=o==null?void 0:o.spec)==null?void 0:_.insight)==null?void 0:N.insight_id)??0,label:((y=(D=o==null?void 0:o.spec)==null?void 0:D.insight)==null?void 0:y.insight_name)??(o==null?void 0:o.display_name)??O},entities:(((I=o==null?void 0:o.spec)==null?void 0:I.entities)??[]).map(M=>({id:M.carc_id??0,representation:M.representation??"",label:M.entity_name??""})),filters:((B=o==null?void 0:o.spec)==null?void 0:B.filters)??{},aggregate:((j=o==null?void 0:o.spec)==null?void 0:j.aggregate)??"",selectedEntityId:d[O]??null,type:o==null?void 0:o.type}}),[t,n,d]),h=a.useCallback(()=>{const O={};return u.forEach($=>{const o=$.entities??[],_=$.selectedEntityId!=null?o.filter(N=>N.id===$.selectedEntityId):o;O[$.alias]={framework_id:$.framework_id,framework_name:$.framework_name,entities:_.map((N,D)=>({index:D+1,entity_id:N.id,entity_name:N.label??String(N.id)}))}}),O},[u]),b=a.useMemo(()=>tr(s,u),[s,u]),w=a.useRef(!1),A=a.useRef(!1);a.useEffect(()=>{s.trim()||(A.current=!1)},[s]);const L=a.useCallback(()=>{A.current=!1,p(null)},[]),P=a.useCallback(async()=>{if(!w.current){if(!s.trim()){Q.error("Enter a formula");return}if(b.errors.length>0){Q.error(b.errors[0]);return}w.current=!0,A.current=!0,p(null);try{const O=await r.mutateAsync({expression_text:s.trim(),references_json:h(),global_settings:{time_alignment_policy:g.timeAlignment,missing_value_policy:g.missingValueHandling,division_by_zero_policy:g.divisionByZero}});p(Fs(O,s.trim())),Q.success("Formula executed successfully")}catch(O){Q.error(be(O))}finally{w.current=!1}}},[s,h,g,r,b]),S=a.useRef(!0),R=a.useRef(P);return a.useEffect(()=>{R.current=P},[P]),a.useEffect(()=>{if(S.current){S.current=!1;return}if(!A.current)return;const O=setTimeout(()=>{R.current()},100);return()=>clearTimeout(O)},[g]),{formula:s,setFormula:l,signalColumnName:i,setSignalColumnName:c,executionConfig:g,setExecutionConfig:x,currentResult:F,resetResult:L,insertTextRef:m,entityFilters:d,setEntityFilters:f,formulaFrameworks:u,referencesJson:h,formulaValidation:b,handleRunFormula:P,isPreviewPending:r.isPending}}const lr=.1;function cr({frameworkDataCost:t,effectiveTags:n,formula:s,signalColumnName:l,formulaFrameworks:i,referencesJson:c,executionConfig:g,frameworkIds:x,hasUsername:F,createSignalMutation:p}){const[m,d]=a.useState(""),[f,r]=a.useState(""),[u,h]=a.useState(""),[b,w]=a.useState(null),[A,L]=a.useState(!0),[P,S]=a.useState(!1),[R,O]=a.useState(null),$=parseFloat(u),o=lr,_=t+($||0),N=!!(m&&x.length>0&&$>=1),D=(E,q)=>{w(E),h(String(q))},y=E=>{h(E),w(null)};a.useEffect(()=>{if(b===null||t===0)return;const E=Math.max(1,Math.round(t*(b/100)));h(String(E))},[t,b]);const I=E=>{const q={type:E,name:m.trim(),description:f.trim()||void 0,framework_ids:x,signal_alpha:u,tags:n,allow_promotional_tokens:A};return E==="signal"&&s.trim()?{...q,framework_ids:i.map(re=>re.framework_id),expression_text:s.trim(),signal_column_name:l.trim()||void 0,references_json:c(),global_settings:{time_alignment_policy:g.timeAlignment,missing_value_policy:g.missingValueHandling,division_by_zero_policy:g.divisionByZero}}:q};return{name:m,setName:d,description:f,setDescription:r,signalAlpha:u,setSignalAlpha:h,selectedTier:b,setSelectedTier:w,allowPromotionalTokens:A,setAllowPromotionalTokens:L,priceNum:$,platformFeeRate:o,totalListPrice:_,showPreview:N,handleTierSelect:D,handleCustomAlphaChange:y,handleSubmit:(E,q)=>{if(E.preventDefault(),!q||!m||x.length===0||!u){Q.error("Please fill in all required fields");return}if(q==="signal"&&!s.trim()){Q.error("Please write a formula for your signal");return}const re=parseFloat(u);if(isNaN(re)||re<1){Q.error("Signal Alpha must be at least 1 token");return}const se=I(q);if(F===!1){O(se),S(!0);return}p.mutate(se)},showUsernameModal:P,closeUsernameModal:()=>{S(!1)},handleUsernameModalSuccess:()=>{S(!1),R&&(p.mutate(R),O(null))},handleUsernameModalCancel:()=>{S(!1),O(null)}}}function dr({draftSignalId:t,listingType:n,currentStep:s,hasUnsavedChanges:l,hasUnsavedChangesRef:i,setHasUnsavedChanges:c,name:g,description:x,frameworkIds:F,signalAlpha:p,tags:m,allowPromotionalTokens:d,formula:f,signalColumnName:r,referencesJson:u,formulaFrameworks:h,setListingType:b,setFrameworkIds:w,setSeededFrameworks:A,setFormula:L,setSignalColumnName:P,setName:S,setDescription:R,setTags:O,setSignalAlpha:$,setAllowPromotionalTokens:o,setCurrentStep:_,skipTierResetRef:N,createDraftMutation:D,updateDraftMutation:y,deleteDraftMutation:I}
1){const B=!!t,[j,M]=a.useState(t),C=a.useRef(!1),{data:E,isLoading:q}=Ue({queryKey:["draft-signal",t],queryFn:()=>vt(t),enabled:!!t}),re=a.useRef(!1);a.useEffect(()=>{if(!E||re.current||(re.current=!0,E.status!=="draft"))return;E.type==="signal"?b("signal"):b("collection");const W=E.frameworks??[],X=W.every(G=>G.alias)?[...W].sort((G,H)=>G.alias.localeCompare(H.alias)):W,ie=X.map(G=>G.framework_id).filter(G=>!!G);if(ie.length>0){N.current=!0,w(ie);const G=X.filter(H=>!!H.framework_id).map(H=>({framework_id:H.framework_id,display_name:H.display_name??H.framework_name??null,order:null,type:H.type??"exchange",spec:H.spec??{},spec_fingerprint:H.spec_fingerprint??"",unit_price:H.unit_price??"0",purchased_at:""}));A(G),Fe({notInSignal:!1,page:1,pageSize:ie.length,frameworkIds:ie}).then(H=>{const le=new Map(((H==null?void 0:H.items)??[]).map(Y=>{var ce;return[Y.framework_id,{...Y,spec:{...Y==null?void 0:Y.spec,entities:He(((ce=Y==null?void 0:Y.spec)==null?void 0:ce.entities)??[])}}]}));A(G.map(Y=>le.get(Y.framework_id)??Y))}).catch(H=>{console.error("Failed to fetch full data for resumed draft frameworks:",H)})}E.expression_text&&L(E.expression_text),E.signal_column_name&&P(E.signal_column_name),E.name&&S(E.name),E.description&&R(E.description),E.tags&&O(E.tags),E.signal_alpha&&E.signal_alpha!=="0"&&$(E.signal_alpha),o(E.allow_promotional_tokens),E.current_step!=null&&_(E.current_step),C.current=!0,c(!1)},[E]);const se=a.useRef(!0);a.useEffect(()=>{if(se.current){se.current=!1;return}if(C.current){C.current=!1;return}c(F.length>0)},[n,g,x,F,p,m,d,f,r,c]),a.useEffect(()=>{const W=X=>{l&&(X.preventDefault(),X.returnValue="")};return window.addEventListener("beforeunload",W),()=>window.removeEventListener("beforeunload",W)},[l]);const Z=as(a.useCallback(({currentLocation:W,nextLocation:X})=>i.current&&W.pathname!==X.pathname,[i])),ge=a.useCallback(()=>{const W={type:n??"collection",name:g.trim()||void 0,description:x.trim()||void 0,framework_ids:F.length>0?F:void 0,signal_alpha:p||void 0,tags:m.length>0?m:void 0,allow_promotional_tokens:d,expression_text:f.trim()||void 0,signal_column_name:r.trim()||void 0,references_json:void 0,current_step:s,status:"draft"};n==="signal"&&f.trim()&&u&&(W.references_json=u(),W.framework_ids=h.map(X=>X.framework_id)),j?y.mutate({listingId:j,payload:W}):D.mutate(W,{onSuccess:X=>M(X.signal_id)})},[n,g,x,F,p,m,d,f,r,s,u,j,h,y,D]),ne=a.useCallback(()=>{j&&(c(!1),I.mutate(j))},[j,c,I]);
1return{isDraftMode:B,isLoadingDraft:q,savedDraftId:j,handleSaveDraft:ge,handleDeleteDraft:ne,blocker:Z}}function ur({currentStep:t,labels:n,subtitles:s,onStepClick:l,canGoForward:i=!1,completedSteps:c=new Set,disabled:g=!1}){return e.jsx("div",{className:"mb-8 border border-border rounded-xl",children:e.jsx("div",{className:"flex items-center",children:n.map((x,F)=>{const p=F+1,m=p===t,d=p<t,f=p===t+1,r=p>t,u=!g&&(d||(r?i&&(f||c.has(p)):c.has(p)));return e.jsxs("div",{className:"flex items-center flex-1 min-w-0",children:[e.jsxs("div",{className:`flex items-center gap-3 min-w-0 px-5 py-4 ${u?"cursor-pointer group":""}`,onClick:u?()=>l==null?void 0:l(p):void 0,role:u?"button":void 0,tabIndex:u?0:void 0,onKeyDown:u?h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),l==null||l(p))}:void 0,children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-semibold transition-colors ${m?"bg-ca-signalOrange text-white":d?"border-2 border-ca-signalOrange text-ca-signalOrange group-hover:bg-ca-signalOrange group-hover:text-white":f&&i?"border-2 border-border text-muted-foreground group-hover:border-ca-signalOrange group-hover:text-ca-signalOrange":"border-2 border-border text-muted-foreground"}`,children:p}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`text-sm font-semibold leading-tight truncate transition-colors ${m?"text-foreground":u?"text-muted-foreground group-hover:text-foreground":"text-muted-foreground"}`,children:x}),(s==null?void 0:s[F])&&e.jsx("p",{className:"text-xs text-muted-foreground leading-tight truncate mt-0.5",children:s[F]})]})]}),F<n.length-1&&e.jsx("div",{className:"flex-1 h-px bg-border"})]},x)})})})}function mt({type:t,selected:n,onSelect:s,icon:l,title:i,description:c,subDescriptionBold:g,subDescription:x}){return e.jsxs("button",{type:"button",onClick:()=>s(t),className:`relative w-full text-left rounded-xl border-2 p-6 transition-all duration-200 ${n?"border-ca-signalOrange bg-ca-signalOrange/5":"border-border bg-card hover:border-ca-signalOrange/40 hover:bg-ca-signalOrange/5"}`,children:[e.jsx("div",{className:"absolute top-4 right-4",children:e.jsx("div",{className:`w-5 h-5 rounded-full flex items-center justify-center transition-all ${n?"bg-ca-signalOrange":"border-2 border-border"}`,children:n&&e.jsx("svg",{width:"11",height:"8",viewBox:"0 0 11 8",fill:"none",children:e.jsx("path",{d:"M1 4L4 7L10 1",stroke:"white",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"})})})}),e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center mb-4 transition-colors ${n?"bg-ca-signalOrange/20 text-ca-signalOrange":"bg-muted text-muted-foreground"}`,children:l}),e.jsx("h3",{className:"text-base font-semibold mb-2",children:i}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:c}),e.jsxs("p",{className:"text-xs text-muted-foreground/70 border-t border-border pt-3",children:[e.jsxs("span",{className:"font-semibold text-foreground/60",children:[g," "]}),x]})]})}function mr(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]})}function gr(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M2 12h2l3-8 4 16 3-10 2 4h6"})})}function fr({selected:t,onSelect:n}){return e.jsx("div",{className:"p-5 border rounded-xl",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(mt,{type:"collection",selected:t==="collection",onSelect:n,icon:e.jsx(mr,{}),title:"Collection",description:"A curated collection of frameworks, grouped for discovery and reuse.",subDescriptionBold:"Like a playlist.",subDescription:"Frameworks grouped together, individually accessible."}),e.jsx(mt,{type:"signal",selected:t==="signal",onSelect:n,icon:e.jsx(gr,{}),title:"Signal",description:"A unified signal derived from multiple frameworks.",subDescriptionBold:"Like a recipe.",subDescription:"Frameworks combined together into one output."})]})})}function je({label:t,value:n,highlighted:s,isPrimary:l}){return e.jsxs("span",{className:de("inline-flex items-center gap-1 rounded-md border px-2 py-1 text-xs max-w-full",s?"font-medium border-ca-signalOrange/35 bg-ca-signalOrange/10 text-foreground dark:bg-ca-signalOrange/15 dark:border-ca-signalOrange/40":l?"border-border bg-background":"border-border/80 bg-muted/40 text-muted-foreground"),title:`${t}: ${n}`,children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:t}),e.jsx("span",{className:"text-foreground font-medium truncate min-w-0",children:n})]})}function Ke({name:t,representation:n,alias:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border bg-background px-2 py-0.5 text-xs",title:n?`${t} · ${n}`:t,children:[s&&e.jsx("code",{className:"text-[10px] font-mono text-ca-signalOrange",children:s}),e.jsx("span",{className:"text-foreground truncate max-w-[160px]",children:t}),n&&e.jsxs("span",{className:"text-muted-foreground",children:["· ",n]})]})}function Ct({children:t}){return e.jsx("div",{className:"rounded-md border border-border/60 bg-gradient-to-br from-muted/50 to-muted/20 p-2",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-ca-signalOrange/10 text-ca-signalOrange",title:"Query scope",children:e.jsx(Rs,{className:"h-3.5 w-3.5","aria-hidden":"true"})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t})})]})})}const Et="w-full rounded-lg border transition-colors",Ft="opacity-60 cursor-not-allowed";function gt(t){return t.charAt(0).toUpperCase()+t.slice(1)}function xr(t){var l,i;const n=t.spec;if(!n)return!1;const s=n.filters;return!!((l=n.insight)!=null&&l.insight_name||((i=n.insight)==null?void 0:i.insight_id)!=null||n.entities&&n.entities.length>0||s!=null&&s.date_resolution||s!=null&&s.location_resolution||s!=null&&s.date_range||Pe(s==null?void 0:s.platform).length>0||Pe(s==null?void 0:s.transaction_method).length>0||s!=null&&s.country||n.aggregate)}function pr({spec:t,alias:n}){var p,m,d;const s=t.filters,l=t.entities??[],i=(p=t.insight)!=null&&p.insight_name?t.aggregate==="mean"?`Avg. ${t.insight.insight_name}`:t.insight.insight_name:null,c=Pe(s==null?void 0:s.platform),g=Pe(s==null?void 0:s.transaction_method),x=[t.aggregate&&{label:"Aggregate",value:gt(t.aggregate)},(s==null?void 0:s.country)&&{label:"Country",value:s.country},(s==null?void 0:s.location_resolution)&&{label:"Location Resolution",value:s.location_resolution.toUpperCase()},(s==null?void 0:s.date_resolution)&&{label:"Date Resolution",value:gt(s.date_resolution)},(s==null?void 0:s.date_range)&&{label:"Date range",value:`${s.date_range.start_date} → ${s.date_range.end_date}`,highlighted:!0},c.length>0&&{label:"Platform",value:c.map(f=>f==="*"?"All":f).join(", ")},g.length>0&&{label:"Transaction Method",value:g.join(", ")}
1].filter(Boolean),F=i||((m=t.insight)==null?void 0:m.insight_id)!=null;return e.jsxs("div",{className:"px-3 pb-3 pt-1 flex flex-col gap-2 border-t border-border/60",children:[x.length>0&&e.jsx(Ct,{children:x.map((f,r)=>e.jsx(je,{label:f.label,value:f.value,highlighted:f.highlighted,isPrimary:r===0},r))}),l.length>0&&e.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/20 p-2",children:[e.jsxs("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mb-1.5",children:["Entities (",l.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.map((f,r)=>e.jsx(Ke,{name:f.entity_name??String(f.carc_id),representation:f.representation,alias:n?`@${n}.${r+1}`:void 0},r))})]}),F&&e.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/20 p-2",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mb-1.5",children:"Insight"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[i&&e.jsx(je,{label:"Name",value:i,isPrimary:!0}),((d=t.insight)==null?void 0:d.insight_id)!=null&&e.jsx(je,{label:"ID",value:String(t.insight.insight_id)})]})]})]})}function hr({framework:t,label:n,checked:s,disabled:l,onToggle:i,alias:c}){var f,r;const[g,x]=a.useState(!1),F=t.framework_id,p=Ae(t.unit_price),m=xr(t),d=((r=(f=t.spec)==null?void 0:f.entities)==null?void 0:r.length)??0;return e.jsxs("div",{className:de(Et,s?"border-ca-signalOrange/60 bg-ca-signalOrange/5":"border-border bg-card",l&&Ft),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",onClick:i,disabled:l,className:"flex items-center gap-3 min-w-0 flex-1 text-left",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(vs,{id:`framework-${F}`,checked:s,readOnly:!0,tabIndex:-1,label:"",className:"checked:bg-ca-signalOrange checked:border-ca-signalOrange focus:ring-ca-signalOrange/20 dark:checked:bg-ca-signalOrange dark:checked:border-ca-signalOrange dark:focus:ring-ca-signalOrange/20"})}),s&&c&&e.jsx("span",{className:"w-7 h-7 rounded-md flex items-center justify-center text-sm font-bold text-white shrink-0 bg-ca-signalOrange",title:`Reference this framework in a formula as @${c}`,children:c.charAt(0).toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground break-words leading-tight",children:n}),d>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[s&&c&&e.jsxs("code",{className:"text-[10px] font-mono px-0.5 rounded border bg-ca-signalOrange/10 text-ca-signalOrange border-ca-signalOrange/20",children:["@",c]}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["• ",d," ",d===1?"entity":"entities"]})]})]})]}),e.jsx(me.Display,{token:p,className:"min-w-fit text-xs text-muted-foreground shrink-0 whitespace-nowrap"}),m&&e.jsxs("button",{type:"button",onClick:()=>x(u=>!u),className:"flex items-center gap-1 p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors","aria-label":g?"Collapse details":"Expand details","aria-expanded":g,children:[e.jsx("span",{className:"text-[11px] mt-[1px] leading-none",children:"Details"}),e.jsx(Ls,{className:de("size-4 transition-transform duration-300",g&&"rotate-90"),"aria-hidden":"true"})]})]}),m&&t.spec&&e.jsx("div",{className:de("grid transition-all duration-300 ease-in-out",g?"grid-rows-[1fr]":"grid-rows-[0fr]"),"aria-hidden":!g,children:e.jsx("div",{className:"overflow-hidden",children:e.jsx(pr,{spec:t.spec,alias:s?c:void 0})})})]})}function br({frameworks:t,selectedFrameworkIds:n,onChangeSelectedFrameworkIds:s,getFrameworkLabel:l,disabled:i,showBrowseMore:c,onBrowseMore:g,isLoadingBrowseMore:x,originalFrameworkIds:F,frameworkAliases:p}){const m=a.useMemo(()=>new Set(n),[n]),d=a.useMemo(()=>new Set(F??[]),[F]),f=r=>{if(i)return;const u=m.has(r)?n.filter(h=>h!==r):[...n,r];s(u)};return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"space-y-2 mb-4 pr-2 -mr-2",children:t.map(r=>{const u=r.framework_id,h=Ae(r.unit_price)===0;return e.jsx(hr,{framework:r,label:l(r),checked:m.has(u),disabled:i||h&&!d.has(u),onToggle:()=>f(u),alias:p==null?void 0:p[u]},u)})}),c&&e.jsx("button",{type:"button",onClick:g,disabled:i||x,className:de(js(Et,"px-4 py-2"),"min-h-[38px] mt-4 flex items-center justify-center gap-2 text-sm font-semibold bg-card hover:bg-secondary/30 border-border",(i||x)&&Ft),children:x?e.jsx(Nt,{xsm:!0}):e.jsx("span",{children:"+ Browse More Frameworks"})})]})}const yr={root:{label:"ms-2 text-xs text-muted-foreground whitespace-nowrap font-normal"},toggle:{base:"relative rounded-full border after:absolute after:rounded-full after:bg-white after:transition-all group-focus:ring-4 group-focus:ring-ca-signalOrange/25",checked:{color:{info:"border-ca-signalOrange bg-ca-signalOrange"}}}};function jr({searchQuery:t,onSearchChange:n,excludeListed:s=!1,onToggleExcludeListed:l,toggleDisabled:i=!1}){return e.jsxs("div",{className:"mb-4",children:[e.jsx(Me,{type:"text",placeholder:"Search",value:t,onChange:c=>n(c.target.value),className:"w-full mb-2 text-sm"}),e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3 px-4 py-3 rounded-lg bg-secondary/40 dark:bg-ca-600/40",children:e.jsx(kt,{checked:!s,onChange:()=>l==null?void 0:l(),label:"Show active listings",sizing:"sm",color:"info",theme:yr,disabled:i})})]})}function ft(t){return t.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function xt(t){if(t==null||t==="")return null;
1if(Array.isArray(t)){const n=t.map(String).filter(Boolean);return n.length===0?null:n.join(", ")}if(typeof t=="object"){const n=t,s=n.start_date??n.start,l=n.end_date??n.end;if(s||l){const i=c=>c?new Date(String(c)).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"...";return`${i(s)} → ${i(l)}`}return null}return String(t)}function pt(t,n){if(t==="date_range")return!0;if(typeof n=="object"&&n!==null){const s=n;return!!(s.start_date??s.start??s.end_date??s.end)}return!1}function At({selectedFrameworkIds:t,frameworks:n,getFrameworkLabel:s,totalDataCost:l,className:i,formulaFrameworks:c,frameworkAliases:g,onRemoveFramework:x,isDisabled:F}){const[p,m]=a.useState(new Set),d=t.map(r=>n.find(u=>u.framework_id===r)).filter(r=>!!r);function f(r){m(u=>{const h=new Set(u);return h.has(r)?h.delete(r):h.add(r),h})}return e.jsx("div",{className:$e("w-[280px] shrink-0 self-start sticky top-24",i),children:e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary/40",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Selected Frameworks"}),e.jsx("span",{className:"inline-flex items-center justify-center min-w-[20px] h-5 px-1.5 rounded-full text-[11px] font-bold text-white bg-ca-signalOrange",children:t.length})]}),e.jsx(me.Display,{token:l})]}),d.length===0?e.jsxs("div",{className:"text-xs text-muted-foreground text-center px-4 py-6 space-y-0.5",children:[e.jsx("p",{children:"Selected frameworks will appear here."}),e.jsx("p",{children:"Pick at least one to continue to the next step."})]}):e.jsx("ul",{className:"max-h-[60vh] overflow-y-auto divide-y divide-border",children:d.map(r=>{var R,O,$,o,_,N,D;const u=g==null?void 0:g[r.framework_id],h=c==null?void 0:c.find(y=>y.framework_id===r.framework_id),b=p.has(r.framework_id),w=((O=(R=r.spec)==null?void 0:R.entities)==null?void 0:O.length)??0,A=[];
1if(h){h.aggregate&&A.push({label:"Aggregate",value:h.aggregate,type:"aggregate"});for(const[y,I]of Object.entries(h.filters)){const B=xt(I);B&&A.push({label:ft(y),value:B,type:pt(y,I)?"date":"filter"})}}else if(r.spec){const{aggregate:y,filters:I}=r.spec;if(y&&A.push({label:"Aggregate",value:y,type:"aggregate"}),I)for(const[B,j]of Object.entries(I)){const M=xt(j);M&&A.push({label:ft(B),value:M,type:pt(B,j)?"date":"filter"})}}const L=h?h.insight.label:((o=($=r.spec)==null?void 0:$.insight)==null?void 0:o.insight_name)??null,P=h?h.insight.id:((N=(_=r.spec)==null?void 0:_.insight)==null?void 0:N.insight_id)??null,S=!!(L||P!=null);return e.jsxs("li",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2 cursor-pointer",onClick:()=>f(r.framework_id),children:[e.jsx("button",{type:"button",className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors mt-0.5","aria-label":b?"Collapse":"Expand","aria-expanded":b,onClick:y=>{y.stopPropagation(),f(r.framework_id)},children:e.jsx($s,{className:$e("size-3.5 transition-transform duration-300",b&&"rotate-90"),"aria-hidden":"true"})}),u&&e.jsx("span",{className:"w-6 h-6 rounded bg-ca-signalOrange text-white flex items-center justify-center text-[11px] font-bold shrink-0",children:u[0].toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium text-foreground line-clamp-2 leading-snug",children:s(r)}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[u&&e.jsxs("code",{className:"text-[10px] font-mono px-1 py-0.5 rounded bg-ca-signalOrange/10 text-ca-signalOrange",children:["@",u]}),w>0&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[w," ",w===1?"entity":"entities"]})]})]}),x&&e.jsx("button",{type:"button",disabled:F,className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50 disabled:pointer-events-none","aria-label":`Remove ${u?u.toUpperCase():s(r)}`,onClick:y=>{y.stopPropagation(),x(r.framework_id)},children:e.jsx(Bs,{className:"size-3.5","aria-hidden":"true"})})]}),e.jsx("div",{className:$e("grid transition-all duration-300 ease-in-out",b?"grid-rows-[1fr]":"grid-rows-[0fr]"),"aria-hidden":!b,children:e.jsx("div",{className:"overflow-hidden",children:e.jsxs("div",{className:"mt-2 ml-7 flex flex-col gap-2",children:[A.length>0&&e.jsx(Ct,{children:A.map(y=>e.jsx(je,{label:y.label,value:y.value,highlighted:y.type==="date",isPrimary:y.type==="aggregate"},y.label))}),h&&h.entities.length>0&&e.jsx("div",{className:"rounded-md border border-border/60 bg-muted/20 p-2 flex flex-wrap gap-1",children:h.entities.map((y,I)=>e.jsx(Ke,{name:y.label,alias:u?`@${u}.${y.index??I+1}`:void 0},y.id))}),!h&&((D=r.spec)==null?void 0:D.entities)&&r.spec.entities.length>0&&e.jsx("div",{className:"rounded-md border border-border/60 bg-muted/20 p-2 flex flex-wrap gap-1",children:r.spec.entities.map((y,I)=>e.jsx(Ke,{name:y.entity_name??y.representation??"",representation:y.representation},y.carc_id??I))}),S&&e.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/20 p-2 flex flex-wrap gap-1.5",children:[L&&e.jsx(je,{label:"Name",value:L,isPrimary:!0}),P!=null&&e.jsx(je,{label:"ID",value:String(P)})]})]})})})]},r.framework_id)})})]})})}function vr({searchQuery:t,onSearchChange:n,excludeListed:s,onToggleExcludeListed:l,frameworks:i,allFrameworkItems:c,selectedFrameworkIds:g,onChangeSelectedFrameworkIds:x,getFrameworkLabel:F,originalFrameworkIds:p,isDisabled:m,frameworkPage:d,isLoadingFrameworks:f,isFetchingFrameworks:r,isFrameworksQueryError:u,isLoadingBrowseMore:h,onRetry:b,showBrowseMore:w,onBrowseMore:A,totalDataCost:L,frameworkAliases:P,formulaFrameworks:S,onRemoveFramework:R,compact:O}){const $=Ge(),o=a.useRef(null),[_,N]=a.useState("60vh");a.useEffect(()=>{const j=o.current;if(!j)return;const M=()=>{const C=j.getBoundingClientRect().top;N(`calc(100vh - ${C+132}px)`)};return M(),window.addEventListener("resize",M),()=>window.removeEventListener("resize",M)},[]);const D=d===1&&(f||r&&c.length===0),y=d===1&&u&&!r&&c.length===0,I=c.length===0&&!h,B=t.trim().length>0||s;return e.jsxs("div",{className:"flex gap-6 flex-1",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(ke,{className:"rounded-xl bg-white dark:bg-[#19191c] p-6 flex flex-col",children:[e.jsx("span",{className:"text-lg font-semibold block mb-4",children:"Select Frameworks"}),e.jsx(jr,{searchQuery:t,onSearchChange:n,excludeListed:s,onToggleExcludeListed:l,toggleDisabled:m||r}),e.jsx("div",{ref:o,className:"overflow-y-auto overflow-x-hidden",style:{maxHeight:_,height:_},children:D?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(Nt,{})}):y?e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 space-y-2",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Could not load frameworks. Check your connection and try again."}),e.jsx(ye,{type:"button",primary:!0,onClick:b,children:"Retry"})]}):I?e.jsx(hs,{title:B?"No matching frameworks":"No frameworks available",description:B?"Try adjusting your search or filters to find frameworks.":"Start building frameworks in Builder to unlock your exchange experience.",action:B?void 0:e.jsx(ye,{type:"button",primary:!0,onClick:()=>$(`/${ws.BUILDER}`),children:"Build a Framework"})}):e.jsx(br,{frameworks:i,selectedFrameworkIds:g,onChangeSelectedFrameworkIds:x,getFrameworkLabel:F,disabled:m,showBrowseMore:w,onBrowseMore:A,isLoadingBrowseMore:h,originalFrameworkIds:p,frameworkAliases:P})})]})}),e.jsx(At,{selectedFrameworkIds:g,frameworks:c,getFrameworkLabel:F,totalDataCost:L,frameworkAliases:P,formulaFrameworks:S,onRemoveFramework:R,isDisabled:m,className:O?"w-1/3":void 0})]})}function wr(t,n,s=4){if(n<0||n>t.value.length)return null;const l=window.getComputedStyle(t),i=document.createElement("div");i.setAttribute("aria-hidden","true"),i.style.cssText=["position:absolute","left:-9999px","top:0","visibility:hidden","pointer-events:none","white-space:pre-wrap","word-wrap:break-word","overflow-wrap:break-word",`width:${t.clientWidth}px`,`font:${l.font}`,`padding:${l.padding}`,`line-height:${l.lineHeight}`,`letter-spacing:${l.letterSpacing}`,`border:${l.border}`,`box-sizing:${l.boxSizing}`,`tab-size:${l.tabSize}`].join(";");const c=t.value.slice(0,n),g=t.value.slice(n);i.appendChild(document.createTextNode(c));const x=document.createElement("span");x.textContent=g.length>0?g.charAt(0):".",i.appendChild(x),document.body.appendChild(i);const F=i.getBoundingClientRect(),p=x.getBoundingClientRect();document.body.removeChild(i);const m=p.top-F.top,d=p.left-F.left,f=p.height>0?p.height:parseFloat(l.lineHeight)||parseFloat(l.fontSize)*1.2||16,r=m-t.scrollTop,u=d-t.scrollLeft;return{top:r+f+s,left:u}}function ze(t,n){const s=t.slice(0,n),l=/(?:^|[\s(,+\-*/])(@[A-Za-z]?(?:\.\d*)?)$/.exec(s);if(!l)return null;const i=l[1];return{token:i,start:n-i.length,end:n}}function Nr({formula:t,onChange:n,onRun:s,onClear:l,frameworks:i,validation:c,isRunning:g=!1,isReinstating:x=!1,insertTextRef:F}){const p=a.useRef(null),m=a.useRef(null),[d,f]=a.useState(0),[r,u]=a.useState(0),[h,b]=a.useState(!0),[w,A]=a.useState(null);a.useEffect(()=>{const o=p.current;o&&(o.style.height="auto",o.style.height=`${Math.min(o.scrollHeight,240)}px`)},[t]);const L=a.useCallback(o=>{const _=p.current;if(!_)return;const N=_.selectionStart,D=_.selectionEnd,y=t.slice(0,N),I=t.slice(D),B=y.length>0&&!y.endsWith(" ")&&!y.endsWith("("),j=I.length>0&&!I.startsWith(" ")&&!I.startsWith(")"),M=y+(B?" ":"")+o+(j?" ":"")+I;n(M),setTimeout(()=>{const C=N+o.length+(B?1:0);_.focus(),_.setSelectionRange(C,C)},0)},[t,n]);F.current=L;const P=a.useMemo(()=>
1{if(!h)return[];const o=ze(t,d);if(!o)return[];const N=o.token.toUpperCase();return i.flatMap(y=>{const I=_t(y),B=[{value:`@${y.alias}`,label:`@${y.alias}`,description:I.length>1?`${y.framework_name} (all Entities)`:y.framework_name}];if(I.length<=1)return B;const j=I.map((M,C)=>({value:`@${y.alias}.${C+1}`,label:`@${y.alias}.${C+1}`,description:M.label||`Entity ${C+1}`}));return[...B,...j]}).filter(y=>y.value.toUpperCase().startsWith(N)).slice(0,8)},[t,d,i,h]),S=a.useCallback(()=>{var M;const o=p.current;if(!o||P.length===0||d<0||d>t.length){A(null);return}if(!ze(t,d)){A(null);return}const N=wr(o,d),D=((M=m.current)==null?void 0:M.clientWidth)??o.clientWidth,I=Math.max(0,D-192),B=(N==null?void 0:N.top)??o.offsetHeight+4,j=N?Math.max(0,Math.min(N.left,I)):0;A({top:B,left:j})},[t,d,P.length]);a.useLayoutEffect(()=>{S()},[S,h]),a.useEffect(()=>{const o=p.current;if(!o)return;const _=()=>{requestAnimationFrame(()=>S())};o.addEventListener("scroll",_,{passive:!0});const N=new ResizeObserver(_);return N.observe(o),m.current&&N.observe(m.current),window.addEventListener("resize",_),()=>{o.removeEventListener("scroll",_),N.disconnect(),window.removeEventListener("resize",_)}},[S]);const R=a.useCallback(o=>{const _=ze(t,d);if(!_)return;const N=t.slice(0,_.start),D=t.slice(_.end),y=!D.startsWith(" "),I=N+o.value+(y?" ":"")+D,B=_.start+o.value.length+(y?1:0);n(I),b(!1),setTimeout(()=>{var j,M;(j=p.current)==null||j.focus(),(M=p.current)==null||M.setSelectionRange(B,B),f(B)},0)},[t,d,n]),O=o=>{if(P.length>0){if(o.key==="ArrowDown"){o.preventDefault(),u(_=>(_+1)%P.length);return}if(o.key==="ArrowUp"){o.preventDefault(),u(_=>_===0?P.length-1:_-1);return}if(o.key==="Tab"||o.key==="Enter"){if(o.key==="Enter"&&(o.metaKey||o.ctrlKey)){if(o.preventDefault(),g||x)return;s();return}o.preventDefault(),R(P[r]??P[0]);return}if(o.key==="Escape"){f(-1);return}}if(o.key==="Enter"&&(o.metaKey||o.ctrlKey)){if(o.preventDefault(),g||x)return;s()}},$=o=>{const _=p.current;if(!_)return;const N=_.selectionStart,D=_.selectionEnd,y=t.slice(0,N),I=t.slice(D);if(o==="()"){n(y+"()"+I),setTimeout(()=>{_.focus(),_.setSelectionRange(N+1,N+1)},0);return}const B=y.length>0&&!y.endsWith(" "),j=I.length>0&&!I.startsWith(" "),M=y+(B?" ":"")+o+(j?" ":"")+I;n(M),setTimeout(()=>{const C=N+o.length+(B?1:0)+(j?1:0);_.focus(),_.setSelectionRange(C,C)},0)};return e.jsxs("div",{className:"bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Formula"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ct,{size:"xs",color:"gray",onClick:l,disabled:g||x,children:"Clear"}),e.jsxs(ct,{size:"xs",onClick:s,isProcessing:g,disabled:g||x,style:{backgroundColor:"#FF5A00"},children:[!g&&e.jsx(Ns,{className:"h-3 w-3 mr-1 mt-0.5"}),g?"Running...":"Run"]})]})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{ref:m,className:"relative w-full",children:[e.jsx("textarea",{ref:p,value:t,onChange:o=>{n(o.target.value),f(o.target.selectionStart??0),u(0),b(!0)},onKeyDown:O,onClick:o=>{f(o.target.selectionStart),u(0)},onKeyUp:o=>{o.key==="ArrowUp"||o.key==="ArrowDown"||(f(o.target.selectionStart),u(0))},placeholder:"Type @ to reference frameworks",disabled:g||x,className:"w-full min-h-[44px] max-h-[240px] bg-transparent resize-none appearance-none outline-none font-mono text-sm border-0 focus:ring-0 overflow-y-auto overflow-x-hidden disabled:opacity-50 disabled:cursor-not-allowed",style:{resize:"none"},spellCheck:!1}),P.length>0&&w!=null&&e.jsxs("div",{className:"absolute z-20 border border-border rounded-md bg-background shadow-md overflow-hidden",style:{top:w.top,left:w.left,right:0,minWidth:"12rem"},role:"listbox","aria-label":"Framework suggestions",children:[e.jsx("div",{className:"px-2 py-1 text-[11px] text-muted-foreground border-b border-border",children:"Framework suggestions"}),e.jsx("ul",{className:"max-h-52 overflow-y-auto",children:P.map((o,_)=>e.jsx("li",{children:e.jsxs("button",{type:"button",onMouseDown:N=>{N.preventDefault(),R(o)},className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 ${_===r?"bg-muted":"hover:bg-muted/60"}`,children:[e.jsx("span",{className:"font-mono shrink-0",children:o.label}),e.jsx("span",{className:"text-xs text-muted-foreground truncate min-w-0",children:o.description})]})},`${o.value}-${o.description}`))}),e.jsx("div",{className:"px-2 py-1 text-[11px] text-muted-foreground border-t border-border",children:"Enter or Tab to apply • Arrow keys to navigate"})]})]}),(c.errors.length>0||c.warnings.length>0)&&e.jsxs("div",{className:"mt-3 space-y-2",children:[c.errors.map(o=>e.jsx("div",{className:"text-xs px-3 py-2 rounded-md border border-red-300/60 bg-red-50 text-red-700",children:o},o)),c.warnings.map(o=>e.jsx("div",{className:"text-xs px-3 py-2 rounded-md border border-amber-300/60 bg-amber-50 text-amber-700",children:o},o))]})]}),e.jsx("div",{className:"border-t border-border px-4 py-2 text-xs text-muted-foreground",children:"Type @ for autocomplete • Use @A for all entities or @A.2 for a specific entity • Cmd/Ctrl+Enter to run"}),e.jsx("div",{className:"border-t border-border px-4 py-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Operators:"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:["+","-","*","/","()"].map(o=>e.jsx("button",{type:"button",onClick:()=>$(o),disabled:g||x,className:"h-7 w-7 border border-border rounded hover:bg-muted hover:border-ca-signalOrange transition-colors font-mono text-sm disabled:opacity-50 disabled:cursor-not-allowed",children:o},o))})]})})]})}const ht=[{name:"SUM",syntax:"SUM(@A)"},{name:"AVG",syntax:"AVG(@A)"},{name:"MAX",syntax:"MAX(@A)"},{name:"MIN",syntax:"MIN(@A)"},{name:"PCT_CHANGE",syntax:"PCT_CHANGE(@A)"},{name:"MOVING_AVG",syntax:"MOVING_AVG(@A, window=7)"},{name:"NORMALIZE",syntax:"NORMALIZE(@A)"},{name:"LOG",syntax:"LOG(@A)"},{name:"ABS",syntax:"ABS(@A)"}];function kr({onInsert:t,disabled:n}){const[s,l]=a.useState(!1),[i,c]=a.useState(""),g=ht.filter(x=>x.name.toLowerCase().includes(i.toLowerCase())||x.syntax.toLowerCase().includes(i.toLowerCase()));return e.jsxs("div",{className:"bg-background border border-border rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>l(!s),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{className:`h-4 w-4 text-muted-foreground transition-transform duration-200 ${s?"rotate-0":"-rotate-90"}`}),e.jsx(Ms,{className:"h-4 w-4 text-ca-signalOrange"}),e.jsx("span",{className:"text-sm font-medium",children:"Functions"})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[ht.length," functions"]})]}),e.jsx("div",{className:`grid transition-all duration-300 ease-in-out ${s?"grid-rows-[1fr]":"grid-rows-[0fr]"}`,children:e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"p-3 border-t border-border",children:e.jsxs("div",{className:"relative",children:[e.jsx(ks,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(Me,{type:"text",placeholder:"Search functions...",value:i,onChange:x=>c(x.target.value),className:"pl-8 text-sm"})]})}),e.jsxs("div",{className:"max-h-[300px] overflow-y-auto divide-y divide-border",children:[g.map(x=>e.jsxs("button",{type:"button",onClick:()=>t(x.syntax),disabled:n,className:"w-full px-4 py-2.5 text-left hover:bg-muted/50 cursor-pointer group border-transparent hover:border-ca-signalOrange transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"font-mono text-sm font-medium",children:x.name}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 font-mono",children:x.syntax})]},x.name)),g.length===0&&e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:"No functions foun
1d"})]})]})})]})}function Sr({formulaFrameworks:t,formula:n,onFormulaChange:s,signalColumnName:l,onSignalColumnNameChange:i,config:c,onConfigChange:g,currentResult:x,onClearResult:F,validation:p,onRun:m,isRunning:d,isReinstating:f,insertTextRef:r,onReinstate:u,onPreviewErrorChange:h}){return e.jsx("div",{className:"flex gap-6",children:e.jsx("div",{className:"flex-1 min-w-0 flex flex-col gap-4",children:e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-4 gap-4 items-start",children:[e.jsxs("div",{className:"xl:col-span-1 flex flex-col gap-4",children:[e.jsxs(ke,{className:"rounded-xl bg-white dark:bg-[#19191c] p-4",children:[e.jsx("h2",{className:"text-lg font-semibold mb-1",children:"Define your formula"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Combine your selected frameworks with arithmetic. Reference each as"," ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-muted text-foreground",children:"@a"})," ","/"," ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-muted text-foreground",children:"@b"})," ","or"," ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-muted text-foreground",children:"@a.1"})," ","for a specific entity."]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsx(Nr,{formula:n,onChange:s,onRun:m,onClear:()=>{s(""),F()},frameworks:t,validation:p,isRunning:d,isReinstating:f,insertTextRef:r}),t.length>0&&e.jsxs("div",{className:"border-t border-border px-4 py-3",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wide text-muted-foreground mb-1.5",children:"Insert reference"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.flatMap(b=>{const w=b.selectedEntityId!=null?(b.entities??[]).filter(A=>A.id===b.selectedEntityId):b.entities??[];if(w.length===0||w.length===1){const A=w[0],L=A?`${b.insight.label} — ${A.label}`:b.framework_name;return[e.jsxs("button",{type:"button",onClick:()=>{var P;return(P=r.current)==null?void 0:P.call(r,`@${b.alias}`)},disabled:d||f,className:"inline-flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1 text-xs hover:bg-muted transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:L,children:[e.jsxs("code",{className:"font-mono",style:{color:"rgb(249, 115, 22)"},children:["@",b.alias]}),e.jsx("span",{className:"text-muted-foreground truncate max-w-[140px]",children:L})]},b.alias)]}return w.map(A=>{const L=(b.entities??[]).findIndex(R=>R.id===A.id),P=L!==-1?L+1:1,S=`${b.insight.label} — ${A.label}`;return e.jsxs("button",{type:"button",onClick:()=>{var R;return(R=r.current)==null?void 0:R.call(r,`@${b.alias}.${P}`)},disabled:d||f,className:"inline-flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1 text-xs hover:bg-muted transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:S,children:[e.jsxs("code",{className:"font-mono",style:{color:"rgb(249, 115, 22)"},children:["@",b.alias,".",P]}),e.jsx("span",{className:"text-muted-foreground truncate max-w-[140px]",children:S})]},`${b.alias}.${P}`)})})})]})]})]}),e.jsx(ar,{config:c,onChange:g,disabled:d||f}),e.jsx(kr,{onInsert:b=>{var w;return(w=r.current)==null?void 0:w.call(r,b)},disabled:d||f})]}),e.jsx("div",{className:"xl:col-span-3 flex flex-col gap-4",children:e.jsx(As,{frameworks:t,result:x,onReinstate:u,isRunning:d,isReinstating:f,config:c,formula:n,onPreviewErrorChange:h,signalColumnName:l,onRenameSignalColumn:i})})]})})})}const _r=(t={})=>{const{maxHeightPx:n,enabled:s=!0}=t,[l,i]=a.useState(!1),[c,g]=a.useState(!1),[x,F]=a.useState(0),p=a.useRef(null);return a.useEffect(()=>{if(!s||!n)return;const m=p.current;if(!m)return;const d=()=>{if(m.scrollHeight>n){g(!0);const u=Array.from(m.children),b=m.getBoundingClientRect().top+n,w=u.filter(A=>A.getBoundingClientRect().top>=b);F(w.length)}else g(!1),F(0)},f=new ResizeObserver(d);return f.observe(m),d(),()=>f.disconnect()},[n,s]),{expanded:l,setExpanded:i,hasOverflow:c,overflowCount:x,wrapRef:p}},bt=6,Cr=26,Er=6,Ee=bt*Cr+(bt-1)*Er,Fr=({value:t,onChange:n,registry:s,maxTags:l,disabled:i=!1,error:c})=>{const g=t.filter(S=>s.some(R=>R.key===S)).length,x=l??Number.POSITIVE_INFINITY,F=g>=x,p=t.map(S=>s.find(R=>R.key===S)).filter(S=>!!S),m=s.filter(S=>!t.includes(S.key)),d=[...p,...m],[f,r]=a.useState(Ee),{expanded:u,setExpanded:h,hasOverflow:b,overflowCount:w,wrapRef:A}=_r({maxHeightPx:f,enabled:s.length>0});a.useEffect(()=>{const S=A.current;if(!S)return;const R=()=>
1{if(u)return;const $=p.length;if($===0){r(Ee);return}const _=Array.from(S.children).slice(0,$);if(_.length===0){r(Ee);return}const N=S.getBoundingClientRect().top,D=Math.max(..._.map(I=>I.getBoundingClientRect().bottom-N)),y=Math.max(Ee,Math.ceil(D));r(y)},O=new ResizeObserver(R);return O.observe(S),R(),()=>O.disconnect()},[u,p.length,A]);const L=S=>{F||t.includes(S)||n([...t,S])},P=S=>{n(t.filter(R=>R!==S))};return e.jsxs("div",{className:"flex flex-col gap-3",children:[s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Suggested tags will appear once a framework is selected."}):e.jsxs(e.Fragment,{children:[e.jsx(zs,{expanded:u,maxHeightPx:f,wrapRef:A,children:d.map(({key:S,title:R})=>{const O=t.includes(S),$=i||!O&&F;return e.jsx("button",{type:"button",disabled:$,onClick:()=>O?P(S):L(S),className:de("px-2.5 py-1 text-xs font-normal rounded-full border transition-all",O?"bg-ca-signalOrange/10 border-ca-signalOrange/40 text-ca-signalOrange":c?"border-red-500 bg-red-50 text-red-900 dark:border-red-400 dark:bg-red-100":"bg-transparent border-border text-muted-foreground",$&&"opacity-50 cursor-not-allowed"),children:R},S)})}),b&&e.jsx(Us,{expanded:u,onToggle:()=>h(S=>!S),overflowCount:w}),Number.isFinite(x)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Select up to ",x," tags. ",g,"/",x," selected."]})]}),c&&e.jsx("span",{className:"text-red-600 text-sm",children:c})]})},Ar=({value:t,selectedTier:n,frameworkDataCost:s,platformFeeRate:l,disabled:i,onTierSelect:c,onCustomChange:g,error:x})=>{const F=[10,15,20].map(m=>({pct:m,tokens:Math.max(1,Math.round(s*(m/100)))})),p=s===0;return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"flex items-center justify-between text-sm",children:e.jsx("span",{className:"text-muted-foreground",children:"Your Signal Alpha"})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This is your markup — you earn this (minus"," ",(l*100).toFixed(0),"% platform fee) on each sale."]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("div",{children:e.jsx(Me,{type:"number",placeholder:"0",min:1,value:t,onChange:m=>g(m.target.value),disabled:i,color:x?"failure":void 0,helperText:x})}),e.jsx(dt,{className:"size-3",color:"orange"})]}),e.jsx("span",{className:"text-muted-foreground text-xs mt-2",children:"Recommended Signal Alpha"}),e.jsx("div",{role:"group",className:de("flex w-full overflow-hidden text-xs",p||i?"opacity-50":""),children:F.map(({pct:m,tokens:d})=>{const f=n===m;return e.jsxs("button",{type:"button",disabled:p||i,onClick:()=>c(m,d),className:de("flex flex-1 flex-wrap items-center justify-center gap-2 px-3 py-1.5 transition-colors first:rounded-l-lg last:rounded-r-lg",p||i?"cursor-not-allowed":"cursor-pointer",f?"bg-ca-signalOrange text-white":"bg-secondary dark:bg-ca-600 text-muted-foreground hover:bg-secondary/50 hover:text-foreground"),children:[!p&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-bold",children:d}),e.jsx(dt,{className:"size-2.5",color:f?"white":"orange"})]}),e.jsxs("span",{children:["(",m,"%)"]})]},m)})})]})};function Pr({tag:t,availableTags:n}){const s=n.find(l=>l.key===t);return e.jsx("span",{className:"px-2.5 py-0.5 text-[11px] font-medium rounded-full border bg-secondary text-muted-foreground border-border",children:(s==null?void 0:s.title)??t})}function yt({label:t,required:n,optional:s,htmlFor:l,children:i}){return e.jsxs("div",{children:[e.jsxs(St,{htmlFor:l,className:"mb-2 block text-sm font-medium",children:[t," ",n&&e.jsx("span",{className:"text-ca-signalOrange",children:"*"}),s&&e.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),i]})}const Mr={root:{label:"ms-2 text-xs text-muted-foreground whitespace-nowrap font-normal"},toggle:{base:"relative rounded-full border after:absolute after:rounded-full after:bg-white after:transition-all group-focus:ring-4 group-focus:ring-ca-signalOrange/25",checked:{color:{info:"border-ca-signalOrange bg-ca-signalOrange"}}}},Ne=({label:t,value:n,labelClassName:s,valueClassName:l,containerClassName:i})=>e.jsxs("div",{className:`flex items-center justify-between text-sm ${i||""}`,children:[e.jsx("span",{className:s||"text-muted-foreground",children:t}),e.jsx("span",{className:l||"font-medium",children:n})]}),jt=({icon:t,count:n,singular:s,plural:l})=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t,{className:"size-3 text-muted-foreground
1/70"}),e.jsxs("span",{children:[n," ",n===1?s:l]})]});function Or({name:t,onNameChange:n,description:s,onDescriptionChange:l,effectiveTags:i,onTagsChange:c,availableTags:g,signalAlpha:x,selectedTier:F,frameworkDataCost:p,platformFeeRate:m,priceNum:d,totalListPrice:f,allowPromotionalTokens:r,onAllowPromoChange:u,onTierSelect:h,onCustomAlphaChange:b,showPreview:w,entityCount:A,frameworkCount:L,user:P,onSubmit:S,isSubmitting:R,isLoading:O,selectedFrameworkIds:$,frameworks:o,getFrameworkLabel:_}){const[N,D]=a.useState({}),y=C=>{C.preventDefault();const E={};(!t||t.trim()==="")&&(E.name="Signal name is required"),L===0&&(E.frameworks="Framework is required");const q=parseFloat(x);(!x||x.trim()===""||!isFinite(q)||q<1)&&(E.signalAlpha="Signal Alpha is required"),g.length>0&&i.length===0&&(E.tags="Tag is required"),D(E),!(Object.keys(E).length>0)&&S(C)},I=C=>{n(C),C.trim()!==""&&N.name&&D(E=>({...E,name:void 0}))},B=C=>{b(C);const E=parseFloat(C);C.trim()!==""&&isFinite(E)&&E>=1&&N.signalAlpha&&D(q=>({...q,signalAlpha:void 0}))},j=(C,E)=>{h(C,E),N.signalAlpha&&D(q=>({...q,signalAlpha:void 0}))},M=C=>{c(C),C.length>0&&N.tags&&D(E=>({...E,tags:void 0}))};return a.useEffect(()=>{g.length===0&&N.tags&&D(C=>({...C,tags:void 0}))},[g,N.tags]),a.useEffect(()=>{L>0&&N.frameworks&&D(C=>({...C,frameworks:void 0}))},[L,N.frameworks]),e.jsxs("div",{className:"grid gap-6 grid-cols-2 xl:grid-cols-3",children:[e.jsxs(ke,{className:"col-start-1 row-start-1 rounded-xl bg-white dark:bg-[#19191c] p-6 flex flex-col gap-5",children:[e.jsx("span",{className:"text-lg font-semibold block",children:"Listing Details"}),e.jsxs("form",{id:"create-signal-form",onSubmit:y,className:"flex flex-col gap-5",children:[e.jsx(yt,{label:"Name",required:!0,htmlFor:"name",children:e.jsx(Me,{type:"text",id:"name",placeholder:"e.g., Advertising Count for Apple",value:t,onChange:C=>I(C.target.value),disabled:O,color:N.name?"failure":void 0,helperText:N.name})}),e.jsx(yt,{label:"Description",optional:!0,htmlFor:"description",children:e.jsx(Os,{id:"description",placeholder:"e.g., Daily worldwide data",value:s,onChange:C=>l(C.target.value),rows:2,disabled:O})}),e.jsxs("div",{children:[e.jsxs(St,{className:"mb-2 block text-sm font-medium",children:["Tags",g.length>0&&e.jsx("span",{className:"text-ca-signalOrange",children:"*"})]}),e.jsx(Fr,{value:i,onChange:M,registry:g,disabled:L===0||O,error:N.tags})]})]})]}),e.jsxs(ke,{className:"col-start-1 xl:col-start-2 rounded-xl bg-white dark:bg-[#19191c] p-6 flex flex-col gap-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Pricing"}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg bg-neutral-100 dark:bg-slate-950 p-4",children:[e.jsx(Ne,{label:"Framework Data Cost",value:e.jsx(me.Display,{token:p})}),e.jsx("div",{className:"w-full h-px bg-border"}),e.jsxs("div",{children:[e.jsx(Ne,{label:"Frameworks Selected",value:L}),N.frameworks&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:N.frameworks})]})]}),e.jsx(Ar,{value:x,selectedTier:F,frameworkDataCost:p,platformFeeRate:m,disabled:O,onTierSelect:j,onCustomChange:B,error:N.signalAlpha}),e.jsx("div",{className:"w-full h-px bg-border"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(Ne,{label:"Total List Price",labelClassName:"font-bold",valueClassName:"font-bold text-orange-500",containerClassName:"bg-neutral-100 dark:bg-slate-950 px-6 py-4 -mx-6",value:e.jsx(me.Display,{className:"text-lg size-6",iconColor:"orange",token:f})}),e.jsx("div",{className:"py-2",children:e.jsx(Ne,{label:"Listing Fee",value:e.jsxs("span",{className:"font-medium flex items-center",children:["-",e.jsx(me.Display,{token:(d||0)*m})]})})}),e.jsx("div",{className:"w-full h-px bg-border mb-2"}),e.jsx(Ne,{label:"Earnings per sale",valueClassName:"font-bold text-green-700",containerClassName:"bg-green-50 dark:bg-[#1a211f] px-6 py-4 -mx-6",value:e.jsx(me.Display,{className:"text-green-700",token:(d||0)*(1-m)})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(kt,{id:"allow_promotional_tokens",checked:r,onChange:u,disabled:O,label:"Allow purchase using promotional tokens",
1sizing:"sm",color:"info",theme:Mr}),e.jsx(Is,{content:e.jsxs("div",{className:"max-w-xs space-y-2 p-1",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Primary Tokens:"})," Purchased with real currency, never expire."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Promotional Tokens:"})," Awarded via grants, typically expire in 12 months."]}),e.jsx("p",{className:"text-ca-signalOrange font-medium",children:"Note: If restricted to Primary Tokens only, some buyers may need to purchase more tokens before they can buy your signal."})]}),children:e.jsx(Ws,{className:"size-3.5 text-muted-foreground cursor-help"})})]}),e.jsxs("div",{className:"flex flex-col gap-3 mt-auto pt-4",children:[e.jsx(ye,{primary:!0,type:"submit",form:"create-signal-form",className:"w-full",loading:R,disabled:O,children:"Publish Signal to Marketplace"}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Your signal will be reviewed and typically appears in the marketplace within 24 hours."})]})]}),e.jsxs("div",{className:"col-start-2 row-start-1 row-span-2 xl:col-start-3 xl:row-span-1 flex flex-col gap-4",children:[e.jsx(At,{selectedFrameworkIds:$,frameworks:o,getFrameworkLabel:_,totalDataCost:p,className:"w-full relative top-auto"}),e.jsxs(ke,{className:"rounded-xl bg-white dark:bg-[#19191c] p-6 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ks,{className:"size-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-lg font-semibold",children:"Listing Preview"})]}),w?e.jsxs("div",{className:"flex flex-col gap-2 rounded-xl border border-dashed border-border bg-secondary/30 p-3",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"p-6",children:[i.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:i.map(C=>e.jsx(Pr,{tag:C,availableTags:g},C))}),e.jsx("h3",{className:"text-sm font-semibold text-foreground mb-1 line-clamp-1",children:t}),s&&e.jsx("p",{className:"text-xs text-muted-foreground mb-3 line-clamp-2",children:s}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(jt,{icon:Hs,count:L,singular:"framework",plural:"frameworks"}),e.jsx(jt,{icon:qs,count:A,singular:"entity",plural:"entities"})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-t border-border bg-secondary/30",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:`size-5 rounded-full flex items-center justify-center text-[9px] font-semibold text-white shrink-0 ${fs((P==null?void 0:P.email)||"")}`,children:xs((P==null?void 0:P.email)||"")}),e.jsx("span",{className:"text-[11px] text-muted-foreground truncate",children:((P==null?void 0:P.email)||"").split("@")[0]})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx("div",{className:"text-sm font-bold text-foreground",children:e.jsx(me.Display,{token:f})})})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-[11px] text-muted-foreground px-4 pt-2",children:[e.jsx("span",{children:"Earnings per sale"}),e.jsx(me.Display,{token:(d||0)*(1-m)})]})]}):e.jsx("div",{className:"flex items-center justify-center rounded-xl border border-dashed border-border bg-secondary/30 p-6 min-h-36",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center leading-relaxed",children:"Preview will appear here once the signal name, frameworks, and signal alpha are set."})})]})]})]})}const Dn=()=>{var ot;const[t]=os(),n=Ge(),s=t.get("framework_ids"),l=t.get("signal_id"),{user:i}=Ss(),{userInfo:c,isFetched:g}=_s(),x=!1,{hasUsername:F,isLoading:p}=is(),[m,d]=a.useState([]),[f,r]=a.useState(!1),u=a.useRef(!1),h=a.useCallback(K=>{u.current=K,r(K)},[]),{frameworkIds:b,setFrameworkIds:w,allFrameworkItems:A,pricedFrameworkItems:L,frameworkPage:P,hasMoreFrameworks:S,isLoadingBrowseMore:R,handleBrowseMoreFrameworks:O,isInitialFrameworksLoading:$,isLoadingFrameworks:o,isFetchingFrameworks:_,isFrameworksQueryError:N,isLoadingUrlFrameworks:D,refetchFrameworks:y,excludeListed:I,handleToggleExcludeListed:B,searchQuery:j,setSearchQuery:M,frameworkDataCost:C,entityCount:E,effectiveTags:q,availableTags:re,skipTierResetRef:se,swapReinstatedFrameworks:Z,setSeededFrameworks:ge}=Zs({urlFrameworkIds:s,isEditMode:x,isResumingDraft:!!l,tags:m}),{createSignalMutation:ne,reinstateMutation:W,createDraftMutation:X,updateDraftMutation:ie,deleteDraftMutation:G}=Xs({setFrameworkIds:w,swapReinstatedFrameworks:Z,skipTierResetRef:se,draftSignalId:l,setHasUnsavedChanges:h}),{formula:H,setFormula:le,signalColumnName:Y,setSignalColumnName:ce,executionConfig:Oe,setExecutionConfig:k,currentResult:T,resetResult:v,insertTextRef:z,formulaFrameworks:U,referencesJson:J,formulaValidation:ae,handleRunFormula:ee,isPreviewPending:ue}=ir({frameworkIds:b,pricedFrameworkItems:L}),{name:V,setName:fe,description:ve,setDescription:xe,signalAlpha:Qe,setSignalAlpha:Ie,selectedTier:Pt,setSelectedTier:Ve,allowPromotionalTokens:Ze,setAllowPromotionalTokens:Se,priceNum:Mt,platformFeeRate:Ot,totalListPrice:It,showPreview:Dt,handleTierSelect:Tt,handleCustomAlphaChange:Lt,handleSubmit:Rt,showUsernameModal:$t,closeUsernameModal:Bt,handleUsernameModalSuccess:zt,handleUsernameModalCancel:Ut}=cr({frameworkDataCost:C,effectiveTags:q,formula:H,signalColumnName:Y,formulaFrameworks:U,referencesJson:J,executionConfig:Oe,frameworkIds:b,hasUsername:F,createSignalMutation:ne}),[Ht,qt]=a.useState(!1),{listingType:te,setListingType:Xe,currentStep:oe,setCurrentStep:De,derivedFrameworkEnabled:Ye,steps:Wt,stepSubtitles:Kt,pageSubtitle:Gt,isLastStep:Je,isListingDetailsStep:Qt,canProceed:et,handleNext:Vt,handleBack:tt,handleStepClick:Zt,completedSteps:Xt,clearCompletedStepsAfter:st,markStepCompleted:Yt}=Ys({isEditMode:x,isResumingDraft:!!l,signalDerivedFrameworkEnabled:Cs.featureFlags.signalDerivedFrameworkEnabled,hasSignalDerivedFrameworkFlag:((ot=c==null?void 0:c.feature_flags)==null?void 0:ot.signal_derived_framework)===!0,hasFormulaPreviewError:Ht,isUserInfoFetched:g,navigate:n,frameworkIds:b,formula:H,formulaValidation:ae}),rt=a.useRef(!1),_e=a.useRef(null);a.useEffect(()=>{if(!rt.current){rt.current=!0;return}if(se.current){se.current=!1;return}le(""),ce(""),k(qe),v(),Ve(null),Ie(""),fe(""),xe(""),d([]),Se(!0),st(2),_e.current=null,De(K=>K>2?2:K)},[b]),a.useEffect(()=>{if(te!=="signal"||oe!==4)return;const K=_e.current;K!==null&&K!==H&&(Ve(null),Ie(""),fe(""),xe(""),d([]),Se(!0),st(3),Yt(4)),_e.current=H},[oe,te,H]);const nt=a.useRef(te);a.useEffect(()=>{if(te===null)return;const K=nt.current;K!==null&&K!==te&&(le(""),ce(""),k(qe),v(),_e.current=null),nt.current=te},[te,le,ce,k,v]);const{hasActiveTickers:at}=Ts(),[Jt,Te]=a.useState(!1),{isDraftMode:es,isLoadingDraft:ts,handleSaveDraft:ss,handleDeleteDraft:rs,blocker:we}=dr({draftSignalId:l,listingType:te,currentStep:oe,hasUnsavedChanges:f,hasUnsavedChangesRef:u,setHasUnsavedChanges:h,name:V,description:ve,frameworkIds:b,signalAlpha:Qe,tags:m,allowPromotionalTokens:Ze,formula:H,signalColumnName:Y,referencesJson:J,formulaFrameworks:U,setListingType:Xe,setFrameworkIds:w,setSeededFrameworks:ge,setFormula:le,setSignalColumnName:ce,setName:fe,setDescription:xe,setTags:d,setSignalAlpha:Ie,setAllowPromotionalTokens:Se,setCurrentStep:De,skipTierResetRef:se,createDraftMutation:X,updateDraftMutation:ie,deleteDraftMutation:G}),Le=a.useRef(!1);a.useEffect(()=>{G.isPending?Le.current=!0:Le.current&&(Le.current=!1,Te(!1))},[G.isPending]);const pe=ts||ne.isPending||X.isPending||ie.isPending||G.isPending||D||p;return e.jsxs(e.Fragment,{children:[$t&&e.jsx(bs,{onClose:Bt,onSuccess:zt,onCancel:Ut}),e.jsx(lt,{header:"Leave without saving?",description:"You have unsaved changes that will be lost if you leave this page.",isOpen:we.state==="blocked",onClose:()=>we.state==="blocked"&&we.reset(),onConfirm:()=>we.state==="blocked"&&we.proceed(),confirmText:"Leave"}),e.jsx(lt,{header:"Delete Draft",description:"Are you sure you want to delete this draft?",isOpen:Jt,onClose:()=>Te(!1),onConfirm:rs,loading:G.isPending,confirmText:"Delete"}),e.jsxs("div",{className:de("flex flex-col w-full min-h-screen bg-background",{[Ds]:at,"pt-16 lg:pt-20":!at}),children:[e.jsx("div",{className:"max-w-7xl w-full mx-auto px-4 py-6 flex-1 flex flex-col",children:e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:tt,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors mb-6",children:[e.jsx(ut,{className:"size-4"}),"Back"]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-xl font-semibold block",children:"List on Exchange"}),e.jsx("span",{className:"text-sm text-muted-foreground block",children:Gt})]}),e.jsx(ur,{currentStep:Ye&&!x?oe:oe-1,labels:Wt,subtitles:Kt,onStepClick:Zt,canGoForward:et&&!Je,completedSteps:Xt,disabled:pe||W.isPending||ue}),Ye&&oe===1&&e.jsx(fr,{selected:te,onSelect:K=>{Xe(K),De(Re=>Re+1)}}),oe===2&&e.jsx(vr,{compact:te==="collection",searchQuery:j,onSearchChange:M,excludeListed:I,onToggleExcludeListed:B,frameworks:L,allFrameworkItems:A,selectedFrameworkIds:b,onChangeSelectedFrameworkIds:w,getFrameworkLabel:We,originalFrameworkIds:[],isDisabled:pe||$,frameworkPage:P,isLoadingFrameworks:o||D,isFetchingFrameworks:_,isFrameworksQueryError:N,isLoadingBrowseMore:R,onRetry:y,showBrowseMore:S,onBrowseMore:O,totalDataCost:C,frameworkAliases:te==="signal"?Object.fromEntries(U.map(K=>[K.framework_id,K.alias])):void 0,formulaFrameworks:te==="signal"?U:void 0,onRemoveFramework:K=>w(Re=>Re.filter(ns=>ns!==K))}),oe===3&&te==="signal"&&e.jsx(Sr,{formulaFrameworks:U,formula:H,onFormulaChange:le,signalColumnName:Y,onSignalColumnNameChange:ce,config:Oe,onConfigChange:k,currentResult:T,onClearResult:v,validation:ae,onRun:ee,isRunning:ue,isReinstating:W.isPending,insertTextRef:z,onReinstate:K=>{W.mutate(K)},onPreviewErrorChange:qt}),Qt&&e.jsx(Or,{name:V,onNameChange:fe,description:ve,onDescriptionChange:xe,effectiveTags:q,onTagsChange:d,availableTags:re,signalAlpha:Qe,selectedTier:Pt,frameworkDataCost:C,platformFeeRate:Ot,priceNum:Mt,totalListPrice:It,allowPromotionalTokens:Ze,onAllowPromoChange:Se,onTierSelect:Tt,onCustomAlphaChange:Lt,showPreview:Dt,entityCount:E,frameworkCount:b.length,user:i,onSubmit:K=>Rt(K,te),isSubmitting:ne.isPending,isLoading:pe,selectedFrameworkIds:b,frameworks:L,getFrameworkLabel:We})]})}),e.jsxs("div",{className:"max-w-7xl w-full mx-auto flex justify-between items-center px-4 py-5 2xl:px-0 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ye,{type:"button",color:"light",onClick:tt,disabled:pe||W.isPending||ue||oe===2&&$,className:"focus:ring-0",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm",children:[e.jsx(ut,{className:"size-4"}),"Back"]})}),es&&e.jsx(ye,{type:"button",color:"light",onClick:()=>Te(!0),disabled:pe||W.isPending||ue,loading:G.isPending,className:"focus:ring-0 text-red-600 hover:text-red-700",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm",children:[e.jsx(Gs,{className:"size-4"}),"Delete Draft"]})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[oe>=2&&e.jsx(ye,{type:"button",color:"light",onClick:ss,disabled:pe||W.isPending||ue||X.isPending||ie.isPending||oe===2&&b.length===0,loading:X.isPending||ie.isPending,className:"focus:ring-0",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm",children:[e.jsx(Qs,{className:"size-4"}),"Save as Draft"]})}),!Je&&oe!==1?e.jsxs(ye,{primary:!0,type:"button",onClick:Vt,disabled:!et||pe||W.isPending||ue,children:["Continue ",e.jsx(Vs,{className:"size-4 ml-1 inline"})]}):null]})]})]})]})};export{Dn 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.