1import{j as t,a as F}from"./react-query-DtH7GInu.js";import{r as y}from"./charts-DXTQz_Nw.js";import{C as _,al as h,o as R,bu as d,cY as U,bn as q,n as P,by as k,aM as K,cR as M,w as m}from"./index-Bk2jHtle.js";import{L as W}from"./vendors-C_aCOv2N.js";import{A as Y}from"./AddToMyEventsButton-D-3PSc-5.js";import{cw as H,cx as z,aZ as D,a4 as Q,a5 as G}from"./ui-components-BYDPAGXP.js";import{CalendarService as V}from"./calendarService-Dsfupc46.js";import{u as Z}from"./useStockLogos-RUb4ts1-.js";function O({event:e,logoUrl:s}){const[a,r]=y.useState(!1),i=e.date instanceof Date?e.date:new Date(e.date),n=ee(i),o=se(e.time),c=ae(e.fiscalDateEnding),l=$(e.eps,e.epsEstimate),g=$(e.revenue,e.revenueEstimate);return t.jsxs(_,{className:h("group relative overflow-hidden h-full","bg-gradient-to-br from-card via-card to-primary/5","border border-border/60 hover:border-primary/40","transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5"),children:[t.jsx("div",{className:h("absolute inset-x-0 top-0 h-0.5 bg-gradient-to-r",n?"from-transparent via-muted-foreground/30 to-transparent":"from-transparent via-primary/60 to-transparent","opacity-60 group-hover:opacity-100 transition-opacity")}),t.jsxs("div",{className:h("p-4 md:p-5","grid gap-4 md:gap-6","grid-cols-[auto_1fr] md:grid-cols-[auto_minmax(0,1fr)_auto_auto]","md:items-center"),children:[t.jsx(J,{date:i}),t.jsxs("div",{className:"min-w-0 flex items-center gap-3",children:[s&&!a?t.jsx("div",{className:"w-10 h-10 rounded-lg bg-white shadow-sm border border-border/40 p-1 flex items-center justify-center flex-shrink-0",children:t.jsx("img",{src:s,alt:"",className:"max-w-full max-h-full object-contain",onError:()=>r(!0)})}):t.jsx("div",{className:"w-10 h-10 rounded-lg bg-gradient-to-br from-primary/15 to-primary/25 flex items-center justify-center flex-shrink-0",children:t.jsx("span",{className:"text-xs font-bold text-primary",children:e.symbol.substring(0,2)})}),t.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx(W,{to:`/stocks/${e.symbol}`,className:"font-bold text-base sm:text-lg tracking-tight text-foreground hover:text-primary transition-colors",children:e.symbol}),n&&t.jsx(R,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 leading-none border-muted-foreground/30 text-muted-foreground font-medium",children:"Released"})]}),te(e)&&t.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground truncate leading-tight",title:e.companyName,children:e.companyName}),t.jsx(X,{session:o})]})]}),t.jsxs("div",{className:h("col-span-2 md:col-span-1","flex items-center gap-5 md:gap-6","md:pl-6 md:border-l md:border-border/60","md:min-w-[180px]"),children:[t.jsx(C,{label:n?"EPS":"EPS est.",primary:n&&e.eps!=null?E(e.eps):e.epsEstimate!=null?E(e.epsEstimate):"â",beat:n?l:null}),t.jsx(C,{label:n?"Rev":"Rev est.",primary:n&&e.revenue!=null?w(e.revenue):e.revenueEstimate!=null?w(e.revenueEstimate):"â",beat:n?g:null})]}),t.jsxs("div",{className:h("col-span-2 md:col-span-1","flex items-center justify-between gap-3","md:flex-col md:items-end md:justify-center md:gap-2","md:pl-6 md:border-l md:border-border/60","md:min-w-[130px]"),children:[t.jsxs("div",{className:"text-left md:text-right leading-tight min-h-[2.25rem] flex flex-col justify-center",children:[e.marketCap!=null&&e.marketCap>0?t.jsx("p",{className:"text-sm font-semibold tracking-tight",children:w(e.marketCap,{prefix:"$"})}):t.jsx("p",{className:"text-xs text-muted-foreground/60",children:"Mkt cap â"}),c&&t.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:c})]}),t.jsx(Y,{event:e,variant:"outline",size:"sm",showLabel:!0})]})]})]})}function J({date:e}){const s=d(e,"MMM").toUpperCase(),a=d(e,"d"),r=d(e,"EEE").toUpperCase();return t.jsxs("div",{className:h("flex-shrink-0 w-14 sm:w-16 rounded-xl overflow-hidden","bg-gradient-to-br from-primary/10 via-primary/15 to-primary/20","border border-primary/20 shadow-sm","text-center"),children:[t.jsx("div",{className:"px-2 py-1 bg-primary/15 text-[10px] font-semibold tracking-wider text-primary",children:s}),t.jsxs("div",{className:"py-1.5 sm:py-2",children:[t.jsx("div",{className:"text-xl sm:text-2xl font-bold leading-none text-foreground",children:a}),t.jsx("div",{className:"text-[10px] font-medium tracking-wider text-muted-foreground mt-1",children:r})]})]})}function X({session:e}){return e==="bmo"?t.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-muted-foreground",children:[t.jsx(H,{className:"h-3.5 w-3.5 text-amber-500"}),t.jsx("span",{children:"Before Open"})]}):e==="amc"?t.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-muted-foreground",children:[t.jsx(z,{className:"h-3.5 w-3.5 text-blue-500"}),t.jsx("span",{children:"After Close"})]}):e==="dmh"?t.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-muted-foreground",children:[t.jsx(D,{className:"h-3.5 w-3.5 text-primary"}),t.jsx("span",{children:"During Market"})]}):t.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-muted-foreground
1/70",children:[t.jsx(D,{className:"h-3.5 w-3.5"}),t.jsx("span",{children:"Time TBD"})]})}function C({label:e,primary:s,beat:a}){const r=a?.direction==="beat",i=a?.direction==="miss";return t.jsxs("div",{className:"space-y-0.5",children:[t.jsx("p",{className:"text-[11px] uppercase tracking-wider text-muted-foreground/80",children:e}),t.jsx("p",{className:h("text-base sm:text-lg font-semibold tracking-tight",r&&"text-emerald-600 dark:text-emerald-400",i&&"text-rose-600 dark:text-rose-400"),children:s}),a&&t.jsxs("div",{className:h("inline-flex items-center gap-0.5 text-[10px] font-medium",r&&"text-emerald-600 dark:text-emerald-400",i&&"text-rose-600 dark:text-rose-400"),children:[r?t.jsx(Q,{className:"h-2.5 w-2.5"}):t.jsx(G,{className:"h-2.5 w-2.5"}),r?"+":"",a.delta.toFixed(2),"%"]})]})}function ee(e){return e.getTime()<Date.now()}function te(e){const s=e.companyName?.trim();return s?s.toUpperCase()!==e.symbol.toUpperCase():!1}function se(e){if(!e)return"tbd";const s=e.toLowerCase();return s==="bmo"||s==="before-market"?"bmo":s==="amc"||s==="after-market"?"amc":s==="dmh"||s==="during-market"?"dmh":"tbd"}function E(e){return`${e<0?"-":""}$${Math.abs(e).toFixed(2)}`}function w(e,{prefix:s=""}={}){const a=Math.abs(e),r=e<0?"-":"";return a>=1e12?`${r}${s}${(a/1e12).toFixed(2)}T`:a>=1e9?`${r}${s}${(a/1e9).toFixed(2)}B`:a>=1e6?`${r}${s}${(a/1e6).toFixed(2)}M`:a>=1e3?`${r}${s}${(a/1e3).toFixed(1)}K`:`${r}${s}${a.toFixed(0)}`}function $(e,s){if(e==null||s==null||s===0)return null;const a=(e-s)/Math.abs(s)*100;return Math.abs(a)<.01?null:{delta:a,direction:a>0?"beat":"miss"}}function ae(e){if(!e)return null;const s=new Date(e);if(Number.isNaN(s.getTime()))return null;const a=s.getMonth()+1;return`Fiscal Q${Math.ceil(a/3)} ${s.getFullYear()}`}const re={all:["calendar"],events:(e,s,a)=>["calendar","events",d(e,"yyyy-MM-dd"),d(s,"yyyy-MM-dd"),a],earnings:(e,s)=>["calendar","earnings",d(e,"yyyy-MM-dd"),d(s,"yyyy-MM-dd")],dividends:(e,s)=>["calendar","dividends",d(e,"yyyy-MM-dd"),d(s,"yyyy-MM-dd")],splits:(e,s)=>["calendar","splits",d(e,"yyyy-MM-dd"),d(s,"yyyy-MM-dd")],ipos:(e,s)=>["calendar","ipos",d(e,"yyyy-MM-dd"),d(s,"yyyy-MM-dd")]};function ne(e,s){const a=new Date;a.setHours(0,0,0,0);const r=new Date(a);r.setDate(r.getDate()-7);const i=new Date(a);return i.setDate(i.getDate()+7),s<r?24*60*60*1e3:s<a?12*60*60*1e3:e<=a&&s>=a?60*60*1e3:e<i?6*60*60*1e3:12*60*60*1e3}function ie(e,s){const a=new Date;return a.setHours(0,0,0,0),s<a?7*24*60*60*1e3:24*60*60*1e3}function oe({from:e,to:s,eventTypes:a,enabled:r=!0,watchlistOnly:i=!1,country:n="ALL"}){U(),console.log("ð [useCalendarEvents] Hook called:",{from:d(e,"yyyy-MM-dd"),to:d(s,"yyyy-MM-dd"),eventTypes:a,country:n,watchlistOnly:i,enabled:r});let o=[];try{const{getStockSymbols:l}=q();o=i?l():[]}catch{console.warn("WatchlistContext not available for calendar")}const c=[...re.events(e,s,a),n,"v6-simple"];return console.log("ð [useCalendarEvents] Query key:",c),F({queryKey:c,queryFn:async({signal:l})=>{console.log("ð [useCalendarEvents] queryFn executing - fetching from API...");const g=l?.reason==="refetch",u=await V.fetchAllEvents(e,s,a,n,g);console.log("ð [useCalendarEvents] API returned:",{eventsLength:u?.length,firstEventDate:u?.[0]?.date,lastEventDate:u?.[u.length-1]?.date,sampleSymbols:u?.slice(0,5).map(f=>`${f.symbol}:${f.date}`)});const x=u?.find(f=>f.type==="dividend");if(x&&console.log("ð [useCalendarEvents] First dividend after transformation:",{symbol:x.symbol,marketCap:x.marketCap,dividendYield:x.dividendYield,dividendAmount:x.dividendAmount}),i&&o.length>0){const f=u.filter(j=>o.includes(j.symbol));return console.log("ð [useCalendarEvents] After watchlist filter:",f.length),f}return console.log("ð [useCalendarEvents] Returning:",u.length,"events (no watchlist filter)"),u},enabled:r,staleTime:ne(e,s),gcTime:ie(e,s),refetchInterval:!1,refetchIntervalInBackground:!1,retry:3,retryDelay:l=>Math.min(1e3*2**l,3e4)})}function le(e){const s=y.useMemo(()=>[...e].sort().join(","),[e]);return F({queryKey:["company-profiles-mcap",s],queryFn:async()=>{if(e.length===0)return{};const{data:a,error:r}=await P.from("company_profiles_cache").select("symbol, market_cap").in("symbol",e);if(r)throw console.error("[useEventMarketCaps] query failed:",r),r;const i={};for(const n of a??[])n.market_cap!=null&&n.market_cap>0&&(i[n.symbol]=Number(n.market_cap));return i},staleTime:24*60*60*1e3,gcTime:48*60*60*1e3,enabled:e.length>0})}const T=14;function de({minResults:e=4,maxResults:s=6}={}){const a=y.useMemo(()=>k(new Date),[]),r=y.useMemo(()=>K(a,T),[a]),{data:i,isLoading:n,isError:o}=oe({from:a,to:r,eventTypes:["earnings"],country:"ALL"}),c=y.useMemo(()=>Array.from(new Set((i??[]).map(x=>x.symbol))),[i]),{data:l,isLoading:g}=le(c);return{events:y.useMemo(()=>{const x=i??[],f=l??{},j=a.getTime(),B=r.getTime(),N=x.filter(p=>{const b=p.date instanceof Date?p.date:new Date(p.date),I=b.getTime();return k(b).getTime()>=j&&I<=B}),v=N.map(p=>{const b=f[p.symbol];return b?{...p,marketCap:p.marketCap??b}:null}).filter(p=>p!==null);return v.length>=e?L(S(v,s)):L(S(N,s))},[i,l,a,r,s,e]),isLoading:n||g,isError:o,windowDays:T}}function S(e,s){const a=[...e].sort((o,c)=>(c.marketCap??0)-(o.marketCap??0)),r=new Map;for(const o of a){const c=o.date instanceof Date?o.date:new Date(o.date),l=d(c,"yyyy-MM-dd"),g=r.get(l);g?g.push(o):r.set(l,[o])}const i=[...r.keys()].sort(),n=[];for(;n.length<s;){let o=!1;for(const c of i){const l=r.get(c);if(l&&l.length>0&&(n.push(l.shift()),o=!0,n.length>=s))break}if(!o)break}return n}function L(e){return[...e].sort((s,a)=>{const r=s.date instanceof Date?s.date.getTime():new Date(s.date).getTime(),i=a.date instanceof Date?a.date.getTime():new Date(a.date).getTime();return r-i})}const A="flex-shrink-0 w-[88vw] sm:w-[36rem] md:w-[40rem]";function ye({config:e}){const{events:s,isLoading:a}=de({minResults:e?.min_results??4,maxResults:e?.max_results??6,initialWindowDays:e?.initial_window_days??7}),r=y.useMemo(()=>s.map(n=>n.symbol),[s]),{data:i}=Z(r);return a?t.jsx(M,{headingId:"upcoming-earnings-heading",title:"Upcoming Earnings",subtitle:e?.subtitle??"Major companies reporting this week and next",linkTo:"/calendar?type=earnings",linkLabel:"View calendar",contentSignal:0,children:Array.from({length:3}).map((n,o)=>t.jsx("div",{className:A,children:t.jsx(_,{className:"p-4 md:p-5 h-full",children:t.jsxs("div",{className:"flex flex-col md:flex-row gap-4 md:gap-5",children:[t.jsxs("div",{className:"flex items-start gap-4 md:flex-1",children:[t.jsx(m,{className:"w-14 sm:w-16 h-16 rounded-xl"}),t.jsxs("div",{className:"flex-1 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(m,{className:"w-9 h-9 rounded-lg"}),t.jsxs("div",{className:"space-y-1.5 flex-1",children:[t.jsx(m,{className:"h-4 w-20"}),t.jsx(m,{className:"h-3 w-32"})]})]}),t.jsx(m,{className:"h-3 w-28"})]})]}),t.jsx("div",{className:"hidden md:block w-px self-stretch bg-border/60"}),t.jsxs("div",{className:"grid grid-cols-2 gap-3 md:gap-4 md:min-w-[200px]",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(m,{className:"h-2 w-12"}),t.jsx(m,{className:"h-5 w-16"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(m,{className:"h-2 w-12"}),t.jsx(m,{className:"h-5 w-16"})]})]}),t.jsx("div",{className:"hidden md:block w-px self-stretch bg-border/60"}),t.jsxs("div",{className:"flex md:flex-col gap-2 md:min-w-[140px]",children:[t.jsx(m,{className:"h-4 w-20 ml-auto"}),t.jsx(m,{className:"h-8 w-32 ml-auto"})]})]})})},o))}):s.length===0?null:t.jsx(M,{headingId:"upcoming-earnings-heading",title:"Upcoming Earnings",subtitle:e?.subtitle??"Major companies reporting this week and next",linkTo:"/calendar?type=earnings",linkLabel:"View calendar",contentSignal:s.length,children:s.map(n=>t.jsx("div",{className:A,children:t.jsx(O,{event:n,logoUrl:i?.[n.symbol]??null})},`${n.symbol}-${String(n.date)}`))})}
1export{ye as UpcomingEarningsSection,ye 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.