1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3067],{25554:function(e,a,t){"use strict";t.d(a,{Cg:function(){return D},DH:function(){return p},DI:function(){return l},F5:function(){return w},Fw:function(){return n},GF:function(){return R},Ij:function(){return g},J1:function(){return N},J7:function(){return r},JV:function(){return A},O4:function(){return i},Od:function(){return c},Ol:function(){return E},T4:function(){return C},UW:function(){return k},WR:function(){return I},aX:function(){return L},cJ:function(){return T},dO:function(){return o},do:function(){return v},hX:function(){return S},ki:function(){return f},kr:function(){return P},mC:function(){return x},qU:function(){return s},vJ:function(){return F}});let n=["read","write","publish"],s=["read"],i="/user/api-tokens",l=e=>"".concat(i,"/").concat(e),r={read:"Read",write:"Write",publish:"Publish"},o={read:"Read your Koast data.",write:"Change your Koast data.",publish:"Push campaigns live to the ad platform."},c=[{value:"never",label:"No expiry"},{value:"30d",label:"30 days"},{value:"90d",label:"90 days"},{value:"1y",label:"1 year"}],d={"30d":30,"90d":90,"1y":365},u=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date;return"never"===e?null:new Date(a.getTime()+864e5*d[e]).toISOString()},h=e=>n.includes(e),m=e=>{let a=Array.isArray(e)?e.filter(h):[],t=n.filter(e=>a.includes(e));return t.length>0?t:[...s]},p=e=>{let a=e.trim().replace(/^\$/,"").replace(/,/g,"");if(!a||!/^\d+(\.\d{1,2})?$/.test(a))return null;let t=Math.round(100*Number(a));return Number.isSafeInteger(t)&&t>0?t:null},v=e=>m(e.scopes).includes("publish"),g=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date;return{name:e.name.trim(),scopes:m(e.scopes),expiresAt:u(e.expiry,a),spendCeilingCents:p(e.spendCeiling)}},x=e=>0!==e.name.trim().length&&(!v(e)||null!==p(e.spendCeiling)),f=(e,a)=>e.includes(a)?e.filter(e=>e!==a):[...e,a],j=e=>"string"==typeof e?e:"",y=e=>"string"==typeof e&&e?e:null,b=e=>"number"==typeof e&&Number.isFinite(e)?Math.trunc(e):null,_=e=>{var a;if(!e||"object"!=typeof e)return null;let t=j(e.id);return t?{id:t,name:j(e.name),prefix:j(e.prefix),scopes:m(e.scopes),createdAt:j(e.createdAt),lastUsedAt:y(e.lastUsedAt),expiresAt:y(e.expiresAt),revokedAt:y(e.revokedAt),spendCeilingCents:b(e.spendCeilingCents),spendCommittedCents:null!==(a=b(e.spendCommittedCents))&&void 0!==a?a:0}:null},w=e=>Array.isArray(e)?e.reduce((e,a)=>{let t=_(a);return t&&e.push(t),e},[]):[],N=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date;return e.revokedAt?"revoked":e.expiresAt&&new Date(e.expiresAt).getTime()<=a.getTime()?"expired":"active"},k={active:"Active",expired:"Expired",revoked:"Revoked"},C=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"â";if(!e)return a;let t=new Date(e);return Number.isNaN(t.getTime())?a:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})},S=e=>e.map(e=>r[e]).join(", "),A=e=>"$".concat((e/100).toFixed(2)),I=e=>null===e.spendCeilingCents?"":(e.spendCeilingCents/100).toFixed(2),P=e=>e.scopes.includes("publish")?null===e.spendCeilingCents?"Not set â cannot publish":"".concat(A(e.spendCommittedCents)," of ").concat(A(e.spendCeilingCents)):"â",T={secret:null,tokenName:null},F=(e,a)=>{switch(a.type){case"reveal":return{secret:a.secret,tokenName:a.tokenName};case"forget":return T;default:return e}},E=e=>e&&"object"==typeof e?y(e.secret):null,D="/user/oauth-clients",L=e=>"".concat(D,"/").concat(e),M=e=>{if(!e||"object"!=typeof e)return null;let a=j(e.id);return a?{id:a,clientName:j(e.clientName)||"Unnamed app",scopes:m(e.scopes),createdAt:j(e.createdAt),lastUsedAt:y(e.lastUsedAt)}:null},R=e=>Array.isArray(e)?e.reduce((e,a)=>{let t=M(a);return t&&e.push(t),e},[]):[]},50259:function(e,a,t){"use strict";t.d(a,{W:function(){return s}});var n=t(99697);let s=async e=>{let{success:a,error:t}=await (0,n.handleFetch)("/brand/change-active",{method:"PUT",body:{newBrandId:e}});return{success:a,error:t}}},10414:function(e,a,t){"use strict";t.r(a),t.d(a,{default:function(){return sh}});var n=t(85893);t(79021);
1var s=t(67294),i=t(98396),l=t(99964),r=t(94184),o=t.n(r),c=t(8683),d=t(41105),u=t(78720),h=t(2275),m=t(67355),p=t(46119),v=t(98327),g=t(25545),x=t(54146),f=t(99697),j=t(92658),y=t(79742),b=t(48856),_=t(89414),w=t(95763),N=t(69686);t(69135);let k="Integrations";var C=e=>{var a;let{navOptions:t,activeOptionName:i,setActiveOptionName:l}=e,r=(0,s.useRef)(null),c=t.find(e=>e.name===k),d=null!==(a=null==c?void 0:c.options.map(e=>e.name))&&void 0!==a?a:[],u=[...t.filter(e=>e.name!==k).flatMap(e=>e.options.map(e=>e.name)),...c&&c.options.length>0?[k]:[]],h=e=>e===k?i===k||d.includes(i):i===e;(0,s.useEffect)(()=>{let e=r.current;if(!e)return;let a=e.querySelector(".settings-tab.--active");if(!a)return;let t=Math.max(0,a.offsetLeft-16);e.scrollTo?e.scrollTo({left:t,behavior:"smooth"}):e.scrollLeft=t},[i]);let m=e=>(0,n.jsx)("div",{className:"settings-nav-section-options",children:e.map((e,a)=>{let{name:t,icon:s}=e;return(0,n.jsxs)("div",{className:o()("settings-nav-section-option",{"--active":i===t}),onClick:()=>l(t),children:[(0,n.jsx)("span",{className:"settings-nav-section-option__icon","data-integration":t,children:s}),(0,n.jsx)("span",{children:t})]},a)})});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"settings-nav",children:t.map((e,a)=>{let{name:t,icon:s,className:i,options:l}=e;return(0,n.jsxs)("div",{className:o()("settings-nav-section",i),children:[(0,n.jsxs)("div",{className:"settings-nav-section-header",children:[s,(0,n.jsx)("span",{children:t})]}),m(l)]},a)})}),(0,n.jsxs)("div",{className:"settings-nav-mobile",children:[(0,n.jsxs)("div",{className:"settings-nav-mobile__head",children:[(0,n.jsx)("h1",{children:"Settings"}),(0,n.jsx)("p",{children:"Manage your account, plan, and billing."})]}),(0,n.jsx)("nav",{className:"settings-tabbar",ref:r,children:u.map(e=>(0,n.jsx)("button",{type:"button",className:o()("settings-tab",{"--active":h(e)}),onClick:()=>l(e),children:e},e))})]})]})};t(4641);var S=e=>{let{component:a}=e;return(0,n.jsx)("div",{className:"settings-display",children:a})},A=t(97256),I=t(52758);t(49907);var P=t(11163),T=t(21023),F=t(87918),E=t(69661),D=t(88078),L=t(72456),M=t(36804),R=t(86501),Z=t(68720);let z=e=>{var a;return{imported:!!(null==e?void 0:e.created),brandId:null!==(a=null==e?void 0:e.brandId)&&void 0!==a?a:null}};var O=()=>{let{isFBIntegrationConnected:e,isFBIntegrationExpired:a,refreshFBIntegrationStatus:t}=(0,c.bp)(),[n,i]=(0,s.useState)(!0),[l,r]=(0,s.useState)(!1),[o,d]=(0,s.useState)(""),[u,h]=(0,s.useState)([]),[m,p]=(0,s.useState)(!1),[v,g]=(0,s.useState)(null),[x,j]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!1),[_,w]=(0,s.useState)(""),[N,k]=(0,s.useState)(null),[C,S]=(0,s.useState)(!1),[A,I]=(0,s.use
1State)(null),[P,T]=(0,s.useState)(!0),[F,E]=(0,s.useState)(!1),[D,L]=(0,s.useState)(null),[M,O]=(0,s.useState)(!1),[B,V]=(0,s.useState)(!0),K=(0,s.useCallback)(async(e,a)=>{d("");let t=await (0,f.handleFetch)(e,a),{success:n,error:s,statusCode:i=200,data:l}=t;if(!n){let a=(null==s?void 0:s.message)||"There was an error fetching your Facebook data. Please try again.",n=null==s?void 0:s.key;return console.error("Facebook API Error (".concat(e,"):"),a,t),d(a),L(null),O(!1),{data:null,success:!1,message:a,statusCode:i,errorKey:n}}return t},[]),U=(0,s.useCallback)(async()=>{var e,a,t;let n=await K("/ads/assets/limit"),s=!0;return!1===n.success&&(null===(e=n.error)||void 0===e?void 0:e.errorKey)==="limitExceeded"||!0===n.success&&(null===(a=n.data)||void 0===a?void 0:a.errorKey)==="limitExceeded"?s=!1:!1===n.success&&console.warn("Non-rate-limit error checking refresh limit:",null===(t=n.error)||void 0===t?void 0:t.message),V(s),s},[K]),W=(0,s.useCallback)(async()=>{i(!0);let e=await K("/ads/status"),{adAccountId:a=null,adAccountName:t=""}=(null==e?void 0:e.data)||{},n=!!a;return j(n),w(t||""),k(a),i(!1),r(!0),{adAccountId:a,hasSelectedAccount:n}},[K]),Q=(0,s.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(S(!0),!e||a)return h([]),p(!0),g(null),L(null),S(!1),[];let{data:s=[]}=await K("/ads/adaccount?fresh=".concat(t,"&minimal=true")),i=Array.isArray(s)?s:[];h(i),p(!0);let l=!1;if(!n&&N&&i.length>0){let e=i.find(e=>{let{id:a}=e;return a===N});e?(g(e),l=!0):console.warn("Initial Ad Account ID not found in fetched list.")}return l||(g(null),L(null)),S(!1),i},[K,N,e,a]),H=(0,s.useCallback)(async function(t){let n=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(!e||a||!N){I(null),n&&T(!1);return}n&&T(!0),d("");let{data:s=null}=await K(t?"/ads/adaccount/details?accountId=".concat(t):"/ads/adaccount/details");I(s),n&&T(!1)},[K,e,a,N]),q=(0,s.useCallback)(async e=>{if(!e){L(null);return}let a=u.find(a=>a.id===e),t=(null==a?void 0:a.name)||"Ad Account ".concat(e);O(!0),d("");try{let a=await K("/ads/assets?accountId=".concat(e)),{pages:n,pixels:s,igAccounts:i}=(null==a?void 0:a.data)||{};L({id:e,name:t,pages:n||[],pixels:s||[],instagramAccounts:i||[]})}catch(e){console.error("Error fetching preview assets:",e),L(null)}finally{O(!1)}},[u,K]),G=(0,s.useCallback)(async function(t){let n,s=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if(!e||a||!N||F||!B)return;E(!0),s&&(n=R.ZP.loading("Refreshing ad account details..."));let{error:i,success:l}=await K(t?"/ads/assets?accountId=".concat(t):"/ads/assets");n&&R.ZP.dismiss(n),l?(H(t),s&&R.ZP.success("Ad account details refreshed successfully.")):s&&R.ZP.error(i||"Failed to refresh ad account details."),E(!1),await U()},[e,a,N,F,H,o,U]),Y=(0,s.useCallback)(async e=>{if(!e||y)return!1;b(!0);try{let a=await K("/ads/adaccount/",{method:"POST",body:{accountId:e}});if(a.success){let{imported:t,brandId:n}=z(a.data);if(t)return Z.k.info("[ACTION] Ad account imported into a new brand",{adAccountId:e,brandId:n}),R.ZP.success("Ad Account imported successfully! The page will refresh to reflect the new changes.",{duration:1e3}),setTimeout(()=>window.location.reload(),1e3),!0;h([]),p(!1),g(null),j(!1),w(""),k(null),I(null),L(null),Z.k.info("[ACTION] Ad account connected",{adAccountId:e}),R.ZP.success("Ad Account selection confirmed. Fetching details...");let{adAccountId:s}=await W();return s?await H(null,!0):T(!1),b(!1),!0}return R.ZP.error(a.message||"Failed to confirm Ad Account selection."),b(!1),L(null),!1}catch(e){return console.error("Error changing ad account:",e),R.ZP.error("An unexpected error occurred while changing the ad account. Please try again."),b(!1),L(null),!1}},[y,K,W,H]);(0,s.useEffect)(()=>{e&&!a?(W().then(e=>{let{hasSelectedAccount:a,adAccountId:t}=e;k(t),Q(!0,!0),a?H(null,!0):(I(null),T(!1),L(null),O(!1))}),U()):(i(!1),r(!0),h([]),p(!0),j(!1),g(null),w(""),I(null),T(!1),k(null),L(null),O(!1),V(!0))},[e,a,W,U,Q,H]);let J=async()=>
1v?Y(v.id):(R.ZP.error("Please select an Ad Account."),!1);return{selectedAdAccount:v,hasSelectedAdAccount:x,facebookDataError:o,isLoadingStatus:n,hasFetchedStatus:l,adAccounts:u,hasFetchedAdAccounts:m,isLoadingAdAccountChange:y,facebookAdAccountName:_,handleSelectAdAccount:e=>{g(u.find(a=>{let{id:t}=a;return t===e})||null),e?q(e):L(null)},handleConfirmAdAccount:J,handleDisconnectFBFromBrand:async()=>{b(!0);let{success:e,message:a}=await (0,f.handleFetch)("/brand/current/facebook-integration",{method:"DELETE"});b(!1),e?(Z.k.info("[ACTION] Ad account disconnected"),R.ZP.success("Facebook integration disconnected for this brand."),h([]),p(!1),g(null),j(!1),w(""),k(null),d(""),I(null),T(!1),L(null),O(!1),t()):R.ZP.error(a||"Failed to disconnect Facebook integration.")},initialAdAccountId:N,fetchAdAccounts:Q,isFetchingAdAccounts:C,adAccountDetails:A,isLoadingDetails:P,isRefreshingDetails:F,refreshAdAccountAssets:G,previewAdAccountDetails:D,isLoadingPreviewDetails:M,canRefreshAssets:B}};let B=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,[t,n]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{let e=setTimeout(()=>n(!0),a);return()=>clearTimeout(e)},[a]),e||!t};var V=t(95202),K=t(84948),U=t(80522);t(71059);var W=t(50480),Q=t(45843);let H={addOverlays:!1,showProducts:!1,visualTouchups:!1,imageAnimation:!1,textImprovements:!1,enhanceCta:!1,music:!1},q={addOverlays:"Add overlays",showProducts:"Show products",visualTouchups:"Visual touch-ups",imageAnimation:"Image animation",textImprovements:"Text improvements",enhanceCta:"Enhance CTA",music:"Music"},G={addOverlays:"Add dynamic overlays and templates to your images",showProducts:"Automatically show relevant products from your catalog",visualTouchups:"Apply automatic visual enhancements to your images",imageAnimation:"Add subtle animations to static images",textImprovements:"AI-powered text optimization and variations",enhanceCta:"Optimize call-to-action buttons for better performance",music:"Add background music to video content"};var Y=e=>{let{adAccountId:a}=e,[t,i]=(0,s.useState)(!1),[l,r]=(0,s.useState)(H),[o,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(new Set),h=async()=>{var e;let a=await (0,f.handleFetch)("/ads/adlauncher/settings"),t=null!==(e=null==a?void 0:a.data)&&void 0!==e?e:a;t&&(i(!!t.defaultUseAdvantageCreatives),r({...H,...t.advantageCreativeSettings||{}}))};(0,s.useEffect)(()=>{h()},[a]);let m=async()=>{let e=!t;i(e);let a={...l};e&&(!l||Object.values(l).every(e=>!1===e))&&r(a={addOverlays:!0,showProducts:!0,visualTouchups:!0,imageAnimation:!0,textImprovements:!0,enhanceCta:!0,music:!0}),c(!0);try{await (0,f.handleFetch)("/ads/adlauncher/settings",{method:"PUT",body:{settings:{defaultUseAdvantageCreatives:e,advantageCreativeSettings:a}}}),R.ZP.success("Settings saved")}finally{c(!1)}},p=async e=>{let a={...l,[e]:!l[e]};r(a);let n=Object.values(a).every(e=>!1===e),s=t;n&&t&&(s=!1,i(!1)),u(a=>new Set(a).add(e));try{await (0,f.handleFetch)("/ads/adlauncher/settings",{method:"PUT",body:{settings:{defaultUseAdvantageCreatives:s,advantageCreativeSettings:a}}}),R.ZP.success("Settings saved")}finally{u(a=>{let t=new Set(a);return t.delete(e),t})}},v=e=>(0,n.jsx)("div",{className:"feature-toggle",children:(0,n.jsx)(T.Z,{title:G[e],placement:"top",children:(0,n.jsx)(W.Z,{control:(0,n.jsx)(Q.Z,{checked:l[e]&&t,onChange:a=>{a.stopPropagation(),p(e)},disabled:!t||d.has(e)}),label:q[e]})})},e);return(0,n.jsxs)("div",{className:"advantage-enhancements-settings",children:[(0,n.jsx)("div",{className:"master-toggle-row",children:(0,n.jsx)(T.Z,{title:"Enable or disable individual Advantage+ creative enhancements for this ad account.",children:(0,n.jsx)(W.Z,{control:(0,n.jsx)(Q.Z,{checked:t,onChange:e=>{e.stopPropagation(),m()},disabled:o}),label:"Enable Advantage+ Enhancements"})})}),(0,n.jsxs)("div",{className:"features-grid",children:[(0,n.jsxs)("div",{className:"feature-group",children:[(0,n.jsx)("h4",{className:"group-title",children:"Visual & Animation"}),(0,n.jsx)("div",{className:"feature-row",children:["addOverlays","visualTouchups","imageAnimation"].map(e=>v(e))})]}),(0,n.jsxs)("div",{className:"feature-group",children:[(0,n.jsx)("h4",{className:"group-title",children:"Text & Content"}),(0,n.jsx)("div",{className:"feature-row",children:["textImprovements","enhanceCta"].map(e=>v(e))})]}),(0,n.jsxs)("div",{className:"feature-group",children:[(0,n.jsx)("h4",{className:"group-title",children:"Media & Products"}),(0,n.jsx)("div",{className:"feature-row",children:["showProducts","music"].map(e=>v(e))})]})]})]})};t(96763);var J=t(36529);let X=()=>(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"
1currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 1 3 5v6c0 5.6 3.8 10.7 9 12 5.2-1.3 9-6.4 9-12V5zm-2 15-4-4 1.4-1.4L10 13.2l6.6-6.6L18 8z"})});var $=e=>{let{logo:a,logoBgColor:t,haloColorRgb:i,eyebrow:l,title:r,subtitle:o,features:c,ctaText:d,ctaIcon:u,onCtaClick:h,ctaLoading:m=!1,ctaLoadingText:p,ctaDisabled:v=!1,trustItems:g}=e;return(0,n.jsx)("div",{className:"integration-empty-state",style:{"--halo-rgb":i,"--logo-shadow-rgb":i},children:(0,n.jsxs)("div",{className:"integration-empty-state__center",children:[(0,n.jsxs)("div",{className:"integration-empty-state__logo-wrap",children:[(0,n.jsx)("span",{className:"integration-empty-state__halo"}),(0,n.jsx)("span",{className:"integration-empty-state__halo integration-empty-state__halo--2"}),(0,n.jsx)("div",{className:"integration-empty-state__logo",style:t?{background:t}:{},children:a})]}),(0,n.jsx)("div",{className:"integration-empty-state__eyebrow",children:l}),(0,n.jsx)("h1",{className:"integration-empty-state__title",children:r}),(0,n.jsx)("p",{className:"integration-empty-state__subtitle",children:o}),(0,n.jsx)("div",{className:"integration-empty-state__features",children:c.map(e=>(0,n.jsxs)("div",{className:"integration-empty-state__feature",children:[(0,n.jsx)("div",{className:"integration-empty-state__feature-icon",children:e.icon}),(0,n.jsx)("div",{className:"integration-empty-state__feature-title",children:e.title}),(0,n.jsx)("div",{className:"integration-empty-state__feature-description",children:e.description})]},e.title))}),(0,n.jsx)("button",{type:"button",className:"integration-empty-state__cta",onClick:h,disabled:m||v,children:m?(0,n.jsx)(J.Z,{color:"#ffffff",size:8}):(0,n.jsxs)(n.Fragment,{children:[u&&(0,n.jsx)("span",{className:"integration-empty-state__cta-icon",children:u}),m&&p?p:d,(0,n.jsx)("span",{className:"integration-empty-state__cta-arrow",children:"â"})]})}),g&&g.length>0&&(0,n.jsx)("div",{className:"integration-empty-state__trust",children:g.map((e,a)=>(0,n.jsxs)(s.Fragment,{children:[(0,n.jsxs)("span",{children:[0===a&&(0,n.jsx)(X,{}),e]}),a<g.length-1&&(0,n.jsx)("span",{className:"integration-empty-state__trust-dot"})]},e))})]})})};t(36249);let ee=()=>(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2Zm-1 5h2v6h-2Zm1 12a1.4 1.4 0 1 1 1.4-1.4A1.4 1.4 0 0 1 12 19Z"})});var ea=e=>{let{message:a,className:t,icon:i,align:l="center"}=e,[r,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(!1),h=(0,s.useRef)(null);return((0,s.useEffect)(()=>{if(h.current&&(clearTimeout(h.current),h.current=null),a){u(!1),c(a);return}r&&(u(!0),h.current=setTimeout(()=>{c(null),u(!1)},220))},[a]),(0,s.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]),r)?(0,n.jsxs)("div",{role:"alert",className:o()("koast-error-banner","koast-error-banner--".concat(l),{"koast-error-banner--exiting":d},t),children:[(0,n.jsx)("span",{className:"koast-error-banner__icon",children:null!=i?i:(0,n.jsx)(ee,{})}),(0,n.jsx)("span",{className:"koast-error-banner__text",children:r})]}):null};t(22589);var et=t(15949),en=t(21833),es=t(30518),ei=t(52169),el=t(42647),er=t(66186),eo=t(29243),ec=t(95590),ed=t(68780),eu=t(26035);let eh={meta:{logo:(0,n.jsx)(d.RU,{width:32,height:32}),haloRgb:"24, 119, 242",credential:null},whop:{logo:(0,n.jsx)(d.BI,{width:40,height:24}),haloRgb:"250, 70, 22",credential:{label:"Company API key",name:"company API key",hint:"Create one in your Whop dashboard under Developer, then paste it here. Koast connects every ad account the key can reach, stores the key encrypted and never displays it again."}},tiktok:{logo:(0,n.jsx)(en.Z,{sx:{fontSize:32}}),haloRgb:"99, 102, 241",credential:null}},em={label:"API key",name:"API key",hint:"Koast stores this encrypted and never displays it again."},ep=new Set(["provider_not_live","provider_not_connectable"]),ev=[{title:"Ad Publishing",description:"Launch and manage campaigns on this provider from Koast.",icon:(0,n.jsx)(en.Z,{fontSize:"small"})},{title:"Account Sync",description:"Pull in the ad accounts your credential can reach.",icon:(0,n.jsx)(es.Z,{fontSize:"small"})},{title:"Unified Reporting",description:"See this provider alongside your other ad spend.",icon:(0,n.jsx)(ei.Z,{fontSize:"small"})}];t(3811);var eg=t(60114),ex=t(19634),ef=t(98675),ej=t(54869),ey=t(25252);t(2403);var eb=t(31026),e_=t(50267),ew=t(26576),eN=t(54299);t(43500);var ek=e=>{let{isConnected:a}
1=e,[t,i]=(0,s.useState)([]),[l,r]=(0,s.useState)(!1),[o,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(null),h=async()=>{if(a){r(!0),c("");try{let{data:e,error:a}=await (0,f.handleFetch)("/integrations/redtrack/campaigns",{method:"GET"});if(a)throw Error(a.message||"Failed to fetch RedTrack campaigns");i(null!=e?e:[]),u(new Date)}catch(e){c(e.message||"Failed to fetch campaigns"),i([])}finally{r(!1)}}};(0,s.useEffect)(()=>{a?h():(i([]),c(""),u(null))},[a]);let m=e=>{if(!e)return"N/A";try{return new Date(e).toLocaleDateString()}catch(e){return"Invalid date"}},p=e=>{switch(e){case 1:return"Active";case 2:return"Paused";case 0:return"Inactive";default:return"Unknown"}};return a?(0,n.jsxs)("div",{className:"redtrack-campaigns-list",children:[(0,n.jsxs)("div",{className:"campaigns-header",children:[(0,n.jsx)("h3",{children:"RedTrack Campaigns"}),(0,n.jsx)(K.Z,{onClick:h,disabled:l,color:"secondary",size:"sm",children:l?"Loading...":"Refresh"})]}),o&&(0,n.jsx)("div",{className:"campaigns-error",children:(0,n.jsxs)("p",{children:["Error: ",o]})}),!l&&!o&&0===t.length&&(0,n.jsx)("div",{className:"campaigns-empty",children:(0,n.jsx)("p",{children:"No campaigns found in your RedTrack account."})}),t.length>0&&(0,n.jsxs)("div",{className:"campaigns-content",children:[(0,n.jsx)("div",{className:"campaigns-summary",children:(0,n.jsxs)("p",{children:["Found ",t.length," campaign",1!==t.length?"s":"",d&&(0,n.jsxs)("span",{className:"last-fetched",children:[" ","⢠Last updated: ",d.toLocaleTimeString()]})]})}),(0,n.jsxs)("div",{className:"campaigns-table",children:[(0,n.jsxs)("div",{className:"campaigns-table-header",children:[(0,n.jsx)("div",{className:"campaign-name",children:"Campaign Name"}),(0,n.jsx)("div",{className:"campaign-status",children:"Status"}),(0,n.jsx)("div",{className:"campaign-created",children:"Created"})]}),(0,n.jsx)("div",{className:"campaigns-table-body",children:t.map(e=>(0,n.jsxs)("div",{className:"campaign-row",children:[(0,n.jsx)("div",{className:"campaign-name",title:"".concat(e.title," (ID: ").concat(e.id,")"),children:e.title}),(0,n.jsx)("div",{className:"campaign-status",children:(0,n.jsx)("span",{className:"status-badge status-".concat(p(e.status).toLowerCase()),children:p(e.status)})}),(0,n.jsx)("div",{className:"campaign-created",children:m(e.created_at)})]},e.id))})]}),(0,n.jsx)("div",{className:"campaigns-note",children:(0,n.jsxs)("p",{children:[(0,n.jsx)("strong",{children:"Beta Testing:"})," Compare this list with your RedTrack dashboard to confirm the integration is working correctly."]})})]})]}):null},eC=t(39042);let eS=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,[t,n]=(0,s.useState)(null),[i,l]=(0,s.useState)(!1),[r,o]=(0,s.use
1State)(null),c=async()=>{try{l(!0),o(null);let a=await (0,f.handleFetch)("/integrations/redtrack/aggregation-status",{method:"GET"});if(null==a?void 0:a.success)n(a.data);else{var e;o((null==a?void 0:null===(e=a.error)||void 0===e?void 0:e.message)||"Failed to fetch status")}}catch(e){console.error("Error fetching RedTrack status:",e),o(e.message||"Network error")}finally{l(!1)}};(0,s.useEffect)(()=>{c()},[]),(0,s.useEffect)(()=>{if(!e)return;let t=setInterval(c,a);return()=>clearInterval(t)},[e,a]);let d=(null==t?void 0:t.overallStatus)==="processing"||(null==t?void 0:t.overallStatus)==="initializing",u=(null==t?void 0:t.overallStatus)==="error",h=(null==t?void 0:t.overallStatus)==="completed";return{status:t,loading:i,error:r,fetchStatus:c,isProcessing:d,hasErrors:u,isCompleted:h}};t(13746);let eA="We could not verify this key's Cometly space. If it belongs to a different space, synced Cometly data will be cleared and a fresh sync (~30 days) will start.",eI=(e,a)=>e?!1===a?"This key belongs to a different Cometly space. Synced Cometly data will be cleared and a fresh sync (~30 days) will start.":"":eA;var eP=t(50749);let eT=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,[t,n]=(0,s.useState)(null),[i,l]=(0,s.useState)(!1),[r,o]=(0,s.use
1State)(null),c=async()=>{try{l(!0),o(null);let a=await (0,f.handleFetch)("/integrations/cometly/aggregation-status",{method:"GET"});if(null==a?void 0:a.success)n(a.data);else{var e;o((null==a?void 0:null===(e=a.error)||void 0===e?void 0:e.message)||"Failed to fetch status")}}catch(e){console.error("Error fetching Cometly status:",e),o(e instanceof Error?e.message:"Network error")}finally{l(!1)}};(0,s.useEffect)(()=>{c()},[]),(0,s.useEffect)(()=>{if(!e)return;let t=setInterval(c,a);return()=>clearInterval(t)},[e,a]);let d=(null==t?void 0:t.overallStatus)==="processing"||(null==t?void 0:t.overallStatus)==="initializing",u=(null==t?void 0:t.overallStatus)==="error",h=(null==t?void 0:t.overallStatus)==="completed";return{status:t,loading:i,error:r,fetchStatus:c,isProcessing:d,hasErrors:u,isCompleted:h}},eF=[{value:"first_platform_touch",label:"First touch (paid)"},{value:"last_platform_touch",label:"Last touch (paid)"}],eE=[{value:"1",label:"1 day"},{value:"7",label:"7 days"},{value:"14",label:"14 days"},{value:"30",label:"30 days"},{value:"60",label:"60 days"},{value:"90",label:"90 days"},{value:"0",label:"Lifetime"}];t(5089);let eD=e=>"".concat(e.toLocaleString()," ad-set days stored."),eL=e=>"number"!=typeof e||e<=0?"Scanning your Hyros account for attribution data.":"Scanning your Hyros account for attribution data â ".concat(e.toLocaleString()," days queued."),eM=e=>"error"===e.status?{tone:"error",message:"Hyros rejected the stored key. Reconnect to continue syncing."}:"no_ad_account"===e.status?{tone:"error",message:"This brand has no Meta ad account connected in Koast, so there is nothing for Hyros to attribute against. Connect Meta first."}:!1===e.workerReachable?{tone:"neutral",message:"Sync status is temporarily unavailable. Attribution data already stored is unaffected."}:e.isScanning?{tone:"progress",message:eL(e.pendingJobs)}:0===e.rowCount?{tone:"neutral",message:"Connected â waiting for the first nightly sync to bring in attribution data."}:"completed"===e.status?{tone:"success",message:eD(e.rowCount)}:{tone:"progress",message:"".concat(eD(e.rowCount)," Refreshing recent days.")};class eR{static isModel(e){return eR.OPTIONS.some(a=>a.value===e)}static modelOf(e){let a=null==e?void 0:e.attributionModel;return eR.isModel(a)?a:eR.DEFAULT_MODEL}}eR.DEFAULT_MODEL="last_click",eR.OPTIONS=[{value:"last_click",label:"Last source"},{value:"first_click",label:"First source"},{value:"scientific",label:"Scientific"}];var eZ=t(59079);let ez=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,[t,n]=(0,s.useState)(null),[i,l]=(0,s.useState)(!1),[r,o]=(0,s.use
1State)(null),c=(0,s.useCallback)(async()=>{try{l(!0),o(null);let a=await (0,f.handleFetch)("/integrations/hyros/status",{method:"GET"});if(null==a?void 0:a.success)n(a.data);else{var e;o((null==a?void 0:null===(e=a.error)||void 0===e?void 0:e.message)||"Failed to fetch status")}}catch(e){o(e instanceof Error?e.message:"Network error")}finally{l(!1)}},[]);return(0,s.useEffect)(()=>{c()},[c]),(0,s.useEffect)(()=>{if(!e)return;let t=setInterval(c,a);return()=>clearInterval(t)},[e,a,c]),{status:t,loading:i,error:r,fetchStatus:c,isInitializing:(null==t?void 0:t.status)==="initializing",hasErrors:(null==t?void 0:t.status)==="error",isCompleted:(null==t?void 0:t.status)==="completed",isScanning:(null==t?void 0:t.isScanning)===!0,isWorkerUnreachable:(null==t?void 0:t.workerReachable)===!1}},eO=[{value:"daily",label:"Daily"}];t(9576);var eB=t(37891),eV=t(53438);let eK=()=>{let{user:e}=(0,c.bp)(),a="whop"===(0,eV.Ip)(null==e?void 0:e.activeBrand),[t,n]=(0,s.useState)([]),[i,l]=(0,s.useState)(!1),[r,o]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{if(!a){l(!0);return}let e=await (0,f.handleFetch)("/pixel/conversion-keys",{method:"GET"});if(l(!0),(null==e?void 0:e.success)===!1||!(null==e?void 0:e.data)){var t;u((null==e?void 0:null===(t=e.error)||void 0===t?void 0:t.message)||"We could not load your conversion keys just now.");return}u(null),n(e.data)},[a]),m=(0,s.useCallback)(async e=>{o(!0),u(null);let a=await (0,f.handleFetch)("/pixel/conversion-keys",{method:"POST",body:JSON.stringify({name:e})});if(o(!1),(null==a?void 0:a.success)===!1||!(null==a?void 0:a.data)){var t;return u((null==a?void 0:null===(t=a.error)||void 0===t?void 0:t.message)||"We could not create that key."),null}let s=a.data;return n(e=>[{id:s.id,name:s.name,prefix:s.prefix,createdAt:s.createdAt},...e]),s},[]);return(0,s.useEffect)(()=>{h()},[h]),{keys:t,hasFetched:i,creating:r,error:d,supported:a,create:m,atLimit:t.length>=3}};var eU=t(98033),eW=t(79347),eQ=t(70154),eH=t(62278),eq=t(50098),eG=()=>(0,n.jsxs)("span",{className:"pixel-agents",children:[(0,n.jsx)("span",{className:"pixel-agents__badge pixel-agents__badge--claude",title:"Claude",children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",stroke:"#FFFFFF",strokeWidth:"2.6",strokeLinecap:"round",children:[(0,n.jsx)("path",{d:"M12 4.5v15"}),(0,n.jsx)("path",{d:"M5.5 8.25l13 7.5"}),(0,n.jsx)("path",{d:"M5.5 15.75l13-7.5"})]})}),(0,n.jsx)("span",{className:"pixel-agents__badge pixel-agents__badge--codex",title:"Codex",children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#FFFFFF",strokeWidth:"1.6",children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"4",ry:"9.5"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"4",ry:"9.5",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"4",ry:"9.5",transform:"rotate(120 12 12)"})]})}),(0,n.jsx)("span",{className:"pixel-agents__badge pixel-agents__badge--cursor",title:"Cursor",children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#FFFFFF",strokeWidth:"1.6",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2.5l8.5 4.75v9.5L12 21.5 3.5 16.75v-9.5z"}),(0,n.jsx)("path",{d:"M12 12l8.5-4.75M12 12v9.5M12 12L3.5 7.25"})]})}),(0,n.jsx)("span",{className:"pixel-agents__badge pixel-agents__badge--gemini",title:"Gemini",children:(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M12 2.5c.6 4.6 2.4 7 7 7.6-4.6.6-6.4 3-7 7.6-.6-4.6-2.4-7-7-7.6 4.6-.6 6.4-3 7-7.6z",fill:"#4285F4"})})})]});t(84947);var eY=t(36315),eJ=t(60666),eX=t(80251);let e$=[{days:7,label:"7 days"},{days:30,label:"30 days"},{days:90,label:"90 days"}],e0=(e,a)=>{try{return new Intl.DateTimeFormat("en-CA",{timeZone:a,year:"numeric",month:"2-digit",day:"2-digit"}).format(e)}catch(a){return e.toISOString().slice(0,10)}},e1=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"UTC",n=e0(a,t);return{from:e0(new Date(Date.parse("".concat(n,"T00:00:00.000Z"))-(Math.max(1,Math.floor(e))-1)*864e5),"UTC"),to:n}},e2=(e,a)=>{var t;let n=new Map((null!==(t=null==a?void 0:a.standardEvents)&&void 0!==t?t:[]).map((e,a)=>[e,a])),s=e=>{var a;return null!==(a=n.get(e.eventName))&&void 0!==a?a:Number.MAX_SAFE_INTEGER};return{standard:e.filter(e=>"standard"===e.kind).sort((e,a)=>s(e)-s(a)),custom:e.filter(e=>"custom"===e.kind),automatic:e.filter(e=>"automatic"===e.kind),native:e.filter(e=>"native"===e.kind)}},e5=e=>"firing"===e?"success":"stale"===e?"warning":"unknown"===e?"danger":"neutral",e3=e=>e<=0?"today":1===e?"yesterday":"".concat(e," days ago"),e4=e=>{var a;return"firing"===e.status?"Firing \xb7 last ".concat(e3(null!==(a=e.lastFiredDays)&&void 0!==a?a:0)):"stale"===e.status?null===e.lastFiredDays?"Stale":"Stale \xb7 last ".concat(e3(e.lastFiredDays)):"unknown"===e.status?"Unknown \xb7 the provider could not read its events":"Never fired"},e8=e=>{if(!Number.isFinite(e.amountMinor)||0===e.amountMinor)return null;let a=e.amountMinor/100;try{return new Intl.NumberFormat("en-US",{style:"currency",currency:e.currency}).format(a)}catch(t){return"".concat(a.toFixed(2)," ").concat(e.currency)}},e6=e=>
1new Intl.NumberFormat("en-US").format(Math.max(0,Math.round(e))),e9=(e,a)=>{var t;return"custom"===e.kind||"standard"===e.kind&&(null!==(t=null==a?void 0:a.testFireEvents)&&void 0!==t?t:[]).includes(e.eventName)},e7=e=>"automatic"===e.kind?"The snippet fires this one on its own on every page.":"native"===e.kind?"Counted by the ad platform itself; nothing to fire.":"Counted as real money by the ad networks, so it cannot be fired from here.",ae=function(e,a){var t,n,s;let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=e.trim(),r=null!==(t=null==a?void 0:a.customEventNameMaxLength)&&void 0!==t?t:0;if(0===l.length)return"Give the event a name.";if(r>0&&l.length>r)return"Keep it under ".concat(r," characters.");let o=l.toLowerCase();return(null!==(n=null==a?void 0:a.reservedNames)&&void 0!==n?n:[]).includes(o)?(null!==(s=null==a?void 0:a.standardEvents)&&void 0!==s?s:[]).includes(o)?'"'.concat(l,'" is a standard event the pixel already fires. Pick a name of your own.'):'"'.concat(l,'" is a name the pixel keeps for its own events. Pick a name of your own.'):i.some(e=>e.toLowerCase()===o)?'"'.concat(l,'" is already defined on this ad account.'):null},aa=e=>{var a;return(null===(a=e.label)||void 0===a?void 0:a.trim())||e.eventName},at=e=>{let{user:a}=(0,c.bp)(),t="whop"===(0,eV.Ip)(null==a?void 0:a.activeBrand),[n,i]=(0,s.useState)(null),[l,r]=(0,s.useState)(!1),[o,d]=(0,s.useState)(!1),[u,h]=(0,s.useState)(null),[m,p]=(0,s.useState)(null),v=(0,s.useCallback)(async function(){let a=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!t)return r(!0),null;a||d(!0);let n=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC",{from:s,to:l}=e1(e,new Date,n),o="?from=".concat(s,"&to=").concat(l,"&timeZone=").concat(encodeURIComponent(n)),c=await (0,f.handleFetch)("/pixel/events/summary".concat(o),{method:"GET",cache:"no-store"});if(a||d(!1),r(!0),(null==c?void 0:c.success)===!1||!(null==c?void 0:c.data)){var u;return h((null==c?void 0:null===(u=c.error)||void 0===u?void 0:u.message)||"We could not read your events just now."),null}let m=c.data;return h(null),i(m),m},[t,e]);(0,s.useEffect)(()=>{v()},[v]);let g=e=>!e||!1===e.success||void 0===e.data,x=(0,s.useCallback)(async e=>{p("create"),h(null);let a=await (0,f.handleFetch)("/pixel/custom-events",{method:"POST",body:JSON.stringify(e)});if(p(null),g(a)){var t;return h((null==a?void 0:null===(t=a.error)||void 0===t?void 0:t.message)||"We could not add that event."),null}return await v(!0),a.data},[v]),j=(0,s.useCallback)(async(e,a)=>{p(e),h(null);let t=await (0,f.handleFetch)("/pixel/custom-events/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(a)});if(p(null),g(t)){var n;return h((null==t?void 0:null===(n=t.error)||void 0===n?void 0:n.message)||"We could not save that event."),null}return await v(!0),t.data},[v]),y=(0,s.useCallback)(async e=>{p(e),h(null);let a=await (0,f.handleFetch)("/pixel/custom-events/".concat(encodeURIComponent(e)),{method:"DELETE"});if(p(null),(null==a?void 0:a.success)===!1){var t;return h((null==a?void 0:null===(t=a.error)||void 0===t?void 0:t.message)||"We could not remove that event."),!1}return await v(!0),!0},[v]);return{summary:n,hasFetched:l,loading:o,error:u,busy:m,supported:t,read:v,createCustomEvent:x,updateCustomEvent:j,deleteCustomEvent:y,fireEvent:(0,s.useCallback)(async e=>{p("fire:".concat(e.eventName)),h(null);let a=await (0,f.handleFetch)("/pixel/events/fire",{method:"POST",body:JSON.stringify(e)});if(p(null),g(a)){var t;return h((null==a?void 0:null===(t=a.error)||void 0===t?void 0:t.message)||"We could not fire that event."),null}return a.data},[])}},an=e=>{let{title:a,hint:t,rows:s,render:i}=e;return 0===s.length?null:(0,n.jsxs)("div",{className:"event-manager__group",children:[(0,n.jsxs)("div",{className:"event-manager__group-head",children:[(0,n.jsx)("span",{className:"event-manager__group-title",children:a}),t&&(0,n.jsx)("span",{className:"event-manager__group-hint",children:t})]}),(0,n.jsx)("div",{className:"event-manager__rows",children:s.map(i)})]})};var as=e=>{var a;let{accountId:t}
1=e,[i,l]=(0,s.useState)(30),[r,o]=(0,s.useState)(!1),[c,d]=(0,s.useState)(""),[u,h]=(0,s.useState)(""),[m,p]=(0,s.useState)(null),[v,g]=(0,s.useState)(""),[x,f]=(0,s.useState)(""),{summary:j,hasFetched:y,loading:b,error:_,busy:w,supported:N,read:k,createCustomEvent:C,updateCustomEvent:S,deleteCustomEvent:A,fireEvent:I}=at(i);(0,s.useEffect)(()=>{if(!N)return;let e=()=>{"visible"===document.visibilityState&&k(!0)},a=setInterval(e,6e4);return window.addEventListener("focus",e),()=>{clearInterval(a),window.removeEventListener("focus",e)}},[N,k]);let P=null!==(a=null==j?void 0:j.vocabulary)&&void 0!==a?a:null,F=(0,s.useMemo)(()=>{var e;return e2(null!==(e=null==j?void 0:j.events)&&void 0!==e?e:[],P)},[j,P]),E=(0,s.useMemo)(()=>F.custom.filter(e=>null!==e.definitionId).map(e=>e.eventName),[F]),D=0===c.length?null:ae(c,P,E);if(!N)return null;let L=async(e,a)=>{await (0,eq.b0)(e)?R.Am.success(a):R.Am.error("We could not copy that. Select it and copy manually.")},M=async e=>{await I({eventName:e.eventName})&&R.Am.success("Fired ".concat(aa(e)," on ").concat(null!=t?t:"this ad account",". It takes a few minutes to be counted; this list refreshes on its own."))},Z=async()=>{let e=await C({name:c.trim(),label:u.trim()||null});if(e){var a;R.Am.success("Added ".concat(null!==(a=e.label)&&void 0!==a?a:e.name,". Fire it from your site with the snippet.")),d(""),h(""),o(!1)}},z=e=>{var a,t;p(e.definitionId),g(null!==(a=e.label)&&void 0!==a?a:""),f(null!==(t=e.description)&&void 0!==t?t:"")},O=async()=>{null!==m&&await S(m,{label:v.trim()||null,description:x.trim()||null})&&p(null)},B=async e=>{null!==e.definitionId&&await A(e.definitionId)&&R.Am.success("Removed ".concat(aa(e),". Events your site already fired stay counted."))},V=e=>{var a;let s=e5(e.status),i=e8(e.value),l=(0,eq.wb)(e.eventName),r=e9(e,P),o=w==="fire:".concat(e.eventName),c=null!==e.definitionId&&m===e.definitionId;return(0,n.jsxs)("div",{className:"event-manager__row",children:[(0,n.jsxs)("div",{className:"event-manager__cell event-manager__cell--name",children:[(0,n.jsx)("span",{className:"event-manager__dot event-manager__dot--".concat(s)}),(0,n.jsxs)("div",{className:"event-manager__names",children:[(0,n.jsx)("span",{className:"event-manager__label",children:aa(e)}),(0,n.jsx)("span",{className:"event-manager__mono",children:null!==(a=e.fullName)&&void 0!==a?a:e.eventName})]})]}),(0,n.jsxs)("div",{className:"event-manager__cell event-manager__cell--status",children:[(0,n.jsx)("span",{className:"event-manager__status event-manager__status--".concat(s),children:e4(e)}),"native"!==e.kind&&(e.wiredOnPage||e.wiredOnHost)&&(0,n.jsx)("span",{className:"event-manager__wired",children:e.wiredOnPage?"On verified page":"On this site"})]}),(0,n.jsxs)("div",{className:"event-manager__cell event-manager__cell--count",children:[(0,n.jsx)("span",{className:"event-manager__count",children:e6(e.count)}),i&&(0,n.jsx)("span",{className:"event-manager__value",children:i})]}),(0,n.jsxs)("div",{className:"event-manager__cell event-manager__cell--actions",children:["native"!==e.kind&&"automatic"!==e.kind&&(0,n.jsx)(T.Z,{title:"Copy ".concat(l),children:(0,n.jsx)("button",{type:"button",className:"event-manager__icon",onClick:()=>{L(l,"Snippet copied.")},children:(0,n.jsx)(eH.Z,{fontSize:"inherit"})})}),(0,n.jsx)(T.Z,{title:r?"Fire a test ".concat(e.eventName," on ").concat(null!=t?t:"this ad account",". It counts as a real conversion."):e7(e),children:(0,n.jsx)("span",{className:"event-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"event-manager__icon",onClick:()=>{M(e)},disabled:!r||o,children:(0,n.jsx)(eY.Z,{fontSize:"inherit"})})})}),null!==e.definitionId&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(T.Z,{title:"Edit the label and description",children:(0,n.jsx)("button",{type:"button",className:"event-manager__icon",onClick:()=>z(e),children:(0,n.jsx)(eJ.Z,{fontSize:"inherit"})})}),(0,n.jsx)(T.Z,{title:"Remove this definition. Events already fired stay counted.",children:(0,n.jsx)("span",{className:"event-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"event-manager__icon event-manager__icon--danger",onClick:()=>{B(e)},disabled:w===e.definitionId,children:(0,n.jsx)(eX.Z,{fontSize:"inherit"})})})})]})]}),c&&(0,n.jsxs)("div",{className:"event-manager__edit",children:[(0,n.jsx)("input",{className:"event-manager__input",placeholder:"Label, for example Watched the VSL",value:v,onCh
1ange:e=>g(e.target.value)}),(0,n.jsx)("input",{className:"event-manager__input event-manager__input--wide",placeholder:"What it means, for the team",value:x,onChange:e=>f(e.target.value)}),(0,n.jsx)("button",{type:"button",className:"event-manager__primary",onClick:()=>{O()},disabled:w===e.definitionId,children:"Save"}),(0,n.jsx)("button",{type:"button",className:"event-manager__ghost",onClick:()=>p(null),children:"Cancel"})]})]},"".concat(e.kind,":").concat(e.eventName))};return(0,n.jsxs)("div",{className:"event-manager",children:[(0,n.jsxs)("div",{className:"event-manager__head",children:[(0,n.jsxs)("div",{className:"event-manager__heading",children:[(0,n.jsx)("div",{className:"event-manager__title",children:"Events"}),(0,n.jsx)("div",{className:"event-manager__detail",children:"Every event this ad account tracks, how often it fired and whether it is still firing."})]}),(0,n.jsxs)("div",{className:"event-manager__controls",children:[(0,n.jsx)("div",{className:"event-manager__segments",children:e$.map(e=>(0,n.jsx)("button",{type:"button",className:"event-manager__segment".concat(e.days===i?" event-manager__segment--active":""),onClick:()=>l(e.days),children:e.label},e.days))}),(0,n.jsx)(T.Z,{title:b?"Reading...":"Refresh",children:(0,n.jsx)("span",{className:"event-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"event-manager__ghost event-manager__ghost--icon",onClick:()=>{k()},disabled:b,"aria-label":"Refresh",children:(0,n.jsx)(eQ.Z,{fontSize:"small"})})})}),(0,n.jsx)("button",{type:"button",className:"event-manager__soft",onClick:()=>o(!r),children:"New event"})]})]}),r&&(0,n.jsxs)("div",{className:"event-manager__add",children:[(0,n.jsxs)("div",{className:"event-manager__add-fields",children:[(0,n.jsx)("input",{className:"event-manager__input",placeholder:"Event name your site will fire, for example watched_vsl",value:c,onChange:e=>d(e.target.value),maxLength:(null==P?void 0:P.customEventNameMaxLength)||void 0}),(0,n.jsx)("input",{className:"event-manager__input",placeholder:"Label (optional)",value:u,onChange:e=>h(e.target.value)}),(0,n.jsx)("button",{type:"button",className:"event-manager__primary",onClick:()=>{Z()},disabled:"create"===w||0===c.trim().length||null!==D,children:"create"===w?"Adding...":"Add event"})]}),(0,n.jsx)("div",{className:"event-manager__note".concat(D?" event-manager__note--problem":""),children:null!=D?D:c.trim()?(0,n.jsxs)(n.Fragment,{children:["Your site fires it with ",(0,n.jsx)("code",{children:(0,eq.wb)(c)})]}):"Defining an event here only names it. It shows as firing once your site sends it."})]}),_&&(0,n.jsx)("div",{className:"event-manager__note event-manager__note--problem",children:_}),!y&&(0,n.jsx)("div",{className:"event-manager__note",children:"Reading events..."}),y&&j&&!j.supported&&(0,n.jsx)("div",{className:"event-manager__note",children:"This ad account's platform reports whether the pixel is installed but publishes no per-event series, so only the events you define here are listed."}),j&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(an,{title:"Standard events",hint:"The names the pixel documents",rows:F.standard,render:V}),(0,n.jsx)(an,{title:"Custom events",hint:0===F.custom.length?void 0:"Your own names, defined here or seen firing",rows:F.custom,render:V}),(0,n.jsx)(an,{title:"Fired by the snippet",hint:"Page views and identity, not conversions",rows:F.automatic,render:V}),(0,n.jsx)(an,{title:"Counted natively",hint:"Recorded by the ad platform without the pixel",rows:F.native,render:V})]})]})},ai=t(31617);let al="https://api.whop.com/api/v1/events",ar=e=>{let a=e.trim();return a?["curl -X POST ".concat(al," \\"),' -H "Authorization: Bearer YOUR_KEY" \\',' -H "Content-Type: application/json" \\',' -d \'{"account_id":"'.concat(a,'","event_name":"lead","event_id":"order_1234",'),' "value":49.99,"currency":"usd","action_source":"website",',' "user":{"email":"[email protected]"},',' "context":{"fbclid":"...","ip_address":"...","user_agent":"..."}}\''].join("\n"):""},ao=(e,a)=>{let t=ar(e);return t&&0!==a.length?["Send my conversions to Whop from my server, in addition to the browser pixel.","","1. Endpoint: POST ".concat(al),"2. Authenticate with the header: Authorization: Bearer <the key I generated in Koast>.",'3. Always send "account_id": "'.concat(e,'". The key only accepts that account.'),"4. Send event_id and use the SAME event_id the browser pixel sends for the same"," conversion, so it is counted once and not twice. It must be UNIQUE per conversion:"," an unresolved macro placeholder such as {txid} gives every event one id, and all but"," the first are dropped as duplicates.","5. Supported event names:",a.join(", "),...a.includes(ai.mX)?[" Send purchase only for a sale on your own checkout, with a value greater than zero."]:[]," Purchases through Whop checkout are already tracked, so do not resend those.",'6. Include as many match keys as you have under "user" (email, phone, external_id)',' and as much attribution as you have under "context" (fbclid, fbp, fbc, gclid,'," ttclid, ip_address, user_agent, utm_source, utm_medium, utm_campaign).","7. Send ONE ip_address, 45 characters maximum. If your tracker emits a comma-separated"," forwarded-for chain, send only the first entry. Whop rejects anything longer with",' "ipAddress is too long (maximum is 45)".',"","Example:","",t,"","The event is acknowledged immediately and becomes queryable within about 15 minutes."].join("\n"):""};var ac=t(25427),ad=t(9904);let au={danger:eW.Z,warning:m.Z,success:m.Z,neutral:m.Z};t(3119);var ah=t(90889),am=t(27261),ap=t(90215);let av=["source","attributionModel","eventName","customEvent","country","hasPurchased","contactable","firstSeenWithinDays","lastSeenWithinDays","query","attribution_model","event_name","custom_event","has_purchased","first_seen_within_days","last_seen_within_days"],ag=e=>Object.keys(null!=e?e:{}).filter(e=>!av.includes(e)),ax={csv_upload:"Customer list",people_filter:"People filters",engagement:"Engagement"},af={pending:"Queued",processing:"Processing",syncing:"Syncing to the ad platform",ready:"Ready",partial:"Partly ready",failed:"Failed",unknown:"Unknown"},aj=e=>"ready"===e?"success":"partial"===e?"warning":"failed"===e?"danger":"unknown"===e?"neutral":"info",ay=e=>"ready"===e||"partial"===e||"failed"===e,ab=e=>{if("lookalike"===e.audienceType){var a;let t=e.lookalikeRatio;if(null===t)return"Lookalike";let n=Math.round((null!==(a=e.lookalikeStartingRatio)&&void 0!==a?a:0)*100);return"Lookalike, top ".concat(n,"â").concat(Math.round(100*t),"%")}return"engagement"===e.sourceType?"ready"===e.status?"Membership maintained by the ad platform":af[e.status]:ay(e.status)||null===e.progressPercent?null!==e.matchedRows&&null!==e.totalRows&&e.totalRows>
10?"".concat(e.matchedRows.toLocaleString("en-US")," of ").concat(e.totalRows.toLocaleString("en-US")," matched"):af[e.status]:"".concat(af[e.status]," \xb7 ").concat(Math.round(e.progressPercent),"%")},a_=e=>{let a=e.find(e=>"available"===e.status&&null!==e.lowerBound&&null!==e.upperBound);return a?"".concat(Math.round(a.lowerBound),"â").concat(Math.round(a.upperBound),"% match"):e.some(e=>"calculating"===e.status)?"Match rate calculating":null},aw=e=>{var a;return"custom"===e.audienceType&&"ready"===e.status&&("engagement"===e.sourceType||(null!==(a=e.matchedRows)&&void 0!==a?a:0)>=100)},aN=e=>"custom"===e.audienceType&&"csv_upload"===e.sourceType&&ay(e.status),ak=e=>"people_filter"===e.sourceType&&e.autoRefresh,aC=()=>({lastSeenWithinDays:30}),aS=e=>{var a;return(null!==(a=e.eventName)&&void 0!==a?a:[]).length>0&&!!e.customEvent},aA=e=>{let a=[],{contactable:t,attributionModel:n,...s}=e;Object.values(s).some(e=>void 0!==e&&""!==e&&!(Array.isArray(e)&&0===e.length))||a.push("Set at least one filter, or the audience would hold everyone."),aS(e)&&a.push("Pick named events or one custom event, not both."),void 0===e.country||""===e.country||/^[A-Z]{2}$/.test(e.country)||a.push("Country is a two-letter code, for example US.");let i=[e.firstSeenWithinDays,e.lastSeenWithinDays];return i.some(e=>void 0!==e&&(!Number.isInteger(e)||e<1))&&a.push("A rolling window is a whole number of days, at least 1."),i.some(e=>void 0!==e&&e>3650)&&a.push("A rolling window is at most ".concat(3650," days.")),[e.source,e.eventName].some(e=>(null!=e?e:[]).length>500)&&a.push("A filter lists at most ".concat(500," values.")),a},aI=e=>{var a;let t=e=>{let a=(null!=e?e:[]).map(e=>e.trim()).filter(Boolean);return 0===a.length?void 0:a},n=e=>(null==e?void 0:e.trim())||void 0;return Object.fromEntries(Object.entries({source:t(e.source),attributionModel:e.attributionModel,eventName:t(e.eventName),customEvent:n(e.customEvent),country:null===(a=n(e.country))||void 0===a?void 0:a.toUpperCase(),hasPurchased:e.hasPurchased,contactable:e.contactable,firstSeenWithinDays:e.firstSeenWithinDays,lastSeenWithinDays:e.lastSeenWithinDays,query:n(e.query)}).filter(e=>{let[,a]=e;return void 0!==a}))},aP={video:{label:"People who watched a video",maxRetentionDays:365,needsIds:"video",events:[{event:"watched_3_seconds",label:"Watched 3 seconds"},{event:"watched_10_seconds",label:"Watched 10 seconds"},{event:"watched_15_seconds",label:"Watched 15 seconds"},{event:"watched_25_percent",label:"Watched 25%"},{event:"watched_50_percent",label:"Watched 50%"},{event:"watched_75_percent",label:"Watched 75%"},{event:"watched_95_percent",label:"Watched 95%"}]},lead_form:{label:"People who opened a lead form",maxRetentionDays:90,needsIds:"form",events:[{event:"opened",label:"Opened the form"},{event:"submitted",label:"Submitted the form"},{event:"not_submitted",label:"Opened but did not submit"}]},instagram_profile:{label:"People who engaged with the Instagram profile",maxRetentionDays:730,needsIds:null,events:[{event:"all",label:"Any engagement"},{event:"engaged",label:"Engaged with a post or ad"},{event:"visited",label:"Visited the profile"},{event:"messaged",label:"Sent a message"},{event:"saved",label:"Saved a post or ad"},{event:"ad_liked",label:"Liked an ad"},{event:"ad_commented",label:"Commented on an ad"},{event:"ad_shared",label:"Shared an ad"},{event:"ad_saved",label:"Saved an ad"},{event:"ad_cta_clicked",label:"Clicked an ad button"},{event:"ad_carousel_swiped",label:"Swiped an ad carousel"},{event:"organic_liked",label:"Liked a post"},{event:"organic_commented",label:"Commented on a post"},{event:"organic_shared",label:"Shared a post"},{event:"organic_saved",label:"Saved a post"},{event:"organic_swiped",label:"Swiped a post"},{event:"organic_carousel_swiped",label:"Swiped a post carousel"}]},facebook_page:{label:"People who engaged with the Facebook page",maxRetentionDays:730,needsIds:null,events:[{event:"engaged",label:"Engaged with the page or an ad"},{event:"visited",label:"Visited the page"},{event:"liked",label:"Currently like the page"},{event:"messaged",label:"Sent a message"},{event:"cta_clicked",label:"Clicked a button"},{event:"saved",label:"Saved the page or a post"},{event:"post_interaction",label:"Interacted with a post"}]}},aT="liked",aF=function(e){var a,t;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return{object:e,event:null!==(t=null===(a=aP[e].events[0])||void 0===a?void 0:a.event)&&void 0!==t?t:"engaged",retentionDays:Math.min(30,aP[e].maxRetentionDays),socialAccountId:n}},aE=(e,a)=>{var t,n,s,i;let l=[],r=aP[e.object];r.events.some(a=>a.event===e.event)||l.push('"'.concat(e.event,'" is not something ').concat(r.label.toLowerCase()," can track.")),e.socialAccountId.trim()||l.push("Pick the social account the ".concat(a," rule watches."));let o="facebook_page"===e.object&&e.event===aT;
1return o&&0!==e.retentionDays?l.push("Current page likes take a retention of 0 days."):!o&&(!Number.isInteger(e.retentionDays)||e.retentionDays<1||e.retentionDays>r.maxRetentionDays)&&l.push("".concat(r.label," keeps people for 1 to ").concat(r.maxRetentionDays," days.")),"video"===r.needsIds&&0===(null!==(t=e.platformVideoIds)&&void 0!==t?t:[]).length&&l.push("Name at least one video id to watch."),"form"===r.needsIds&&0===(null!==(n=e.platformFormIds)&&void 0!==n?n:[]).length&&l.push("Name at least one lead form id to watch."),((null!==(s=e.platformVideoIds)&&void 0!==s?s:[]).length>50||(null!==(i=e.platformFormIds)&&void 0!==i?i:[]).length>50)&&l.push("A rule watches at most ".concat(50," ids.")),l},aD=e=>{let a=[];0===e.include.length&&a.push("Add at least one inclusion rule."),(e.include.length>10||e.exclude.length>10)&&a.push("At most ".concat(10," inclusion and ").concat(10," exclusion rules.")),e.include.forEach(e=>a.push(...aE(e,"include"))),e.exclude.forEach(e=>a.push(...aE(e,"exclude")));let t=e.include.filter(e=>"video"===e.object);t.length>0&&t.length<e.include.length&&a.push("Video rules cannot be mixed with other sources; build a second audience for them."),new Set(t.map(e=>e.retentionDays)).size>1&&a.push("Every video rule shares one retention window."),t.length>0&&e.exclude.length>0&&a.push("A video audience cannot exclude anyone; exclude it on the ad set instead.");let n=e.include.filter(e=>"facebook_page"===e.object&&e.event===aT);return n.length>0&&n.length<e.include.length&&a.push('"Currently like the page" stands alone;
1 it cannot be combined with other events.'),[...new Set(a)]},aL=e=>{let a=[];return e.sourceAudienceId||a.push("Pick the audience to build lookalikes from."),(!Number.isInteger(e.count)||e.count<1||e.count>6)&&a.push("Create between 1 and ".concat(6," audiences.")),(!Number.isInteger(e.percentage)||e.percentage<1||e.percentage>20)&&a.push("Reach between 1% and ".concat(20,"%.")),Number.isInteger(e.count)&&e.count>0&&Number.isInteger(e.percentage)&&e.percentage%e.count!=0&&a.push("".concat(e.percentage,"% is split evenly across ").concat(e.count," audiences, so it must divide by ").concat(e.count,".")),a},aM=(e,a)=>{if(!Number.isInteger(e)||e<1||!Number.isInteger(a)||a%e!=0)return[];let t=a/e;return Array.from({length:e},(e,a)=>"".concat(a*t,"â").concat((a+1)*t,"%"))},aR=e=>{let{provider:a,providerLabel:t,loading:n}=(0,b.Hq)(),i=null!==a&&"meta"!==a,[l,r]=(0,s.useState)([]),[o,c]=(0,s.useState)(!0),[d,u]=(0,s.useState)(!1),[h,m]=(0,s.useState)(!1),[p,v]=(0,s.useState)(null),[g,x]=(0,s.useState)(null),f=(0,s.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!i||!a||!e){r([]),u(!0);return}t||m(!0);let n=await ap.NV.listAudienceDetails(a,e);if(t||m(!1),u(!0),!n.ok){v(n.failure.message);return}v(null),c(n.data.supported),r(n.data.audiences)},[i,a,e]);(0,s.useEffect)(()=>{f()},[f]);let j=l.some(e=>!ay(e.status)&&"unknown"!==e.status);(0,s.useEffect)(()=>{if(!j)return;let e=setInterval(()=>{"visible"===document.visibilityState&&f(!0)},15e3);return()=>clearInterval(e)},[j,f]);let y=(0,s.useCallback)(async(t,n)=>{if(!a||!e)return null;x(t),v(null);let s=await n();return(x(null),s.ok)?(await f(!0),s.data):(v(s.failure.message),null)},[a,e,f]),_=(0,s.useCallback)(t=>y("create",()=>ap.NV.createFilterAudience(a,e,t)),[y,a,e]),w=(0,s.useCallback)(t=>y("create",()=>ap.NV.createEngagementAudience(a,e,t)),[y,a,e]),N=(0,s.useCallback)(t=>y("lookalike",()=>
1ap.NV.createLookalikeAudiences(a,e,t)),[y,a,e]),k=(0,s.useCallback)((t,n)=>y(t,()=>ap.NV.addPeople(a,e,t,n)),[y,a,e]),C=(0,s.useCallback)((t,n)=>y(t,()=>ap.NV.updateAudience(a,e,t,n)),[y,a,e]),S=(0,s.useCallback)(t=>y(t,()=>ap.NV.deleteAudience(a,e,t)),[y,a,e]);return{provider:a,providerLabel:t,isProviderManaged:i,capabilitiesLoading:n,supported:o,audiences:l,hasFetched:d,loading:h,error:p,busy:g,refetch:f,createFilterAudience:_,createEngagementAudience:w,createLookalikes:N,addPeople:k,updateAudience:C,deleteAudience:S}};var aZ=t(63884),az=t(79193),aO=t(26034),aB=t(60402);let aV=e=>new Promise(a=>{let t=new FileReader;t.onload=()=>a("string"==typeof t.result?t.result:""),t.onerror=()=>a(""),t.readAsDataURL(e)});var aK=e=>{let{open:a,audience:t,maxFileBytes:i,saving:l,onClose:r,onAdd:o}=e,[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null);(0,s.useEffect)(()=>{a&&(d(null),h(null))},[a]);let m=e=>{if(h(null),e&&(0,aB.IE)(e.size,i)){h("The file must be under ".concat((0,aB.XC)(i),".")),d(null);return}d(e)},p=async()=>{if(!t||!c)return;let e=await aV(c);if(!e){h("We could not read that file.");return}await o(t.id,{fileName:c.name,contentType:c.type||"text/csv",data:e})&&r()};return(0,n.jsx)(V.hB,{id:"audience-add-people",open:a,onClose:r,width:520,children:(0,n.jsxs)(V.Vq,{title:"Add people",subtitle:t?'A new CSV with the same columns as "'.concat(t.name,'". Existing members stay.'):void 0,onClose:r,footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"secondary",onClick:r,disabled:l,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:()=>{p()},loading:l,disabled:!c,children:"Add people"})]}),children:[(0,n.jsx)(V.gN,{label:"Customer list",hint:c?void 0:"A CSV with one customer per row.",children:(0,n.jsxs)("label",{className:"custom-audience-upload__file",htmlFor:"audience-add-people-file",children:[(0,n.jsx)("span",{className:"custom-audience-upload__file-name",children:c?c.name:"Choose a CSV file"}),(0,n.jsx)("input",{id:"audience-add-people-file",type:"file",accept:".csv,text/csv",hidden:!0,onChange:e=>{var a,t;return m(null!==(t=null===(a=e.target.files)||void 0===a?void 0:a[0])&&void 0!==t?t:null)}})]})}),u&&(0,n.jsx)("p",{className:"custom-audience-upload__error",children:u})]})})},aU=t(5306),aW=t(50135),aQ=t(96612);let aH=(e,a)=>new Intl.DateTimeFormat("en-CA",{timeZone:a,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),aq=(e,a,t)=>{let[n,i]=(0,s.useState)([]),[l,r]=(0,s.useState)([]),[o,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!t||!e||!a)return;let n=!1;u(!0);let s=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC",l=ne
1w Date,o=aH(new Date(l.getTime()-7776e6),s),d=aH(l,s),h="?from=".concat(o,"&to=").concat(d,"&timeZone=").concat(encodeURIComponent(s));return Promise.all([aQ.cY.listCampaigns(e,a),(0,f.handleFetch)("/pixel/events/summary".concat(h),{method:"GET",cache:"no-store"})]).then(e=>{var a,t,s;let[l,o]=e;if(n)return;i(l.ok?l.data:[]);let d=(null==o?void 0:o.success)?o.data:null;r(null!==(t=null==d?void 0:null===(a=d.vocabulary)||void 0===a?void 0:a.standardEvents)&&void 0!==t?t:[]),c((null!==(s=null==d?void 0:d.events)&&void 0!==s?s:[]).filter(e=>"custom"===e.kind).map(e=>e.eventName))}).catch(()=>{n||i([])}).finally(()=>{n||u(!1)}),()=>{n=!0}},[t,e,a]),{campaigns:n,standardEvents:l,customEvents:o,loading:d}},aG=(e,a,t,n)=>{let[i,l]=(0,s.useState)([]),[r,o]=(0,s.useState)(!0),[c,d]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!n||!e||!a||!t){l([]);return}let s=!1;d(!0);let i="/ads/providers/".concat(e,"/accounts/").concat(encodeURIComponent(a),"/page-identities/").concat(encodeURIComponent(t),"/lead-forms");return(0,f.handleFetch)(i,{method:"GET",cache:"no-store"}).then(e=>{if(s)return;let a=(null==e?void 0:e.success)?e.data:null,t=Array.isArray(null==a?void 0:a.leadForms)?a.leadForms:[];o((null==a?void 0:a.supported)!==!1),l(t.filter(e=>"string"==typeof e.id&&"string"==typeof e.name).map(e=>({id:String(e.id),name:String(e.name)})))}).catch(()=>{s||l([])}).finally(()=>{s||d(!1)}),()=>{s=!0}},[n,e,a,t]),{leadForms:i,supported:r,loading:c}},aY=e=>{let{options:a,value:t,onChange:s,ariaLabel:i,disabled:l=!1}=e;return(0,n.jsx)("div",{className:"audience-manager__chips",role:"radiogroup","aria-label":i,children:a.map(e=>{let a=e.value===t;return(0,n.jsx)("button",{type:"button",role:"radio","aria-checked":a,className:"audience-manager__chip".concat(a?" audience-manager__chip--active":""),disabled:l||e.disabled,onClick:()=>s(e.value),children:e.label},String(e.value))})})},aJ=e=>{let{items:a,onRemove:t,emptyText:s}=e;return 0===a.length?s?(0,n.jsx)("div",{className:"audience-manager__hint",children:s}):null:(0,n.jsx)("div",{className:"audience-manager__chips",children:a.map(e=>(0,n.jsxs)("span",{className:"audience-manager__chip audience-manager__chip--value",children:[(0,n.jsx)("span",{children:e.label}),(0,n.jsx)("button",{type:"button",className:"audience-manager__chip-remove","aria-label":"Remove ".concat("string"==typeof e.label?e.label:e.value),onClick:()=>t(e.value),children:"\xd7"})]},e.value))})},aX=[7,30,90,180,365],a$=[7,30,60,90,180,365,730],a0=e=>a$.filter(a=>a<=aP[e].maxRetentionDays),a1=[{key:"events",label:"Did something specific"},{key:"sources",label:"Where they came from"},{key:"country",label:"Country"},{key:"firstSeen",label:"First seen recently"},{key:"customEvent",label:"Fired a custom event"}],a2={contactable:!0},a5=[{id:"recent-visitors",title:"Recent visitors",description:"Anyone the pixel saw in the last 30 days.",suggestedName:"Visitors, last 30 days",filters:{...a2,lastSeenWithinDays:30}},{id:"customers",title:"Customers",description:"People who have bought, seen in the last year.",suggestedName:"Customers, last 12 months",filters:{...a2,hasPurchased:!0,lastSeenWithinDays:365}},{id:"window-shoppers",title:"Visited, never bought",description:"Seen in the last 90 days, no purchase yet.",suggestedName:"Visited but never bought, 90 days",filters:{...a2,hasPurchased:!1,lastSeenWithinDays:90}},{id:"leads",title:"Leads",description:"Fired the lead event in the last 180 days.",suggestedName:"Leads, last 180 days",filters:{...a2,eventName:["pixel.lead"],lastSeenWithinDays:180},opens:"events"},{id:"from-ads",title:"Came from my ads",description:"Pick the campaigns below; everyone they brought in.",suggestedName:"Came from my ads",filters:{...a2,lastSeenWithinDays:180},opens:"sources"},{id:"blank",title:"Start empty",description:"Choose every filter yourself.",suggestedName:"",filters:{...a2,lastSeenWithinDays:30}}],a3=e=>{var a,t;let n=[];return(null!==(a=e.eventName)&&void 0!==a?a:[]).length>0&&n.push("events"),(null!==(t=e.source)&&void 0!==t?t:[]).length>0&&n.push("sources"),e.country&&n.push("country"),void 0!==e.firstSeenWithinDays&&n.push("firstSeen"),e.customEvent&&n.push("customEvent"),n},a4=(e,a)=>{let t={...e};return"events"===a&&delete t.eventName,"sources"===a&&delete t.source,"country"===a&&delete t.country,"firstSeen"===a&&delete t.firstSeenWithinDays,"customEvent"===a&&delete t.customEvent,t},a8=e=>
1{let a=e.replace(/^pixel\./,"").split(/[_.]+/).filter(Boolean);return 0===a.length?e:[a[0].charAt(0).toUpperCase()+a[0].slice(1),...a.slice(1)].join(" ")},a6=e=>[{value:"payment.completed",label:"Completed a payment at Whop checkout",group:"Checkout"},...e.map(e=>({value:"pixel.".concat(e),label:a8(e),group:"Pixel events"}))],a9=(e,a)=>{var t,n;return null!==(n=null===(t=a.find(a=>a.value===e))||void 0===t?void 0:t.label)&&void 0!==n?n:a8(e)},a7=e=>"whop:".concat(e,":*"),te=e=>{let a=e.trim().replace(/^https?:\/\//i,"").replace(/^www\./i,"").split(/[/?#\s]/)[0].toLowerCase();return a?"referrer:".concat(a):null},ta=e=>[...e.map(e=>({value:a7(e.id),label:e.name,group:"Whop campaigns"})),{value:"ext:meta:*",label:"Ads run on Meta",group:"Elsewhere"},{value:"direct",label:"Direct: typed the address or used a bookmark",group:"Elsewhere"}],tt=(e,a)=>{var t;let n=a.find(a=>a.value===e);return n?n.label:e.startsWith("referrer:")?"Referred by ".concat(e.slice(9)):e.startsWith("whop:")?"Campaign ".concat(null!==(t=e.split(":")[1])&&void 0!==t?t:e):e},tn=(e,a,t)=>{let n=new Set(e.map(e=>e.value));return[...e,...a.filter(e=>!n.has(e)).map(e=>({value:e,label:t(e),group:"Saved"}))]},ts="AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY HK HM HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PN PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW".split(" "),ti=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en";try{var t;return null!==(t=new Intl.DisplayNames([a],{type:"region"}).of(e))&&void 0!==t?t:e}catch(a){return e}},tl=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"en";return ts.map(a=>({code:a,name:ti(a,e)})).sort((a,t)=>a.name.localeCompare(t.name,e))},tr=[{id:"page-engaged",title:"Engaged with my page",description:"Interacted with the Facebook page or its ads in the last year.",suggestedName:"Page engagers, 365 days",rule:{object:"facebook_page",event:"engaged",retentionDays:365}},{id:"instagram-engaged",title:"Engaged on Instagram",description:"Interacted with the Instagram profile, a post or an ad in the last year.",suggestedName:"Instagram engagers, 365 days",rule:{object:"instagram_profile",event:"engaged",retentionDays:365}},{id:"form-submitted",title:"Submitted a lead form",description:"Sent a form in the last 90 days; pick which forms below.",suggestedName:"Lead form submitters, 90 days",rule:{object:"lead_form",event:"submitted",retentionDays:90}},{id:"form-abandoned",title:"Opened a form, did not submit",description:"Opened but never sent, in the last 90 days.",suggestedName:"Opened a form, did not submit, 90 days",rule:{object:"lead_form",event:"not_submitted",retentionDays:90}},{id:"video-half",title:"Watched half a video",description:"Watched at least 50% of the videos you pick, in the last year.",suggestedName:"Watched half the video, 365 days",rule:{object:"video",event:"watched_50_percent",retentionDays:365}}],to=(e,a)=>({...e.rule,socialAccountId:a}),tc=e=>Array.from(new Set(e.split(/[\s,;]+/).map(e=>e.replace(/["']/g,"").trim()).filter(Boolean))),td={facebook_page:"Facebook page",instagram_profile:"Instagram profile",lead_form:"Lead form",video:"Video"},tu=Object.keys(aP),th="custom",tm=(e,a)=>a.filter(a=>"instagram_profile"===e?"publishing-identity"===a.kind:"page"===a.kind),tp=e=>{var a,t;let{rule:i,index:l,side:r,socialAccounts:o,provider:c,accountId:d,open:u,onChange:h,onRemove:m}=e,p=aP[i.object],v="audience-".concat(r,"-").concat(l),g=tm(i.object,o),x=a0(i.object),f="facebook_page"===i.object&&i.event===aT,[j,y]=(0,s.use
1State)(!x.includes(i.retentionDays)),[b,_]=(0,s.useState)(""),w=aG(c,d,"lead_form"===i.object&&i.socialAccountId||null,u),N=(0,s.useMemo)(()=>{var e;let a=new Set(w.leadForms.map(e=>e.id)),t=(null!==(e=i.platformFormIds)&&void 0!==e?e:[]).filter(e=>!a.has(e)).map(e=>({id:e,name:"Form ".concat(e)}));return[...w.leadForms,...t]},[w.leadForms,i.platformFormIds]),k=e=>{let a="facebook_page"===i.object&&e===aT;h({...i,event:e,retentionDays:a?0:i.retentionDays||30})},C=()=>{var e;let a=tc(b);0!==a.length&&(h({...i,platformVideoIds:Array.from(new Set([...null!==(e=i.platformVideoIds)&&void 0!==e?e:[],...a]))}),_(""))},S=w.supported&&(w.leadForms.length>0||w.loading);return(0,n.jsxs)("div",{className:"audience-manager__rule",children:[(0,n.jsx)(V.gN,{label:"Who",htmlFor:"".concat(v,"-object"),children:(0,n.jsx)(aY,{ariaLabel:"Engagement source",options:tu.map(e=>({value:e,label:td[e]})),value:i.object,onChange:e=>{var a,t;let n=aF(e,null!==(t=null===(a=tm(e,o)[0])||void 0===a?void 0:a.id)&&void 0!==t?t:"");y(!1),h({...n,retentionDays:Math.min(i.retentionDays||n.retentionDays,aP[e].maxRetentionDays)||n.retentionDays})}})}),(0,n.jsxs)("div",{className:"audience-manager__grid",children:[(0,n.jsx)(V.gN,{label:"Did",htmlFor:"".concat(v,"-event"),children:(0,n.jsx)(V.px,{id:"".concat(v,"-event"),value:i.event,onChange:e=>k(e.target.value),children:p.events.map(e=>(0,n.jsx)("option",{value:e.event,children:e.label},e.event))})}),(0,n.jsx)(V.gN,{label:"instagram_profile"===i.object?"Instagram account":"Facebook page",required:!0,htmlFor:"".concat(v,"-account"),hint:0===g.length?"No account of this kind can serve ads here yet.":void 0,children:1===g.length?(0,n.jsx)("div",{className:"audience-manager__static",children:g[0].name}):(0,n.jsxs)(V.px,{id:"".concat(v,"-account"),value:i.socialAccountId,onChange:e=>h({...i,socialAccountId:e.target.value,platformFormIds:void 0}),children:[(0,n.jsx)("option",{value:"",children:"Pick an account"}),g.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})})]}),(0,n.jsx)(V.gN,{label:"Within the last",htmlFor:"".concat(v,"-retention"),hint:f?"Current likes have no window: the audience is whoever likes the page today.":"Up to ".concat(p.maxRetentionDays," days for ").concat(p.label.toLowerCase().replace("people who ",""),"."),children:f?(0,n.jsx)("div",{className:"audience-manager__static",children:"Right now"}):(0,n.jsxs)("div",{className:"audience-manager__stack",children:[(0,n.jsx)(aY,{ariaLabel:"Retention window",options:[...x.map(e=>({value:String(e),label:"".concat(e," days")})),{value:th,label:"Other"}],value:j?th:String(i.retentionDays),onChange:e=>{e===th?y(!0):(y(!1),h({...i,retentionDays:Number(e)}))}}),j&&(0,n.jsxs)("div",{className:"audience-manager__inline",children:[(0,n.jsx)(V.oi,{id:"".concat(v,"-retention"),type:"number",min:1,max:p.maxRetentionDays,value:i.retentionDays||"",onChange:e=>h({...i,retentionDays:Number.parseInt(e.target.value,10)||0})}),(0,n.jsx)("span",{className:"audience-manager__hint",children:"days"})]})]})}),"form"===p.needsIds&&(0,n.jsx)(V.gN,{label:"Which forms",required:!0,htmlFor:"".concat(v,"-forms"),hint:S?"The forms this page owns.":"This page lists no forms yet. Paste form ids from the ads manager, separated by commas.",children:S?(0,n.jsx)(aU.Z,{multiple:!0,id:"".concat(v,"-forms"),className:"koast-autocomplete",options:N,getOptionLabel:e=>e.name,isOptionEqualToValue:(e,a)=>e.id===a.id,value:N.filter(e=>{var a;return(null!==(a=i.platformFormIds)&&void 0!==a?a:[]).includes(e.id)}),onChange:(e,a)=>h({...i,platformFormIds:a.map(e=>e.id)}),loading:w.loading,ChipProps:{size:"small"},renderInput:e=>{var a;return(0,n.jsx)(aW.Z,{...e,placeholder:0===(null!==(a=i.platformFormIds)&&void 0!==a?a:[]).length?"Search forms":""})}}):(0,n.jsx)(V.oi,{id:"".concat(v,"-forms"),value:(null!==(a=i.platformFormIds)&&void 0!==a?a:[]).join(", "),placeholder:"123456789, 987654321",onChange:e=>h({...i,platformFormIds:tc(e.target.value)})})}),"video"===p.needsIds&&(0,n.jsxs)(V.gN,{label:"Which videos",required:!0,htmlFor:"".concat(v,"-videos"),hint:"Paste each video's id: the long number in its Facebook URL. Up to 50.",children:[(0,n.jsxs)("div",{className:"audience-manager__inline",children:[(0,n.jsx)(V.oi,{id:"".concat(v,"-videos"),value:b,placeholder:"Video id",onChange:e=>_(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),C())}}),(0,n.jsx)(V.Qd,{variant:"secondary",size:"sm",onClick:C,disabled:0===tc(b).length,children:"Add"})]}),(0,n.jsx)(aJ,{items:(null!==(t=i.platformVideoIds)&&void 0!==t?t:[]).map(e=>({value:e,label:e})),onRemove:e=>{var a;return h({...i,platformVideoIds:(null!==(a=i.platformVideoIds)&&void 0!==a?a:[]).filter(a=>a!==e)})}})]}),(0,n.jsx)("button",{type:"button",className:"audience-manager__icon audience-manager__icon--danger audience-manager__rule-remove","aria-label":"Remove rule",onClick:m,children:(0,n.jsx)(eX.Z,{fontSize:"inherit"})})]})};var tv=e=>{let{open:a,onClose:t,saving:i,socialAccounts:l,provider:r,accountId:o,onCreate:c}
1=e,[d,u]=(0,s.useState)(""),[h,m]=(0,s.useState)(!0),[p,v]=(0,s.useState)({platform:"meta",include:[],exclude:[]}),[g,x]=(0,s.useState)(null),[f,j]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!1),_=e=>{var a,t;return null!==(t=null===(a=tm(e,l)[0])||void 0===a?void 0:a.id)&&void 0!==t?t:""},w=e=>{x(e.id),v({platform:"meta",include:[to(e,_(e.rule.object))],exclude:[]}),j(!1),b(!1),h&&u(e.suggestedName)};(0,s.useEffect)(()=>{var e,t;a&&(u(tr[0].suggestedName),m(!0),x(tr[0].id),v({platform:"meta",include:[to(tr[0],null!==(t=null===(e=tm(tr[0].rule.object,l)[0])||void 0===e?void 0:e.id)&&void 0!==t?t:"")],exclude:[]}),j(!1),b(!1))},[a]),(0,s.useEffect)(()=>{a&&0!==l.length&&v(e=>{let a=e=>e.map(e=>{var a,t;return e.socialAccountId?e:{...e,socialAccountId:null!==(t=null===(a=tm(e.object,l)[0])||void 0===a?void 0:a.id)&&void 0!==t?t:""}}),t=a(e.include),n=a(e.exclude);return t.some((a,t)=>a!==e.include[t])||n.some((a,t)=>a!==e.exclude[t])?{...e,include:t,exclude:n}:e})},[a,l]);let N=(0,s.useMemo)(()=>{let e=aD(p);return d.trim()||e.unshift("Give the audience a name."),e},[p,d]),k=e=>{v(e),b(!0)},C=(e,a,t)=>k({...p,[e]:p[e].map((e,n)=>n===a?t:e)}),S=(e,a)=>k({...p,[e]:p[e].filter((e,t)=>t!==a)}),A=e=>k({...p,[e]:[...p[e],aF("facebook_page",_("facebook_page"))]}),I=async()=>{b(!0),!(N.length>0)&&await c({name:d.trim(),engagement:p})&&t()},P=[...p.include,...p.exclude].some(e=>"video"===e.object),T={socialAccounts:l,provider:r,accountId:o,open:a};return(0,n.jsx)(V.hB,{id:"audience-engagement-builder",open:a,onClose:t,width:720,children:(0,n.jsxs)(V.Vq,{title:"Build an audience from engagement",subtitle:"People who engaged with your pages, profile, videos or lead forms. The ad platform keeps the membership current.",onClose:t,footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"secondary",onClick:t,disabled:i,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:()=>{I().catch(()=>void 0)},loading:i,disabled:y&&N.length>0,children:"Build audience"})]}),children:[(0,n.jsx)("div",{className:"audience-manager__templates",role:"radiogroup","aria-label":"Start from",children:tr.map(e=>(0,n.jsxs)("button",{type:"button",role:"radio","aria-checked":g===e.id,className:"audience-manager__template".concat(g===e.id?" audience-manager__template--active":""),onClick:()=>w(e),children:[(0,n.jsx)("span",{className:"audience-manager__template-title",children:e.title}),(0,n.jsx)("span",{className:"audience-manager__template-text",children:e.description})]},e.id))}),(0,n.jsx)(V.gN,{label:"Audience name",required:!0,htmlFor:"audience-engagement-name",children:(0,n.jsx)(V.oi,{id:"audience-engagement-name",value:d,placeholder:"Watched half the launch video",onChange:e=>{u(e.target.value),m(""===e.target.value),b(!0)}})}),(0,n.jsx)("div",{className:"audience-manager__section-title",children:"Include anyone who"}),p.include.map((e,a)=>(0,n.jsx)(tp,{rule:e,index:a,side:"include",...T,onChange:e=>C("include",a,e),onRemove:()=>S("include",a)},"include-".concat(a))),(0,n.jsx)("button",{type:"button",className:"audience-manager__link",onClick:()=>A("include"),disabled:p.include.length>=10,children:"+ Also include people whoâ¦"}),P?(0,n.jsx)("div",{className:"audience-manager__hint",children:"Video audiences cannot carry exclusions; the ad platform builds them from the watch events alone."}):(0,n.jsxs)(n.Fragment,{children:[!f&&0===p.exclude.length&&(0,n.jsx)("button",{type:"button",className:"audience-manager__link",onClick:()=>{j(!0),A("exclude")},children:"â Exclude people whoâ¦"}),(f||p.exclude.length>0)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"audience-manager__section-title",children:"Exclude anyone who"}),p.exclude.map((e,a)=>(0,n.jsx)(tp,{rule:e,index:a,side:"exclude",...T,onChange:e=>C("exclude",a,e),onRemove:()=>S("exclude",a)},"exclude-".concat(a))),(0,n.jsx)("button",{type:"button",className:"audience-manager__link",onClick:()=>A("exclude"),disabled:p.exclude.length>=10,children:"+ Also exclude people whoâ¦"})]})]}),y&&N.length>0&&(0,n.jsx)("ul",{className:"audience-manager__problems",children:N.map(e=>(0,n.jsx)("li",{children:e},e))})]})})};let tg="custom",tx=e=>{if(!e)return aC();let a=(a,t)=>{var n;return null!==(n=e[a])&&void 0!==n?n:e[t]};return{source:a("source","source"),attributionModel:a("attributionModel","attribution_model"),eventName:a("eventName","event_name"),customEvent:a("customEvent","custom_event"),country:a("country","country"),hasPurchased:a("hasPurchased","has_purchased"),contactable:a("contactable","contactable"),firstSeenWithinDays:a("firstSeenWithinDays","first_seen_within_days"),lastSeenWithinDays:a("lastSeenWithinDays","last_seen_within_days"),query:a("query","query")}},tf=e=>{let{id:a,value:t,onChange:i,allowNone:l=!1}
1=e,r=void 0!==t&&aX.includes(t),[o,c]=(0,s.useState)(void 0!==t&&!r),d=o?tg:void 0!==t?String(t):l?"any":null,u=[...l?[{value:"any",label:"Any time"}]:[],...aX.map(e=>({value:String(e),label:"".concat(e," days")})),{value:tg,label:"Other"}];return(0,n.jsxs)("div",{className:"audience-manager__stack",children:[(0,n.jsx)(aY,{ariaLabel:"Window in days",options:u,value:d,onChange:e=>{"any"===e?(c(!1),i(void 0)):e===tg?c(!0):(c(!1),i(Number(e)))}}),o&&(0,n.jsxs)("div",{className:"audience-manager__inline",children:[(0,n.jsx)(V.oi,{id:a,type:"number",min:1,value:null!=t?t:"",placeholder:"Days",onChange:e=>i(""===e.target.value?void 0:Number.parseInt(e.target.value,10))}),(0,n.jsx)("span",{className:"audience-manager__hint",children:"days"})]})]})};var tj=e=>{var a,t,i;let{open:l,onClose:r,editing:o=null,saving:c,provider:d,accountId:u,onCreate:h,onUpdate:m}=e,[p,v]=(0,s.useState)(""),[g,x]=(0,s.useState)(!0),[f,j]=(0,s.useState)(aC),[y,b]=(0,s.useState)(!0),[_,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(null),[C,S]=(0,s.useState)([]),[A,I]=(0,s.use
1State)(!1),[P,T]=(0,s.useState)(""),F=aq(d,u,l);(0,s.useEffect)(()=>{var e,a;if(!l)return;let t=tx(null!==(e=null==o?void 0:o.filters)&&void 0!==e?e:null);v(null!==(a=null==o?void 0:o.name)&&void 0!==a?a:""),x(!o),j(o?t:{...a5[0].filters}),k(o?null:a5[0].id),S(o?a3(t):[]),I(!!(o&&(t.attributionModel||t.query||!1===t.contactable))),b(!o||o.autoRefresh),T(""),w(!1)},[l,o]),(0,s.useEffect)(()=>{if(!l||o||null===N)return;let e=a5.find(e=>e.id===N);e&&g&&v(e.suggestedName)},[l,o,N,g]);let E=(0,s.useMemo)(()=>{var e;return ag(null!==(e=null==o?void 0:o.filters)&&void 0!==e?e:null)},[o]),D=(0,s.useMemo)(()=>{var e;let a=a6(F.standardEvents);return tn(a,null!==(e=f.eventName)&&void 0!==e?e:[],e=>a9(e,a))},[F.standardEvents,f.eventName]),L=(0,s.useMemo)(()=>{var e;let a=ta(F.campaigns);return tn(a,null!==(e=f.source)&&void 0!==e?e:[],e=>tt(e,a))},[F.campaigns,f.source]),M=(0,s.useMemo)(()=>tl(),[]),R=(0,s.useMemo)(()=>{let e=aA(aI(f));return p.trim()||e.unshift("Give the audience a name."),E.length>0&&e.unshift("This audience uses filters this builder cannot edit yet (".concat(E.join(", "),"); saving would drop them. Rename it, or build a new audience.")),e},[f,p,E]),Z=e=>{j(a=>({...a,...e})),w(!0)},z=e=>{k(e.id),j({...e.filters}),S(e.opens?[e.opens]:[]),w(!1)},O=e=>S(a=>a.includes(e)?a:[...a,e]),B=e=>{S(a=>a.filter(a=>a!==e)),j(a=>a4(a,e)),w(!0)},K=()=>{var e;let a=te(P);a&&(Z({source:Array.from(new Set([...null!==(e=f.source)&&void 0!==e?e:[],a]))}),T(""))},U=async()=>{if(w(!0),R.length>0)return;let e=aI(f);(o?await m(o.id,{name:p.trim(),filters:e}):await h({name:p.trim(),filters:e,autoRefresh:y}))&&r()},W=void 0===f.hasPurchased?"any":f.hasPurchased?"yes":"no",Q=a1.filter(e=>!C.includes(e.key)),H=null!==(a=M.find(e=>e.code===f.country))&&void 0!==a?a:null,q=e=>{switch(e){case"events":return(0,n.jsx)(V.gN,{label:"Did any of these",htmlFor:"audience-filter-events",hint:F.loading?"Loading the pixel's eventsâ¦":"Standard pixel events and Whop checkout. Pick as many as apply.",children:(0,n.jsx)(aU.Z,{multiple:!0,id:"audience-filter-events",className:"koast-autocomplete",options:D,groupBy:e=>e.group,getOptionLabel:e=>e.label,isOptionEqualToValue:(e,a)=>e.value===a.value,value:D.filter(e=>{var a;return(null!==(a=f.eventName)&&void 0!==a?a:[]).includes(e.value)}),onChange:(e,a)=>Z({eventName:a.map(e=>e.value)}),loading:F.loading,ChipProps:{size:"small"},renderInput:e=>{var a;return(0,n.jsx)(aW.Z,{...e,placeholder:0===(null!==(a=f.eventName)&&void 0!==a?a:[]).length?"Search events":""})}})});case"sources":return(0,n.jsxs)(V.gN,{label:"Came from",htmlFor:"audience-filter-sources",hint:F.loading?"Loading the account's campaignsâ¦":"Your campaigns, ads run elsewhere, direct visits, or a site that linked to you.",children:[(0,n.jsx)(aU.Z,{multiple:!0,id:"audience-filter-sources",className:"koast-autocomplete",options:L,groupBy:e=>e.group,getOptionLabel:e=>e.label,isOptionEqualToValue:(e,a)=>e.value===a.value,value:L.filter(e=>{var a;return(null!==(a=f.source)&&void 0!==a?a:[]).includes(e.value)}),onChange:(e,a)=>Z({source:a.map(e=>e.value)}),loading:F.loading,ChipProps:{size:"small"},renderInput:e=>{var a;return(0,n.jsx)(aW.Z,{...e,placeholder:0===(null!==(a=f.source)&&void 0!==a?a:[]).length?"Search campaigns and sources":""})}}),(0,n.jsxs)("div",{className:"audience-manager__inline audience-manager__inline--top",children:[(0,n.jsx)(V.oi,{id:"audience-filter-referrer",value:P,placeholder:"Add a referring site, e.g. youtube.com",onChange:e=>T(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),K())}}),(0,n.jsx)(V.Qd,{variant:"secondary",size:"sm",onClick:K,disabled:!te(P),children:"Add"})]})]});case"country":return(0,n.jsx)(V.gN,{label:"Country",htmlFor:"audience-filter-country",hint:"Where the person was when the pixel saw them.",children:(0,n.jsx)(V.lq,{id:"audience-filter-country",options:M,value:H,onChange:e=>Z({country:null==e?void 0:e.code}),getOptionLabel:e=>"".concat(e.name," (").concat(e.code,")"),isOptionEqualToValue:(e,a)=>e.code===a.code,placeholder:"Search countries"})});case"firstSeen":return(0,n.jsx)(V.gN,{label:"First seen in the last",htmlFor:"audience-filter-first-seen",hint:"Only people who are new to you within this window.",children:(0,n.jsx)(tf,{id:"audience-filter-first-seen",value:f.firstSeenWithinDays,onChange:e=>Z({firstSeenWithinDays:e})})});case"customEvent":var a,t;return(0,n.jsx)(V.gN,{label:"Fired this custom event",htmlFor:"audience-filter-custom",hint:0===F.customEvents.length?"No custom events defined yet. Define them under Settings â Pixel, or type the exact name.":"One custom event. It cannot combine with the standard events above.",children:F.customEvents.length>0?(0,n.jsx)(V.lq,{id:"audience-filter-custom",options:F.customEvents,value:null!==(a=f.customEvent)&&void 0!==a?a:null,onChange:e=>Z({customEvent:null!=e?e:void 0}),getOptionLabel:e=>e,placeholder:"Search custom events"}):(0,n.jsx)(V.oi,{id:"audience-filter-custom",value:null!==(t=f.customEvent)&&void 0!==t?t:"",placeholder:"watched_vsl",onChange:e=>Z({customEvent:e.target.value||void 0})})});default:return null}};return(0,n.jsx)(V.hB,{id:"audience-filter-builder",open:l,onClose:r,width:680,children:(0,n.jsxs)(V.Vq,{title:o?"Edit the People filters":"Build an audie
1nce from your People",subtitle:"Everyone the pixel and checkout have seen who matches. Whop rebuilds it twice a day.",onClose:r,footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"audience-manager__footer-note",children:"Size and match rate show on the audience row once it is built."}),(0,n.jsx)(V.Qd,{variant:"secondary",onClick:r,disabled:c,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:()=>{U().catch(()=>void 0)},loading:c,disabled:E.length>0||_&&R.length>0,children:o?"Save filters":"Build audience"})]}),children:[!o&&(0,n.jsx)("div",{className:"audience-manager__templates",role:"radiogroup","aria-label":"Start from",children:a5.map(e=>(0,n.jsxs)("button",{type:"button",role:"radio","aria-checked":N===e.id,className:"audience-manager__template".concat(N===e.id?" audience-manager__template--active":""),onClick:()=>z(e),children:[(0,n.jsx)("span",{className:"audience-manager__template-title",children:e.title}),(0,n.jsx)("span",{className:"audience-manager__template-text",children:e.description})]},e.id))}),(0,n.jsx)(V.gN,{label:"Audience name",required:!0,htmlFor:"audience-filter-name",children:(0,n.jsx)(V.oi,{id:"audience-filter-name",value:p,placeholder:"Recent US visitors",onChange:e=>{v(e.target.value),x(""===e.target.value),w(!0)}})}),(0,n.jsx)(V.gN,{label:"Seen in the last",htmlFor:"audience-filter-last-seen",children:(0,n.jsx)(tf,{id:"audience-filter-last-seen",value:f.lastSeenWithinDays,onChange:e=>Z({lastSeenWithinDays:e}),allowNone:!0})}),(0,n.jsx)(V.gN,{label:"Purchased",htmlFor:"audience-filter-purchased",children:(0,n.jsx)(aY,{ariaLabel:"Purchased",options:[{value:"any",label:"Anyone"},{value:"yes",label:"Customers only"},{value:"no",label:"Never bought"}],value:W,onChange:e=>Z({hasPurchased:"any"===e?void 0:"yes"===e})})}),C.map(e=>(0,n.jsxs)("div",{className:"audience-manager__extra",children:[q(e),(0,n.jsx)("button",{type:"button",className:"audience-manager__link audience-manager__extra-remove",onClick:()=>B(e),children:"Remove"})]},e)),Q.length>0&&(0,n.jsxs)("div",{className:"audience-manager__extras",children:[(0,n.jsx)("span",{className:"audience-manager__extras-label",children:"Narrow it down:"}),Q.map(e=>(0,n.jsxs)("button",{type:"button",className:"audience-manager__chip audience-manager__chip--add",onClick:()=>O(e.key),children:["+ ",e.label]},e.key))]}),(0,n.jsxs)("details",{className:"audience-manager__advanced",open:A,onToggle:e=>I(e.target.open),children:[(0,n.jsx)("summary",{children:"Advanced"}),(0,n.jsxs)("label",{className:"audience-manager__check",htmlFor:"audience-filter-contactable",children:[(0,n.jsx)("input",{id:"audience-filter-contactable",type:"checkbox",checked:!0===f.contactable,onChange:e=>Z({contactable:!!e.target.checked||void 0})}),(0,n.jsx)("span",{children:"Only people with an email or phone the ad platform can match. Off means everyone, including anonymous visitors, which lowers the match rate."})]}),(0,n.jsx)(V.gN,{label:"Attribution",htmlFor:"audience-filter-attribution",hint:"Which touch decides where someone came from: the last one before they acted, or the very first.",children:(0,n.jsx)(aY,{ariaLabel:"Attribution",options:[{value:"last_touch",label:"Last touch"},{value:"first_touch",label:"First touch"}],value:null!==(t=f.attributionModel)&&void 0!==t?t:"last_touch",onChange:e=>Z({attributionModel:"first_touch"===e?"first_touch":void 0})})}),(0,n.jsx)(V.gN,{label:"Name, email or phone contains",htmlFor:"audience-filter-query",hint:"A text match on the person's own details. Rarely what a targeting audience needs.",children:(0,n.jsx)(V.oi,{id:"audience-filter-query",value:null!==(i=f.query)&&void 0!==i?i:"",onChange:e=>Z({query:e.target.value})})})]}),!o&&(0,n.jsxs)("label",{className:"audience-manager__check",htmlFor:"audience-filter-refresh",children:[(0,n.jsx)("input",{id:"audience-filter-refresh",type:"checkbox",checked:y,onChange:e=>b(e.target.checked)}),(0,n.jsx)("span",{children:"Keep it up to date: rebuild membership from these filters twice a day. Set once, at creation."})]}),(_||E.length>0)&&R.length>0&&(0,n.jsx)("ul",{className:"audience-manager__problems",children:R.map(e=>(0,n.jsx)("li",{children:e},e))})]})})},ty=e=>{var a;let{open:t,source:i,saving:l,onClose:r,onCreate:o}
1=e,[c,d]=(0,s.useState)(1),[u,h]=(0,s.useState)(2),[m,p]=(0,s.useState)(!1);(0,s.useEffect)(()=>{t&&(d(1),h(2),p(!1))},[t]);let v={sourceAudienceId:null!==(a=null==i?void 0:i.id)&&void 0!==a?a:"",count:c,percentage:u},g=aL(v),x=aM(c,u),f=async()=>{p(!0),!(g.length>0)&&await o(v)&&r()};return(0,n.jsx)(V.hB,{id:"audience-lookalike",open:t,onClose:r,width:520,children:(0,n.jsxs)(V.Vq,{title:"Build lookalikes",subtitle:i?'People similar to "'.concat(i.name,'", in similarity bands from the closest match outwards.'):void 0,onClose:r,footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"secondary",onClick:r,disabled:l,children:"Cancel"}),(0,n.jsxs)(V.Qd,{variant:"primary",onClick:()=>{f()},loading:l,disabled:m&&g.length>0,children:["Build ",1===c?"lookalike":"".concat(c," lookalikes")]})]}),children:[(0,n.jsxs)("div",{className:"audience-manager__grid",children:[(0,n.jsx)(V.gN,{label:"How many audiences",htmlFor:"audience-lookalike-count",hint:"1 to ".concat(6,"."),children:(0,n.jsx)(V.oi,{id:"audience-lookalike-count",type:"number",min:1,max:6,value:c,onChange:e=>{d(Number.parseInt(e.target.value,10)||0),p(!0)}})}),(0,n.jsx)(V.gN,{label:"Total reach (%)",htmlFor:"audience-lookalike-percentage",hint:"1 to ".concat(20,"% of the platform's people, split evenly."),children:(0,n.jsx)(V.oi,{id:"audience-lookalike-percentage",type:"number",min:1,max:20,value:u,onChange:e=>{h(Number.parseInt(e.target.value,10)||0),p(!0)}})})]}),x.length>0&&(0,n.jsxs)("p",{className:"audience-manager__hint",children:["You get ",1===x.length?"one audience":"".concat(x.length," audiences"),": ",x.join(", "),"."]}),m&&g.length>0&&(0,n.jsx)("ul",{className:"audience-manager__problems",children:g.map(e=>(0,n.jsx)("li",{children:e},e))})]})})};let tb=e=>aw(e)?"Build lookalike audiences from this one":"lookalike"===e.audienceType?"A lookalike cannot seed another lookalike; build from its source audience.":"ready"!==e.status?"Lookalikes need this audience to be ready first.":"Lookalikes need at least ".concat(100," matched people in the source audience."),t_=e=>{let a=e.platformAudienceIds.length;return 0===a?"":1===a?" \xb7 on the ad platform":" \xb7 on ".concat(a," platforms")};var tw=t(56756);let tN=(e,a)=>{let t=a.isOrgOwner||a.isOrgAdmin||a.isMediaBuyer;if(e.hideIfAppSumo&&a.isOnAppSumoPlan||e.hideIfNonAdmin&&!a.isOrgAdmin||e.hideIfNonSuperAdmin&&!a.isOrgOwner)return!1;switch(e.name){case"Ad Accounts":case"Facebook":return t;case"Pixel":case"Audiences":return a.brandReportsAPixel;case"Dropbox":return a.canAccessDropbox;case"Google Drive":return a.canAccessGoogleDrive;case"Frame.io":return a.canUseFrameio;case"Slack":case"Cometly":case"Hyros":return a.canAccessIntegrations;case"RedTrack":return a.hasRedTrackBeta&&a.canAccessIntegrations;default:return!0}},tk=(e,a)=>e.filter(e=>!(e.hideIfNonAdmin&&!a.isOrgAdmin)).map(e=>({...e,options:e.options.filter(e=>tN(e,a))})).filter(e=>e.options.length>0);t(62187);var tC=t(13631);t(71612);var tS=t(53715);t(27657);var tA=t(19620),tI=t(68955),tP=t(90418),tT=t(93086),tF=t(6563);let tE=[{value:"America/New_York",label:"America/New_York (Eastern)"},{value:"America/Chicago",label:"America/Chicago (Central)"},{value:"America/Denver",label:"America/Denver (Mountain)"},{value:"America/Los_Angeles",label:"America/Los_Angeles (Pacific)"},{value:"America/Phoenix",label:"America/Phoenix (Arizona)"},{value:"America/Anchorage",label:"America/Anchorage (Alaska)"},{value:"Pacific/Honolulu",label:"Pacific/Honolulu (Hawaii)"},{value:"America/Toronto",label:"America/Toronto (Toronto)"},{value:"America/Vancouver",label:"America/Vancouver (Vancouver)"},{value:"America/Mexico_City",label:"America/Mexico_City"},{value:"America/Sao_Paulo",label:"America/Sao_Paulo"},{value:"America/Buenos_Aires",label:"America/Buenos_Aires"},{value:"America/Santiago",label:"America/Santiago"},{value:"America/Lima",label:"America/Lima"},{value:"America/Bogota",label:"America/Bogota"},{value:"America/Caracas",label:"America/Caracas"},{value:"Europe/London",label:"Europe/London (GMT)"},{value:"Europe/Paris",label:"Europe/Paris (CET)"},{value:"Europe/Berlin",label:"Europe/Berlin"},{value:"Europe/Rome",label:"Europe/Rome"},{value:"Europe/Madrid",label:"Europe/Madrid"},{value:"Europe/Amsterdam",label:"Europe/Amsterdam"},{value:"Europe/Brussels",label:"Europe/Brussels"},{value:"Europe/Vienna",label:"Europe/Vienna"},{value:"Europe/Zurich",label:"Europe/Zurich"},{value:"Europe/Stockholm",label:"Europe/Stockholm"},{value:"Europe/Copenhagen",label:"Europe/Copenhagen"},{value:"Europe/Oslo",label:"Europe/Oslo"},{value:"Europe/Helsinki",label:"Europe/Helsinki"},{value:"Europe/Warsaw",label:"Europe/Warsaw"},{value:"Europe/Prague",label:"Europe/Prague"},{value:"Europe/Budapest",label:"Europe/Budapest"},{value:"Europe/Athens",label:"Europe/Athens"},{value:"Europe/Istanbul",label:"Europe/Istanbul"},{value:"Europe/Moscow",label:"Europe/Moscow"},{value:"Europe/Lisbon",label:"Europe/Lisbon"},{value:"Europe/Dublin",label:"Europe/Dublin"},{value:"Africa/Cairo",label:"Africa/Cairo"},{value:"Africa/Johannesburg",label:"Africa/Johannesburg"},{value:"Africa/Lagos",label:"Africa/Lagos"},{value:"Africa/Nairobi",label:"Africa/Nairobi"},{value:"Africa/Casablanca",label:"Africa/Casablanca"},{value:"Asia/Dubai",label:"Asia/Dubai"},{value:"Asia/Riyadh",label:"Asia/Riyadh"},{value:"Asia/Tehran",label:"Asia/Tehran"},{value:"Asia/Karachi",label:"Asia/Karachi"},{value:"Asia/Kolkata",label:"Asia/Kolkata (India)"},{value:"Asia/Dhaka",label:"Asia/Dhaka"},{value:"Asia/Bangkok",label:"Asia/Bangkok"},{value:"Asia/Singapore",label:"Asia/Singapore"},{value:"Asia/Hong_Kong",label:"Asia/Hong_Kong"},{value:"Asia/Shanghai",label:"Asia/Shanghai (China)"},{value:"Asia/Tokyo",label:"Asia/Tokyo (Japan)"},{value:"Asia/Seoul",label:"Asia/Seoul (South Korea)"},{value:"Asia/Jakarta",label:"Asia/Jakarta"},{value:"Asia/Manila",label:"Asia/Manila"},{value:"Asia/Taipei",label:"Asia/Taipei"},{value:"Asia/Kuala_Lumpur",label:"Asia/Kuala_Lumpur"},{value:"Asia/Ho_Chi_Minh",label:"Asia/Ho_Chi_Minh"},{value:"Australia/Sydney",label:"Australia/Sydney (AEST)"},{value:"Australia/Melbourne",label:"Australia/Melbourne"},{value:"Australia/Brisbane",label:"Australia/Brisbane"},{value:"Australia/Perth",label:"Australia/Perth (AWST)"},{value:"Australia/Adelaide",label:"Australia/Adelaide"},{value:"Pacific/Auckland",label:"Pacific/Auckland (New Zealand)"},{value:"Pacific/Fiji",label:"Pacific/Fiji"},{value:"UTC",label:"UTC"}];var tD=t(10724),tL=t(40044),tM=t(82920),tR=t(99588),tZ=t(1029);t(31778);var tz=t(19784);t(16418);var tO=t(42176),tB=t(50853),tV=t(87357);function tK(e){let{toggleAddUserModal:a,disableButton:t,isCurrentUserAdmin:i}=e,l=(0,s.useMemo)(()=>i?"You have reached your organization's user limit.":"Must be an admin to invite new users.",[i]);return(0,n.jsx)(tO.D,{className:"organization-toolbar",children:(0,n.jsxs)("div",{className:"organization-toolbar__actions",children:[(0,n.jsx)(tB.M,{}),(0,n.jsx)(tV.Z,{sx:{flexGrow:1}}),(0,n.jsx)(tF.Z,{title:l,disabled:!t,children:(0,n.jsx)("div",{children:(0,n.jsx)(K.Z,{onClick:a,disabled:t,children:"Invite Members"})})})]})})}var tU=e=>{let{toggleAddUserModal:a,disableButton:t,isCurrentUserAdmin:s}=e;return(0,n.jsx)(tK,{toggleAddUserModal:a,disableButton:t,isCurrentUserAdmin:s})};let tW=(e,a,t,n)=>{let s=Number(e),i=Number(a);return s&&i?(0,tR.Id)(s,i,t,n):(0,tR.Id)(e,a,t,n)};var tQ=e=>{let{organizationUsers:a,toggleAddUserModal:t,toggleEditUserPermissionsModal:i,userLimit:l,isCurrentUserAdmin:r,isCurrentUserSuperAdmin:o,currentUser:c,showToolbar:d=!0}
1=e,[u,h]=(0,s.useState)(null),[m,p]=(0,s.useState)({}),v=(0,s.useMemo)(()=>a.length>=l||!r,[a.length,l,r]),g=e=>!e.originalName,x=e=>{let a=m[e];return!!(a&&Date.now()<a)},j=async(e,a)=>{h(e);try{let{success:t,error:n}=await (0,f.handleFetch)("/organization/users/".concat(e,"/resend-invite"),{method:"POST"});t?(p(a=>({...a,[e]:Date.now()+3e5})),R.ZP.success("Invitation resent to ".concat(a))):R.ZP.error((null==n?void 0:n.message)||"Failed to resend invitation")}catch(e){R.ZP.error("Failed to resend invitation")}finally{h(null)}},y=e=>!r||(!!e.isSuperAdmin||!!e.isOrgAdmin)&&!o,b=e=>r?e.isSuperAdmin&&!o?"Only the organization owner can manage other owners.":e.isOrgAdmin&&!o?"Only the organization owner can manage admin permissions.":"":"Must be an admin to edit user permissions.",_=(0,s.useMemo)(()=>a.some(e=>!e.name),[a]),w=[{field:"name",headerName:"Name",flex:1.5,minWidth:150,sortComparator:tW},{field:"roles",headerName:"Role",flex:.75,minWidth:110,renderCell:e=>e.value.map(e=>(0,n.jsx)(F.Z,{label:e,sx:{marginRight:"0.5em"}},e))},{field:"email",headerName:"Email",flex:1,minWidth:190},{field:"createdAt",headerName:"User Since",flex:1,minWidth:120,sortComparator:tW,valueFormatter:tz.p6},..._&&r?[{field:"resend",headerName:"",flex:.75,minWidth:100,disableColumnMenu:!0,disableReorder:!0,filterable:!1,sortable:!1,renderCell:e=>{if(!g(e.row))return null;let a=x(e.row.id),t=u===e.row.id;return(0,n.jsx)(tF.Z,{title:a?"Invite was recently sent":"",disabled:!a,placement:"left",children:(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",height:"100%"},children:(0,n.jsx)(K.Z,{size:"sm",onClick:()=>j(e.row.id,e.row.email),disabled:t||a,loading:t,table:!0,color:"primary",children:a?"Sent":"Resend"})})})}}]:[],{field:"action",headerName:"",flex:.5,minWidth:80,disableColumnMenu:!0,disableReorder:!0,filterable:!1,sortable:!1,renderCell:e=>(0,n.jsx)(tF.Z,{title:b(e.row),disabled:!y(e.row),placement:"left",children:(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",height:"100%"},children:(0,n.jsx)("button",{type:"button",className:"linkbtn",onClick:()=>i(e.row),disabled:y(e.row),children:"Edit"})})})}],N=(0,s.useMemo)(()=>a.map(e=>{let{roles:a}=e,t=a.map(e=>e.name);t.length||(t=["Member"]),e.isAdmin&&(t=["Admin"]);let{id:n,name:s,email:i,createdAt:l,isOrgAdmin:r,isSuperAdmin:o}=e;return{id:n,name:s||"Pending Invite Accept",originalName:s,email:i,roles:t,createdAt:l,isOrgAdmin:r,isSuperAdmin:o}}),[a]);return(0,n.jsx)("div",{className:"organization-table",children:(0,n.jsx)(tZ._,{rows:N,columns:w,initialState:{pagination:{paginationModel:{pageSize:10}}},pageSizeOptions:[10],disableRowSelectionOnClick:!0,...d&&{slots:{toolbar:tU},slotProps:{toolbar:{toggleAddUserModal:t,disableButton:v,isCurrentUserAdmin:r}}}})})};t(45955),t(95340),t(38692);var tH=t(72428);t(45486);var tq=t(18972),tG=t(59334),tY=t(69368),tJ=t(94054),tX=t(34521),t$=t(54110);let t0="SELECT_ALL_BRANDS",t1=e=>void 0!==e.id&&void 0!==e.name;var t2=e=>{let{index:a,brands:t,alterInvites:i,deleteInvite:l=()=>void 0,isLast:r=!1,roles:c,noDelete:d=!1}=e,u=(0,s.useMemo)(()=>c.find(e=>"Admin"===e.name),[c]),h=(0,s.useMemo)(()=>c.find(e=>"Media Buyer"===e.name),[c]),[m,p]=(0,s.useState)(""),[v,g]=(0,s.useState)(null),[x,j]=(0,s.useState)([t0,...t]);(0,s.useEffect)(()=>{null===v&&(h?g(h):c.length>0&&g(c[0]))},[v,h,c]);let y=(0,s.useCallback)(()=>{u&&(null==v?void 0:v.id)===u.id&&j([t0,...t])},[v,u,t]);(0,s.useEffect)(()=>{y()},[v,t,y]);let b=(0,s.useMemo)(()=>!!(0,f.Xt)(m)&&0!==x.length,[m,x]),_=(0,s.useMemo)(()=>r?"Cannot remove last invite.":b?"":"Cannot remove incomplete form.",[r,b]),w=c.map(e=>(0,n.jsx)(tq.Z,{value:e,children:(0,n.jsx)("span",{className:"organization-form__role-option",children:(0,n.jsx)(tG.Z,{primary:e.name,secondary:e.description,sx:{"& .MuiListItemText-secondary":{whiteSpace:"normal",overflow:"visible",textOverflow:"clip"},"& .MuiListItemText-primary":{display:"block"}}})})},e.id)),N=e=>!!(x.includes(t0)||1===x.length&&x.includes(e)),k=t.map(e=>(0,n.jsxs)(tq.Z,{value:e,disabled:N(e),children:[(0,n.jsx)(tY.Z,{checked:x.indexOf(e)>-1}),(0,n.jsx)(tG.Z,{primary:e.name})]}
1,e.id)),C=(0,s.useMemo)(()=>h&&(null==v?void 0:v.id)===h.id?"All Current Ad Accounts":"All Ad Accounts",[v,h]),S=(0,n.jsxs)(tq.Z,{value:t0,children:[(0,n.jsx)(tY.Z,{checked:x.includes(t0)}),(0,n.jsx)(tG.Z,{primary:C})]},t0),A=e=>{g(e.target.value)},I=e=>{let a=e.target.value,n=x.includes(t0),s=a.includes(t0);if(!u||(null==v?void 0:v.id)!==u.id){if(!n&&s){j([t0,...t]);return}if(n&&!s){j([]);return}a.filter(e=>"string"!=typeof e).length===t.length&&u?g(u):u&&h&&(null==v?void 0:v.id)===u.id&&g(h),j(a)}};return(0,s.useEffect)(()=>{let e=x.filter(t1),t=v||h||(c.length>0?c[0]:null);i(a,{complete:b,email:m,roles:t?[t]:[],brands:e})},[b,m,v,x,a,i,h,c]),(0,n.jsxs)("form",{className:o()("km-permrow",{"km-permrow--no-delete":d}),children:[(0,n.jsx)(tJ.Z,{className:"organization-form__user",children:(0,n.jsx)(V.gN,{label:"Email",required:!0,htmlFor:"invite-email-".concat(a),children:(0,n.jsx)(V.oi,{id:"invite-email-".concat(a),value:m,placeholder:"Email",onChange:e=>{let{target:{value:a}}=e;return p(a)},required:!0})})}),(0,n.jsx)(tJ.Z,{className:"organization-form__role",children:(0,n.jsx)(t$.Z,{labelId:"select-role",value:v,label:"Role",onChange:e=>A(e),renderValue:e=>(0,n.jsx)(tV.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(0,n.jsx)(F.Z,{label:null==e?void 0:e.name},null==e?void 0:e.name)}),required:!0,children:w})}),(0,n.jsx)(tJ.Z,{className:"organization-form__brand",children:(0,n.jsxs)(t$.Z,{labelId:"select-brand",value:(null==v?void 0:v.id)===(null==u?void 0:u.id)?[t0,...t]:x,label:"Ad Accounts",onChange:e=>I(e),disabled:(null==v?void 0:v.id)===(null==u?void 0:u.id),renderValue:e=>{if((null==v?void 0:v.id)===(null==u?void 0:u.id)||x.includes(t0))return(0,n.jsx)(F.Z,{label:C,className:"edit-user-permissions-form__chip"},"all");let a=e.filter(t1).map(e=>e.name);return(0,n.jsx)(tV.Z,{sx:{display:"flex",gap:.5},children:(0,n.jsx)(F.Z,{label:"".concat(a.length," Ad Account").concat(a.length>1?"s":"")},a.length)})},multiple:!0,required:!0,children:[S,k]})}),!d&&(0,n.jsx)(tF.Z,{title:_,disabled:!1,placement:"right",children:(0,n.jsx)("span",{style:!b||r?{cursor:"not-allowed"}:{},children:(0,n.jsx)(V.hU,{disabled:!b||r,onClick:()=>l(a),"aria-label":"delete",children:(0,n.jsx)(tX.wg,{fontSize:"inherit"})})})})]})};let t5={0:{complete:!1,email:"",brands:[],roles:[]}},t3={complete:!1,email:"",brands:[],roles:[]};var t4=e=>{let{open:a,onClose:t,currentOrganization:i,roles:l,userLimit:r,numCurrUsers:o,refetch:c,isModal:d=!0,onSubmitStart:u,onSubmitEnd:h,bypassUserLimit:m=!1}=e,{brands:p}=i,[v,g]=(0,s.useState)(t5),[x,j]=(0,s.useState)(1),[y,b]=(0,s.useState)(1),[_,w]=(0,s.useState)(""),[N,k]=(0,s.useState)(!1),C=(0,s.useMemo)(()=>1===x,[x]),S=(0,s.useMemo)(()=>Object.values(v).some(e=>!1===e.complete),[v]),A=(0,s.useMemo)(()=>!m&&o+x>=r?"You have an organization limit of ".concat(r," users."):x>=5?"You may only add a maximum of 5 users at a time.":"Complete current invites before adding another.",[o,x,r,m]),I=(0,s.useMemo)(()=>!!(x>=5||Object.values(v).some(e=>!e||!1===e.complete))||!m&&o+x>=r,[x,v,o,r,m]),P=(0,s.useCallback)((e,a)=>{g(t=>({...t,[e]:a}))},[g]),T=()=>{j(e=>e+1),g(e=>({...e,[y]:t3})),b(e=>e+1)},F=e=>{j(e=>e-1);let a={...v};delete a[e],g(a)},E=async()=>{w(""),k(!0),null==u||u();let e=Object.values(v),a=await Promise.all(e.map(async e=>{let a=e.brands.filter(e=>"string"!=typeof e),t={email:e.email,brands:a,roles:e.roles},{data:n,success:s,error:i}=await (0,f.handleFetch)("/organization/users",{method:"POST",body:t});if(i){w(i.message||"Something went wrong. Please try again."),R.ZP.error("Error inviting ".concat(e.email));return}return s&&R.ZP.success("Successfully invited ".concat(e.email)),n}));k(!1),null==h||h(),a.every(e=>void 0!==e)&&c&&t&&(c(),t())};(0,s.useEffect)(()=>{g(t5),j(1),b(1)},[a]);let D=()=>{let e=Object.keys(v);return Object.values(v).map((a,t)=>(0,n.jsx)(t2,{brands:p,roles:l,index:Number(e[t]),alterInvites:P,deleteInvite:F,isLast:C},e[t]))},L=(0,n.jsx)(tF.Z,{title:A,disabled:!I,children:(0,n.jsx)("span",{children:(0,n.jsxs)("button",{type:"button",className:"organization-addrow",onClick:T,disabled:I,children:[(0,n.jsx)(tH.Z,{}),"Add another user"]})})});return d?(0,n.jsx)(V.hB,{id:"invite-users",open:a,onClose:t,width:780,children:(0,n.jsxs)(V.Vq,{onClose:t,title:"Invite New Members",subtitle:"Invite new members by email to join your organization.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:t,children:"Close"}),(0,n.jsx)(tF.Z,{title:"All invites must be complete to submit.",disabled:!S&&!N,children:(0,n.jsx)("span",{children:(0,n.jsx)(V.Qd,{variant:"primary",onClick:E,disabled:S||N,loading:N,children:"Send Invites"})})})]}),children:[_&&(0,n.jsx)("p",{className:"organization-modal__error",children:_}),(0,n.jsx)("div",{className:"organization__form",children:D()}),L]})}):(0,n.jsxs)(n.Fragment,{children:[_&&(0,n.jsx)("p",{className:"organization-modal__error",children:_}),(0,n.jsx)("div",{className:"organization__form",children:D()}),(0,n.jsxs)("div",{className:"organization-add-user__buttons",children:[(0,n.jsx)(tF.Z,{title:A,disabled:!I,children:(0,n.jsx)("div",{children:(0,n.jsx)(K.Z,{onClick:T,disabled:I,color:"secondary",children:"Add another"})})}),(0,n.jsx)(tF.Z,{title:"All invites must be complete to submit.",disabled:!S,children:(0,n.jsx)("div",{children:(0,n.jsx)(K.Z,{onClick:E,disabled:S,children:"Send Invites"})})})]})]})};t(43023),t(7258);let t8=(e,a)=>e.map(e=>{let{id:t}=e;for(let e=0;e<a.length;e++)if(a[e].id===t)return a[e];return e}),t6="SELECT_ALL_BRANDS",t9=e=>void 0!==e.id&&void 0!==e.name,t7=(e,a)=>{let t=!1;
1return e.forEach(e=>{a.has(e)||(t=!0)}),t};var ne=e=>{let{brands:a,users:t,defaultUser:i,roles:l,onClose:r,setDeleteUser:o,setError:c,toggleDeleteUserModal:d,registerSubmit:u}=e,[h,m]=(0,s.useState)(i),[p,v]=(0,s.useState)(i.roles[0]||null),g=(0,s.useMemo)(()=>t8(l,h.roles),[h,l]),x=(0,s.useMemo)(()=>t8(a,h.allowedBrands),[h,a]),j=(0,s.useMemo)(()=>g.find(e=>"Admin"===e.name),[g]),y=(0,s.useMemo)(()=>g.find(e=>"Media Buyer"===e.name),[g]),b=(0,s.useMemo)(()=>h.allowedBrands.length===a.length||h.roles.includes(j)?[...x,t6]:h.allowedBrands,[a.length,j,x,h.allowedBrands,h.roles]),[_,w]=(0,s.useState)(b);(0,s.useEffect)(()=>{h.allowedBrands.length===a.length||h.roles.includes(j)?w([...x,t6]):w(h.allowedBrands),v(h.roles[0]||null)},[h,a.length,i.allowedBrands,j,x]);let N=g.map(e=>(0,n.jsx)(tq.Z,{value:e,children:(0,n.jsx)("span",{className:"organization-form__role-option",children:(0,n.jsx)(tG.Z,{primary:e.name,secondary:e.description,sx:{"& .MuiListItemText-secondary":{whiteSpace:"normal",overflow:"visible",textOverflow:"clip"},"& .MuiListItemText-primary":{display:"block"}}})})},e.id)),k=t.map(e=>(0,n.jsx)(tq.Z,{value:e.id,children:e.email},e.id)),C=e=>!!(_.includes(t6)||1===_.length&&_.includes(e)),S=x.map(e=>(0,n.jsxs)(tq.Z,{value:e,disabled:C(e),children:[(0,n.jsx)(tY.Z,{checked:_.indexOf(e)>-1}),(0,n.jsx)(tG.Z,{primary:e.name})]},e.id)),A=(0,s.useMemo)(()=>y&&(null==p?void 0:p.id)===y.id?"All Current Ad Accounts":"All Ad Accounts",[p,y]),I=(0,n.jsxs)(tq.Z,{value:t6,children:[(0,n.jsx)(tY.Z,{checked:_.includes(t6)}),(0,n.jsx)(tG.Z,{primary:A})]},t6),P=e=>{let a=e.target.value;v(a),j&&a.id===j.id&&w([t6,...x])},E=e=>{let a=e.target.value,n=t.find(e=>e.id===a);n&&(m(n),o(n))},D=e=>{let t=e.target.value,n=_.includes(t6),s=t.includes(t6);if(!j||(null==p?void 0:p.id)!==j.id){if(!n&&s){w([t6,...x]);return}if(n&&!s){w([]);return}t.filter(e=>"string"!=typeof e).length===a.length&&j?v(j):j&&y&&(null==p?void 0:p.id)===j.id&&v(y),w(t)}},L=(0,s.useMemo)(()=>{let e=new Set(h.roles.map(e=>e.id)),a=new Set(p?[p.id]:[]),t=new Set(b.filter(t9).map(e=>e.id)),n=new Set(_.filter(t9).map(e=>e.id));return t7(e,a)||t7(a,e)||t7(t,n)||t7(n,t)},[h.roles,p,b,_]),M=async()=>{if(!L){r();return}let e=_.filter(e=>"string"!=typeof e),{error:a,success:t}=await (0,f.handleFetch)("/user/permissions",{method:"PUT",body:{user:h,brands:e,roles:p?[p]:[]}});t?(r(),R.ZP.success("Successfully updated ".concat(h.email,"'s permissions."))):(c(a.message),R.ZP.error("Error updating ".concat(h.email,"'s permissions.")))},Z=async()=>{d()},z=(0,s.useMemo)(()=>L?"Save Changes":"Close",[L]);return(0,s.useEffect)(()=>{u(M,z)},[u,z,L,h,p,_]),(0,n.jsxs)("form",{className:"km-permrow",children:[(0,n.jsx)(tJ.Z,{className:"organization-form__user",children:(0,n.jsx)(t$.Z,{labelId:"select-role",value:h.id||"",label:"User",onChange:e=>E(e),required:!0,children:k})}),(0,n.jsx)(tJ.Z,{className:"organization-form__role",children:(0,n.jsx)(t$.Z,{labelId:"select-role",value:p||"",label:"Role",onChange:e=>P(e),renderValue:e=>(0,n.jsx)(tV.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(0,n.jsx)(F.Z,{label:null==e?void 0:e.name},null==e?void 0:e.name)}),required:!0,children:N})}),(0,n.jsx)(tJ.Z,{className:"organization-form__brand",children:(0,n.jsxs)(t$.Z,{labelId:"select-brand",value:(null==p?void 0:p.id)===(null==j?void 0:j.id)?[t6,...x]:_,label:"Ad Accounts",onChange:e=>D(e),disabled:(null==p?void 0:p.id)===(null==j?void 0:j.id),renderValue:e=>{if((null==p?void 0:p.id)===(null==j?void 0:j.id)||_.includes(t6))return(0,n.jsx)(F.Z,{label:A,className:"edit-user-permissions-form__chip"},"all");let a=e.filter(t9).map(e=>e.name);return(0,n.jsx)(tV.Z,{sx:{display:"flex",gap:.5},children:(0,n.jsx)(F.Z,{label:"".concat(a.length," Ad Account").concat(a.length>1?"s":"")},a.length)})},multiple:!0,required:!0,children:[I,S]})}),(0,n.jsx)(T.Z,{title:"Delete User",placement:"right",children:(0,n.jsx)("span",{children:(0,n.jsx)(V.hU,{onClick:Z,"aria-label":"delete",children:(0,n.jsx)(tX.dI,{fontSize:"inherit"})})})})]})};function na(e){let{user:a,open:t,onClose:i,refetch:l,closeEditModal:r}
1=e,[o,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(!1),h=async e=>{c(""),u(!0);let{error:t,success:n}=await (0,f.handleFetch)("/organization/users/".concat(e),{method:"DELETE"});u(!1),n?(l(),r(),R.ZP.success("Successfully deleted ".concat(a.email,"!"))):(R.ZP.error("Error deleting ".concat(a.email,".")),c(t.message))};return(0,n.jsx)(V.hB,{id:"delete-user-confirm",open:t,onClose:i,onEnter:d?void 0:()=>h(a.id),width:480,children:(0,n.jsx)(V.Vq,{onClose:i,confirmIcon:"warning",title:"Are you sure you want to remove this user from your organization?",subtitle:"This user will no longer have access to your organization. You will need to contact support to add them again.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:i,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",loading:d,onClick:()=>h(a.id),children:"Remove"})]}),children:o&&(0,n.jsx)("p",{className:"organization-modal__error",children:o})})})}var nt=e=>{let{open:a,onClose:t,currentOrganization:i,selectedUser:l,roles:r,refetch:o}=e,{brands:c,users:d}=i,[u,h]=(0,s.useState)(l),[m,p]=(0,s.useState)(!1),[v,g]=(0,s.useState)(""),[x,f]=(0,s.useState)(()=>()=>void 0),[j,y]=(0,s.useState)("Save Changes"),b=(0,s.useMemo)(()=>{if(d)return d.filter(e=>e.id===l.id)[0]},[d,l.id]),_=()=>p(e=>!e),w=(0,s.useCallback)((e,a)=>{f(()=>e),y(a)},[]);return(0,n.jsxs)(V.hB,{id:"edit-user-permissions",open:a,onClose:t,width:780,children:[(0,n.jsxs)(V.Vq,{onClose:t,title:"Edit User Permissions",subtitle:"Control which ad accounts each user can access.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:t,children:"Close"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:()=>x(),children:j})]}),children:[v&&(0,n.jsx)("p",{className:"organization-modal__error",children:v}),l&&(0,n.jsx)(ne,{brands:c,users:d,defaultUser:b,roles:r,onClose:()=>{o(),t()},setDeleteUser:h,setError:g,toggleDeleteUserModal:_,registerSubmit:w})]}),m&&(0,n.jsx)(na,{open:m,user:u,onClose:_,closeEditModal:t,refetch:o})]})};let nn={id:0,email:"",name:"",role:"",createdAt:"",roles:[],allowedBrands:[]};t(41745);var ns=t(98961),ni=t(14766);function nl(e){let a=new URLSearchParams;return a.set("preset",e.preset),"custom"===e.preset&&(e.from&&a.set("from",e.from),e.to&&a.set("to",e.to)),a.toString()}function nr(e){if(e&&"object"==typeof e&&!1===e.success&&e.error)throw Error(e.error.message||"Request failed");return e}class no{async getMetrics(e,a){let t=new URLSearchParams(nl(e));return t.set("role",a),nr(await (0,f.handleFetch)("/org-admin/metrics?".concat(t.toString())))}async getFeatureUsage(e,a){let t=new URLSearchParams(nl(e));return t.set("role",a),nr(await (0,f.handleFetch)("/org-admin/feature-usage?".concat(t.toString())))}async getLogins(e,a,t){let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:100,s=new URLSearchParams(nl(e));return s.set("cursor",String(null!=t?t:0)),s.set("limit",String(n)),nr(await (0,f.handleFetch)("/org-admin/logins?".concat(s.toString())))}async buildLoginsCsv(e){let a=new URLSearchParams(nl(e)),t=await (0,f.handleFetch)("/org-admin/logins.csv?".concat(a.toString()),{"Content-Type":"text/plain"});if(t&&"object"==typeof t&&!1===t.success&&t.error)throw Error(t.error.message||"CSV download failed");return t}}let nc=new no,nd=e=>{let{data:a,series:t,height:s=200,loading:i}=e;if(i)return(0,n.jsx)(ns.Od,{variant:"chart",width:"100%",height:s});if(!a||0===a.length||0===t.length)return(0,n.jsx)("div",{className:"k-empty",children:(0,n.jsx)("p",{children:"No ads launched in this range."})});let l=Math.max(...a.map(e=>t.reduce((a,t)=>{var n;return a+(null!==(n=e.values[String(t.userId)])&&void 0!==n?n:0)},0)),0);return 0===l?(0,n.jsx)("div",{className:"k-empty",children:(0,n.jsx)("p",{children:"No ads launched in this range."})}):(0,n.jsx)("div",{className:"org-admin-stacked-bars",style:{height:s},children:a.map(e=>{let a=t.reduce((a,t)=>{var n;return a+(null!==(n=e.values[String(t.userId)])&&void 0!==n?n:0)},0),s=0===a?0:a/l*100;return(0,n.jsx)("div",{className:"org-admin-stacked-bars__col",title:"".concat(e.date," \xb7 ").concat(a),style:{height:"".concat(s,"%")},children:0===a?(0,n.jsx)("div",{className:"org-admin-stacked-bars__empty"}):t.map(t=>{var s;let i=null!==(s=e.values[String(t.userId)])&&void 0!==s?s:0;if(0===i)return null;let l=i/a*100;return(0,n.jsx)("div",{className:"org-admin-stacked-bars__seg",style:{background:t.color,height:"".concat(l,"%")},title:"".concat(t.name,": ").concat(i)},t.userId)})},e.date)})})},nu=e=>{let{series:a,max:t=12}=e,s=a.slice(0,t),i=a.length-s.length;return(0,n.jsxs)("div",{className:"org-admin-legend",children:[s.map(e=>(0,n.jsxs)("span",{className:"org-admin-legend__item",children:[(0,n.jsx)("span",{className:"org-admin-legend__swatch",style:{background:e.color}}),e.name]}
1,e.userId)),i>0&&(0,n.jsxs)("span",{className:"org-admin-legend__item",children:["+",i," more"]})]})},nh={key:"adsLaunched",dir:"desc"},nm=e=>new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1}).format(e);var np=e=>{var a,t,i,l,r,o,c,d,u,h,m;let{roleFilter:p="all",title:v,range:g}=e,[x,f]=(0,s.useState)(null),[j,y]=(0,s.useState)(null),[b,_]=(0,s.useState)(nh),w=null===x&&null===j;(0,s.useEffect)(()=>{let e=!1;return y(null),nc.getMetrics(g,p).then(a=>{e||f(a)}).catch(a=>{e||y(a.message||"Failed to load")}),()=>{e=!0}},[g.preset,g.from,g.to,p]);let N=(0,s.useMemo)(()=>{if(!x)return[];let e=[...x.detail],a="asc"===b.dir?1:-1;return e.sort((e,t)=>{let n=e[b.key],s=t[b.key];return null===n&&null===s?0:null===n?1:null===s?-1:"number"==typeof n&&"number"==typeof s?(n-s)*a:String(n).localeCompare(String(s))*a}),e},[x,b]),k="Media Buyer"===p?"Ads launched \xb7 by media buyer":"Ads launched",C="Content Manager"===p?"Creative uploads \xb7 by content manager":"Creative uploads",S="max"===g.preset?"all time":"custom"===g.preset?"selected range":"Last ".concat(g.preset),A="max"===g.preset?"all time":"custom"===g.preset?"selected range":g.preset;return(0,n.jsxs)("div",{children:[v&&(0,n.jsx)("h2",{className:"admin-pageheader__title",style:{marginBottom:16},children:v}),(0,n.jsxs)("div",{className:"org-admin-row--kpis",children:[(0,n.jsx)(ns.Nx,{loading:w,label:"ADS LAUNCHED",value:null!==(a=null==x?void 0:x.kpis.adsLaunched.formattedValue)&&void 0!==a?a:"0",icon:(0,n.jsx)(ni.J,{name:"bolt",size:14}),tone:"violet"}),(0,n.jsx)(ns.Nx,{loading:w,label:"CREATIVES UPLOADED",value:null!==(t=null==x?void 0:x.kpis.creativesUploaded.formattedValue)&&void 0!==t?t:"0",icon:(0,n.jsx)(ni.J,{name:"chart",size:14}),tone:"cyan"}),(0,n.jsx)(ns.Nx,{loading:w,label:"CAMPAIGNS CREATED",value:null!==(i=null==x?void 0:x.kpis.batchesCreated.formattedValue)&&void 0!==i?i:"0",icon:(0,n.jsx)(ni.J,{name:"rocket",size:14}),tone:"success"}),(0,n.jsx)(ns.Nx,{loading:w,label:"ACTIVE TEAMMATES",value:null!==(l=null==x?void 0:x.kpis.activeTeammates.formattedValue)&&void 0!==l?l:"0",icon:(0,n.jsx)(ni.J,{name:"users",size:14})})]}),(0,n.jsxs)("div",{className:"org-admin-row",children:[(0,n.jsx)(ns.LB,{title:k,subtitle:S,icon:(0,n.jsx)(ni.J,{name:"bolt",size:16}),actions:x?(0,n.jsx)(nu,{series:x.series,max:6}):null,children:(0,n.jsx)(nd,{data:null!==(r=null==x?void 0:x.charts.adsLaunchedDaily)&&void 0!==r?r:[],series:null!==(o=null==x?void 0:x.series)&&void 0!==o?o:[],loading:w})}),(0,n.jsx)(ns.LB,{title:C,subtitle:"Daily uploads \xb7 ".concat(A),icon:(0,n.jsx)(ni.J,{name:"chart",size:16}),children:(0,n.jsx)(ns.TH,{data:(null!==(c=null==x?void 0:x.charts.creativeUploadsDaily)&&void 0!==c?c:[]).map(e=>({x:e.date.slice(5),y:e.value})),loading:w,formatY:e=>nm(e)})})]}),(0,n.jsxs)("div",{className:"org-admin-row--kpis",children:[(0,n.jsx)(ns.Nx,{loading:w,label:"TEAMMATES",value:null!==(d=null==x?void 0:x.tileCluster.teammates)&&void 0!==d?d:0,icon:(0,n.jsx)(ni.J,{name:"users",size:14})}),(0,n.jsx)(ns.Nx,{loading:w,label:"MEDIA BUYERS",value:null!==(u=null==x?void 0:x.tileCluster.mediaBuyers)&&void 0!==u?u:0,icon:(0,n.jsx)(ni.J,{name:"bolt",size:14}),tone:"violet"}),(0,n.jsx)(ns.Nx,{loading:w,label:"CONTENT MANAGERS",value:null!==(h=null==x?void 0:x.tileCluster.contentManagers)&&void 0!==h?h:0,icon:(0,n.jsx)(ni.J,{name:"chart",size:14}),tone:"cyan"}),(0,n.jsx)(ns.Nx,{loading:w,label:"CONNECTED AD ACCOUNTS",value:null!==(m=null==x?void 0:x.tileCluster.connectedAdAccounts)&&void 0!==m?m:0,icon:(0,n.jsx)(ni.J,{name:"facebook",size:14})})]}),(0,n.jsx)(ns.LB,{title:"Metrics by User",subtitle:"Understand performance by each user in your organization",icon:(0,n.jsx)(ni.J,{name:"users",size:16}),flush:!0,children:j?(0,n.jsx)(ns.$w,{title:"Couldn't load detail",description:j}):(0,n.jsx)(ns.Rm,{loading:w,rows:N,rowKey:e=>e.userId,sort:b,onSortChange:_,emptyTitle:"No teammate activity",emptyDescription:"No data for the selected range.",columns:[{key:"name",header:"Teammate",sortable:!0,cell:e=>(0,n.jsx)(ns.V,{name:e.name,email:e.email})},{key:"role",header:"Role",sortable:!0,cell:e=>e.role},{key:"adsLaunched",header:"Ads launched",sortable:!0,align:"right",cell:e=>
1ns.ZN.num(e.adsLaunched)},{key:"creativesUploaded",header:"Creatives uploaded",sortable:!0,align:"right",cell:e=>ns.ZN.num(e.creativesUploaded)},{key:"batchesCreated",header:"Campaigns",sortable:!0,align:"right",cell:e=>ns.ZN.num(e.batchesCreated)},{key:"lastLogin",header:"Last login",sortable:!0,cell:e=>ns.ZN.relative(e.lastLogin)}]})})]})},nv=e=>{let{range:a}=e,[t,i]=(0,s.useState)([]),[l,r]=(0,s.useState)(null),[o,c]=(0,s.useState)(!0),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(""),[p,v]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=!1;return c(!0),u(null),nc.getLogins(a,void 0,void 0,100).then(a=>{e||(i(a.entries),r(a.nextCursor))}).catch(a=>{e||u(a.message||"Failed to load logins")}).finally(()=>{e||c(!1)}),()=>{e=!0}},[a.preset,a.from,a.to]);let g=async()=>{if(null!==l){c(!0);try{let e=await nc.getLogins(a,void 0,l,100);i(a=>[...a,...e.entries]),r(e.nextCursor)}catch(e){u(e.message||"Failed to load more")}finally{c(!1)}}},x=(0,s.useMemo)(()=>{if(!h.trim())return t;let e=h.trim().toLowerCase();return t.filter(a=>a.name.toLowerCase().includes(e)||a.email.toLowerCase().includes(e))},[t,h]),f=async()=>{v(!0);try{let e=await nc.buildLoginsCsv(a),t=new Blob([e],{type:"text/csv;charset=utf-8"}),n=URL.createObjectURL(t),s=document.createElement("a");s.href=n,s.download="login-history-".concat(a.preset,".csv"),document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(n)}catch(e){u(e.message||"CSV download failed")}finally{v(!1)}};return(0,n.jsx)(ns.LB,{title:"Login History",subtitle:"Reverse-chronological audit log",icon:(0,n.jsx)(ni.J,{name:"activity",size:16}),actions:(0,n.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,n.jsx)(ns.HU,{value:h,onChange:m,placeholder:"Filter by teammateâ¦"}),(0,n.jsx)("button",{type:"button",className:"k-iconbtn-xs",onClick:f,disabled:p,"aria-label":"Export CSV",title:"Export CSV",children:(0,n.jsx)(ni.J,{name:"download",size:16})})]}),flush:!0,children:d?(0,n.jsx)(ns.$w,{title:"Couldn't load login history",description:d}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ns.Rm,{loading:o&&0===t.length,rows:x,rowKey:e=>"".concat(e.userId,"-").concat(e.timestamp),emptyTitle:"No logins in this range",emptyDescription:"Pick a different date range or clear filters.",columns:[{key:"timestamp",header:"Timestamp",cell:e=>ns.ZN.date(e.timestamp)},{key:"teammate",header:"Teammate",cell:e=>(0,n.jsx)(ns.V,{name:e.name,email:e.email})}]}),null!==l&&(0,n.jsx)("div",{style:{display:"flex",justifyContent:"center",padding:12},children:(0,n.jsx)(K.Z,{variant:"outlined",color:"primary",size:"sm",onClick:g,disabled:o,children:o?"Loadingâ¦":"Load more"})})]})})};let ng=[{value:"7d",label:"7D"},{value:"14d",label:"14D"},{value:"30d",label:"30D"},{value:"max",label:"MAX"}],nx=["7d","14d","30d","max"],nf={members:"Team members, brands, and workspace-level settings.","team-activity":"What your team is shipping, who's active, and when.","login-history":"Reverse-chronological audit of teammate sign-ins."};var nj=t(72232),ny=t(30465),nb=t(25464),n_=t(96540),nw=t(68673);let nN=e=>{let a=(0,eV.JF)(e);return e.url&&a?"".concat(e.url," | Connected Ad Account: ").concat(null==a?void 0:a.name):e.url?"".concat(e.url):a?"Connected Ad Account: ".concat(a.name):""},nk=e=>e.activeBrand||null,nC=(e,a)=>e.find(e=>e.id===a);var nS=t(50259),nA=e=>{let{open:a,onClose:t,onSubmit:s}=e;return(0,n.jsx)(V.hB,{id:"switch-ad-account-confirm",open:a,onClose:t,onEnter:s,width:440,children:(0,n.jsx)(V.Vq,{onClose:t,title:"Switch active ad account?",subtitle:"This will refresh the page to load the selected ad account.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:t,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:s,children:"Switch Ad Account"})]})})})},nI=t(7958),nP=t(24459),nT=t(46585),nF=t(6707),nE=t(30886),nD=t(42356);t(46413);var nL=t(98456),nM=t(35089);class nR{static displayName(e){return e.accountName||e.brandName}static removedClause(e,a){return e?a?"Removed ".concat(e," by ").concat(a):"Removed ".concat(e):null}static lastUsedClause(e){return e?"Last used ".concat(e):null}static dateLabel(e){if(!e)return null;let a=new Date(e);return Number.isNaN(a.getTime())?null:a.toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"})}static rowLabel(e,a){let t=nR.removedClause(nR.dateLabel(e.removedAt),e.removedBy);return[nR.displayName(e),a,null!=t?t:nR.lastUsedClause(nR.dateLabel(e.lastUsedAt))].filter(
1Boolean).join(" \xb7 ")}static restoreTitle(e){return"Restore ".concat(e,"?")}static restoreSuccess(e){return"".concat(e," is back. You can find it in your ad account switcher.")}}var nZ=e=>{let{accountName:a,onClose:t,onConfirm:s,restoring:i=!1,refusal:l=null}=e;return(0,n.jsx)(V.Vq,{onClose:t,title:nR.restoreTitle(a),footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:t,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:s,loading:i,children:"Restore ad account"})]}),children:(0,n.jsxs)("div",{className:"restore-ad-account",children:[(0,n.jsx)("p",{className:"restore-ad-account__body",children:"This brings the ad account back into Koast with its pages, pixel and settings. Campaigns on the ad provider are not changed â anything paused stays paused until you resume it."}),l&&(0,n.jsx)("p",{className:"restore-ad-account__refusal",children:l})]})})},nz=t(81758);let nO=e=>Array.isArray(null==e?void 0:e.accounts)?e.accounts.map(e=>{var a,t,n,s,i,l;return{brandId:Number(null==e?void 0:e.brandId),brandName:String(null!==(a=null==e?void 0:e.brandName)&&void 0!==a?a:""),accountName:null!==(t=null==e?void 0:e.accountName)&&void 0!==t?t:null,provider:null!==(n=null==e?void 0:e.provider)&&void 0!==n?n:null,removedAt:null!==(s=null==e?void 0:e.removedAt)&&void 0!==s?s:null,removedBy:null!==(i=null==e?void 0:e.removedBy)&&void 0!==i?i:null,lastUsedAt:null!==(l=null==e?void 0:e.lastUsedAt)&&void 0!==l?l:null}}):[],nB=()=>{let{data:e,isLoading:a,mutate:t}=(0,nz.ZP)("/brand/archived",f.handleFetch),[n,i]=(0,s.useState)(null),l=(0,s.useCallback)(async e=>{i(e);let a=await (0,f.handleFetch)("/brand/".concat(e,"/restore"),{method:"POST"});if(i(null),!(null==a?void 0:a.success)){var n,s;return{ok:!1,message:null!==(s=null==a?void 0:null===(n=a.error)||void 0===n?void 0:n.message)&&void 0!==s?s:""}}return await t(),{ok:!0,message:""}},[t]);return{accounts:nO(null==e?void 0:e.data),loading:a,restoring:n,restore:l,refresh:t}},nV=e=>{let{account:a,onRestore:t,disabled:s=!1}=e;return(0,n.jsxs)("div",{className:"info-row archived-row",children:[(0,n.jsx)("div",{className:"info-row__value archived-row__label",children:nR.rowLabel(a,(0,nM.gP)((0,eV.so)(a.provider)))}),(0,n.jsx)("div",{className:"info-row__action",children:(0,n.jsx)("button",{type:"button",className:"linkbtn",onClick:()=>t(a),disabled:s,children:"Restore"})})]})},nK=e=>{let{accounts:a,loading:t=!1,restoring:s=null,onRestore:i}=e;return t?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsx)("div",{className:"info-row archived-row",children:(0,n.jsx)("div",{className:"info-row__value archived-row__loading",children:(0,n.jsx)(nL.Z,{size:16,color:"inherit"})})})}):0===a.length?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsx)("div",{className:"info-row archived-row",children:(0,n.jsx)("div",{className:"info-row__value archived-row__empty",children:"No archived ad accounts. Accounts you remove from Koast appear here so you can bring them back."})})}):(0,n.jsx)("div",{className:"info-card",children:a.map(e=>(0,n.jsx)(nV,{account:e,onRestore:i,disabled:null!==s},e.brandId))})};var nU=e=>{let{onRestored:a}=e,{accounts:t,loading:i,restoring:l,restore:r}=nB(),[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(""),h=()=>{c(null),u("")},m=async()=>{if(!o)return;let{ok:e,message:t}=await r(o.brandId);if(!e){u(t);return}R.ZP.success(nR.restoreSuccess(nR.displayName(o))),null==a||a(o.brandId),h()};return(0,n.jsxs)("div",{className:"archived-ad-accounts",children:[(0,n.jsx)(V.hB,{id:"restore-ad-account-confirm",open:!!o,onClose:h,width:480,children:o&&(0,n.jsx)(nZ,{accountName:nR.displayName(o),onClose:h,onConfirm:m,restoring:l===o.brandId,refusal:d||null})}),(0,n.jsx)("div",{className:"panel-head",children:(0,n.jsx)("h2",{children:"Archived ad accounts"})}),(0,n.jsx)(nK,{accounts:t,loading:i,restoring:l,onRestore:e=>{u(""),c(e)}}),(0,n.jsx)("p",{className:"archived-ad-accounts__note",children:"An archived ad account still exists on the ad provider. Restoring it brings its pages, pixel and settings back into Koast. Anything created in Koast before it was archived comes back with it."})]})};t(51011),t(10799);var nW=t(25554);let nQ=()=>
1{let[e,a]=(0,s.useState)([]),[t,n]=(0,s.useState)(!0),[i,l]=(0,s.useState)(null),[r,o]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[m,p]=(0,s.useReducer)(nW.vJ,nW.cJ),v=(0,s.useCallback)(async()=>{n(!0);let{success:e,data:t,error:s}=await (0,f.handleFetch)(nW.O4);if(n(!1),!e){l((null==s?void 0:s.message)||"We could not load your API keys.");return}l(null),a((0,nW.F5)(t))},[]);(0,s.useEffect)(()=>{v()},[v]);let g=(0,s.useCallback)(async e=>{let a=(0,nW.Ij)(e);o(!0);let{success:t,data:n,error:s}=await (0,f.handleFetch)(nW.O4,{method:"POST",body:a});if(o(!1),!t)return R.ZP.error((null==s?void 0:s.message)||"We could not create that API key."),!1;let i=(0,nW.Ol)(n);return i&&p({type:"reveal",tokenName:a.name,secret:i}),await v(),!0},[v]),x=(0,s.useCallback)(async e=>{d(e.id);let{success:a,error:t}=await (0,f.handleFetch)((0,nW.DI)(e.id),{method:"DELETE"});return(d(null),a)?(R.ZP.success("".concat(e.name," revoked.")),await v(),!0):(R.ZP.error((null==t?void 0:t.message)||"We could not revoke that API key."),!1)},[v]),j=(0,s.useCallback)(async(e,a)=>{h(e.id);let{success:t,error:n}=await (0,f.handleFetch)((0,nW.DI)(e.id),{method:"PATCH",body:{spendCeilingCents:a}});return(h(null),t)?(R.ZP.success(null===a?"".concat(e.name," can no longer publish."):"".concat(e.name," can publish up to ").concat((0,nW.JV)(a),".")),await v(),!0):(R.ZP.error((null==n?void 0:n.message)||"We could not change that publish limit."),!1)},[v]);return{tokens:e,loading:t,error:i,creating:r,revokingId:c,savingCeilingId:u,secretState:m,refresh:v,createToken:g,revokeToken:x,setSpendCeiling:j,dismissSecret:(0,s.useCallback)(()=>p({type:"forget"}),[])}},nH=()=>
1{let[e,a]=(0,s.useState)([]),[t,n]=(0,s.useState)(!0),[i,l]=(0,s.useState)(null),[r,o]=(0,s.useState)(null),c=(0,s.useCallback)(async()=>{n(!0);let{success:e,data:t,error:s}=await (0,f.handleFetch)(nW.Cg);if(n(!1),!e){l((null==s?void 0:s.message)||"We could not load your authorized apps.");return}l(null),a((0,nW.GF)(t))},[]);(0,s.useEffect)(()=>{c()},[c]);let d=(0,s.useCallback)(async e=>{o(e.id);let{success:a,error:t}=await (0,f.handleFetch)((0,nW.aX)(e.id),{method:"DELETE"});return(o(null),a)?(R.ZP.success("".concat(e.clientName," no longer has access.")),await c(),!0):(R.ZP.error((null==t?void 0:t.message)||"We could not revoke that app."),!1)},[c]);return{apps:e,loading:t,error:i,revokingId:r,refresh:c,revokeApp:d}};var nq=e=>{let{tokens:a,revokingId:t,onRevoke:s,onEditCeiling:i}=e;return(0,n.jsx)("div",{className:"api-keys__table-wrap",children:(0,n.jsxs)("table",{className:"api-keys__table",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:"Name"}),(0,n.jsx)("th",{children:"Key"}),(0,n.jsx)("th",{children:"Access"}),(0,n.jsx)("th",{children:"Publish limit"}),(0,n.jsx)("th",{children:"Created"}),(0,n.jsx)("th",{children:"Last used"}),(0,n.jsx)("th",{children:"Expires"}),(0,n.jsx)("th",{children:"Status"}),(0,n.jsx)("th",{"aria-label":"Actions"})]})}),(0,n.jsx)("tbody",{children:a.map(e=>{let a=(0,nW.J1)(e);return(0,n.jsxs)("tr",{className:o()("api-keys__row","--".concat(a)),children:[(0,n.jsx)("td",{className:"api-keys__name",children:e.name}),(0,n.jsx)("td",{className:"api-keys__prefix",children:(0,n.jsx)("code",{children:e.prefix})}),(0,n.jsx)("td",{children:(0,nW.hX)(e.scopes)}),(0,n.jsx)("td",{className:"api-keys__ceiling",children:"revoked"===a?(0,nW.kr)(e):(0,n.jsx)("button",{type:"button",className:"linkbtn api-keys__ceiling-edit",onClick:()=>i(e),children:(0,nW.kr)(e)})}),(0,n.jsx)("td",{children:(0,nW.T4)(e.createdAt)}),(0,n.jsx)("td",{children:(0,nW.T4)(e.lastUsedAt,"Never")}),(0,n.jsx)("td",{children:(0,nW.T4)(e.expiresAt,"No expiry")}),(0,n.jsx)("td",{children:(0,n.jsx)("span",{className:o()("api-keys__status","--".concat(a)),children:nW.UW[a]})}),(0,n.jsx)("td",{className:"api-keys__row-action",children:"revoked"!==a&&(0,n.jsx)("button",{type:"button",className:"linkbtn api-keys__revoke",onClick:()=>s(e),disabled:t===e.id,children:"Revoke"})})]},e.id)})})]})})};let nG={name:"",scopes:[...nW.qU],expiry:"never",spendCeiling:""},nY=e=>{let{draft:a,creating:t,onChange:s,onClose:i,onSubmit:l}=e;return(0,n.jsx)(V.Vq,{onClose:i,title:"Create API key",subtitle:"Use this key to connect an external client to Koast.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:i,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:l,disabled:!(0,nW.mC)(a)||t,loading:t,children:"Create key"})]}),children:(0,n.jsxs)("div",{className:"api-keys__form",children:[(0,n.jsx)(V.gN,{label:"Name",required:!0,htmlFor:"api-key-name",hint:"So you can tell your keys apart later.",children:(0,n.jsx)(V.oi,{id:"api-key-name",value:a.name,placeholder:"Claude Desktop",onChange:e=>s({...a,name:e.target.value})})}),(0,n.jsx)(V.gN,{label:"Access",hint:"Pick the least this client needs.",children:(0,n.jsx)("div",{className:"api-keys__scopes",children:nW.Fw.map(e=>(0,n.jsxs)("label",{className:"api-keys__scope",htmlFor:"api-key-scope-".concat(e),children:[(0,n.jsx)("input",{id:"api-key-scope-".concat(e),type:"checkbox",checked:a.scopes.includes(e),onChange:()=>s({...a,scopes:(0,nW.ki)(a.scopes,e)})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("span",{className:"api-keys__scope-label",children:nW.J7[e]}),(0,n.jsx)("span",{className:"api-keys__scope-hint",children:nW.dO[e]})]})]},e))})}),(0,nW.do)(a)&&(0,n.jsx)(V.gN,{label:"Publish limit",required:!0,htmlFor:"api-key-spend-ceiling",hint:"The most this key may ever put live, in total. Publishing is refused without one.",children:(0,n.jsx)(V.oi,{id:"api-key-spend-ceiling",startAdornment:"$",value:a.spendCeiling,placeholder:"500.00",inputMode:"decimal",onChange:e=>s({...a,spendCeiling:e.target.value})})}),(0,n.jsx)(V.gN,{label:"Expiry",htmlFor:"api-key-expiry",hint:"A key with no expiry works until you revoke it.",children:(0,n.jsx)(V.px,{id:"api-key-expiry",value:a.expiry,onChange:e=>s({...a,expiry:e.target.value}),children:nW.Od.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})})]})})};var nJ=e=>{let{open:a,creating:t,onClose:i,onCreate:l}
1=e,[r,o]=(0,s.useState)(nG);(0,s.useEffect)(()=>{a&&o(nG)},[a]);let c=()=>{(0,nW.mC)(r)&&!t&&l(r)};return(0,n.jsx)(V.hB,{id:"create-api-key",open:a,onClose:i,onEnter:c,width:520,children:(0,n.jsx)(nY,{draft:r,creating:t,onChange:o,onClose:i,onSubmit:c})})};let nX=async e=>{try{await navigator.clipboard.writeText(e),R.ZP.success("Key copied.")}catch(e){R.ZP.error("We could not copy that. Select it and copy manually.")}},n$=e=>{let{secretState:a,onClose:t}=e,{secret:s,tokenName:i}=a;return s?(0,n.jsxs)(V.Vq,{onClose:t,title:"Copy your API key",subtitle:"This is the only time ".concat(i||"this key"," will be shown. Once you close this we cannot show it again."),footer:(0,n.jsx)(V.Qd,{variant:"primary",onClick:t,children:"Done"}),children:[(0,n.jsxs)("div",{className:"api-keys__secret",children:[(0,n.jsx)("code",{className:"api-keys__secret-value",children:s}),(0,n.jsx)(V.Qd,{variant:"secondary",onClick:()=>nX(s),children:"Copy"})]}),(0,n.jsx)("p",{className:"api-keys__secret-note",children:"Store it somewhere safe. If you lose it, create a new key and revoke this one."})]}):null};var n0=e=>{let{secretState:a,onClose:t}=e;return(0,n.jsx)(V.hB,{id:"api-key-secret",open:!!a.secret,onClose:t,width:520,children:(0,n.jsx)(n$,{secretState:a,onClose:t})})};let n1=e=>{let{token:a,revoking:t,onClose:s,onConfirm:i}=e;return(0,n.jsx)(V.Vq,{onClose:s,confirmIcon:"warning",title:"Revoke ".concat(a.name,"?"),subtitle:"Anything still using this key stops working straight away. This cannot be undone.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:s,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",loading:t,onClick:i,children:"Revoke"})]})})};var n2=e=>{let{token:a,revoking:t,onClose:s,onConfirm:i}=e;return a?(0,n.jsx)(V.hB,{id:"revoke-api-key",open:!0,onClose:s,onEnter:t?void 0:i,width:480,children:(0,n.jsx)(n1,{token:a,revoking:t,onClose:s,onConfirm:i})}):null};let n5=e=>{let{token:a,value:t,saving:s,onChange:i,onClose:l,onConfirm:r}=e;return(0,n.jsx)(V.Vq,{onClose:l,title:"Publish limit for ".concat(a.name),subtitle:"The most this key may ever put live, in total. Clear it to stop the key publishing.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:l,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",loading:s,onClick:r,children:"Save limit"})]}),children:(0,n.jsx)("div",{className:"api-keys__form",children:(0,n.jsx)(V.gN,{label:"Limit",htmlFor:"api-key-ceiling-edit",hint:"Already committed: ".concat((0,nW.JV)(a.spendCommittedCents),". A limit below that leaves nothing to publish."),children:(0,n.jsx)(V.oi,{id:"api-key-ceiling-edit",startAdornment:"$",value:t,placeholder:"500.00",inputMode:"decimal",onChange:e=>i(e.target.value)})})})})};var n3=e=>{let{token:a,saving:t,onClose:i,onConfirm:l}
1=e,[r,o]=(0,s.useState)("");if((0,s.useEffect)(()=>{a&&o((0,nW.WR)(a))},[a]),!a)return null;let c=()=>{t||l((0,nW.DH)(r))};return(0,n.jsx)(V.hB,{id:"api-key-spend-ceiling",open:!0,onClose:i,onEnter:c,width:480,children:(0,n.jsx)(n5,{token:a,value:r,saving:t,onChange:o,onClose:i,onConfirm:c})})},n4=e=>{let{apps:a,revokingId:t,onRevoke:s}=e;return(0,n.jsx)("div",{className:"api-keys__table-wrap",children:(0,n.jsxs)("table",{className:"api-keys__table",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{children:"App"}),(0,n.jsx)("th",{children:"Access"}),(0,n.jsx)("th",{children:"Authorized"}),(0,n.jsx)("th",{children:"Last used"}),(0,n.jsx)("th",{"aria-label":"Actions"})]})}),(0,n.jsx)("tbody",{children:a.map(e=>(0,n.jsxs)("tr",{className:"api-keys__row",children:[(0,n.jsx)("td",{className:"api-keys__name",children:e.clientName}),(0,n.jsx)("td",{children:(0,nW.hX)(e.scopes)}),(0,n.jsx)("td",{children:(0,nW.T4)(e.createdAt)}),(0,n.jsx)("td",{children:(0,nW.T4)(e.lastUsedAt,"Never")}),(0,n.jsx)("td",{className:"api-keys__row-action",children:(0,n.jsx)("button",{type:"button",className:"linkbtn api-keys__revoke",onClick:()=>s(e),disabled:t===e.id,children:"Revoke"})})]},e.id))})]})})};let n8=e=>{let{app:a,revoking:t,onClose:s,onConfirm:i}=e;return(0,n.jsx)(V.Vq,{onClose:s,confirmIcon:"warning",title:"Revoke ".concat(a.clientName,"?"),subtitle:"The app loses access straight away and any session it has open stops working. To use it again you will need to connect it again.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:s,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",loading:t,onClick:i,children:"Revoke"})]})})};var n6=e=>{let{app:a,revoking:t,onClose:s,onConfirm:i}=e;return a?(0,n.jsx)(V.hB,{id:"revoke-authorized-app",open:!0,onClose:s,onEnter:t?void 0:i,width:480,children:(0,n.jsx)(n8,{app:a,revoking:t,onClose:s,onConfirm:i})}):null};t(25966);var n9=t(6571),n7=t(16359),se=t(92463),sa=t(61094);let st={Slack:sa.tX.SLACK,RedTrack:sa.tX.REDTRACK,Cometly:sa.tX.COMETLY,Hyros:sa.tX.HYROS},sn={Facebook:"meta",Whop:"whop",TikTok:"tiktok"},ss=(e,a,t,n)=>{let s=sn[e];return s&&n?t&&a===s?"connected":"disconnected":"unknown"},si=(e,a)=>a?e===sa.QK.ACTIVE?"connected":"disconnected":"unknown",sl={connected:"Connected",disconnected:"Not connected",reconnect:"Reconnect",unknown:""};var sr=e=>{let{options:a,initialProvider:t}=e,{connections:i,hasFetched:l}=(0,tT.u)(),{connected:r,provider:c,loading:d}=(0,b.Hq)(),[u,h]=(0,s.useState)(null!=t?t:null),[m,p]=(0,s.useState)(null),[v,g]=(0,s.useState)(null),x=(0,s.useMemo)(()=>a.map(e=>e.name),[a]);(0,s.useEffect)(()=>{let e=!0;return x.includes("Google Drive")&&(0,n7.Hb)().then(a=>{e&&p(!!a.isConnected)}).catch(()=>{e&&p(!1)}),x.includes("Dropbox")&&(0,se.Gj)().then(a=>{e&&g(!!a.isConnected)}).catch(()=>{e&&g(!1)}),()=>{e=!1}},[x]);let f=e=>{var a;let t=st[e];if(t)return si(null===(a=i[t])||void 0===a?void 0:a.status,l);if(sn[e])return ss(e,c,r,!d);switch(e){case"Google Drive":if(null===m)return"unknown";return m?"connected":"disconnected";case"Dropbox":if(null===v)return"unknown";return v?"connected":"disconnected";default:return"unknown"}},j=e=>{h(a=>a===e?null:e)};return(0,n.jsxs)("div",{className:"mobile-integrations",children:[(0,n.jsx)("div",{className:"section__title",children:"Integrations"}),(0,n.jsx)("div",{className:"mobile-integrations__list",children:a.map(e=>{let a=f(e.name),t=u===e.name;return(0,n.jsxs)("div",{className:o()("mint-row",{"--open":t}),children:[(0,n.jsxs)("button",{type:"button",className:"mint-row__head","aria-expanded":t,onClick:()=>j(e.name),children:[(0,n.jsx)("span",{className:"mint-row__logo",children:e.icon}),(0,n.jsxs)("span",{className:"mint-row__main",children:[(0,n.jsx)("span",{className:"mint-row__name",children:e.name}),"unknown"!==a&&(0,n.jsx)("span",{className:o()("mint-row__state","--".concat(a)),children:sl[a]})]}),(0,n.jsx)(n9.Z,{className:"mint-row__chevron"})]}),t&&(0,n.jsx)("div",{className:"mint-row__body",children:e.component})]},e.name)})})]})};let so="Integrations",sc="global-settings",sd=[{name:"General",options:[{name:"Account",component:(0,n.jsx)(A.Z,{inModal:!0}),icon:(0,n.jsx)(u.Z,{})},{name:"Ad Accounts",component:(0,n.jsx)(()=>{let{brands:e,loading:a,mutate:t}=(0,nj.Nn)(),{user:i,openSettingsModal:l,showSettingsModal:r}=(0,c.bp)(),{current:o,refetch:d}=(0,ec.jJ)("meta"),u=(0,az.nf)((0,eV.Qy)(null==i?void 0:i.activeBrand),(0,eV.Ip)(null==i?void 0:i.activeBrand)),[h,m]=(0,s.use
1State)(void 0),[p,v]=(0,s.useState)(!1),[g,x]=(0,s.useState)(!1),[j,y]=(0,s.useState)(!1),[_,w]=(0,s.useState)(null),[N,k]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),[A,I]=(0,s.useState)(null),P=(0,eu.Xm)(o),{limits:T}=(0,tM.w)(),F=(0,s.useMemo)(()=>nk(i),[i]);(0,s.useEffect)(()=>{(async()=>{let{data:e=0}=await (0,f.handleFetch)("/brand/count");S(e)})()},[e]);let E=(0,s.useMemo)(()=>(0,nD.F)(C,T.brandsLimit),[C,T.brandsLimit]),D=(0,nD.P)(T.brandsLimit),L=a=>{let t=nC(e,a);t&&(y(!0),m(t),v(!0))},M=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;y(!1),m(void 0),I(e),v(!0)},{setPendingProvider:Z}=(0,nF.h)({current:o,refetch:d,settingsOpen:r,onConnected:M}),z=e=>{if(w(null),!e.connected){Z(e.id),l((0,b.IL)(e.id));return}M(e.id)},O=a=>{m(nC(e,a)),x(!0)},B=async()=>{if(!(null==h?void 0:h.id))return;let{success:e,error:a}=await (0,nS.W)(h.id);if(x(!1),!e){R.ZP.error((null==a?void 0:a.message)||"Failed to change Ad Account. Please try again.");return}R.ZP.success("Ad Account change successful! The page will refresh to reflect the new changes.",{duration:1e3}),setTimeout(()=>{window.location.reload()},500)},V=async e=>{await (0,nS.W)(e),R.ZP.success("Ad Account added! The page will refresh to reflect the new changes.",{duration:1e3}),setTimeout(()=>{window.location.reload()},500)};return(0,n.jsxs)("div",{className:"brand-settings-container",children:[(0,n.jsx)(nw.Z,{open:p,onClose:()=>v(!1),onSubmit:j?B:V,editMode:j,brand:h,provider:A}),(0,n.jsx)(nP.ZP,{open:N,onClose:()=>k(!1),onProvisioned:e=>{let{brandId:a}=e;return(0,nS.W)(a)}}),(0,n.jsx)(nA,{open:g,onClose:()=>x(!1),onSubmit:B}),(0,n.jsxs)("div",{className:"panel-head panel-head--with-action",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{style:{display:"flex",alignItems:"center",gap:8},children:["Ad Accounts",(0,n.jsx)(nI.Z,{})]}),(0,n.jsx)("p",{children:"Connect and manage the ad accounts linked to this workspace."})]}),(0,n.jsx)(tF.Z,{title:D,disabled:E,children:(0,n.jsxs)("button",{type:"button",className:"brand-create-btn",onClick:e=>w(e.currentTarget),children:[(0,n.jsx)(n_.Z,{fontSize:"small"}),"Add ad account"]})})]}),u.isProviderManaged&&(0,n.jsxs)("div",{className:"brand-page-identity",children:[(0,n.jsx)("h3",{className:"brand-page-identity__title",children:"Facebook Page"}),(0,n.jsx)("p",{className:"brand-page-identity__hint",children:"The page your ads run from. Set it up here whenever you like, including after skipping it during setup."}),(0,n.jsx)(nT.vA,{accountId:u.accountId,onCreated:u.refetch,compact:!0})]}),(0,n.jsxs)(nb.Z,{anchorEl:_,open:!!_,onClose:()=>w(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[P.map(e=>(0,n.jsxs)(tq.Z,{onClick:()=>z(e),className:"brand-add-menu__item",disabled:!E,children:[(0,n.jsx)(nE.Z,{provider:e.id,className:"brand-add-menu__item-icon"}),(0,eu.WF)(e,P.length)]},e.id)),(0,n.jsxs)(tq.Z,{onClick:()=>{w(null),k(!0)},className:"brand-add-menu__item",disabled:!E,children:[(0,n.jsx)("img",{src:"/svgs/koast-k-icon.svg",alt:"",width:15,height:15,className:"brand-add-menu__item-icon"}),"Create new ad account"]})]}),a?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Loadingâ¦"}),(0,n.jsx)("div",{className:"info-row__value"}),(0,n.jsx)("div",{className:"info-row__action"})]})}):e&&0!==e.length?(0,n.jsx)("div",{className:"info-card",children:e.map(e=>{let a=e.id===(null==F?void 0:F.id),t=nN(e);return(0,n.jsxs)("div",{className:"info-row brand-row",children:[(0,n.jsxs)("div",{className:"info-row__label brand-row__name",children:[(0,n.jsx)(tF.Z,{title:"Switch ad account",disabled:!1,children:(0,n.jsx)(ny.Z,{size:"small",checked:a,onClick:()=>O(e.id),sx:{padding:"4px",marginRight:"4px"}})}),(0,n.jsx)("span",{children:e.name})]}),(0,n.jsxs)("div",{className:"info-row__value",children:[t||(0,n.jsx)("span",{style:{color:"var(--k-text-3)"},children:"No details"}),a&&(0,n.jsx)("div",{className:"secondary",children:"Currently active"})]}),(0,n.jsx)("div",{className:"info-row__action",children:(0,n.jsx)("button",{type:"button",className:"linkbtn",onClick:()=>L(e.id),children:"Edit"})})]},e.id)})}):(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"No ad accounts"}),(0,n.jsx)("div",{className:"info-row__value",children:(0,n.jsx)("span",{style:{color:"var(--k-text-3)"},children:"Create your first ad account to get started."})}),(0,n.jsx)("div",{className:"info-row__action"})]})}),(0,n.jsx)(nU,{onRestored:()=>t()})]})},{}),icon:(0,n.jsx)(h.Z,{})},{name:"Pixel",component:(0,n.jsx)(()=>{var e,a;let{user:t}
1=(0,c.bp)(),[i,l]=(0,s.useState)(null),[r,o]=(0,s.useState)(!1),d=(0,s.useRef)(!1),[u,h]=(0,s.useState)(null),[m,p]=(0,s.useState)(""),[v,g]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),j=(0,s.useRef)(null),{status:y,hasFetched:b,checking:_,error:w,supported:N,read:k,verify:C}=(0,eB.c)(),S=(0,eV.Qy)(null==t?void 0:t.activeBrand),{verifiableEvents:A,testFireEvents:I,loading:P}=(0,eU.B)(S);(0,s.useEffect)(()=>()=>{j.current&&clearTimeout(j.current)},[]);let{keys:T,creating:F,error:E,create:D,atLimit:L}=eK();if((0,s.useEffect)(()=>{b&&!d.current&&(d.current=!0,l((0,ac.pc)(y)))},[b,y]),(0,s.useEffect)(()=>{if(!N)return;let e=()=>{"visible"===document.visibilityState&&k(void 0,!0)},a=setInterval(e,15e3);return document.addEventListener("visibilitychange",e),window.addEventListener("focus",e),()=>{clearInterval(a),document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",e)}},[N,k]),(0,s.useEffect)(()=>{r&&0!==I.length&&(0,ac.yw)(y,I)===I.length&&o(!1)},[r,y,I]),!N)return(0,n.jsx)("div",{className:"pixel-panel__unsupported",children:"Pixel measurement is reported by the ad platform this account runs on. This account does not report one."});if(!b||P)return(0,n.jsx)(U.DP,{});let M=(0,ac.Mm)(y,w),Z=au[M.tone],z=(0,ac.bO)(y),O=(0,ac.Sm)(y),B=(0,ac.yw)(y,A),V=(0,ac.xf)(y,A),K=(0,ai.dL)(A),W=(0,eq.VJ)(null!=S?S:""),Q=null!==(a=null==y?void 0:y.url)&&void 0!==a?a:"",H=null!=u?u:Q,q=H.trim(),G=Math.max(4,O/3*100),Y=async(e,a)=>{if(!e){R.Am.error("We do not know this ad account yet, so there is nothing to copy.");return}try{await navigator.clipboard.writeText(e),R.Am.success(a)}catch(e){R.Am.error("We could not copy that. Select it and copy manually.")}},J=e=>l(a=>a===e?null:e),X=e=>{j.current&&clearTimeout(j.current),j.current=setTimeout(()=>l(e),1e3)},$=async()=>{await Y(W,"Snippet copied."),W&&X(2)},ee=async()=>{let e=(0,eq.S4)(null!=S?S:"",(0,ai.qZ)(A));await Y(e,"Prompt copied. Paste it into your agent."),e&&X(2)},ea=async()=>{let e=await C(q);(null==e?void 0:e.installed)&&X(3)},et=async()=>{let e=(0,eq.o$)(null!=S?S:"",(0,ai.qZ)(I));await Y(e,"Copied. Paste it in the console on a page that has the snippet."),e&&o(!0)},en=async()=>{let e=await D(m.trim());e&&(g(e.secret),p(""))},es=e=>{var a;let t=null===(a=z[e])||void 0===a?void 0:a.done;return"pixel-panel__step-number".concat(t?" pixel-panel__step-number--done":"").concat(i!==e+1||t?"":" pixel-panel__step-number--active")};return(0,n.jsxs)("div",{className:"pixel-panel",children:[(0,n.jsxs)("div",{className:"pixel-panel__status",children:[(0,n.jsx)("span",{className:"pixel-panel__status-icon pixel-panel__status-icon--".concat(M.tone),children:(0,n.jsx)(Z,{fontSize:"inherit"})}),(0,n.jsxs)("div",{className:"pixel-panel__status-body",children:[(0,n.jsx)("div",{className:"pixel-panel__status-title",children:M.headline}),(0,n.jsx)("div",{className:"pixel-panel__status-detail",children:M.detail})]}),(0,n.jsxs)("button",{type:"button",className:"pixel-panel__ghost",onClick:()=>{k()},disabled:_,children:[(0,n.jsx)(eQ.Z,{fontSize:"small"}),(0,n.jsx)("span",{children:_?"Checking...":"Re-check"})]})]}),(0,n.jsxs)("div",{className:"pixel-panel__progress",children:[(0,n.jsx)("span",{className:"pixel-panel__progress-label",children:"Setup"}),(0,n.jsx)("span",{className:"pixel-panel__progress-track",children:(0,n.jsx)("span",{className:"pixel-panel__progress-fill",style:{width:"".concat(G,"%")}})}),(0,n.jsxs)("span",{className:"pixel-panel__progress-count",children:[O," of ",3," done"]})]}),(0,n.jsxs)("div",{className:"pixel-panel__steps",children:[(0,n.jsxs)("div",{className:"pixel-panel__step",children:[(0,n.jsxs)("div",{className:"pixel-panel__step-rail",children:[(0,n.jsx)("span",{className:es(0),children:"1"}),(0,n.jsx)("span",{className:"pixel-panel__step-line"})]}),(0,n.jsxs)("div",{className:"pixel-panel__step-body",children:[(0,n.jsx)("div",{className:"pixel-panel__step-head",onClick:()=>J(1),children:(0,n.jsxs)("div",{className:"pixel-panel__step-heading",children:[(0,n.jsx)("div",{className:"pixel-panel__step-title",children:"Add the snippet to your site"}),(0,n.jsxs)("div",{className:"pixel-panel__step-detail",children:["Paste it into the ",(0,n.jsx)("span",{className:"pixel-panel__mono",children:"<head>"})," of every page in the funnel, before any other script."]})]})}),1===i&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"pixel-panel__snippet",children:[(0,n.jsx)("code",{className:"pixel-panel__snippet-code",children:W}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__snippet-copy",onClick:()=>{$()},children:"Copy"})]}),(0,n.jsxs)("div",{className:"pixel-panel__snippet-actions",children:[(0,n.jsxs)("button",{type:"button",className:"pixel-panel__ghost pixel-panel__ghost--agents",onClick:()=>{ee()},children:[(0,n.jsx)(eG,{}),(0,n.jsx)("span",{children:"Copy prompt for your AI agent"})]}),(0,n.jsxs)("span",{className:"pixel-panel__account",children:["Ad account ",(0,n.jsx)("code",{children:null!=S?S:"not connected"})]})]})]})]})]}),(0,n.jsxs)("div",{className:"pixel-panel__step",children:[(0,n.jsxs)("div",{className:"pixel-panel__step-rail",children:[(0,n.jsx)("span",{className:es(1),children:"2"}),(0,n.jsx)("span",{className:"pixel-panel__step-line"})]}),(0,n.jsxs)("div",{className:"pixel-panel__step-body",children:[(0,n.jsxs)("div",{className:"pixel-panel__step-head",onClick:()=>J(2),children:[(0,n.jsxs)("div",{className:"pixel-panel__step-heading",children:[(0,n.jsx)("div",{className:"pixel-panel__step-title pixel-panel__step-title--muted",children:"Verify a live page"}),(0,n.jsx)("div",{className:"pixel-panel__step-detail pixel-panel__step-detail--muted",children:"We load the URL and look for the snippet."})]}),(0,n.jsx)("span",{className:"pixel-panel__step-aside",children:(null===(e=z[1])||void 0===e?void 0:e.done)?"Verified":"Not verified"})]}),2===i&&(0,n.jsxs)("div",{className:"pixel-panel__row",children:[(0,n.jsx)("input",{className:"pixel-panel__input",placeholder:"https://your-site.com/checkout",value:H,onChange:e=>h(e.target.value)}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__primary",onClick:()=>{ea()},disabled:(0,ad.Q7)(_,q),children:_?"Checking...":"Check page"})]})]})]}),(0,n.jsxs)("div",{className:"pixel-panel__step",children:[(0,n.jsx)("div",{className:"pixel-panel__step-rail",children:(0,n.jsx)("span",{className:es(2),
1children:"3"})}),(0,n.jsxs)("div",{className:"pixel-panel__step-body pixel-panel__step-body--last",children:[(0,n.jsxs)("div",{className:"pixel-panel__step-head",onClick:()=>J(3),children:[(0,n.jsxs)("div",{className:"pixel-panel__step-heading",children:[(0,n.jsx)("div",{className:"pixel-panel__step-title pixel-panel__step-title--muted",children:"Send conversion events"}),(0,n.jsx)("div",{className:"pixel-panel__step-detail pixel-panel__step-detail--muted",children:"Fire the matching event at each funnel step."})]}),(0,n.jsxs)("span",{className:"pixel-panel__step-aside",children:[B," of ",A.length," detected"]})]}),3===i&&(0,n.jsxs)("div",{className:"pixel-panel__events",children:[V.map(e=>(0,n.jsxs)("div",{className:"pixel-panel__event",children:[(0,n.jsx)("span",{className:"pixel-panel__event-dot".concat("never"===e.state?"":" pixel-panel__event-dot--".concat(e.state))}),(0,n.jsx)("span",{className:"pixel-panel__event-label",children:e.label}),(0,n.jsx)("span",{className:"pixel-panel__event-name",children:e.event})]},e.event)),(0,n.jsx)("div",{className:"pixel-panel__event-hint",children:(0,n.jsxs)("span",{children:["Fire with ",(0,n.jsx)("code",{children:'whop.track("lead")'})]})}),K&&(0,n.jsx)("div",{className:"pixel-panel__event-hint",children:(0,n.jsxs)("span",{children:["Fire ",(0,n.jsx)("code",{children:"purchase"})," only for sales on your own checkout. Whop already tracks its own."]})}),(0,n.jsxs)("div",{className:"pixel-panel__event-actions",children:[(0,n.jsxs)("button",{type:"button",className:"pixel-panel__soft",onClick:()=>{et()},children:["Copy a snippet that fires ",I.length," of them"]}),(0,n.jsx)("span",{className:"pixel-panel__note pixel-panel__note--inline",children:r?"Watching for them to arrive on ".concat(null!=S?S:"this account",". Whop takes a few minutes to count an event; this panel updates on its own."):"Paste it in your browser console on any page carrying the snippet. It scopes the events to ".concat(null!=S?S:"this ad account",", and they count as real conversions there.")})]})]})]})]})]}),(0,n.jsxs)("div",{className:"pixel-panel__server",children:[(0,n.jsxs)("div",{className:"pixel-panel__server-head",children:[(0,n.jsxs)("div",{className:"pixel-panel__step-heading",children:[(0,n.jsxs)("div",{className:"pixel-panel__server-title",children:["Server-side tracking ",(0,n.jsx)("span",{children:"Optional"})]}),(0,n.jsxs)("div",{className:"pixel-panel__server-detail",children:["Count the sales that ad blockers and cookie rules hide. ",T.length," of ",3," keys created."]})]}),(0,n.jsxs)("div",{className:"pixel-panel__server-actions",children:[(0,n.jsxs)("button",{type:"button",className:"pixel-panel__ghost",onClick:()=>{Y(ao(null!=S?S:"",(0,ai.qZ)(A)),"API instructions copied.")},children:[(0,n.jsx)(eH.Z,{fontSize:"small"}),(0,n.jsx)("span",{children:"API instructions"})]}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__soft",onClick:()=>f(!x),children:"Create key"})]})]}),x&&(0,n.jsxs)("div",{className:"pixel-panel__keys",children:[v&&(0,n.jsxs)("div",{className:"pixel-panel__reveal",children:[(0,n.jsxs)("div",{className:"pixel-panel__reveal-title",children:["New key ",(0,n.jsx)("span",{children:"â shown once, copy it now."})]}),(0,n.jsxs)("div",{className:"pixel-panel__reveal-row",children:[(0,n.jsx)("code",{className:"pixel-panel__reveal-secret",children:v}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__reveal-copy",onClick:()=>{Y(v,"Key copied.")},children:"Copy key"}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__reveal-dismiss",onClick:()=>g(null),children:"I saved it"})]})]}),T.map(e=>(0,n.jsxs)("div",{className:"pixel-panel__key",children:[(0,n.jsx)("span",{className:"pixel-panel__key-name",children:e.name}),(0,n.jsx)("span",{className:"pixel-panel__key-prefix",children:e.prefix}),(0,n.jsx)("span",{className:"pixel-panel__key-badge",children:"Active"})]},e.id)),(0,n.jsxs)("div",{className:"pixel-panel__row",children:[(0,n.jsx)("input",{className:"pixel-panel__input",placeholder:"Key name, for example Checkout server",value:m,onChange:e=>p(e.target.value),disabled:L}),(0,n.jsx)("button",{type:"button",className:"pixel-panel__primary",onClick:()=>{en()},disabled:F||L||m.trim().length<2,children:F?"Creating...":"Create key"})]}),E&&(0,n.jsx)("div",{className:"pixel-panel__note",children:E}),(0,n.jsx)("div",{className:"pixel-panel__note",children:L?"You have used all ".concat(3," keys for this ad account. Ke
1ys cannot be deleted from Koast yet, so contact support if you need another."):"Up to ".concat(3," keys per ad account. A key works only for this ad account and can only send conversions.")})]})]}),(0,n.jsx)(as,{accountId:null!=S?S:null})]})},{}),icon:(0,n.jsx)(m.Z,{})},{name:"Audiences",component:(0,n.jsx)(()=>{let{user:e}=(0,c.bp)(),a=(0,eV.Qy)(null==e?void 0:e.activeBrand),t=aR(a),i=(0,aZ.C)(a),l=(0,az.nf)(a,t.provider),[r,o]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(null),[v,g]=(0,s.useState)(""),[x,f]=(0,s.useState)(null),j=(0,s.useMemo)(()=>l.selectableOptions.map(e=>({id:e.id,name:e.name,kind:e.kind})),[l.selectableOptions]);if(t.capabilitiesLoading)return(0,n.jsx)(U.DP,{});if(!t.isProviderManaged)return(0,n.jsx)("div",{className:"audience-manager__unsupported",children:"Audiences are built on the ad platform this account runs on. This account manages them in its own ads manager."});if(!t.hasFetched)return(0,n.jsx)(U.DP,{});let y=function(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;u(a),o(e)},b=()=>{o(null),u(null)},_=e=>{m(e.id),g(e.name)},w=async e=>{let a=v.trim();if(!a||a===e.name){m(null);return}await t.updateAudience(e.id,{name:a})&&(R.Am.success("Renamed to ".concat(a,".")),m(null))},N=async e=>{let a=await t.deleteAudience(e.id);f(null),a&&R.Am.success("Deleted ".concat(e.name,". Ad sets that used it keep running without it."))},k=e=>{let a=aj(e.status),s=a_(e.matchRates),i=t.busy===e.id,l=h===e.id,r=x===e.id;return(0,n.jsxs)("div",{className:"audience-manager__row",children:[(0,n.jsxs)("div",{className:"audience-manager__cell audience-manager__cell--name",children:[(0,n.jsx)("span",{className:"audience-manager__dot audience-manager__dot--".concat(a)}),(0,n.jsxs)("div",{className:"audience-manager__names",children:[l?(0,n.jsxs)("span",{className:"audience-manager__rename",children:[(0,n.jsx)("input",{className:"koast-input",value:v,onChange:e=>g(e.target.value),onKeyDown:a=>{"Enter"===a.key&&w(e),"Escape"===a.key&&m(null)}}),(0,n.jsx)("button",{type:"button",className:"audience-manager__soft",onClick:()=>{w(e)},disabled:i,children:"Save"}),(0,n.jsx)("button",{type:"button",className:"audience-manager__ghost",onClick:()=>m(null),children:"Cancel"})]}):(0,n.jsx)("span",{className:"audience-manager__label",children:e.name}),(0,n.jsxs)("span",{className:"audience-manager__meta",children:["lookalike"===e.audienceType?"Lookalike":ax[e.sourceType],e.autoRefresh?" \xb7 auto-refresh":"",t_(e)]})]})]}),(0,n.jsxs)("div",{className:"audience-manager__cell audience-manager__cell--status",children:[(0,n.jsx)("span",{className:"audience-manager__status audience-manager__status--".concat(a),children:ab(e)}),s&&(0,n.jsx)("span",{className:"audience-manager__match",children:s}),e.errorMessage&&(0,n.jsx)("span",{className:"audience-manager__error-text",children:e.errorMessage})]}),(0,n.jsxs)("div",{className:"audience-manager__cell audience-manager__cell--actions",children:[(0,n.jsx)(T.Z,{title:tb(e),children:(0,n.jsx)("span",{className:"audience-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"audience-manager__icon",onClick:()=>y("lookalike",e),disabled:!aw(e)||i,children:(0,n.jsx)(p.Z,{fontSize:"inherit"})})})}),(0,n.jsx)(T.Z,{title:aN(e)?"Add people from another CSV":"Only an uploaded list that has finished processing can take more people.",children:(0,n.jsx)("span",{className:"audience-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"audience-manager__icon",onClick:()=>y("addPeople",e),disabled:!aN(e)||i,children:(0,n.jsx)(ah.Z,{fontSize:"inherit"})})})}),(0,n.jsx)(T.Z,{title:ak(e)?"Edit the People filters":"Rename",children:(0,n.jsx)("span",{className:"audience-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"audience-manager__icon",onClick:()=>ak(e)?y("filters",e):_(e),disabled:i,children:(0,n.jsx)(eJ.Z,{fontSize:"inherit"})})})}),r?(0,n.jsxs)("span",{className:"audience-manager__confirm",children:[(0,n.jsx)("span",{children:"Delete?"}),(0,n.jsx)("button",{type:"button",className:"audience-manager__danger",onClick:()=>{N(e)},disabled:i,children:"Yes, delete"}),(0,n.jsx)("button",{type:"button",className:"audience-manager__ghost",onClick:()=>f(null),children:"Keep"})]}
1):(0,n.jsx)(T.Z,{title:"Delete this audience",children:(0,n.jsx)("span",{className:"audience-manager__icon-wrap",children:(0,n.jsx)("button",{type:"button",className:"audience-manager__icon audience-manager__icon--danger",onClick:()=>f(e.id),disabled:i,children:(0,n.jsx)(eX.Z,{fontSize:"inherit"})})})})]})]},e.id)},C=t.audiences.filter(e=>"custom"===e.audienceType),S=t.audiences.filter(e=>"lookalike"===e.audienceType);return(0,n.jsxs)("div",{className:"audience-manager",children:[(0,n.jsxs)("div",{className:"audience-manager__head",children:[(0,n.jsxs)("div",{className:"audience-manager__heading",children:[(0,n.jsx)("div",{className:"audience-manager__title",children:"Audiences"}),(0,n.jsxs)("div",{className:"audience-manager__detail",children:["Custom and lookalike audiences on ",null!=a?a:"this ad account",": where they stand, how well they matched, and the tools to build more."]})]}),(0,n.jsxs)("div",{className:"audience-manager__controls",children:[(0,n.jsxs)("button",{type:"button",className:"audience-manager__ghost",onClick:()=>{t.refetch()},disabled:t.loading,children:[(0,n.jsx)(eQ.Z,{fontSize:"small"}),(0,n.jsx)("span",{children:t.loading?"Reading...":"Refresh"})]}),i.canCreate&&(0,n.jsxs)("button",{type:"button",className:"audience-manager__ghost",onClick:()=>y("upload"),children:[(0,n.jsx)(am.Z,{fontSize:"small"}),(0,n.jsx)("span",{children:"Upload a list"})]}),(0,n.jsx)("button",{type:"button",className:"audience-manager__soft",onClick:()=>y("filters"),disabled:!t.supported,children:"From your People"}),(0,n.jsx)("button",{type:"button",className:"audience-manager__soft",onClick:()=>y("engagement"),disabled:!t.supported,children:"From engagement"})]})]}),t.error&&(0,n.jsx)("div",{className:"audience-manager__note audience-manager__note--problem",children:t.error}
1),!t.supported&&(0,n.jsx)("div",{className:"audience-manager__note",children:"This ad account's platform lists audiences but builds them in its own ads manager; upload a list here, and build the rest there."}),t.supported&&0===t.audiences.length&&(0,n.jsx)("div",{className:"audience-manager__note",children:"No audiences yet. Upload a customer list, build one from the people your pixel has seen, or from engagement with your pages and videos."}),C.length>0&&(0,n.jsxs)("div",{className:"audience-manager__group",children:[(0,n.jsxs)("div",{className:"audience-manager__group-title",children:["Custom audiences ",(0,n.jsx)("span",{children:C.length})]}),(0,n.jsx)("div",{className:"audience-manager__rows",children:C.map(k)})]}),S.length>0&&(0,n.jsxs)("div",{className:"audience-manager__group",children:[(0,n.jsxs)("div",{className:"audience-manager__group-title",children:["Lookalikes ",(0,n.jsx)("span",{children:S.length})]}),(0,n.jsx)("div",{className:"audience-manager__rows",children:S.map(k)})]}),(0,n.jsx)("div",{className:"audience-manager__legend",children:["pending","processing","syncing","ready","partial","failed"].map(e=>(0,n.jsxs)("span",{className:"audience-manager__legend-item",children:[(0,n.jsx)("span",{className:"audience-manager__dot audience-manager__dot--".concat(aj(e))}),af[e]]},e))}),(0,n.jsx)(aO.Uf,{open:"upload"===r,provider:t.provider,accountId:null!=a?a:null,creation:i.creation,onClose:b,onCreated:()=>{R.Am.success("Building the audience from your list. It appears below and updates on its own."),t.refetch(!0),i.refetch()}}),(0,n.jsx)(tj,{open:"filters"===r,provider:t.provider,accountId:null!=a?a:null,editing:d,saving:"create"===t.busy||null!==d&&t.busy===d.id,onClose:b,onCreate:async e=>{let a=await t.createFilterAudience(e);return a&&R.Am.success("Building ".concat(a.name," from your People. It updates below as it processes.")),a},onUpdate:async(e,a)=>{let n=await t.updateAudience(e,a);return n&&R.Am.success("Filters replaced. The audience is rebuilding now."),n}}),(0,n.jsx)(tv,{open:"engagement"===r,provider:t.provider,accountId:null!=a?a:null,saving:"create"===t.busy,socialAccounts:j,onClose:b,onCreate:async e=>{let a=await t.createEngagementAudience(e);return a&&R.Am.success("Building ".concat(a.name,". The ad platform fills it in as people engage.")),a}}),(0,n.jsx)(ty,{open:"lookalike"===r,source:d,saving:"lookalike"===t.busy,onClose:b,onCreate:async e=>{let a=await t.createLookalikes(e);return a&&R.Am.success("Building ".concat(1===a.length?"a lookalike":"".concat(a.length," lookalikes"),". They appear below as they process.")),a}}),(0,n.jsx)(aK,{open:"addPeople"===r,audience:d,maxFileBytes:i.creation.maxFileBytes,saving:null!==d&&t.busy===d.id,onClose:b,onAdd:async(e,a)=>{let n=await t.addPeople(e,a);return n&&R.Am.success("Adding those people. Existing members stay; the count updates as it processes."),n}})]})},{}),icon:(0,n.jsx)(p.Z,{})},{name:"Organization",component:(0,n.jsx)(()=>{var e,a,t,l;let{user:r}=(0,c.bp)(),[o,d]=(0,s.useState)({}),[u,h]=(0,s.useState)(!1),[m,p]=(0,s.useState)(!1),[v,g]=(0,s.useState)(nn),[x,j]=(0,s.useState)([]),[b,_]=(0,s.useState)(!1),{limits:w}=(0,tM.w)(),N=(0,y.om)(),k=(0,y.pn)(),C=N||k,[S,A]=(0,s.useState)({preset:"30d"}),I=(0,s.useCallback)(e=>{A("custom"===e?{preset:"custom"}:{preset:e})},[]),[P,T]=(0,s.useState)("members"),F="members"===P||C?P:"members",E="team-activity"===F||"login-history"===F,D=(0,i.Z)("(max-width:768px)"),[L,M]=(0,s.useState)(!1),R=(0,s.useCallback)(e=>{I(e),M(!0),window.setTimeout(()=>M(!1),420)},[I]),Z=(0,s.useMemo)(()=>{var e;return(null==o?void 0:null===(e=o.users)||void 0===e?void 0:e.length)||0},[o]),z=(0,s.useMemo)(()=>(null==o?void 0:o.admins)&&(null==o?void 0:o.admins)||[],[o]),O=(0,s.useMemo)(()=>N,[N]),B=w.usersLimit||1,V=w.brandsLimit||1,K=Math.max(B-Z,0),U=null!==(t=null==r?void 0:null===(e=r.allowedBrands)||void 0===e?void 0:e.length)&&void 0!==t?t:0,W=(0,s.useMemo)(()=>Z>=B||!O,[Z,B,O]),Q=(0,s.useMemo)(()=>O?"You have reached your organization's user limit.":"Must be an admin to invite new users.",[O]),H=(0,s.useMemo)(()=>{let e=null==o?void 0:o.users;return e?e.sort((e,a)=>{let t=z.find(a=>a.id===e.id),n=z.find(e=>e.id===a.id);return t&&!n?-1:!t&&n?1:0}).map(e=>{var a;let t=z.find(a=>a.id===e.id),n=null===(a=e.roles)||void 0===a?void 0:a.some(e=>"ADMIN"===e.name.toUpperCase());return{...e,isSuperAdmin:!!t,isOrgAdmin:!!t||n}}):[]},[null==o?void 0:o.users,z]);(0,s.useEffect)(()=>{q()},[]),(0,s.useEffect)(()=>{G()},[b]);let q=async()=>{let{success:e,data:a}=await (0,f.handleFetch)("/organization/roles");e&&j(a)},G=async()=>{let{data:e}=await (0,f.handleFetch)("/organization/current");d(e)},Y=()=>{h(!u)},J=e=>{e&&g(e),p(!m)},X=()=>{_(e=>!e)},$=(null==o?void 0:o.name)||(null==r?void 0:null===(a=r.activeBrand)||void 0===a?void 0:a.name)||"â",ee=E?(0,n.jsx)("div",{className:"organization-settings__filter ".concat(L?"is-refetching":""),children:(0,n.jsx)(ns.lK,{value:(l=S.preset,nx.includes(l)?l:"30d"),options:ng,onChange:R})}):null;return(0,n.jsxs)("div",{className:"organization-settings-container",children:[(0,n.jsxs)("div",{className:"panel-head organization-settings__panel-head",children:[(0,n.jsxs)("div",{className:"organization-settings__panel-head-text",children:[(0,n.jsx)("h2",{children:"Organization"}),(0,n.jsx)("p",{children:nf[F]})]}),!D&&ee]}),(0,n.jsxs)(tD.Z,{value:F,onChange:(e,a)=>T(a),className:"organization-settings__tabs",children:[(0,n.jsx)(tL.Z,{label:"Members",value:"members"}),C&&(0,n.jsx)(tL.Z,{label:"Team Activity",value:"team-activity"}),C&&(0,n.jsx)(tL.Z,{label:"Login History",value:"login-history"})]}),D&&ee,u&&(0,n.jsx)(t4,{open:u,onClose:Y,currentOrganization:o,roles:x,userLimit:B,numCurrUsers:Z,refetch:X}),m&&(0,n.jsx)(nt,{open:m,onClose:J,currentOrganization:o,selectedUser:v,roles:x,refetch:X}),"members"===F&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"info-card",children:[(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Worksp
1ace name"}),(0,n.jsx)("div",{className:"info-row__value",children:$}),(0,n.jsx)("div",{className:"info-row__action"})]}),(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Members"}),(0,n.jsxs)("div",{className:"info-row__value",children:[Z," member",1!==Z?"s":"",K>0&&" \xb7 ".concat(K," seat").concat(1!==K?"s":""," available")]}),(0,n.jsx)("div",{className:"info-row__action",children:(0,n.jsx)(tF.Z,{title:Q,disabled:!W,children:(0,n.jsx)("button",{type:"button",className:"linkbtn",onClick:Y,disabled:W,children:"Invite"})})})]}),(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Brands"}),(0,n.jsxs)("div",{className:"info-row__value",children:[U," of ",V," used"]}),(0,n.jsx)("div",{className:"info-row__action"})]})]}),(0,n.jsxs)("div",{className:"section",children:[(0,n.jsx)("div",{className:"sec-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{children:"Team members"}),(0,n.jsx)("p",{children:"Manage who has access to this workspace and their permissions."})]})}),(0,n.jsx)("div",{className:"organization-settings__grid",children:(0,n.jsx)(tQ,{organizationUsers:H,userLimit:B,toggleAddUserModal:Y,toggleEditUserPermissionsModal:J,isCurrentUserAdmin:O,isCurrentUserSuperAdmin:k,currentUser:r,showToolbar:!1})})]})]}),"team-activity"===F&&C&&(0,n.jsx)("div",{className:"organization-settings__team-activity admin-shell",children:(0,n.jsx)(np,{range:S})}),"login-history"===F&&C&&(0,n.jsx)("div",{className:"organization-settings__team-activity admin-shell",children:(0,n.jsx)(nv,{range:S})})]})},{}),icon:(0,n.jsx)(v.Z,{}),hideIfNonAdmin:!0},{name:"Billing",component:(0,n.jsx)(I.Z,{}),icon:(0,n.jsx)(g.Z,{}),hideIfAppSumo:!0,hideIfNonSuperAdmin:!0},{name:"API Keys",component:(0,n.jsx)(()=>{let{tokens:e,loading:a,error:t,creating:i,revokingId:l,savingCeilingId:r,secretState:o,createToken:c,revokeToken:d,setSpendCeiling:u,dismissSecret:h}
1=nQ(),m=nH(),[p,v]=(0,s.useState)(!1),[g,x]=(0,s.useState)(null),[f,j]=(0,s.useState)(null),[y,b]=(0,s.useState)(null),_=async e=>{await c(e)&&v(!1)},w=async()=>{g&&await d(g)&&x(null)},N=async e=>{f&&await u(f,e)&&j(null)},k=async()=>{y&&await m.revokeApp(y)&&b(null)};return(0,n.jsxs)("div",{className:"api-keys-settings",children:[(0,n.jsxs)("div",{className:"panel-head",children:[(0,n.jsx)("h2",{children:"API Keys"}),(0,n.jsx)("p",{children:"Personal keys that let an external client work with your Koast account."})]}),(0,n.jsxs)("div",{className:"section",children:[(0,n.jsxs)("div",{className:"sec-head",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{children:"Your keys"}),(0,n.jsx)("p",{children:"A key carries your access. Revoke one the moment you stop using it."})]}),(0,n.jsx)("button",{type:"button",className:"linkbtn",onClick:()=>v(!0),children:"Create key"})]}),a?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Loadingâ¦"}),(0,n.jsx)("div",{className:"info-row__value"}),(0,n.jsx)("div",{className:"info-row__action"})]})}):t?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Something went wrong"}),(0,n.jsx)("div",{className:"info-row__value",children:t}),(0,n.jsx)("div",{className:"info-row__action"})]})}):0===e.length?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"No API keys"}),(0,n.jsx)("div",{className:"info-row__value",children:(0,n.jsx)("span",{style:{color:"var(--k-text-3)"},children:"Create a key to connect an external client to Koast."})}),(0,n.jsx)("div",{className:"info-row__action"})]})}):(0,n.jsx)("div",{className:"info-card api-keys__card",children:(0,n.jsx)(nq,{tokens:e,revokingId:l,onRevoke:x,onEditCeiling:j})})]}),(0,n.jsxs)("div",{className:"section",children:[(0,n.jsx)("div",{className:"sec-head",children:(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{children:"Authorized apps"}),(0,n.jsx)("p",{children:"Apps you signed in to with your Koast account. Revoke one to take its access away."})]})}),m.loading?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Loadingâ¦"}),(0,n.jsx)("div",{className:"info-row__value"}),(0,n.jsx)("div",{className:"info-row__action"})]})}):m.error?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"Something went wrong"}),(0,n.jsx)("div",{className:"info-row__value",children:m.error}),(0,n.jsx)("div",{className:"info-row__action"})]})}):0===m.apps.length?(0,n.jsx)("div",{className:"info-card",children:(0,n.jsxs)("div",{className:"info-row",children:[(0,n.jsx)("div",{className:"info-row__label",children:"No authorized apps"}),(0,n.jsx)("div",{className:"info-row__value",children:(0,n.jsx)("span",{style:{color:"var(--k-text-3)"},children:"Apps you connect to Koast by signing in appear here."})}),(0,n.jsx)("div",{className:"info-row__action"})]})}):(0,n.jsx)("div",{className:"info-card api-keys__card",children:(0,n.jsx)(n4,{apps:m.apps,revokingId:m.revokingId,onRevoke:b})})]}),(0,n.jsx)(nJ,{open:p,creating:i,onClose:()=>v(!1),onCreate:_}),(0,n.jsx)(n2,{token:g,revoking:!!(g&&l===g.id),onClose:()=>x(null),onConfirm:w}),(0,n.jsx)(n3,{token:f,saving:!!(f&&r===f.id),onClose:()=>j(null),onConfirm:N}),(0,n.jsx)(n6,{app:y,revoking:!!(y&&m.revokingId===y.id),onClose:()=>b(null),onConfirm:k}),(0,n.jsx)(n0,{secretState:o,onClose:h})]})},{}),icon:(0,n.jsx)(x.Z,{})}]},{name:"Integrations",options:[{name:"Facebook",component:(0,n.jsx)(e=>{var a;let{context:t="settings"}=e,{user:i,redirectToFBAuth:l,integrationStatus:r,isFBIntegrationConnected:o,isFBIntegrationExpired:u,hasFetchedFBIntegrationStatus:h,hasValidFacebookIntegration:m,facebookSettingsPanel:p,setFacebookSettingsPanel:v,refreshFBIntegrationStatus:g}=(0,c.bp)(),x=(0,P.useRouter)(),y=(null==i?void 0:null===(a=i.activeBrand)||void 0===a?void 0:a.name)||void 0,{selectedAdAccount:b,hasSelectedAdAccount:_,facebookDataError:w,hasFetchedStatus:N,handleSelectAdAccount:k,handleConfirmAdAccount:C,facebookAdAccountName:S,adAccounts:A,isLoadingAdAccountChange:I,handleDisconnectFBFromBrand:R,initialAdAccountId:Z,fetchAdAccounts:z,isFetchingAdAccounts:W,adAccountDetails:Q,isLoadingDetails:H,isRefreshingDetails:q,refreshAdAccountAssets:G,previewAdAccountDetails:J,isLoadingPreviewDetails:X,hasFetchedAdAccounts:ee,canRefreshAssets:et}
1=O(),en=null==r?void 0:r.facebookUserName,[es,ei]=(0,s.useState)(!1),[el,er]=(0,s.useState)(!1),[eo,ec]=(0,s.useState)(!1),[ed,eu]=(0,s.useState)(""),[eh,em]=(0,s.useState)(!1),[ep,ev]=(0,s.useState)(!1),eg=B(!h||!N);(0,s.useEffect)(()=>{let{query:e}=x,a=null==e?void 0:e.error,t=j.hW[a];t&&(eu(t),(0,f.Od)("error")),((null==e?void 0:e.panel)==="enhancements"||"enhancements"===p)&&(em(!0),ev(!0),(null==e?void 0:e.panel)==="enhancements"&&(0,f.Od)("panel"),"enhancements"===p&&v(null),setTimeout(()=>{ev(!1)},1500))},[x,p,v]),(0,s.useEffect)(()=>{!m||_||ee||z(!0,!0)},[m,_,ee,z]);let ex=()=>{er(!0),l(t),setTimeout(()=>{er(!1)},5e3)},ef=function(){let{loadingText:e=""}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,n.jsxs)("div",{className:"facebook-integration-loading",children:[e&&(0,n.jsx)("div",{className:"facebook-integration-loading-text",children:e}),(0,n.jsx)(d.Ho,{})]})},ej=(0,s.useMemo)(()=>u?"Access Token Expired":o?"Connected":"Not Connected",[o,u]),ey=(0,s.useMemo)(()=>u?"error":o?"success":"neutral",[o,u]),eb=()=>(0,n.jsx)(U.RW,{label:ej,variant:ey}),e_=()=>W&&!A.length?ef({loadingText:"Loading ad accounts..."}):!A.length&&ee?(0,n.jsxs)("div",{className:"fb-modal-empty",children:[(0,n.jsx)("h4",{children:"No Ad Accounts Found"}),(0,n.jsx)("p",{children:"No ad accounts were found or are accessible via your linked Facebook account. Please check your Facebook Business Manager permissions or try reconnecting."})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"ad-account-selector-container",children:(0,n.jsx)(V.gN,{label:"Ad account",htmlFor:"fb-ad-account-select",children:(0,n.jsx)(V.lq,{id:"fb-ad-account-select",options:A,getOptionLabel:e=>e.name||"",value:b,onChange:e=>{k((null==e?void 0:e.id)||null)},isOptionEqualToValue:(e,a)=>e.id===a.id,placeholder:"Search Ad Accounts...",loading:W,disabled:W||I})})}),eN(),(0,n.jsx)(ea,{message:w&&b?"Error fetching preview details: ".concat(w):null,className:"facebook-integration-error preview-error"})]}),ew=(e,a,t)=>(0,n.jsxs)("div",{className:"details-section",children:[(0,n.jsx)("h4",{className:"group-title",children:e}),(0,n.jsx)("div",{className:"chip-container",children:a.length>0?a.map(t):(0,n.jsx)(F.Z,{label:"No ".concat(e.toLowerCase()," found"),disabled:!0,size:"small"})})]}),eN=()=>{if(X)return(0,n.jsxs)("div",{className:"ad-account-summary loading preview-summary",children:[(0,n.jsx)("h4",{children:"Previewing Ad Account Details..."}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Name:"})," ",(0,n.jsx)(D.Z,{width:"60%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pages:"})," ",(0,n.jsx)(D.Z,{width:"30%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pixels:"})," ",(0,n.jsx)(D.Z,{width:"30%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Instagram:"})," ",(0,n.jsx)(D.Z,{width:"30%"})]})]});if(!J)return(0,n.jsxs)("div",{className:"ad-account-summary preview-summary --empty",children:[(0,n.jsx)(M.Z,{className:"preview-empty__icon"}),(0,n.jsx)("p",{children:"Select an ad account above to preview its details."})]});let{name:e,pages:a=[],pixels:t=[],instagramAccounts:s=[]}=J;return(0,n.jsxs)("div",{className:"ad-account-summary preview-summary",children:[(0,n.jsxs)("h4",{children:["Preview: ",e]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pages:"}),(0,n.jsxs)("span",{className:"value",children:[a.length," connected"]})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pixels:"}),(0,n.jsxs)("span",{className:"value",children:[t.length," connected"]})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Instagram:"}),(0,n.jsx)("span",{className:"value",children:s.length>0?"".concat(s.length," connected"):"None connected"})]}),ew("Associated Pages",a,e=>(0,n.jsx)(F.Z,{label:e.name,size:"small",variant:"outlined"},e.id)),ew("Associated Pixels",t,e=>(0,n.jsx)(F.Z,{label:e.name,size:"small",variant:"outlined"},e.id)),ew("Instagram Accounts",s,e=>(0,n.jsx)(F.Z,{avatar:e.profilePic?(0,n.jsx)(E.Z,{alt:e.username,src:e.profilePic}):void 0,label:e.username,size:"small",variant:"outlined"},e.id))]})};return eg?(0,n.jsx)("div",{className:"facebook-integration-container",children:(0,n.jsx)(U.DP,{})}):(0,n.jsxs)(n.Fragment,{children:[(()=>{let e=()=>ec(!1);return(0,n.jsx)(V.hB,{id:"facebook-disconnect",open:eo,onClose:e,width:480,children:(0,n.jsx)(V.Vq,{onClose:e,confirmIcon:"warning",title:"Are you sure you want to disconnect your Facebook Integration?",subtitle:"All features that rely on your Facebook data such as Ad Launching and Automations will be disabled for this ad account. You can reconnect at any time.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:e,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",onClick:()=>{R(),ec(!1)},children:"Disconnect Integration"})]})})})})(),(()=>{let e=!b||b.id===Z||I,a="";b?b.id===Z&&(a="Please select a different ad account to switch."):a="Please select an ad account.";let t=()=>{ei(!1)},s=async()=>{let e=await C();ei(!1),e&&g()};return(0,n.jsx)(V.hB,{id:"facebook-change-account",open:es,onClose:t,width:600,children:(0,n.jsx)(V.Vq,{onClose:t,title:"Change Facebook Ad Account",subtitle:y?(0,n.jsxs)(n.Fragment,{children:["For ",(0,n.jsx)("strong",{children:y}),". The ad account you pick replaces the one it advertises through now."]}):void 0,footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:t,children:"Cancel"}),(0,n.jsx)(T.Z,{title:a,placement:"top",arrow:!0,children:(0,n.jsx)("span",{children:(0,n.jsx)(V.Qd,{variant:"primary",onClick:()=>{e||s()},disabled:e,loading:I,children:"Change Ad Account"})})})]}),children:e_()})})})(),(0,n.jsxs)("div",{className:"facebook-integration-container",children:[m?_?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Facebook Integration"}),eb()]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Facebook ad account linked to this workspace."}),(0,n.jsx)("div",{className:"facebook-manage-integration-section",children:(0,n.jsx)("div",{className:"facebook-manage-actions",children:(0,n.jsx)(U.QQ,{header:"Ad account",leftContent:(0,n.jsxs)(n.Fragment,{children:["Currently integrated: ",(0,n.jsx)("strong",{children:S||"None selected"})]}),buttonText:"Change Ad Account",buttonVariant:"outlined",buttonOnClick:()=>ei(!0)})})}),(0,n.jsx)(U.QQ,{header:"Advantage+ enhancements",leftContent:"Configure Meta's AI-powered creative optimization features for your ads.",buttonText:eh?"Hide Settings":"Manage Settings",buttonVariant:"outlined",buttonOnClick:()=>em(!eh)}),(0,n.jsx)("div",{className:"facebook-section-content ".concat(eh?"expanded":"collapsed"," ").concat(ep?"flicker-highlight":""),children:eh&&(0,n.jsx)(Y,{adAccountId:(null==b?void 0:b.id)||Z||void 0})}),(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Removes Koast's access to this Facebook Ad Account. You can reconnect at any time.",buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>ec(!0),buttonColor:"error"}),(0,n.jsx)(U.QQ,{header:"Connected assets",leftContent:"View and manage connected pages, pixels, and Instagram accounts for this ad account."}),(0,n.jsxs)("div",{className:"facebook-section-content expanded",children:[(()=>{if(H||!Q)return(0,n.jsxs)("div",{className:"ad-account-summary loading",children:[(0,n.jsx)("h4",{children:"Connected Ad Account Summary"}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Name"})," ",(0,n.jsx)(D.Z,{width:"60%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pages"})," ",(0,n.jsx)(D.Z,{width:"30%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pixels"})," ",(0,n.jsx)(D.Z,{width:"30%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Instagram accounts"})," ",(0,n.jsx)(D.Z,{width:"30%"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Last synced"})," ",(0,n.jsx)(D.Z,{width:"30%"})]})]});let{name:e,pages:a=[],pixels:t=[],instagramAccounts:s=[],updatedAt:i}=Q;return(0,n.jsxs)("div",{className:"ad-account-summary",children:[(0,n.jsxs)("div",{className:"summary-header",children:[(0,n.jsx)("h4",{children:"Connected Ad Account Summary"}),(0,n.jsx)(T.Z,{title:et?"Full refresh of the connected pages, pixels, and Instagram accounts from Facebook.":"Asset refresh limit reached. Please try again in a few minutes.",children:(0,n.jsx)("span",{children:(0,n.jsxs)(K.Z,{variant:"link",size:"sm",onClick:()=>G(null==b?void 0:b.id),loading:q,disabled:H||q||!et,className:"refresh-assets-button",children:[(0,n.jsx)(L.Z,{fontSize:"small"})," Refresh Assets"]})})})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Ad account name"}),(0,n.jsx)("span",{className:"value",children:e})]}),en&&(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Facebook profile"}),(0,n.jsx)("span",{className:"value",children:en})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pages"}),(0,n.jsxs)("span",{className:"value",children:[a.length," connected"]})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Pixels"}),(0,n.jsxs)("span",{className:"value",children:[t.length," connected"]})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Instagram accounts"}),(0,n.jsx)("span",{className:"value",children:s.length>0?"".concat(s.length," connected"):"None connected"})]}),(0,n.jsxs)("div",{className:"summary-item",children:[(0,n.jsx)("span",{className:"label",children:"Last synced"}),(0,n.jsx)("span",{className:"value",children:i?new Date(i).toLocaleStr
1ing():"Never"})]})]})})(),(()=>{if(!Q)return null;let{pages:e=[],pixels:a=[],instagramAccounts:t=[]}=Q;return(0,n.jsxs)("div",{className:"ad-account-details-view",children:[ew("Associated Pages",e,e=>(0,n.jsx)(F.Z,{label:e.name,size:"small",variant:"outlined"},e.id)),ew("Associated Pixels",a,e=>(0,n.jsx)(F.Z,{label:e.name,size:"small",variant:"outlined"},e.id)),ew("Instagram Accounts",t,e=>(0,n.jsx)(F.Z,{avatar:e.profilePic?(0,n.jsx)(E.Z,{alt:e.username,src:e.profilePic}):void 0,label:e.username,size:"small",variant:"outlined"},e.id))]})})()]})]}):(()=>{let e=!b||I,a=async()=>{await C()&&g()};return(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Facebook Integration"}),eb()]}),children:[(0,n.jsxs)("p",{className:"integration-lead",children:["Choose the Facebook ad account you want to integrate with"," ",y?(0,n.jsx)("strong",{children:y}):"this workspace","."]}),(0,n.jsxs)("div",{className:"select-ad-account-view",children:[e_(),(0,n.jsxs)("div",{className:"select-ad-account-view__footer",children:[(0,n.jsx)(V.Qd,{variant:"ghostDanger",onClick:()=>ec(!0),disabled:I,children:"Disconnect Integration"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:a,disabled:e,loading:I,children:"Confirm Selection"})]})]})]})})():(()=>{let e=u?"Your Facebook access token has expired":"Supercharge your advertising on Facebook",a=u?"Reconnect to continue using the Facebook integration and its powerful features.":"Connect your Facebook ad account and unlock the full potential of your campaigns with these key features.",t=u?"Reconnect Facebook":"Connect Facebook Ad Account",s=[{title:"Ad Publishing",description:"Easily manage and publish your ads to Facebook.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M4 4h16v3H4zm0 5h16v2H4zm0 4h10v2H4zm0 4h10v2H4zm12-1 5 3v-6z"})})},{title:"Brand Consistency",description:"AI tools keep your messaging aligned with your brand voice.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 2 2 7v7c0 5 4 9 10 10 6-1 10-5 10-10V7zm0 10h8c-.7 4-3.8 6.8-8 7.9z"})})},{title:"Creative Sync",description:"Import existing creative assets to jumpstart campaigns.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4h2v4h14v-4zM7 10l1.4-1.4L11 11.2V2h2v9.2l2.6-2.6L17 10l-5 5z"})})}];return(0,n.jsx)($,{logo:(0,n.jsxs)("svg",{viewBox:"0 0 36 36",width:"32",height:"32","aria-hidden":!0,children:[(0,n.jsx)("circle",{cx:"18",cy:"18",r:"18",fill:"#1877F2"}),(0,n.jsx)("path",{d:"M20 18h2.8l.4-3.4h-3.2v-2c0-1 .3-1.7 1.7-1.7h1.6V7.7c-.3-.1-1.3-.2-2.5-.2-2.5 0-4.2 1.5-4.2 4.3v2.4h-2.8V18h2.8v8.8H20z",fill:"#fff"})]}),haloColorRgb:"24, 119, 242",eyebrow:u?"Integration \xb7 Meta \xb7 Reconnect":"Integration \xb7 Meta",title:e,subtitle:a,features:s,ctaText:t,ctaIcon:(0,n.jsxs)("svg",{viewBox:"0 0 24 24",width:"16",height:"16","aria-hidden":!0,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#fff"}),(0,n.jsx)("path",{d:"M13.5 12h2l.3-2.5h-2.3V8c0-.7.2-1.2 1.2-1.2h1.2V4.5c-.2 0-.9-.1-1.8-.1-1.8 0-3 1.1-3 3v1.7H9v2.5h2.1v6.3h2.4z",fill:"#5561FF"})]}),onCtaClick:ex,ctaLoading:el,ctaLoadingText:"Redirecting to Facebook...",trustItems:["Meta-approved OAuth","Revoke anytime","~30 seconds to set up"]})})(),m&&w&&!b&&(0,n.jsx)(ea,{message:w||null,className:"facebook-integration-error"}),(0,n.jsx)(ea,{message:ed||null,className:"facebook-integration-error"})]})]})},{}),icon:(0,n.jsx)(d.RU,{})},{name:"Whop",component:(0,n.jsx)(e=>{var a,t,i,l;let{providerId:r,label:o}=e,{user:d,setSettingsModalActiveTab:u}=(0,c.bp)(),{loading:h,hasFetched:m,submitting:p,connectable:v,isSupported:g,isConnected:x,accounts:f,accountsLoading:j,accountsFailure:y,current:_,loadFailure:w,actionFailure:N,clearActionFailure:k,connect:C,disconnect:S,refetch:A,startOAuth:I,loadAccounts:P,brandAccount:T,hasPickedAccount:F,selectAccount:E}
1=(0,ec.jJ)(r),[D,L]=(0,s.useState)(""),[M,Z]=(0,s.useState)(!1),[z,O]=(0,s.useState)(!1),[K,W]=(0,s.useState)(null),Q=B(!m||h),H=(null==v?void 0:v.label)||o,q=eh[r],G=null!==(t=q.credential)&&void 0!==t?t:em,Y=null==_?void 0:_.reason,J=(null==N?void 0:N.code)==="provider_not_live",X=(null==N?void 0:N.code)==="provider_not_connectable",ee=!!N&&!ep.has(N.code),en=(null==v?void 0:v.credentialKind)==="apiKey",es=(null==v?void 0:v.credentialKind)==="oauth",ei=(0,ed.o)(null==d?void 0:null===(a=d.activeBrand)||void 0===a?void 0:a.id,x?r:null),eg=(0,eu.xL)(_,r)||null!==ei&&!0!==ei,ex=x&&(!en||eg),ef=(0,s.useMemo)(()=>f,[f]),ej=ef.length?"the ".concat(ef.length," ad account").concat(1===ef.length?"":"s"," above"):"every ".concat(H," ad account linked here"),ey=null!==(i=null!=K?K:null==T?void 0:T.externalAccountId)&&void 0!==i?i:null,eb=(null==T?void 0:T.name)||(null==T?void 0:T.externalAccountId)||"None selected",e_=()=>{L(""),k(),Z(!0)},ew=()=>{L(""),Z(!1)},eN=async()=>{let e=D.trim();if(!e)return;let a=await C(e);L(""),(!a||ep.has(a.code))&&Z(!1)},ek=async()=>{let e=await I("settings");"url"in e&&(window.location.href=e.url)},eC=async()=>{await S()||O(!1)},eS=()=>{k(),u((0,b.IL)(r))},eA=()=>(0,n.jsxs)("div",{className:"ad-provider-notice ad-provider-notice--pending",children:[(0,n.jsx)(el.Z,{className:"ad-provider-notice__icon",fontSize:"small"}),(0,n.jsxs)("div",{className:"ad-provider-notice__body",children:[(0,n.jsxs)("div",{className:"ad-provider-notice__title",children:[H," isn't available on your workspace yet"]}),(0,n.jsx)("p",{className:"ad-provider-notice__text",children:Y||"Koast doesn't offer a ".concat(H," connection here yet. There's nothing to set up right now.")})]})]}),eI=e=>(0,n.jsxs)("div",{className:"ad-provider-account",children:[(0,n.jsxs)("div",{className:"ad-provider-account__head",children:[(0,n.jsx)("span",{className:"ad-provider-account__name",children:e.name||e.externalAccountId}),e.isDefault&&(0,n.jsx)("span",{className:"ad-provider-account__default",children:"Default"})]}),(0,n.jsxs)("div",{className:"ad-provider-account__meta",children:[(0,n.jsx)("span",{className:"ad-provider-account__id",children:e.externalAccountId}),e.currencyCode&&(0,n.jsxs)("span",{className:"ad-provider-account__chip",children:[(0,n.jsx)(eo.Z,{fontSize:"inherit"}),e.currencyCode]}),e.timezoneName&&(0,n.jsxs)("span",{className:"ad-provider-account__chip",children:[(0,n.jsx)(el.Z,{fontSize:"inherit"}),e.timezoneName]}),e.scopeKind&&(0,n.jsx)("span",{className:"ad-provider-account__chip",children:e.scopeKind})]})]},e.externalAccountId),eP=(0,s.useMemo)(()=>{var e;
1return null!==(e=ef.find(e=>e.externalAccountId===ey))&&void 0!==e?e:null},[ef,ey]),eT=(0,s.useMemo)(()=>(0,et.D)({stringify:e=>{var a;let t=ef.find(a=>a.externalAccountId===e);return"".concat(null!==(a=null==t?void 0:t.name)&&void 0!==a?a:""," ").concat(e)}}),[ef]),eF=async()=>{if(!ey)return;let e=await E(ey);"code"in e||(R.ZP.success(e.imported?"Ad Account imported successfully! The page will refresh to show it.":"Ad Account connected! The page will refresh to reflect the new changes.",{duration:1e3}),setTimeout(()=>window.location.reload(),1e3))},eE=()=>eP?eI(eP):(0,n.jsx)("div",{className:"ad-provider-account ad-provider-account--preview",children:(0,n.jsx)("p",{className:"ad-provider-accounts__empty",children:"Select an ad account above to see its details."})});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.hB,{id:"ad-provider-credential",open:M,onClose:ew,width:480,children:(0,n.jsxs)(V.Vq,{onClose:ew,title:x?"Replace ".concat(H," API Key"):"Add ".concat(H," API Key"),footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:ew,disabled:p,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:eN,loading:p,disabled:!D.trim()||p,children:"Connect"})]}),children:[(0,n.jsx)(ea,{message:ee?(null==N?void 0:N.message)||"Koast couldn't connect ".concat(H,". Nothing was saved."):null,className:"ad-provider-error",align:"left"}),(0,n.jsxs)("form",{className:"ad-provider-form",onSubmit:e=>{e.preventDefault(),eN()},children:[(0,n.jsx)(V.gN,{label:G.label,required:!0,htmlFor:"ad-provider-credential-input",hint:G.hint,children:(0,n.jsx)(V.oi,{id:"ad-provider-credential-input",type:"password",value:D,onChange:e=>L(e.target.value),placeholder:"Enter your ".concat(H," ").concat(G.name),autoComplete:"off",spellCheck:!1,"data-1p-ignore":!0,autoFocus:!0})}),(0,n.jsx)("button",{type:"submit",hidden:!0,"aria-hidden":"true"})]})]})}),(0,n.jsx)(V.hB,{id:"ad-provider-disconnect",open:z,onClose:()=>O(!1),width:480,children:(0,n.jsx)(V.Vq,{onClose:()=>O(!1),confirmIcon:"warning",title:"Disconnect ".concat(H," from this workspace?"),subtitle:"Koast will delete the stored ".concat(H," API key and drop access to ").concat(ej,". Campaign launching, automations and reporting for ").concat(H," stop working immediately, and ads already live on ").concat(H," will keep running where Koast can no longer manage or pause them. You'll need a new API key to reconnect."),footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>O(!1),disabled:p,children:"Keep Connected"}),(0,n.jsxs)(V.Qd,{variant:"danger",onClick:eC,loading:p,children:["Disconnect ",H]})]}),children:(0,n.jsx)(ea,{message:z&&N?N.message:null,className:"ad-provider-error",align:"left"})})}),(0,n.jsxs)("div",{className:"ad-provider-integration-container",children:[Q&&(0,n.jsx)(U.DP,{}),!Q&&(0,n.jsxs)(n.Fragment,{children:[w?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("span",{children:[H," Integration"]}),children:[(0,n.jsx)(ea,{message:w.message,className:"ad-provider-error",align:"left"}),(0,n.jsx)(U.QQ,{header:"Connection status",leftContent:"Koast couldn't read this workspace's ad provider connection.",buttonText:"Retry",buttonVariant:"outlined",buttonOnClick:A})]}):ex?F?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsxs)("span",{children:[H," Integration"]}),(0,n.jsx)(U.RW,{label:(null==_?void 0:_.credentialIsValid)===!1?"Credential Invalid":"Connected",variant:(null==_?void 0:_.credentialIsValid)===!1?"error":"success"})]}),children:[(0,n.jsxs)("p",{className:"integration-lead",children:["Manage the ",H," ad account linked to this workspace."]}),(null==_?void 0:_.credentialIsValid)===!1&&(0,n.jsx)(ea,{message:Y||"Koast can no longer authenticate with ".concat(H,". Add a new ").concat(G.name," to restore access."),className:"ad-provider-error",align:"left"}),en&&eg&&(0,n.jsx)(U.QQ,{header:"API key",leftContent:"Stored securely by Koast. The key is never shown again after you save it.",buttonText:"Replace API Key",buttonVariant:"outlined",buttonOnClick:e_}),es&&(0,n.jsx)(U.QQ,{header:"Connection",leftContent:"Signed in with ".concat(H,". Reconnect to refresh the permissions Koast was granted."),buttonText:"Reconnect",buttonVariant:"outlined",buttonOnClick:ek,buttonDisabled:p}),(0,n.jsx)(U.QQ,{header:"Ad account",leftContent:(0,n.jsxs)(n.Fragment,{children:["Currently integrated: ",(0,n.jsx)("strong",{children:eb})]})}),eg&&(0,n.jsx)(U.QQ,{className:"ad-provider-section--flush",header:"Disconnect integration",leftContent:"Removes Koast's access to your ".concat(H," ad accounts."),buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>O(!0),buttonColor:"error"})]}):(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsxs)("span",{children:[H," Integration"]}),(0,n.jsx)(U.RW,{label:(null==_?void 0:_.credentialIsValid)===!1?"Credential Invalid":"Connected",variant:(null==_?void 0:_.credentialIsValid)===!1?"error":"success"})]}),children:[(0,n.jsxs)("p",{className:"integration-lead",children:["Choose the ",H," ad account you want to integrate with"," ",(null==d?void 0:null===(l=d.activeBrand)||void 0===l?void 0:l.name)?(0,n.jsx)("strong",{children:d.activeBrand.name}):"this workspace","."]}),(null==_?void 0:_.credentialIsValid)===!1&&(0,n.jsx)(ea,{message:Y||"Koast can no longer authenticate with ".concat(H,". Add a new ").concat(G.name," to restore access."),className:"ad-provider-error",align:"left"}),(0,n.jsxs)("div",{className:"ad-provider-select-view",children:[y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ea,{message:y.message||"Koast couldn't load your ".concat(H," ad accounts."),className:"ad-provider-error",align:"left"}),(0,n.jsx)(V.Qd,{variant:"secondary",onClick:()=>P(r),children:"Retry"})]}):j||ef.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"ad-provider-select-view__field",children:(0,n.jsx)(V.gN,{label:"Ad account",htmlFor:"ad-provider-account-select",children:(0,n.jsx)(V.lq,{id:"ad-provider-account-select",options:ef.map(e=>e.externalAccountId),value:ey,onChange:e=>W(e||null),getOptionLabel:e=>{let a=ef.find(a=>a.externalAccountId===e);
1return(null==a?void 0:a.name)?"".concat(a.name," (").concat(e,")"):e},filterOptions:eT,placeholder:"Search ".concat(H," ad accounts..."),loading:j,disabled:j||p})})}),eE()]}):(0,n.jsxs)("p",{className:"ad-provider-accounts__empty",children:["No ad accounts were returned for this ",G.name,". Check it in your"," ",H," dashboard, then replace it here."]}),(0,n.jsxs)("div",{className:"ad-provider-select-view__footer",children:[(0,n.jsx)(V.Qd,{variant:"ghostDanger",onClick:()=>O(!0),disabled:p,children:"Disconnect Integration"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:eF,disabled:!ey||p,loading:p,children:"Confirm Selection"})]})]})]}):g&&es&&!J&&!X?(0,n.jsx)($,{logo:q.logo,haloColorRgb:q.haloRgb,eyebrow:"Integration \xb7 ".concat(H),title:"Connect ".concat(H," to launch and track ads"),subtitle:"Sign in with ".concat(H," to link its ad accounts to this workspace."),features:ev,ctaText:"Connect ".concat(H),onCtaClick:ek,ctaLoading:p,trustItems:["Secure OAuth","Revoke anytime","No password stored"]}):J||X||!g||!en?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsxs)("span",{children:[H," Integration"]}),(0,n.jsx)(U.RW,{label:"Not Connected",variant:"neutral"})]}),children:[J&&(0,n.jsxs)("div",{className:"ad-provider-notice ad-provider-notice--pending",children:[(0,n.jsx)(el.Z,{className:"ad-provider-notice__icon",fontSize:"small"}),(0,n.jsxs)("div",{className:"ad-provider-notice__body",children:[(0,n.jsxs)("div",{className:"ad-provider-notice__title",children:[H," integration isn't live yet"]}),(0,n.jsx)("p",{className:"ad-provider-notice__text",children:(null==N?void 0:N.message)||"Koast can't connect ".concat(H," ad accounts yet. Nothing is wrong with your credential and nothing was saved.")}),(0,n.jsxs)("p",{className:"ad-provider-notice__text",children:["We'll turn this on for your workspace as soon as the ",H," connection ships."]})]})]}),X&&(en?(0,n.jsxs)("div",{className:"ad-provider-notice ad-provider-notice--info",children:[(0,n.jsx)(er.Z,{className:"ad-provider-notice__icon",fontSize:"small"}),(0,n.jsxs)("div",{className:"ad-provider-notice__body",children:[(0,n.jsxs)("div",{className:"ad-provider-notice__title",children:[H," can't be connected to this ad account"]}),(0,n.jsx)("p",{className:"ad-provider-notice__text",children:(null==N?void 0:N.message)||"This ad account can't take a ".concat(H," ").concat(G.name,". Nothing was saved.")})]})]}):(0,n.jsxs)("div",{className:"ad-provider-notice ad-provider-notice--info",children:[(0,n.jsx)(er.Z,{className:"ad-provider-notice__icon",fontSize:"small"}),(0,n.jsxs)("div",{className:"ad-provider-notice__body",children:[(0,n.jsxs)("div",{className:"ad-provider-notice__title",children:[H," doesn't use an API key"]}),(0,n.jsx)("p",{className:"ad-provider-notice__text",children:(null==N?void 0:N.message)||"".concat(H," connects through a secure login flow instead of a pasted credential.")}),(0,n.jsxs)(V.Qd,{variant:"secondary",onClick:eS,children:["Go to ",H," settings"]})]})]})),!J&&!X&&!g&&eA(),!J&&!X&&g&&!en&&eA(),en&&!X&&(0,n.jsx)(U.QQ,{header:"API key",leftContent:(0,n.jsx)("span",{className:"ad-provider-muted",children:"Not connected"}),buttonText:J?"Try Again":"Add API Key",buttonVariant:"outlined",buttonOnClick:e_})]}):(0,n.jsx)($,{logo:q.logo,haloColorRgb:q.haloRgb,eyebrow:"Integration \xb7 ".concat(H),title:"Connect ".concat(H," to launch and track ads"),subtitle:"Paste your ".concat(H," ").concat(G.name," to link its ad accounts to this workspace."),features:ev,ctaText:"Add API Key",onCtaClick:e_,trustItems:["API key auth","Revoke anytime","Stored encrypted"]}),ee&&!M&&!z&&(0,n.jsx)(ea,{message:(null==N?void 0:N.message)||null,className:"ad-provider-error",align:"left"})]})]})]})},{providerId:"whop",label:"Whop"}),icon:(0,n.jsx)(d.BI,{})},{name:"Slack",component:(0,n.jsx)(()=>{let{loading:e,hasFetched:a,connection:t,isConnected:i,getAuthUrl:l,channels:r,loadingChannels:o,fetchChannels:d,updateSettings:u,sendTestNotification:h,testingNotification:m,disconnect:p}=(0,tP.Y)(),{refetch:v}=(0,tT.u)(),{currentBrandInfo:g}
1=(0,c.bp)(),x=B(!a),[j,y]=(0,s.useState)(!1),[b,_]=(0,s.useState)(null),[w,N]=(0,s.useState)("YESTERDAY"),[k,C]=(0,s.useState)(()=>{var e;return(null===(e=(0,eV.JF)(g))||void 0===e?void 0:e.timezoneName)||Intl.DateTimeFormat().resolvedOptions().timeZone});(0,s.useEffect)(()=>{i&&d()},[i,d]),(0,s.useEffect)(()=>{if(r.length>0){let a=null==t?void 0:t.metadata;if(null==a?void 0:a.channelId){let e=r.find(e=>e.id===a.channelId);e&&_(e)}if((null==a?void 0:a.defaultTimeframe)&&N(a.defaultTimeframe),null==a?void 0:a.defaultTimezone)C(a.defaultTimezone);else{var e;let a=null===(e=(0,eV.JF)(g))||void 0===e?void 0:e.timezoneName;a&&C(a)}}},[r,t,g]);let S=async()=>{let e=await l();e?window.location.href=e:R.ZP.error("Failed to initiate Slack connection")},A=async e=>{if(!e)return;_(e);let a=await u(e.id,e.name,e.isPrivate);a.success?R.ZP.success(e.isPrivate?"Channel updated successfully":"Channel updated and bot joined successfully"):(R.ZP.error(a.error||"Failed to update channel"),_(null))},I=async()=>{if(!b){R.ZP.error("Please select a channel first");return}await h()?R.ZP.success("Test notification sent successfully!"):R.ZP.error("Failed to send test notification")},P=async()=>{await p()?(y(!1),_(null),R.ZP.success("Slack disconnected successfully")):R.ZP.error("Failed to disconnect Slack")},T=async(e,a)=>{if(a)try{(await (0,f.handleFetch)("/integrations/slack/defaults",{method:"PUT",body:JSON.stringify({defaultTimeframe:a.value})})).success?(N(a.value),R.ZP.success("Default timeframe updated")):R.ZP.error("Failed to update default timeframe")}catch(e){R.ZP.error("Failed to update default timeframe")}},F=async(e,a)=>{if(a)try{(await (0,f.handleFetch)("/integrations/slack/defaults",{method:"PUT",body:JSON.stringify({defaultTimezone:a.value})})).success?(C(a.value),await v(),R.ZP.success("Default timezone updated")):R.ZP.error("Failed to update default timezone")}catch(e){R.ZP.error("Failed to update default timezone")}};return x?(0,n.jsx)("div",{className:"slack-integration-container",children:(0,n.jsx)(U.DP,{})}):(0,n.jsxs)(n.Fragment,{children:[(()=>{let e=()=>y(!1);return(0,n.jsx)(V.hB,{id:"slack-disconnect",open:j,onClose:e,width:480,children:(0,n.jsx)(V.Vq,{onClose:e,confirmIcon:"warning",title:"Are you sure you want to disconnect Slack?",subtitle:"All automated Slack notifications for this brand will be disabled. You can reconnect at any time.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:e,children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",onClick:P,children:"Disconnect"})]})})})})(),(0,n.jsx)("div",{className:"slack-integration-container",children:i?(()=>{let e=null==t?void 0:t.metadata,a=null==e?void 0:e.teamName;return(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Slack Integration"}),(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Slack workspace and notification settings for this brand."}),(0,n.jsx)(U.QQ,{header:"Workspace",leftContent:a||"Connected workspace"}),(0,n.jsx)(U.QQ,{header:"Notification Channel",leftContent:(0,n.jsx)("div",{className:"slack-channel-selector",children:(0,n.jsx)(aU.Z,{fullWidth:!0,options:r,getOptionLabel:e=>e.name,value:b,onChange:(e,a)=>A(a),loading:o,disabled:o,renderOption:(e,a)=>{let t=a.isPrivate&&!a.isMember,{key:s,onClick:i,...l}=e;return(0,n.jsx)(tF.Z,{title:"Invite the bot to this private channel first using /invite @YourBot",placement:"right",disableHoverListener:!t,children:(0,n.jsx)("li",{...l,onClick:e=>{if(t){e.preventDefault(),e.stopPropagation();return}i&&i(e)},className:"slack-channel-option ".concat(t?"not-selectable":""),children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[(0,n.jsx)("div",{className:"channel-icon",children:a.isPrivate?(0,n.jsx)(tA.Z,{fontSize:"small"}):(0,n.jsx)(tI.Z,{fontSize:"small"})}),(0,n.jsx)("span",{className:"channel-name",children:a.name}),t&&(0,n.jsx)("span",{className:"bot-not-invited",children:"Bot not invited"})]})},s)})},renderInput:e=>(0,n.jsx)(aW.Z,{...e,placeholder:"Select a channel...",size:"small",InputProps:{...e.InputProps,startAdornment:b&&(0,n.jsx)("div",{className:"selected-channel-icon",children:b.isPrivate?(0,n.jsx)(tA.Z,{fontSize:"small"}):(0,n.jsx)(tI.Z,{fontSize:"small"})})}}),isOptionEqualToValue:(e,a)=>e.id===a.id})})}),(0,n.jsx)(U.QQ,{header:"Default Update Timeframe",leftContent:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(aU.Z,{options:[{value:"TODAY",label:"Today"},{value:"YESTERDAY",label:"Yesterday"},{value:"LAST_3_DAYS",label:"Last 3 days"},{value:"LAST_7_DAYS",label:"Last 7 days"},{value:"SINCE_LAUNCH",label:"Since launch"}],value:[{value:"TODAY",label:"Today"},{value:"YESTERDAY",label:"Yesterday"},{value:"LAST_3_DAYS",label:"Last 3 days"},{value:"LAST_7_DAYS",label:"Last 7 days"},{value:"SINCE_LAUNCH",label:"Since launch"}].find(e=>e.value===w)||{value:"YESTERDAY",label:"Yesterday"},onChange:T,getOptionLabel:e=>e.label,renderInput:e=>(0,n.jsx)(aW.Z,{...e,placeholder:"Select default timeframe",size:"small"}),isOptionEqualToValue:(e,a)=>e.value===a.value}),(0,n.jsx)("p",{style:{fontSize:"0.75rem",color:"var(--k-text-2)",marginTop:"8px",marginBottom:0},children:"This will be the default timeframe when enabling campaign monitoring"})]})}),(0,n.jsx)(U.QQ,{header:"Default Timezone",leftContent:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(aU.Z,{options:tE,value:tE.find(e=>e.value===k)||tE.find(e=>"UTC"===e.value),onChange:F,getOptionLabel:e=>e.label,renderInput:e=>(0,n.jsx)(aW.Z,{...e,placeholder:"Select default timezone",size:"small"}),isOptionEqualToValue:(e,a)=>e.value===a.value}),(0,n.jsx)("p",{style:{fontSize:"0.75rem",color:"var(--k-text-2)",marginTop:"8px",marginBottom:0},children:"All daily Slack updates will be sent in this timezone"})]})}),(0,n.jsx)(U.QQ,{header:"Test notification",leftContent:"Send a test message to verify your integration is working correctly.",buttonText:"Send Test",buttonVariant:"outlined",buttonOnClick:I,buttonDisabled:!b||m}),(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Stops all automated Slack notifications for this brand. You can reconnect at any time.",buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>y(!0),buttonColor:"error"})]})})():(()=>{let a=[{title:"Daily Summaries",description:"Receive once-per-day performance reports for every active campaign.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"
1currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M19 3h-1V1h-2v2H8V1H6v2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zm0 16H5V8h14zM7 10h5v5H7z"})})},{title:"Key Metrics",description:"Track spend, results, CPA, and campaign health at a glance.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M3 13h2v8H3zm4-5h2v13H7zm4 2h2v11h-2zm4-4h2v15h-2zm4 6h2v9h-2z"})})},{title:"Actionable Insights",description:"Identify ad sets that need attention with detailed breakdowns.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M13 3a9 9 0 1 0 8.94 10H13zM11 11V2a9 9 0 0 1 9 9z"})})}];return(0,n.jsx)($,{logo:(0,n.jsxs)("svg",{viewBox:"0 0 24 24",width:"32",height:"32","aria-hidden":!0,children:[(0,n.jsx)("path",{fill:"#E01E5A",d:"M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313z"}),(0,n.jsx)("path",{fill:"#36C5F0",d:"M8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312z"}),(0,n.jsx)("path",{fill:"#2EB67D",d:"M18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312z"}),(0,n.jsx)("path",{fill:"#ECB22E",d:"M15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z"})]}),haloColorRgb:"74, 21, 75",eyebrow:"Integration \xb7 Slack",title:"Connect Slack for daily campaign updates",subtitle:"Get automated daily performance summaries for your live campaigns delivered directly to your Slack workspace.",features:a,ctaText:"Connect Slack",onCtaClick:S,ctaLoading:e,ctaLoadingText:"Connecting...",trustItems:["Slack-approved OAuth","Revoke anytime","Bot permissions only"]})})()})]})},{}),icon:(0,n.jsx)(d.MA,{})},{name:"Google Drive",component:(0,n.jsx)(()=>{let{googleLoading:e,isConnected:a,hasCheckedStatus:t,showPicker:i,accessToken:l,isImporting:r,removeLoading:o,checkIntegrationStatus:c,handleCheckStatus:d,handleOpenPicker:u,handleClosePicker:h,handleFilesPicked:m,handleRemoveIntegration:p}=(0,ef.O)(),v=(0,ex.r)(),g=B(!t);(0,s.useEffect)(()=>{if(i)return;c();let e=setInterval(c,5e3);return()=>clearInterval(e)},[c,i]);let x=async()=>{await d()},f=async()=>{u()},j=async()=>{await p()};return(0,n.jsxs)("div",{className:"google-drive-integration",children:[v&&(0,n.jsx)(ey.Z,{text:"We're currently importing creatives from your Google Drive. This may take a while, but you can leave this page and continue using the app.",icon:(0,n.jsx)(eg.Z,{})}),g&&(0,n.jsx)(U.DP,{}),!g&&(a?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Google Drive Integration"}),(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Google Drive account connected to your creative library."}),(0,n.jsx)(U.QQ,{header:"Import assets",leftContent:"Browse and import creatives from your Google Drive. Koast pulls the files you pick into your library â originals stay in Drive.",buttonText:r?"Opening pickerâ¦":"Import from Drive",buttonVariant:"outlined",buttonOnClick:f,buttonDisabled:r}),(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Removes Koast's access to your Google Drive. Previously imported creatives stay in your library. You can reconnect at any time.",buttonText:o?"Disconnectingâ¦":"Disconnect",buttonVariant:"outlined",buttonOnClick:j,buttonColor:"error",buttonDisabled:o})]}):(()=>{let a=[{title:"Native Picker",description:"Browse and select files with the official Google Drive picker.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"
1currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8z"})})},{title:"Bulk Import",description:"Import many creatives at once from any Drive folder.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"})})},{title:"Read-only Access",description:"Koast only reads what you pick â never writes or deletes.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 1 3 5v6c0 5.6 3.8 10.7 9 12 5.2-1.3 9-6.4 9-12V5zm0 10.9h7c-.5 4.1-3.3 7.8-7 8.9z"})})}];return(0,n.jsx)($,{logo:(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 87.3 78","aria-hidden":!0,children:[(0,n.jsx)("path",{d:"M6.6 66.85l3.85 6.65c.8 1.4 1.95 2.5 3.3 3.3l13.75-23.8H0c0 1.55.4 3.1 1.2 4.5l5.4 9.35z",fill:"#0066da"}),(0,n.jsx)("path",{d:"M43.65 25L29.9 1.2c-1.35.8-2.5 1.9-3.3 3.3l-25.4 44a9.06 9.06 0 0 0-1.2 4.5h27.45l16.2-28z",fill:"#00ac47"}),(0,n.jsx)("path",{d:"M73.55 76.8c1.35-.8 2.5-1.9 3.3-3.3l1.6-2.75 7.65-13.25c.8-1.4 1.2-2.95 1.2-4.5H59.8L69.3 76.8h4.25z",fill:"#ea4335"}),(0,n.jsx)("path",{d:"M43.65 25L57.4 1.2C56.05.4 54.55 0 53 0H34.3c-1.55 0-3.05.4-4.4 1.2L43.65 25z",fill:"#00832d"}),(0,n.jsx)("path",{d:"M59.8 53H27.45L13.7 76.8c1.35.8 2.85 1.2 4.4 1.2h51.8c1.55 0 3.05-.4 4.4-1.2L59.8 53z",fill:"#2684fc"}),(0,n.jsx)("path",{d:"M73.4 26.5l-12.7-22c-.8-1.4-1.95-2.5-3.3-3.3L43.65 25 59.8 53h27.5c0-1.55-.4-3.1-1.2-4.5l-12.7-22z",fill:"#ffba00"})]}),haloColorRgb:"66, 133, 244",eyebrow:"Integration \xb7 Google Drive",title:"Import creatives straight from Google Drive",subtitle:"Connect your Google Drive and pull in assets without leaving Koast.",features:a,ctaText:"Connect Google Drive",onCtaClick:x,ctaLoading:e,ctaLoadingText:"Redirecting to Google...",trustItems:["Google-approved OAuth","Revoke anytime","Read-only access"]})})()),i&&l&&(0,n.jsx)(ej.Z,{accessToken:l,onPickerClosed:h,onFilesPicked:m})]})},{}),icon:(0,n.jsx)(d.k6,{})},{name:"Dropbox",component:(0,n.jsx)(()=>{let{dropboxLoading:e,isConnected:a,hasCheckedStatus:t,isImporting:i,checkIntegrationStatus:l,handleDropboxImport:r,handleRemoveIntegration:o,removeLoading:c}=(0,tC.j)(),d=B(!t);(0,s.useEffect)(()=>
1{l()},[l]);let u=async()=>{await r()},h=async()=>{await o()};return(0,n.jsxs)("div",{className:"dropbox-integration",children:[d&&(0,n.jsx)(U.DP,{}),!d&&(a?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Dropbox Integration"}),(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Dropbox account connected to your creative library."}),(0,n.jsx)(U.QQ,{header:"Import assets",leftContent:"Browse and import creatives from your Dropbox. Koast pulls the files you pick into your library â originals stay in Dropbox.",buttonText:i?"Opening pickerâ¦":"Import from Dropbox",buttonVariant:"outlined",buttonOnClick:u,buttonDisabled:i}),(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Removes Koast's access to your Dropbox. Previously imported creatives stay in your library. You can reconnect at any time.",buttonText:c?"Disconnectingâ¦":"Disconnect",buttonVariant:"outlined",buttonOnClick:h,buttonColor:"error",buttonDisabled:c})]}):(()=>{let a=[{title:"Bulk Import",description:"Bring in large folders of creatives in a single click.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"})})},{title:"Folder Structure",description:"Keep your Dropbox organization intact inside Koast.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8z"})})},{title:"Read-only Access",description:"Koast only reads what you import â never writes or deletes.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 1 3 5v6c0 5.6 3.8 10.7 9 12 5.2-1.3 9-6.4 9-12V5zm0 10.9h7c-.5 4.1-3.3 7.8-7 8.9z"})})}];return(0,n.jsx)($,{logo:(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"-35.3175 -50 306.085 300","aria-hidden":!0,children:[(0,n.jsx)("path",{fill:"#0061ff",d:"M58.86 75l58.87-37.5L58.86 0 0 37.5z"}),(0,n.jsx)("path",{fill:"#0061ff",d:"M176.59 75l58.86-37.5L176.59 0l-58.86 37.5z"}),(0,n.jsx)("path",{fill:"#0061ff",d:"M117.73 112.5L58.86 75 0 112.5 58.86 150z"}),(0,n.jsx)("path",{fill:"#0061ff",d:"M176.59 150l58.86-37.5L176.59 75l-58.86 37.5z"}),(0,n.jsx)("path",{fill:"#0061ff",d:"M176.59 162.5L117.73 125l-58.87 37.5 58.87 37.5z"})]}),haloColorRgb:"0, 97, 255",eyebrow:"Integration \xb7 Dropbox",title:"Import creatives straight from Dropbox",subtitle:"Connect your Dropbox and pull in assets without leaving Koast.",features:a,ctaText:"Connect Dropbox",onCtaClick:u,ctaLoading:e,ctaLoadingText:"Redirecting to Dropbox...",trustItems:["Dropbox-approved OAuth","Revoke anytime","Read-only access"]})})())]})},{}),icon:(0,n.jsx)(d.AW,{})},{name:"Frame.io",component:(0,n.jsx)(()=>{let{frameioLoading:e,isConnected:a,hasCheckedStatus:t,removeLoading:i,checkIntegrationStatus:l,connect:r,handleRemoveIntegration:o}=(0,tS.$)(),d=(0,P.useRouter)(),{setShowSettingsModal:u}=(0,c.bp)(),h=B(!t);return(0,s.useEffect)(()=>
1{l()},[l]),(0,n.jsxs)("div",{className:"frameio-integration",children:[h&&(0,n.jsx)(U.DP,{}),!h&&(a?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Frame.io Integration"}),(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Frame.io account connected to your creative library."}),(0,n.jsx)(U.QQ,{header:"Import assets",leftContent:"Browse and import creatives from your Frame.io account. Koast pulls the files you pick into your library. Originals stay in Frame.io.",buttonText:"Import from Frame.io",buttonVariant:"outlined",buttonOnClick:()=>{u(!1),d.push("/launchpad?frameio=import")}}),(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Removes Koast's access to your Frame.io. Previously imported creatives stay in your library. You can reconnect at any time.",buttonText:i?"Disconnectingâ¦":"Disconnect",buttonVariant:"outlined",buttonOnClick:o,buttonColor:"error",buttonDisabled:i})]}):(()=>{let a=[{title:"Bulk Import",description:"Bring in approved frames and clips in a single click.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"})})},{title:"Project Structure",description:"Browse workspaces, projects and folders just like in Frame.io.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8z"})})},{title:"Read-only Access",description:"Koast only reads what you import, never writes or deletes.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 1 3 5v6c0 5.6 3.8 10.7 9 12 5.2-1.3 9-6.4 9-12V5zm0 10.9h7c-.5 4.1-3.3 7.8-7 8.9z"})})}];return(0,n.jsx)($,{logo:(0,n.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none","aria-hidden":!0,children:[(0,n.jsxs)("g",{stroke:"var(--k-primary)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M 10.69 22.64 L 9.38 21.47 L 8.24 20.15 L 7.28 18.69 L 6.51 17.12 L 5.95 15.46 L 5.61 13.75 L 5.5 12 L 5.61 10.25 L 5.95 8.54 L 6.51 6.88 L 7.28 5.31 L 8.24 3.85 L 9.38 2.53 L 10.69 1.36"}),(0,n.jsx)("path",{d:"M 12.84 19.88 L 11.88 19.02 L 11.03 18.04 L 10.31 16.96 L 9.75 15.79 L 9.33 14.56 L 9.08 13.29 L 9 12 L 9.08 10.71 L 9.33 9.44 L 9.75 8.21 L 10.31 7.04 L 11.03 5.96 L 11.88 4.98 L 12.84 4.12"}),(0,n.jsx)("path",{d:"M 15 17.12 L 14.37 16.56 L 13.82 15.92 L 13.35 15.22 L 12.99 14.46 L 12.72 13.67 L 12.55 12.84 L 12.5 12 L 12.55 11.16 L 12.72 10.33 L 12.99 9.54 L 13.35 8.78 L 13.82 8.08 L 14.37 7.44 L 15 6.88"}
1),(0,n.jsx)("path",{d:"M 17.03 14.52 L 16.72 14.25 L 16.45 13.93 L 16.22 13.59 L 16.04 13.21 L 15.91 12.82 L 15.83 12.41 L 15.8 12 L 15.83 11.59 L 15.91 11.18 L 16.04 10.79 L 16.22 10.41 L 16.45 10.07 L 16.72 9.75 L 17.03 9.48"})]}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.2",fill:"var(--k-primary)"})]}),haloColorRgb:"96, 88, 255",eyebrow:"Integration \xb7 Frame.io",title:"Import creatives straight from Frame.io",subtitle:"Connect your Frame.io account and pull in assets without leaving Koast.",features:a,ctaText:"Connect Frame.io",onCtaClick:r,ctaLoading:e,ctaLoadingText:"Redirecting to Frame.io...",trustItems:["Adobe-approved OAuth","Revoke anytime","Read-only access"]})})())]})},{}),icon:(0,n.jsx)(d.y0,{})},{name:"Hyros",component:(0,n.jsx)(()=>{var e,a;let{hasFetched:t,connection:i,isConnected:l,updateAttributionModel:r,disconnect:o}=(0,eZ._)(),{status:c}=ez(l,5e3),[u,h]=(0,s.useState)(!1),[m,p]=(0,s.useState)(!1),[v,g]=(0,s.useState)(""),[x,f]=(0,s.useState)(!1),[j,y]=(0,s.useState)(""),b=B(!t),_=()=>{window.open(eZ.B,"_blank","noopener,noreferrer")},w=async()=>{p(!0),g("");try{await o(),h(!1)}catch(e){g(e instanceof Error?e.message:"Failed to disconnect integration")}finally{p(!1)}},N=async e=>{if(eR.isModel(e)){f(!0),y("");try{await r(e)}catch(e){y(e instanceof Error?e.message:"Failed to update the attribution model")}finally{f(!1)}}},k=c?eM(c):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.hB,{id:"hyros-disconnect",open:u,onClose:()=>h(!1),width:480,children:(0,n.jsx)(V.Vq,{onClose:()=>h(!1),confirmIcon:"warning",title:"Are you sure you want to disconnect Hyros?",subtitle:"Any Koast features using Hyros data will no longer work until you reconnect.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>h(!1),children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",onClick:w,loading:m,children:"Disconnect"})]}),children:(0,n.jsx)(ea,{message:v||null,className:"hyros-modal-error"})})}),(0,n.jsxs)("div",{className:"hyros-integration-container",children:[b&&(0,n.jsx)(U.DP,{}),!b&&(l?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Hyros Integration"}),l&&(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Hyros connection that syncs ad-set level attribution into Koast."}),(0,n.jsx)(U.QQ,{header:"Hyros Account",leftContent:l&&i?(0,n.jsx)("span",{className:"monospace-key",children:(null===(e=i.metadata)||void 0===e?void 0:e.email)||(null===(a=i.metadata)||void 0===a?void 0:a.maskedApiKey)||"Connected"}):(0,n.jsx)("span",{className:"not-connected",children:"Not Connected"}),buttonText:l?"Reconnect":"Connect Hyros",buttonVariant:"outlined",buttonOnClick:_,buttonColor:l?"secondary":"primary"}),l?(0,n.jsx)(U.QQ,{header:"Attribution Settings",leftContent:(0,n.jsxs)("div",{className:"hyros-attribution-fields",children:[(0,n.jsx)(V.gN,{label:"Attribution model",hint:"The model the Hyros columns report on. Changing it re-fetches the last 30 days; earlier days show no Hyros data.",htmlFor:"hyros-attribution-model",children:(0,n.jsx)(V.px,{id:"hyros-attribution-model",value:eR.modelOf(null==i?void 0:i.metadata),disabled:x,onChange:e=>N(e.target.value),children:eR.OPTIONS.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(ea,{message:j||null}),(0,n.jsx)(V.gN,{label:"Data refresh",hint:"Koast re-fetches recent days as Hyros redistributes attribution.",htmlFor:"hyros-refresh-cadence",children:(0,n.jsx)(V.px,{id:"hyros-refresh-cadence",value:"daily",disabled:!0,children:eO.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})})]})}):null,l&&c&&k?(0,n.jsx)(U.QQ,{header:"Data Status",leftContent:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(()=>{switch(null==k?void 0:k.tone){case"success":return(0,n.jsx)(eb.Z,{style:{color:"#4caf50",fontSize:20}});case"error":return(0,n.jsx)(ew.Z,{style:{color:"#f44336",fontSize:20}});case"progress":return(0,n.jsx)(e_.Z,{style:{color:"#2196f3",fontSize:20},className:"rotating"});case"neutral":return(0,n.jsx)(M.Z,{style:{color:"#9e9e9e",fontSize:20}});default:return null}})(),(0,n.jsx)("span",{children:k.message})]}),c.latestDate&&(0,n.jsxs)("div",{style:{fontSize:"12px",color:"#888"},children:["Most recent day: ",new Date(c.latestDate).toLocaleDateString()]}),c.lastFetchedAt&&(0,n.jsxs)("div",{style:{fontSize:"12px",color:"#888"},children:["Last refreshed: ",new Date(c.lastFetchedAt).toLocaleStr
1ing()]})]})}):null,l&&(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Stops Koast from fetching attribution data from Hyros. Data already stored stays readable.",buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>h(!0),buttonColor:"error"})]}):(()=>{let e=[{title:"Ad-Set Attribution",description:"Pull Hyros sales, revenue and cost per Meta ad set into Koast.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M3 13h2v8H3zm4-5h2v13H7zm4 2h2v11h-2zm4-4h2v15h-2zm4 6h2v9h-2z"})})},{title:"Retroactive Corrections",description:"Recent days are re-fetched as Hyros redistributes attribution.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M12 5V1L7 6l5 5V7a6 6 0 1 1-6 6H4a8 8 0 1 0 8-8z"})})},{title:"Unified Reporting",description:"See Meta spend and Hyros attribution side by side.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM15 19l-6-2.11V5l6 2.11z"})})}];return(0,n.jsx)($,{logo:(0,n.jsx)(d.Bm,{size:36}),haloColorRgb:"31, 41, 55",eyebrow:"Integration \xb7 Hyros",title:"Connect Hyros for ad-set level attribution",subtitle:"Approve Koast in Hyros and you will be returned here with the connection in place. No API key to copy.",features:e,ctaText:"Connect Hyros",onCtaClick:_,trustItems:["Approved in Hyros","Revoke anytime","Read-only access"]})})())]})]})},{}),icon:(0,n.jsx)(d.Bm,{})},{name:"RedTrack",component:(0,n.jsx)(()=>{var e;let{hasFetched:a,connection:t,isConnected:i,connect:l,disconnect:r}=(0,eC.J)(),{status:o,loading:c,isProcessing:u,hasErrors:h,isCompleted:m}
1=eS(i,5e3),[p,v]=(0,s.useState)(""),[g,x]=(0,s.useState)(!1),[f,j]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!1),[_,w]=(0,s.useState)(""),N=B(!a),k=async()=>{if(!p.trim()){w("API key is required");return}b(!0),w("");try{await l(p.trim()),x(!1),v("")}catch(e){w(e.message||"Failed to connect integration")}finally{b(!1)}},C=async()=>{b(!0),w("");try{await r(),j(!1)}catch(e){w(e.message||"Failed to disconnect integration")}finally{b(!1)}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.hB,{id:"redtrack-api-key",open:g,onClose:()=>x(!1),width:480,children:(0,n.jsxs)(V.Vq,{onClose:()=>x(!1),title:i?"Update RedTrack API Key":"Add RedTrack API Key",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>x(!1),children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:k,loading:y,disabled:!p.trim(),children:"Save"})]}),children:[(0,n.jsx)(ea,{message:_||null,className:"redtrack-modal-error"}),(0,n.jsx)(V.gN,{label:"API Key",required:!0,htmlFor:"redtrack-api-key-input",children:(0,n.jsx)(V.oi,{id:"redtrack-api-key-input",value:p,onChange:e=>v(e.target.value),placeholder:"Enter your RedTrack API key",autoFocus:!0})})]})}),(0,n.jsx)(V.hB,{id:"redtrack-disconnect",open:f,onClose:()=>j(!1),width:480,children:(0,n.jsx)(V.Vq,{onClose:()=>j(!1),confirmIcon:"warning",title:"Are you sure you want to disconnect RedTrack?",subtitle:"Any Koast features using RedTrack data will no longer work until you reconnect.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>j(!1),children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",onClick:C,loading:y,children:"Disconnect"})]}),children:(0,n.jsx)(ea,{message:_||null,className:"redtrack-modal-error"})})}),(0,n.jsxs)("div",{className:"redtrack-integration-container",children:[N&&(0,n.jsx)(U.DP,{}),!N&&(i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"RedTrack Integration"}),i&&(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the RedTrack connection that syncs cost & conversion data into Koast."}),(0,n.jsx)(U.QQ,{header:"RedTrack API Key",leftContent:i&&t?(0,n.jsx)("span",{className:"monospace-key",children:(null===(e=t.metadata)||void 0===e?void 0:e.maskedApiKey)||"API Key Set"}):(0,n.jsx)("span",{className:"not-connected",children:"Not Connected"}),buttonText:i?"Change API Key":"Add API Key",buttonVariant:"outlined",buttonOnClick:()=>{v(""),w(""),x(!0)},buttonColor:i?"secondary":"primary"}),i&&o?(0,n.jsx)(U.QQ,{header:"Data Processing Status",leftContent:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(()=>{if(!o||!i)return null;switch(o.overallStatus){case"completed":return(0,n.jsx)(eb.Z,{style:{color:"var(--k-success)",fontSize:20}});case"processing":case"initializing":return(0,n.jsx)(e_.Z,{style:{color:"var(--k-info)",fontSize:20},className:"rotating"});case"error":return(0,n.jsx)(ew.Z,{style:{color:"var(--k-error)",fontSize:20}});default:return(0,n.jsx)(eN.Z,{style:{color:"var(--k-warning)",fontSize:20}})}})(),(0,n.jsx)("span",{children:o.statusMessage})]}),(()=>{if(!o||!i)return null;let{overallStatus:e,processing:a}=o;return"processing"===e&&365===a.totalDays&&a.completedDays<330?(0,n.jsx)("div",{style:{fontSize:"12px",color:"var(--k-text-2)",marginTop:4},children:"\uD83D\uDCCA Processing complete historical data for long-term analytics ⢠Campaign performance is available for processed days"}):"completed"===e?(0,n.jsx)("div",{style:{fontSize:"12px",color:"var(--k-text-2)",marginTop:4},children:"â
All data processed"}):"processing"===e?(0,n.jsx)("div",{style:{fontSize:"12px",color:"var(--k-text-2)",marginTop:4},children:"\uD83D\uDD04 Processing recent data updates"}):null})(),o.processing.totalDays>0&&(0,n.jsxs)("div",{style:{fontSize:"14px",color:"var(--k-text-2)"},children:[(0,n.jsxs)("div",{style:{marginBottom:4},children:["Progress: ",o.processing.completionPercentage,"% (",o.processing.completedDays,"/",o.processing.totalDays," days)",(()=>{if(!((null==o?void 0:o.overallStatus)==="processing"&&365===o.processing.totalDays&&o.processing.completedDays<330))return null;let e=365-o.processing.completedDays;return(0,n.jsxs)("span",{style:{marginLeft:8,fontSize:"12px",color:"var(--k-text-3)"},children:["⢠~",Math.round(e/24),"h remaining (estimated)"]})})()]}),(0,n.jsx)("div",{style:{width:"200px",height:"6px",backgroundColor:"var(--k-border-strong)",borderRadius:"3px",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:"".concat(o.processing.completionPercentage,"%"),height:"100%",backgroundColor:h?"var(--k-error)":m?"var(--k-success)":"var(--k-info)",transition:"width 0.3s ease"}})}),o.processing.processingDays>0&&(0,n.jsxs)("div",{style:{marginTop:4,fontSize:"12px"},children:[o.processing.processingDays," days currently processing"]})]}),o.hasData&&o.dateRange.earliest&&o.dateRange.latest&&(0,n.jsxs)("div",{style:{fontSize:"12px",color:"var(--k-text-3)",marginTop:4},children:["Data available: ",new Date(o.dateRange.earliest).toLocaleDateString()," to ",new Date(o.dateRange.latest).toLocaleDateString()]})]})}):null,i&&(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Stops Koast from fetching cost & conversion data from RedTrack. You can reconnect at any time.",buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>j(!0),buttonColor:"error"})]}),(0,n.jsx)(ek,{isConnected:i})]}):(()=>
1{let e=[{title:"Cost & Conversions",description:"Sync spend and conversion data from RedTrack into Koast.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M11.8 10.9c-2.3-.6-3-1.2-3-2.2 0-1.1 1.1-1.9 2.8-1.9 1.9 0 2.5.9 2.6 2.3h2.2c0-1.9-1.2-3.6-3.5-4.2V2.5h-3v2.4c-2.1.5-3.8 1.9-3.8 4 0 2.6 2.1 3.8 5.2 4.6 2.8.7 3.3 1.7 3.3 2.7 0 .8-.6 2-2.8 2-2.1 0-3-.9-3.1-2.3H6.5c.1 2.4 1.9 3.8 4 4.2V22h3v-2.4c2.1-.4 3.8-1.6 3.8-3.9 0-3.2-2.7-4.2-5.5-4.8z"})})},{title:"Campaign Mapping",description:"Automatically map RedTrack campaigns to Koast launches.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM15 19l-6-2.11V5l6 2.11z"})})},{title:"Unified Reporting",description:"See Meta spend and RedTrack conversions side by side.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M3 13h2v8H3zm4-5h2v13H7zm4 2h2v11h-2zm4-4h2v15h-2zm4 6h2v9h-2z"})})}];return(0,n.jsx)($,{logo:(0,n.jsx)(d.gM,{size:36}),haloColorRgb:"255, 71, 61",eyebrow:"Integration \xb7 RedTrack",title:"Connect RedTrack for cost & conversion data",subtitle:"Paste your RedTrack API key to sync performance data from RedTrack to Koast.",features:e,ctaText:"Add API Key",onCtaClick:()=>{v(""),w(""),x(!0)},trustItems:["API key auth","Revoke anytime","Read-only access"]})})())]})]})},{}),icon:(0,n.jsx)(d.gM,{})},{name:"Cometly",component:(0,n.jsx)(()=>{var e,a,t,i;let{hasFetched:l,connection:r,isConnected:o,connect:c,disconnect:u}=(0,eP.q)(),{status:h,hasErrors:m,isCompleted:p}=eT(o,5e3),[v,g]=(0,s.useState)(""),[x,j]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!1),[_,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(""),[C,S]=(0,s.useState)(""),A=B(!l);(0,s.useEffect)(()=>{if(!x||!o){S("");return}let e=v.trim();if(!e){S("");return}let a=!1,t=setTimeout(async()=>{try{let{data:t,success:n}=await (0,f.handleFetch)("/integrations/cometly/key-precheck",{method:"POST",body:{apiKey:e}});if(a)return;S(eI(!!n,null==t?void 0:t.sameSpace))}catch(e){a||S(eA)}},400);return()=>{a=!0,clearTimeout(t)}},[v,x,o]);let I=(null==r?void 0:null===(e=r.metadata)||void 0===e?void 0:e.attributionModel)||"last_platform_touch",P=String(null!==(t=null==r?void 0:null===(a=r.metadata)||void 0===a?void 0:a.attributionWindow)&&void 0!==t?t:"7"),T=async()=>{if(!v.trim()){k("API key is required");return}w(!0),k("");try{await c(v.trim()),j(!1),g("")}catch(e){k(e instanceof Error?e.message:"Failed to connect integration")}finally{w(!1)}},F=async()=>{w(!0),k("");try{await u(),b(!1)}catch(e){k(e instanceof Error?e.message:"Failed to disconnect integration")}finally{w(!1)}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.hB,{id:"cometly-api-key",open:x,onClose:()=>j(!1),width:480,children:(0,n.jsxs)(V.Vq,{onClose:()=>j(!1),title:o?"Update Cometly API Key":"Add Cometly API Key",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>j(!1),children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"primary",onClick:T,loading:_,disabled:!v.trim(),children:"Save"})]}),children:[(0,n.jsx)(ea,{message:N||null,className:"cometly-modal-error"}),(0,n.jsx)(V.gN,{label:"API Key",required:!0,htmlFor:"cometly-api-key-input",hint:(0,n.jsx)("a",{href:"https://app.cometly.com/space/settings/integrations/api",target:"_blank",rel:"noreferrer",children:"Get your API key from Cometly"}),children:(0,n.jsx)(V.oi,{id:"cometly-api-key-input",value:v,onChange:e=>g(e.target.value),placeholder:"Enter your Cometly API key",autoFocus:!0})}),C&&(0,n.jsx)("div",{className:"cometly-modal-space-warning",role:"alert",children:C})]})}),(0,n.jsx)(V.hB,{id:"cometly-disconnect",open:y,onClose:()=>b(!1),width:480,children:(0,n.jsx)(V.Vq,{onClose:()=>b(!1),confirmIcon:"warning",title:"Are you sure you want to disconnect Cometly?",subtitle:"Any Koast features using Cometly data will no longer work until you reconnect.",footer:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(V.Qd,{variant:"ghost",onClick:()=>b(!1),children:"Cancel"}),(0,n.jsx)(V.Qd,{variant:"danger",onClick:F,loading:_,children:"Disconnect"})]}),children:(0,n.jsx)(ea,{message:N||null,className:"cometly-modal-error"})})}),(0,n.jsxs)("div",{className:"cometly-integration-container",children:[A&&(0,n.jsx)(U.DP,{}),!A&&(o?(0,n.jsxs)(U.$i,{header:(0,n.jsxs)("div",{className:"integration-header-with-status",children:[(0,n.jsx)("span",{children:"Cometly Integration"}),o&&(0,n.jsx)(U.RW,{label:"Connected"})]}),children:[(0,n.jsx)("p",{className:"integration-lead",children:"Manage the Cometly connection that syncs multi-touch attribution data into Koast."}),(0,n.jsx)(U.QQ,{header:"Cometly API Key",leftContent:o&&r?(0,n.jsx)("span",{className:"monospace-key",children:(null===(i=r.metadata)||void 0===i?void 0:i.maskedApiKey)||"API Key Set"}):(0,n.jsx)("span",{className:"not-connected",children:"Not Connected"}),buttonText:o?"Change API Key":"Add API Key",buttonVariant:"outlined",buttonOnClick:()=>{g(""),k(""),j(!0)},buttonColor:o?"secondary":"primary"}),o?(0,n.jsx)(U.QQ,{header:"Attribution Settings",leftContent:(0,n.jsxs)("div",{className:"cometly-attribution-fields",children:[(0,n.jsx)(V.gN,{label:"Attribution model",hint:"Fixed to the account default for now.",htmlFor:"cometly-attribution-model",children:(0,n.jsx)(V.px,{id:"cometly-attribution-model",value:I,disabled:!0,children:eF.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(V.gN,{label:"Attribution window",hint:"Fixed to the account default for now.",htmlFor:"cometly-attribution-window",children:(0,n.jsx)(V.px,{id:"cometly-attribution-window",value:P,disabled:!0,children:eE.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})})]})}):null,o&&h?(0,n.jsx)(U.QQ,{header:"Data Processing Status",leftContent:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(()=>{if(!h||!o)return null;switch(h.overallStatus){case"completed":return(0,n.jsx)(eb.Z,{style:{color:"#4caf50",fontSize:20}});case"processing":case"initializing":return(0,n.jsx)(e_.Z,{style:{color:"#2196f3",fontSize:20},className:"rotating"});case"error":return(0,n.jsx)(ew.Z,{style:{color:"#f44336",fontSize:20}});default:return(0,n.jsx)(eN.Z,{style:{color:"#ff9800",fontSize:20}})}})(),(0,n.jsx)("span",{children:h.statusMessage})]}),(()=>{if(!h||!o)return null;let{overallStatus:e}=h;return"completed"===e?(0,n.jsx)("div",{style:{fontSize:"12px",color:"#666",marginTop:4},children:"All data processed."}):"processing"===e?(0,n.jsx)("div",{style:{fontSize:"12px",color:"#666",marginTop:4},children:"Processing recent data updates."}):null})(),h.processing.totalDays>0&&!h.processing.isScanning&&(0,n.jsxs)("div",{style:{fontSize:"14px",color:"#666"},children:[(0,n.jsxs)("div",{style:{marginBottom:4},children:["Progress: ",h.processing.completionPercentage,"% (",h.processing.completedDays,"/",h.processing.totalDays," days)"]}),(0,n.jsx)("div",{style:{width:"200px",height:"6px",backgroundColor:"#e0e0e0",borderRadius:"3px",overflow:"hidden"},children:(0,n.jsx)("div",{style:{width:"".concat(h.processing.completionPercentage,"%"),height:"100%",backgroundColor:m?"#f44336":p?"#4caf50":"#2196f3",transition:"width 0.3s ease"}})}),h.processing.processingDays>0&&(0,n.jsxs)("div",{style:{marginTop:4,fontSize:"12px"},children:[h.processing.processingDays," days currently processing"]})]}),h.hasData&&h.dateRange.earliest&&h.dateRange.latest&&(0,n.jsxs)("div",{style:{fontSize:"12px",color:"#888",marginTop:4},children:["Data available: ",new Date(h.dateRange.earliest).toLocaleDateString()," to ",new Date(h.dateRange.latest).toLocaleDateString()]})]})}):null,o&&(0,n.jsx)(U.QQ,{header:"Disconnect integration",leftContent:"Stops Koast from fetching attribution data from Cometly. You can reconnect at any time.",buttonText:"Disconnect",buttonVariant:"outlined",buttonOnClick:()=>b(!0),buttonColor:"error"})]}):(()=>{let e=[{title:"Multi-Touch Attribution",description:"Sync attribution and conversion data from Cometly into Koast.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"
1currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M11.8 10.9c-2.3-.6-3-1.2-3-2.2 0-1.1 1.1-1.9 2.8-1.9 1.9 0 2.5.9 2.6 2.3h2.2c0-1.9-1.2-3.6-3.5-4.2V2.5h-3v2.4c-2.1.5-3.8 1.9-3.8 4 0 2.6 2.1 3.8 5.2 4.6 2.8.7 3.3 1.7 3.3 2.7 0 .8-.6 2-2.8 2-2.1 0-3-.9-3.1-2.3H6.5c.1 2.4 1.9 3.8 4 4.2V22h3v-2.4c2.1-.4 3.8-1.6 3.8-3.9 0-3.2-2.7-4.2-5.5-4.8z"})})},{title:"Campaign Mapping",description:"Automatically map Cometly campaigns to Koast launches.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM15 19l-6-2.11V5l6 2.11z"})})},{title:"Unified Reporting",description:"See Meta spend and Cometly attribution side by side.",icon:(0,n.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor","aria-hidden":!0,children:(0,n.jsx)("path",{d:"M3 13h2v8H3zm4-5h2v13H7zm4 2h2v11h-2zm4-4h2v15h-2zm4 6h2v9h-2z"})})}];return(0,n.jsx)($,{logo:(0,n.jsx)(d.Qv,{size:36}),haloColorRgb:"31, 41, 55",eyebrow:"Integration \xb7 Cometly",title:"Connect Cometly for multi-touch attribution",subtitle:"Paste your Cometly API key to sync attribution data from Cometly to Koast.",features:e,ctaText:"Add API Key",onCtaClick:()=>{g(""),k(""),j(!0)},trustItems:["API key auth","Revoke anytime","Read-only access"]})})())]})]})},{}),icon:(0,n.jsx)(d.Qv,{})}]}],su=sd[0].options[0].component;var sh=()=>{var e,a;let{user:t,showSettingsModal:r,setShowSettingsModal:u,settingsModalActiveTab:h,setSettingsModalActiveTab:m}=(0,c.bp)(),[p,v]=(0,s.useState)(!1),g=(0,y.om)(),x=(0,y.pn)(),k=(0,w.E)("redtrack-beta",!0),A=(0,y.QP)("integrations"),I=(0,y.QP)("dropbox"),P=(0,y.QP)("google"),T=(0,_.v)(),{connected:F,provider:E}=(0,b.Hq)(),D=null==t?void 0:null===(e=t.roles)||void 0===e?void 0:e.some(e=>"MEDIA BUYER"===e.name.toUpperCase()),L="whop"===(0,eV.Ip)(null==t?void 0:t.activeBrand),{stack:M,push:R,pop:Z}=(0,N.Vu)(),z=(0,N.ni)(M,sc),O=(0,i.Z)("(max-width:768px)");(0,s.useEffect)(()=>{r?R(sc):Z(sc)},[r,R,Z]),(0,s.useEffect)(()=>()=>Z(sc),[Z]),(0,tw.PP)(r);let B=(0,s.useMemo)(()=>{var e,a;return tk(sd,{isOrgAdmin:g,isOrgOwner:x,isMediaBuyer:!!D,isOnAppSumoPlan:!!(null==t?void 0:null===(a=t.subscriptionPlan)||void 0===a?void 0:null===(e=a.planName)||void 0===e?void 0:e.includes("APP_SUMO")),brandReportsAPixel:L,canAccessIntegrations:A,canAccessDropbox:I,canAccessGoogleDrive:P,canUseFrameio:T,hasRedTrackBeta:k})},[g,x,null==t?void 0:null===(a=t.subscriptionPlan)||void 0===a?void 0:a.planName,I,P,T,A,D,L,k]);(0,s.useEffect)(()=>{r&&(0,f.WC)("settings",h)},[h,r]);let V=(0,s.useMemo)(()=>{var e,a;let t=null!==(a=null===(e=B.find(e=>e.name===so))||void 0===e?void 0:e.options)&&void 0!==a?a:[],s=B.flatMap(e=>e.options),i=s.some(e=>e.name===h)?h:F?(0,b.IL)(E):so,l=i===so||t.some(e=>e.name===i);if(O&&t.length>0&&l){let e=i===so?void 0:i;return(0,n.jsx)(sr,{options:t,initialProvider:e})}let r=(null==s?void 0:s.find(e=>e.name===i))||{};return(null==r?void 0:r.component)?r.component:t.length>0?t[0].component:su},[B,h,O,F,E]),K=()=>{p||(v(!0),setTimeout(()=>{u(!1),(0,f.Od)("settings"),m(j.hP),v(!1)},160))};return t?(0,n.jsx)(l.Z,{className:o()("global-settings-modal",{"--open":r,"--covered":z,"--closing":p}),open:r,onClose:K,keepMounted:!0,children:(0,n.jsxs)("div",{className:"global-settings",children:[(0,n.jsx)("button",{type:"button",className:"global-settings-close","aria-label":"Close settings",onClick:K,children:(0,n.jsx)(d.Tw,{width:16,height:16})}),B.length>0&&(0,n.jsx)("div",{className:"global-settings-left",children:(0,n.jsx)(C,{navOptions:B,activeOptionName:h,setActiveOptionName:m})}),V&&(0,n.jsx)("div",{className:"global-settings-right",children:(0,n.jsx)(S,{component:V})})]})}):null}},97256:function(e,a,t){"use strict";var n=t(85893),s=t(67294),i=t(8683),l=t(99697),r=t(41105),o=t(7574),c=t(86e3);t(80968);let d=e=>{if(!e)return"?";let a=e.trim().split(/\s+/);return 1===a.length?a[0].slice(0,2).toUpperCase():(a[0][0]+a[a.length-1][0]).toUpperCase()};a.Z=e=>{let{inModal:a=!1}=e,{user:t,showSettingsModal:u}
1=(0,i.bp)(),[h,m]=(0,s.useState)(null),[p,v]=(0,s.useState)(h),[g,x]=(0,s.useState)(!1),[f,j]=(0,s.useState)(!0),[y,b]=(0,s.useState)(null),[_,w]=(0,s.useState)(!0),N=(0,s.useMemo)(()=>JSON.stringify(h)!==JSON.stringify(p),[h,p]),k=(0,s.useMemo)(()=>{let e={};return h&&p&&Object.keys(p).forEach(a=>{h[a]!==p[a]&&(e[a]=p[a])}),e},[h,p]);(0,s.useEffect)(()=>{C(),S()},[]),(0,s.useEffect)(()=>{a&&u&&(C(),S())},[a,u]);let C=async()=>{var e;let a=await (0,l.handleFetch)("/user/active-brand/settings"),t=null!==(e=null==a?void 0:a.data)&&void 0!==e?e:a;m(t),v(t),j(!1)},S=async()=>{try{let e=await (0,l.handleFetch)("/user/account-stats");(null==e?void 0:e.data)&&b(e.data)}catch(e){console.error("Failed to fetch account stats:",e)}finally{w(!1)}},A=async()=>{var e;if(!N)return;x(!0);let a=await (0,l.handleFetch)("/user/active-brand/settings",{method:"PUT",body:{settings:k}});x(!1),m(null!==(e=null==a?void 0:a.data)&&void 0!==e?e:a)},I=e=>new Date(e).toLocaleDateString("en-US",{month:"long",year:"numeric"}),P=(0,s.useMemo)(()=>{var e;let a=null==t?void 0:null===(e=t.roles)||void 0===e?void 0:e[0];return a?a.name.toLowerCase().replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()):null},[null==t?void 0:t.roles]);return(0,n.jsxs)("div",{className:"account-settings-container",children:[(0,n.jsxs)("div",{className:"panel-head",children:[(0,n.jsx)("h2",{children:"Account"}),(0,n.jsx)("p",{children:"Your personal information and workspace activity."})]}),(0,n.jsxs)("section",{className:"section",children:[(0,n.jsx)("div",{className:"section__title",children:"Account info"}),(()=>{if(!t)return null;let{name:e,email:a}=t;return(0,n.jsxs)("div",{className:"account-info-card",children:[(0,n.jsxs)("div",{className:"account-info-row",children:[(0,n.jsx)("div",{className:"account-info-row__label",children:"Profile"}),(0,n.jsx)("div",{className:"account-info-row__value",children:(0,n.jsxs)("div",{className:"account-avatar-row",children:[(0,n.jsx)("span",{className:"account-avatar-lg",children:d(e)}),(0,n.jsxs)("div",{className:"account-avatar-meta",children:[(0,n.jsx)("div",{className:"account-avatar-name",children:e||"Unnamed user"}),P&&(0,n.jsx)("div",{className:"account-avatar-sub",children:P})]})]})}),(0,n.jsx)("div",{className:"account-info-row__action"})]}),(0,n.jsxs)("div",{className:"account-info-row",children:[(0,n.jsx)("div",{className:"account-info-row__label",children:"Email"}),(0,n.jsx)("div",{className:"account-info-row__value",children:a}),(0,n.jsx)("div",{className:"account-info-row__action"})]}),(null==y?void 0:y.memberSince)&&(0,n.jsxs)("div",{className:"account-info-row",children:[(0,n.jsx)("div",{className:"account-info-row__label",children:"Member since"}),(0,n.jsx)("div",{className:"account-info-row__value",children:I(y.memberSince)}),(0,n.jsx)("div",{className:"account-info-row__action"})]})]})})(),!N||f?null:(0,n.jsxs)("div",{className:"settings-save-cancel-buttons",children:[(0,n.jsx)(o.Z,{onClick:A,disabled:g||!N||f,isLoading:g,loadingText:"Saving...",size:"large",children:"Save Changes"}),(0,n.jsx)(o.Z,{onClick:()=>{v(h)},disabled:g||f,size:"large",variant:"secondary",children:"Cancel"})]})]}),(0,n.jsxs)("section",{className:"section",children:[(0,n.jsx)("div",{className:"section__title",children:"Appearance"}),(0,n.jsxs)("div",{className:"settings-appearance",children:[(0,n.jsxs)("div",{className:"settings-appearance__copy",children:[(0,n.jsx)("div",{className:"settings-appearance__label",children:"Theme"}),(0,n.jsx)("div",{className:"settings-appearance__hint",children:"Light, dark, or match your system."})]}),(0,n.jsx)(c.Z,{inline:!0})]})]}),(0,n.jsxs)("section",{className:"section",children:[(0,n.jsx)("div",{className:"section__title",children:"Activity"}),(()=>{if(_)return(0,n.jsx)("div",{className:"activity-grid activity-grid--loading",children:[1,2,3,4].map(e=>(0,n.jsxs)("div",{className:"activity-stat activity-stat--loading",children:[(0,n.jsx)("div",{className:"activity-stat__icon-skeleton"}),(0,n.jsx)("div",{className:"activity-stat__value-skeleton"}),(0,n.jsx)("div",{className:"activity-stat__label-skeleton"})]},e))});if(!y)return null;let e=[{value:y.launches,label:"Launches",icon:(0,n.jsx)(r.WC,{})},{value:y.generations,label:"Ad generations",icon:(0,n.jsx)(r.R6,{})},{value:y.creatives,label:"Creatives uploaded",icon:(0,n.jsx)(r.XB,{})},{value:y.automations,label:"Automations created",icon:(0,n.jsx)(r.uu,{})}];return(0,n.jsx)("div",{className:"activity-grid",children:e.map(e=>{var a;return(0,n.jsxs)("div",{className:"activity-stat",children:[(0,n.jsx)("div",{className:"activity-stat__top",children:(0,n.jsx)("div",{className:"activity-stat__icon",children:e.icon})}),(0,n.jsx)("div",{className:"activity-stat__value",children:(null!==(a=e.value)&&void 0!==a?a:0).toLocaleStr
1ing()}),(0,n.jsx)("div",{className:"activity-stat__label",children:e.label})]},e.label)})})})()]})]})}},68369:function(e,a,t){"use strict";t.d(a,{Kq:function(){return d},Lb:function(){return o},So:function(){return u},o4:function(){return p},vB:function(){return v},zw:function(){return c}});var n=t(48856),s=t(53438);let i="crossAccountImport",l="crossProviderImport",r="sameAccountImport",o=e=>{let{brandProvider:a,capabilityFor:t}=e;return null!==a&&[r,i,l].some(e=>!(0,n.zZ)(t(e)))},c=e=>{let{brandProvider:a,supportedProviders:t,capabilityFor:s}=e;if(null===a)return[];let o=[];return(0,n.zZ)(s(r))&&(0,n.zZ)(s(i))||o.push(a),(0,n.zZ)(s(l))||t.filter(e=>e!==a).forEach(e=>o.push(e)),o},d=e=>({sameAccount:!(0,n.zZ)(e(r)),crossAccount:!(0,n.zZ)(e(i))}),u=(e,a,t,n)=>{let s=e.flatMap(e=>{let{provider:s,accounts:i}=e;return s!==a?i.map(e=>({...e,provider:s,isDestination:!1})):m(i,s,t,n).map(e=>({...e,provider:s,isDestination:h(s,e,t)}))});return[...s.filter(e=>e.isDestination),...s.filter(e=>!e.isDestination)]},h=(e,a,t)=>{let n=(0,s.t5)(e,t);return!!n&&(0,s.t5)(e,a.externalAccountId)===n},m=(e,a,t,n)=>(0,s.t5)(a,t)?e.filter(e=>h(a,e,t)?n.sameAccount:n.crossAccount):[...e],p=e=>e.sourceConnected?e.sourceAccountId?"campaigns":"accounts":"connect",v=(e,a,t)=>{let n=(null!=a?a:"").trim();return e&&n&&0!==t.length?{campaignIds:[...t],sourceType:"existing",sourceAdAccountId:n,sourceProvider:e}:null}},96612:function(e,a,t){"use strict";t.d(a,{cY:function(){return o}});var n=t(99697),s=t(49832),i=t(68369);let l=(e,a)=>"/ads/providers/".concat(e,"/accounts/").concat(encodeURIComponent(a),"/campaigns"),r=e=>"/v3/campaign-launch/".concat(e,"/import-campaigns");class o{static listAccounts(e){return s.LP.listAccounts(e)}static async listCampaigns(e,a){var t;let i=await (0,n.handleFetch)(l(e,a));if(!(null==i?void 0:i.success))return{ok:!1,failure:(0,s.cg)(null==i?void 0:i.error,"Could not load campaigns for that ad account.")};let r=Array.isArray(i.data)?i.data:null===(t=i.data)||void 0===t?void 0:t.campaigns;return{ok:!0,data:Array.isArray(r)?r:[]}}static async importCampaigns(e,a,t,l){var o,c;let d=(0,i.vB)(a,t,l);if(!d)return{ok:!1,failure:{code:"unknown",message:"Pick an ad account and at least one campaign."}};let u=await (0,n.handleFetch)(r(e),{method:"POST",body:d});return(null==u?void 0:u.success)?{ok:!0,data:{warnings:Array.isArray(null===(o=u.data)||void 0===o?void 0:o.warnings)?u.data.warnings:[],campaignCount:d.campaignIds.length,alreadyImporting:(null===(c=u.data)||void 0===c?void 0:c.alreadyImporting)===!0}}:{ok:!1,failure:(0,s.cg)(null==u?void 0:u.error,"Could not import those campaigns.")}}}},68780:function(e,a,t){"use strict";t.d(a,{o:function(){return r}});var n=t(67294),s=t(49832),i=t(35089);let l=(e,a)=>{let t=e.find(e=>e.brandId===a);return t?t.billable:null},r=(e,a)=>{let t=!!e&&(0,i.N4)(a),r=t?"".concat(e,":").concat(a):"",[o,c]=(0,n.useState)({key:"",billable:null});return(0,n.useEffect)(()=>{if(!t||!e)return;let a=!1;return s.LP.getBrandLaunchReadiness([e]).then(t=>{a||c({key:r,billable:t.ok?l(t.data,e):null})}),()=>{a=!0}},[t,e,r]),!!t&&(o.key===r?o.billable:null)}},50749:function(e,a,t){"use strict";t.d(a,{q:function(){return i}});var n=t(61094),s=t(93086);let i=()=>{let{loading:e,hasFetched:a,connections:t,connect:i,disconnect:l}=(0,s.u)(),r=t[n.tX.COMETLY]||null;return{loading:e,hasFetched:a,connection:r,isConnected:!!r,connect:e=>i(n.tX.COMETLY,e),disconnect:()=>l(n.tX.COMETLY)}}},59079:function(e,a,t){"use strict";t.d(a,{B:function(){return r},_:function(){return o}});var n=t(67294),s=t(61094),i=t(93086),l=t(99697);let r="https://app.hyros.com/external-services/koast",o=()=>{let{loading:e,hasFetched:a,connections:t,disconnect:r,refetch:o}=(0,i.u)(),c=t[s.tX.HYROS]||null;return{loading:e,hasFetched:a,connection:c,isConnected:!!c,exchangeCode:(0,n.useCallback)(async e=>{let{success:a,error:t}=await (0,l.handleFetch)("/integrations/hyros/exchange",{method:"POST",body:{code:e}});if(!a)throw Error((null==t?void 0:t.message)||"Failed to connect Hyros");await o()},[o]),updateAttributionModel:(0,n.useCallback)(async e=>{let{success:a,error:t}=await (0,l.handleFetch)("/integrations/hyros/settings",{method:"PUT",body:{attributionModel:e}});if(!a)throw Error((null==t?void 0:t.message)||"Failed to update the attribution model");await o()},[o]),disconnect:()=>r(s.tX.HYROS)}}},39042:function(e,a,t){"use strict";t.d(a,{J:function(){return i}});var n=t(61094),s=t(93086);let i=()=>{let{loading:e,hasFetched:a,connections:t,connect:i,disconnect:l}=(0,s.u)(),r=t[n.tX.REDTRACK]||null;return{loading:e,hasFetched:a,connection:r,isConnected:!!r,connect:e=>i(n.tX.REDTRACK,e),disconnect:()=>l(n.tX.REDTRACK)}}},90418:function(e,a,t){"use strict";t.d(a,{Y:function(){return r}});var n=t(67294),s=t(61094),i=t(93086),l=t(99697);let r=()=>{let{loading:e,hasFetched:a,connections:t,refetch:r,disconnect:o}
1=(0,i.u)(),c=t[s.tX.SLACK]||null,[d,u]=(0,n.useState)([]),[h,m]=(0,n.useState)(!1),[p,v]=(0,n.useState)(!1),g=(0,n.useCallback)(async()=>{try{var e;let a=await (0,l.handleFetch)("/integrations/slack/auth-url");if(a.success&&(null===(e=a.data)||void 0===e?void 0:e.url))return a.data.url;return null}catch(e){return console.error("Failed to get Slack auth URL:",e),null}},[]),x=(0,n.useCallback)(async()=>{if(c){m(!0);try{let e=await (0,l.handleFetch)("/integrations/slack/channels");e.success&&e.data&&u(e.data)}catch(e){console.error("Failed to fetch Slack channels:",e)}finally{m(!1)}}},[c]);return{loading:e,hasFetched:a,connection:c,isConnected:!!c,getAuthUrl:g,channels:d,loadingChannels:h,fetchChannels:x,updateSettings:(0,n.useCallback)(async(e,a,t)=>{try{var n;let s=await (0,l.handleFetch)("/integrations/slack/settings",{method:"PUT",body:JSON.stringify({channelId:e,channelName:a,isPrivate:t})});if(s.success)return await r(),{success:!0};return{success:!1,error:null===(n=s.error)||void 0===n?void 0:n.message}}catch(e){return console.error("Failed to update Slack settings:",e),{success:!1,error:"Failed to update settings"}}},[r]),sendTestNotification:(0,n.useCallback)(async()=>{v(!0);try{return(await (0,l.handleFetch)("/integrations/slack/test",{method:"POST"})).success}catch(e){return console.error("Failed to send test notification:",e),!1}finally{v(!1)}},[]),testingNotification:p,disconnect:(0,n.useCallback)(async()=>{try{return await o(s.tX.SLACK),u([]),!0}catch(e){return console.error("Failed to disconnect Slack:",e),!1}},[o])}}},95763:function(e,a,t){"use strict";t.d(a,{E:function(){return i},p:function(){return r}});var n=t(58192),s=t(99697);let i=function(e){let a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=(0,n.dl)(e);return!!(0,s.D0)()&&!!a||!!t},l=function(e){let a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=(0,n.ZR)(e);return(0,s.D0)()&&a?"OVERRIDE":t||"control"},r=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return l("dollar-offer",e)}},22589:function(){},71059:function(){},10799:function(){},46413:function(){},3119:function(){},51011:function(){},13746:function(){},62187:function(){},36249:function(){},49907:function(){},71612:function(){},79021:function(){},3811:function(){},5089:function(){},96763:function(){},25966:function(){},41745:function(){},45955:function(){},45486:function(){},7258:function(){},95340:function(){},43023:function(){},38692:function(){},31778:function(){},16418:function(){},84947:function(){},9576:function(){},43500:function(){},2403:function(){},4641:function(){},69135:function(){},27657:function(){}}]);
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.