ghost 6.21.0 → 6.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/tryghost-i18n-6.21.2.tgz +0 -0
- package/components/{tryghost-parse-email-address-6.21.0.tgz → tryghost-parse-email-address-6.21.2.tgz} +0 -0
- package/content/themes/casper/LICENSE +1 -1
- package/content/themes/casper/README.md +7 -2
- package/content/themes/casper/assets/built/casper.js +1 -2
- package/content/themes/casper/assets/built/casper.js.map +1 -1
- package/content/themes/casper/assets/built/global.css +1 -2
- package/content/themes/casper/assets/built/global.css.map +1 -1
- package/content/themes/casper/assets/built/screen.css +1 -2
- package/content/themes/casper/assets/built/screen.css.map +1 -1
- package/content/themes/casper/assets/css/global.css +4 -0
- package/content/themes/casper/default.hbs +5 -5
- package/content/themes/casper/error-404.hbs +1 -1
- package/content/themes/casper/error.hbs +2 -2
- package/content/themes/casper/gulpfile.js +13 -2
- package/content/themes/casper/locales/context.json +112 -0
- package/content/themes/casper/locales/de-CH.json +112 -0
- package/content/themes/casper/locales/de.json +112 -0
- package/content/themes/casper/locales/en.json +112 -0
- package/content/themes/casper/locales/fr.json +112 -0
- package/content/themes/casper/locales/ga.json +112 -0
- package/content/themes/casper/locales/gd.json +112 -0
- package/content/themes/casper/locales/nl.json +112 -0
- package/content/themes/casper/locales/pt-BR.json +112 -0
- package/content/themes/casper/locales/sv.json +112 -0
- package/content/themes/casper/locales/uk.json +112 -0
- package/content/themes/casper/locales/zh.json +112 -0
- package/content/themes/casper/package.json +12 -11
- package/content/themes/casper/partials/post-card.hbs +4 -4
- package/content/themes/casper/post.hbs +4 -4
- package/content/themes/casper/tag.hbs +1 -1
- package/content/themes/source/LICENSE +1 -1
- package/content/themes/source/README.md +4 -1
- package/content/themes/source/assets/built/screen.css +1 -2
- package/content/themes/source/assets/built/screen.css.map +1 -1
- package/content/themes/source/assets/built/source.js +1 -2
- package/content/themes/source/assets/built/source.js.map +1 -1
- package/content/themes/source/assets/css/screen.css +18 -16
- package/content/themes/source/default.hbs +1 -1
- package/content/themes/source/gulpfile.js +5 -3
- package/content/themes/source/locales/context.json +112 -0
- package/content/themes/source/locales/de-CH.json +112 -0
- package/content/themes/source/locales/de.json +112 -0
- package/content/themes/source/locales/en.json +112 -0
- package/content/themes/source/locales/fr.json +112 -0
- package/content/themes/source/locales/ga.json +112 -0
- package/content/themes/source/locales/gd.json +112 -0
- package/content/themes/source/locales/nl.json +112 -0
- package/content/themes/source/locales/pt-BR.json +112 -0
- package/content/themes/source/locales/sv.json +112 -0
- package/content/themes/source/locales/uk.json +112 -0
- package/content/themes/source/locales/zh.json +112 -0
- package/content/themes/source/package.json +13 -11
- package/content/themes/source/partials/components/featured.hbs +1 -1
- package/content/themes/source/partials/components/footer.hbs +1 -1
- package/content/themes/source/partials/components/header-content.hbs +1 -1
- package/content/themes/source/partials/components/navigation.hbs +5 -5
- package/content/themes/source/partials/components/post-list.hbs +7 -7
- package/content/themes/source/partials/email-subscription.hbs +5 -5
- package/content/themes/source/partials/lightbox.hbs +6 -6
- package/content/themes/source/partials/post-card.hbs +1 -1
- package/content/themes/source/partials/search-toggle.hbs +1 -1
- package/content/themes/source/post.hbs +2 -2
- package/core/built/admin/assets/{PolarAngleAxis-a31TecIQ.js → PolarAngleAxis-D8t9UwHk.js} +1 -1
- package/core/built/admin/assets/{_baseAssignValue-Dw5pcaUJ.js → _baseAssignValue-DPyNU5o6.js} +1 -1
- package/core/built/admin/assets/{a-large-small-Cf_hUupE.js → a-large-small-BijOKCoa.js} +1 -1
- package/core/built/admin/assets/admin-x-settings/admin-x-settings.js +1 -1
- package/core/built/admin/assets/admin-x-settings/{code-editor-view-C1ZFtR6M.mjs → code-editor-view-DJsXOcZ2.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/{index-zyVbQw03.mjs → index-BnhIi5NU.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/{index-D96qFjP9.mjs → index-CnwJhGbs.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/{index-ILVAmH8Q.mjs → index-DaGaokMn.mjs} +1067 -1063
- package/core/built/admin/assets/admin-x-settings/{modals-BbDVa22r.mjs → modals-D02VJnTV.mjs} +2838 -2840
- package/core/built/admin/assets/{at-sign-DyMz5le1.js → at-sign-_JfhlimD.js} +1 -1
- package/core/built/admin/assets/{audience-BevM-Udw.js → audience-BdrhpNZ4.js} +1 -1
- package/core/built/admin/assets/{avatar-flipboard-DiGYhH_s.js → avatar-flipboard-BdmM8eOn.js} +1 -1
- package/core/built/admin/assets/{bluesky-sharing-Dj4VOEDi.js → bluesky-sharing-yeM8KkY8.js} +1 -1
- package/core/built/admin/assets/{chart-BDdnkPgC.js → chart-CULaDoVB.js} +1 -1
- package/core/built/admin/assets/{chunk.138.5c4b0d0ae3f21c9c726d.js → chunk.482.c45c97fe666cd1a6b060.js} +4 -4
- package/core/built/admin/assets/{chunk.524.54ba5b50c191627c46f2.js → chunk.524.7fc2692374515780e66e.js} +4 -4
- package/core/built/admin/assets/{chunk.582.3232d44081d84d135e3d.js → chunk.582.fd8c4fa8e637e2d5611e.js} +8 -8
- package/core/built/admin/assets/{code-editor-view-V0wBeYuE.js → code-editor-view-UA2xKjk1.js} +1 -1
- package/core/built/admin/assets/{comments-CqurDRGu.js → comments-DoNjlMYA.js} +1 -1
- package/core/built/admin/assets/{content-helpers-C8lVEp2H.js → content-helpers-BRzxAgjP.js} +1 -1
- package/core/built/admin/assets/{copy-BdseBMKx.js → copy-CbX-_mHj.js} +1 -1
- package/core/built/admin/assets/{data-list--5Xfh5gm.js → data-list-nZOiCWV9.js} +1 -1
- package/core/built/admin/assets/{deleted-feed-item-Bmxp6PAR.js → deleted-feed-item-DjkZpKDC.js} +1 -1
- package/core/built/admin/assets/{edit-profile-Bi-G8vrq.js → edit-profile-BY_oJrQn.js} +1 -1
- package/core/built/admin/assets/{empty-indicator-C1cLHSRX.js → empty-indicator-DoxAratw.js} +1 -1
- package/core/built/admin/assets/{en-DPpVO1wK.js → en-B9ScC5j9.js} +1 -1
- package/core/built/admin/assets/{feed-lCu_EJ0a.js → feed-BsgqABLQ.js} +1 -1
- package/core/built/admin/assets/{filters-BYYV0fmK.js → filters-CscMb_Gl.js} +1 -1
- package/core/built/admin/assets/{gh-chart-BYWaeEuY.js → gh-chart-GokHrG5_.js} +1 -1
- package/core/built/admin/assets/{ghost-565670d46ad5b30935426b5dfa95bc81.js → ghost-d1843f84a9476ccbdf2a350848ac88aa.js} +2 -2
- package/core/built/admin/assets/{growth-DXHnB1EQ.js → growth-CKOWA1_V.js} +1 -1
- package/core/built/admin/assets/{hash-tZATAzZa.js → hash-twG7-iIB.js} +1 -1
- package/core/built/admin/assets/{inbox-B-LuWyHY.js → inbox-BdkIJbSq.js} +1 -1
- package/core/built/admin/assets/{index-BDrJ3N3y.js → index-B7OzWwwP.js} +1 -1
- package/core/built/admin/assets/{index-B8tGZsrG.js → index-BFySh9qo.js} +1 -1
- package/core/built/admin/assets/{index-EiGE3Aiy.js → index-BOWUajrT.js} +1 -1
- package/core/built/admin/assets/{index-ig4J4RpO.js → index-BQLCImHQ.js} +1 -1
- package/core/built/admin/assets/{index-BmKPrbBK.js → index-C398bG84.js} +1 -1
- package/core/built/admin/assets/{index-BX0_v5NB.js → index-C5YCjM6z.js} +1 -1
- package/core/built/admin/assets/{index-DEwhVcR5.js → index-CHpxzPRR.js} +1 -1
- package/core/built/admin/assets/{index-CX1A5TwO.js → index-CM-iA6b-.js} +3 -3
- package/core/built/admin/assets/{index-9bj69FKq.js → index-CgCHCdle.js} +1 -1
- package/core/built/admin/assets/{index-BocVu6WC.js → index-Cw441AFq.js} +1 -1
- package/core/built/admin/assets/{index-jHIJgh6L.js → index-D9S88kRl.js} +1 -1
- package/core/built/admin/assets/{index-CqvBC0jL.js → index-DbgA2vK8.js} +1 -1
- package/core/built/admin/assets/{index-2H-Jp89Z.js → index-ghPdV1ln.js} +1 -1
- package/core/built/admin/assets/{index-BcOzgmTC.js → index-tX0pajfP.js} +1 -1
- package/core/built/admin/assets/{index-BxVUX0dN.js → index-upXLfQxx.js} +1 -1
- package/core/built/admin/assets/{koenig-lexical-BdX9U-oB.js → koenig-lexical-GZS7bHDz.js} +1 -1
- package/core/built/admin/assets/{kpi-card-DQ1AbLJB.js → kpi-card-B6fmS7IH.js} +1 -1
- package/core/built/admin/assets/{kpis-vcbQvnLh.js → kpis-B-JXQ-4C.js} +1 -1
- package/core/built/admin/assets/{label-CNmRJkLy.js → label-ChHoKmj0.js} +1 -1
- package/core/built/admin/assets/{links-BE51SJxR.js → links-DQSOljcR.js} +1 -1
- package/core/built/admin/assets/{list-filter-BwnQ0Xlp.js → list-filter-cWuCDOLb.js} +1 -1
- package/core/built/admin/assets/{loader-circle-CcLEGvsN.js → loader-circle-B5ILzHHu.js} +1 -1
- package/core/built/admin/assets/{lucide-react-DHFgHS1l.js → lucide-react-CM0rB7CS.js} +1 -1
- package/core/built/admin/assets/{main-layout-DsxBNVo-.js → main-layout-BE7vZmy0.js} +1 -1
- package/core/built/admin/assets/{members-3okEkvWv.js → members-C10Z_BuG.js} +1 -1
- package/core/built/admin/assets/{message-square-text-BkERj4f5.js → message-square-text-DVZjnBBF.js} +1 -1
- package/core/built/admin/assets/{minus-C6oMPJo2.js → minus-BWrVDnd-.js} +1 -1
- package/core/built/admin/assets/{modals-CfUec0CL.js → modals-Bx7uDUHI.js} +15 -15
- package/core/built/admin/assets/{moderation-DEHUqi1e.js → moderation-DwlKZoB5.js} +1 -1
- package/core/built/admin/assets/{newsletter-Cp-39ksw.js → newsletter-DkOl42UB.js} +1 -1
- package/core/built/admin/assets/{newsletters-Bj58VQa2.js → newsletters-DNt9qd4h.js} +1 -1
- package/core/built/admin/assets/{note-9ysQWJz6.js → note-C-BLqULD.js} +1 -1
- package/core/built/admin/assets/{offers-DORdeAfE.js → offers-CU0KFuyW.js} +1 -1
- package/core/built/admin/assets/{overview-aZmI_71o.js → overview-DAEelSKq.js} +1 -1
- package/core/built/admin/assets/{pagemenu-DK1tbdsq.js → pagemenu-Cr7_YYR8.js} +1 -1
- package/core/built/admin/assets/{post-analytics-context-D8nk51yA.js → post-analytics-context-B2ytyOU0.js} +1 -1
- package/core/built/admin/assets/{post-analytics-header-qh1LEasb.js → post-analytics-header-CvR25xxU.js} +1 -1
- package/core/built/admin/assets/{post-analytics-HdZI-1J7.js → post-analytics-qpfoP-57.js} +1 -1
- package/core/built/admin/assets/{post-share-modal-CvTf3PP9.js → post-share-modal-DDhiG0X4.js} +1 -1
- package/core/built/admin/assets/{posts-mIxckqHa.js → posts-DTy4lguT.js} +1 -1
- package/core/built/admin/assets/{referrers-qhD64pmp.js → referrers-BzKz9fT9.js} +1 -1
- package/core/built/admin/assets/{repeat-Idtsb62O.js → repeat-C_xWSLK1.js} +1 -1
- package/core/built/admin/assets/{reply-DXS-C-Rk.js → reply-CXnb6Juu.js} +1 -1
- package/core/built/admin/assets/{select-CeD8IhXy.js → select-WZUCQgjI.js} +1 -1
- package/core/built/admin/assets/{settings-BHfStwmS.js → settings-BC82mM6N.js} +1 -1
- package/core/built/admin/assets/{settings-M0QTt_tT.js → settings-EbntXZw9.js} +7 -7
- package/core/built/admin/assets/{sort-button-BoTFsBYE.js → sort-button-CFYf_NOQ.js} +1 -1
- package/core/built/admin/assets/{source-icon-opy8g_Nk.js → source-icon-xS8eeWX-.js} +1 -1
- package/core/built/admin/assets/{sprout-BKOFkdV8.js → sprout-CLmu2pln.js} +1 -1
- package/core/built/admin/assets/{square-BjZk7vJx.js → square-D0Y5-h0C.js} +1 -1
- package/core/built/admin/assets/{stats-DXXxmfRV.js → stats-B5O9DjYi.js} +1 -1
- package/core/built/admin/assets/{stats-view-D_5J0Nf7.js → stats-view-Cr6M1ycv.js} +1 -1
- package/core/built/admin/assets/{step-1-BcaR_MDC.js → step-1-DGbl6AAj.js} +1 -1
- package/core/built/admin/assets/{step-2-BR0jqEO_.js → step-2-Rf8oissi.js} +1 -1
- package/core/built/admin/assets/{step-3-CMPME0ky.js → step-3-tMPmbeBc.js} +1 -1
- package/core/built/admin/assets/{table-CwbnKMYe.js → table-CXo8NKU2.js} +1 -1
- package/core/built/admin/assets/{tabs-hfT89L_O.js → tabs-BMk71Tf2.js} +1 -1
- package/core/built/admin/assets/{tags-BSwYlj_e.js → tags-CSl0BjsA.js} +1 -1
- package/core/built/admin/assets/{tags-C3b5AHTm.js → tags-CqHx8i6Q.js} +1 -1
- package/core/built/admin/assets/{ticket-BnxPoED1.js → ticket-BtYGyQvH.js} +1 -1
- package/core/built/admin/assets/{tiers-DHKKzaBK.js → tiers-CPwRaPSt.js} +1 -1
- package/core/built/admin/assets/{toggle-group-U-Oqm2AA.js → toggle-group-QFge4qQs.js} +1 -1
- package/core/built/admin/assets/{topic-filter-28veMlW4.js → topic-filter-DnYtZ5e5.js} +1 -1
- package/core/built/admin/assets/{trash-D6TuYuIs.js → trash-B4ncKmRu.js} +1 -1
- package/core/built/admin/assets/{use-growth-stats-COmCRCzY.js → use-growth-stats-eFO-f1o1.js} +1 -1
- package/core/built/admin/assets/{use-infinite-virtual-scroll-mIEgtLoq.js → use-infinite-virtual-scroll-DTqnBtHM.js} +1 -1
- package/core/built/admin/assets/{use-scroll-restoration-CXVseKDj.js → use-scroll-restoration-o1DrSdlb.js} +1 -1
- package/core/built/admin/assets/{use-simple-pagination-5-LKveLR.js → use-simple-pagination-BsBGNcxc.js} +1 -1
- package/core/built/admin/assets/{user-plus-CKQ-d0d4.js → user-plus-BS8SGBmk.js} +1 -1
- package/core/built/admin/assets/{user-round-check-BWc7Da4S.js → user-round-check-BgOPeBFs.js} +1 -1
- package/core/built/admin/assets/{wallet-cards-BlDtHc6_.js → wallet-cards-Be7G77lR.js} +1 -1
- package/core/built/admin/assets/{web-Bvvtl44p.js → web-BNs01IAt.js} +1 -1
- package/core/built/admin/index.html +5 -5
- package/core/frontend/helpers/cancel_link.js +2 -2
- package/core/server/api/endpoints/authors-public.js +3 -3
- package/core/server/api/endpoints/files.js +2 -1
- package/core/server/api/endpoints/pages-public.js +3 -3
- package/core/server/api/endpoints/posts-public.js +3 -3
- package/core/server/api/endpoints/users.js +6 -2
- package/core/server/api/endpoints/utils/api-filter-utils.js +22 -0
- package/core/server/api/endpoints/utils/api-filter-utils.ts +22 -0
- package/core/server/lib/lexical.js +2 -1
- package/core/server/lib/mobiledoc.js +1 -1
- package/core/server/lib/request-external.js +78 -2
- package/core/server/services/email-service/email-templates/partials/styles.hbs +3 -1
- package/core/server/services/koenig/node-renderers/image-renderer.js +80 -10
- package/core/server/services/koenig/render-utils/srcset-attribute.js +15 -3
- package/core/server/services/members/members-api/controllers/router-controller.js +5 -5
- package/core/server/services/members/members-api/repositories/member-repository.js +1 -1
- package/core/server/services/members/members-api/utils/get-discount-window.js +70 -4
- package/core/server/services/members/members-api/utils/has-active-offer.js +10 -14
- package/core/server/services/oembed/oembed-service.js +9 -1
- package/core/server/services/offers/application/offer-mapper.js +48 -0
- package/core/server/services/offers/application/offers-api.js +2 -2
- package/core/shared/config/defaults.json +1 -1
- package/core/shared/labs.js +2 -1
- package/package.json +6 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/yarn.lock +148 -16
- package/components/tryghost-i18n-6.21.0.tgz +0 -0
- package/core/server/api/endpoints/utils/public-endpoint-utils.js +0 -18
- package/core/server/api/endpoints/utils/public-endpoint-utils.ts +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as o,cs as $e,ct as Oe,cv as ze,cr as Ie,cM as Se,X as se,cu as Re,B as D,a0 as oe,ac as ke,ab as te,D as W,v as G,w as H,x as Q,ah as X,cX as Ae,cY as Ue,cZ as Be,W as P,b1 as Ve,ar as Ke,b2 as Ye,b3 as We,b5 as B,b6 as ce,cm as _e,c9 as Ge,c_ as He,z as Ce,e as Qe,cG as de,c$ as Xe,aO as Je,aM as Ze,aK as Le,d0 as V,cJ as ue,bS as qe,d1 as es,f as ss,cl as me}from"./index-CX1A5TwO.js";import{C as ae,a as le,b as Me,d as pe,e as re,f as ts,F as as}from"./filters-BYYV0fmK.js";import{P as ls,T as rs}from"./tags-C3b5AHTm.js";import{u as De}from"./newsletters-Bj58VQa2.js";import{D as ns,b as is,N as os,C as cs,c as ds,d as us,e as ms,A as ps,T as fs,S as fe,a as be,P as bs,M as hs}from"./ticket-BnxPoED1.js";import{g as gs}from"./get-site-timezone-BDBAcjmq.js";import{u as xs}from"./offers-DORdeAfE.js";import{u as js}from"./tiers-DHKKzaBK.js";import{M as q,U as vs}from"./user-plus-CKQ-d0d4.js";import{E as ws,C as ys,F as Ns,b as Ss}from"./loader-circle-CcLEGvsN.js";import{u as ks}from"./posts-mIxckqHa.js";import{H as Y,u as _s}from"./use-infinite-virtual-scroll-mIEgtLoq.js";import{M as Cs,u as Ls}from"./use-scroll-restoration-CXVseKDj.js";import{E as he}from"./empty-indicator-C1cLHSRX.js";const Ms=({label:t,onSave:s,onCancel:a,onDelete:l,isDuplicateName:n})=>{const[r,c]=o.useState(t.name),[i,d]=o.useState(!1),[b,g]=o.useState(""),[u,x]=o.useState(!1),[j,w]=o.useState(!1),v=o.useRef(null),m=u||j;o.useEffect(()=>{v.current?.focus(),v.current?.select()},[]);const p=S=>{const y=S.trim();return y?n?.(y,t.id)?"A label with this name already exists":"":"Name is required"},f=async()=>{const S=p(r);if(S){g(S);return}x(!0);try{await s(t.id,r.trim()),a()}catch{x(!1)}},h=S=>{S.key==="Enter"?(S.preventDefault(),f()):S.key==="Escape"&&(S.preventDefault(),m||a())},k=async()=>{w(!0);try{await l(t.id)}catch{w(!1),d(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2 py-1.5","data-edit-row":!0,children:[e.jsx("input",{ref:v,className:"h-7 w-full rounded border border-border bg-background px-2 text-sm outline-none focus:ring-1 focus:ring-ring disabled:opacity-50",disabled:m,type:"text",value:r,onChange:S=>{c(S.target.value),g("")},onKeyDown:h}),b&&e.jsx("span",{className:"text-xs text-destructive",children:b}),i?e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx("span",{className:"flex-1 font-semibold",children:"Delete label?"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"destructive",onClick:k,children:j?"Deleting...":"Delete"})]}):e.jsxs("div",{className:"flex items-center",children:[e.jsx(D,{className:"h-6 gap-1 px-1.5 text-xs text-red hover:bg-red/5 hover:text-red",disabled:m,size:"sm",variant:"ghost",onClick:()=>d(!0),children:"Delete"}),e.jsxs("div",{className:"ml-auto flex gap-1",children:[e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"outline",onClick:a,children:"Cancel"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",onClick:f,children:u?"Saving...":"Save"})]})]})]})},Ds=({label:t,isSelected:s,showEdit:a,onToggle:l,onEditClick:n})=>e.jsxs(re,{className:"group",value:t.slug,onSelect:()=>l(t.slug),children:[e.jsx("span",{className:"flex-1 truncate",children:t.name}),a?e.jsxs("button",{"aria-label":`Edit label ${t.name}`,className:"relative ml-1 flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground",type:"button",onClick:r=>{r.stopPropagation(),r.preventDefault(),n()},children:[s&&e.jsx(oe,{className:"absolute size-3 text-primary transition-opacity duration-150 group-hover:opacity-0"}),e.jsx(ls,{className:"absolute size-3 translate-x-2 opacity-0 transition-all duration-150 ease-out group-hover:translate-x-0 group-hover:opacity-100"})]}):s&&e.jsx(oe,{className:"size-4 shrink-0 text-primary"})]}),Ee=({labels:t,selectedSlugs:s,search:a,onToggle:l,onEdit:n,onDelete:r,isDuplicateName:c,canCreateFromSearch:i,onCreate:d,isCreating:b,onSearchClear:g})=>{const[u,x]=o.useState(null),j=t.filter(h=>h.name.toLowerCase().includes(a.toLowerCase())),w=!!d&&a.trim()&&i?.(a),v=!!n,m=async()=>{if(d){const h=await d(a.trim());h&&l(h.slug),g?.()}},p=async(h,k)=>{n&&await n(h,k)},f=async h=>{r&&(await r(h),x(null))};return e.jsxs(e.Fragment,{children:[!w&&j.length===0&&e.jsx(Me,{children:"No labels found"}),j.length>0&&e.jsx(pe,{className:"[&_[cmdk-group-heading]]:hidden",children:j.map(h=>u===h.id?e.jsx(Ms,{isDuplicateName:c,label:h,onCancel:()=>x(null),onDelete:f,onSave:p},h.id):e.jsx(Ds,{isSelected:s.includes(h.slug),label:h,showEdit:v,onEditClick:()=>x(h.id),onToggle:l},h.id))}),w&&e.jsx(pe,{className:"[&_[cmdk-group-heading]]:hidden",children:e.jsxs(re,{disabled:b,onSelect:m,children:[e.jsx(Re,{className:"size-4"}),b?"Creating...":`Create "${a.trim()}"`]})})]})},Pe=({labels:t,onToggle:s})=>e.jsx(e.Fragment,{children:t.map(a=>e.jsxs(Se,{className:"cursor-pointer gap-1 pr-1",variant:"outline",onClick:l=>{l.stopPropagation(),s(a.slug)},children:[a.name,e.jsx(se,{className:"size-3"})]},a.id))}),ne=({labels:t,selectedSlugs:s,isLoading:a,onToggle:l,canCreateFromSearch:n,onCreate:r,isCreating:c,onEdit:i,onDelete:d,isDuplicateName:b,inline:g=!1,align:u="start"})=>{const x=s.map(j=>t.find(w=>w.slug===j)).filter(j=>!!j);return g?e.jsx(Es,{align:u,canCreateFromSearch:n,isCreating:c,isDuplicateName:b,isLoading:a,labels:t,selectedLabels:x,selectedSlugs:s,onCreate:r,onDelete:d,onEdit:i,onToggle:l}):e.jsx(Ts,{canCreateFromSearch:n,isCreating:c,isDuplicateName:b,isLoading:a,labels:t,selectedLabels:x,selectedSlugs:s,onCreate:r,onDelete:d,onEdit:i,onToggle:l})},Es=({labels:t,selectedLabels:s,selectedSlugs:a,onToggle:l,isLoading:n,align:r="start",canCreateFromSearch:c,onCreate:i,isCreating:d,onEdit:b,onDelete:g,isDuplicateName:u})=>{const x=o.useRef(null),[j,w]=o.useState(0),v=o.useCallback(()=>{const p=x.current,f=p?.parentElement;if(p&&f){const h=p.getBoundingClientRect(),k=f.getBoundingClientRect();w(Math.round(k.left-h.left))}},[]),m=s.length===0?"Select...":s.length===1?s[0].name:`${s.length} labels`;return e.jsxs($e,{onOpenChange:p=>{p&&v()},children:[e.jsx(Oe,{asChild:!0,children:e.jsx("button",{ref:x,className:"flex size-full items-center truncate text-left text-sm",type:"button",children:m})}),e.jsx(ze,{align:r,alignOffset:j,className:"w-64 p-0",children:n?e.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-muted-foreground",children:"Loading labels..."}):e.jsx(Ps,{canCreateFromSearch:c,isCreating:d,isDuplicateName:u,labels:t,selectedLabels:s,selectedSlugs:a,onCreate:i,onDelete:g,onEdit:b,onToggle:l})})]})},Ps=({selectedLabels:t,...s})=>{const[a,l]=o.useState("");return e.jsxs(ae,{shouldFilter:!1,children:[t.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 border-b px-3 py-2",children:e.jsx(Pe,{labels:t,onToggle:s.onToggle})}),e.jsxs("div",{className:"flex items-center border-b px-3",children:[e.jsx(Ie,{className:"mr-2 size-4 shrink-0 opacity-50"}),e.jsx("input",{className:"flex h-9 w-full bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground",placeholder:"Search labels...",value:a,onChange:n=>l(n.target.value)})]}),e.jsx(le,{className:"max-h-64 overflow-y-auto",children:e.jsx(Ee,{...s,search:a,onSearchClear:()=>l("")})})]})},Ts=({labels:t,selectedLabels:s,selectedSlugs:a,onToggle:l,isLoading:n,canCreateFromSearch:r,onCreate:c,isCreating:i,onEdit:d,onDelete:b,isDuplicateName:g})=>{const[u,x]=o.useState(!1),[j,w]=o.useState(""),v=o.useRef(null),m=o.useRef(null);o.useEffect(()=>{if(!u)return;const f=h=>{m.current&&!m.current.contains(h.target)&&x(!1)};return document.addEventListener("pointerdown",f),()=>document.removeEventListener("pointerdown",f)},[u]);const p=f=>{f.key==="Backspace"&&!j&&a.length>0&&l(a[a.length-1]),f.key==="Escape"&&(x(!1),v.current?.blur())};return e.jsxs("div",{ref:m,className:"relative",children:[e.jsxs("div",{className:"flex min-h-9 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border border-transparent bg-gray-150 px-3 py-1 text-sm transition-colors focus-within:border-green focus-within:bg-transparent focus-within:shadow-[0_0_0_2px_rgba(48,207,67,.25)] dark:bg-gray-900",role:"combobox",onClick:()=>{v.current?.focus(),x(!0)},children:[e.jsx(Pe,{labels:s,onToggle:l}),e.jsx("input",{ref:v,className:"min-w-[80px] flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground",placeholder:s.length===0?"Search labels...":"",value:j,onChange:f=>{w(f.target.value),u||x(!0)},onFocus:()=>x(!0),onKeyDown:p})]}),u&&e.jsx("div",{className:"absolute left-0 top-full z-50 mt-1 w-full rounded-md border bg-white shadow-md dark:bg-gray-950",children:n?e.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-muted-foreground",children:"Loading labels..."}):e.jsx(ae,{shouldFilter:!1,children:e.jsx(le,{className:"max-h-64 overflow-y-auto",children:e.jsx(Ee,{canCreateFromSearch:r,isCreating:i,isDuplicateName:g,labels:t,search:j,selectedSlugs:a,onCreate:c,onDelete:b,onEdit:d,onSearchClear:()=>w(""),onToggle:l})})})})]})},J="LabelsResponseType",Te=ke({dataType:J,path:"/labels/"}),Fs=te({method:"POST",path:()=>"/labels/",body:t=>({labels:[t]}),updateQueries:{dataType:J,emberUpdateType:"createOrUpdate",update:(t,s)=>{const a=s;return a&&{...a,labels:a.labels.concat(t.labels)}}}}),$s=te({method:"PUT",path:t=>`/labels/${t.id}/`,body:t=>({labels:[t]}),updateQueries:{dataType:J,emberUpdateType:"createOrUpdate",update:(t,s)=>{const a=s;return a&&{...a,labels:a.labels.map(l=>t.labels.find(({id:n})=>n===l.id)||l)}}}}),Os=te({method:"DELETE",path:t=>`/labels/${t}/`,updateQueries:{dataType:J,emberUpdateType:"delete",update:(t,s,a)=>{const l=s;return l&&{...l,labels:l.labels.filter(n=>n.id!==a)}}}});function ie({selectedSlugs:t,onSelectionChange:s}){const{data:a,isLoading:l}=Te({searchParams:{limit:"100"}}),n=o.useMemo(()=>a?.labels||[],[a]),{mutateAsync:r,isLoading:c}=Fs(),{mutateAsync:i}=$s(),{mutateAsync:d}=Os(),b=o.useRef(t);b.current=t;const g=o.useCallback(m=>{const p=b.current;p.includes(m)?s(p.filter(f=>f!==m)):s([...p,m])},[s]),u=o.useCallback((m,p)=>{const f=m.trim().toLowerCase();return n.some(h=>h.name.toLowerCase()===f&&h.id!==p)},[n]),x=o.useCallback(m=>{const p=m.trim();return p?!u(p):!1},[u]),j=o.useCallback(async m=>{const p=m.trim();return!p||u(p)?void 0:(await r({name:p}))?.labels?.[0]},[r,u]),w=o.useCallback(async(m,p)=>{const f=p.trim();if(!f||u(f,m))return;const h=n.find(y=>y.id===m),S=(await i({id:m,name:f}))?.labels?.[0];if(h&&S&&h.slug!==S.slug){const y=b.current;y.includes(h.slug)&&s(y.map(_=>_===h.slug?S.slug:_))}},[i,u,n,s]),v=o.useCallback(async m=>{const p=n.find(f=>f.id===m);if(await d(m),p){const f=b.current;f.includes(p.slug)&&s(f.filter(h=>h!==p.slug))}},[d,n,s]);return{labels:n,selectedSlugs:t,isLoading:l,toggleLabel:g,createLabel:j,editLabel:w,deleteLabel:v,isDuplicateName:u,canCreateFromSearch:x,isCreating:c}}const zs=({values:t,onChange:s})=>{const a=ie({selectedSlugs:t,onSelectionChange:s});return e.jsx(ne,{isDuplicateName:a.isDuplicateName,labels:a.labels,selectedSlugs:a.selectedSlugs,inline:!0,onDelete:a.deleteLabel,onEdit:a.editLabel,onToggle:a.toggleLabel})};function Is({open:t,memberCount:s,onOpenChange:a,onConfirm:l,isLoading:n=!1}){const[r,c]=o.useState([]),i=ie({selectedSlugs:r,onSelectionChange:c}),d=o.useCallback(g=>{g||c([]),a(g)},[a]),b=()=>{const g=i.labels.filter(u=>r.includes(u.slug)).map(u=>u.id);g.length>0&&l(g)};return e.jsx(W,{open:t,onOpenChange:d,children:e.jsxs(G,{className:"gap-5",onOpenAutoFocus:g=>g.preventDefault(),children:[e.jsx(H,{children:e.jsxs(Q,{children:["Add label to ",s.toLocaleString()," ",s===1?"member":"members"]})}),e.jsx(ne,{canCreateFromSearch:i.canCreateFromSearch,isCreating:i.isCreating,isDuplicateName:i.isDuplicateName,isLoading:i.isLoading,labels:i.labels,selectedSlugs:i.selectedSlugs,onCreate:i.createLabel,onDelete:i.deleteLabel,onEdit:i.editLabel,onToggle:i.toggleLabel}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{disabled:r.length===0||n,onClick:b,children:n?"Adding...":r.length>1?`Add ${r.length} labels`:"Add label"})]})]})})}function Rs({open:t,memberCount:s,nql:a,onOpenChange:l,onConfirm:n,isLoading:r=!1}){const[c,i]=o.useState([]),{data:d,isLoading:b}=Ae({searchParams:{...a?{filter:a}:{},include:"labels",limit:"all",fields:"id"},enabled:t}),g=o.useMemo(()=>{const v=new Set;for(const m of d?.members||[])for(const p of m.labels||[])v.add(p.slug);return v},[d]),u=ie({selectedSlugs:c,onSelectionChange:i}),x=o.useMemo(()=>u.labels.filter(v=>g.has(v.slug)),[u.labels,g]),j=o.useCallback(v=>{v||i([]),l(v)},[l]),w=()=>{const v=u.labels.filter(m=>c.includes(m.slug)).map(m=>m.id);v.length>0&&n(v)};return e.jsx(W,{open:t,onOpenChange:j,children:e.jsxs(G,{className:"gap-5",onOpenAutoFocus:v=>v.preventDefault(),children:[e.jsx(H,{children:e.jsxs(Q,{children:["Remove label from ",s.toLocaleString()," ",s===1?"member":"members"]})}),e.jsx(ne,{isDuplicateName:u.isDuplicateName,isLoading:u.isLoading||b,labels:x,selectedSlugs:u.selectedSlugs,onDelete:u.deleteLabel,onEdit:u.editLabel,onToggle:u.toggleLabel}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(D,{disabled:c.length===0||r,onClick:w,children:r?"Removing...":c.length>1?`Remove ${c.length} labels`:"Remove label"})]})]})})}function As({open:t,newsletters:s,memberCount:a,onOpenChange:l,onConfirm:n,isLoading:r=!1}){const[c,i]=o.useState("all"),[d,b]=o.useState([]),[g,u]=o.useState(""),[x,j]=o.useState(!1),w=o.useRef(null),v=o.useRef(null);o.useEffect(()=>{t||(i("all"),b([]),u(""),j(!1))},[t]),o.useEffect(()=>{if(!x)return;const y=_=>{w.current&&!w.current.contains(_.target)&&j(!1)};return document.addEventListener("pointerdown",y),()=>document.removeEventListener("pointerdown",y)},[x]);const m=y=>{y||(i("all"),b([]),u(""),j(!1)),l(y)},p=o.useCallback(y=>{b(_=>_.includes(y)?_.filter(T=>T!==y):[..._,y])},[]),f=s.length>=2,h=()=>{n(!f||c==="all"?null:d)},k=r||f&&c==="selected"&&d.length===0,S=a===1?"member":"members";return e.jsx(W,{open:t,onOpenChange:m,children:e.jsxs(G,{className:"gap-5",children:[e.jsx(H,{children:e.jsx(Q,{children:"Unsubscribe members"})}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{"aria-label":"Unsubscribe scope",className:"flex flex-col gap-3",role:"radiogroup",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{checked:c==="all",className:"mt-0.5 size-4 cursor-pointer accent-black",name:"unsubscribe-mode",type:"radio",value:"all",onChange:()=>i("all")}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Unsubscribe from all newsletters"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[a.toLocaleString()," ",S," will be unsubscribed from ",s.length," ",s.length===1?"newsletter":"newsletters","."]})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{checked:c==="selected",className:"mt-0.5 size-4 cursor-pointer accent-black",name:"unsubscribe-mode",type:"radio",value:"selected",onChange:()=>i("selected")}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Unsubscribe from selected newsletters"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Select which newsletters to unsubscribe ",a.toLocaleString()," ",S," from."]})]})]})]}),c==="selected"&&e.jsxs("div",{ref:w,className:"relative space-y-2",children:[e.jsx("label",{className:"text-sm font-semibold",htmlFor:"newsletter-search",children:"Newsletters"}),e.jsxs("div",{className:"flex min-h-9 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border bg-background px-3 py-1 text-sm",onClick:()=>{v.current?.focus(),j(!0)},children:[d.map(y=>{const _=s.find(T=>T.id===y);return _?e.jsxs(Se,{className:"cursor-pointer gap-1 pr-1",variant:"outline",onClick:T=>{T.stopPropagation(),p(y)},children:[_.name,e.jsx(se,{className:"size-3"})]},y):null}),e.jsx("input",{ref:v,className:"min-w-[80px] flex-1 bg-transparent py-1 text-sm outline-none placeholder:text-muted-foreground",id:"newsletter-search",placeholder:d.length===0?"Search newsletters...":"",value:g,onChange:y=>{u(y.target.value),x||j(!0)},onFocus:()=>j(!0),onKeyDown:y=>{y.key==="Escape"&&(j(!1),v.current?.blur()),y.key==="Backspace"&&!g&&d.length>0&&p(d[d.length-1])}})]}),x&&e.jsx("div",{className:"absolute left-0 top-full z-50 mt-1 w-full rounded-md border bg-white shadow-md dark:bg-gray-950",children:e.jsx(ae,{shouldFilter:!1,children:e.jsxs(le,{className:"max-h-64 overflow-y-auto",children:[e.jsx(Me,{children:"No newsletters found."}),s.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())).map(y=>e.jsxs(re,{value:y.name,onSelect:()=>p(y.id),children:[y.name,d.includes(y.id)&&e.jsx(ts,{})]},y.id))]})})})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Are you sure you want to unsubscribe ",a.toLocaleString()," ",S," from all newsletters? They will no longer receive any email newsletters from you."]}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(D,{disabled:k,variant:"destructive",onClick:h,children:r?"Unsubscribing...":"Unsubscribe"})]})]})})}function Us({open:t,memberCount:s,onOpenChange:a,onConfirm:l,onExportBackup:n,isLoading:r=!1}){const[c,i]=o.useState(!1),d=g=>{g||i(!1),a(g)},b=async()=>{if(!(s<1||r||c))try{i(!0),await n(),l()}catch{}finally{i(!1)}};return e.jsx(W,{open:t,onOpenChange:d,children:e.jsxs(G,{className:"gap-5",children:[e.jsx(H,{children:e.jsx(Q,{children:"Delete selected members?"})}),e.jsx("div",{className:"text-sm",children:s>0?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["You're about to delete ",e.jsxs("strong",{children:[s.toLocaleString()," ",s===1?"member":"members"]}),". This is permanent! All Ghost data will be deleted, this will have no effect on subscriptions in Stripe."]}),e.jsx("p",{className:"mt-4",children:"A backup of your selection will be automatically downloaded to your device before deletion."})]}):e.jsx("p",{children:"No members are selected."})}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{disabled:r||c||s<1,variant:"destructive",onClick:b,children:r||c?"Deleting...":"Download backup & delete members"})]})]})})}async function ge(t){const s=new URLSearchParams({limit:"all"});t&&s.set("filter",t);const a=new Date().toJSON().substring(0,10);await He(`/members/upload/?${s}`,`members.${a}.csv`)}const Bs=({isFiltered:t,memberCount:s,nql:a,canBulkDelete:l})=>{const{data:n,isLoading:r}=De({searchParams:{filter:"status:-archived",limit:"50"}}),c=n?.newsletters||[],{mutateAsync:i,isLoading:d}=Ue(),{mutate:b,isLoading:g}=Be(),[u,x]=o.useState(!1),[j,w]=o.useState(!1),[v,m]=o.useState(!1),[p,f]=o.useState(!1),[h,k]=o.useState(!1),S=o.useCallback(async()=>{try{await ge(a)}catch(L){throw P.error("Export failed",{description:"There was a problem downloading your member data. Please check your connection and try again."}),L}},[a]),y=o.useCallback(async L=>{try{for(const M of L)await i({filter:a||"",all:!a,action:{type:"addLabel",meta:{label:{id:M}}}});w(!1),P.success(L.length>1?"Labels added successfully":"Label added successfully")}catch{P.error("Failed to add label",{description:"There was a problem applying this label. Please try again."})}},[i,a]),_=o.useCallback(async L=>{try{for(const M of L)await i({filter:a||"",all:!a,action:{type:"removeLabel",meta:{label:{id:M}}}});m(!1),P.success(L.length>1?"Labels removed successfully":"Label removed successfully")}catch{P.error("Failed to remove label",{description:"There was a problem removing this label. Please try again."})}},[i,a]),T=o.useCallback(async L=>{const M={filter:a||"",all:!a};if(L===null){try{await i({...M,action:{type:"unsubscribe"}}),f(!1),P.success("Members unsubscribed successfully")}catch{P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}return}x(!0);try{const N=await Promise.allSettled(L.map(O=>i({...M,action:{type:"unsubscribe",newsletter:O}}))),E=N.filter(O=>O.status==="fulfilled").length,C=N.length;f(!1),E===C?P.success(`Unsubscribed from ${C} ${C===1?"newsletter":"newsletters"}`):E>0?P.warning(`Unsubscribed from ${E} of ${C} newsletters`,{description:"Some newsletters could not be unsubscribed. Please try again."}):P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}catch{P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}finally{x(!1)}},[i,a]),R=o.useCallback(()=>{b({filter:a||"",all:!a},{onSuccess:()=>{k(!1),P.success("Members deleted successfully")},onError:()=>{P.error("Failed to delete members",{description:"There was a problem deleting these members. Please try again."})}})},[b,a]),$=o.useCallback(async()=>{try{await ge(a)}catch(L){throw P.error("Export failed",{description:"There was a problem downloading your backup. Please check your connection and try again."}),L}},[a]);return e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{children:[e.jsx(Ke,{asChild:!0,children:e.jsx(D,{variant:"outline",children:e.jsx(Ye,{className:"size-4"})})}),e.jsx(We,{align:"end",children:s>0&&e.jsxs(e.Fragment,{children:[e.jsxs(B,{onClick:S,children:[e.jsx(ns,{className:"mr-2 size-4"}),t?`Export ${s.toLocaleString()} members`:"Export all members"]}),e.jsx(ce,{}),e.jsxs(B,{onClick:()=>w(!0),children:[e.jsx(rs,{className:"mr-2 size-4"}),"Add label to ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsxs(B,{onClick:()=>m(!0),children:[e.jsx(_e,{className:"mr-2 size-4"}),"Remove label from ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsxs(B,{disabled:r,onClick:()=>f(!0),children:[e.jsx(is,{className:"mr-2 size-4"}),"Unsubscribe ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsx(ce,{}),e.jsxs(B,{className:"text-destructive focus:text-destructive",disabled:!l,onClick:()=>k(!0),children:[e.jsx(Ge,{className:"mr-2 size-4"}),"Delete ",s.toLocaleString()," ",s===1?"member":"members"]})]})})]}),e.jsx(D,{asChild:!0,children:e.jsx("a",{className:"font-bold",href:"#/members/new",children:"New member"})}),e.jsx(Is,{isLoading:d,memberCount:s,open:j,onConfirm:y,onOpenChange:w}),e.jsx(Rs,{isLoading:d,memberCount:s,nql:a,open:v,onConfirm:_,onOpenChange:m}),e.jsx(As,{isLoading:d||u,memberCount:s,newsletters:c,open:p,onConfirm:T,onOpenChange:f}),e.jsx(Us,{isLoading:g,memberCount:s,open:h,onConfirm:R,onExportBackup:$,onOpenChange:k})]})},Vs=({children:t,className:s,...a})=>e.jsx("section",{className:Ce("flex gap-6 flex-col p-4 lg:p-8 size-full grow",s),...a,children:t}),Ks=[{value:"paid",label:"Paid"},{value:"free",label:"Free"},{value:"comped",label:"Complimentary"}],Ys=[{value:"subscribed",label:"Subscribed"},{value:"unsubscribed",label:"Unsubscribed"},{value:"email-disabled",label:"Email disabled"}],Ws=[{value:"subscribed",label:"Subscribed to at least one"},{value:"unsubscribed",label:"Unsubscribed from all"},{value:"email-disabled",label:"Email disabled"}],Gs=[{value:"month",label:"Monthly"},{value:"year",label:"Yearly"}],Hs=[{value:"active",label:"Active"},{value:"trialing",label:"Trialing"},{value:"canceled",label:"Canceled"},{value:"unpaid",label:"Unpaid"},{value:"past_due",label:"Past Due"},{value:"incomplete",label:"Incomplete"},{value:"incomplete_expired",label:"Incomplete - Expired"}],F=[{value:"is",label:"is"},{value:"is-not",label:"is not"}],xe=[{value:"is",label:"is"},{value:"contains",label:"contains"},{value:"does-not-contain",label:"does not contain"},{value:"starts-with",label:"starts with"},{value:"ends-with",label:"ends with"}],K=[{value:"is-less",label:"before"},{value:"is-or-less",label:"on or before"},{value:"is-greater",label:"after"},{value:"is-or-greater",label:"on or after"}],ee=[{value:"is",label:"is"},{value:"is-greater",label:"is greater than"},{value:"is-less",label:"is less than"}],Qs=[{value:"1",label:"More like this"},{value:"0",label:"Less like this"}];function Xs({labels:t=[],tiers:s=[],newsletters:a=[],hasMultipleTiers:l=!1,paidMembersEnabled:n=!1,emailAnalyticsEnabled:r=!1,labelsOptions:c=[],tiersOptions:i=[],onTiersSearchChange:d,tiersSearchValue:b,tiersLoading:g=!1,offersOptions:u=[],hasOffers:x=!1,postResourceOptions:j=[],onPostResourceSearchChange:w,postResourceSearchValue:v,postResourceLoading:m=!1,emailResourceOptions:p=[],onEmailResourceSearchChange:f,emailResourceSearchValue:h,emailResourceLoading:k=!1,membersTrackSources:S=!1,emailTrackOpens:y=!1,emailTrackClicks:_=!1,audienceFeedbackEnabled:T=!1,siteTimezone:R="Etc/UTC"}){return o.useMemo(()=>{const $=[],L=new Date(new Date().toLocaleString("en-US",{timeZone:R})).toISOString().split("T")[0],M=[];if(M.push({key:"name",label:"Name",type:"text",icon:e.jsx(Je,{className:"size-4"}),placeholder:"Enter name...",operators:xe,defaultOperator:"is",className:"w-48"}),M.push({key:"email",label:"Email",type:"text",icon:e.jsx(q,{className:"size-4"}),placeholder:"Enter email...",operators:xe,defaultOperator:"is",className:"w-64"}),(t.length>0||c.length>0)&&M.push({key:"label",label:"Label",type:"select",icon:e.jsx(_e,{className:"size-4"}),options:c.length>0?c:t.map(N=>({value:N.slug,label:N.name})),customRenderer:N=>Qe.createElement(zs,N),defaultOperator:"is_any_of",hideOperatorSelect:!0,searchable:!0,className:"w-64"}),a.length<=1&&M.push({key:"subscribed",label:"Newsletter subscription",type:"select",icon:e.jsx(q,{className:"size-4"}),options:Ys,operators:F,searchable:!1}),M.push({key:"last_seen_at",label:"Last seen",type:"date",icon:e.jsx(ws,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),M.push({key:"created_at",label:"Created",type:"date",icon:e.jsx(ys,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),S&&M.push({key:"signup",label:"Signed up on post/page",type:"select",icon:e.jsx(vs,{className:"size-4"}),options:j,operators:F,searchable:!0,onSearchChange:w,searchValue:v,isLoading:m,placeholder:"Select a post or page...",className:"w-64"}),$.push({group:"Basic",fields:M}),a.length>1){const N=[];N.push({key:"subscribed",label:"All newsletters",type:"select",icon:e.jsx(q,{className:"size-4"}),options:Ws,operators:F,searchable:!1}),a.forEach(E=>{N.push({key:`newsletters.${E.slug}`,label:E.name,type:"select",icon:e.jsx(os,{className:"size-4"}),options:[{value:"subscribed",label:"Subscribed"},{value:"unsubscribed",label:"Unsubscribed"}],operators:[{value:"is",label:"is"}],searchable:!1,hideOperatorSelect:!0})}),$.push({group:"Newsletters",fields:N})}if(n){const N=[];l&&N.push({key:"tier_id",label:"Membership tier",type:"select",icon:e.jsx(de,{className:"size-4"}),options:i.length>0?i:s.map(E=>({value:E.id,label:E.name})),operators:F,searchable:!0,onSearchChange:d,searchValue:b,isLoading:g,className:"w-64"}),N.push({key:"status",label:"Member status",type:"select",icon:e.jsx(cs,{className:"size-4"}),options:Ks,operators:F,searchable:!1}),N.push({key:"subscriptions.plan_interval",label:"Billing period",type:"select",icon:e.jsx(ds,{className:"size-4"}),options:Gs,operators:F,searchable:!1}),N.push({key:"subscriptions.status",label:"Stripe subscription status",type:"select",icon:e.jsx(de,{className:"size-4"}),options:Hs,operators:F,searchable:!1}),N.push({key:"subscriptions.start_date",label:"Paid start date",type:"date",icon:e.jsx(us,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),N.push({key:"subscriptions.current_period_end",label:"Next billing date",type:"date",icon:e.jsx(ms,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),S&&N.push({key:"conversion",label:"Subscription started on post/page",type:"select",icon:e.jsx(ps,{className:"size-4"}),options:j,operators:F,searchable:!0,onSearchChange:w,searchValue:v,isLoading:m,placeholder:"Select a post or page...",className:"w-64"}),x&&N.push({key:"offer_redemptions",label:"Offer",type:"multiselect",icon:e.jsx(fs,{className:"size-4"}),options:u,defaultOperator:"is_any_of",hideOperatorSelect:!0,autoCloseOnSelect:!0,searchable:!0,className:"w-64"}),$.push({group:"Subscription",fields:N})}if(r){const N=[];N.push({key:"email_count",label:"Emails sent (all time)",type:"number",icon:e.jsx(fe,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,className:"w-24"}),N.push({key:"email_opened_count",label:"Emails opened (all time)",type:"number",icon:e.jsx(be,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,className:"w-24"}),y&&N.push({key:"email_open_rate",label:"Open rate (all time)",type:"number",icon:e.jsx(bs,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,max:100,suffix:"%",className:"w-24"}),N.push({key:"emails.post_id",label:"Sent email",type:"select",icon:e.jsx(fe,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),y&&N.push({key:"opened_emails.post_id",label:"Opened email",type:"select",icon:e.jsx(be,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),_&&N.push({key:"clicked_links.post_id",label:"Clicked email",type:"select",icon:e.jsx(hs,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),T&&N.push({key:"newsletter_feedback",label:"Responded with feedback",type:"select",icon:e.jsx(Xe,{className:"size-4"}),options:p,operators:Qs,defaultOperator:"1",searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),$.push({group:"Email",fields:N})}return $},[t,s,a,l,n,r,c,i,d,b,g,u,x,j,w,v,m,p,f,h,k,S,y,_,T,R])}const Js="PagesResponseType",Zs=ke({dataType:Js,path:"/pages/"});function je(t,s){return s?`${t}+title:~'${s.replace(/'/g,"\\'")}'`:t}function ve(t){const[s,a]=o.useState(""),l=t==="post",n=je(l?"status:published":"(status:published,status:sent)+newsletter_id:-null",s),{data:r,isLoading:c}=ks({searchParams:{filter:n,limit:"25",fields:"id,title",order:"published_at DESC"}}),{data:i,isLoading:d}=Zs({searchParams:{filter:je("status:published",s),limit:"25",fields:"id,title",order:"published_at DESC"},enabled:l}),b=o.useMemo(()=>{const u=r?.posts||[];if(!l)return u.map(w=>({value:w.id,label:w.title}));const x=i?.pages||[],j=[];for(const w of u)j.push({value:w.id,label:w.title});for(const w of x)j.push({value:w.id,label:w.title,detail:"Page"});return j},[r,i,l]),g=o.useCallback(u=>{a(u)},[]);return{options:b,isLoading:c||l&&d,searchValue:s,onSearchChange:g}}function qs(t){const s=new Map,a=[],l=[];for(const n of t)n.redemption_type==="retention"&&(n.cadence==="month"?a.push(n.id):n.cadence==="year"&&l.push(n.id));return a.length>0&&s.set("retention:month",a),l.length>0&&s.set("retention:year",l),s}function et(t,s,a){const l=[];for(const n of t)s&&n.redemption_type==="retention"||l.push({value:n.id,label:n.name});return s&&(a.has("retention:month")&&l.push({value:"retention:month",label:"Monthly Retention"}),a.has("retention:year")&&l.push({value:"retention:year",label:"Yearly Retention"})),l}const we=({filters:t,onFiltersChange:s})=>{const{data:a}=Te({searchParams:{limit:"100"}}),{data:l}=js({searchParams:{limit:"100"}}),{data:n}=xs({}),{data:r}=De({searchParams:{limit:"100"}}),{data:c}=Ze({}),{data:i}=Le({}),d=c?.settings||[],b=V(d,"paid_members_enabled")===!0,g=i?.config?.emailAnalytics===!0,u=V(d,"members_track_sources")===!0,x=V(d,"email_track_opens")===!0,j=V(d,"email_track_clicks")===!0,w=i?.config?.labs?.audienceFeedback===!0,v=i?.config?.labs?.retentionOffers===!0,m=gs(d),p=a?.labels||[],f=l?.tiers||[],h=r?.newsletters||[],k=n?.offers||[],S=f.filter(C=>C.type==="paid"&&C.active),y=S.length>1,_=o.useMemo(()=>v?qs(k):new Map,[k,v]),T=o.useMemo(()=>et(k,v,_),[k,v,_]),R=o.useMemo(()=>_.size===0?t:t.map(C=>{if(C.field!=="offer_redemptions")return C;const O=[...C.values],z=[],A=new Set;for(const[I,U]of _)U.length>0&&U.every(Z=>O.includes(Z))&&(z.push(I),U.forEach(Z=>A.add(Z)));for(const I of O)A.has(I)||z.push(I);return{...C,values:z}}),[t,_]),$=o.useCallback(C=>{if(_.size===0){s(C);return}const O=C.map(z=>{if(z.field!=="offer_redemptions")return z;const A=[];for(const I of z.values){const U=_.get(I);U?A.push(...U):A.push(I)}return{...z,values:[...new Set(A)]}});s(O)},[s,_]),L=ve("post"),M=ve("email"),N=Xs({labels:p,tiers:S,newsletters:h.filter(C=>C.status==="active"),hasMultipleTiers:y,paidMembersEnabled:b,emailAnalyticsEnabled:g,labelsOptions:p.map(C=>({value:C.slug,label:C.name})),tiersOptions:S.map(C=>({value:C.id,label:C.name})),offersOptions:T,hasOffers:k.length>0,postResourceOptions:L.options,onPostResourceSearchChange:L.onSearchChange,postResourceSearchValue:L.searchValue,postResourceLoading:L.isLoading,emailResourceOptions:M.options,onEmailResourceSearchChange:M.onSearchChange,emailResourceSearchValue:M.searchValue,emailResourceLoading:M.isLoading,membersTrackSources:u,emailTrackOpens:x,emailTrackClicks:j,audienceFeedbackEnabled:w,siteTimezone:m}),E=t.length>0;return e.jsx(as,{addButtonIcon:E?e.jsx(Ns,{}):e.jsx(Ss,{}),addButtonText:E?"Add filter":"Filter",allowMultiple:!0,className:`[&>button]:order-last ${E?"[&>button]:border-none":"w-auto"}`,clearButtonClassName:"font-normal text-muted-foreground",clearButtonIcon:e.jsx(se,{}),clearButtonText:"Clear",fields:N,filters:R,keyboardShortcut:"f",popoverAlign:E?"start":"end",showClearButton:E,showSearchInput:!1,onChange:$})},st=({children:t,totalMembers:s,isLoading:a})=>e.jsxs(Y,{className:"relative !pb-6 md:sticky",variant:"inline-nav",children:[e.jsxs(Y.Title,{children:["Members ",!a&&e.jsx("span",{className:"font-normal text-muted-foreground",children:s.toLocaleString()})]}),t]}),tt=({children:t})=>e.jsx("div",{className:"size-full",children:e.jsx("div",{className:"relative flex size-full flex-col",children:e.jsx("div",{className:"grid w-full grow",children:e.jsx("div",{className:"flex h-full flex-col","data-testid":"members-page",children:t})})})});function at(t){if(!t)return{text:"Unknown",isKnown:!1};try{const s=JSON.parse(t);return s.country?s.country_code==="US"&&s.region?{text:`${s.region}, US`,isKnown:!0}:{text:s.country,isKnown:!0}:{text:"Unknown",isKnown:!1}}catch{return{text:"Unknown",isKnown:!1}}}function lt(t){switch(t){case"paid":return"Paid";case"comped":return"Complimentary";default:return"Free"}}function rt({item:t}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Cs,{avatarImage:t.avatar_image,className:"size-10 min-w-10 md:size-10 md:min-w-10",memberId:t.id}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.name||t.email||"Anonymous"}),t.name&&t.email&&e.jsx("div",{className:"truncate text-sm text-muted-foreground","data-testid":"member-email",children:t.email})]})]})}function nt({status:t,tiers:s}){const a=s?.map(l=>l.name).join(", ");return e.jsx("div",{className:"flex justify-end lg:justify-start",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm",children:lt(t)}),a&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:a})]})})}function it({emailOpenRate:t}){const s=t!=null;return e.jsx("div",{className:`hidden text-sm lg:block ${s?"text-foreground":"text-muted-foreground"}`,children:s?`${Math.round(t)}%`:"N/A"})}function ot({geolocation:t}){const s=at(t);return e.jsx("div",{className:`hidden truncate text-sm lg:block ${s.isKnown?"text-foreground":"text-muted-foreground"}`,children:s.text})}function ct({createdAt:t}){return e.jsxs("div",{className:"hidden lg:block",children:[e.jsx("div",{className:"text-sm",children:ue.utc(t).format("D MMM YYYY")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:ue.utc(t).fromNow()})]})}function dt({item:t,gridCols:s,showEmailOpenRate:a,onClick:l,...n}){return e.jsxs("div",{...n,className:`grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_7rem] items-center gap-2 border-b px-4 py-3 hover:bg-muted/50 lg:gap-4 ${s}`,"data-testid":"members-list-item",onClick:()=>l(t.id),children:[e.jsx(rt,{item:t}),e.jsx(nt,{status:t.status,tiers:t.tiers}),a&&e.jsx(it,{emailOpenRate:t.email_open_rate}),e.jsx(ot,{geolocation:t.geolocation}),e.jsx(ct,{createdAt:t.created_at})]})}const ye=({height:t})=>e.jsx("div",{"aria-hidden":"true",className:"flex",children:e.jsx("div",{className:"flex",style:{height:t}})}),ut=o.forwardRef(function(s,a){return e.jsx("div",{ref:a,...s,"aria-hidden":"true",className:"relative flex flex-col",children:e.jsx("div",{className:"relative z-10 h-[72px] animate-pulse",children:e.jsx("div",{className:"h-full rounded-md bg-muted","data-testid":"loading-placeholder"})})})});function mt({items:t,totalItems:s,hasNextPage:a,isFetchingNextPage:l,fetchNextPage:n,isLoading:r,showEmailOpenRate:c=!0,onRowClick:i}){const d=o.useRef(null);Ls({parentRef:d,isLoading:r});const{visibleItems:b,spaceBefore:g,spaceAfter:u}=_s({items:t,totalItems:s,hasNextPage:a,isFetchingNextPage:l,fetchNextPage:n,parentRef:d,estimateSize:()=>72}),x=m=>{i?i(m):window.location.hash=`/members/${m}`},v=c?"lg:grid-cols-[3fr_1fr_1fr_1.5fr_1.5fr]":"lg:grid-cols-[3fr_1fr_1.5fr_1.5fr]";return e.jsx("div",{ref:d,className:"overflow-hidden",children:e.jsxs("div",{className:"flex flex-col","data-testid":"members-list",children:[e.jsxs("div",{className:`sticky top-0 z-10 hidden border-b bg-background lg:grid lg:gap-4 lg:px-4 lg:py-3 ${v}`,children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Member"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Status"}),c&&e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Open rate"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Location"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Created"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(ye,{height:g}),b.map(({key:m,virtualItem:p,item:f,props:h})=>p.index>t.length-1?e.jsx(ut,{...h},m):e.jsx(dt,{...h,gridCols:v,item:f,showEmailOpenRate:c,onClick:x},m)),e.jsx(ye,{height:u})]})]})})}const pt=["name","email","label","subscribed","last_seen_at","created_at","signup","newsletters","tier_id","status","subscriptions.plan_interval","subscriptions.status","subscriptions.start_date","subscriptions.current_period_end","conversion","email_count","email_opened_count","email_open_rate","emails.post_id","opened_emails.post_id","clicked_links.post_id","newsletter_feedback","offer_redemptions"],Fe=new Set(["label","offer_redemptions"]);function ft(t){return"'"+t.replace(/'/g,"\\'")+"'"}function bt(t){return{"is-less":"<","is-or-less":"<=",is:"","is-not":"-","is-greater":">","is-or-greater":">=",contains:"~","does-not-contain":"-~","starts-with":"~^","ends-with":"~$",before:"<",after:">",is_not:"-",is_any_of:"",is_not_any_of:"-",greater_than:">",less_than:"<",equals:"",not_equals:"-"}[t]??""}function ht(t){const s=[];for(const a of t){if(!a.values[0]&&a.values[0]!==0)continue;const l=a.field,n=a.operator,r=a.values[0],c=bt(n);if(l.startsWith("newsletters.")){const i=l.replace("newsletters.","");String(r)==="subscribed"?s.push(`(newsletters.slug:${i}+email_disabled:0)`):s.push(`(newsletters.slug:-${i},email_disabled:1)`);continue}switch(l){case"name":case"email":{const i=ft(String(r));s.push(`${l}:${c}${i}`);break}case"label":case"tier_id":case"offer_redemptions":{if(Array.isArray(a.values)&&a.values.length>0){const i="["+a.values.join(",")+"]";s.push(`${l}:${c}${i}`)}else r&&s.push(`${l}:${c}${r}`);break}case"status":{s.push(`status:${c}${r}`);break}case"subscribed":{r==="email-disabled"?n==="is"?s.push("(email_disabled:1)"):s.push("(email_disabled:0)"):n==="is"||n==="is_any_of"?r==="subscribed"?s.push("(subscribed:true+email_disabled:0)"):s.push("(subscribed:false+email_disabled:0)"):r==="subscribed"?s.push("(subscribed:false,email_disabled:1)"):s.push("(subscribed:true,email_disabled:1)");break}case"newsletters":{const[i,d]=String(r).split(":");d==="subscribed"||n==="is"&&d!=="unsubscribed"?s.push(`(newsletters.slug:${i}+email_disabled:0)`):s.push(`(newsletters.slug:-${i},email_disabled:1)`);break}case"last_seen_at":case"created_at":case"subscriptions.start_date":case"subscriptions.current_period_end":{const i=String(r);s.push(`${l}:${c}'${i}'`);break}case"email_count":case"email_opened_count":case"email_open_rate":{s.push(`${l}:${c}${r}`);break}case"subscriptions.plan_interval":{s.push(`subscriptions.plan_interval:${c}${r}`);break}case"subscriptions.status":{s.push(`subscriptions.status:${c}${r}`);break}case"signup":case"conversion":case"emails.post_id":case"opened_emails.post_id":case"clicked_links.post_id":{s.push(`${l}:${c}'${r}'`);break}case"newsletter_feedback":{const i=n;s.push(`(feedback.post_id:'${r}'+feedback.score:${i})`);break}default:typeof r=="string"&&r.includes(" ")?s.push(`${l}:${c}'${r}'`):s.push(`${l}:${c}${r}`)}}return s.length?s.join("+"):void 0}function gt(t){if(!t)return null;const s=t.indexOf(":");return s<=0?null:{operator:t.substring(0,s),value:t.substring(s+1)}}function xt(t){const s=[];for(const[a,l]of t.entries()){if(a==="search"||!a.startsWith("newsletters.")&&!pt.includes(a)||!l)continue;const r=gt(l);if(r){const c=Fe.has(a)?r.value?r.value.split(","):[]:[r.value];s.push({id:a,field:a,operator:r.operator,values:c})}}return s}function Ne(t,s){const a=new URLSearchParams;for(const l of t){const n=l.field;if(Fe.has(n)){const r=l.values.length>0?l.values.map(c=>String(c)).join(","):"";a.set(n,`${l.operator}:${r}`);continue}if(l.values[0]!==void 0){const r=`${l.operator}:${String(l.values[0])}`;a.set(n,r)}}return s&&a.set("search",s),a}function jt(){const[t,s]=qe(),a=o.useMemo(()=>xt(t),[t]),l=o.useMemo(()=>t.get("search")??"",[t]),n=o.useCallback((b,g={})=>{const u=typeof b=="function"?b(a):b,x=t.get("search")??void 0,j=Ne(u,x),w=g.replace??!0;s(j,{replace:w})},[a,t,s]),r=o.useCallback((b,g={})=>{const u=Ne(a,b||void 0),x=g.replace??!0;s(u,{replace:x})},[a,s]),c=o.useCallback(({replace:b=!0}={})=>{s(new URLSearchParams,{replace:b})},[s]),i=o.useMemo(()=>ht(a),[a]),d=a.length>0||l.length>0;return{filters:a,nql:i,search:l,setFilters:n,setSearch:r,clearFilters:c,isFiltered:d}}const vt=["subscriptions.plan_interval","subscriptions.status","subscriptions.start_date","subscriptions.current_period_end","conversion","offer_redemptions"],$t=()=>{const{filters:t,nql:s,setFilters:a,isFiltered:l,clearFilters:n}=jt(),{data:r}=Le(),c=r?.config?.emailAnalytics===!0,i=o.useMemo(()=>!t.some(k=>vt.includes(k.field)),[t]),d=o.useMemo(()=>{if(s)return{include:"labels,tiers",limit:"50",order:"created_at desc",filter:s}},[s]),{data:b,isError:g,isFetching:u,isFetchingNextPage:x,isRefetching:j,fetchNextPage:w,hasNextPage:v}=es({searchParams:d,keepPreviousData:!0}),m=u&&!x&&!j,p=b?.meta?.pagination?.total??0,f=t.length>0,h=Ce("flex flex-row",!f&&"items-center gap-2",f&&"col-span-full row-start-4 pt-5");return e.jsxs(tt,{children:[e.jsxs(st,{isLoading:m,totalMembers:p,children:[e.jsx(Y.Actions,{children:e.jsxs(Y.ActionGroup,{children:[!f&&e.jsx(we,{filters:t,onFiltersChange:a}),e.jsx(Bs,{canBulkDelete:i,isFiltered:l,memberCount:p,nql:s})]})}),f&&e.jsx("div",{className:h,children:e.jsx(we,{filters:t,onFiltersChange:a})})]}),e.jsx(Vs,{children:m?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(ss,{size:"lg"})}):g?e.jsxs("div",{className:"mb-16 flex h-full flex-col items-center justify-center",children:[e.jsx("h2",{className:"mb-2 text-xl font-medium",children:"Error loading members"}),e.jsx("p",{className:"mb-4 text-muted-foreground",children:"Please reload the page to try again"}),e.jsx(D,{onClick:()=>window.location.reload(),children:"Reload page"})]}):b?.members.length?e.jsx(mt,{fetchNextPage:w,hasNextPage:v,isFetchingNextPage:x,isLoading:u&&!x,items:b.members,showEmailOpenRate:c,totalItems:p}):e.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:l?e.jsxs(e.Fragment,{children:[e.jsx(he,{title:"No members match the current filter",children:e.jsx(me,{})}),e.jsx(D,{className:"mt-4",variant:"outline",onClick:()=>n({replace:!1}),children:"Show all members"})]}):e.jsx(he,{title:"No members yet",children:e.jsx(me,{})})})})]})};export{$t as default};
|
|
1
|
+
import{j as e,r as o,cs as $e,ct as Oe,cv as ze,cr as Ie,cM as Se,X as se,cu as Re,B as D,a0 as oe,ac as ke,ab as te,D as W,v as G,w as H,x as Q,ah as X,cX as Ae,cY as Ue,cZ as Be,W as P,b1 as Ve,ar as Ke,b2 as Ye,b3 as We,b5 as B,b6 as ce,cm as _e,c9 as Ge,c_ as He,z as Ce,e as Qe,cG as de,c$ as Xe,aO as Je,aM as Ze,aK as Le,d0 as V,cJ as ue,bS as qe,d1 as es,f as ss,cl as me}from"./index-CM-iA6b-.js";import{C as ae,a as le,b as Me,d as pe,e as re,f as ts,F as as}from"./filters-CscMb_Gl.js";import{P as ls,T as rs}from"./tags-CqHx8i6Q.js";import{u as De}from"./newsletters-DNt9qd4h.js";import{D as ns,b as is,N as os,C as cs,c as ds,d as us,e as ms,A as ps,T as fs,S as fe,a as be,P as bs,M as hs}from"./ticket-BtYGyQvH.js";import{g as gs}from"./get-site-timezone-BDBAcjmq.js";import{u as xs}from"./offers-CU0KFuyW.js";import{u as js}from"./tiers-CPwRaPSt.js";import{M as q,U as vs}from"./user-plus-BS8SGBmk.js";import{E as ws,C as ys,F as Ns,b as Ss}from"./loader-circle-B5ILzHHu.js";import{u as ks}from"./posts-DTy4lguT.js";import{H as Y,u as _s}from"./use-infinite-virtual-scroll-DTqnBtHM.js";import{M as Cs,u as Ls}from"./use-scroll-restoration-o1DrSdlb.js";import{E as he}from"./empty-indicator-DoxAratw.js";const Ms=({label:t,onSave:s,onCancel:a,onDelete:l,isDuplicateName:n})=>{const[r,c]=o.useState(t.name),[i,d]=o.useState(!1),[b,g]=o.useState(""),[u,x]=o.useState(!1),[j,w]=o.useState(!1),v=o.useRef(null),m=u||j;o.useEffect(()=>{v.current?.focus(),v.current?.select()},[]);const p=S=>{const y=S.trim();return y?n?.(y,t.id)?"A label with this name already exists":"":"Name is required"},f=async()=>{const S=p(r);if(S){g(S);return}x(!0);try{await s(t.id,r.trim()),a()}catch{x(!1)}},h=S=>{S.key==="Enter"?(S.preventDefault(),f()):S.key==="Escape"&&(S.preventDefault(),m||a())},k=async()=>{w(!0);try{await l(t.id)}catch{w(!1),d(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2 py-1.5","data-edit-row":!0,children:[e.jsx("input",{ref:v,className:"h-7 w-full rounded border border-border bg-background px-2 text-sm outline-none focus:ring-1 focus:ring-ring disabled:opacity-50",disabled:m,type:"text",value:r,onChange:S=>{c(S.target.value),g("")},onKeyDown:h}),b&&e.jsx("span",{className:"text-xs text-destructive",children:b}),i?e.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[e.jsx("span",{className:"flex-1 font-semibold",children:"Delete label?"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"destructive",onClick:k,children:j?"Deleting...":"Delete"})]}):e.jsxs("div",{className:"flex items-center",children:[e.jsx(D,{className:"h-6 gap-1 px-1.5 text-xs text-red hover:bg-red/5 hover:text-red",disabled:m,size:"sm",variant:"ghost",onClick:()=>d(!0),children:"Delete"}),e.jsxs("div",{className:"ml-auto flex gap-1",children:[e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",variant:"outline",onClick:a,children:"Cancel"}),e.jsx(D,{className:"h-6 px-2 text-xs",disabled:m,size:"sm",onClick:f,children:u?"Saving...":"Save"})]})]})]})},Ds=({label:t,isSelected:s,showEdit:a,onToggle:l,onEditClick:n})=>e.jsxs(re,{className:"group",value:t.slug,onSelect:()=>l(t.slug),children:[e.jsx("span",{className:"flex-1 truncate",children:t.name}),a?e.jsxs("button",{"aria-label":`Edit label ${t.name}`,className:"relative ml-1 flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground",type:"button",onClick:r=>{r.stopPropagation(),r.preventDefault(),n()},children:[s&&e.jsx(oe,{className:"absolute size-3 text-primary transition-opacity duration-150 group-hover:opacity-0"}),e.jsx(ls,{className:"absolute size-3 translate-x-2 opacity-0 transition-all duration-150 ease-out group-hover:translate-x-0 group-hover:opacity-100"})]}):s&&e.jsx(oe,{className:"size-4 shrink-0 text-primary"})]}),Ee=({labels:t,selectedSlugs:s,search:a,onToggle:l,onEdit:n,onDelete:r,isDuplicateName:c,canCreateFromSearch:i,onCreate:d,isCreating:b,onSearchClear:g})=>{const[u,x]=o.useState(null),j=t.filter(h=>h.name.toLowerCase().includes(a.toLowerCase())),w=!!d&&a.trim()&&i?.(a),v=!!n,m=async()=>{if(d){const h=await d(a.trim());h&&l(h.slug),g?.()}},p=async(h,k)=>{n&&await n(h,k)},f=async h=>{r&&(await r(h),x(null))};return e.jsxs(e.Fragment,{children:[!w&&j.length===0&&e.jsx(Me,{children:"No labels found"}),j.length>0&&e.jsx(pe,{className:"[&_[cmdk-group-heading]]:hidden",children:j.map(h=>u===h.id?e.jsx(Ms,{isDuplicateName:c,label:h,onCancel:()=>x(null),onDelete:f,onSave:p},h.id):e.jsx(Ds,{isSelected:s.includes(h.slug),label:h,showEdit:v,onEditClick:()=>x(h.id),onToggle:l},h.id))}),w&&e.jsx(pe,{className:"[&_[cmdk-group-heading]]:hidden",children:e.jsxs(re,{disabled:b,onSelect:m,children:[e.jsx(Re,{className:"size-4"}),b?"Creating...":`Create "${a.trim()}"`]})})]})},Pe=({labels:t,onToggle:s})=>e.jsx(e.Fragment,{children:t.map(a=>e.jsxs(Se,{className:"cursor-pointer gap-1 pr-1",variant:"outline",onClick:l=>{l.stopPropagation(),s(a.slug)},children:[a.name,e.jsx(se,{className:"size-3"})]},a.id))}),ne=({labels:t,selectedSlugs:s,isLoading:a,onToggle:l,canCreateFromSearch:n,onCreate:r,isCreating:c,onEdit:i,onDelete:d,isDuplicateName:b,inline:g=!1,align:u="start"})=>{const x=s.map(j=>t.find(w=>w.slug===j)).filter(j=>!!j);return g?e.jsx(Es,{align:u,canCreateFromSearch:n,isCreating:c,isDuplicateName:b,isLoading:a,labels:t,selectedLabels:x,selectedSlugs:s,onCreate:r,onDelete:d,onEdit:i,onToggle:l}):e.jsx(Ts,{canCreateFromSearch:n,isCreating:c,isDuplicateName:b,isLoading:a,labels:t,selectedLabels:x,selectedSlugs:s,onCreate:r,onDelete:d,onEdit:i,onToggle:l})},Es=({labels:t,selectedLabels:s,selectedSlugs:a,onToggle:l,isLoading:n,align:r="start",canCreateFromSearch:c,onCreate:i,isCreating:d,onEdit:b,onDelete:g,isDuplicateName:u})=>{const x=o.useRef(null),[j,w]=o.useState(0),v=o.useCallback(()=>{const p=x.current,f=p?.parentElement;if(p&&f){const h=p.getBoundingClientRect(),k=f.getBoundingClientRect();w(Math.round(k.left-h.left))}},[]),m=s.length===0?"Select...":s.length===1?s[0].name:`${s.length} labels`;return e.jsxs($e,{onOpenChange:p=>{p&&v()},children:[e.jsx(Oe,{asChild:!0,children:e.jsx("button",{ref:x,className:"flex size-full items-center truncate text-left text-sm",type:"button",children:m})}),e.jsx(ze,{align:r,alignOffset:j,className:"w-64 p-0",children:n?e.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-muted-foreground",children:"Loading labels..."}):e.jsx(Ps,{canCreateFromSearch:c,isCreating:d,isDuplicateName:u,labels:t,selectedLabels:s,selectedSlugs:a,onCreate:i,onDelete:g,onEdit:b,onToggle:l})})]})},Ps=({selectedLabels:t,...s})=>{const[a,l]=o.useState("");return e.jsxs(ae,{shouldFilter:!1,children:[t.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 border-b px-3 py-2",children:e.jsx(Pe,{labels:t,onToggle:s.onToggle})}),e.jsxs("div",{className:"flex items-center border-b px-3",children:[e.jsx(Ie,{className:"mr-2 size-4 shrink-0 opacity-50"}),e.jsx("input",{className:"flex h-9 w-full bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground",placeholder:"Search labels...",value:a,onChange:n=>l(n.target.value)})]}),e.jsx(le,{className:"max-h-64 overflow-y-auto",children:e.jsx(Ee,{...s,search:a,onSearchClear:()=>l("")})})]})},Ts=({labels:t,selectedLabels:s,selectedSlugs:a,onToggle:l,isLoading:n,canCreateFromSearch:r,onCreate:c,isCreating:i,onEdit:d,onDelete:b,isDuplicateName:g})=>{const[u,x]=o.useState(!1),[j,w]=o.useState(""),v=o.useRef(null),m=o.useRef(null);o.useEffect(()=>{if(!u)return;const f=h=>{m.current&&!m.current.contains(h.target)&&x(!1)};return document.addEventListener("pointerdown",f),()=>document.removeEventListener("pointerdown",f)},[u]);const p=f=>{f.key==="Backspace"&&!j&&a.length>0&&l(a[a.length-1]),f.key==="Escape"&&(x(!1),v.current?.blur())};return e.jsxs("div",{ref:m,className:"relative",children:[e.jsxs("div",{className:"flex min-h-9 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border border-transparent bg-gray-150 px-3 py-1 text-sm transition-colors focus-within:border-green focus-within:bg-transparent focus-within:shadow-[0_0_0_2px_rgba(48,207,67,.25)] dark:bg-gray-900",role:"combobox",onClick:()=>{v.current?.focus(),x(!0)},children:[e.jsx(Pe,{labels:s,onToggle:l}),e.jsx("input",{ref:v,className:"min-w-[80px] flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground",placeholder:s.length===0?"Search labels...":"",value:j,onChange:f=>{w(f.target.value),u||x(!0)},onFocus:()=>x(!0),onKeyDown:p})]}),u&&e.jsx("div",{className:"absolute left-0 top-full z-50 mt-1 w-full rounded-md border bg-white shadow-md dark:bg-gray-950",children:n?e.jsx("div",{className:"flex items-center justify-center py-6 text-sm text-muted-foreground",children:"Loading labels..."}):e.jsx(ae,{shouldFilter:!1,children:e.jsx(le,{className:"max-h-64 overflow-y-auto",children:e.jsx(Ee,{canCreateFromSearch:r,isCreating:i,isDuplicateName:g,labels:t,search:j,selectedSlugs:a,onCreate:c,onDelete:b,onEdit:d,onSearchClear:()=>w(""),onToggle:l})})})})]})},J="LabelsResponseType",Te=ke({dataType:J,path:"/labels/"}),Fs=te({method:"POST",path:()=>"/labels/",body:t=>({labels:[t]}),updateQueries:{dataType:J,emberUpdateType:"createOrUpdate",update:(t,s)=>{const a=s;return a&&{...a,labels:a.labels.concat(t.labels)}}}}),$s=te({method:"PUT",path:t=>`/labels/${t.id}/`,body:t=>({labels:[t]}),updateQueries:{dataType:J,emberUpdateType:"createOrUpdate",update:(t,s)=>{const a=s;return a&&{...a,labels:a.labels.map(l=>t.labels.find(({id:n})=>n===l.id)||l)}}}}),Os=te({method:"DELETE",path:t=>`/labels/${t}/`,updateQueries:{dataType:J,emberUpdateType:"delete",update:(t,s,a)=>{const l=s;return l&&{...l,labels:l.labels.filter(n=>n.id!==a)}}}});function ie({selectedSlugs:t,onSelectionChange:s}){const{data:a,isLoading:l}=Te({searchParams:{limit:"100"}}),n=o.useMemo(()=>a?.labels||[],[a]),{mutateAsync:r,isLoading:c}=Fs(),{mutateAsync:i}=$s(),{mutateAsync:d}=Os(),b=o.useRef(t);b.current=t;const g=o.useCallback(m=>{const p=b.current;p.includes(m)?s(p.filter(f=>f!==m)):s([...p,m])},[s]),u=o.useCallback((m,p)=>{const f=m.trim().toLowerCase();return n.some(h=>h.name.toLowerCase()===f&&h.id!==p)},[n]),x=o.useCallback(m=>{const p=m.trim();return p?!u(p):!1},[u]),j=o.useCallback(async m=>{const p=m.trim();return!p||u(p)?void 0:(await r({name:p}))?.labels?.[0]},[r,u]),w=o.useCallback(async(m,p)=>{const f=p.trim();if(!f||u(f,m))return;const h=n.find(y=>y.id===m),S=(await i({id:m,name:f}))?.labels?.[0];if(h&&S&&h.slug!==S.slug){const y=b.current;y.includes(h.slug)&&s(y.map(_=>_===h.slug?S.slug:_))}},[i,u,n,s]),v=o.useCallback(async m=>{const p=n.find(f=>f.id===m);if(await d(m),p){const f=b.current;f.includes(p.slug)&&s(f.filter(h=>h!==p.slug))}},[d,n,s]);return{labels:n,selectedSlugs:t,isLoading:l,toggleLabel:g,createLabel:j,editLabel:w,deleteLabel:v,isDuplicateName:u,canCreateFromSearch:x,isCreating:c}}const zs=({values:t,onChange:s})=>{const a=ie({selectedSlugs:t,onSelectionChange:s});return e.jsx(ne,{isDuplicateName:a.isDuplicateName,labels:a.labels,selectedSlugs:a.selectedSlugs,inline:!0,onDelete:a.deleteLabel,onEdit:a.editLabel,onToggle:a.toggleLabel})};function Is({open:t,memberCount:s,onOpenChange:a,onConfirm:l,isLoading:n=!1}){const[r,c]=o.useState([]),i=ie({selectedSlugs:r,onSelectionChange:c}),d=o.useCallback(g=>{g||c([]),a(g)},[a]),b=()=>{const g=i.labels.filter(u=>r.includes(u.slug)).map(u=>u.id);g.length>0&&l(g)};return e.jsx(W,{open:t,onOpenChange:d,children:e.jsxs(G,{className:"gap-5",onOpenAutoFocus:g=>g.preventDefault(),children:[e.jsx(H,{children:e.jsxs(Q,{children:["Add label to ",s.toLocaleString()," ",s===1?"member":"members"]})}),e.jsx(ne,{canCreateFromSearch:i.canCreateFromSearch,isCreating:i.isCreating,isDuplicateName:i.isDuplicateName,isLoading:i.isLoading,labels:i.labels,selectedSlugs:i.selectedSlugs,onCreate:i.createLabel,onDelete:i.deleteLabel,onEdit:i.editLabel,onToggle:i.toggleLabel}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{disabled:r.length===0||n,onClick:b,children:n?"Adding...":r.length>1?`Add ${r.length} labels`:"Add label"})]})]})})}function Rs({open:t,memberCount:s,nql:a,onOpenChange:l,onConfirm:n,isLoading:r=!1}){const[c,i]=o.useState([]),{data:d,isLoading:b}=Ae({searchParams:{...a?{filter:a}:{},include:"labels",limit:"all",fields:"id"},enabled:t}),g=o.useMemo(()=>{const v=new Set;for(const m of d?.members||[])for(const p of m.labels||[])v.add(p.slug);return v},[d]),u=ie({selectedSlugs:c,onSelectionChange:i}),x=o.useMemo(()=>u.labels.filter(v=>g.has(v.slug)),[u.labels,g]),j=o.useCallback(v=>{v||i([]),l(v)},[l]),w=()=>{const v=u.labels.filter(m=>c.includes(m.slug)).map(m=>m.id);v.length>0&&n(v)};return e.jsx(W,{open:t,onOpenChange:j,children:e.jsxs(G,{className:"gap-5",onOpenAutoFocus:v=>v.preventDefault(),children:[e.jsx(H,{children:e.jsxs(Q,{children:["Remove label from ",s.toLocaleString()," ",s===1?"member":"members"]})}),e.jsx(ne,{isDuplicateName:u.isDuplicateName,isLoading:u.isLoading||b,labels:x,selectedSlugs:u.selectedSlugs,onDelete:u.deleteLabel,onEdit:u.editLabel,onToggle:u.toggleLabel}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(D,{disabled:c.length===0||r,onClick:w,children:r?"Removing...":c.length>1?`Remove ${c.length} labels`:"Remove label"})]})]})})}function As({open:t,newsletters:s,memberCount:a,onOpenChange:l,onConfirm:n,isLoading:r=!1}){const[c,i]=o.useState("all"),[d,b]=o.useState([]),[g,u]=o.useState(""),[x,j]=o.useState(!1),w=o.useRef(null),v=o.useRef(null);o.useEffect(()=>{t||(i("all"),b([]),u(""),j(!1))},[t]),o.useEffect(()=>{if(!x)return;const y=_=>{w.current&&!w.current.contains(_.target)&&j(!1)};return document.addEventListener("pointerdown",y),()=>document.removeEventListener("pointerdown",y)},[x]);const m=y=>{y||(i("all"),b([]),u(""),j(!1)),l(y)},p=o.useCallback(y=>{b(_=>_.includes(y)?_.filter(T=>T!==y):[..._,y])},[]),f=s.length>=2,h=()=>{n(!f||c==="all"?null:d)},k=r||f&&c==="selected"&&d.length===0,S=a===1?"member":"members";return e.jsx(W,{open:t,onOpenChange:m,children:e.jsxs(G,{className:"gap-5",children:[e.jsx(H,{children:e.jsx(Q,{children:"Unsubscribe members"})}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{"aria-label":"Unsubscribe scope",className:"flex flex-col gap-3",role:"radiogroup",children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{checked:c==="all",className:"mt-0.5 size-4 cursor-pointer accent-black",name:"unsubscribe-mode",type:"radio",value:"all",onChange:()=>i("all")}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Unsubscribe from all newsletters"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[a.toLocaleString()," ",S," will be unsubscribed from ",s.length," ",s.length===1?"newsletter":"newsletters","."]})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{checked:c==="selected",className:"mt-0.5 size-4 cursor-pointer accent-black",name:"unsubscribe-mode",type:"radio",value:"selected",onChange:()=>i("selected")}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Unsubscribe from selected newsletters"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Select which newsletters to unsubscribe ",a.toLocaleString()," ",S," from."]})]})]})]}),c==="selected"&&e.jsxs("div",{ref:w,className:"relative space-y-2",children:[e.jsx("label",{className:"text-sm font-semibold",htmlFor:"newsletter-search",children:"Newsletters"}),e.jsxs("div",{className:"flex min-h-9 w-full cursor-text flex-wrap items-center gap-1.5 rounded-md border bg-background px-3 py-1 text-sm",onClick:()=>{v.current?.focus(),j(!0)},children:[d.map(y=>{const _=s.find(T=>T.id===y);return _?e.jsxs(Se,{className:"cursor-pointer gap-1 pr-1",variant:"outline",onClick:T=>{T.stopPropagation(),p(y)},children:[_.name,e.jsx(se,{className:"size-3"})]},y):null}),e.jsx("input",{ref:v,className:"min-w-[80px] flex-1 bg-transparent py-1 text-sm outline-none placeholder:text-muted-foreground",id:"newsletter-search",placeholder:d.length===0?"Search newsletters...":"",value:g,onChange:y=>{u(y.target.value),x||j(!0)},onFocus:()=>j(!0),onKeyDown:y=>{y.key==="Escape"&&(j(!1),v.current?.blur()),y.key==="Backspace"&&!g&&d.length>0&&p(d[d.length-1])}})]}),x&&e.jsx("div",{className:"absolute left-0 top-full z-50 mt-1 w-full rounded-md border bg-white shadow-md dark:bg-gray-950",children:e.jsx(ae,{shouldFilter:!1,children:e.jsxs(le,{className:"max-h-64 overflow-y-auto",children:[e.jsx(Me,{children:"No newsletters found."}),s.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())).map(y=>e.jsxs(re,{value:y.name,onSelect:()=>p(y.id),children:[y.name,d.includes(y.id)&&e.jsx(ts,{})]},y.id))]})})})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Are you sure you want to unsubscribe ",a.toLocaleString()," ",S," from all newsletters? They will no longer receive any email newsletters from you."]}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(D,{disabled:k,variant:"destructive",onClick:h,children:r?"Unsubscribing...":"Unsubscribe"})]})]})})}function Us({open:t,memberCount:s,onOpenChange:a,onConfirm:l,onExportBackup:n,isLoading:r=!1}){const[c,i]=o.useState(!1),d=g=>{g||i(!1),a(g)},b=async()=>{if(!(s<1||r||c))try{i(!0),await n(),l()}catch{}finally{i(!1)}};return e.jsx(W,{open:t,onOpenChange:d,children:e.jsxs(G,{className:"gap-5",children:[e.jsx(H,{children:e.jsx(Q,{children:"Delete selected members?"})}),e.jsx("div",{className:"text-sm",children:s>0?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["You're about to delete ",e.jsxs("strong",{children:[s.toLocaleString()," ",s===1?"member":"members"]}),". This is permanent! All Ghost data will be deleted, this will have no effect on subscriptions in Stripe."]}),e.jsx("p",{className:"mt-4",children:"A backup of your selection will be automatically downloaded to your device before deletion."})]}):e.jsx("p",{children:"No members are selected."})}),e.jsxs(X,{children:[e.jsx(D,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(D,{disabled:r||c||s<1,variant:"destructive",onClick:b,children:r||c?"Deleting...":"Download backup & delete members"})]})]})})}async function ge(t){const s=new URLSearchParams({limit:"all"});t&&s.set("filter",t);const a=new Date().toJSON().substring(0,10);await He(`/members/upload/?${s}`,`members.${a}.csv`)}const Bs=({isFiltered:t,memberCount:s,nql:a,canBulkDelete:l})=>{const{data:n,isLoading:r}=De({searchParams:{filter:"status:-archived",limit:"50"}}),c=n?.newsletters||[],{mutateAsync:i,isLoading:d}=Ue(),{mutate:b,isLoading:g}=Be(),[u,x]=o.useState(!1),[j,w]=o.useState(!1),[v,m]=o.useState(!1),[p,f]=o.useState(!1),[h,k]=o.useState(!1),S=o.useCallback(async()=>{try{await ge(a)}catch(L){throw P.error("Export failed",{description:"There was a problem downloading your member data. Please check your connection and try again."}),L}},[a]),y=o.useCallback(async L=>{try{for(const M of L)await i({filter:a||"",all:!a,action:{type:"addLabel",meta:{label:{id:M}}}});w(!1),P.success(L.length>1?"Labels added successfully":"Label added successfully")}catch{P.error("Failed to add label",{description:"There was a problem applying this label. Please try again."})}},[i,a]),_=o.useCallback(async L=>{try{for(const M of L)await i({filter:a||"",all:!a,action:{type:"removeLabel",meta:{label:{id:M}}}});m(!1),P.success(L.length>1?"Labels removed successfully":"Label removed successfully")}catch{P.error("Failed to remove label",{description:"There was a problem removing this label. Please try again."})}},[i,a]),T=o.useCallback(async L=>{const M={filter:a||"",all:!a};if(L===null){try{await i({...M,action:{type:"unsubscribe"}}),f(!1),P.success("Members unsubscribed successfully")}catch{P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}return}x(!0);try{const N=await Promise.allSettled(L.map(O=>i({...M,action:{type:"unsubscribe",newsletter:O}}))),E=N.filter(O=>O.status==="fulfilled").length,C=N.length;f(!1),E===C?P.success(`Unsubscribed from ${C} ${C===1?"newsletter":"newsletters"}`):E>0?P.warning(`Unsubscribed from ${E} of ${C} newsletters`,{description:"Some newsletters could not be unsubscribed. Please try again."}):P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}catch{P.error("Failed to unsubscribe members",{description:"There was a problem unsubscribing these members. Please try again."})}finally{x(!1)}},[i,a]),R=o.useCallback(()=>{b({filter:a||"",all:!a},{onSuccess:()=>{k(!1),P.success("Members deleted successfully")},onError:()=>{P.error("Failed to delete members",{description:"There was a problem deleting these members. Please try again."})}})},[b,a]),$=o.useCallback(async()=>{try{await ge(a)}catch(L){throw P.error("Export failed",{description:"There was a problem downloading your backup. Please check your connection and try again."}),L}},[a]);return e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{children:[e.jsx(Ke,{asChild:!0,children:e.jsx(D,{variant:"outline",children:e.jsx(Ye,{className:"size-4"})})}),e.jsx(We,{align:"end",children:s>0&&e.jsxs(e.Fragment,{children:[e.jsxs(B,{onClick:S,children:[e.jsx(ns,{className:"mr-2 size-4"}),t?`Export ${s.toLocaleString()} members`:"Export all members"]}),e.jsx(ce,{}),e.jsxs(B,{onClick:()=>w(!0),children:[e.jsx(rs,{className:"mr-2 size-4"}),"Add label to ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsxs(B,{onClick:()=>m(!0),children:[e.jsx(_e,{className:"mr-2 size-4"}),"Remove label from ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsxs(B,{disabled:r,onClick:()=>f(!0),children:[e.jsx(is,{className:"mr-2 size-4"}),"Unsubscribe ",s.toLocaleString()," ",s===1?"member":"members"]}),e.jsx(ce,{}),e.jsxs(B,{className:"text-destructive focus:text-destructive",disabled:!l,onClick:()=>k(!0),children:[e.jsx(Ge,{className:"mr-2 size-4"}),"Delete ",s.toLocaleString()," ",s===1?"member":"members"]})]})})]}),e.jsx(D,{asChild:!0,children:e.jsx("a",{className:"font-bold",href:"#/members/new",children:"New member"})}),e.jsx(Is,{isLoading:d,memberCount:s,open:j,onConfirm:y,onOpenChange:w}),e.jsx(Rs,{isLoading:d,memberCount:s,nql:a,open:v,onConfirm:_,onOpenChange:m}),e.jsx(As,{isLoading:d||u,memberCount:s,newsletters:c,open:p,onConfirm:T,onOpenChange:f}),e.jsx(Us,{isLoading:g,memberCount:s,open:h,onConfirm:R,onExportBackup:$,onOpenChange:k})]})},Vs=({children:t,className:s,...a})=>e.jsx("section",{className:Ce("flex gap-6 flex-col p-4 lg:p-8 size-full grow",s),...a,children:t}),Ks=[{value:"paid",label:"Paid"},{value:"free",label:"Free"},{value:"comped",label:"Complimentary"}],Ys=[{value:"subscribed",label:"Subscribed"},{value:"unsubscribed",label:"Unsubscribed"},{value:"email-disabled",label:"Email disabled"}],Ws=[{value:"subscribed",label:"Subscribed to at least one"},{value:"unsubscribed",label:"Unsubscribed from all"},{value:"email-disabled",label:"Email disabled"}],Gs=[{value:"month",label:"Monthly"},{value:"year",label:"Yearly"}],Hs=[{value:"active",label:"Active"},{value:"trialing",label:"Trialing"},{value:"canceled",label:"Canceled"},{value:"unpaid",label:"Unpaid"},{value:"past_due",label:"Past Due"},{value:"incomplete",label:"Incomplete"},{value:"incomplete_expired",label:"Incomplete - Expired"}],F=[{value:"is",label:"is"},{value:"is-not",label:"is not"}],xe=[{value:"is",label:"is"},{value:"contains",label:"contains"},{value:"does-not-contain",label:"does not contain"},{value:"starts-with",label:"starts with"},{value:"ends-with",label:"ends with"}],K=[{value:"is-less",label:"before"},{value:"is-or-less",label:"on or before"},{value:"is-greater",label:"after"},{value:"is-or-greater",label:"on or after"}],ee=[{value:"is",label:"is"},{value:"is-greater",label:"is greater than"},{value:"is-less",label:"is less than"}],Qs=[{value:"1",label:"More like this"},{value:"0",label:"Less like this"}];function Xs({labels:t=[],tiers:s=[],newsletters:a=[],hasMultipleTiers:l=!1,paidMembersEnabled:n=!1,emailAnalyticsEnabled:r=!1,labelsOptions:c=[],tiersOptions:i=[],onTiersSearchChange:d,tiersSearchValue:b,tiersLoading:g=!1,offersOptions:u=[],hasOffers:x=!1,postResourceOptions:j=[],onPostResourceSearchChange:w,postResourceSearchValue:v,postResourceLoading:m=!1,emailResourceOptions:p=[],onEmailResourceSearchChange:f,emailResourceSearchValue:h,emailResourceLoading:k=!1,membersTrackSources:S=!1,emailTrackOpens:y=!1,emailTrackClicks:_=!1,audienceFeedbackEnabled:T=!1,siteTimezone:R="Etc/UTC"}){return o.useMemo(()=>{const $=[],L=new Date(new Date().toLocaleString("en-US",{timeZone:R})).toISOString().split("T")[0],M=[];if(M.push({key:"name",label:"Name",type:"text",icon:e.jsx(Je,{className:"size-4"}),placeholder:"Enter name...",operators:xe,defaultOperator:"is",className:"w-48"}),M.push({key:"email",label:"Email",type:"text",icon:e.jsx(q,{className:"size-4"}),placeholder:"Enter email...",operators:xe,defaultOperator:"is",className:"w-64"}),(t.length>0||c.length>0)&&M.push({key:"label",label:"Label",type:"select",icon:e.jsx(_e,{className:"size-4"}),options:c.length>0?c:t.map(N=>({value:N.slug,label:N.name})),customRenderer:N=>Qe.createElement(zs,N),defaultOperator:"is_any_of",hideOperatorSelect:!0,searchable:!0,className:"w-64"}),a.length<=1&&M.push({key:"subscribed",label:"Newsletter subscription",type:"select",icon:e.jsx(q,{className:"size-4"}),options:Ys,operators:F,searchable:!1}),M.push({key:"last_seen_at",label:"Last seen",type:"date",icon:e.jsx(ws,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),M.push({key:"created_at",label:"Created",type:"date",icon:e.jsx(ys,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),S&&M.push({key:"signup",label:"Signed up on post/page",type:"select",icon:e.jsx(vs,{className:"size-4"}),options:j,operators:F,searchable:!0,onSearchChange:w,searchValue:v,isLoading:m,placeholder:"Select a post or page...",className:"w-64"}),$.push({group:"Basic",fields:M}),a.length>1){const N=[];N.push({key:"subscribed",label:"All newsletters",type:"select",icon:e.jsx(q,{className:"size-4"}),options:Ws,operators:F,searchable:!1}),a.forEach(E=>{N.push({key:`newsletters.${E.slug}`,label:E.name,type:"select",icon:e.jsx(os,{className:"size-4"}),options:[{value:"subscribed",label:"Subscribed"},{value:"unsubscribed",label:"Unsubscribed"}],operators:[{value:"is",label:"is"}],searchable:!1,hideOperatorSelect:!0})}),$.push({group:"Newsletters",fields:N})}if(n){const N=[];l&&N.push({key:"tier_id",label:"Membership tier",type:"select",icon:e.jsx(de,{className:"size-4"}),options:i.length>0?i:s.map(E=>({value:E.id,label:E.name})),operators:F,searchable:!0,onSearchChange:d,searchValue:b,isLoading:g,className:"w-64"}),N.push({key:"status",label:"Member status",type:"select",icon:e.jsx(cs,{className:"size-4"}),options:Ks,operators:F,searchable:!1}),N.push({key:"subscriptions.plan_interval",label:"Billing period",type:"select",icon:e.jsx(ds,{className:"size-4"}),options:Gs,operators:F,searchable:!1}),N.push({key:"subscriptions.status",label:"Stripe subscription status",type:"select",icon:e.jsx(de,{className:"size-4"}),options:Hs,operators:F,searchable:!1}),N.push({key:"subscriptions.start_date",label:"Paid start date",type:"date",icon:e.jsx(us,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),N.push({key:"subscriptions.current_period_end",label:"Next billing date",type:"date",icon:e.jsx(ms,{className:"size-4"}),operators:K,defaultOperator:"is-or-less",defaultValue:L,className:"w-40"}),S&&N.push({key:"conversion",label:"Subscription started on post/page",type:"select",icon:e.jsx(ps,{className:"size-4"}),options:j,operators:F,searchable:!0,onSearchChange:w,searchValue:v,isLoading:m,placeholder:"Select a post or page...",className:"w-64"}),x&&N.push({key:"offer_redemptions",label:"Offer",type:"multiselect",icon:e.jsx(fs,{className:"size-4"}),options:u,defaultOperator:"is_any_of",hideOperatorSelect:!0,autoCloseOnSelect:!0,searchable:!0,className:"w-64"}),$.push({group:"Subscription",fields:N})}if(r){const N=[];N.push({key:"email_count",label:"Emails sent (all time)",type:"number",icon:e.jsx(fe,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,className:"w-24"}),N.push({key:"email_opened_count",label:"Emails opened (all time)",type:"number",icon:e.jsx(be,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,className:"w-24"}),y&&N.push({key:"email_open_rate",label:"Open rate (all time)",type:"number",icon:e.jsx(bs,{className:"size-4"}),operators:ee,defaultOperator:"is",defaultValue:0,min:0,max:100,suffix:"%",className:"w-24"}),N.push({key:"emails.post_id",label:"Sent email",type:"select",icon:e.jsx(fe,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),y&&N.push({key:"opened_emails.post_id",label:"Opened email",type:"select",icon:e.jsx(be,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),_&&N.push({key:"clicked_links.post_id",label:"Clicked email",type:"select",icon:e.jsx(hs,{className:"size-4"}),options:p,operators:F,searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),T&&N.push({key:"newsletter_feedback",label:"Responded with feedback",type:"select",icon:e.jsx(Xe,{className:"size-4"}),options:p,operators:Qs,defaultOperator:"1",searchable:!0,onSearchChange:f,searchValue:h,isLoading:k,placeholder:"Select an email...",className:"w-64"}),$.push({group:"Email",fields:N})}return $},[t,s,a,l,n,r,c,i,d,b,g,u,x,j,w,v,m,p,f,h,k,S,y,_,T,R])}const Js="PagesResponseType",Zs=ke({dataType:Js,path:"/pages/"});function je(t,s){return s?`${t}+title:~'${s.replace(/'/g,"\\'")}'`:t}function ve(t){const[s,a]=o.useState(""),l=t==="post",n=je(l?"status:published":"(status:published,status:sent)+newsletter_id:-null",s),{data:r,isLoading:c}=ks({searchParams:{filter:n,limit:"25",fields:"id,title",order:"published_at DESC"}}),{data:i,isLoading:d}=Zs({searchParams:{filter:je("status:published",s),limit:"25",fields:"id,title",order:"published_at DESC"},enabled:l}),b=o.useMemo(()=>{const u=r?.posts||[];if(!l)return u.map(w=>({value:w.id,label:w.title}));const x=i?.pages||[],j=[];for(const w of u)j.push({value:w.id,label:w.title});for(const w of x)j.push({value:w.id,label:w.title,detail:"Page"});return j},[r,i,l]),g=o.useCallback(u=>{a(u)},[]);return{options:b,isLoading:c||l&&d,searchValue:s,onSearchChange:g}}function qs(t){const s=new Map,a=[],l=[];for(const n of t)n.redemption_type==="retention"&&(n.cadence==="month"?a.push(n.id):n.cadence==="year"&&l.push(n.id));return a.length>0&&s.set("retention:month",a),l.length>0&&s.set("retention:year",l),s}function et(t,s,a){const l=[];for(const n of t)s&&n.redemption_type==="retention"||l.push({value:n.id,label:n.name});return s&&(a.has("retention:month")&&l.push({value:"retention:month",label:"Monthly Retention"}),a.has("retention:year")&&l.push({value:"retention:year",label:"Yearly Retention"})),l}const we=({filters:t,onFiltersChange:s})=>{const{data:a}=Te({searchParams:{limit:"100"}}),{data:l}=js({searchParams:{limit:"100"}}),{data:n}=xs({}),{data:r}=De({searchParams:{limit:"100"}}),{data:c}=Ze({}),{data:i}=Le({}),d=c?.settings||[],b=V(d,"paid_members_enabled")===!0,g=i?.config?.emailAnalytics===!0,u=V(d,"members_track_sources")===!0,x=V(d,"email_track_opens")===!0,j=V(d,"email_track_clicks")===!0,w=i?.config?.labs?.audienceFeedback===!0,v=i?.config?.labs?.retentionOffers===!0,m=gs(d),p=a?.labels||[],f=l?.tiers||[],h=r?.newsletters||[],k=n?.offers||[],S=f.filter(C=>C.type==="paid"&&C.active),y=S.length>1,_=o.useMemo(()=>v?qs(k):new Map,[k,v]),T=o.useMemo(()=>et(k,v,_),[k,v,_]),R=o.useMemo(()=>_.size===0?t:t.map(C=>{if(C.field!=="offer_redemptions")return C;const O=[...C.values],z=[],A=new Set;for(const[I,U]of _)U.length>0&&U.every(Z=>O.includes(Z))&&(z.push(I),U.forEach(Z=>A.add(Z)));for(const I of O)A.has(I)||z.push(I);return{...C,values:z}}),[t,_]),$=o.useCallback(C=>{if(_.size===0){s(C);return}const O=C.map(z=>{if(z.field!=="offer_redemptions")return z;const A=[];for(const I of z.values){const U=_.get(I);U?A.push(...U):A.push(I)}return{...z,values:[...new Set(A)]}});s(O)},[s,_]),L=ve("post"),M=ve("email"),N=Xs({labels:p,tiers:S,newsletters:h.filter(C=>C.status==="active"),hasMultipleTiers:y,paidMembersEnabled:b,emailAnalyticsEnabled:g,labelsOptions:p.map(C=>({value:C.slug,label:C.name})),tiersOptions:S.map(C=>({value:C.id,label:C.name})),offersOptions:T,hasOffers:k.length>0,postResourceOptions:L.options,onPostResourceSearchChange:L.onSearchChange,postResourceSearchValue:L.searchValue,postResourceLoading:L.isLoading,emailResourceOptions:M.options,onEmailResourceSearchChange:M.onSearchChange,emailResourceSearchValue:M.searchValue,emailResourceLoading:M.isLoading,membersTrackSources:u,emailTrackOpens:x,emailTrackClicks:j,audienceFeedbackEnabled:w,siteTimezone:m}),E=t.length>0;return e.jsx(as,{addButtonIcon:E?e.jsx(Ns,{}):e.jsx(Ss,{}),addButtonText:E?"Add filter":"Filter",allowMultiple:!0,className:`[&>button]:order-last ${E?"[&>button]:border-none":"w-auto"}`,clearButtonClassName:"font-normal text-muted-foreground",clearButtonIcon:e.jsx(se,{}),clearButtonText:"Clear",fields:N,filters:R,keyboardShortcut:"f",popoverAlign:E?"start":"end",showClearButton:E,showSearchInput:!1,onChange:$})},st=({children:t,totalMembers:s,isLoading:a})=>e.jsxs(Y,{className:"relative !pb-6 md:sticky",variant:"inline-nav",children:[e.jsxs(Y.Title,{children:["Members ",!a&&e.jsx("span",{className:"font-normal text-muted-foreground",children:s.toLocaleString()})]}),t]}),tt=({children:t})=>e.jsx("div",{className:"size-full",children:e.jsx("div",{className:"relative flex size-full flex-col",children:e.jsx("div",{className:"grid w-full grow",children:e.jsx("div",{className:"flex h-full flex-col","data-testid":"members-page",children:t})})})});function at(t){if(!t)return{text:"Unknown",isKnown:!1};try{const s=JSON.parse(t);return s.country?s.country_code==="US"&&s.region?{text:`${s.region}, US`,isKnown:!0}:{text:s.country,isKnown:!0}:{text:"Unknown",isKnown:!1}}catch{return{text:"Unknown",isKnown:!1}}}function lt(t){switch(t){case"paid":return"Paid";case"comped":return"Complimentary";default:return"Free"}}function rt({item:t}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Cs,{avatarImage:t.avatar_image,className:"size-10 min-w-10 md:size-10 md:min-w-10",memberId:t.id}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.name||t.email||"Anonymous"}),t.name&&t.email&&e.jsx("div",{className:"truncate text-sm text-muted-foreground","data-testid":"member-email",children:t.email})]})]})}function nt({status:t,tiers:s}){const a=s?.map(l=>l.name).join(", ");return e.jsx("div",{className:"flex justify-end lg:justify-start",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm",children:lt(t)}),a&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:a})]})})}function it({emailOpenRate:t}){const s=t!=null;return e.jsx("div",{className:`hidden text-sm lg:block ${s?"text-foreground":"text-muted-foreground"}`,children:s?`${Math.round(t)}%`:"N/A"})}function ot({geolocation:t}){const s=at(t);return e.jsx("div",{className:`hidden truncate text-sm lg:block ${s.isKnown?"text-foreground":"text-muted-foreground"}`,children:s.text})}function ct({createdAt:t}){return e.jsxs("div",{className:"hidden lg:block",children:[e.jsx("div",{className:"text-sm",children:ue.utc(t).format("D MMM YYYY")}),e.jsx("div",{className:"text-xs text-muted-foreground",children:ue.utc(t).fromNow()})]})}function dt({item:t,gridCols:s,showEmailOpenRate:a,onClick:l,...n}){return e.jsxs("div",{...n,className:`grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_7rem] items-center gap-2 border-b px-4 py-3 hover:bg-muted/50 lg:gap-4 ${s}`,"data-testid":"members-list-item",onClick:()=>l(t.id),children:[e.jsx(rt,{item:t}),e.jsx(nt,{status:t.status,tiers:t.tiers}),a&&e.jsx(it,{emailOpenRate:t.email_open_rate}),e.jsx(ot,{geolocation:t.geolocation}),e.jsx(ct,{createdAt:t.created_at})]})}const ye=({height:t})=>e.jsx("div",{"aria-hidden":"true",className:"flex",children:e.jsx("div",{className:"flex",style:{height:t}})}),ut=o.forwardRef(function(s,a){return e.jsx("div",{ref:a,...s,"aria-hidden":"true",className:"relative flex flex-col",children:e.jsx("div",{className:"relative z-10 h-[72px] animate-pulse",children:e.jsx("div",{className:"h-full rounded-md bg-muted","data-testid":"loading-placeholder"})})})});function mt({items:t,totalItems:s,hasNextPage:a,isFetchingNextPage:l,fetchNextPage:n,isLoading:r,showEmailOpenRate:c=!0,onRowClick:i}){const d=o.useRef(null);Ls({parentRef:d,isLoading:r});const{visibleItems:b,spaceBefore:g,spaceAfter:u}=_s({items:t,totalItems:s,hasNextPage:a,isFetchingNextPage:l,fetchNextPage:n,parentRef:d,estimateSize:()=>72}),x=m=>{i?i(m):window.location.hash=`/members/${m}`},v=c?"lg:grid-cols-[3fr_1fr_1fr_1.5fr_1.5fr]":"lg:grid-cols-[3fr_1fr_1.5fr_1.5fr]";return e.jsx("div",{ref:d,className:"overflow-hidden",children:e.jsxs("div",{className:"flex flex-col","data-testid":"members-list",children:[e.jsxs("div",{className:`sticky top-0 z-10 hidden border-b bg-background lg:grid lg:gap-4 lg:px-4 lg:py-3 ${v}`,children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Member"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Status"}),c&&e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Open rate"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Location"}),e.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-gray-700",children:"Created"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(ye,{height:g}),b.map(({key:m,virtualItem:p,item:f,props:h})=>p.index>t.length-1?e.jsx(ut,{...h},m):e.jsx(dt,{...h,gridCols:v,item:f,showEmailOpenRate:c,onClick:x},m)),e.jsx(ye,{height:u})]})]})})}const pt=["name","email","label","subscribed","last_seen_at","created_at","signup","newsletters","tier_id","status","subscriptions.plan_interval","subscriptions.status","subscriptions.start_date","subscriptions.current_period_end","conversion","email_count","email_opened_count","email_open_rate","emails.post_id","opened_emails.post_id","clicked_links.post_id","newsletter_feedback","offer_redemptions"],Fe=new Set(["label","offer_redemptions"]);function ft(t){return"'"+t.replace(/'/g,"\\'")+"'"}function bt(t){return{"is-less":"<","is-or-less":"<=",is:"","is-not":"-","is-greater":">","is-or-greater":">=",contains:"~","does-not-contain":"-~","starts-with":"~^","ends-with":"~$",before:"<",after:">",is_not:"-",is_any_of:"",is_not_any_of:"-",greater_than:">",less_than:"<",equals:"",not_equals:"-"}[t]??""}function ht(t){const s=[];for(const a of t){if(!a.values[0]&&a.values[0]!==0)continue;const l=a.field,n=a.operator,r=a.values[0],c=bt(n);if(l.startsWith("newsletters.")){const i=l.replace("newsletters.","");String(r)==="subscribed"?s.push(`(newsletters.slug:${i}+email_disabled:0)`):s.push(`(newsletters.slug:-${i},email_disabled:1)`);continue}switch(l){case"name":case"email":{const i=ft(String(r));s.push(`${l}:${c}${i}`);break}case"label":case"tier_id":case"offer_redemptions":{if(Array.isArray(a.values)&&a.values.length>0){const i="["+a.values.join(",")+"]";s.push(`${l}:${c}${i}`)}else r&&s.push(`${l}:${c}${r}`);break}case"status":{s.push(`status:${c}${r}`);break}case"subscribed":{r==="email-disabled"?n==="is"?s.push("(email_disabled:1)"):s.push("(email_disabled:0)"):n==="is"||n==="is_any_of"?r==="subscribed"?s.push("(subscribed:true+email_disabled:0)"):s.push("(subscribed:false+email_disabled:0)"):r==="subscribed"?s.push("(subscribed:false,email_disabled:1)"):s.push("(subscribed:true,email_disabled:1)");break}case"newsletters":{const[i,d]=String(r).split(":");d==="subscribed"||n==="is"&&d!=="unsubscribed"?s.push(`(newsletters.slug:${i}+email_disabled:0)`):s.push(`(newsletters.slug:-${i},email_disabled:1)`);break}case"last_seen_at":case"created_at":case"subscriptions.start_date":case"subscriptions.current_period_end":{const i=String(r);s.push(`${l}:${c}'${i}'`);break}case"email_count":case"email_opened_count":case"email_open_rate":{s.push(`${l}:${c}${r}`);break}case"subscriptions.plan_interval":{s.push(`subscriptions.plan_interval:${c}${r}`);break}case"subscriptions.status":{s.push(`subscriptions.status:${c}${r}`);break}case"signup":case"conversion":case"emails.post_id":case"opened_emails.post_id":case"clicked_links.post_id":{s.push(`${l}:${c}'${r}'`);break}case"newsletter_feedback":{const i=n;s.push(`(feedback.post_id:'${r}'+feedback.score:${i})`);break}default:typeof r=="string"&&r.includes(" ")?s.push(`${l}:${c}'${r}'`):s.push(`${l}:${c}${r}`)}}return s.length?s.join("+"):void 0}function gt(t){if(!t)return null;const s=t.indexOf(":");return s<=0?null:{operator:t.substring(0,s),value:t.substring(s+1)}}function xt(t){const s=[];for(const[a,l]of t.entries()){if(a==="search"||!a.startsWith("newsletters.")&&!pt.includes(a)||!l)continue;const r=gt(l);if(r){const c=Fe.has(a)?r.value?r.value.split(","):[]:[r.value];s.push({id:a,field:a,operator:r.operator,values:c})}}return s}function Ne(t,s){const a=new URLSearchParams;for(const l of t){const n=l.field;if(Fe.has(n)){const r=l.values.length>0?l.values.map(c=>String(c)).join(","):"";a.set(n,`${l.operator}:${r}`);continue}if(l.values[0]!==void 0){const r=`${l.operator}:${String(l.values[0])}`;a.set(n,r)}}return s&&a.set("search",s),a}function jt(){const[t,s]=qe(),a=o.useMemo(()=>xt(t),[t]),l=o.useMemo(()=>t.get("search")??"",[t]),n=o.useCallback((b,g={})=>{const u=typeof b=="function"?b(a):b,x=t.get("search")??void 0,j=Ne(u,x),w=g.replace??!0;s(j,{replace:w})},[a,t,s]),r=o.useCallback((b,g={})=>{const u=Ne(a,b||void 0),x=g.replace??!0;s(u,{replace:x})},[a,s]),c=o.useCallback(({replace:b=!0}={})=>{s(new URLSearchParams,{replace:b})},[s]),i=o.useMemo(()=>ht(a),[a]),d=a.length>0||l.length>0;return{filters:a,nql:i,search:l,setFilters:n,setSearch:r,clearFilters:c,isFiltered:d}}const vt=["subscriptions.plan_interval","subscriptions.status","subscriptions.start_date","subscriptions.current_period_end","conversion","offer_redemptions"],$t=()=>{const{filters:t,nql:s,setFilters:a,isFiltered:l,clearFilters:n}=jt(),{data:r}=Le(),c=r?.config?.emailAnalytics===!0,i=o.useMemo(()=>!t.some(k=>vt.includes(k.field)),[t]),d=o.useMemo(()=>{if(s)return{include:"labels,tiers",limit:"50",order:"created_at desc",filter:s}},[s]),{data:b,isError:g,isFetching:u,isFetchingNextPage:x,isRefetching:j,fetchNextPage:w,hasNextPage:v}=es({searchParams:d,keepPreviousData:!0}),m=u&&!x&&!j,p=b?.meta?.pagination?.total??0,f=t.length>0,h=Ce("flex flex-row",!f&&"items-center gap-2",f&&"col-span-full row-start-4 pt-5");return e.jsxs(tt,{children:[e.jsxs(st,{isLoading:m,totalMembers:p,children:[e.jsx(Y.Actions,{children:e.jsxs(Y.ActionGroup,{children:[!f&&e.jsx(we,{filters:t,onFiltersChange:a}),e.jsx(Bs,{canBulkDelete:i,isFiltered:l,memberCount:p,nql:s})]})}),f&&e.jsx("div",{className:h,children:e.jsx(we,{filters:t,onFiltersChange:a})})]}),e.jsx(Vs,{children:m?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(ss,{size:"lg"})}):g?e.jsxs("div",{className:"mb-16 flex h-full flex-col items-center justify-center",children:[e.jsx("h2",{className:"mb-2 text-xl font-medium",children:"Error loading members"}),e.jsx("p",{className:"mb-4 text-muted-foreground",children:"Please reload the page to try again"}),e.jsx(D,{onClick:()=>window.location.reload(),children:"Reload page"})]}):b?.members.length?e.jsx(mt,{fetchNextPage:w,hasNextPage:v,isFetchingNextPage:x,isLoading:u&&!x,items:b.members,showEmailOpenRate:c,totalItems:p}):e.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:l?e.jsxs(e.Fragment,{children:[e.jsx(he,{title:"No members match the current filter",children:e.jsx(me,{})}),e.jsx(D,{className:"mt-4",variant:"outline",onClick:()=>n({replace:!1}),children:"Show all members"})]}):e.jsx(he,{title:"No members yet",children:e.jsx(me,{})})})})]})};export{$t as default};
|