1import{r as f,j as e}from"./react-BJCrwb27.js";import{Y as F,w as A,Q as N,z as V,V as G}from"./route-support-BEJAjkqU.js";import{R as T}from"./RevenueOverTimeChart-Bs2rJ8fA.js";import{bK as E,bL as U,bM as $,bN as I,bG as O}from"./index-Cok8iJMB.js";import{c as k,f as g}from"./creatorPortal-188mXP-S.js";import{P as z,a as Q,C as L,b as W}from"./components-BrcHjtLw.js";import{R as H,C as K}from"./ResilientMedia-BplRjQo7.js";import{VideoPlayerModal as Y}from"./VideoPlayer-KPEiL8LF.js";import{d as Z,S as q}from"./LegacyStatCard-BX5KLrud.js";import"./vendor-DIeMxnSD.js";import"./tanstack-BOscu_PA.js";import"./sample-display-Bk_79GLP.js";import"./RemoteVideoTranscript-DaZRi_f8.js";import"./metricValueClass-CAz524vd.js";import"./AnimatedNumber-CyNAVZ7E.js";function j({changePct:i,changePeriod:n,hero:a=!1,label:s,tooltip:m,value:t}){const o=Number(i),p=Number.isFinite(o),d=Math.round(Math.abs(o)*10)/10;return e.jsx(Q,{hero:a,label:s,tooltip:m,value:t,children:p?e.jsx(q,{change:`${d}%`,directionUp:o>=0,neutral:o===0,period:n,positive:o>=0}):null})}function R({kind:i,rows:n}){return n.length?i==="platform"?e.jsx("div",{"aria-label":"Attributed GMV by platform",children:n.map(a=>{const s=a.key==="tiktok"?"tiktok_shop":a.key==="meta"?"meta":null;return e.jsxs("div",{className:"platform-row",children:[e.jsxs("div",{className:"platform-left",children:[s?e.jsx(G,{platform:s}):e.jsx("div",{"aria-hidden":"true",className:"platform-icon",children:"â¢"}),e.jsx("div",{className:"platform-name",children:a.label})]}),e.jsxs("div",{className:"platform-right",children:[e.jsx("div",{className:"platform-bar-wrap",children:e.jsx("div",{className:"platform-bar",style:{background:a.key==="meta"?"#0081fb":a.key==="tiktok"?"#fe2c55":"var(--text3)",width:`${Math.max(3,a.pct||0)}%`}})}),e.jsxs("div",{className:"platform-val-badge",children:[e.jsx("span",{children:k(a.gmv)}),e.jsxs("span",{className:"platform-val-chg",style:{color:"var(--text3)"},children:[a.pct,"%"]})]})]})]},a.key)})}):e.jsx("div",{"aria-label":"Attributed GMV by brand",className:"creator-dash-breakdown",children:n.slice(0,5).map(a=>e.jsxs("div",{className:"creator-dash-breakdown-row",children:[e.jsxs("div",{className:"creator-dash-breakdown-main",children:[e.jsx(W,{brandId:a.key,logoLocked:a.logo_locked,logoUrl:a.logo_url,name:a.label,size:30}),e.jsxs("div",{children:[e.jsx("div",{className:"creator-dash-breakdown-name",children:a.label}),e.jsxs("div",{className:"creator-dash-breakdown-sub",children:[a.orders," order",a.orders===1?"":"s"]})]})]}),e.jsx("div",{"aria-hidden":"true",className:"creator-dash-breakdown-meter",children:e.jsx("span",{style:{width:`${Math.max(3,a.pct||0)}%`}})}),e.jsxs("div",{className:"creator-dash-breakdown-value",children:[e.jsx("strong",{children:k(a.gmv)}),e.jsxs("span",{children:[a.pct,"%"]})]})]},a.key))}):e.jsx(L,{children:"No attributed GMV in this range yet."})}function J(i,n,a=Date.now()){if(n==="all")return!0;if(!i.posted_at)return!1;const s=new Date(i.posted_at).getTime();if(!Number.isFinite(s)||s>a)return!1;if(typeof n=="string"&&n.startsWith("custom:")){const[,t,o]=n.split(":"),p=new Date(`${t}T00:00:00`).getTime(),d=new Date(`${o}T23:59:59.999`).getTime();return!Number.isFinite(p)||!Number.isFinite(d)?!1:s>=p&&s<=d}const m=n==="24h"?1:n==="7d"?7:n==="90d"?90:30;return a-s<=m*24*60*60*1e3}function X({brandId:i,failed:n,items:a,loading:s,onRetry:m,range:t}){const[o,p]=f.useState(""),d=f.useMemo(()=>a.filter(l=>{var c;return J(l,t)&&(!i||((c=l.brand_ids)==null?void 0:c.includes(i)))}).sort((l,c)=>(Number(c.views)||0)-(Number(l.views)||0)).slice(0,4),[i,a,t]);return s?e.jsx(V,{className:"h-40 w-full"}):n&&!d.length?e.jsx(N,{onRetry:m,title:"Posts did not load",variant:"inline"}):d.length?e.jsxs(e.Fragment,{children:[n?e.jsx(N,{onRetry:m,title:"Posts could not refresh. Showing previously loaded posts.",variant:"inline"}):null,e.jsx("div",{className:"creator-dash-videos",children:d.map((l,c)=>{var u;return e.jsxs("button",{className:"creator-dash-video",disabled:!l.url,onClick:()=>{l.url&&p(l.url)},type:"button",children:[e.jsxs("div",{className:"creator-dash-video-thumb",children:[e.jsx(H,{fallback:e.jsx(K,{label:"No preview"}),src:l.thumbnail}),e.jsx("span",{children:l.platform||"post"})]}),e.jsxs("div",{className:"creator-dash-video-body",children:[e.jsx("div",{children:((u=l.caption)==null?void 0:u.trim())||"Untitled post"}),e.jsxs("span",{children:[g(l.views)," views · ",g(l.likes)," likes"]}
1)]})]},`${l.url||l.caption||c}`)})}),o?e.jsx(Y,{onClose:()=>p(""),url:o}):null]}):e.jsx(L,{children:"No posts in this range yet."})}function ee({brandId:i,brands:n,content:a,contentFailed:s=!1,contentLoading:m=!1,dashboard:t,dashboardFailed:o=!1,dashboardLoading:p=!1,onBrandChange:d,onContentRetry:l,onDashboardRetry:c,range:u}){var y,M,S,w,P;const r=t==null?void 0:t.summary,_=f.useMemo(()=>n.filter((h,x,B)=>!!h.brand_id&&B.findIndex(D=>D.brand_id===h.brand_id)===x).map(h=>({label:h.brand_name,value:h.brand_id})).sort((h,x)=>h.label.localeCompare(x.label)),[n]),b=t==null?void 0:t.series,C=f.useMemo(()=>({labels:(b==null?void 0:b.map(h=>h.label))??null,points:(b==null?void 0:b.map(h=>h.total))??null}),[b]),v=Z(u);return e.jsxs("div",{className:"creator-dashboard","data-testid":"creator-performance-dashboard",children:[e.jsx("h1",{className:"sr-only",children:"Creator performance dashboard"}),e.jsx("div",{"aria-label":"Dashboard filters",className:"creator-dashboard-filters",role:"group",children:e.jsx(O,{ariaLabel:"Filter dashboard by brand",className:"filter-select creator-range-select",disabled:!_.length,onChange:d,options:[{value:"",label:"All brands"},..._],searchable:!0,searchEmptyMessage:"No matching brands",searchPlaceholder:"Search brands",value:i})}),o&&t?e.jsx(N,{onRetry:c,title:"Sales attribution could not refresh. Showing your last saved totals. They may be out of date.",variant:"inline"}):null,o&&!t?e.jsx(N,{description:"No totals have been changed. Retry to load your tracked sales.",onRetry:c,title:"Sales attribution did not load"}):e.jsxs(e.Fragment,{children:[e.jsx(z,{children:p&&!t?Array.from({length:5}).map((h,x)=>e.jsx(V,{className:"h-[120px]"},x)):e.jsxs(e.Fragment,{children:[e.jsx(j,{changePct:(y=r==null?void 0:r.changes)==null?void 0:y.attributed_gmv_pct,changePeriod:v,hero:!0,label:"GMV",tooltip:"Attributed GMV from sales in the selected date range.",value:k(r==null?void 0:r.attributed_gmv)}),e.jsx(j,{changePct:(M=r==null?void 0:r.changes)==null?void 0:M.active_brands_pct,changePeriod:v,label:"Brands",tooltip:"Brands with at least one attributed sale in the selected date range.",value:g(r==null?void 0:r.active_brands)}),e.jsx(j,{changePct:(S=r==null?void 0:r.changes)==null?void 0:S.orders_pct,changePeriod:v,label:"# of Sales",tooltip:"Attributed sales in the selected date range.",value:g(r==null?void 0:r.orders)}),e.jsx(j,{changePct:(w=r==null?void 0:r.changes)==null?void 0:w.avg_order_value_pct,changePeriod:v,label:"AOV",tooltip:"Attributed GMV divided by attributed sales in the selected date range.",value:k(r==null?void 0:r.avg_order_value)}),e.jsx(j,{changePct:(P=r==null?void 0:r.changes)==null?void 0:P.submitted_videos_pct,changePeriod:v,label:"# of Videos",tooltip:"Videos submitted to brands in the selected date range.",value:g(r==null?void 0:r.submitted_videos)})]})}),e.jsxs("div",{className:"grid-2-1 creator-performance-row",children:[e.jsxs("section",{"aria-labelledby":"creator-performance-time",className:"card creator-performance-card",children:[e.jsx("div",{className:"card-hd creator-performance-card-head",children:e.jsx("div",{children:e.jsx("div",{className:"card-title",id:"creator-performance-time",children:"Performance over time"})})}),e.jsx(T,{ariaLabel:"Attributed GMV over time",emptyMessage:"No attributed sales in this range yet.",labels:C.labels,points:C.points,showZeroSeries:!1})]}),e.jsxs("section",{"aria-labelledby":"creator-platform-breakdown",className:"card creator-performance-card",children:[e.jsx("div",{className:"card-hd creator-performance-card-head",children:e.jsx("div",{children:e.jsx("div",{className:"card-title",id:"creator-platform-breakdown",children:"Platform breakdown"})})}),e.jsx(R,{kind:"platform",rows:(t==null?void 0:t.platform_breakdown)??[]})]})]}),e.jsxs("div",{className:"grid-2 creator-performance-row",children:[e.jsxs("section",{"aria-labelledby":"creator-brand-gmv",className:"card creator-performance-card",children:[e.jsx("div",{className:"card-hd creator-performance-card-head",children:e.jsx("div",{children:e.jsx("div",{className:"card-title",id:"creator-brand-gmv",children:"Brand GMV"})})}),e.jsx(R,{kind:"brand",rows:(t==null?void 0:t.brand_breakdown)??[]})]}
1),e.jsxs("section",{"aria-labelledby":"creator-top-videos",className:"card creator-performance-card",children:[e.jsx("div",{className:"card-hd creator-performance-card-head",children:e.jsx("div",{children:e.jsx("div",{className:"card-title",id:"creator-top-videos",children:"Top videos"})})}),e.jsx(X,{brandId:i,failed:s,items:a,loading:m,onRetry:l,range:u})]})]})]})]})}function ue(){var l,c;const[i,n]=f.useState(""),{creatorDashboardRange:a}=E(),s=U(a,i);F(s);const m=!s.isPending;$(m);const t=I(m),[o,p]=f.useState([]),d=(l=s.data)==null?void 0:l.linked_brands;return d&&d!==o&&p(d),f.useEffect(()=>{A("route")},[]),e.jsx(e.Fragment,{children:e.jsx(ee,{brandId:i,brands:o,content:((c=t.data)==null?void 0:c.items)??[],contentFailed:t.isError,contentLoading:t.isLoading&&!t.data,dashboard:s.data,dashboardFailed:s.isError,dashboardLoading:s.isLoading&&!s.data,onBrandChange:n,onContentRetry:()=>{t.refetch()},onDashboardRetry:()=>{s.refetch()},range:a})})}export{ue as CreatorHome,ee as CreatorPerformanceDashboard,J as postedInRange};
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.