1import{an as he,r as p,af as e,aw as at,b3 as Ee,ay as rt,az as ot,aG as lt,bK as ct,aI as gs,b$ as Ae,bt as dt,bu as ut,as as mt}from"./vendor-BgWhiDrf.js";import{dZ as pt,D as ee,C as k,c9 as J,bJ as Cs,bN as re,i as L,ak as G,y as O,p as As,Od as ht,R as j,T as y,A as gt,cb as xt,I as ks,cr as Ie,dp as Me,gB as Is,WY as bt,Vj as ft,WZ as yt,AQ as jt,eo as Ps,e as vt,oA as _t,ao as Re,X as Ts,Y as Fe,Gm as xs,G$ as wt,ba as ne,W_ as N,k as St,d8 as Ct,W$ as bs,X0 as Ds,CR as pe,cd as At,ce as kt,cf as fs,B as T,az as Ls,dd as ie,G as ys,j as It,an as Q,dH as ge,dl as Pt,aX as Tt,X1 as js,X2 as Dt,X3 as vs,b1 as Lt,eq as Pe,gr as ae,aq as Es,$ as Ms,aI as Te,cl as Et,cm as Mt,S as Be,cn as Rt,co as Ft,aZ as Bt,CX as Rs,CY as zt,GH as Wt,aw as Fs,ad as De,X4 as Ot,X5 as qt,Jb as $t,Jc as Ut,b as Vt,c7 as Ht,c8 as Qt,tZ as Gt,CZ as Kt,NP as Nt,tE as Jt,X6 as Xt,h9 as Yt,CQ as Zt,b5 as en,eE as sn,H6 as tn,w as nn,f7 as an,hb as rn,l as on,f9 as ln,n as cn,o as dn,fa as W,cZ as un,c$ as mn,dF as pn,X7 as hn,lq as gn,bV as xn,X8 as bn,eG as fn,bS as yn,L as ke,ae as jn,c4 as vn,ab as _n,ac as wn,g0 as Sn,my as Cn,cP as An,dU as kn,dV as In,e2 as Pn,f6 as Tn,e0 as _s}from"./main-COyT_q74.js";import{u as Bs,A as zs}from"./outlet-D0RJWsUE.js";import{A as Dn}from"./add-resource-menu-B3AGQsU5.js";import{D as Ln}from"./detail-bar-CmUVp82u.js";import{M as En}from"./move-to-folder-DW7oB7IL.js";import{E as Mn}from"./edit-label-modal-Do7GruID.js";import{L as Rn}from"./labels-D7EIb96M.js";import{R as Fn}
1from"./label-form-B_jQqApr.js";import{D as Bn}from"./delete-resource-dialog-BjnlfCdA.js";import{a as zn}from"./dependencies-modal-8JvqIYuD.js";import{u as Wn}from"./use-audience-edit-lock-OLa9th5X.js";import{g as On}from"./array-BbQpcH1-.js";import{K as H}from"./constants-B2IlNFDy.js";import{S as qn}from"./static-audience-badge-B0ZBPcNB.js";import{S as $n}from"./syncs-cell-BkyFlboz.js";import{u as Un}from"./use-folder-crumbs-2JP3maE_.js";import{E as Vn}from"./experiment-status-badge-O2PNCiHz.js";import{D as Hn}from"./drawer-DPeWOPDQ.js";import{b as Qn,A as Gn}from"./audience-sidebar-context-BgFF7TAt.js";import{u as Kn,C as Nn,A as Jn}from"./audience-agent-page-sidebar-C89tR4fG.js";import{g as Xn}from"./use-audience-insights-panel-DXC2NcMy.js";import{i as Yn}from"./model-deletion-DrGIPYtG.js";import"./bounded-range-fetch-CggGfMWc.js";import"./vendor-charts-34qQJjVh.js";import"./use-template-validation-yjEdVTQB.js";import"./sync-DOmTynYq.js";import"./use-graph-context-CcSLVwbt.js";import"./journey-entry-event-context-Df72oAKz.js";import"./permission-utils-CcYd2CoM.js";import"./message-content-fields-C0blALK_.js";import"./elk.bundled-Dr8LgqPm.js";import"./node-ab-test-summary-BRr4NRzg.js";import"./variant-label-Btu1x_j3.js";import"./message-variant-content-Der7RFOv.js";import"./types-BDR0lhVm.js";import"./index-DxLJy5ec.js";import"./tags-DNlGVdcj.js";import"./decode-BrJoIbzt.js";import"./twilio-content-formats-9YHizxom.js";import"./add-label-menu-BbmP7vfc.js";import"./schemas-CVeYPD3C.js";import"./transform-DkTW016v.js";import"./merge-message-content-CVOZufBv.js";import"./resolve-dynamic-content-in-html-CIdo3nxV.js";import"./preview-markers-Bbhp-Rc7.js";import"./extract-profile-mappings-DfhOJSZX.js";import"./content-block-json-transform-B-7HyoAo.js";import"./use-journey-templates-hook-PwZmURDq.js";import"./use-validate-schedule-overlap-DD2D6oYW.js";import"./detect-schedule-overlap-B0RrDz2H.js";import"./filter-BKQn7lHt.js";import"./use-submit-draft-syncs-CboXAjCe.js";import"./types-C6fsm4h2.js";import"./use-folders-DyrzKigQ.js";import"./utils-B7jtqgFn.js";import"./user-facing-project-filter-MHsZukqU.js";import"./types-tb_2Dj0g.js";import"./term-qWA9duLp.js";import"./last-updated-1y07vupx.js";import"./sync-alert-card-BxFlX3V0.js";import"./utils-CPUVUfEd.js";import"./sync-alerts-badge-CM1ZAQky.js";import"./use-alerts-for-syncs-L_EGBFmX.js";import"./audience-R565SlHs.js";import"./subset-selector-CCRBeTUk.js";import"./constants-B5dKYw0r.js";import"./agent-sidebar-f5LG5hu5.js";import"./index-iEEwNQt2.js";import"./use-is-large-screen-wZdFXcmh.js";import"./page-sidebar-container-Dzz13yv6.js";import"./resource-wizard-ClVCq4rG.js";import"./use-agent-sidebar-state-5OzWKbZT.js";import"./constants-BVCulNrb.js";import"./audience-page-agent-context-Cpe-ArSK.js";const Zn=({parentModelId:s,kpi:i,isOpen:a,onSubmit:r,onClose:o})=>{const{enableIkeaDemoFeatures:u}=he(),{toast:b}=O(),[g,h]=p.useState(i),[m,x]=p.useState(!1);p.useEffect(()=>{h(i)},[i]);const l=async()=>{x(!0);try{await r(g),o(),b({id:"update-audience-kpi",title:"KPI updated",variant:"success"})}catch(d){G(d),b({id:"update-audience-kpi",title:"Failed to update KPI",message:"Please try again.",variant:"error"})}finally{x(!1)}},c=pt({parentModelId:s??""},{enabled:!!s&&u,select:d=>d.goals});return u?e.jsx(ee,{isOpen:a,variant:"form",title:"Update the audience KPI",onClose:o,actions:e.jsxs(re,{children:[e.jsx(L,{onClick:o,isDisabled:m,children:"Close"}),e.jsx(L,{variant:"primary",onClick:l,isLoading:m,children:"Save"})]}),children:e.jsxs(k,{gap:4,children:[e.jsx(J,{children:"Define a KPI to track the audienceâs performance."}),e.jsx(Cs,{isClearable:!0,placeholder:"Select a metricâ¦",isLoading:c.isLoading,optionLabel:d=>d.name,optionValue:d=>d.id,options:c.data??[],value:g,onChange:h})]})}):null},ei=({isOpen:s,syncs:i,onClose:a})=>{const{workspace:r}=As(),[o,u]=p.useState(new Set),[b,g]=p.useState(!1),{toast:h}=O(),m=ht(),x=i.filter(c=>!c.draft),l=async()=>{try{g(!0);for(const c of o)await m.mutateAsync({id:Number(c)});h({id:"run-syncs",title:"Syncs are running",message:"Your syncs are now running.",variant:"success"}),a()}catch(c){h({id:"run-syncs",title:"Syncs are running",message:"Your syncs are now running.",variant:"success"}),G(c)}finally{g(!1)}};return e.jsx(ee,{actions:e.jsxs(re,{children:[e.jsx(L,{variant:"secondary",onClick:a,children:"Close"}),e.jsxs(L,{icon:Me,isDisabled:o.size===0,isLoading:b,variant:"primary",onClick:l,children:["Run ",at("syncs",o.size,!0)]})]}),isOpen:s,title:`Run ${r!=null&&r.approvals_required?"approved sync(s)":"sync(s)"}`,variant:"form",onClose:a,children:e.jsxs(k,{gap:2,children:[e.jsx(j,{children:e.jsx(y,{color:"text.primary",fontWeight:"medium",children:"Selected syncs will run immediately:"})}),x.length===0?e.jsx(gt,{type:"info",title:"No approved syncs",message:"Please add and approve syncs before running them."}):e.jsx(k,{children:x.map(({id:c,destination:d},S)=>{var P,E,F;if(!c)return null;const f=o.has(c);return e.jsxs(j,{align:"center",gap:2,py:3,borderTopWidth:S===0?void 0:"hairline",borderTopStyle:S===0?void 0:"solid",borderColor:"base.border",children:[e.jsx(xt,{isChecked:f,onChange:()=>{u(D=>{const C=new Set(D);return f?C.delete(c):C.add(c),C})}}),e.jsx(ks,{name:((P=d==null?void 0:d.definition)==null?void 0:P.name)??"Private destination",src:(E=d==null?void 0:d.definition)==null?void 0:E.icon}),e.jsx(Ie,{color:"text.primary",fontWeight:"medium",children:(d==null?void 0:d.name)??((F=d==null?void 0:d.definition)==null?void 0:F.name)??"Private destination"})]},c)})})]})})},si=()=>{const{audience:s}=Bs(),{appEnableLlmAudienceSummary:i}=he(),{agents:a}=Is(),r=i&&a,o=s.description??s.llm_description??"",[u,b]=p.useState(o),g=s.llm_description_job_id,m=s.llm_description_job_status==="processing",[x,l]=p.useState(!1);p.useEffect(()=>{b(o)},[o]);const c=s.llm_description!==null&&s.llm_description===s.description,{toast:d}=O(),S=p.useCallback(_=>{d({id:"generate-summary",title:"Failed to generate description",variant:"error",message:_})},[d]),f=p.useMemo(()=>({v2:{resource:"model",grant:"can_update",id:s.id}}),[s.id]),P=bt();ft({jobId:g},{enabled:m,refetchInterval:_=>{var K;
1return((K=_==null?void 0:_.llmBackgroundJobResult)==null?void 0:K.__typename)==="LLMBackgroundJobProcessing"?500:!1},onSuccess:({llmBackgroundJobResult:_})=>{(_==null?void 0:_.__typename)==="LLMBackgroundJobSuccess"?(l(!1),b(_.result.summary)):(_==null?void 0:_.__typename)==="LLMBackgroundJobFailure"&&(l(!1),S(_.error))}});const{mutateAsync:E,isLoading:F}=yt(),D=p.useCallback(()=>{g&&(E({jobId:g}),l(!1))},[E,g,l]),C=p.useMemo(()=>({"aria-label":"Generate with Agents",icon:jt,buttonTooltip:"Generate description",usedActionTooltip:c?"Generated by AI":void 0,showOnEmptyDescription:!0,onClick:async()=>{l(!0);const _=await P.mutateAsync({segmentId:s.id});_.executeLLMBackgroundJob.__typename==="ExecuteLLMBackgroundJobErrorResponse"&&(S(_.executeLLMBackgroundJob.error),l(!1))}}),[s.id,P,c,S]),{mutateAsync:M,isLoading:B}=Ps(),X=p.useCallback(async _=>{_!==o&&(await M({id:s.id,input:{description:_}}),d({id:"description-update",title:"Description was updated",variant:"success"}))},[s.id,M,o,d]),Y=p.useCallback(async _=>
1{b(o),s.description===null&&await M({id:s.id,input:{description:""}})},[o,s.id,M,s.description]);return e.jsxs(j,{align:"center",gap:1,children:[e.jsx(vt,{isLoading:x,children:e.jsx(j,{width:x?"250px":"100%",children:e.jsx(_t,{enablePristineSubmit:!0,isDisabled:B||x,leftAction:r?C:void 0,permission:f,placeholder:r?"Generate a description or click to edit":void 0,value:u??"",onChange:X,onCancel:Y})})}),x&&g&&e.jsx(Re,{message:"Cancel generation",children:e.jsx(Ts,{"aria-label":"Cancel audience description generation",icon:Fe,isLoading:F,onClick:D})})]})},ti="/assets/audiences-agents-modal-bg-DQsGqA0a.png",ni=()=>{const{value:s,setLocal:i}=xs({key:"agents.audiences-agent-announcement-dialog-dismissed",initialValue:!1,useWorkspace:!1}),{value:a}=xs({key:"agents.tos-modal-dismissed",initialValue:!1,useWorkspace:!1}),{appAgentsAudiencesPage:r,appHideAudiencesAgentAnnouncement:o}=he(),u=wt();return{setIsDismissed:i,shouldShowAudiencesAgentDialog:!!r&&!s&&!o&&!a&&!u}};function ii({onClickCta:s}){const{shouldShowAudiencesAgentDialog:i,setIsDismissed:a}=ni(),r=()=>{a(!0),ne("Audiences Agent Announcement Dialog Dismissed")},o=()=>{s(),a(!0),ne("Audiences Agent Announcement Dialog Clicked CTA")};return p.useEffect(()=>{i&&ne("Audiences Agent Announcement Dialog Shown")},[i]),i?e.jsxs(N,{onClose:r,media:{type:"image",src:ti},mediaPosition:"top center",children:[e.jsxs(N.Body,{children:[e.jsx(N.Heading,{children:"Let AI help with audiences"}),e.jsx(y,{color:"text.secondary",children:"AI-powered assistance is now built into Customer Studio. Describe what you need, and our agent will help you build and analyze audiences."}),e.jsxs(k,{as:"ul",gap:2,ml:2,children:[e.jsx(N.ListItem,{children:"Build audiences with natural language"}),e.jsx(N.ListItem,{children:"Instantly summarize and analyze audiences"}),e.jsx(N.ListItem,{children:"Get suggestions to improve performance"})]}),e.jsx(y,{color:"text.secondary",children:"Say hello to smarter workflows in Customer Studio."})]}),e.jsxs(N.Actions,{children:[e.jsx(L,{onClick:r,children:"Close"}),e.jsxs(L,{onClick:o,variant:"primary",children:["Try it out",e.jsx(St,{ml:1})]})]})]}):null}const Le=s=>({v2:{resource:"model",grant:"can_update",id:s}}),ai=10,ri=({parentModelId:s,sourceName:i,isOpen:a,onClose:r,isStale:o=!1})=>{var oe,q,se,le;const[u,b]=p.useState(0),[g,h]=p.useState(null),{limit:m,offset:x,page:l,setPage:c}=Ct({limit:ai}),{data:d,isLoading:S}=bs({parentModelId:s,limit:m,offset:x},{enabled:a,keepPreviousData:!0,notifyOnChangeProps:"tracked"}),f=d==null?void 0:d.segments_by_pk,P=p.useMemo(()=>(f==null?void 0:f.realtime_audiences_warehouse_pull_runs)??[],[f==null?void 0:f.realtime_audiences_warehouse_pull_runs]),E=((q=(oe=f==null?void 0:f.realtime_audiences_warehouse_pull_runs_aggregate)==null?void 0:oe.aggregate)==null?void 0:q.count)??0,F=(se=f==null?void 0:f.realtime_audiences_scheduled_warehouse_pull)==null?void 0:se.next_full_refresh_date,D=i??"Source",C=hi({parentModelId:s,isActive:a&&u===1}),{toast:M}=O(),B=Ee(),{mutateAsync:X,isLoading:Y}=Ds({onSuccess:()=>{B.invalidateQueries(pe.getKey({parentModelId:s})),B.invalidateQueries(bs.getKey({parentModelId:s,limit:m,offset:x}))}}),_=((le=P[0])==null?void 0:le.status)==="running",K=async()=>{try{await X({parentModelId:s}),M({id:"warehouse-pull-trigger",title:"Pull queued",message:_?`An on-demand ${D} pull will start once the current pull finishes.`:`An on-demand ${D} pull will start shortly.`,variant:"success"})}catch{M({id:"warehouse-pull-trigger",title:"Failed to queue pull",message:"Try again, or contact support if the issue persists.",variant:"error"})}};return e.jsxs(e.Fragment,{children:[e.jsxs(Hn,{isOpen:a,onClose:r,size:"lg",blockBackgroundInteraction:!1,children:[e.jsxs(rt,{border:"none",p:0,flexDir:"column",alignItems:"stretch",w:"100%",children:[e.jsxs(j,{px:6,pt:5,pb:3,justify:"space-between",align:"flex-start",children:[e.jsxs(k,{gap:1,flex:1,minWidth:0,children:[e.jsxs(y,{fontWeight:"semibold",size:"lg",children:["Realtime audience ",D," cache"]}),e.jsxs(y,{color:"text.secondary",size:"sm",fontWeight:"normal",children:["History of ",D," data pulls for this parent model. Scheduled runs are always full refreshes, on-demand runs may be partial when the staging table is still compatible."]})]}),e.jsx(Ts,{"aria-label":"Close drawer",icon:Fe,onClick:r})]}),e.jsx(At,{index:u,onChange:b,children:e.jsxs(kt,{px:6,children:[e.jsx(fs,{children:"History"}),e.jsx(fs,{children:"Configuration"})]})})]}),e.jsxs(ot,{p:0,children:[o&&e.jsxs(k,{gap:1,mx:6,mt:4,p:3,bg:"warning.background",border:"1px solid",borderColor:"warning.border",borderRadius:"md",children:[e.jsxs(j,{align:"center",gap:3,children:[e.jsx(T,{as:Ls,color:"warning.base",fontSize:"24px",flexShrink:0}),e.jsx(y,{size:"sm",color:"warning.base",fontWeight:"semibold",children:"Definitions changed since last pull"})]}),e.jsx(T,{pl:"36px",children:e.jsx(y,{size:"sm",color:"warning.base",children:"Audience or mapping changes haven't been applied yet â pull now to update, or wait for the next scheduled run."})})]}),u===0?e.jsxs(k,{px:6,py:4,gap:4,children:[e.jsxs(j,{justify:"space-between",align:"center",gap:4,children:[e.jsxs(k,{gap:1,children:[e.jsx(y,{color:"text.secondary",size:"sm",children:"Next scheduled pull"}),e.jsxs(j,{align:"center",gap:2,children:[e.jsx(T,{borderRadius:"full",boxSize:"6px",bg:"text.secondary"}),e.jsx(y,{fontWeight:"medium",children:F?ie(F,"EEE, MMM d, yyyy '@' h:mm a"):"Not scheduled"})]})]}),e.jsxs(ys,{permission:Le(s),icon:Me,isLoading:Y,onClick:K,children:["Run ",D," pull"]})]}),e.jsxs(k,{children:[e.jsx(It,{columns:[{name:"Pull date",cell:({started_at:A})=>e.jsx(y,{fontWeight:"medium",children:ie(A,"MM/dd/yy 'at' h:mm a")??"--"})},{name:"Status",max:"min-content",cell:A=>e.jsx(oi,{run:A})},{name:"Trigger",max:"min-content",cell:({trigger_source:A})=>e.jsx(y,{children:li(A)})},{name:"Duration",max:"min-content",cell:A=>e.jsx(y,{children:ci(A)})},{name:"Rows",max:"min-content",cell:A=>A.status==="failure"?e.jsx(T,{as:"button",type:"button",onClick:xe=>{xe.stopPropagation(),h(A.error||"No additional error details.")},cursor:"pointer",children:e.jsx(Q,{variant:"error",children:"View error"})}):e.jsx(y,{children:A.row_count!=null?ge(Number(A.row_count)):"--"})}],data:P,loading:S,primaryKey:"id",placeholder:{title:"No pulls yet",body:"Warehouse pulls will appear here once the audience starts refreshing.",error:"Failed to load pull history. Try again, or contact support if it keeps happening."}}),e.jsx(j,{mt:4,justify:"flex-end",children:e.jsx(Pt,{alwaysShow:!0,compact:!0,count:E,label:"pulls",page:l,rowsPerPage:m,setPage:c})})]})]}):e.jsx(k,{px:6,py:4,gap:4,children:e.jsx(Tt,{label:"Pull schedule",children:e.jsx(Cs,{isDisabled:C.isLoading||C.isSaving,value:C.selectedHours,onChange:A=>{typeof A=="number"&&C.setSelectedHours(A)},options:ui})})})]}
1),u===1&&e.jsxs(lt,{justifyContent:"flex-start",gap:3,children:[e.jsx(ys,{permission:Le(s),variant:"primary",isDisabled:!C.hasChanges||C.isLoading,isLoading:C.isSaving,onClick:C.handleSave,children:"Save"}),e.jsx(L,{variant:"tertiary",isDisabled:!C.hasChanges||C.isSaving,onClick:C.handleCancel,children:"Cancel"})]})]}),e.jsx(ee,{isOpen:!!g,variant:"info",width:"lg",title:"Pull error",actions:e.jsx(L,{onClick:()=>h(null),children:"Close"}),onClose:()=>h(null),children:e.jsx(T,{as:"pre",whiteSpace:"pre-wrap",fontFamily:"mono",fontSize:"sm",bg:"base.lightBackground",borderRadius:"md",p:3,maxH:"400px",overflow:"auto",children:g})})]})},oi=({run:s})=>{const i=s.status;if(i==="success"&&s.refresh_type==="skipped")return e.jsx(Q,{variant:"subtle",svgIcon:vs,children:"Skipped"});switch(i){case"running":return e.jsx(Q,{variant:"info",svgIcon:Pe,children:"In progress"});case"success":return e.jsx(Q,{variant:"success",svgIcon:Lt,children:"Success"});case"failure":return e.jsx(Q,{variant:"error",svgIcon:Fe,children:"Failed"});case"skipped":return e.jsx(Q,{variant:"subtle",svgIcon:vs,children:"Skipped"});default:return e.jsx(Q,{children:s.status})}},li=s=>{switch(s){case"scheduled":return"Scheduled";case"on_demand":return"On-demand";default:return s}},ci=s=>
1s.status==="running"&&s.started_at?`${ae(s.started_at,null,{units:"short"})} elapsed`:s.started_at&&s.completed_at?ae(s.started_at,s.completed_at,{units:"short"}):"--",di=24,ui=[{value:24,label:"Every 24 hours (default)"},{value:12,label:"Every 12 hours"},{value:8,label:"Every 8 hours"},{value:6,label:"Every 6 hours"},{value:4,label:"Every 4 hours"}],mi=s=>({type:"interval",schedule:{interval:{quantity:s,unit:"hour"}}}),pi=s=>{var a,r;const i=(r=(a=s==null?void 0:s.schedule)==null?void 0:a.interval)==null?void 0:r.quantity;return typeof i=="number"&&i>0?i:di},hi=({parentModelId:s,isActive:i})=>{var S,f;const{toast:a}=O(),r=Ee(),{data:o,isLoading:u}=js({parentModelId:s},{enabled:i,refetchOnMount:"always"}),b=pi((f=(S=o==null?void 0:o.segments_by_pk)==null?void 0:S.realtime_audiences_scheduled_warehouse_pull)==null?void 0:f.schedule),[g,h]=p.useState(b);p.useEffect(()=>{h(b)},[b]);const{mutateAsync:m,isLoading:x}=Dt({onSuccess:()=>{r.invalidateQueries(pe.getKey({parentModelId:s})),r.invalidateQueries(js.getKey({parentModelId:s}))}});return{selectedHours:g,setSelectedHours:h,isLoading:u,isSaving:x,hasChanges:g!==b,handleSave:async()=>{try{await m({parentModelId:s,schedule:mi(g)}),a({id:"warehouse-pull-schedule-saved",title:"Schedule updated",message:`Realtime audience cache will now refresh every ${g} hours.`,variant:"success"})}catch{a({id:"warehouse-pull-schedule-saved",title:"Failed to update schedule",message:"Try again, or contact support if the issue persists.",variant:"error"})}},handleCancel:()=>h(b)}},gi={current:"Current",stale:"Stale",refreshing:"Refreshing",pending:"Pending"},xi={current:"green.500",stale:"warning.base",refreshing:"transparent",pending:"yellow.400"},bi=({parentModelId:s,sourceName:i,isStale:a=!1})=>{var B;const[r,o]=p.useState(!1),u=Ee(),{refetchInterval:b}=Es({maxMs:5e3}),{data:g,isLoading:h}=pe({parentModelId:s},{refetchInterval:b,onSuccess:()=>{u.invalidateQueries(["WarehousePullRunsHistory"])}}),m=g==null?void 0:g.segments_by_pk,x=m==null?void 0:m.realtime_audiences_scheduled_warehouse_pull,l=x==null?void 0:x.last_successful_run,c=(B=m==null?void 0:m.realtime_audiences_warehouse_pull_runs)==null?void 0:B[0],d=p.useMemo(()=>(c==null?void 0:c.status)==="running"?"refreshing":l?a?"stale":"current":"pending",[c==null?void 0:c.status,l,a]),S=i??"Source",f=(c==null?void 0:c.status)==="running",{toast:P}=O(),{isPermitted:E}=Ms(Le(s)),{mutateAsync:F,isLoading:D}=Ds({onSuccess:()=>{u.invalidateQueries(pe.getKey({parentModelId:s}))}}),C=async()=>{try{await F({parentModelId:s}),P({id:"warehouse-pull-trigger",title:"Pull queued",message:f?`An on-demand ${S} pull will start once the current pull finishes.`:`An on-demand ${S} pull will start shortly.`,variant:"success"})}catch{P({id:"warehouse-pull-trigger",title:"Failed to queue pull",message:"Try again, or contact support if the issue persists.",variant:"error"})}};if(h||!m)return null;const M=d==="refreshing"&&(c!=null&&c.started_at)?`${ae(c.started_at,null,{units:"short"})} elapsed`:l!=null&&l.completed_at?Te(l.completed_at):null;return e.jsxs(e.Fragment,{children:[e.jsxs(Et,{trigger:"hover",openDelay:100,closeDelay:150,placement:"bottom-start",isLazy:!0,children:[e.jsx(Mt,{children:e.jsxs(j,{align:"center",gap:2,flexShrink:0,cursor:"default",tabIndex:0,outline:"none",children:[d==="refreshing"?e.jsx(Be,{size:"sm"}):e.jsx(T,{borderRadius:"full",boxSize:"8px",bg:xi[d],flexShrink:0}),e.jsx(y,{fontWeight:"medium",children:gi[d]}),M&&e.jsx(y,{color:"text.secondary",children:M})]})}),e.jsx(Rt,{children:e.jsx(Ft,{width:"320px",bg:"white",borderRadius:"lg",boxShadow:"lg",border:"1px solid",borderColor:"base.border",p:4,_focus:{outline:"none"},children:e.jsxs(k,{gap:4,children:[e.jsxs(y,{fontWeight:"semibold",children:["Realtime audience",i?` ${i}`:""," cache"]}),a&&e.jsxs(k,{gap:1,p:3,bg:"warning.background",border:"1px solid",borderColor:"warning.border",borderRadius:"md",children:[e.jsxs(j,{align:"center",gap:3,children:[e.jsx(T,{as:Ls,color:"warning.base",fontSize:"24px",flexShrink:0}),e.jsx(y,{size:"sm",color:"warning.base",fontWeight:"semibold",children:"Definitions changed since last pull"})]}),e.jsx(T,{pl:"36px",children:e.jsx(y,{size:"sm",color:"warning.base",children:"Audience or mapping changes haven't been applied yet â pull now to update, or wait for the next scheduled run."})})]}),e.jsxs(k,{gap:3,children:[e.jsx(me,{label:"Last pull",value:d==="refreshing"&&(c!=null&&c.started_at)?`${ie(c.started_at,"EEE, MMM d 'at' h:mm a")} | ${ae(c.started_at,null,{units:"short"})} elapsed`:l!=null&&l.completed_at?`${ie(l.completed_at,"EEE, MMM d 'at' h:mm a")} | ${Te(l.completed_at)}`:"--"}),e.jsx(me,{label:"Duration",value:l!=null&&l.started_at&&(l!=null&&l.completed_at)?ae(l.started_at,l.completed_at,{units:"short"})??"--":"--"}),e.jsx(me,{label:"Row count",value:(l==null?void 0:l.row_count)!=null?ge(Number(l.row_count)):"--"}),e.jsx(me,{label:"Next scheduled pull",value:(x==null?void 0:x.next_full_refresh_date)&&ie(x.next_full_refresh_date,"EEE, MMM d 'at' h:mm a")||"--"})]}),e.jsxs(j,{justify:"space-between",align:"center",children:[e.jsxs(j,{as:"a",href:"https://hightouch.com/docs/audiences
1/realtime-audiences",target:"_blank",rel:"noreferrer",align:"center",gap:1,color:"primary.base",_hover:{color:"primary.hover"},children:[e.jsx(y,{fontWeight:"medium",color:"inherit",children:"View docs"}),e.jsx(T,{as:Bt,fontSize:"12px",color:"inherit"})]}),e.jsxs(j,{gap:2,children:[a&&e.jsx(Re,{isDisabled:E,message:"You do not have permission to run a pull for this audience",children:e.jsx(T,{as:"span",display:"inline-flex",children:e.jsx(T,{as:"button",type:"button",onClick:C,disabled:D||!E,pointerEvents:E?void 0:"none",borderRadius:"md",border:"1px solid",borderColor:"base.border",px:3,py:1,fontSize:"sm",fontWeight:"medium",color:"text.primary",_hover:{bg:"base.lightBackground"},_disabled:{opacity:.6,cursor:"not-allowed"},children:D?"Runningâ¦":"Run pull"})})}),e.jsx(T,{as:"button",type:"button",onClick:()=>o(!0),borderRadius:"md",border:"1px solid",borderColor:"base.border",px:3,py:1,fontSize:"sm",fontWeight:"medium",color:"text.primary",_hover:{bg:"base.lightBackground"},children:"View history"})]})]})]})})})]}),e.jsx(ri,{parentModelId:s,sourceName:i,isOpen:r,onClose:()=>o(!1),isStale:a})]})},me=({label:s,value:i})=>e.jsxs(k,{gap:0,children:[e.jsx(y,{color:"text.secondary",size:"sm",children:s}),e.jsx(y,{fontWeight:"medium",children:i})]}),fi={reupload:{title:"Re-upload CSV",confirmLabel:"Confirm",warning:"This will replace all current members of your audience",toastTitle:"Re-uploading CSV",toastMessage:"Your audience is being refreshed from the new CSV. This may take a few minutes.",errorTitle:"Could not re-upload CSV"},import:{title:"Import from CSV",confirmLabel:"Import",warning:"This will replace this audience's filter-based definition with the uploaded CSV",toastTitle:"Importing from CSV",toastMessage:"Your audience is being built from the CSV. This may take a few minutes.",errorTitle:"Could not import from CSV"}},ws=({audienceId:s,parentModel:i,mode:a,onClose:r})=>{const{toast:o}=O(),u=fi[a],{value:b,onChange:g,preview:h,isPreviewing:m,isReady:x,previewMembers:l}=Kn({parentModelId:i.id.toString()}),c=Rs(),d=c.isLoading,S=p.useRef(!1),f=async()=>{if(!(!h||!x||S.current)){S.current=!0;try{await c.mutateAsync({input:{audienceId:s,staticListId:h.staticListId}}),o({id:"csv-import",title:u.toastTitle,message:u.toastMessage,variant:"success"}),r()}catch(P){G(P),o({id:"csv-import",title:u.errorTitle,message:P.message,variant:"error"})}finally{S.current=!1}}};return e.jsx(ee,{isOpen:!0,variant:"form",title:u.title,width:"5xl",height:"85vh",maxHeight:"85vh",actions:e.jsxs(j,{align:"center",gap:4,children:[e.jsx(y,{color:"text.warning",children:u.warning}),e.jsxs(re,{children:[e.jsx(L,{onClick:r,children:"Cancel"}),e.jsx(L,{variant:"primary",isLoading:d,isDisabled:!x,onClick:f,children:u.confirmLabel})]})]}),onClose:r,children:e.jsx(Nn,{parentModel:i,value:b,onChange:g,onPreviewMembers:l,isPreviewing:m,jobId:h==null?void 0:h.jobId,materializedRowCount:h==null?void 0:h.rowCount})})},yi=({audienceId:s,onClose:i})=>{var g,h,m;const{toast:a}=O(),r=zt(),o=Wt({audienceIds:[s]}),u=(m=(h=(g=o.data)==null?void 0:g.cachedAudienceSizes)==null?void 0:h[0])==null?void 0:m.size,b=async()=>{try{await r.mutateAsync({input:{audienceId:s}}),a({id:"convert-to-static",title:"Converting to static audience",message:"We're adding all eligible profiles as members. This may take a few minutes.",variant:"success"}),i()}catch(x){G(x),a({id:"convert-to-static",title:"Could not convert to static audience",message:x.message,variant:"error"})}};return e.jsx(ee,{isOpen:!0,variant:"info",headerIcon:"warning",title:"Convert to static audience",width:"md",actions:e.jsxs(re,{children:[e.jsx(L,{onClick:i,children:"Cancel"}),e.jsx(L,{variant:"primary",isLoading:r.isLoading,onClick:b,children:"Confirm"})]}),onClose:i,children:e.jsxs(k,{gap:4,children:[e.jsx(J,{children:"Converting the audience will prevent new members from entering and existing members from leaving."}),e.jsx(J,{children:"It will take a few minutes to add all eligible profiles as members."}),(u!=null||o.isLoading)&&e.jsxs(j,{align:"center",gap:2,bg:"base.lightBackgroun
1d",borderRadius:"md",px:4,py:3,children:[o.isLoading?e.jsx(Be,{size:"sm"}):e.jsx(T,{as:Fs,color:"text.secondary",fontSize:"20px"}),e.jsx(y,{color:"text.secondary",children:u!=null?`~${De(Number(u))} members`:"Calculating membersâ¦"})]})]})})};function ji(s){var d,S;const{mutateAsync:i}=Ot(),[a,r]=p.useState(null),[o,u]=p.useState(),b=p.useCallback(async()=>{r(null),u(void 0);try{const f=await i({input:{audienceId:s}});r({jobId:f.enqueueStaticListRefreshPreview.jobId,staticListId:f.enqueueStaticListRefreshPreview.staticListId})}catch(f){u(f.message)}},[s,i]);p.useEffect(()=>{b()},[b]);const{refetchInterval:g}=Es({baseMs:2e3,backoffFactor:1}),h=qt({jobId:(a==null?void 0:a.jobId)??""},{enabled:!!(a!=null&&a.jobId),refetchInterval:(f,P)=>(f==null?void 0:f.staticListRefreshPreview)==null?g(f,P):!1}),m=(d=h.data)==null?void 0:d.staticListRefreshPreview,x=(m==null?void 0:m.__typename)==="StaticListRefreshPreviewSuccess"?{size:m.size,entered:m.entered,exited:m.exited}:null,l=o??(h.isError?(S=h.error)==null?void 0:S.message:(m==null?void 0:m.__typename)==="StaticListRefreshPreviewError"?m.error:void 0),c=l!=null;return{staticListId:(a==null?void 0:a.staticListId)??null,diff:x,isLoading:!c&&x==null,isError:c,error:l,retry:()=>{b()}}}const vi=({audienceId:s,onClose:i})=>{const{toast:a}=O(),{staticListId:r,diff:o,isLoading:u,isError:b,error:g,retry:h}=ji(s),m=Rs(),x=async()=>{if(r)try{await m.mutateAsync({input:{audienceId:s,staticListId:r}}),a({id:"update-members",title:"Updating members",message:"Your audience's members are being refreshed with today's data.",variant:"success"}),i()}catch(l){G(l),a({id:"update-members",title:"Could not update members",message:l.message,variant:"error"})}};return e.jsx(ee,{isOpen:!0,variant:"info",headerIcon:"warning",title:"Update members",width:"md",actions:e.jsxs(re,{children:[e.jsx(L,{onClick:i,children:"Cancel"}),e.jsx(L,{variant:"primary",isDisabled:o==null||!r,isLoading:m.isLoading,onClick:x,children:"Update members"})]}),onClose:i,children:e.jsxs(k,{gap:4,children:[e.jsx(J,{children:"Re-run this audience's filters with today's data and replace the current member list."}),b?e.jsxs(k,{gap:3,align:"flex-start",children:[e.jsx(y,{color:"text.danger",children:g??"Couldn't calculate membership changes."}),e.jsx(L,{onClick:h,children:"Try again"})]}):u||o==null?e.jsxs(j,{align:"center",gap:2,children:[e.jsx(Be,{size:"sm"}),e.jsx(y,{color:"text.secondary",children:"Calculating membership changesâ¦"})]}
1):e.jsxs(k,{gap:3,bg:"base.lightBackground",borderRadius:"md",px:4,py:3,children:[e.jsx(Ss,{icon:$t,color:"success.base",label:"Entering",count:o.entered}),e.jsx(Ss,{icon:Ut,color:"danger.base",label:"Leaving",count:o.exited}),e.jsxs(j,{justify:"space-between",align:"center",pt:3,borderTop:"1px solid",borderColor:"base.divider",children:[e.jsx(y,{fontWeight:"medium",children:"New total"}),e.jsxs(y,{fontWeight:"medium",children:[ge(o.size)," members"]})]})]})]})})},Ss=({icon:s,color:i,label:a,count:r})=>e.jsxs(j,{justify:"space-between",align:"center",children:[e.jsxs(j,{align:"center",gap:2,children:[e.jsx(T,{as:s,color:i,fontSize:"16px",flexShrink:0}),e.jsx(y,{color:"text.secondary",children:a})]}),e.jsx(y,{children:ge(r)})]}),Ka=()=>{var l,c;const{id:s}=mt(),{data:i,isFetching:a}=kn({id:s??""},{enabled:!!s,refetchOnMount:"always",suspense:!0}),r=i==null?void 0:i.segments_by_pk,o=In({audience_id:s??""},{enabled:!!s,suspense:!0,meta:{isFastEndpoint:!0}}),u=(c=(l=o.data)==null?void 0:l.segments_by_pk)==null?void 0:c.parent,b=p.useMemo(()=>u&&{...u,relationships:u.relationships.filter(d=>d.to_model.type===null||d.to_model.type==="interaction")},[u]),[g,h]=p.useState(!!(b!=null&&b.sampled_model_available)),m=a||o.isFetching,x=p.useMemo(()=>({audience:r,parentModel:b,audienceFetching:m,id:s,isFastQueryEnabled:g,setIsFastQueryEnabled:h}),[r,b,m,s,g,h]);return s?!r||!b?e.jsx(Tn,{subtitle:"An error occurred while fetching this resource. Try again, or contact support if the issue persists.",title:"Audience not found"}):e.jsx(zs,{context:x}):e.jsx(Pn,{})},Na=()=>{var He,Qe,Ge,Ke,Ne,Je,Xe,Ye,Ze,es,ss,ts,ns,is,as,rs,os,ls,cs,ds,us,ms,ps;const{toast:s}=O(),i=Vt(),a=ct(),{workspace:r}=As(),[o,u]=p.useState(!1),[b,g]=p.useState(!1),[h,m]=p.useState(!1),[x,l]=p.useState(!1),[c,d]=p.useState(!1),[S,f]=p.useState(!1),[P,E]=p.useState(!1),[F,D]=p.useState(!1),[C,M]=p.useState(!1),{appAgentsAudiencesPage:B,appAudienceAgentsTrackClosedGlobally:X,appDeleteModelV2ResolverEnabled:Y,appMoveAudienceAgentsToPageSidebar:_,audienceOverviewEnabled:K,audienceTemplatesEnabled:oe,enableIkeaDemoFeatures:q,rtaOverviewEnabled:se,schemaV2:le,staticListsEnabled:A}=he(),{agents:xe}=Is(),{audience:t,parentModel:v,audienceFetching:Ws,id:I,isFastQueryEnabled:be,setIsFastQueryEnabled:Os}=Bs(),ce=Ht(),fe={resourceType:"audience",resourceId:String(I)},{totalFor:qs}=Qt({resources:[fe]}),ze=qs(fe),$={v2:{resource:"model",grant:"can_update",id:I}},z=t==null?void 0:t.visual_query_filter,de=((z==null?void 0:z.additionalColumns)??[]).filter(n=>{if(n.column.type==="static_value")return!0;const R=Gt(n.column);return v.traits.some(Z=>Z.id===R)}),{mutateAsync:ye}=Ps(),{mutateAsync:$s}=Kt(),{mutateAsync:Us}=Nt(),{data:je}=Jt({parentModelId:v.id},{enabled:!!v}),te=Xt({id:I},{enabled:!ce}),{isPermitted:Vs}=Ms({v2:{resource:"model",grant:"can_read",id:v.id}}),Hs=Wn(t),We=Un({folderId:((He=t==null?void 0:t.folder)==null?void 0:He.id)??null,folderType:"audiences",viewType:"models"}),Qs=t!=null&&t.name?[...We,{label:t.name}]:We,Oe=((Qe=t.updated_by_user)==null?void 0:Qe.name)||((Ge=t.created_by_user)==null?void 0:Ge.name),ue=(Ke=t==null?void 0:t.priority_list_memberships)==null?void 0:Ke[0],U=t==null?void 0:t.syncs,Gs=new Set((Ne=te.data)==null?void 0:Ne.journeysBeingDeleted.map(({id:n})=>n)),ve=[{name:"Journeys",resources:On(((Je=te.data)==null?void 0:Je.journeys)??[],"id").map(n=>({id:n.id,name:n.name,description:Gs.has(n.id)?"Deletion in progress":void 0,url:`/journeys/${n.id}`,created_at:n.created_at,updated_at:n.updated_at,created_by_user:n.created_by_user,updated_by_user:n.updated_by_user}))},{name:"Priority lists",resources:(Ye=((Xe=te.data)==null?void 0:Xe.priority_lists)??[])==null?void 0:Ye.map(n=>({id:n.id,name:n.name,url:`/priority-lists/${n.id}`,created_at:n.created_at,updated_at:n.updated_at,created_by_user:n.created_by_user,updated_by_user:n.updated_by_user}))},{name:"Saved charts",resources:(es=((Ze=te.data)==null?void 0:Ze.saved_analytics_charts)??[])==null?void 0:es.map(n=>({id:n.id,name:n.name,description:gs(n.chart_type),chart_type:n.chart_type,url:`/analytics/${n.id}`,created_at:n.created_at,updated_at:n.updated_at,created_by_user:n.created_by_user,updated_by_user:n.updated_by_user}))}].filter(({resources:n})=>n.length>0),w=t==null?void 0:t.connection,_e=Object.keys(Ae(t==null?void 0:t.labels,q?[H]:[])||{}),qe=je==null?void 0:je.sync_templates,Ks=Array.isArray(qe)&&qe.length>0,$e=!!(r!=null&&r.sync_templates_only&&!Ks),V=!!((ss=t==null?void 0:t.visual_query_filter)!=null&&ss.isRealtime||t!=null&&t.is_realtime_audience),we=((ts=t.static_list)==null?void 0:ts.type)==="csv",Se=p.useMemo(()=>{var n;
1return new Set(((n=v==null?void 0:v.relationships)==null?void 0:n.filter(R=>Yt(R.to_model.event)).map(R=>R.to_model.id.toString()))??[])},[v==null?void 0:v.relationships]),Ns=p.useMemo(()=>Zt(z==null?void 0:z.conditions,Se),[z==null?void 0:z.conditions,Se]),{isStale:Js}=Qn({audienceId:I??"",parentModelId:v!=null&&v.id?String(v.id):"",visualQueryFilter:z,realtimeEventModelIds:Se,isRealtimeAudience:V}),Xs=(n=!0)=>{ne("Model Updated",{model_id:I,model_type:_s.Visual,model_name:t==null?void 0:t.name,source_id:w==null?void 0:w.id,source_type:w==null?void 0:w.type}),n&&s({id:"update-audience",title:"Audience was updated",variant:"success"})},Ys=async n=>{await ye({id:I,input:{name:n}}),Xs()},Ue=async()=>{try{Y?await Us({id:I}):await $s({id:I}),s({id:"delete-audience",title:"Audience was deleted",variant:"success"}),ne("Model Deleted",{model_id:I,model_type:_s.Visual,model_name:t==null?void 0:t.name,source_id:w==null?void 0:w.id,source_type:w==null?void 0:w.type}),i("/audiences")}catch(n){throw Y?(s({id:"delete-audience",title:"Failed to delete this audience",message:n.message,variant:"error"}),Yn(n)||G(n)):n.message.startsWith("Foreign key violation")&&n.message.includes("journey_nodes")?s({id:"delete-audience",title:"Failed to delete this audience",message:"This audience cannot be deleted because it is used in a journey. First remove the audience from the journey and try again.",variant:"error"}):n.message.startsWith("Foreign key violation")&&n.message.includes("decision_engine")?s({id:"delete-audience",title:"Failed to delete this audience",message:"This audience cannot be deleted because it is used in a decision engine agent. First replace the audience in that agent or delete the agent and try again.",variant:"error"}):n.message.startsWith("Foreign key violation")&&n.message.includes("segments")?s({id:"delete-audience",title:"Failed to delete this audience",message:"This audience cannot be deleted because it is used in a priority list. First remove the audience from the priority list and try again.",variant:"error"}):n.message.startsWith("Foreign key violation")?(s({id:"delete-audience",title:"Failed to delete this audience",message:"This audience cannot be deleted because other resources rely on it.",variant:"error"}),G(n)):(s({id:"delete-audience",title:"Failed to delete this audience",variant:"error"}),G(n)),u(!1),n}},Ce=!!(_&&B&&xe&&!we),Zs=Xn({audienceId:I,appAgentsAudiencesPage:!!B,appAudienceAgentsTrackClosedGlobally:!!X}),et=p.useMemo(()=>{var hs;const n={title:"Overview",path:"overview",variant:"dashboard",hasBottomPadding:!0},R={title:"Definition",path:"definition",variant:"dashboard"},Z={title:"Members",path:"members",variant:"table"},tt={title:"Experiment",path:"splits",variant:"card",statusIndicator:e.jsx(Vn,{status:((hs=t.experiment)==null?void 0:hs.status)||"hidden",hideIfHidden:!0})},nt={title:"Syncs",path:"syncs",count:U.length||void 0,variant:"table"},it={title:"Traits",path:"traits",count:de.length||void 0,variant:"table"};return[we?Z:R,(V?se:K)&&n,!V&&tt,nt,!V&&it,{title:"Activity",path:"activity",variant:"page"},ce&&{title:"Usage",path:"usage",count:ze||void 0,variant:"card"},{title:"Settings",path:"settings",variant:"form"}].filter(en)},[V,de==null?void 0:de.length,U==null?void 0:U.length,K,ce,se,ze,(ns=t.experiment)==null?void 0:ns.status,we]);p.useEffect(()=>{V&&(a.pathname.includes("traits")||a.pathname.includes("splits"))&&i("./definition")},[V,a.pathname,i]);const Ve=(as=(is=t.visual_query_filter)==null?void 0:is.idr)==null?void 0:as.threshold,st=Ve?`${gs(Ve)} â ${v.name}`:v.name;return e.jsxs(e.Fragment,{children:[e.jsx(Gn,{agentAvailable:Ce,children:e.jsx(sn,{permission:$,children:e.jsx(tn,{lock:Hs.permissionLock,children:e.jsx(nn,{title:`${t.name} - Audiences`,tabs:et,crumbs:Qs,sidebar:Ce?e.jsx(Jn,{enabled:Ce,storageKey:Zs,audience:t,parentModel:v,isFastQueryEnabled:be}):void 0,header:e.jsxs(k,{width:"100%",children:[e.jsxs(j,{align:"center",justify:"space-between",width:"100%",children:[e.jsxs(j,{align:"center",gap:2,minWidth:0,children:[e.jsx(an,{permission:$,size:"lg",value:(t==null?void 0:t.name)??"",onChange:Ys,showOverflowingContentAsTooltip:!0}),t.is_realtime_audience&&e.jsx(Q,{svgIcon:rn,variant:"info",children:"Realtime audience"})]}),e.jsxs(j,{align:"center",gap:3,ml:8,children:[e.jsxs(on,{children:[e.jsx(ln,{variant:"secondary"}),e.jsxs(cn,{children:[t.syncs.length>0&&e.jsxs(dn,{icon:Me,onClick:()=>d(!0),children:["Run"," ",r!=null&&r.approvals_required?"approved sync(s)":"sync(s)"]}),e.jsx(W,{permission:$,icon:un,onClick:()=>{l(!0)},children:"Move to folder"}),e.jsx(W,{permission:$,icon:mn,onClick:()=>{g(!0)},children:"Edit labels"}),e.jsx(W,{permission:{v2:{resource:"model",grant:"can_create",creationOptions:{type:"audience",parentModelId:((rs=v.id)==null?void 0:rs.toString())??""}}},icon:pn,onClick:()=>
1{i(`/audiences/${I}/clone`)},children:"Make a copy"}),A&&!t.static_list&&e.jsx(W,{permission:$,icon:hn,onClick:()=>{D(!0)},children:"Convert to static audience"}),A&&((os=t.static_list)==null?void 0:os.type)==="snapshot"&&e.jsx(W,{permission:$,icon:Pe,onClick:()=>{M(!0)},children:"Update members"}),A&&((ls=t.static_list)==null?void 0:ls.type)==="csv"&&e.jsx(W,{permission:$,icon:Pe,onClick:()=>{f(!0)},children:"Re-upload CSV"}),A&&!t.static_list&&e.jsx(W,{permission:$,icon:gn,onClick:()=>{E(!0)},children:"Import from CSV"}),q&&e.jsx(W,{permission:$,icon:xn,onClick:()=>{m(!0)},children:"Update the audience KPI"}),oe&&e.jsx(W,{permission:{v2:{resource:"model",grant:"can_update",id:(v==null?void 0:v.id)??""}},icon:bn,onClick:()=>{i(`/templates/audience-templates/new?audienceId=${I}`)},children:"Create template from this audience"}),e.jsx(fn,{}),e.jsx(W,{permission:{v2:{resource:"model",grant:"can_delete",id:I}},isDisabled:te.isLoading,icon:yn,variant:"danger",onClick:()=>{u(!0)},children:"Delete"})]})]}),e.jsx(Dn,{tooltip:$e?"This workspace only allows syncs created from templates. Add a sync template to create a sync.":void 0,isDisabled:$e,audie
1nce:t,parentModel:v})]})]}),e.jsx(j,{children:e.jsx(si,{})}),e.jsx(j,{mt:3,children:e.jsxs(Ln,{children:[e.jsxs(j,{align:"center",gap:2,flexShrink:0,maxWidth:"300px",children:[e.jsx(ks,{src:(cs=w==null?void 0:w.definition)==null?void 0:cs.icon,name:((ds=w==null?void 0:w.definition)==null?void 0:ds.name)??""}),Vs?e.jsx(ke,{isTruncated:!0,href:le?`/schema-v2/view?source=${w==null?void 0:w.id}&id=${v.id}`:`/schema/parent-models/${v.id}`,children:e.jsx(Ie,{fontWeight:"medium",color:"inherit",children:st})}):e.jsx(Ie,{fontWeight:"medium",children:v.name})]}),V&&Ns&&e.jsx(bi,{parentModelId:String(v.id),sourceName:(us=w==null?void 0:w.definition)==null?void 0:us.name,isStale:Js}),e.jsxs(j,{align:"center",gap:2,flexShrink:0,children:[e.jsx(y,{children:"Last updated:"}),e.jsxs(j,{gap:1,align:"center",children:[jn(t.updated_at||t.created_at),Oe&&e.jsxs(e.Fragment,{children:[e.jsx(y,{children:"by"}),e.jsx(vn,{size:"sm",name:Oe})]})]})]}),t.static_list&&e.jsxs(j,{gap:1.5,children:[e.jsx(T,{as:Fs,color:"text.tertiary",fontSize:"20px"}),(((ms=t.subsets)==null?void 0:ms.length)??0)>0?e.jsxs(_n,{color:"text.secondary",message:wn,children:[De(t.static_list.size)," ","members"]}):e.jsxs(y,{color:"text.secondary",children:[De(t.static_list.size)," ","members"]}),t.static_list.last_materialized_at&&e.jsxs(y,{color:"text.tertiary",children:["(refreshed"," ",Te(t.static_list.last_materialized_at),")"]})]}),(U.length>0||t.static_list)&&e.jsxs(j,{align:"center",gap:2,children:[U.length>0&&e.jsx($n,{syncs:U}),t.static_list&&e.jsx(qn,{showTooltip:!0})]}),v.sampled_model_available&&e.jsxs(j,{align:"center",gap:1,children:[e.jsxs(y,{color:"text.secondary",children:["Fast queries: ",be?"on":"off"]}),e.jsx(Re,{message:"Fast queries generate an estimated size which is a close approximate to the exact size. You can change this selection on the âDefinitionâ page.",children:e.jsx(Sn,{color:"text.secondary"})})]}),ue&&e.jsxs(j,{align:"center",gap:2,children:[e.jsxs(y,{children:["#",ue.rank+1," in"]}),e.jsx(ke,{href:`/priority-lists/${ue.priority_list.id}`,children:e.jsxs(j,{color:"primary",gap:2,align:"center",_hover:{color:"secondary"},children:[ue.priority_list.name,e.jsx(T,{as:Cn,fontSize:"16px"})]})})]}),(_e==null?void 0:_e.length)>0&&e.jsx(j,{children:e.jsx(Rn,{labels:Ae(t==null?void 0:t.labels,q?[H]:[])})})]})})]}),children:e.jsx(zs,{context:{audience:t,parentModel:v,id:I,audienceFetching:Ws,isFastQueryEnabled:be,setIsFastQueryEnabled:Os}})})})})}),B&&e.jsx(ii,{onClickCta:()=>{i("./definition?openAgent=true")}}),ce?e.jsx(Bn,{isOpen:o,resourceLabel:"audience",resource:fe,onClose:()=>{u(!1)},onDelete:Ue}):e.jsxs(e.Fragment,{children:[e.jsx(zn,{isOpen:o&&ve.length>0,resourceType:"audience",onClose:()=>u(!1),dependencies:ve}),e.jsx(An,{confirmButtonText:"Delete",isOpen:o&&ve.length===0,title:"Delete audience",variant:"danger",onClose:()=>{u(!1)},onConfirm:Ue,children:e.jsxs(k,{gap:6,children:[e.jsx(J,{children:"Are you sure you want to delete this audience? You won't be able to undo this."}),e.jsx(J,{children:"This audience may not be deleted until the resources that reference it are deleted as well."}),U.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(J,{children:"The following syncs will be deleted as well:"}),e.jsx(k,{alignItems:"start",children:e.jsx(dt,{children:U.map(({destination:n,id:R})=>e.jsx(ut,{children:e.jsx(ke,{href:`/syncs/${R}`,children:(n==null?void 0:n.name)||(n==null?void 0:n.definition.name)||"Unknown sync"})},R))})})]})]})})]}),t&&x&&e.jsx(En,{folder:t.folder,folderType:"audiences",modelIds:[t.id],viewType:"models",onClose:()=>l(!1)}),e.jsx(Mn,{isOpen:b,labels:Ae(t.labels,q?[H]:[]),resourceType:Fn.Model,onClose:()=>g(!1),onSubmit:n=>{var Z;const R={...n};return q&&((Z=t==null?void 0:t.labels)!=null&&Z[H])&&(R[H]=t.labels[H]),ye({id:I,input:{tags:R}})}}),e.jsx(Zn,{isOpen:q&&h,kpi:(ps=t.labels)==null?void 0:ps[H],parentModelId:v.id,onSubmit:async n=>{await ye({id:I,input:{tags:{...(t==null?void 0:t.labels)??{},[H]:n}}})},onClose:()=>m(!1)}),e.jsx(ei,{isOpen:c,syncs:t.syncs,onClose:()=>d(!1)}),S&&e.jsx(ws,{mode:"reupload",audienceId:I,parentModel:v,onClose:()=>f(!1)}),P&&e.jsx(ws,{mode:"import",audienceId:I,parentModel:v,onClose:()=>E(!1)}),F&&e.jsx(yi,{audienceId:I,onClose:()=>D(!1)}),C&&e.jsx(vi,{audienceId:I,onClose:()=>M(!1)})]})};export{Na as AudienceDetails,Ka as AudienceLoader}; 2//# sourceMappingURL=index-CIJyNyPv.js.map
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.