1import{u as V,r as h,j as e,E as I,aW as Ge,aX as Qe,aY as He,aZ as Ze,a_ as Xe,aC as K,g9 as _e,a1 as xe,a2 as ge,a3 as le,a5 as pe,T as Q,ak as be,al as je,ax as Le,e as Ne,gc as Ye,cw as R,fX as Y,S as ce,bj as ve,aG as de,y as Je,fG as et,iu as ue,aP as G,bl as We,aL as tt,ce as at,fY as me,iv as Oe,fB as Te,iw as Fe,a9 as se,aa as ne,ab as ie,ad as re,fZ as st,ix as nt,iy as it,c9 as rt,iz as lt,iA as Me,be as ct,bf as ot,bg as dt,cd as fe,bh as ye,iB as Ae,iC as ut,iD as mt,iE as xt,bq as gt,d as pt,iF as ht,iG as ft,av as yt,iH as bt,bQ as jt,F as vt}from"./index-6AHMKm1b.js";import{R as Nt}from"./RouteGuard-DrwqEmDx.js";import{B as Ct}from"./BackIcon-Du8_Ckud.js";import{u as St,S as wt,W as kt,A as _t}from"./AgencyWebsiteStatsBar-CXznO6v0.js";import{S as Pe}from"./SearchIcon-CEO72Ymf.js";import{F as Ot}from"./FilterIcon-D7ssDQgN.js";import{A as Tt}from"./AgencyTierLossBanners-CdQTYDjN.js";import{C as Ft}from"./CancelTrialModal-5PPz1Ihk.js";import{E as Mt}from"./ellipsis-vertical-B7M_KyTy.js";import"./ChangePlanNewPricingDialog-ClGD5RKs.js";import"./agencyPlanFeatures-CUNG-t-9.js";import"./agencyDiscount-BdQJ5hVW.js";import"./coupon-C3vzSeyC.js";import"./badge-percent-B2FXwGCI.js";const Lt=({onFilterChange:t,onReset:c,initialState:r,websites:i,isNewPricing:O=!1})=>{const{t:x}=V(),[f,S]=h.useState(r),b=h.useMemo(()=>{const l=new Set(i.map(o=>o.organizationName));return Array.from(l)},[i]),w=h.useMemo(()=>O?[{label:x("agency.addSitePage.planModal.basic"),value:"agency-basic"},{label:x("agency.addSitePage.planModal.pro"),value:"agency-pro"},{label:x("agency.addSitePage.planModal.ultimate"),value:"agency-ultimate"}]:[{label:x("agency.addSitePage.planModal.basic"),value:"agency-yearly"},{label:x("agency.addSitePage.planModal.pro"),value:"agency-pro-monthly"},{label:x("agency.addSitePage.planModal.ultimate"),value:"agency-ultimate-monthly"}],[O,x]),A=h.useMemo(()=>["gdpr","ccpa","gdpr-ccpa"],[]),T=l=>{const o={...f,organisation:l};S(o),t(o)},P=l=>{const o={...f};o.bannerStatus=o.bannerStatus===l?"":l,S(o),t(o)},j=l=>{const o={...f};l==="iab-tcf-v2.3"?(o.iabStatus=!o.iabStatus,o.regulation=""):(o.regulation=o.regulation===l?"":l,o.iabStatus=!1),S(o),t(o)},L=l=>{var k;const o={...f},M=(k=w.find(g=>g.label===l))==null?void 0:k.value;M&&(o.plans=o.plans===M?"":M,S(o),t(o))},m=()=>{const l={organisation:"",bannerStatus:"",regulation:"",plans:"",iabStatus:!1};S(l),c(),t(l)};return e.jsxs("div",{className:"absolute right-0 top-12 z-50 w-96 bg-white rounded-lg shadow-lg p-7",children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("p",{className:"text-xl font-semibold",children:x("agency.filterComponent.title")}),e.jsx(I,{variant:"link",className:"text-primary p-0 text-md font-medium",onClick:m,children:x("agency.filterComponent.resetAll")})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"organisation-select",className:"block text-md font-medium mb-2",children:x("agency.filterComponent.organisationLabel")}),e.jsxs(Ge,{value:f.organisation,onValueChange:T,children:[e.jsx(Qe,{id:"organisation-select",className:"w-full",children:e.jsx(He,{placeholder:x("agency.filterComponent.selectOrganisationPlaceholder")})}),e.jsx(Ze,{children:b.map(l=>e.jsx(Xe,{value:l,children:l},l))})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"banner-status-group",className:"block text-md font-medium mb-3",children:x("agency.filterComponent.bannerStatusLabel")}),e.jsxs("fieldset",{id:"banner-status-group",className:"flex gap-2 border-none p-0 m-0","aria-labelledby":"banner-status-group",children:[e.jsx(K,{variant:f.bannerStatus==="active"?"primary":"secondary",className:"cursor-pointer px-3 py-2 rounded-full",onClick:()=>P("active"),children:x("agency.filterComponent.active")}),e.jsx(K,{variant:f.bannerStatus==="inactive"?"primary":"secondary",className:"cursor-pointer px-3 py-2 rounded-full",onClick:()=>P("inactive"),children:x("agency.filterComponent.inactive")})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"regulation-group",className:"block text-md font-medium mb-3",children:x("agency.filterComponent.regulationLabel")}),e.jsxs("fieldset",{id:"regulation-group",className:"flex flex-wrap gap-2 border-none p-0 m-0","aria-labelledby":"regulation-group",children:[A.map(l=>e.jsx(K,{variant:f.regulation===l?"primary":"secondary",className:"cursor-pointer px-3 py-2 rounded-full",onClick:()=>j(l),children:l==="gdpr"?x("agency.filterComponent.gdpr"):l==="ccpa"?x("agency.filterComponent.usStateLaws"):l==="gdpr-ccpa"?x("agency.filterComponent.gdprAndUsStateLaws"):l},l)),e.jsx(K,{variant:f.iabStatus?"primary":"secondary",className:"cursor-pointer px-3 py-2 rounded-full",onClick:()=>j("iab-tcf-v2.3"),children:x("agency.filterComponent.iabTcf")})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{htmlFor:"plan-group",className:"block text-md font-medium mb-3",children:x("agency.filterComponent.planLabel")}),e.jsx("fieldset",{id:"plan-group",className:"flex flex-wrap gap-3 border-none p-0 m-0","aria-labelledby":"plan-group",children:w.map(l=>e.jsx(K,{variant:f.plans===l.value?"primary":"secondary",className:"cursor-pointer px-3 py-2 rounded-full",onClick:()=>L(l.label),children:l.label},l.label))})]})]})},Wt=({isOpen:t,onClose:c,website:r})=>{const{t:i}=V(),[O,x]=h.useState([]),[f,S]=h.useState(""),[b,w]=h.useState(""),[A,T]=h.useState(!1),[P,j]=h.useState(!1),[L,m]=h.useState(null),l=h.useCallback(async()=>
1{if(r){T(!0);try{const y=await _e.getOrganizationsForCopyConfig(r.id);x(y)}catch(y){console.error(y),m("Failed to load organizations.")}finally{T(!1)}}},[r]);h.useEffect(()=>{t&&r?l():o()},[t,r,l]);const o=()=>{x([]),S(""),w(""),m(null)},M=y=>{S(y),w("")},k=O.find(y=>y.id.toString()===f),F=k?(y=>Array.isArray(y.websites)?y.websites:y.websites&&Array.isArray(y.websites.data)?y.websites.data:[])(k).filter(y=>y.id!==(r==null?void 0:r.id)):[],W=F.find(y=>y.id.toString()===b),B=async()=>{if(!(!r||!k||!W)){j(!0);try{await _e.copyConfiguration({sourceOrgId:r.organization_id,destinationOrgId:k.id,sourceWebsiteId:r.id,destinationWebsiteId:W.id}),c()}catch(y){const D=y instanceof Error?y.message:"Failed to copy configuration.";m(D)}finally{j(!1)}}},z=!f||!b||P||A;return e.jsx(xe,{open:t,onOpenChange:c,children:e.jsxs(ge,{children:[e.jsx(le,{children:e.jsx(pe,{children:i("copyConfiguration.title")})}),e.jsx("div",{className:"text-[16px] text-gray-700 mb-4",children:e.jsx(Q,{i18nKey:"copyConfiguration.description",components:{cookieBanner:e.jsx("b",{}),languageSettings:e.jsx("b",{})}})}),e.jsx(be,{variant:"primary",className:"mb-6",children:e.jsxs("div",{className:"flex",children:[e.jsxs("svg",{className:"w-5 h-5 mr-2 flex-shrink-0 text-primary-dark",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",fill:"none"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 16v-4m0-4h.01"})]}),e.jsx(je,{children:i("copyConfiguration.infoMessage")})]})}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:i("copyConfiguration.dropdownLabel.websiteSelectionTitle")}),e.jsx("input",{type:"text",className:"w-full rounded-md border border-gray-200 bg-gray-50 px-3 py-2 text-gray-700 text-base outline-none cursor-not-allowed",value:(r==null?void 0:r.url)||"",disabled:!0})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[i("copyConfiguration.dropdownLabel.OrganizationSelectionTitle")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{className:"w-full rounded-md border border-gray-200 px-3 py-2 text-gray-700 text-base outline-none",value:f,onChange:y=>M(y.target.value),disabled:A,children:[e.jsx("option",{value:"",children:i("copyConfiguration.dropdownLabel.OrganizationPlaceholder")}),O.map(y=>e.jsxs("option",{value:y.id,children:[y.name," (",y.id,")"]},y.id))]}),A&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:i("common.loading")})]}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:[i("copyConfiguration.dropdownLabel.DestinationWebsiteTitle")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{className:"w-full rounded-md border border-gray-200 px-3 py-2 text-gray-700 text-base outline-none",value:b,onChange:y=>w(y.target.value),disabled:!f,children:[e.jsx("option",{value:"",children:i("copyConfiguration.dropdownLabel.DestinationWebsitePlaceholder")}),F.map(y=>e.jsx("option",{value:y.id,children:y.url},y.id))]}),k&&F.length===0&&e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:i("copyConfiguration.dropdownLabel.emptyWebsites")})]}),L&&e.jsx("p",{className:"text-sm text-red-500 mb-4",children:L}),(W==null?void 0:W.showLowerPlanWarningBanner)&&e.jsx(be,{variant:"warning",className:"mb-4",children:e.jsxs("div",{className:"flex",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"mr-2 flex-shrink-0 text-warning-dark",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]}),e.jsx(je,{children:i("copyConfiguration.lowerPlanWebsiteAlert")})]})}),e.jsxs(Le,{children:[e.jsx(I,{variant:"secondary-light",onClick:c,className:"text-base font-medium",disabled:P,children:i("common.cancel")}),e.jsx(I,{variant:"primary",onClick:B,disabled:z,className:"text-base font-medium",children:P?"Publishing...":i("copyConfiguration.publish")})]})]})})},At=({isOpen:t,onClose:c,website:r,onDelete:i,isAgency:O,organizationId:x})=>{const{t:f}=V(),S=Ne(),{mutate:b,isPending:w}=Ye(),A=R(k=>k.pricingModel),T=R(k=>{var g,F,W;return((F=(g=k.websiteCounts)==null?void 0:g.by_status)==null?void 0:F.active)??((W=k.license)==null?void 0:W.active_sites)??0}),P=!!(O&&r&&A==="v2"),{currentTier:j,futureTier:L,willLoseTier:m}=h.useMemo(()=>
1{if(!P)return{currentTier:Y(0),futureTier:Y(0),willLoseTier:!1};const k=Y(T),g=Y(Math.max(0,T-1));return{currentTier:k,futureTier:g,willLoseTier:k.key!==g.key}},[P,T]),l=()=>{c(),S({to:"/agency/add-site"})},o=h.useRef(!1),M=k=>{if(o.current)return;o.current=!0;const g=()=>{o.current=!1};try{k.parent_website_id?g():O?b({websiteId:k.id,organizationId:x},{onSuccess:()=>{i(k),c()},onSettled:g}):g()}catch(F){console.error(F),g()}};return e.jsx(xe,{open:t,onOpenChange:c,children:e.jsxs(ge,{children:[e.jsx(le,{children:e.jsx(pe,{children:f("webappUserSubscriptions.deleteModal.title")})}),P?e.jsxs("div",{className:"mb-6 mt-2 flex flex-col gap-5 text-md font-normal text-secondary-dark",children:[e.jsx("p",{className:"m-0 leading-[1.5]",children:e.jsx(Q,{i18nKey:"agency.deleteSiteModal.introBody",values:{url:(r==null?void 0:r.url)??""},components:{urlWrap:e.jsx("span",{className:"font-semibold text-inherit"}),warnWrap:e.jsx("span",{className:"font-semibold text-inherit"})}})}),e.jsx(Tt,{willLoseTier:m,currentTier:j,futureTier:L,onAddSiteClick:l,variant:"deleteSite"})]}):e.jsx("div",{className:"mb-6 mt-2 text-md font-normal text-secondary-dark",children:e.jsx(Q,{i18nKey:"webappUserSubscriptions.deleteModal.agencyText",values:{url:r==null?void 0:r.url},components:{b:e.jsx("b",{})}})}),e.jsxs(Le,{className:"flex justify-end items-center gap-2",children:[e.jsx(I,{variant:"secondary-light",onClick:c,className:"text-base font-medium",disabled:w,children:f("common.cancel")}),e.jsx(I,{variant:"danger",onClick:()=>M(r),className:"text-base font-medium",disabled:w,children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[f("webappUserSubscriptions.deleteModal.delete"),w&&e.jsx(ce,{className:"h-4 w-4"})]})})]})]})})},Pt=t=>{const{views:c,views_limit:r}=t;return r?Math.min(c/r*100,100):0},It=t=>t&&typeof t=="object"&&t.pageviews&&typeof t.pageviews=="object"&&"views"in t.pageviews&&"views_limit"in t.pageviews?{views:Number(t.pageviews.views)||0,views_limit:Number(t.pageviews.views_limit)||0}:{views:0,views_limit:0},Bt=(t,c)=>{if(!t)return"";const i=t.toLowerCase().split("-").map(O=>{switch(O){case"gdpr":return"GDPR";case"ccpa":return"US State Laws";default:return O.toUpperCase()}});return i.length===2?e.jsxs(e.Fragment,{children:[i[0]," ",e.jsx("br",{})," & ",i[1],c&&e.jsxs(e.Fragment,{children:[e.jsx("br",{}),"(IAB TCF v2.3)"]})]}):c?e.jsxs(e.Fragment,{children:[i[0],e.jsx("br",{}),"(IAB TCF v2.3)"]}):i.join(", ")},Ie=h.memo(({value:t,onChange:c})=>{const{t:r}=V();return e.jsxs("div",{className:"flex items-center gap-3 w-80 bg-secondary-lightest px-7 py-3 rounded-lg",children:[e.jsx(Pe,{svgColor:"secondary-dark",width:16,height:16}),e.jsx(ve,{placeholder:r("agency.websites.searchWebsite"),className:"flex-1 border-none bg-transparent p-0 h-auto focus-visible:outline-none placeholder:text-secondary-dark",value:t,onChange:i=>c(i.target.value),"data-testid":"search-input"})]})});Ie.displayName="SearchBar";const Be=h.memo(({isActive:t,onClick:c})=>e.jsxs(I,{className:"flex gap-1 ml-4 bg-secondary-lightest text-dark border-0",onClick:c,children:[t?"Show all":"Filter by",e.jsx(Ot,{svgColor:"dark"})]}));Be.displayName="FilterButton";const De=h.memo(({website:t,index:c,planSlug:r,extendedWebsite:i,isNewPricing:O,isAgencyLicenseSuspended:x,isAccountOwner:f,reactivatingWebsiteId:S,onCopyInstallationCode:b,onDeleteSite:w,onReactivate:A,onCancelTrial:T,pricingModel:P,t:j})=>{var M,k;const{safePageViews:L,usagePercent:m}=h.useMemo(()=>{const g=It(t);return{safePageViews:g,usagePercent:Pt(g)}},[t]),l=h.useMemo(()=>{const g=t.url||"",F=g.length>Oe,W=Te(g,Oe);return{url:g,isUrlTruncated:F,displayUrl:W}},[t.url]),o=h.useMemo(()=>{const g=t.organizationName||"",F=g.length>Fe,W=Te(g,Fe);return{orgName:g,isTruncated:F,displayName:W}},[t.organizationName]);return e.jsxs("tr",{className:"group hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-normal text-md leading-5 text-secondary-dark",children:t.organization||""}),l.isUrlTruncated?e.jsx(se,{children:e.jsxs(ne,{children:[e.jsx(ie,{asChild:!0,children:e.jsx("div",{className:"text-xs font-normal text-gray-400 cursor-default","data-testid":`site-url-${t.id}`,"aria-label":l.url,tabIndex:0,children:l.displayUrl})}),e.jsx(re,{side:"top",className:"whitespace-nowrap max-w-none","data-testid":`site-url-tooltip-${t.id}`,children:l.url})]})}):e.jsx("div",{className:"text-xs font-normal text-gray-400","data-testid":`site-url-${t.id}`,children:l.displayUrl})]})}),e.jsx("td",{className:"px-6 py-4 text-dark",children:o.isTruncated?e.jsx(se,{children:e.jsxs(ne,{children:[e.jsx(ie,{asChild:!0,children:e.jsx("div",{className:"text-md font-normal text-secondary-dark cursor-default","data-testid":`org-name-${t.id}`,children:o.displayName})}),e.jsx(re,{side:"top",className:"whitespace-nowrap max-w-none","data-testid":`org-name-tooltip-${t.id}`,children:o.orgName})]})}):e.jsx("div",{className:"text-md font-normal text-secondary-dark","data-testid":`org-name-${t.id}`,children:o.displayName})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-gray-900",children:st(String(t.created_at||""))}),e.jsx("div",{className:"text-sm text-gray-400",children:nt(String(t.created_at||""))})]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs(K,{variant:it(r),children:[me(r),t.is_trial?` ${j("agency.trialSuffix")}`:""]})}),O&&e.jsx("td",{className:"px-6 py-4 text-gray-600","data-testid":`trial-status-${t.id}`,children:t.trial_ends_at?lt(t.trial_ends_at)?j("agency.trialEnded"):rt(new Date(t.trial_ends_at),"MMM dd, yyyy"):"-"}),e.jsx("td",{className:"px-6 py-4 text-gray-600",children:Bt(String(i.applicableLaw??""),!!i.iabStatus)}),e.jsx("td",{className:"px-6 py-4",children:e.jsx(K,{variant:Me(t)?"success":"danger",children:Me(t)?"Active":"Inactive"})}),e.jsx("td",{className:"px-6 py-4",children:t.website_status==="paymentPending"?e.jsx("span",{className:"text-sm text-gray-600",children:"-"}):e.jsxs("div",{className:"flex flex-col gap-2",children:[me(r)==="Agency Ultimate"?e.jsx("span",{className:"text-sm text-gray-600","data-testid":"unlimited-text",children:j("agency.unlimited")}):e.jsx("span",{className:"text-sm text-gray-600",children:`${(L.views||0).toLocaleStr
1ing()} /${(L.views_limit||0).toLocaleString()}`}),me(r)!=="Agency Ultimate"&&e.jsx("div",{className:"h-1.5 w-24 rounded-full bg-gray-100","data-testid":"progress-bar-container",children:e.jsx("div",{className:"h-1.5 rounded-full bg-blue-600",style:{width:`${m}%`},"data-testid":"progress-bar"})})]})}),e.jsx("td",{className:"px-6 py-4 sticky right-0 z-10 bg-white group-hover:bg-gray-50","data-testid":`actions-cell-${t.id}`,children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex flex-1 items-center justify-center gap-4","data-testid":`actions-content-${t.id}`,children:(M=t.website_metadata)!=null&&M.has_scheduled_trial_cancellation?e.jsx(wt,{website:t,onReactivate:A,isReactivating:S===t.id}):e.jsx(kt,{website:t,index:c,isAgencyLicenseSuspended:x,t:j})}),e.jsxs(ct,{children:[e.jsx(ot,{asChild:!0,children:e.jsx("button",{className:"w-10 h-10 flex items-center justify-center p-0 bg-transparen hover:bg-gray-100 focus:outline-none","aria-label":"More actions",type:"button",children:e.jsx(Mt,{className:"w-5 h-5"})})}),e.jsxs(dt,{align:"end",sideOffset:4,className:"w-auto p-0 shadow-lg",children:[t.website_status!=="paymentPending"&&(()=>{const g=f||fe("organization::website:copy-installation-code",t.organization_id);return e.jsx(se,{children:e.jsxs(ne,{children:[e.jsx(ie,{asChild:!0,children:e.jsx("div",{children:e.jsx(ye,{className:"px-4 py-2 text-sm text-secondary-dark cursor-pointer hover:bg-gray-50 data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed",disabled:!g,onClick:()=>{g&&setTimeout(()=>b(t),0)},role:"menuitem","data-testid":`copy-installation-code-item-${t.id}`,children:j("agency.copyInstallationCode")})})}),!g&&e.jsx(re,{side:"right",sideOffset:5,"data-testid":`copy-installation-code-tooltip-${t.id}`,children:e.jsx("p",{className:"text-xs",children:e.jsx(Q,{i18nKey:"permissions.permissionMessage.copyInstallationCode",components:{bold:e.jsx("strong",{})},values:{accountOwner:j("permissions.roles.accountOwner")}})})})]})})})(),(()=>{const g=f||fe("organization::website:delete",t.organization_id);return e.jsx(se,{children:e.jsxs(ne,{children:[e.jsx(ie,{asChild:!0,children:e.jsx("div",{children:e.jsx(ye,{className:"px-4 py-2 text-sm text-secondary-dark cursor-pointer hover:bg-gray-50 data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed",disabled:!g,onClick:()=>{g&&setTimeout(()=>w(t),0)},role:"menuitem","data-testid":`delete-site-item-${t.id}`,children:j("agency.deleteSite")})})}),!g&&e.jsx(re,{side:"right",sideOffset:5,"data-testid":`delete-site-tooltip-${t.id}`,children:e.jsx("p",{className:"text-xs",children:e.jsx(Q,{i18nKey:"permissions.permissionMessage.deleteWebsite",components:{bold:e.jsx("strong",{})},values:{accountOwner:j("permissions.roles.accountOwner")}})})})]})})})(),P==="v2"&&t.is_trial===!0&&t.status!=="draft"&&!((k=t.website_metadata)!=null&&k.has_scheduled_trial_cancellation)&&(()=>
1{const g=f||fe("organization::website:cancel-trial",t.organization_id);return e.jsx(se,{children:e.jsxs(ne,{children:[e.jsx(ie,{asChild:!0,children:e.jsx("div",{children:e.jsx(ye,{className:"px-4 py-2 text-sm text-secondary-dark cursor-pointer hover:bg-gray-50 data-[disabled]:opacity-50 data-[disabled]:cursor-not-allowed",disabled:!g,onClick:()=>{g&&setTimeout(()=>T(t.id),0)},role:"menuitem","data-testid":`cancel-trial-item-${t.id}`,children:j("agency.cancelTrial.dropdownLabel")})})}),!g&&e.jsx(re,{side:"right",sideOffset:5,"data-testid":`cancel-trial-tooltip-${t.id}`,children:e.jsx("p",{className:"text-xs",children:e.jsx(Q,{i18nKey:"permissions.permissionMessage.cancelTrial",components:{bold:e.jsx("strong",{})},values:{accountOwner:j("permissions.roles.accountOwner")}})})})]})})})()]})]})]})})]})});De.displayName="WebsiteTableRow";const Dt=({apiParams:t})=>{const{t:c}=V(),r=R(a=>a.isAgencyLicenseSuspended()),i=de(a=>a.isAgency()),O=de(a=>a.accountID()),x=R(a=>{var E,U;const _=(E=a.websiteCounts)==null?void 0:E.by_status;return _?_.active-(_.scheduled_cancellation??0):((U=a.license)==null?void 0:U.active_sites)??0}),f=R(a=>a.pricingModel),S=f==="v2",b=S?9:8,w=Je(a=>{var _;return(_=a.user)==null?void 0:_.id}),A=de(a=>{var _;return(_=a.account)==null?void 0:_.user_id}),T=w!==void 0&&w===A;et(a=>a.organizations);const[P,j]=h.useState(!1),[L,m]=h.useState(!1),[l,o]=h.useState(null),[M,k]=h.useState(null),g=h.useRef(null),{data:F,isLoading:W,isFetchingNextPage:B,fetchNextPage:z,hasNextPage:y}=ue(t),D=(F==null?void 0:F.pages.flatMap(a=>a.data||[]))||[],{reactivatingWebsiteId:J,handleReactivate:ee}=St(D);h.useEffect(()=>{if(!y||B)return;const a=new window.IntersectionObserver(E=>{E[0].isIntersecting&&z()}),_=g.current;return _&&a.observe(_),()=>{_&&a.unobserve(_)}},[y,B,z]);const q=h.useCallback(a=>a&&typeof a=="object"&&a.websiteplan&&typeof a.websiteplan=="object"&&"slug"in a.websiteplan?String(a.websiteplan.slug):"",[]),H=h.useCallback(a=>{const _=`<!-- Start cookieyes banner --> <script id="cookieyes" type="text/javascript" src="https://cdn-cookieyes.com/client_data/${a.key}/script.js"><\/script> <!-- End cookieyes banner -->`;navigator.clipboard.writeText(_).then(()=>{G.success(c("agency.installationCodeCopied"),{className:"!bg-[#b3ded0] !text-[#14142a] !border-[#b3ded0] !rounded",icon:e.jsx(We,{className:"w-5 h-5",color:"#00754E"})})}).catch(()=>{G.error(c("agency.installationCodeCopyFailed"),{className:"!bg-red-100 !text-[#14142a] !border-red-100 !rounded"})})},[c]),Z=h.useCallback(a=>{o(a),m(!0)},[]),X=()=>{m(!1)};return W?e.jsx("div",{className:"mt-8 overflow-hidden rounded-lg shadow-sm bg-white p-8 min-h-[300px] flex items-center justify-center",children:e.jsx(tt,{isCardLoader:!0,"data-testid":"loader"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto rounded-xl bg-white mx-8 min-h-[500px] flex flex-col",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-[#F8F9FF] text-secondary-dark",children:e.jsxs("tr",{children:[e.jsx("th",{className:"whitespace-nowrap pl-px-7 px-6 py-4 text-left align-top font-medium",children:c("agency.website")}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:c("agency.organisation")}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{children:c("agency.createdDateShort")}),e.jsx("span",{className:"text-xs text-gray-400 font-normal",children:c("agency.createdDateShortTooltip")})]})}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:c("agency.plan")}),S&&e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:c("agency.trialStatus")}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:c("agency.regulation")}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:c("agency.bannerStatus")}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-left align-top font-medium",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{children:c("agency.pageViews")}),e.jsx("span",{className:"text-xs text-gray-400 font-normal",children:c("agency.pageViewsPerMonthQualifier")})]})}),e.jsx("th",{className:"whitespace-nowrap px-6 py-4 text-center align-top font-medium sticky right-0 z-10 bg-[#F8F9FF]","data-testid":"actions-header-sticky",children:c("agency.actions")})]})}),e.jsxs("tbody",{className:"divide-y divide-gray-100",children:[D.map((a,_)=>{const E=q(a),U=a;return e.jsx(De,{website:a,index:_,planSlug:E,extendedWebsite:U,isNewPricing:S,isAgencyLicenseSuspended:r,isAccountOwner:T,reactivatingWebsiteId:J,onCopyInstallationCode:H,onDeleteSite:Z,onReactivate:ee,onCancelTrial:k,pricingModel:f,t:c},a.id||_)}),D.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:b,className:"px-6 py-4 text-center text-gray-500",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(at,{className:"mb-2"}),e.jsx("p",{className:"text-secondary-dark text-xl font-semibold mb-2",children:c("agency.websites.noWebsitesFound")}),e.jsx("div",{className:"text-secondary-dark text-md mb-2",children:c("agency.websites.startImplementing")})]})})}),y&&e.jsx("tr",{children:e.jsx("td",{colSpan:b,className:"px-6 py-4 text-center",children:e.jsx("div",{ref:g,style:{minHeight:40},children:B&&e.jsx(ce,{className:"mx-auto h-6 w-6 border-secondary-dark border-t-transparent","data-testid":"spinner"})})})})]})]})}),e.jsx(Wt,{isOpen:P,onClose:()=>j(!1),website:l}),e.jsx(At,{isOpen:L,onClose:()=>m(!1),website:l,onDelete:X,isAgency:i,organizationId:O}),(()=>{const a=D.find(he=>he.id===M);if(!a)return null;const _=Y(x),E=Y(Math.max(0,x-1)),U=q(a);return e.jsx(Ft,{isOpen:M!==null,onClose:()=>k(null),websiteId:a.id,websiteUrl:a.url,trialEndsAt:a.trial_ends_at,planName:me(U),currentTier:_,futureTier:E,willLoseTier:_.key!==E.key})})()]})},Et=({websites:t,apiParams:c,searchText:r,setSearchText:i,filterState:O,onFilterChange:x,onFilterReset:f})=>{const[S,b]=h.useState(!1),w=R(T=>T.pricingModel),A=h.useRef(null);return h.useEffect(()=>{function T(P){const j=P.target,L=j.closest('[role="listbox"]');A.current&&!A.current.contains(j)&&!L&&b(!1)}return S&&document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[S]),e.jsxs("div",{className:"mt-8 overflow-hidden rounded-lg shadow-sm bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between bg-white mx-8 my-6",children:[e.jsx(Ie,{value:r,onChange:i}),e.jsxs("div",{className:"relative",ref:A,children:[e.jsx(Be,{isActive:Object.values(O).some(T=>!!T),onClick:()=>{Object.values(O).some(T=>!!T)?f():b(!S)}}),S&&e.jsx(Lt,{onFilterChange:x,onReset:f,initialState:O,websites:t,isNewPricing:w==="v2"})]})]}),e.jsx(Dt,{apiParams:c})]})}
1,zt=({width:t=50,height:c=50,svgColor:r="#B13548",fillColor:i="#EC4A5E"})=>e.jsxs("svg",{width:t,height:c,viewBox:"0 0 50 50",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{width:"50",height:"50",rx:"8",fill:i,fillOpacity:"0.3"}),e.jsx("path",{d:"M25 20.0001V22.6668M25 28.0001V28.0134M15.6666 33.3334H34.3333C34.7684 33.3304 35.1961 33.2209 35.5792 33.0146C35.9622 32.8083 36.289 32.5114 36.5309 32.1498C36.7729 31.7881 36.9227 31.3728 36.9672 30.94C37.0118 30.5072 36.9498 30.0701 36.7866 29.6668L27.32 13.3334C27.0894 12.9166 26.7513 12.5692 26.341 12.3273C25.9306 12.0854 25.463 11.9578 24.9866 11.9578C24.5103 11.9578 24.0426 12.0854 23.6323 12.3273C23.222 12.5692 22.8839 12.9166 22.6533 13.3334L13.1866 29.6668C13.0266 30.0609 12.9631 30.4875 13.0015 30.9112C13.0399 31.3348 13.1791 31.7431 13.4075 32.102C13.6359 32.4608 13.9468 32.7599 14.3143 32.9741C14.6818 33.1883 15.0952 33.3115 15.52 33.3334",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Rt=({isOpen:t,onClose:c,onConfirm:r,websiteUrl:i,nextBillingDate:O,isLoading:x})=>{const{t:f}=V();return e.jsx(xe,{open:t,onOpenChange:c,children:e.jsxs(ge,{className:"sm:max-w-[500px]",children:[e.jsx(le,{children:e.jsx(pe,{children:f("agency.addOn.modal.cancelConfirmation.title")})}),e.jsx("div",{className:"bg-orange-50 border border-orange-100 rounded-lg p-4 mb-6 text-md",children:e.jsx(Q,{i18nKey:"agency.addOn.modal.cancelConfirmation.message",values:{websiteUrl:i,nextBillingDate:O},components:{1:e.jsx("span",{className:"font-medium"})}})}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(I,{variant:"secondary-light",onClick:c,disabled:x,className:"text-base font-medium",children:f("agency.addOn.modal.noKeep")}),e.jsx(I,{variant:"danger",onClick:r,disabled:x,children:x?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2"}),f("agency.addOn.modal.cancelling")]}):f("agency.addOn.modal.yesCancel")})]})]})})},qt=({isOpen:t,onClose:c,websites:r=[]})=>{const{t:i}=V(),O=Ne(),x=R(s=>s.getAddOns()),f=de(s=>s.accountID()),{isLoading:S}=Ae(),{data:b,isLoading:w}=ut(f),{mutateAsync:A,isPending:T}=mt(),{mutateAsync:P}=xt(),[j,L]=h.useState(""),[m,l]=h.useState(null),[o,M]=h.useState({}),[k,g]=h.useState({}),[F,W]=h.useState({isOpen:!1,websiteId:null,websiteUrl:"",nextBillingDate:""}),[B,z]=h.useState(!1),y=r.filter(s=>s.url.toLowerCase().includes(j.toLowerCase()));h.useEffect(()=>{t||(l(null),M({}),g({}),L(""))},[t]),h.useEffect(()=>{if(m){const s=r.reduce((u,n)=>{const p=b==null?void 0:b.websites.find(N=>N.website_id===n.id),d=p==null?void 0:p.addons.find(N=>N.plan_id===m.id);return u[n.url]={selected:!1,quantity:0,id:n.id},(d==null?void 0:d.status)==="active"&&(u[n.url]={selected:!0,quantity:d.quantity,id:n.id},g(N=>({...N,[n.url]:{quantity:d.quantity,id:n.id}}))),u},{});M(s)}},[m,r,b]);const D=s=>{l(s),M({}),g({})},J=(s,u)=>{const n=r.find(p=>p.url===s);n&&M(p=>{var C;const d=b==null?void 0:b.websites.find(te=>te.website_id===n.id),N=d==null?void 0:d.addons.find(te=>te.plan_id===(m==null?void 0:m.id)),v={...p,[s]:{selected:u,quantity:u?1:0,id:n.id}};return(N==null?void 0:N.status)==="active"&&(v[s]={selected:!0,quantity:((C=p[s])==null?void 0:C.quantity)||N.quantity,id:n.id}),v})},ee=(s,u)=>{const n=r.find(d=>d.url===s);if(!n)return;const p=Math.min(Math.max(u,0),100);M(d=>({...d,[s]:{...d[s],quantity:p,id:n.id}}))},q=()=>y.filter(s=>{var u;return(((u=s.pageviews)==null?void 0:u.views_limit)||0)>0}).map(s=>s.url),H=()=>{const s=q(),u=s.every(p=>{const d=o[p];if(!d)return!1;const N=b==null?void 0:b.websites.find(C=>C.website_id===d.id);return(N==null?void 0:N.addons.some(C=>C.plan_id===(m==null?void 0:m.id)&&C.status==="active"))||d.selected}),n={...o};s.forEach(p=>{const d=n[p];if(!d)return;const N=b==null?void 0:b.websites.find(C=>C.website_id===d.id);(N==null?void 0:N.addons.some(C=>C.plan_id===(m==null?void 0:m.id)&&C.status==="active"))||(n[p]={...d,selected:!u,quantity:u?0:1})}),M(n)},Z=()=>{const s=q(),u={...o};s.forEach(n=>{const p=u[n];if(!p)return;const d=b==null?void 0:b.websites.find(v=>v.website_id===p.id);(d==null?void 0:d.addons.some(v=>v.plan_id===(m==null?void 0:m.id)&&v.status==="active"))||(u[n]={...p,selected:!1,quantity:0})}),M(u)},X=()=>m?Object.entries(o).reduce((s,[,u])=>u.selected&&u.quantity>0?s+m.cost*u.quantity:s,0):0,a=()=>{l(null),M({})},_=async()=>{var u;if(!m||!f){G.error(i("agency.addOn.modal.errors.somethingWrong"),{className:"!bg-red-100 !text-[#14142a] !border-red-100 !rounded"});return}const s=Object.entries(o).filter(([,n])=>n.selected).map(([,n])=>({website_id:n.id,quantity:n.quantity||1}
1));if(s.length===0){G.error(i("agency.addOn.modal.errors.selectWebsite"),{className:"!bg-red-100 !text-[#14142a] !border-red-100 !rounded"});return}try{const n=await A({account_id:f,addon_plan_id:m.id,websites:s});if(c(),n.invoice_url){const p=window.open(n.invoice_url,"stripe_invoice","noopener,noreferrer");p==null||p.focus(),setTimeout(()=>{p==null||p.focus()},100)}else(n==null?void 0:n.success)===!0?O({to:"/payment/add-ons",search:{status:"success",plan_id:m.id}}):G.error(i("agency.addOn.modal.errors.retryPayment"),{className:"!bg-red-100 !text-[#14142a] !border-red-100 !rounded"})}catch(n){c();const p=n;if((u=p==null?void 0:p.response)!=null&&u.data){const{code:d,invoice_url:N,subscription_id:v}=p.response.data;if(N){const C=window.open(N,"stripe_invoice","noopener,noreferrer");C==null||C.focus(),setTimeout(()=>{C==null||C.focus()},100);return}if(d==="agency.addon.payment_declined"&&v){O({to:"/payment/add-ons",search:{status:"failed",subscription_id:v.toString()}});return}}O({to:"/payment/add-ons",search:{status:"failed",plan_id:m.id}})}},E=async s=>{const u=r.find(v=>v.id===s);if(!u)return;const n=b==null?void 0:b.websites.find(v=>v.website_id===s),p=n==null?void 0:n.addons.find(v=>v.plan_id===(m==null?void 0:m.id));if(!(p!=null&&p.next_billing_date)){const v=new Date;v.setMonth(v.getMonth()+1);const C=v.toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"});W({isOpen:!0,websiteId:s,websiteUrl:u.url,nextBillingDate:C});return}const N=new Date(p.next_billing_date).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"});W({isOpen:!0,websiteId:s,websiteUrl:u.url,nextBillingDate:N})},U=async()=>{if(!(!F.websiteId||!f)){z(!0);try{await P({website_id:F.websiteId,account_id:f});const s=r.find(u=>u.id===F.websiteId);s&&(M(u=>({...u,[s.url]:{...u[s.url],selected:!1,quantity:0}})),g(u=>({...u,[s.url]:null}))),G.success(i("agency.addOn.modal.cancelConfirmation.successMessage"),{className:"!bg-[#b3ded0] !text-[#14142a] !border-[#b3ded0] !rounded",icon:e.jsx(We,{className:"w-5 h-5",color:"#00754E"})}),W(u=>({...u,isOpen:!1}))}catch{G.error(i("agency.addOn.modal.cancelConfirmation.errorMessage"),{className:"!bg-red-100 !text-[#14142a] !border-red-100 !rounded"})}finally{z(!1)}}},he=()=>Object.values(o).every(s=>!s.selected||s.selected&&s.quantity>=1&&s.quantity<=100),Ee=()=>he()?Object.entries(o).some(([s,u])=>{const n=k[s];return!!(u.selected&&!n||!u.selected&&n||u.selected&&n&&u.quantity!==n.quantity)}):!1,ze=s=>[...y].filter(n=>{var p;return(((p=n.pageviews)==null?void 0:p.views_limit)||0)>0}).sort((n,p)=>{var v,C;const d=((v=n.pageviews)==null?void 0:v.views)||0;return(((C=p.pageviews)==null?void 0:C.views)||0)-d}).map(n=>{var Ce,Se,we,ke;const p=b==null?void 0:b.websites.find($=>$.website_id===n.id),d=p==null?void 0:p.addons.find($=>$.plan_id===s.id),N=(d==null?void 0:d.status)==="active",v=n.pageviews||{views:0,views_limit:0},C=new Intl.NumberFormat().format(v.views),te=new Intl.NumberFormat().format(v.views_limit),ae=((Ce=o[n.url])==null?void 0:Ce.selected)||!1,oe=((Se=o[n.url])==null?void 0:Se.quantity)||0,Ue=s.features.page_view_limit||0,Ve=oe*Ue,$e=(((ke=(we=n.websiteplan)==null?void 0:we.features)==null?void 0:ke.page_view_limit)||0)+Ve,Ke=ae&&((d==null?void 0:d.quantity)!==oe||!(d!=null&&d.status));return e.jsxs("div",{className:"flex items-center gap-3 py-2 border-b last:border-b-0",children:[e.jsx(gt,{checked:ae,disabled:N,onCheckedChange:$=>!N&&J(n.url,$),"data-testid":`website-checkbox-${n.url}`}),e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500",children:"ð"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs",children:n.url}),e.jsx("span",{className:"text-xs text-gray-500",children:i("agency.addOn.modal.pageViews.used",{used:C,limit:te})}),Ke&&e.jsx("span",{className:"text-xs text-blue-600",children:i("agency.addOn.modal.pageViews.new",{limit:new Intl.NumberFormat().format($e)})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{type:"number",min:"1",max:"100",disabled:!ae,value:oe===0?"":oe,onChange:$=>ee(n.url,parseInt($.target.value)||0),className:"w-16 h-9 rounded-md border border-gray-200 bg-white px-2 py-1 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-200 focus-visible:ring-offset-0","data-testid":`quantity-input-${n.url}`}),e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>E(n.id),className:`px-4 py-1 rounded ${ae&&N?"bg-red-50 text-red-500 hover:bg-red-100 hover:text-red-600":"bg-gray-100 text-gray-400 hover:bg-gray-200"}`,disabled:!ae||!N,"data-testid":`cancel-button-${n.url}`,children:i("agency.addOn.modal.cancel")})]})]},n.url)}),Re=()=>e.jsxs(e.Fragment,{children:[e.jsx(le,{children:e.jsx(pe,{children:i("agency.addOn.modal.title")})}),e.jsx("div",{className:"grid gap-4 py-4",children:S||w?e.jsx("div",{className:"flex justify-center items-center py-8",children:e.jsx(ce,{className:"w-6 h-6"})}):(x==null?void 0:x.length)>0&&x.map(s=>e.jsx("button",{type:"button","data-testid":"addon-item",className:"p-4 border rounded-lg cursor-pointer hover:border-blue-500 transition-colors text-left",onClick:()=>D(s),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),D(s))},tabIndex:0,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-blue-50",children:e.jsx("span",{className:"text-2xl",children:"ð"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:s.name}),e.jsx("p",{className:"text-gray-500",children:s.description})]})]}),e.jsxs("div",{className:"text-xl font-medium",children:["$",s.cost,e.
1jsx("span",{className:"text-sm text-gray-500",children:i("agency.addOn.modal.perMonth")})]})]})},s.id))})]}),qe=()=>{const s=Object.values(o).filter(d=>d.selected).length,u=Object.values(o).every(d=>d.selected),n=Object.values(o).every(d=>!d.selected),p=X();return e.jsxs(e.Fragment,{children:[e.jsx(le,{children:e.jsxs("div",{className:"flex items-center gap-3 mt-3",children:[e.jsx("div",{className:"bg-blue-50 p-2 rounded-lg",children:e.jsx("span",{className:"text-base",children:"ð"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-md text-left",children:m==null?void 0:m.name}),e.jsx("p",{className:"text-gray-600 text-sm text-left",children:m==null?void 0:m.description})]})]})}),e.jsxs("div",{className:"py-3",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"mb-3",children:e.jsxs("div",{className:"flex items-center gap-3 w-full bg-secondary-lightest px-7 py-3 rounded-lg",children:[e.jsx(Pe,{svgColor:"secondary-dark",width:16,height:16}),e.jsx(ve,{type:"text",placeholder:i("agency.addOn.modal.searchPlaceholder"),value:j,onChange:d=>L(d.target.value),className:"flex-1 border-none bg-transparent p-0 h-auto focus-visible:outline-none placeholder:text-secondary-dark"})]})}),e.jsx("div",{className:"border rounded-lg p-3 max-h-[300px] overflow-y-auto",children:ze(m)}),e.jsxs("div",{className:"flex gap-3 mt-1",children:[e.jsx(I,{variant:"link",onClick:H,disabled:u,className:"text-blue-600 text-[11px] h-auto p-0",children:i("agency.addOn.modal.selectAll")}),e.jsx(I,{variant:"link",onClick:Z,disabled:n,className:"text-gray-600 text-[11px] h-auto p-0",children:i("agency.addOn.modal.clearAll")})]})]}),e.jsx("div",{className:"border-t pt-3 mb-4",children:e.jsxs("div",{className:"flex justify-between items-center text-sm",children:[e.jsx("div",{children:e.jsx("span",{"data-testid":"total-websites",children:i("agency.addOn.modal.totalWebsites",{count:s})})}),e.jsx("div",{children:e.jsx("span",{"data-testid":"total-amount",children:i("agency.addOn.modal.totalAmount",{amount:p})})})]})}),e.jsxs("div",{className:"flex justify-between mt-6",children:[e.jsx(I,{variant:"outline-secondary-light",onClick:a,children:i("agency.addOn.modal.back")}),e.jsx(I,{onClick:_,disabled:T||!Ee(),className:"bg-blue-600 hover:bg-blue-700","data-testid":"purchase-button",children:T?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2"}),i("agency.addOn.modal.processing")]}):(()=>{const d=Object.values(o).filter(v=>v.selected).reduce((v,C)=>v+C.quantity,0),N=Object.values(k).filter(Boolean).reduce((v,C)=>v+((C==null?void 0:C.quantity)||0),0);return d>N?i("agency.addOn.modal.purchaseAndEnable"):i("agency.addOn.modal.updatePurchase")})()})]})]})]})};return e.jsxs(e.Fragment,{children:[e.jsx(xe,{open:t,onOpenChange:c,children:e.jsx(ge,{className:"sm:max-w-[600px]","data-testid":"dialog-content",children:m?qe():Re()})}),e.jsx(Rt,{isOpen:F.isOpen,onClose:()=>!B&&W(s=>({...s,isOpen:!1})),onConfirm:U,websiteUrl:F.websiteUrl,nextBillingDate:F.nextBillingDate,isLoading:B})]})};function Ut(t){return t==="total"?"all":t}function Vt(t){return t==="all"?"total":t}function $t(t){return(t==null?void 0:t.filter)==="active"||(t==null?void 0:t.filter)==="inactive"?t.filter:"all"}const Kt=({t})=>e.jsx(vt,{to:"/agency/dashboard",children:e.jsxs(I,{variant:"ghost",className:"px-2 py-3 gap-1 pl-0 text-blue-600 hover:text-blue-700 hover:bg-transparent",children:[e.jsx(Ct,{}),t("agency.websites.backToDashboard")]})}),oa=pt("/agency/websites")({component:Gt});function Gt(){var H,Z,X;const{data:t=[]}=ht(),{data:c=[]}=ft(),{data:r}=Ae(),i=yt({strict:!1}),O=Ne(),[x,f]=h.useState("statCard"),[S,b]=h.useState(()=>$t(i)),[w,A]=h.useState({organisation:"",bannerStatus:"",regulation:"",plans:"",iabStatus:!1}),[T,P]=h.useState(""),j={};if(x==="statCard")S!=="all"&&(j.banner_status=S);else if(x==="filterComponent"){if(w.organisation){const a=t.find(_=>_.organizationName===w.organisation);a&&(j.organizations=a.organization_id)}w.bannerStatus&&(j.banner_status=w.bannerStatus),w.regulation&&(j.regulations=w.regulation),w.iabStatus!==void 0&&(j.iabStatus=w.iabStatus?1:0),w.plans&&(j.plans=w.plans)}T&&(j.search=T);const{t:L}=V(),[m,l]=h.useState(!1),o=R(a=>a.showWebsiteRenewalFailedAlert),M=R(a=>a.license),k=bt(),{data:g}=ue({}),{data:F}=ue({banner_status:"active"}),{data:W}=ue({banner_status:"inactive"}),B={total:((H=g==null?void 0:g.pages[0])==null?void 0:H.total)||0,active:((Z=F==null?void 0:F.pages[0])==null?void 0:Z.total)||0,inactive:((X=W==null?void 0:W.pages[0])==null?void 0:X.total)||0},z=async()=>
1{if(M)try{l(!0);const a={agencyUpgradeLicenseId:M.id},_=await k.mutateAsync(a);window.open(_,"_blank","noopener,noreferrer")}catch(a){console.error(a)}finally{l(!1)}},y=a=>{f("statCard"),b(a),A({organisation:"",bannerStatus:"",regulation:"",plans:"",iabStatus:!1})},D=a=>{A(a),f("filterComponent")},J=()=>{A({organisation:"",bannerStatus:"",regulation:"",plans:"",iabStatus:!1}),f("statCard"),b("all")};h.useEffect(()=>{const a=x==="statCard"&&S!=="all"?S:void 0;(i.filter??void 0)!==a&&O({search:_=>({..._,filter:a}),replace:!0})},[x,S,i.filter,O]);const[ee,q]=h.useState(!1);return e.jsxs(Nt,{permissionKey:"user::agency-dashboard:index",children:[e.jsxs("div",{className:"agency px-8 py-6 bg-secondary-lightest min-h-screen",children:[o()&&e.jsxs(be,{variant:"destructive",className:"p-5 border-danger-lightestest bg-danger-lightestest text-danger-darkestest flex items-center mb-6",children:[e.jsx("div",{className:"mr-4",children:e.jsx(zt,{})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(jt,{className:"!text-xl !font-semibold !text-danger-dark",children:L("subscriptions.agencyUserSubscription.alerts.paymentFailed.title")}),e.jsx(je,{className:"mt-1 text-secondary-dark font-normal",children:L("subscriptions.agencyUserSubscription.alerts.paymentFailed.description")})]}),e.jsx("div",{className:"flex-shrink-0 ml-4",children:e.jsx(I,{variant:"primary",className:"text-white",onClick:z,disabled:m,children:L(m?"subscriptions.agencyUserSubscription.alerts.paymentFailed.loading":"subscriptions.agencyUserSubscription.alerts.paymentFailed.buttonText")})})]}),e.jsx("div",{className:"mb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Kt,{t:L}),e.jsx("div",{className:"flex items-center gap-4",children:t.length>0&&r&&r.length>0&&e.jsx(I,{variant:"primary",className:"text-white",onClick:()=>q(!0),children:L("agency.websites.addOns")})})]})}),e.jsx("h6",{className:"mb-7 text-2xl font-semibold text-secondary-dark",children:L("agency.websites.allWebsites")}),e.jsx(_t,{total:B.total,active:B.active,inactive:B.inactive,selected:x==="statCard"?Vt(S):void 0,onSelect:a=>y(Ut(a))}),e.jsx("div",{className:"mt-6",children:e.jsx(Et,{websites:t,apiParams:j,searchText:T,setSearchText:P,filterState:w,onFilterChange:D,onFilterReset:J,activeFilterType:x,statCardFilter:S})})]}),e.jsx(qt,{isOpen:ee,onClose:()=>q(!1),websites:c})]})}export{oa as Route};
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.