1import{af as e,an as le,r as o}from"./vendor-B2oIjyY4.js";import{$ as ce,Q as me,a0 as pe,a1 as ge,a2 as Q,a3 as he,a4 as be,a5 as fe,a6 as v,a7 as G,a8 as Se,N as ve,a9 as xe,R as x,C as y,aa as ye,ab as Ie,ac as K,T as V,ad as Ae,ae as _e,af as Ce,ag as je,ah as Pe,ai as Me,y as we,aj as Te}from"./main-CJK8sxkW.js";import{A as Ee,a as Be,S as W,P as I,b as Oe,c as ke}from"./agent-panel-button-C3ME53IC.js";import{u as Re}from"./use-audience-insights-panel-LL1gk1Wq.js";import{M as De}from"./member-table-Bikhv0u6.js";import{S as Ne}from"./subset-selector-CeH3ktje.js";import{A as Fe}from"./audience-page-agent-context-BmtkaQg8.js";import{u as Ue}from"./outlet-CRFGt_DD.js";import"./bounded-range-fetch-CggGfMWc.js";import"./vendor-charts-BqgCVUWx.js";import"./data-row-DfgkjsZ9.js";import"./click-to-copy-BRVv3ysm.js";import"./use-parent-model-fields-DOuZtTST.js";import"./search-CVbYxP5X.js";const ss=()=>e.jsx(ce,{children:e.jsx(qe,{})}),qe=()=>{var T,E,B,O,k,R,D,N,F;const{audience:i,parentModel:u}=Ue(),{toast:p}=we(),{appAgentsAudiencesPage:c,appAudienceAgentsTrackClosedGlobally:H}=le(),{hasValidationErrors:L}=me(),{mutateAsync:Y,isLoading:$}=pe(),a=i.static_list,n=ge(i,{resetOnlyOnSourceChange:!1}),d=o.useMemo(()=>Q(n.state.subsets),[n.state.subsets]),[g,X]=o.useState(()=>Q(i.subsets)),b=o.useMemo(()=>{if(d.length!==g.length)return!0;const s=new Set(g);return d.some(t=>!s.has(t))},[d,g]),J=async()=>{if(L()){p({id:"save-subsets",title:"Unable to save subsets",message:"Check your subset selection and try again.",variant:"error"});return}try{const s=String(i.id),t=d.map(r=>({segment_id:s,subset_value_id:r}));await Y({audience_id:s,upsert_objects:t,upsert_subset_ids:t.map(({subset_value_id:r})=>r)}),X(d),p({id:"save-subsets",title:"Subsets were updated",variant:"success"})}catch(s){Te(s),p({id:"save-subsets",title:"Unable to save subsets",message:s.message,variant:"error"})}},{isInsightsOpen:l,setIsInsightsOpen:Z,panel:h,setPanel:ee,onPanelButtonClick:A,onInsightsButtonClick:se}=Re({autoOpen:!1,audienceId:(T=i.id)==null?void 0:T.toString(),appAgentsAudiencesPage:!!c,appAudienceAgentsTrackClosedGlobally:!!H,agentSessionParam:null}),_=o.useRef(null),C=he({parentModelId:u.id,audienceId:i.id}),[j,te]=o.useState(""),[f,P]=o.useState(""),M=n.state.visual_query_filter,ae=((B=(E=n.state.connection)==null?void 0:E.id)==null?void 0:B.toString())??((k=(O=u.connection)==null?void 0:O.id)==null?void 0:k.toString())??"",m=be(n.state,{columns:u.columns,useSampledModels:!1,primaryKeyIds:f?[f]:void 0,onCompleted:(s,t)=>{t&&p({id:"members-error",title:"Member query failed",message:fe(t),variant:"error"})}}),ne=d.join(",");o.useEffect(()=>{!u.id||(a==null?void 0:a.type)!=="csv"||m.runQuery({limit:!0,disableRowCounter:!1})},[u.id,a==null?void 0:a.type,f,ne,M]);const ie=()=>P(j.trim()),re=d.length>0,w=o.useCallback((s,t)=>{n.onChange({...s.length>0&&{visual_query_filter:{...n.state.visual_query_filter,conditions:s.map(r=>G(r))}},...t!=null&&{subsets:v(t)}})},[n]),oe=o.useCallback(({templateId:s,templateConditions:t})=>{var z;const r=n.state.visual_query_filter,U=n.state.audience_templates,q=t==null?void 0:t[0];if(q){const S=(z=r==null?void 0:r.conditions)==null?void 0:z[0],ue=[{type:Se.And,conditions:[...(S==null?void 0:S.conditions)??[],q]}];n.onChange({visual_query_filter:G({...r??{},conditions:ue},!0),audience_templates:[...U??[],{id:s}]})}return()=>n.onChange({visual_query_filter:r,audience_templates:U})},[n]),de=o.useMemo(()=>{var s;return{updateConditions:w,canApplyInPlace:!0,audienceId:(s=i.id)==null?void 0:s.toString()}},[w,i.id]);return(a==null?void 0:a.type)!=="csv"?e.jsx(ve,{to:"../definition",replace:!0}):e.jsx(Fe,{value:de,children:e.jsxs(xe,{agentAvailable:!!c,children:[e.jsxs(x,{position:"relative",display:"grid",gridTemplateColumns:{base:"1fr",[I]:l?`1fr ${Ee}px`:"1fr 0px"},gap:{base:0,[I]:l?4:0},alignItems:"start",width:"100%",py:4,children:[e.jsxs(y,{gridColumn:{base:"1",[I]:"1"},gridRow:"1",gap:4,minWidth:0,children:[e.jsxs(x,{align:"center",gap:2,justify:"space-between",px:6,children:[e.jsxs(y,{gap:1,children:[re?e.jsxs(ye,{color:"text.primary",size:"lg",message:Ie,children:[K(a.size)," members"]}):e.jsxs(V,{color:"text.primary",size:"lg",children:[K(a.size)," members"]}),a.last_materialized_at&&e.jsxs(V,{color:"text.secondary",size:"sm",children:["Imported on"," ",(R=Ae(a.last_materialized_at))==null?void 0:R.toLowerCase()]})]}),e.jsxs(x,{gap:2,children:[e.jsx(_e,{width:"sm",placeholder:"Search",value:j,onChange:s=>{const t=s.target.value;te(t),t.trim()===""&&P("")},onKeyDown:s=>{s.key==="Enter"&&ie()}}),c?e.jsxs(e.Fragment,{children:[e.jsx(Be,{isOpen:l&&h==="agent",onClick:()=>A("agent")}),e.jsx(W,{isInsightsOpen:l&&h==="insights",onClick:()=>A("insights"),permission:C})]}):e.jsx(W,{isInsightsOpen:l,onClick:se,permission:C})]})]}),e.jsx(Ne,{parentModelId:(D=u.id)==null?void 0:D.toString(),value:d,hasBorderRadius:!1,showAndConnector:!1,onChange:s=>n.onChange({subsets:v(s)})}),e.jsx(De,{audienceRows:m.rows??[],parentModel:u,isLoading:m.loading||m.schemaLoading,error:m.error,includeMergedColumns:!1,onSelectMember:()=>{},selectedMember:void 0})]}),e.jsx(Oe,{isOpen:l,showAgentTosOverlay:!!c&&h==="agent",sticky:!0,children:e.jsx(y,{ref:_,flexGrow:1,position:"relative",maxHeight:"calc(100vh - 220p
1x)",overflowY:"auto",pb:10,children:e.jsx(ke,{appAgentsAudiencesPage:!!c,isOpen:l,setOpen:Z,panel:h,setPanel:ee,textAreaPortalRoot:_,sourceId:ae,parentModelId:((N=u.id)==null?void 0:N.toString())??"",audienceName:i.name,audienceId:(F=i.id)==null?void 0:F.toString(),isStaticList:!!(a!=null&&a.id),filter:M??Ce,subsetIds:d,destinationId:void 0,isFastQuery:!1,applyTemplate:oe})})})]}),e.jsxs(je,{isDisabled:!b,children:[e.jsx(Pe,{permission:{v2:{resource:"model",grant:"can_update",id:i.id??""}},isLoading:$,isDisabled:!b,onClick:J,children:"Save subsets"}),e.jsx(Me,{isDisabled:!b,onClick:()=>n.onChange({subsets:v(g)}),children:"Discard changes"})]})]})})};export{ss as AudienceMembers}; 2//# sourceMappingURL=members-CvmGBq3t.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.