1import{a as s,j as e}from"./react-vendor-DgOoyD0u.js";import{d as ae,s$ as it,t0 as ot,w as Fe,eB as lt,eC as dt,hF as Te,t1 as ct,t2 as ut,A as ne,ae as Be,b8 as mt,p as ht,qc as gt,ht as Ne,hu as ft,f9 as Ge,bJ as ge,R as ce,T as We,aD as pt,qd as Ue,qe as fe,qf as ze,t3 as xt,t4 as bt,t5 as yt,t6 as Ct,t7 as kt,t8 as vt,cX as pe,M as St,qg as jt,a as _e,t9 as we,cp as Nt,bT as Ee,a4 as _t,hw as wt,hx as Et,aG as Dt,a5 as Mt,ta as De,W as Me,c0 as Pt,c1 as It,tb as Lt,tc as At,td as Rt,te as Ot,c as Ft,u as Tt,tf as Bt,hv as Pe,hB as Gt,eK as Wt,kq as Ut,af as zt,f as $t,tg as Ht,th as qt,ti as Kt,tj as Qt,tk as Xt,H as Jt,aw as Vt,tl as Yt}from"./index-gGVBATlq.js";import{a as $e,b as Zt}from"./vendor-tanstack-C4KNVybO.js";import{r as ea,c as ta,b as aa,a as sa}from"./resolvePreferredPageGrain-DOFh4SoB.js";import{u as He,a as qe,C as ra,r as na,D as ia}from"./styles-B_L7L7AN.js";import{w as ue,s as oa,b as la,c as da,g as ca}from"./SignalDataViz-14jb6EEQ.js";import{f as ua,g as ma,c as Ke,d as ha,w as ga}from"./signalsDashboardFilterCatalog-DddcmCiW.js";import{L as me,T as fa,S as Qe,B as H,D as xe,a2 as pa,a3 as xa,a4 as ba,M as ya,e as Ca,g as ka,k as va,m as he,x as Ie}from"./vendor-flowbite-DLP2iZ0W.js";import{S as Sa,v as ja,b as Na,f as _a,a as wa}from"./index-NjuMNn5i.js";import{D as Ea,v as de,n as Da,a as Le,f as Ma,b as Xe}from"./dashboardEmailScheduleDisplay-DdXzgMgG.js";import{c0 as Pa,dJ as Ia,dK as La}from"./vendor-react-icons-DTNGkDGs.js";import{a as Aa}from"./index-DrqHhBUX.js";import{S as Ra}from"./SignalsLastRefreshLabel-D9LzFzoc.js";import{m as Oa}from"./dashboardShareAudienceOptions-Cl8_-8ly.js";import{S as Fa}from"./SignalsPeriodPicker-6fRhgG5e.js";import{b as Ae,c as Ta,e as Re,d as Ba,a as Ga,I as Wa}from"./signalsDashboardWidgetRefresh-Cp0AGlHO.js";import{S as Ua}from"./SignalsDataSourceGate-qNBR-kmD.js";import{a as za,s as $a}from"./signalsDashboardQuerySync-Bq61gaLl.js";import"./vendor-mermaid-Bx-bZjuG.js";import"./vendor-cytoscape-BgeL2iwd.js";import"./vendor-lodash-DtG3RRjV.js";import"./vendor-markdown-CitJEg14.js";import"./ErrorBoundary-DbCGZLO5.js";import"./buildDashboardWidgetComponentJson-Oxnzo5Q9.js";import"./SignalsLastRefreshContext-C01oNin-.js";import"./SelectorDropdownTrigger-Dj6ZPS_G.js";import"./LocationDropdown-28-O_tG0.js";import"./vendor-charts-BmOIOlNy.js";import"./ChatDataViz-ngB_P607.js";import"./graphSurface-Dse4mqQl.js";import"./index-CNGvnBPd.js";import"./datePickerStyles-Cd7BrkUP.js";import"./pageContentTitle-DPz0hkPm.js";import"./formatLastRefreshed-Bu7L2rj_.js";import"./index-_ZXdOaMn.js";import"./index-DeEqEilg.js";import"./useHorizontalScrollFade-DCXhGVN_.js";import"./usePillTabSlider-BQJJlb7J.js";import"./PeriodNavigation-ClqM0BaE.js";import"./NoBrandIntegrationPopover-BXmoD2rf.js";function Ha(a){const{showSnackbar:n}=ae(),[d,o]=s.useState(!1),[c,x]=s.useState(null),[l,w]=s.useState(""),{mutate:v,isPending:g}=it(),S=(C,M)=>{const P=M.trim();x({id:C,name:P}),w(P),o(!0)},j=()=>{!a||!c||!l.trim()||g||v({scope:a,page_id:c.id,name:l.trim().slice(0,ot)},{onSuccess:()=>{x(null),w(""),o(!1),n("Dashboard renamed","success")},onError:C=>{console.error("Failed to rename dashboard:",C),n("Could not rename dashboard","error")}})},E=()=>{o(!1),x(null),w("")},y=C=>{w(C)},N=!l.trim()||l.trim()===(c?.name?.trim()??"")||g;return{isModalOpen:d,newDashboardName:l,isPending:g,isSaveDisabled:N,showRenameModal:S,handleClose:E,handleRename:j,handleNameChange:y}}function qa(a){if(a&&typeof a=="object"&&"response"in a){const n=a.response?.data?.message;if(typeof n=="string"&&n.trim())return n.trim()}return"Could not update sharing"}function Ka(a){return a.share_rotate?"Share link replaced. Old links will not work.":a.share_published===!0?"Share link published":a.share_published===!1?"Share link unpublished":a.audience_group_ids!==void 0?"Share groups updated":a.shared_with_team?"Dashboard shared with your team":"Dashboard is private to you"}function Qa(a){const n=$e(),{getAccessTokenSilently:d}=Fe(),{showSnackbar:o}=ae();return Zt({mutationFn:async c=>{if(!a)throw new Error("Dashboard scope is required");const x=await d();if(Te(a)){if(c.shared_with_team===void 0)throw new Error("Team share is required");return ct({organisation_id:a.organisationId,page_id:c.page_id,shared_with_team
1:c.shared_with_team,token:x})}return ut({brand_id:a.brandId,page_id:c.page_id,shared_with_team:c.shared_with_team,share_published:c.share_published,audience_group_ids:c.audience_group_ids,share_rotate:c.share_rotate,token:x})},onSuccess:(c,x)=>{a&&(n.invalidateQueries({queryKey:lt(a)}),n.invalidateQueries({queryKey:dt(a,x.page_id)}),o(Ka(x),"success"))},onError:c=>{console.error("Failed to update dashboard sharing:",c),o(qa(c),"error")}})}function Xa(){const{selectedBrand:a,brands:n}=s.useContext(ne),{pathname:d}=Be(),o=mt();return s.useMemo(()=>{if(ht(d)!=null&&/\/organisation\/\d+\/signals\/(dashboards|reports)\//.test(d)){const x=gt(d,n);if(x)return Ne({organisationId:x.organisationId,anchorBrandId:x.anchorBrandId})}return o?Ne({organisationId:o.organisationId,anchorBrandId:o.anchorBrandId}):ft(a?.id??0)},[n,d,a?.id,o])}function be(a){return a?a.kind==="organisation"?a.anchorBrandId:a.brandId:0}function Ja(a,n){return{rangeGrain:"week",groupingGrain:"week",periodOffset:0,periodLabel:"",locationIds:[],brandIds:[],engagementColumn:ma(a),regularityColumn:ua(n),excludeMarketplace:!0}}function Oe(a,n){return a==="day"||a==="week"||a==="month"?a:n}function Va(a,n,d){const o=Ja(n,d);if(!a||typeof a!="object")return o;const c=a.periodGrain??a.period_grain,x=Oe(a.rangeGrain??a.range_grain??c,o.rangeGrain),l=Oe(a.groupingGrain??a.grouping_grain??c,o.groupingGrain),w=Number(a.periodOffset??a.period_offset??0),v=a.locationIds??a.location_ids,g=Array.isArray(v)?v.map(Number).filter(y=>Number.isFinite(y)&&y>0):[],S=a.brandIds??a.brand_ids,j=Array.isArray(S)?S.map(Number).filter(y=>Number.isFinite(y)&&y>0):[],E=a.excludeMarketplace??a.exclude_marketplace;return{rangeGrain:x,groupingGrain:l,periodOffset:Number.isFinite(w)?Math.max(0,Math.trunc(w)):0,periodLabel:String(a.periodLabel??a.period_label??o.periodLabel),locationIds:g,brandIds:j,engagementColumn:String(a.engagementColumn??a.engagement_column??o.engagementColumn),regularityColumn:String(a.regularityColumn??a.regularity_column??o.regularityColumn),excludeMarketplace:typeof E=="boolean"?E:o.excludeMarketplace}}function oe(a){const n=[a.first_name,a.last_name].filter(Boolean);return n.length?n.join(" "):a.email?a.email:`User #${a.id}`}function Ya(a){return{cadence:"daily",time_of_day:9,minute:0,timezone:a?.trim()||Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}}function Za({show:a,brandId:n,widgets:d,schedule:o,brandOptions:c=[],organisationBrandFilter:x=!1,onClose:l,onSave:w,saving:v=!1}){const{selectedBrand:g}=s.useContext(ne),{showSnackbar:S}=ae(),{data:j=[],isLoading:E}=Ge({enabled:a&&n>0}),y=s.useMemo(()=>Ke(d),[d]),[N,C]=s.useState(""),[M,P]=s.useState(null),[k,I]=s.useState([]),[A,D]=s.useState([]),[B,G]=s.useState(""),[R,i]=s.useState(""),b=He();s.useEffect(()=>{if(!a)return;const r=g?.timezone??ge();C(o?.name??""),P(o?.schedule_config??Ya(r)),I(o?.recipient_user_ids??[]),D(o?.recipient_emails??[]),G(""),i("");const m=Va(o?.filter_state??{},g?.engagement,g?.frequency);b.setRangeGrain(m.rangeGrain),b.setGroupingGrain(m.groupingGrain),b.setPeriodOffset(m.periodOffset),b.setLocationIds(m.locationIds),b.setBrandIds(m.brandIds),b.setEngagementColumn(m.engagementColumn),b.setRegularityColumn(m.regularityColumn),b.setExcludeMarketplace(m.excludeMarketplace)},[a,o?.id,g?.engagement,g?.frequency,g?.timezone]);const L=s.useMemo(()=>[...j].filter(r=>r.email?.trim()).sort((r,m)=>oe(r).localeCompare(oe(m),void 0,{sensitivity:"base"})),[j]),z=s.useMemo(()=>{const r=new Map;for(const m of L){const T=Number(m.id);m.email?.trim()&&Number.isFinite(T)&&r.set(T,m.email.trim())}return r},[L]),t=s.useMemo(()=>{const r=[];for(const m of k){const T=L.find(Q=>Number(Q.id)===m),h=z.get(m);r.push({key:`user-${m}`,label:T?`${oe(T)}${h?` (${h})`:""}`:`User #${m}`,kind:"user"})}for(const m of A)r.push({key:`email-${m}`,label:m,kind:"email"});return r},[A,k,L,z]),f=()=>{const r=R.trim();if(!r)return;if(!Ue(r)){S("Enter a valid email address","error");return}const m=de({recipient_user_ids:k,recipient_emails:fe(A,[r])});if(m){S(m,"error");return}D(T=>fe(T,[r])),i("")},_=r=>{if(!r)return;const m=Number(r);
1if(!Number.isFinite(m))return;const T=de({recipient_user_ids:k.includes(m)?k:[...k,m],recipient_emails:A});if(T){S(T,"error");return}I(h=>h.includes(m)?h:[...h,m]),G("")},O=r=>{if(r.kind==="user"){const T=Number(r.key.replace("user-",""));I(h=>h.filter(Q=>Q!==T));return}const m=r.key.replace("email-","");D(T=>ze(T,m))},K=async()=>{if(v)return;const r=Da(N);if(!r){S("Enter a schedule name","error");return}if(!M){S("Choose a schedule","error");return}const m=ja(M);if(!m.valid){S(m.errors[0]??"Fix the schedule settings","error");return}const T=de({recipient_user_ids:k,recipient_emails:A});if(T){S(T,"error");return}if(d.length===0){S("Add widgets to this dashboard first","error");return}const h={...b.filterState,periodLabel:b.filterState.periodLabel};await w({name:r,schedule_config:M,filter_state:h,recipient_user_ids:k,recipient_emails:A})};return e.jsx(ce,{showModal:a,onClose:l,title:o?"Edit email schedule":"New email schedule",showFooter:!1,size:"lg",bodyCustomClass:"text-left",parentCustomClass:"!items-center !justify-center px-4",modalWrapperCustomClass:"!text-left",bodyContent:e.jsxs("div",{className:"flex w-full flex-col gap-5",children:[e.jsxs("div",{children:[e.jsx(me,{htmlFor:"dashboard-email-schedule-name",children:"Name"}),e.jsx(fa,{id:"dashboard-email-schedule-name",className:"mt-1",value:N,maxLength:Ea,onChange:r=>C(r.target.value),placeholder:"Weekly sales summary"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-sm font-semibold text-gray-900 dark:text-white",children:"Schedule"}),e.jsx(Sa,{value:M,onChange:P,canSchedule:!0,defaultTimezone:g?.timezone??ge(),hideEnableToggle:!0})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-sm font-semibold text-gray-900 dark:text-white",children:"Filters"}),e.jsx("p",{className:"mb-3 text-sm text-gray-600 dark:text-gray-400",children:"These filters apply when the schedule runs."}),e.jsx(qe,{controls:y,groupingGrain:b.groupingGrain,onGroupingGrainChange:b.setGroupingGrain,periodOffset:b.periodOffset,periodLabel:b.filterState.periodLabel,onPreviousPeriod:b.moveToPreviousPeriod,onNextPeriod:b.moveToNextPeriod,locationIds:b.locationIds,onLocationIdsChange:b.setLocationIds,brandOptions:c,brandIds:b.brandIds,organisationBrandFilter:x,onBrandIdsChange:b.setBrandIds,engagementColumn:b.engagementColumn,onEngagementColumnChange:b.setEngagementColumn,regularityColumn:b.regularityColumn,onRegularityColumnChange:b.setRegularityColumn,excludeMarketplace:b.excludeMarketplace,onExcludeMarketplaceChange:b.setExcludeMarketplace})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-sm font-semibold text-gray-900 dark:text-white",children:"Recipients"}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[e.jsx(me,{htmlFor:"dashboard-schedule-user",children:"Team members"}),E?e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"Loading usersâ¦"}):L.length===0?e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:"No team members with email found."}):e.jsxs(Qe,{id:"dashboard-schedule-user",className:"mt-1",value:
1B,onChange:r=>_(r.target.value),children:[e.jsx("option",{value:"",children:"Add a team member"}),L.map(r=>e.jsxs("option",{value:String(r.id),children:[oe(r),r.email?` (${r.email})`:""]},r.id))]})]}),e.jsxs("div",{children:[e.jsx(me,{htmlFor:"dashboard-schedule-email",children:"Email address"}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("input",{id:"dashboard-schedule-email",type:"email",value:R,onChange:r=>i(r.target.value),onKeyDown:r=>{r.key==="Enter"&&(r.preventDefault(),f())},placeholder:"[email protected]",className:"min-w-0 flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white"}),e.jsx(H,{type:"button",color:"light",onClick:f,disabled:!R.trim(),children:"Add"})]})]}),t.length>0?e.jsx("ul",{className:"flex flex-wrap gap-2",children:t.map(r=>e.jsx("li",{children:e.jsx(We,{color:"gray",onRemove:()=>O(r),removeLabel:`Remove ${r.label}`,children:r.label})},r.key))}):null]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(H,{type:"button",color:"light",onClick:l,disabled:v,children:"Cancel"}),e.jsx(H,{type:"button",onClick:()=>{K()},disabled:v,className:pt,children:v?"Savingâ¦":o?"Save changes":"Create schedule"})]})]})})}function le(a){const n=[a.first_name,a.last_name].filter(Boolean);return n.length?n.join(" "):a.email?a.email:`User #${a.id}`}function es({show:a,scope:n,pageId:d,pageName:o,filterState:c,onClose:x}){const l=be(n),{getAccessTokenSilently:w}=Fe(),{showSnackbar:v}=ae(),{data:g=[],isLoading:S}=Ge({enabled:a&&l>0}),[j,E]=s.useState([]),[y,N]=s.useState([]),[C,M]=s.useState(""),[P,k]=s.useState(""),[I,A]=s.useState(""),[D,B]=s.useState(!1);s.useEffect(()=>{a&&(E([]),N([]),M(""),k(""),A(""))},[a,d]);const G=s.useMemo(()=>[...g].filter(t=>t.email?.trim()).sort((t,f)=>le(t).localeCompare(le(f),void 0,{sensitivity:"base"})),[g]),R=s.useMemo(()=>{const t=[];for(const f of j){const _=G.find(O=>O.id===f);t.push({key:`user-${f}`,label:_?le(_):`User #${f}`,kind:"user",value:f})}for(const f of y)t.push({key:`email-${f}`,label:f,kind:"email",value:f});return t},[y,j,G]),i=()=>{const t=P.trim();if(t){if(!Ue(t)){v("Enter a valid email address","error");return}N(f=>fe(f,[t])),k("")}},b=t=>{!t||!G.find(_=>_.id===t)?.email?.trim()||(E(_=>_.includes(t)?_:[..._,t]),M(""))},L=t=>{if(t.kind==="user"){E(f=>f.filter(_=>_!==String(t.value)));return}N(f=>ze(f,String(t.value)))},z=async()=>{const t=de({recipient_user_ids:j.map(f=>Number(f)),recipient_emails:y});if(t){v(t,"error");return}B(!0);try{const f=await w(),_={recipient_user_ids:j.map(K=>Number(K)),recipient_emails:y,filter_state:c,optional_message:I.trim()||void 0},O=Te(n)?await xt({organisation_id:n.organisationId,page_id:d,payload:_,token:f}):await bt({brand_id:n.brandId,page_id:d,payload:_,token:f});v(O.recipients===1?"Email is on its way":"Emails are on their way","success"),x()}catch(f){v(f instanceof Error?f.message:"Failed to send email","error")}finally{B(!1)}};return e.jsx(ce,{showModal:a,onClose:x,title:"Email dashboard",showFooter:!1,size:"md",bodyCustomClass:"text-left",parentCustomClass:"!items-center !justify-center px-4",modalWrapperCustomClass:"!text-left",bodyContent:e.jsxs("div",{className:"flex w-full max-w-md flex-col gap-4",children:[e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Sends every report on"," ",e.jsx("span",{className:"font-medium text-gray-900 dark:text-white",children:o})," ","using your current filters."]}),e.jsx("div",{children:S?e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Loading usersâ¦"}):G.length===0?e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No team members with email found."}):e.jsxs(Qe,{id:"share-dashboard-user","aria-label":"Add a team member",value:C,onChange:t=>b(t.target.value),children:[e.jsx("option",{value:"",children:"Add a team member"}),G.map(t=>e.jsxs("option",{value:String(t.id),children:[le(t),t.email?` (${t.email})`:""]},t.id))]})}),e.jsx("div",{children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{id:"share-dashboard-manual-email",type:"email",value:P,onChange:t=>k(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),i())},placeholder:"[email protected]","aria-label":"Email address",className:"min-w-0 flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white"}),e.jsx(H,{type:"button",color:"light",onClick:i,disabled:!P.trim(),children:"Add"})]})}),R.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400",children:"Recipients"}),e.jsx("ul",{className:"flex flex-wrap gap-2",children:R.map(t=>e.jsx("li",{children:e.jsx(We,{color:"gray",onRemove:()=>L(t),removeLabel:`Remove ${t.label}`,children:t.label})},t.key))})]}):null,e.jsx("div",{children:e.jsx("textarea",{id:"share-dashboard-message",value:I,onChange:t=>A(t.target.value),placeholder:"Add a note for recipientsâ¦","aria-label":"Message (optional)",rows:3,className:"w-full resize-none rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 focus:border-primary-500 focus:outline-none focus:ring-1 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white"})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(H,{type:"button",color:"light",onClick:x,disabled:D,children:"Cancel"}),e.jsx(H,{type:"button",color:"dark",onClick:()=>{z()},disabled:D||j.length+y.length===0,children:D?"Sendingâ¦":"Send"})]})]})})}function ts({scope:a,pageId:n,pageName:d,filterState:o,widgets:c,canManage:x,disabled:l=!1,brandOptions:w=[],organisationBrandFilter:v=!1}){const g=be(a),{selectedBrand:S}=s.useContext(ne),{showSnackbar:j}=ae(),E=S?.timezone??ge(),{data:y=[],isInitialLoading:N,isError:C}=yt(a,n),M=y.length>=Le,P=Ct(),k=kt(),I=vt(),[A,D]=s.useState(!1),[B,G]=s.useState(!1),[R,i]=s.useState(null),[b,L]=s.useState(null),z=P.isPending||k.isPending,t=()=>{i(null),D(!0)},f=r=>{i(r),D(!0)},_=async r=>{try{R?(await k.mutateAsync({scope:a,page_id:n,schedule_id:R.id,payload:r}),j("Schedule updated","success")):(await P.mutateAsync({scope:a,page_id:n,payload:r}),j("Schedule created","success")),D(!1),i(null)}catch(m){j(m instanceof Error?m.message:"Could not save schedule","error")}},O=async()=>
1{if(b)try{await I.mutateAsync({scope:a,page_id:n,schedule_id:b.id}),j("Schedule removed","success"),L(null)}catch(r){j(r instanceof Error?r.message:"Could not remove schedule","error")}};if(!x&&y.length===0)return null;const K=()=>{G(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(xe,{arrowIcon:!1,placement:"bottom-end",dismissOnClick:!1,renderTrigger:()=>e.jsxs(Xe,{disabled:l,title:"Email schedules",children:[e.jsx(ba,{className:"h-5 w-5"}),y.length>0?e.jsx("span",{className:"absolute right-1 top-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-gray-900 px-1 text-[10px] font-medium text-white dark:bg-white dark:text-gray-900",children:y.length}):null]}),theme:{floating:{base:"z-50 w-80 max-w-[min(20rem,calc(100vw-1rem))] rounded-lg border border-gray-200 bg-white shadow-lg focus:outline-none dark:border-dm-border-subtle dark:bg-dm-elevated",content:"p-0",target:"inline-flex"}},children:[e.jsx("div",{className:"border-b border-gray-200 px-4 py-3 dark:border-gray-700",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[x?e.jsx(H,{type:"button",size:"sm",color:"dark",onClick:K,disabled:l||c.length===0,className:"w-full justify-center",children:"Email now"}):null,e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:"Email schedules"}),x?e.jsx(H,{type:"button",size:"xs",color:"light",onClick:t,disabled:l||c.length===0||M,children:"Add schedule"}):null]})]})}),e.jsxs("div",{className:"max-h-80 overflow-y-auto px-4 py-3",children:[c.length===0?e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Add widgets to this dashboard before creating an email schedule."}):N?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(pe,{})}):C?e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Could not load email schedules."}):y.length===0?e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Email this dashboard on a schedule with your chosen filters."}):e.jsx("ul",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:y.map(r=>e.jsxs("li",{className:"flex flex-col gap-2 py-3 first:pt-0 last:pb-0",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:r.name}),e.jsxs("p",{className:"mt-0.5 text-sm text-gray-600 dark:text-gray-400",children:[r.schedule_config?Na(r.schedule_config):"Not scheduled"," · ",Ma(r)]}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:["Next:"," ",_a(r.schedule_next_run_at,E)," ","· Last:"," ",wa(r.schedule_last_run_at,E)]}),r.schedule_last_run_status?e.jsx("div",{className:"mt-2",children:e.jsx(St,{color:jt(r.schedule_last_run_status),children:r.schedule_last_run_status==="success"?"Last run succeeded":r.schedule_last_run_status==="partial"?"Last run partially sent":r.schedule_last_run_status==="failed"?"Last run failed":r.schedule_last_run_status})}):null]}),x?e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(H,{type:"button",size:"xs",color:"light",onClick:()=>f(r),disabled:l,children:[e.jsx(pa,{className:"mr-1 h-3.5 w-3.5"}),"Edit"]}),e.jsxs(H,{type:"button",size:"xs",color:"light",className:"text-red-600 hover:text-red-700",onClick:()=>L(r),disabled:l||I.isPending,children:[e.jsx(xa,{className:"mr-1 h-3.5 w-3.5"}),"Delete"]})]}):null]},r.id))}),x&&M?e.jsxs("p",{className:"mt-3 text-xs text-gray-500 dark:text-gray-400",children:["Maximum of ",Le," schedules per dashboard."]}):null]})]}),e.jsx(es,{show:B,scope:a,pageId:n,pageName:d,filterState:o,onClose:()=>G(!1)}),e.jsx(Za,{show:A,brandId:g,widgets:c,schedule:R,brandOptions:w,organisationBrandFilter:v,onClose:()=>{D(!1),i(null)},onSave:_,saving:z}),e.jsxs(ya,{show:b!=null,size:"md",onClose:()=>L(null),children:[e.jsx(Ca,{children:"Delete email schedule?"}),e.jsx(ka,{children:e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["â",b?.name,"â will stop sending scheduled emails."]})}),e.jsxs(va,{className:"justify-end gap-2",children:[e.jsx(H,{color:"light",onClick:()=>L(null),disabled:I.isPending,children:"Cancel"}),e.jsx(H,{color:"failure",onClick:()=>{O()},disabled:I.isPending,children:I.isPending?"Deletingâ¦":"Delete"})]})]})]})}function as({widgetToDelete:a,showDeletePageModal:n,widgetDeletePending:d,pageDeletePending:o,onCloseWidgetDelete:c,onConfirmWidgetDelete:x,onClosePageDelete:l,onConfirmPageDelete:w}){return e.jsxs(e.Fragment,{children:[e.jsx(ce,{showModal:a!=null,onClose:c,title:"Remove widget?",showFooter:!1,size:"sm",bodyContent:e.jsxs("div",{className:"space-y-4 text-left",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"This widget will be removed from the dashboard."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:c,className:_e,children:"Cancel"}),e.jsx("button",{type:"button",onClick:x,disabled:d,className:we,children:"Remove"})]})]})}),e.jsx(ce,{showModal:n,onClose:l,title:"Delete dashboard?",showFooter:!1,size:"sm",bodyContent:e.jsxs("div",{className:"space-y-4 text-left",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"This removes the dashboard and all widgets on it."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:l,className:_e,children:"Cancel"}),e.jsx("button",{type:"button",onClick:w,disabled:o,className:we,children:"Delete"})]})]})})]})}function ss({pageName:a,editMode:n,canManage:d,widgetCount:o,layoutPreview:c,layoutDirty:x,labelsDirty:l,layoutSaving:w,filters:v,trailing:g,duplicating:S=!1,onRename:j,onDuplicate:E,onDelete:y,onEnterEditMode:N,onCancelEditMode:C,onSaveLayout:M,onLayoutPreviewChange:P}){const k=d&&o>0,I=x||l,A=v!=null||g!=null||k,D=k?n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex rounded-lg border border-gray-200 p-0.5 dark:border-gray-600",role:"group","aria-label":"Layout preview",children:[e.jsx("button",{type:"button",onClick:()=>P("desktop"),className:`rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${c==="desktop"?"bg-gray-900 text-white dark:bg-white dark:text-gray-900":"text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"}`,children:"Desktop"}),e.jsx("button",{type:"button",onClick:()=>P("mobile"),className:`rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${c==="mobile"?"bg-gray-900 text-white dark:bg-white dark:text-gray-900":"text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"}`,children:"Mobile / tablet"})]}),e.jsx(H,{type:"button",size:"sm",color:"light",onClick:C,disabled:w,className:"max-sm:min-h-11",children:"Cancel"}),e.jsx(H,{type:"button",size:"sm",color:"dark",onClick:M,disabled:!I||w,className:"max-sm:min-h-11",children:w?"Savingâ¦":"Save changes"})]}):e.jsxs(H,{type:"button",size:"sm",color:"light",onClick:N,className:"max-sm:min-h-11 shrink-0 max-sm:px-3",children:[e.jsx("span",{className:"max-sm:hidden",children:"Edit dashboard"}),e.jsx("span",{className:"sm:hidden",children:"Edit"})]}):null;return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 sm:gap-2",children:[e.jsx(Aa,{hideOnMobile:!0,className:"truncate",children:a}),e.jsx("div",{className:"flex-shrink-0",children:d?e.jsxs(xe,{arrowIcon:!1,renderTrigger:()=>e.jsx("button",{type:"button","aria-label":"Dashboard actions",disabled:n,className:"relative z-20 inline-flex min-h-11 min-w-11 shrink-0 touch-manipulation items-center justify-center rounded-md border-0 bg-transparent p-0 text-gray-500 hover:text-gray-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-400/50 disabled:opacity-50 dark:text-gray-400 dark:hover:text-gray-200",children:e.jsx(Pa,{className:"h-5 w-5 shrink-0 text-gray-600 dark:text-gray-300"})}),inline:!0,theme:{floating:{base:"z-50"}},children:[e.jsx(he,{onClick:j,className:n?"pointer-events-none opacity-50":"",children:"Rename dashboard"}),e.jsx(he,{onClick:E,disabled:n||S,className:n||S?"pointer-events-none opacity-50":"",children:S?"Duplicatingâ¦":"Duplicate dashboard"}),e.jsx(he,{onClick:y,className:"text-red-500",children:"Delete dashboard"})]}):null})]}),e.jsx(Ra,{}),A?e.jsxs("div",{className:["flex flex-col gap-2 sm:flex-row sm:items-center",v!=null?"sm:justify-between":"sm:justify-end"].join(" "),children:[v!=null?e.jsx("div",{className:"order-2 flex min-w-0 flex-nowrap items-center gap-2 overflow-x-auto pb-0.5 [-ms-overflow-style:none] [scrollbar-width:none] sm:order-1 sm:flex-wrap sm:overflow-visible sm:pb-0 [&::-webkit-scrollbar]:hidden",children:v}):null,g!=null||D?e.jsxs("div",{className:"order-1 flex w-full min-w-0 flex-nowrap items-center gap-1.5 sm:order-2 sm:w-auto
1sm:justify-end sm:gap-2",children:[g,D]}):null]}):null]})}function rs({onClick:a,isActive:n=!1}){return e.jsx("div",{className:"flex justify-center pt-1",children:e.jsxs("button",{type:"button",onClick:a,"aria-pressed":n,className:"inline-flex items-center gap-2 rounded-full border border-dashed border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:border-gray-400 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-gray-400/50 dark:border-gray-600 dark:text-gray-300 dark:hover:border-gray-500 dark:hover:text-white",children:[e.jsx(Ia,{className:"h-3 w-3 shrink-0"}),"Add new Component"]})})}function ns(a,n){const d=String(n||"").trim();if(!d)return null;const o=String(a||"").replace(/\/$/,"");return o?`${o}/share/d/${encodeURIComponent(d)}`:null}function is({sharedWithTeam:a,disabled:n=!1,onChange:d,allowPublish:o=!1,brandId:c,shareToken:x=null,sharePublished:l=!1,audienceGroupIds:w=[],onPublishChange:v,onAudienceGroupIdsChange:g,onRotate:S}){const j=o&&c!=null&&c>0,{data:E,isLoading:y}=Nt(String(c||""),j),N=E?.website_auth?.enabled===!0,{data:C=[]}=Ee(j?c:void 0,"customer"),{data:M=[]}=Ee(j?c:void 0,"business"),P=s.useMemo(()=>Oa({contactGroups:C,businessGroups:M}),[C,M]),[k,I]=s.useState(()=>[...w]),A=w.join(",");s.useEffect(()=>{I(A?A.split(",").map(t=>Number(t)):[])},[A]);const D=ns(_t,x),[B,G]=s.useState(!1);s.useEffect(()=>{if(!B)return;const t=window.setTimeout(()=>G(!1),1500);return()=>window.clearTimeout(t)},[B]);const R=N&&k.length>0&&!y,i=P.filter(t=>t.kind==="contact"),b=P.filter(t=>t.kind==="business"),L=(t,f)=>{const _=f?Array.from(new Set([...k,t])):k.filter(O=>O!==t);I(_),l&&g?.(_)},z=async()=>{if(D)try{await navigator.clipboard.writeText(D),G(!0)}catch{G(!1)}};return e.jsx(xe,{arrowIcon:!1,placement:"bottom-end",dismissOnClick:!1,renderTrigger:()=>e.jsx(Xe,{disabled:n,title:o?"Share":"Share with team",className:a||l?"border-green-200 text-green-700 dark:border-green-800 dark:text-green-400":void 0,children:e.jsx(La,{className:"h-5 w-5"})}),theme:{floating:{base:"z-50 w-80 max-w-[min(20rem,calc(100vw-1rem))] rounded-lg border border-gray-200 bg-white shadow-lg focus:outline-none dark:border-dm-border-subtle dark:bg-dm-elevated",content:"p-0",target:"inline-flex"}},children:e.jsxs("div",{className:"px-4 py-3",onClick:t=>t.stopPropagation(),onKeyDown:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"Share with team"}),e.jsx(Ie,{checked:a,disabled:n,label:"",onChange:d})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-600 dark:text-gray-400",children:"Others in this brand can open this dashboard."}),o?e.jsxs("div",{className:"mt-4 border-t border-gray-200 pt-3 dark:border-dm-border-subtle",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"Publish share link"}),e.jsx(Ie,{checked:l,disabled:n||!l&&!R,label:"",onChange:t=>{t&&!R||v?.(t,k)}})]}),!N&&!y?e.jsxs("p",{className:"mt-2 text-xs text-gray-600 dark:text-gray-400",children:["Turn on website login before you can publish a share link."," ",e.jsx("a",{href:"/settings/brand/tracking",className:"font-medium text-gray-900 underline dark:text-white",children:"Turn on website login"})]}):e.jsx("p",{className:"mt-2 text-xs text-gray-600 dark:text-gray-400",children:"People in these groups can open the link after they sign in."}),e.jsxs("div",{className:"mt-3 max-h-40 space-y-3 overflow-y-auto",children:[i.length>0?e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Contact groups"}),e.jsx("div",{className:"mt-1 space-y-1",children:i.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-800 dark:text-gray-200",children:[e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:k.includes(t.id),disabled:n,onChange:f=>L(t.id,f.target.checked)}),t.name]},t.id))})]}):null,b.length>0?e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Business groups"}),e.jsx("div",{className:"mt-1 space-y-1",children:b.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-800 dark:text-gray-200",children:[e.jsx("input",{type:"checkbox",className:"rounded border-gray-300",checked:k.includes(t.id),disabled:n,onChange:f=>L(t.id,f.target.checked)}),t.name]},t.id))})]}):null]}),l&&D?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{readOnly:!0,value:D,className:"min-w-0 flex-1 rounded-md border border-gray-200 bg-gray-50 px-2 py-1 text-xs text-gray-700 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"}),e.jsx("button",{type:"button",className:"shrink-0 rounded-md border border-gray-200 px-2 py-1 text-xs font-medium text-gray-800 dark:border-gray-600 dark:text-gray-200",onClick:()=>void z(),children:B?"Copied":"Copy link"})]}),e.jsx("button",{type:"button",className:"text-xs font-medium text-gray-800 underline dark:text-gray-200",disabled:n,onClick:()=>S?.(),children:"Replace link"}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Replaces the URL. Old links stop working."})]}):null]}):null]})})}function os(a,n){return a.created_by_user_id==null?!0:n==null||n===""?!1:Number(a.created_by_user_id)===Number(n)}function ls({brandId:a,dashboardScope:n,page:d,widgets:o,emptyState:c,refetchWidgets:x,filterContext:l}){const w=$e(),{selectedBrand:v,user:g}=s.useContext(ne),S=wt(),j=Et(),E=s.useMemo(()=>({serves_businesses_and_customers:S,journeys_enabled:j}),[S,j]),{setAIChatOpen:y,isAIChatOpen:N,activeChatId:C,setActiveChatId:M,setChatHeader:P,setDefaultStarterMessage:k,publishSidePanelAgentContext:I,setMessages:A,getMessages:D,messages:B,sidePanelContextEpoch:G,setRe
1serveSpaceForChat:R,setChatPanelPlacement:i}=s.useContext(Dt),{setOpen:b}=s.useContext(Mt),[L,z]=s.useState(null),t=s.useMemo(()=>d&&a>0?De(a,d.id,L):null,[a,d,L]),f=s.useRef(!1),_=s.useRef(!1),O=s.useRef(null),K=s.useRef(0),r=s.useRef(!1),m=s.useRef(C);m.current=C;const T=s.useCallback(p=>{if(!d)return;const F=p!=null?o.find(W=>W.id===p)??null:null;I({headline:d.name,primaryDocument:Ae({page:d,widgets:o,focusWidgetId:p,filterContext:l,brandFeatures:E}),attachments:[Me("generic")]}),P(F?`Edit ${F.name}`:`Explore ${d.name}`)},[E,l,d,I,P,o]),h=s.useCallback((p,F)=>{if(!d)return;const W=D(F);if(W&&W.length>0&&!(W.length===1&&W[0].sender==="default"))return;const Y=p!=null?o.find(ee=>ee.id===p)??null:null,Z=o.length===0&&Y==null;A(F,Z?[Ta(d.name,E)]:[Pt(Re({pageName:d.name,focusWidget:Y,isEmpty:Z}))])},[E,D,d,A,o]),Q=s.useCallback((p=null)=>{if(!d||a<=0)return;const F=De(a,d.id,p);if(N&&C===F){c.useCenteredChat&&p===null&&(_.current=!0),y(!1);return}const W=p!=null?o.find(X=>X.id===p)??null:null;z(p),k(Re({pageName:d.name,focusWidget:W,isEmpty:o.length===0&&W==null})),T(p),h(p,F),M(F),y(!0),b(!1),g&&v&&It("AI Explore Opened",{brandId:v.id,userId:g.id,userEmail:g.email,chatId:F,context:"signals-dashboard-page",widgetId:p})},[C,a,c.useCenteredChat,N,d,T,h,v,M,y,k,b,g,o]),te=s.useMemo(()=>t?(C===t?B:D(t)??[]).some(F=>F.sender==="user"):!1,[C,t,D,B]);s.useEffect(()=>{f.current=!1,_.current=!1,O.current=null,K.current=0,z(null)},[d?.id]),s.useEffect(()=>{Lt(K.current,o.length)&&(_.current=!1,f.current=!1),K.current=o.length},[o.length]),s.useEffect(()=>c.useCenteredChat?(R(!1),i("center"),()=>{R(!0),i("side")}):(R(!0),i("side"),()=>{R(!0),i("side")}),[c.useCenteredChat,i,R]),s.useEffect(()=>{!At({isConfirmedEmpty:c.isConfirmedEmpty,userDismissedExplore:_.current,autoOpenedAlready:f.current})||!d||!t||(f.current=!0,Q(null))},[c.isConfirmedEmpty,t,Q,d]),s.useEffect(()=>{if(!t||C!==t)return;let p=Ba({messages:B,previousFingerprint:O.current,hasPriorConversation:te});if(!p&&te)for(let F=B.length-1;F>=0;F-=1){const W=B[F];if(W.sender!=="bot"&&W.sender!=="system")continue;const X=za(Ga(W));if(!X)continue;const Y=`save:${W.timestamp??F}:${X.pageId??X.pageSlug??"na"}`;if(Y===O.current)break;p=Y;break}p&&(O.current=p,n&&d?.id?$a(w,n,d.id):x())},[C,n,t,te,B,d?.id,w,x]),s.useEffect(()=>{const p=t;return()=>{p&&m.current===p&&y(!1)}},[t,y]),s.useEffect(()=>{const p=N&&t!=null&&Rt(C,a,d?.id??0);r.current&&!p&&x(),r.current=p},[C,a,t,N,d?.id,x]),s.useEffect(()=>{if(!t||C!==t||!d)return;const p=I({headline:d.name,primaryDocument:Ae({page:d,widgets:o,focusWidgetId:L,filterContext:l,brandFeatures:E}),attachments:[Me("generic")]});return typeof p=="function"?p:void 0},[C,E,t,l,L,d,I,G,o]),s.useEffect(()=>{const p=()=>Q(null);return window.addEventListener("openAIExplore",p),()=>window.removeEventListener("openAIExplore",p)},[Q]);const U=s.useMemo(()=>{if(!N||!d||a<=0)return!1;const p=Ot(C);return p?.brandId===a&&p.pageId===d.id&&p.widgetId==null},[C,a,N,d]);return{handleOpenAIExplore:Q,isAIChatOpen:N,isPageExploreOpen:U}}function Xs(){const{pageId:a}=Ft(),n=Tt(),{pathname:d}=Be(),{showSnackbar:o}=ae(),{user:c,brands:x}=s.useContext(ne),l=Xa(),w=be(l),v=s.useMemo(()=>{const u=Number(a);return Number.isFinite(u)&&u>0?u:null},[a]),[g,S]=s.useState(!1),[j,E]=s.useState("desktop"),[y,N]=s.useState([]),[C,M]=s.useState(!1),[P,k]=s.useState({}),[I,A]=s.useState(null),[D,B]=s.useState(!1),{data:G=[],isInitialLoading:R}=Bt(l),i=s.useMemo(()=>v!=null?G.find(u=>u.id===v)??null:a?G.find(u=>u.slug===a)??null:null,[G,a,v]);s.useEffect(()=>{if(!i||!l||v!=null)return;const u=Pe(l,i.id);d!==u&&n(u,{replace:!0})},[l,n,i,v,d]);const{data:b,isInitialLoading:L,refetch:z}=Gt(l,i?.id??null),t=b?.widgets??[],f=l==null||w<=0||R,_=Wt(ia),O=s.useMemo(()=>Ut({hasPage:i!=null,widgetCount:t.length,editMode:g,pagesLoading:R,widgetsLoading:i!=null&&L&&!(Number(i.widget_count)>0)}),[g,i,i?.widget_count,R,t.length,L]),K=s.useMemo(()=>ue(t),[t]),r=g?y:K,m=na({useStackLayout:_,editMode:g,layoutPreview:j}),T=s.useMemo(()=>oa(t),[t]),h=He(),{adoptPreferredGrain:Q,resetGrainAdoptionForPage:te}=h;s.useEffect(()=>{te(i?.id!=null?String(i.id):null)},[i?.id,te]),s.useEffect(()=>{i?.id==null||t.length===0||Q(String(i.id),ea(t))},[Q,i?.id,t]);const U=s.useMemo(()=>{const u=Ke(t);return l?.kind==="organisation"?{...u,showBrands:!1}:u},[l?.kind,t]),p=s.useMemo(()=>
1{if(l?.kind!=="organisation")return[];const u=zt(l.organisationId,x);return u?u.brandsInOrg.map($=>({id:$.id,name:$.name})):[]},[l,x]),F=s.useMemo(()=>new Set(p.map(u=>u.id)),[p]),W=s.useMemo(()=>ha(h.filterState,U,F.size>0?F:void 0),[h.filterState,U,F]),X=s.useCallback(u=>ga(u,U)?W:void 0,[U,W]),Y=s.useMemo(()=>({controls:U,filterState:h.filterState,refreshOverrides:W}),[U,h.filterState,W]),{handleOpenAIExplore:Z,isAIChatOpen:ee,isPageExploreOpen:Je}=ls({brandId:w,dashboardScope:l,page:i,widgets:t,emptyState:O,refetchWidgets:z,filterContext:Y}),Ve=s.useMemo(()=>({onAiExploreClick:()=>Z(null)}),[Z]);$t(Ve);const ye=s.useMemo(()=>ta(t,P)>0,[P,t]),Ce=Ht(),ke=qt(),ve=Kt(),Se=Qt(),J=Ha(l),ie=Xt(),se=Qa(l),V=s.useMemo(()=>i?os(i,c?.id):!1,[i,c?.id]),Ye=s.useCallback(()=>{!l||!i||ie.isPending||ie.mutate({scope:l,page_id:i.id},{onSuccess:u=>{o("Dashboard duplicated","success"),n(Pe(l,u.page.id))},onError:u=>{console.error("Failed to duplicate dashboard:",u),o("Could not duplicate dashboard","error")}})},[l,ie,n,i,o]);s.useEffect(()=>{g||(M(!1),k({}))},[g,t]);const Ze=s.useCallback(()=>{N(ue(t)),M(!1),k(aa(t)),E(_?"mobile":"desktop"),S(!0)},[_,t]),et=s.useCallback(()=>{N(ue(t)),M(!1),k({}),E("desktop"),S(!1)},[t]),tt=s.useCallback(u=>{N(u),M(!la(u,K))},[K]),at=s.useCallback((u,$)=>{k(q=>({...q,[u]:$}))},[]),st=async()=>{if(!i||!l)return;const u=C,$=ye;try{if(u){const q=da(r);await Ce.mutateAsync({scope:l,page_id:i.id,layouts:ca(q)}),N(q),M(!1)}if($)for(const q of t){const je=P[q.id];if(!je)continue;const re=sa(q,je,q.data_viz_json);re&&await ke.mutateAsync({scope:l,page_id:i.id,widget_id:q.id,...re.name!==void 0?{name:re.name}:{},...re.labels!==void 0?{labels:re.labels}:{}})}await z(),k({}),S(!1),o("Changes saved","success")}catch(q){o(q instanceof Error?q.message:"Could not save changes","error")}},rt=async()=>{if(I==null||!i||!l)return;const u=I;try{await ve.mutateAsync({scope:l,page_id:i.id,widget_id:u}),o("Widget removed","success"),A(null),g&&N($=>$.filter(q=>Number(q.i)!==u)),await z()}catch($){o($ instanceof Error?$.message:"Could not remove widget","error")}},nt=async()=>{if(!(!i||!l))try{await Se.mutateAsync({scope:l,page_id:i.id}),o("Dashboard removed","success"),B(!1),n("/signals/live")}catch(u){o(u instanceof Error?u.message:"Could not remove dashboard","error")}};return e.jsxs(Ua,{children:[e.jsx(Jt,{children:e.jsx("title",{children:i?.name?`${i.name} â Signals`:"Dashboard â Signals"})}),e.jsx("div",{className:`flex w-full min-w-0 flex-col gap-3 overflow-x-hidden md:gap-4 ${O.useCenteredChat&&ee?"min-h-0 flex-1":""}`,children:f?e.jsx("div",{className:"flex min-h-[240px] items-center justify-center",children:e.jsx(pe,{})}):i?e.jsxs(e.Fragment,{children:[e.jsx(ss,{pageName:i.name,editMode:g,canManage:V,widgetCount:t.length,layoutPreview:j,layoutDirty:C,labelsDirty:ye,layoutSaving:Ce.isPending||ke.isPending,duplicating:ie.isPending,filters:t.length>0&&!g?e.jsx(qe,{controls:U,hidePeriodControls:U.showPeriod||U.showGrouping,groupingGrain:h.groupingGrain,onGroupingGrainChange:h.setGrain,periodOffset:h.periodOffset,periodLabel:h.filterState.periodLabel,onPreviousPeriod:h.moveToPreviousPeriod,onNextPeriod:h.moveToNextPeriod,locationIds:h.locationIds,onLocationIdsChange:h.setLocationIds,brandOptions:p,brandIds:h.brandIds,organisationBrandFilter:!1,onBrandIdsChange:u=>{if(F.size===0){h.setBrandIds(u);return}h.setBrandIds(u.filter($=>F.has($)))},engagementColumn:h.engagementColumn,onEngagementColumnChange:h.setEngagementColumn,regularityColumn:h.regularityColumn,onRegularityColumnChange:h.setRegularityColumn,excludeMarketplace:h.excludeMarketplace,onExcludeMarketplaceChange:h.setExcludeMarketplace}):void 0,trailing:e.jsxs(e.Fragment,{children:[t.length>0&&!g&&(U.showPeriod||U.showGrouping)?e.jsx(Fa,{value:h.groupingGrain,onChange:h.setGrain,periodState:{offset:h.periodOffset,currentPeriod:h.filterState.periodLabel},onPreviousPeriod:h.moveToPreviousPeriod,onNextPeriod:h.moveToNextPeriod,showPeriodNavigation:U.showPeriod,showDatePeriodTabs:U.showGrouping,isNextDisabled:h.periodOffset<=0}):null,V?e.jsx(is,{sharedWithTeam:i.shared_with_team,disabled:g||se.isPending,allowPublish:l?.kind==="brand",brandId:l?.kind==="brand"?l.brandId:void 0,shareToken:i.share_token??null,sharePublished:!!i.share_published_at,audie
1nceGroupIds:i.audience_group_ids??[],onChange:u=>{se.mutate({page_id:i.id,shared_with_team:u})},onPublishChange:(u,$)=>{se.mutate({page_id:i.id,share_published:u,audience_group_ids:u?$:void 0})},onAudienceGroupIdsChange:u=>{se.mutate({page_id:i.id,audience_group_ids:u})},onRotate:()=>{se.mutate({page_id:i.id,share_rotate:!0})}}):null,l&&t.length>0?e.jsx(ts,{scope:l,pageId:i.id,pageName:i.name,filterState:h.filterState,widgets:t,canManage:!0,disabled:g,brandOptions:p,organisationBrandFilter:!1}):null]}),onRename:V?()=>J.showRenameModal(i.id,i.name):()=>{},onDuplicate:V?Ye:()=>{},onDelete:V?()=>B(!0):()=>{},onEnterEditMode:Ze,onCancelEditMode:et,onSaveLayout:()=>{st()},onLayoutPreviewChange:E}),O.isConfirmedEmpty&&!(ee&&O.useCenteredChat)?e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Ask AI to add charts and tables to this dashboard."}):null,i!=null&&L&&t.length===0&&Number(i.widget_count)>0?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center",children:e.jsx(pe,{})}):null,O.useCenteredChat&&ee?e.jsx(Wa,{}):null,!(L&&t.length===0&&Number(i.widget_count)>0)&&!(O.useCenteredChat&&ee)?e.jsx(ra,{dashboardScope:l,widgets:t,orderedWidgets:T,emptyState:O,editMode:V&&g,draftLayout:r,useStaticStack:m==="stack",showMobileStackEditor:m==="mobile-stack-editor",showDesktopGrid:m==="desktop-grid",widgetFilterOverrides:X,filterControls:U,filterState:h.filterState,onExploreWidget:Z,onDeleteWidget:A,onLayoutChange:tt,labelDrafts:P,onLabelDraftChange:at}):null,!g&&!(O.useCenteredChat&&ee)?e.jsx(rs,{onClick:()=>Z(null),isActive:Je}):null]}):e.jsxs("div",{className:`rounded-lg p-6 ${Vt}`,children:[e.jsx("h1",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Dashboard not found"}),e.jsx("p",{className:"mt-2 text-sm text-gray-600 dark:text-gray-400",children:"This dashboard may have been removed or belongs to another brand."})]})}),e.jsx(as,{widgetToDelete:V?I:null,showDeletePageModal:V&&D,widgetDeletePending:ve.isPending,pageDeletePending:Se.isPending,onCloseWidgetDelete:()=>A(null),onConfirmWidgetDelete:()=>{rt()},onClosePageDelete:()=>B(!1),onConfirmPageDelete:()=>{nt()}}),e.jsx(Yt,{mode:"rename",isOpen:J.isModalOpen,name:J.newDashboardName,isPending:J.isPending,isSaveDisabled:J.isSaveDisabled,onClose:J.handleClose,onSubmit:J.handleRename,onNameChange:J.handleNameChange})]})}export{Xs 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.