ghost 6.57.0 → 6.57.1

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.
Files changed (205) hide show
  1. package/components/tryghost-adapter-base-scheduling-0.2.1.tgz +0 -0
  2. package/components/tryghost-kg-converters-1.2.4.tgz +0 -0
  3. package/components/tryghost-kg-default-cards-10.3.4.tgz +0 -0
  4. package/components/tryghost-kg-default-nodes-2.1.5.tgz +0 -0
  5. package/components/tryghost-kg-default-transforms-1.3.3.tgz +0 -0
  6. package/components/tryghost-kg-html-to-lexical-1.3.3.tgz +0 -0
  7. package/components/tryghost-kg-lexical-html-renderer-1.4.3.tgz +0 -0
  8. package/core/built/admin/assets/{about-C7O-AgRZ.js → about-BNojRaxf.js} +1 -1
  9. package/core/built/admin/assets/{account-migration-Cv_ol1ko.js → account-migration-DMS8JsM-.js} +1 -1
  10. package/core/built/admin/assets/{add-integration-modal-m9Dv6f77.js → add-integration-modal-DU9ghGLS.js} +1 -1
  11. package/core/built/admin/assets/{add-newsletter-modal-CPSVZL2H.js → add-newsletter-modal-DFxuQrYu.js} +1 -1
  12. package/core/built/admin/assets/{add-recommendation-modal-Ci9Z5yat.js → add-recommendation-modal-D-3LOrdd.js} +1 -1
  13. package/core/built/admin/assets/{analytics-DqSCVV8U.js → analytics-DTIMRhWw.js} +1 -1
  14. package/core/built/admin/assets/{announcement-bar-modal-DU3avV7d.js → announcement-bar-modal-DGCcezB6.js} +1 -1
  15. package/core/built/admin/assets/{api-keys-BK0LylyK.js → api-keys-Dx4NeNpK.js} +1 -1
  16. package/core/built/admin/assets/{audience-DTJtXXWY.js → audience-DkknNqhZ.js} +1 -1
  17. package/core/built/admin/assets/{automations-dtQ_MRZ7.js → automations-DvSU7QhW.js} +1 -1
  18. package/core/built/admin/assets/{bluesky-sharing-B8Es3AuV.js → bluesky-sharing-yZ9A_jL8.js} +1 -1
  19. package/core/built/admin/assets/{breadcrumb-tg5zL--z.js → breadcrumb-CjOH7LCU.js} +1 -1
  20. package/core/built/admin/assets/{chart-helpers-CZElTGYL.js → chart-helpers-DGxvWnBT.js} +1 -1
  21. package/core/built/admin/assets/{checkbox-Cyo-x7mC.js → checkbox-BSUcnNq_.js} +1 -1
  22. package/core/built/admin/assets/{chunk.873.b8fc05a8ab877fb819ed.js → chunk.424.4a27628efdade15c2dab.js} +3 -3
  23. package/core/built/admin/assets/chunk.524.dce1c51e0bc30fb2718e.js +25 -0
  24. package/core/built/admin/assets/{chunk.211.6f7328d63c41536451b3.js → chunk.571.40f093ed6d883993714e.js} +5 -5
  25. package/core/built/admin/assets/chunk.582.3a430d5c6a744fd475b6.js +27 -0
  26. package/core/built/admin/assets/{code-editor-view-Dq1rQ4tS.js → code-editor-view-BcyKABrG.js} +1 -1
  27. package/core/built/admin/assets/{color-picker-field-BonBgxhU.js → color-picker-field-8NoSnhNI.js} +1 -1
  28. package/core/built/admin/assets/{color-utils-BsrwXuDz.js → color-utils-Dzeeuj1F.js} +1 -1
  29. package/core/built/admin/assets/{combobox-uX5r_paI.js → combobox-5rdgDrDV.js} +1 -1
  30. package/core/built/admin/assets/{command-DxwBO2pF.js → command-BOYMbZa_.js} +1 -1
  31. package/core/built/admin/assets/{comments-Dn-RO-nU.js → comments-BhNM5CYl.js} +1 -1
  32. package/core/built/admin/assets/{confirmation-modal-B6D6mk6R.js → confirmation-modal-CYD7x3UQ.js} +1 -1
  33. package/core/built/admin/assets/{content-api-modal-BxQ-7T6u.js → content-api-modal-BtW4Z1-1.js} +1 -1
  34. package/core/built/admin/assets/{copy-field-BAxL4Zqn.js → copy-field-CEp_XieW.js} +1 -1
  35. package/core/built/admin/assets/{custom-integration-modal---d_l7lc.js → custom-integration-modal-bk3lNEuQ.js} +1 -1
  36. package/core/built/admin/assets/{date-range-select-PB2n1HZf.js → date-range-select-B3Ij1Rqg.js} +1 -1
  37. package/core/built/admin/assets/{debounce-Dg2fW5Rg.js → debounce-Cx5B_9OI.js} +1 -1
  38. package/core/built/admin/assets/{design-and-theme-modal-DYRT207a.js → design-and-theme-modal-B2xYKS1I.js} +3 -3
  39. package/core/built/admin/assets/{dirty-confirm-dialog-BnDJ39ao.js → dirty-confirm-dialog-YE9L21gY.js} +1 -1
  40. package/core/built/admin/assets/{disabled-sources-indicator-iMHrkyV3.js → disabled-sources-indicator-uIzbWL7K.js} +1 -1
  41. package/core/built/admin/assets/{dist-D5vhMdXf.js → dist-ARN6XTcR.js} +1 -1
  42. package/core/built/admin/assets/{dist-cFzKLG7y.js → dist-Bg8bSvLA.js} +1 -1
  43. package/core/built/admin/assets/{dist-WeOIvSYM.js → dist-CsvXCJSe.js} +1 -1
  44. package/core/built/admin/assets/{domain-BR8FIdjD.js → domain-DzrOAPY8.js} +1 -1
  45. package/core/built/admin/assets/{dropzone-hNxmUvwD.js → dropzone-CzhP33wa.js} +1 -1
  46. package/core/built/admin/assets/{edit-profile-CENrkY0l.js → edit-profile-oufs4R4n.js} +1 -1
  47. package/core/built/admin/assets/{editor-B18D0lm8.js → editor-BBKrunMK.js} +3 -3
  48. package/core/built/admin/assets/{embed-signup-form-modal-BsCYUMvQ.js → embed-signup-form-modal-Ch3s6lqA.js} +1 -1
  49. package/core/built/admin/assets/{explore-BmrnljWw.js → explore-CA-R01Br.js} +1 -1
  50. package/core/built/admin/assets/{feed-Dy4li6i8.js → feed-ClC8_Gld.js} +1 -1
  51. package/core/built/admin/assets/{field-Dh_lwk13.js → field-B3OPenbP.js} +1 -1
  52. package/core/built/admin/assets/{filter-sources-D2zDuJH5.js → filter-sources-CiPLnG9A.js} +1 -1
  53. package/core/built/admin/assets/{filters-3JBQcNtJ.js → filters-Bz0HsRie.js} +1 -1
  54. package/core/built/admin/assets/{filters-CFt_BDe4.js → filters-yFvybRMe.js} +1 -1
  55. package/core/built/admin/assets/{first-promoter-modal-D6Rjxugw.js → first-promoter-modal-BC0UpYCD.js} +1 -1
  56. package/core/built/admin/assets/{gift-link-modal-zMtlJhLQ.js → gift-link-modal-BKRuqo-k.js} +1 -1
  57. package/core/built/admin/assets/{global-data-provider-B949LDXJ.js → global-data-provider-RzW6Bnlf.js} +1 -1
  58. package/core/built/admin/assets/{growth-CFws67_i.js → growth-ClNAldfL.js} +1 -1
  59. package/core/built/admin/assets/{growth-C38Xtp8D.js → growth-Dz8OSG06.js} +1 -1
  60. package/core/built/admin/assets/{history-modal-ILAOkbxH.js → history-modal-DIVuQ5Ct.js} +1 -1
  61. package/core/built/admin/assets/{html-field-9a9Id_2q.js → html-field-CVZ2sMxw.js} +1 -1
  62. package/core/built/admin/assets/{images-CrQKVc9Q.js → images-Ok8FFJ3A.js} +1 -1
  63. package/core/built/admin/assets/{inbox-BrSRzyvz.js → inbox-CMUVI6qb.js} +1 -1
  64. package/core/built/admin/assets/{index-BHy2DZX-.js → index-DUXM0NlS.js} +2 -2
  65. package/core/built/admin/assets/{input-group-6vEPvX9S.js → input-group-2XU-iuh_.js} +1 -1
  66. package/core/built/admin/assets/{invite-user-modal-5xDCEw90.js → invite-user-modal-DrZ7xxrZ.js} +1 -1
  67. package/core/built/admin/assets/{koenig-editor-base-BWLEB9Vf.js → koenig-editor-base-BPj4S760.js} +1 -1
  68. package/core/built/admin/assets/koenig-lexical/koenig-lexical.js +9254 -9251
  69. package/core/built/admin/assets/koenig-lexical/koenig-lexical.umd.js +124 -124
  70. package/core/built/admin/assets/{koenig-lexical-Cj62r_y9.js → koenig-lexical-Cdjv-m3_.js} +98 -98
  71. package/core/built/admin/assets/{kpi-card-IHDo8Q56.js → kpi-card-J8Mj1sDX.js} +1 -1
  72. package/core/built/admin/assets/{kpi-card-DOUnkZcN.js → kpi-card-awos0BMH.js} +1 -1
  73. package/core/built/admin/assets/{kpi-helpers-CjUdECAK.js → kpi-helpers-SEhvH-8E.js} +1 -1
  74. package/core/built/admin/assets/{kpi-tabs-X3DkOYbI.js → kpi-tabs-R6BjsKhd.js} +1 -1
  75. package/core/built/admin/assets/{label-Dq6QaOuS.js → label-BMC3dzLI.js} +1 -1
  76. package/core/built/admin/assets/{label-picker-8YlhS2U3.js → label-picker-Bnlru5tO.js} +1 -1
  77. package/core/built/admin/assets/layout-yR9rlvEw.js +1 -0
  78. package/core/built/admin/assets/{limit-modal-BRPsit_B.js → limit-modal-COmLevuY.js} +1 -1
  79. package/core/built/admin/assets/{member-custom-fields-CmvsuuV_.js → member-custom-fields-BvFKEpxJ.js} +1 -1
  80. package/core/built/admin/assets/{member-detail-DCvRrkmJ.js → member-detail-CWdPAe3p.js} +1 -1
  81. package/core/built/admin/assets/{members-DxbSKngD.js → members-Bnt0ih2R.js} +1 -1
  82. package/core/built/admin/assets/{moderation-Da5lhhWh.js → moderation-mPjYHgZW.js} +1 -1
  83. package/core/built/admin/assets/{multi-select-combobox-CYdkH7KQ.js → multi-select-combobox-CsoyHAiX.js} +1 -1
  84. package/core/built/admin/assets/{navigation-modal-BIoTwtMy.js → navigation-modal-D_c0badj.js} +1 -1
  85. package/core/built/admin/assets/{newsletter-BptlVoJm.js → newsletter-DR49NyGS.js} +1 -1
  86. package/core/built/admin/assets/{newsletter-detail-modal-BIvxqE0N.js → newsletter-detail-modal-B45pL1pb.js} +1 -1
  87. package/core/built/admin/assets/{newsletter-emails-Bf8IZLsP.js → newsletter-emails-B-OLfrvr.js} +1 -1
  88. package/core/built/admin/assets/{newsletters-BgrIZk0V.js → newsletters-DGs5BaKH.js} +1 -1
  89. package/core/built/admin/assets/{note-DYcLOmDb.js → note-CSVsUKBm.js} +1 -1
  90. package/core/built/admin/assets/{notifications-B2SPFIV9.js → notifications-DV9FRtDw.js} +1 -1
  91. package/core/built/admin/assets/{offers-container-modal-BZnZITMw.js → offers-container-modal-B0hFS8nk.js} +1 -1
  92. package/core/built/admin/assets/{onboarding-route-DgdfxkQh.js → onboarding-route--jL5KLPD.js} +1 -1
  93. package/core/built/admin/assets/{overview-Dt2_mR6U.js → overview-B-ZPNqMo.js} +1 -1
  94. package/core/built/admin/assets/{overview-BYQJXSog.js → overview-D96iwoJi.js} +1 -1
  95. package/core/built/admin/assets/{page-header-CpmxJj5B.js → page-header-DAvDYKO9.js} +1 -1
  96. package/core/built/admin/assets/{pintura-modal-B4MuBuuO.js → pintura-modal-jiUCxX0Q.js} +1 -1
  97. package/core/built/admin/assets/{portal-frame-BF0NBIji.js → portal-frame-D4D4nEO6.js} +1 -1
  98. package/core/built/admin/assets/{portal-modal-DMVbm0oy.js → portal-modal-BLFdYeDH.js} +1 -1
  99. package/core/built/admin/assets/{post-analytics-CXWBOGyP.js → post-analytics-BhAtiFJp.js} +1 -1
  100. package/core/built/admin/assets/{post-analytics-header-ChzjXVPt.js → post-analytics-header-DK27VjJm.js} +1 -1
  101. package/core/built/admin/assets/{post-analytics-provider-Cgw4U_fw.js → post-analytics-provider-DGg0FUqs.js} +1 -1
  102. package/core/built/admin/assets/{post-share-modal-B9Vmk_XM.js → post-share-modal-DtFAC132.js} +1 -1
  103. package/core/built/admin/assets/{preferences-BfzJmnsd.js → preferences-CuWLISHa.js} +1 -1
  104. package/core/built/admin/assets/{preview-modal-Dw_HtD6S.js → preview-modal-DctYx20m.js} +1 -1
  105. package/core/built/admin/assets/{profile-BT5vtv9b.js → profile-BsKYYtuL.js} +1 -1
  106. package/core/built/admin/assets/{radio-group-I7ou7PoJ.js → radio-group-CI5_Kf_d.js} +1 -1
  107. package/core/built/admin/assets/{select-D9oU1IoM.js → select-CkXqNJDJ.js} +1 -1
  108. package/core/built/admin/assets/settings-B4vM-rgV.js +4 -0
  109. package/core/built/admin/assets/{settings-CpvHWix7.js → settings-ZCj-W56o.js} +1 -1
  110. package/core/built/admin/assets/{settings-breadcrumbs-K0USP2nw.js → settings-breadcrumbs-DIq31FwA.js} +1 -1
  111. package/core/built/admin/assets/{share-modal-ClIyPzc5.js → share-modal-BNj14g79.js} +1 -1
  112. package/core/built/admin/assets/{slack-modal-1XXqOfiw.js → slack-modal-C6SpMQ-q.js} +1 -1
  113. package/core/built/admin/assets/{sort-button-CdBsm40v.js → sort-button-B-k54ow2.js} +1 -1
  114. package/core/built/admin/assets/{source-icon-CEYmVLXR.js → source-icon-Cej3sZM6.js} +1 -1
  115. package/core/built/admin/assets/{stats-D8nZCTy5.js → stats-B2KW8E2y.js} +1 -1
  116. package/core/built/admin/assets/{stats-view-CugFVf0g.js → stats-view-CVzU2-p5.js} +1 -1
  117. package/core/built/admin/assets/{step-1-DOYjrORn.js → step-1-Dbn1iIMU.js} +1 -1
  118. package/core/built/admin/assets/{step-2-vA6RsarH.js → step-2-BahnSuN6.js} +1 -1
  119. package/core/built/admin/assets/{step-3-BtIBxMId.js → step-3-CW04e2ZJ.js} +1 -1
  120. package/core/built/admin/assets/{stripe-button-UFP4QRXd.js → stripe-button-BkBZqaGG.js} +1 -1
  121. package/core/built/admin/assets/{stripe-connect-modal-C_L3uM6n.js → stripe-connect-modal-CYDDrSJm.js} +1 -1
  122. package/core/built/admin/assets/{table-TMCgCQK7.js → table-BtLcEi1M.js} +1 -1
  123. package/core/built/admin/assets/{tabs-Dd6oOKbv.js → tabs-BaWRfg8j.js} +1 -1
  124. package/core/built/admin/assets/{tag-detail-D3l-UJPR.js → tag-detail-CmqiC32L.js} +1 -1
  125. package/core/built/admin/assets/{tags-WdKQGWR8.js → tags-BbygUvNB.js} +1 -1
  126. package/core/built/admin/assets/{testimonials-modal-CqWp-xXJ.js → testimonials-modal--bdzppyh.js} +1 -1
  127. package/core/built/admin/assets/{tier-detail-modal-BkcR2u0A.js → tier-detail-modal-BZmAsIy4.js} +1 -1
  128. package/core/built/admin/assets/{toggle-group-Guorw93z.js → toggle-group-CVl-Xigr.js} +1 -1
  129. package/core/built/admin/assets/{topic-filter-CbgoWIHn.js → topic-filter-BoRHRbL1.js} +1 -1
  130. package/core/built/admin/assets/{transistor-modal-DuNnnpal.js → transistor-modal-CBPDqEGy.js} +1 -1
  131. package/core/built/admin/assets/{unsplash-modal-y2bVwTHH.js → unsplash-modal-CixoRAO2.js} +1 -1
  132. package/core/built/admin/assets/{use-analytics-data-B-b4wNSC.js → use-analytics-data-BiWvcf1u.js} +1 -1
  133. package/core/built/admin/assets/{use-check-theme-limit-error-m09J38Mq.js → use-check-theme-limit-error-B14lZukR.js} +1 -1
  134. package/core/built/admin/assets/use-feature-flag-BmJoc5WN.js +1 -0
  135. package/core/built/admin/assets/{use-filter-params-BnbBDc7T.js → use-filter-params-ChoV72Hw.js} +1 -1
  136. package/core/built/admin/assets/{use-growth-stats-DPU5rt3W.js → use-growth-stats-Dom8xVzo.js} +1 -1
  137. package/core/built/admin/assets/{use-limiter-BkN3E4gw.js → use-limiter-Dwg8ivgQ.js} +1 -1
  138. package/core/built/admin/assets/{use-pintura-config-C_z8HTG2.js → use-pintura-config-Bj4QmiVk.js} +1 -1
  139. package/core/built/admin/assets/{use-pintura-editor-DNgbkhGp.js → use-pintura-editor-DvrslmPE.js} +1 -1
  140. package/core/built/admin/assets/{use-post-referrers-C2mXyrp-.js → use-post-referrers-pxIHTXFs.js} +1 -1
  141. package/core/built/admin/assets/{use-reply-chain-data-DaK8q2qQ.js → use-reply-chain-data-CmFe0N6F.js} +1 -1
  142. package/core/built/admin/assets/{use-setting-group-YlYcoNyP.js → use-setting-group-Cmp_sy-d.js} +1 -1
  143. package/core/built/admin/assets/{use-settings-navigation-Bf1g1rEh.js → use-settings-navigation-BmROPrls.js} +1 -1
  144. package/core/built/admin/assets/{use-simple-pagination-D9ckKo5-.js → use-simple-pagination-D5rL3YwO.js} +1 -1
  145. package/core/built/admin/assets/{use-tinybird-query-GSa32hVw.js → use-tinybird-query-DP2dMaq7.js} +1 -1
  146. package/core/built/admin/assets/{use-tinybird-token-CKLOZFsw.js → use-tinybird-token-DrK_skPQ.js} +1 -1
  147. package/core/built/admin/assets/{use-url-input-z-p0Kewm.js → use-url-input-ChrUZBFf.js} +1 -1
  148. package/core/built/admin/assets/{user-detail-modal-BMxOA4Sv.js → user-detail-modal-XODpOqNC.js} +1 -1
  149. package/core/built/admin/assets/{virtual-list-RHeEL05L.js → virtual-list-Dnoafqbk.js} +1 -1
  150. package/core/built/admin/assets/{web-xJtcwMy4.js → web-D71mjB2r.js} +1 -1
  151. package/core/built/admin/assets/{web-Bw2QMO5u.js → web-z71lA1Y3.js} +1 -1
  152. package/core/built/admin/assets/{zapier-modal-BP2f4-vY.js → zapier-modal-Bp507Um7.js} +1 -1
  153. package/core/built/admin/index.html +5 -5
  154. package/core/frontend/web/middleware/admin-toolbar.js +1 -1
  155. package/core/frontend/web/middleware/serve-indexnow-key.js +1 -7
  156. package/core/server/api/endpoints/index.js +2 -2
  157. package/core/server/api/endpoints/themes.js +6 -1
  158. package/core/server/models/base/plugins/overrides.js +7 -5
  159. package/core/server/services/adapter-manager/adapter-paths.js +16 -12
  160. package/core/server/services/adapter-manager/adapter-paths.ts +17 -12
  161. package/core/server/services/audience-feedback/audience-feedback-controller.js +10 -1
  162. package/core/server/services/audience-feedback/feedback-repository.js +4 -1
  163. package/core/server/services/auth/session/session-service.js +18 -3
  164. package/core/server/services/automations/database-automations-repository.js +5 -5
  165. package/core/server/services/automations/database-automations-repository.ts +12 -12
  166. package/core/server/services/automations/database-date.js +52 -3
  167. package/core/server/services/automations/database-date.ts +23 -2
  168. package/core/server/services/email-analytics/email-analytics-service-wrapper.js +1 -1
  169. package/core/server/services/email-analytics/email-analytics-service.js +3 -2
  170. package/core/server/services/email-analytics/index.js +2 -3
  171. package/core/server/services/email-analytics/index.ts +1 -2
  172. package/core/server/services/email-analytics/lib/queries.js +91 -124
  173. package/core/server/services/email-analytics/lib/queries.ts +341 -0
  174. package/core/server/services/indexnow-ping/index.js +0 -2
  175. package/core/server/services/indexnow-ping/index.ts +0 -2
  176. package/core/server/services/indexnow-ping/indexnow-ping-service.js +5 -7
  177. package/core/server/services/indexnow-ping/indexnow-ping-service.ts +7 -13
  178. package/core/server/services/members/members-api/repositories/member-repository.js +51 -0
  179. package/core/server/services/slack-notifications/slack-notifications.js +2 -2
  180. package/core/server/services/slack-ping/index.js +1 -1
  181. package/core/server/services/slack-ping/index.ts +1 -1
  182. package/core/server/services/slack-ping/slack-ping-service.js +1 -0
  183. package/core/server/services/slack-ping/slack-ping-service.ts +1 -0
  184. package/core/server/services/stats/members-stats-service.js +0 -7
  185. package/core/server/services/themes/storage.js +19 -2
  186. package/core/server/services/webhooks/serialize.js +10 -1
  187. package/core/server/web/api/endpoints/admin/routes.js +2 -2
  188. package/core/shared/custom-theme-settings-cache/custom-theme-settings-bread-service.js +4 -0
  189. package/core/shared/custom-theme-settings-cache/custom-theme-settings-service.js +39 -0
  190. package/core/shared/labs.js +1 -1
  191. package/package.json +11 -11
  192. package/pnpm-lock.yaml +41 -41
  193. package/pnpm-workspace.yaml +18 -18
  194. package/components/tryghost-adapter-base-scheduling-0.2.0.tgz +0 -0
  195. package/components/tryghost-kg-converters-1.2.3.tgz +0 -0
  196. package/components/tryghost-kg-default-cards-10.3.3.tgz +0 -0
  197. package/components/tryghost-kg-default-nodes-2.1.4.tgz +0 -0
  198. package/core/built/admin/assets/chunk.524.cd5498dd4e195f679266.js +0 -25
  199. package/core/built/admin/assets/chunk.582.6f92ec1f03734bf2ea3f.js +0 -27
  200. package/core/built/admin/assets/layout-TMj4P-vv.js +0 -1
  201. package/core/built/admin/assets/settings-CfZFbyu_.js +0 -4
  202. package/core/built/admin/assets/use-feature-flag-ud0Qz8vt.js +0 -1
  203. package/core/server/services/email-analytics/jobs/update-member-email-analytics/index.js +0 -14
  204. /package/core/built/admin/assets/{chunk.211.6f7328d63c41536451b3.js.LICENSE.txt → chunk.571.40f093ed6d883993714e.js.LICENSE.txt} +0 -0
  205. /package/core/server/api/endpoints/{gift-reminders.js → gifts.js} +0 -0
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{m as r,p as i,v as a}from"./hooks-D6EE7BIt.js";import{n as o}from"./dist-Ndy-PuGN.js";import{t as s}from"./use-form-vRjI0Kwk.js";import{a as c,i as l,n as u,r as d,t as f}from"./offers-Um6ab71O.js";import{f as p}from"./dist-Cb5RSHSg.js";import{t as m}from"./inline-Cw-gigDW.js";import{t as h}from"./stack-CIfOAAVf.js";import{t as g}from"./switch-CE2NuMn-.js";import{i as _,n as v,o as y,s as b,t as x}from"./select-D9oU1IoM.js";import{o as S,s as C,t as w}from"./use-settings-navigation-Bf1g1rEh.js";import{a as T,i as E,n as D,o as O,r as k,t as A}from"./field-Dh_lwk13.js";import{a as j,i as M,n as N,r as P,t as F}from"./input-group-6vEPvX9S.js";import{n as I,t as L}from"./radio-group-I7ou7PoJ.js";import{a as R,c as z,n as B,r as V,s as H,t as U}from"./table-TMCgCQK7.js";import{t as W}from"./textarea-d9qEkMOP.js";import{$n as G,$r as K,Ds as q,Pr as J,Ss as ee,Xr as te,Yr as ne,Zr as re,ai as ie,bs as ae,co as oe,cr as Y,ei as se,ni as ce,ri as le,ti as ue,wn as de}from"./index-BHy2DZX-.js";import{a as fe,r as pe}from"./tiers-Da6kxHQP.js";import{n as me}from"./confirmation-modal-B6D6mk6R.js";import{n as X}from"./global-data-provider-B949LDXJ.js";import{t as he}from"./brand-icon-09YqFZjV.js";import{o as ge,r as _e}from"./zapier-modal-BP2f4-vY.js";import{t as ve}from"./preview-modal-Dw_HtD6S.js";import{t as ye}from"./portal-frame-BF0NBIji.js";import{t as be}from"./settings-breadcrumbs-K0USP2nw.js";import{i as xe,r as Se}from"./currency-Dy4Tc2R2.js";var Ce=(e,t)=>{let{disableBackground:n=!1,name:r,code:i,displayTitle:a=``,displayDescription:o=``,type:s,cadence:c,amount:l=0,duration:u,durationInMonths:d,currency:f=`usd`,status:p,tierId:m,redemptionType:h=`signup`}=e;t=t.replace(/\/$/,``);let g=new URLSearchParams;return g.append(`disableBackground`,`false`),g.append(`name`,encodeURIComponent(r)),g.append(`code`,encodeURIComponent(i)),g.append(`display_title`,encodeURIComponent(a)),g.append(`display_description`,encodeURIComponent(o)),g.append(`type`,encodeURIComponent(s)),g.append(`cadence`,encodeURIComponent(c)),g.append(`amount`,encodeURIComponent(l)),g.append(`duration`,encodeURIComponent(u)),g.append(`duration_in_months`,encodeURIComponent(d)),g.append(`currency`,encodeURIComponent(f)),g.append(`status`,encodeURIComponent(p)),g.append(`tier_id`,encodeURIComponent(m)),g.append(`redemption_type`,encodeURIComponent(h)),n&&g.append(`disableBackground`,`true`),g.append(`admin_toolbar`,`0`),`${t}/?v=modal-portal-offer#/portal/preview/offer?${g.toString()}`},we=e=>{let t=[];return e.forEach(e=>{t.push({label:`${e.name} - Monthly`,value:`${e.id}-month-${e.currency}`}),t.push({label:`${e.name} - Yearly`,value:`${e.id}-year-${e.currency}`})}),t},Z=e(t(),1),Q=n();function Te(e){return e.toString().toLowerCase().trim().replace(/\s+/g,`-`).replace(/[^\w-]+/g,``).replace(/--+/g,`-`)}var Ee=191,De=e=>{let{fixedAmount:t=0,percentAmount:n=0,trialAmount:r=0,amount:i=0}=e;switch(e.type){case`fixed`:return t*100;case`percent`:return n;case`trial`:return r;default:return i}},Oe=({tierOptions:e,handleTierChange:t,selectedTier:n,typeOptions:r,durationOptions:i,handleTypeChange:a,handleDurationChange:o,overrides:s,handleAmountTypeChange:c,handleNameInput:l,handleTextAreaInput:u,handleDisplayTitleInput:d,handleDurationInMonthsInput:f,handleAmountInput:m,handleCodeInput:h,clearError:g,errors:S,testId:C,handleTrialAmountInput:w,amountOptions:P})=>{let R=s.cadence===`year`,z=R?i.filter(e=>e.value!==`repeating`):i,[B,V]=(0,Z.useState)(0),H=B>40?`text-red`:`text-green`,{siteData:U}=X(),[G,K]=(0,Z.useState)(!1),q=de(U),ee=`${q}${s.code.value}`;return(0,Q.jsx)(`div`,{className:`pt-7`,"data-testid":C,children:(0,Q.jsxs)(T,{className:`mb-10 gap-8`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{"data-invalid":!!S.name||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-name`,children:`Offer name`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.name||void 0,id:`offer-name`,maxLength:40,placeholder:`Black Friday`,onChange:e=>{l(e),V(e.target.value.length)},onKeyDown:()=>g(`name`)}),S.name?(0,Q.jsx)(E,{children:S.name}):(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Q.jsx)(`span`,{children:`Visible to members on Stripe Checkout page`}),(0,Q.jsxs)(`strong`,{children:[(0,Q.jsx)(`span`,{className:H,children:p(B)}),` / `,p(40)]})]})})]}),(0,Q.jsxs)(A,{"data-invalid":!!S.displayTitle||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.displayTitle||void 0,id:`offer-display-title`,maxLength:Ee,placeholder:`Black Friday Special`,value:s.displayTitle.value,onChange:e=>{d(e)},onKeyDown:()=>g(`displayTitle`)}),S.displayTitle&&(0,Q.jsx)(E,{children:S.displayTitle})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`offer-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`offer-display-description`,maxLength:Ee,placeholder:`Take advantage of this limited-time offer.`,value:s.displayDescription,onChange:e=>{u(e)}})]})]})]}),(0,Q.jsxs)(`section`,{className:`mt-4`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`Details`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(L,{"aria-label":`Offer type`,className:`rounded-md border border-border-default p-4`,value:s.type===`trial`?`trial`:`percent`,onValueChange:a,children:r.map(e=>{let t=`offer-type-${e.value}`;return(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsx)(I,{id:t,value:e.value}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(O,{className:`cursor-pointer`,htmlFor:t,children:e.title}),(0,Q.jsx)(k,{children:e.description})]})]},e.value)})}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Tier — Cadence`}),(0,Q.jsxs)(x,{value:n.value,onValueChange:n=>{let r=e.find(e=>e.value===n);r&&t(r)},children:[(0,Q.jsx)(y,{"aria-label":`Tier — Cadence`,"data-testid":`tier-cadence-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:e.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),s.type!==`trial`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(A,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-amount`,children:`Amount off`}),(0,Q.jsxs)(F,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(M,{id:`offer-amount`,type:`number`,value:s.type===`fixed`?s.fixedAmount===0?``:s.fixedAmount?.toString():s.percentAmount===0?``:s.percentAmount?.toString(),onChange:e=>{m(e)},onKeyDown:()=>g(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsxs)(x,{value:s.type===`percent`?P[0].value:P[1].value,onValueChange:c,children:[(0,Q.jsx)(y,{"aria-label":`Amount type`,className:`h-7 w-20 border-0 bg-transparent px-2 shadow-none focus-visible:ring-0`,"data-testid":`amount-type-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{align:`end`,children:P.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})})]}),S.amount&&(0,Q.jsx)(E,{children:S.amount})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Duration`}),(0,Q.jsxs)(x,{value:s.duration,onValueChange:e=>{g(`durationInMonths`),o(e)},children:[(0,Q.jsx)(y,{"aria-label":`Duration`,"data-testid":`duration-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:z.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),s.duration===`repeating`&&!R&&(0,Q.jsx)(`div`,{className:`-mt-4`,children:(0,Q.jsxs)(A,{"data-invalid":!!S.durationInMonths||void 0,children:[(0,Q.jsxs)(F,{"data-invalid":!!S.durationInMonths||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!S.durationInMonths||void 0,"data-testid":`duration-months-input`,type:`number`,value:s.durationInMonths===0?``:String(s.durationInMonths),onChange:e=>{f(e)},onKeyDown:()=>g(`durationInMonths`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:s.durationInMonths===1?`month`:`months`})})]}),S.durationInMonths&&(0,Q.jsx)(E,{children:S.durationInMonths})]})})]}),s.type===`trial`&&(0,Q.jsxs)(A,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`trial-duration`,children:`Trial duration`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.amount||void 0,id:`trial-duration`,type:`number`,value:s.trialAmount?.toString(),onChange:e=>{w(e)},onKeyDown:()=>g(`amount`)}),S.amount&&(0,Q.jsx)(E,{children:S.amount})]}),(0,Q.jsxs)(A,{"data-invalid":!!S.code||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-code`,children:`Offer code`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.code||void 0,id:`offer-code`,placeholder:`black-friday`,value:s.code.value,onChange:e=>{h(e)},onKeyDown:()=>g(`code`)}),S.code?(0,Q.jsx)(E,{children:S.code}):s.code.value!==``&&(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[q,(0,Q.jsx)(`span`,{className:`font-bold`,children:s.code.value})]}),(0,Q.jsx)(J,{className:`h-auto p-0 text-sm text-green hover:text-green`,size:`sm`,type:`button`,variant:`link`,onClick:async()=>{await navigator.clipboard.writeText(ee),K(!0),setTimeout(()=>K(!1),2e3)},children:G?`Copied`:`Copy`})]})})]})]})]})]})})},$=e=>{let[t,n,r]=e.split(`-`);if(!t||!n||!r)throw Error(`Invalid input format. Expected format is: id-period-currency`);return{id:t,period:n,currency:r}},ke=()=>{let{siteData:e}=X(),t=[{title:`Discount`,description:`Offer a special reduced price`,value:`percent`},{title:`Free trial`,description:`Give free access for a limited time`,value:`trial`}],n=[{value:`once`,label:`First-payment`},{value:`repeating`,label:`Multiple-months`},{value:`forever`,label:`Forever`}],[r,i]=(0,Z.useState)(``),{updateRoute:c}=w(),{data:{tiers:l}={}}=fe(),d=pe(l||[]),p=we(d),{mutateAsync:m}=f(),[h,g]=(0,Z.useState)({tier:p[0]||{},dataset:{id:p[0]?.value?$(p[0]?.value).id:``,period:p[0]?.value?$(p[0]?.value).period:``,currency:p[0]?.value?$(p[0]?.value).currency:``}}),{data:{offers:_=[]}={}}=u(),{formState:v,updateForm:y,handleSave:b,saveState:x,okProps:S,validate:C,errors:T,clearError:E}=s({initialState:{disableBackground:!1,name:``,code:{isDirty:!1,value:``},displayTitle:{isDirty:!1,value:``},displayDescription:``,type:`percent`,cadence:h?.dataset?.period||``,amount:0,duration:`once`,durationInMonths:1,currency:h?.dataset?.currency||`USD`,status:`active`,tierId:h?.dataset?.id||``,trialAmount:7,fixedAmount:0,percentAmount:0},onSave:async()=>{let e=v.type===`trial`?`trial`:v.duration,t={name:v.name,code:v.code.value,display_title:v.displayTitle.value,display_description:v.displayDescription,cadence:v.cadence,amount:De(v)||0,duration:e,...e===`repeating`?{duration_in_months:v.durationInMonths}:{},currency:v.currency,status:v.status,redemption_type:`signup`,tier:{id:v.tierId},type:v.type,currency_restriction:!1},n=await m(t);n&&n.offers&&n.offers.length>0&&c(`offers/success/${n.offers[0].id}`)},onSaveError:()=>{},onValidate:()=>{let e={};return!v.name&&v.name.length===0&&(e.name=`Name is required`),!v.code.value&&v.code.value.length===0&&(e.code=`Code is required`),!v.displayTitle.value&&v.displayTitle.value.length===0&&(e.displayTitle=`Display title is required`),v.type===`percent`&&v.percentAmount===0&&(e.amount=`Enter an amount greater than 0.`),v.type===`percent`&&(v.percentAmount<1||v.percentAmount>100)&&(e.amount=`Enter an amount between 1 and 100%.`),(v.type===`fixed`&&v.fixedAmount===0||v.type===`fixed`&&v.fixedAmount<1)&&(e.amount=`Enter an amount greater than 0.`),v.type===`trial`&&v.trialAmount===0&&(e.amount=`Enter an amount greater than 0.`),v.type===`trial`&&v.trialAmount<1&&(e.amount=`Free trial must be at least 1 day.`),v.type!==`trial`&&v.duration===`repeating`&&(!Number.isInteger(v.durationInMonths)||v.durationInMonths<1)&&(e.durationInMonths=`Enter a whole number of months (1 or more).`),e},savingDelay:500}),D=[{value:`percent`,label:`%`},{value:`fixed`,label:v.currency}],O=e=>{let t=$(e.value),n=t.period===`year`;g({tier:e,dataset:t}),y(e=>({...e,cadence:t.period,currency:t.currency,tierId:t.id,duration:n&&e.duration===`repeating`?`once`:e.duration})),n&&E(`durationInMonths`)},k=e=>{e===`trial`&&(E(`amount`),E(`durationInMonths`)),y(t=>({...t,type:e}))},A=e=>{y(t=>({...t,type:e===`percent`?`percent`:`fixed`}))},j=e=>{let t=e.target;v.type===`fixed`?y(e=>({...e,fixedAmount:Number(t.value)})):v.type===`percent`?y(e=>({...e,percentAmount:Number(t.value)})):y(e=>({...e,amount:Number(t.value)}))},M=e=>{let t=e.target,n=Number(t.value);y(e=>({...e,durationInMonths:Number.isNaN(n)?0:n}))},N=e=>{let t=e.target.value;y(e=>{let n={...e};return n.name=t,e.code.isDirty||(E(`code`),n.code={...e.code,value:Te(t)}),e.displayTitle.isDirty||(E(`displayTitle`),n.displayTitle={...e.displayTitle,value:t}),n})},P=e=>{let t=e.target;y(e=>({...e,displayTitle:{...e.displayTitle,isDirty:!0,value:t.value}}))},F=e=>{let t=e.target;y(e=>({...e,displayDescription:t.value}))},I=e=>{let t=e.target;y(e=>({...e,trialAmount:Number(t.value)}))},L=e=>{y(t=>({...t,duration:e}))},R=e=>{let t=e.target;y(e=>({...e,code:{...e.code,isDirty:!0,value:t.value}}))},z=()=>{_.length>0?c(`offers/edit`):c(`offers`)},B=(0,Z.useMemo)(()=>({name:v.name||``,code:v.code.value||``,displayTitle:v.displayTitle.value||``,displayDescription:v.displayDescription||``,type:v.type||`percent`,cadence:v.cadence||`month`,amount:De(v)||0,duration:v.type===`trial`?`trial`:v.duration||`once`,durationInMonths:v.durationInMonths||0,currency:v.currency||`USD`,status:v.status||`active`,tierId:v.tierId||d[0]?.id,redemptionType:`signup`}),[v,d]);(0,Z.useEffect)(()=>{let t=Ce(B,e.url);i(t)},[v,e.url,v.type,B]);let V=(0,Q.jsx)(Oe,{amountOptions:D,clearError:E,durationOptions:n,errors:T,handleAmountInput:j,handleAmountTypeChange:A,handleCodeInput:R,handleDisplayTitleInput:P,handleDurationChange:L,handleDurationInMonthsInput:M,handleNameInput:N,handleTextAreaInput:F,handleTierChange:O,handleTrialAmountInput:I,handleTypeChange:k,overrides:v,selectedTier:h.tier,testId:`add-offer-sidebar`,tierOptions:p,typeOptions:t,validate:C}),H=(0,Q.jsx)(ye,{href:r||``,portalParent:`offers`});return(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:x===`unsaved`,height:`full`,okLabel:`Publish`,okVariant:S.variant,preview:H,previewToolbar:!1,sidebar:V,size:`lg`,testId:`add-offer-modal`,title:`Offer`,width:1140,onCancel:z,onClose:()=>{c(`offers`)},onOk:async()=>{if(C(),!Object.values(T).every(e=>!e)){o.dismiss(),o.info(`Can't save offer`,{description:`Make sure you filled all required fields`});return}try{if(await b({force:!0}))return}catch(e){let t;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message),o.dismiss(),t&&o.error(`Can't save offer`,{description:t||`Please try again later`})}}})},Ae=e=>new Date(e).toLocaleDateString(`default`,{year:`numeric`,month:`short`,day:`2-digit`}),je=e=>{let t=`${i().adminRoot}#/members`,n=`offer_redemptions:[${e.join(`,`)}]`;return`${t}?filter=${encodeURIComponent(n)}`},Me=e=>je([e]),Ne=({amount:e,duration:t})=>e===100&&t===`repeating`,Pe=(e,t)=>`Retention ${e} (${t})`,Fe=({amount:e,duration:t,durationInMonths:n})=>Ne({amount:e,duration:t})?`${n} ${n===1?`month`:`months`} free`:t===`once`?`${e}% off once`:t===`repeating`?`${e}% off for ${n} mo`:`${e}% off forever`,Ie=(e,t)=>{let n=t.trim(),r=Fe(e),i=Pe(r,n);if(i.length<=40)return i;let a=i.length-40,o=Math.max(3,n.length-a);return Pe(r,n.slice(0,o))};function Le(e){return new Date(e).toLocaleDateString(`default`,{year:`numeric`,month:`short`,day:`2-digit`})}var Re=({clearError:e,errors:t,offer:n,updateOffer:i})=>{let{siteData:a}=X(),[s,c]=(0,Z.useState)(!1),u=r(),{mutateAsync:d}=l(),[f,m]=(0,Z.useState)(n?.name.length||0),h=f>40?`text-red`:`text-green`,{updateRoute:g}=w();(0,Z.useEffect)(()=>{n?.name&&m(n?.name.length)},[n?.name]);let _=de(a),v=`${_}${n?.code}`,y=async()=>{await navigator.clipboard.writeText(v),c(!0),setTimeout(()=>c(!1),2e3)},b=async()=>{n?.status===`active`?C.show(me,{title:`Archive offer`,prompt:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{children:`New members will no longer be able to subscribe using this offer.`}),(0,Q.jsxs)(`p`,{children:[`All members that previously redeemed `,(0,Q.jsx)(`strong`,{children:n?.name}),` will remain unchanged.`]})]}),okLabel:`Archive`,okVariant:`destructive`,onOk:async e=>{try{await d({...n,status:`archived`}),e?.remove(),o.success(`Offer archived`),g(`offers/edit`)}catch(e){u(e)}}}):C.show(me,{title:`Reactivate offer`,prompt:(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`p`,{children:[`Reactivating `,(0,Q.jsx)(`strong`,{children:n?.name}),` will allow new members to subscribe using this offer. Existing members will remain unchanged.`]})}),okLabel:`Reactivate`,onOk:async e=>{try{await d({...n,status:`active`}),e?.remove(),o.success(`Offer reactivated`),g(`offers/edit`)}catch(e){u(e)}}})};return(0,Q.jsxs)(`div`,{className:`flex grow flex-col pt-2`,children:[(0,Q.jsxs)(T,{className:`mb-10 grow gap-8`,children:[(0,Q.jsx)(`section`,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5 rounded-md border border-grey-300 p-4 pb-3.5 dark:border-grey-800`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Created on`}),(0,Q.jsx)(`span`,{children:Le(n?.created_at?n.created_at:``)})]}),(0,Q.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Performance`}),(0,Q.jsxs)(`span`,{children:[p(n?.redemption_count||0),` `,n?.redemption_count===1?`redemption`:`redemptions`]})]}),n?.redemption_count>0&&n?.last_redeemed?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Last redemption`}),(0,Q.jsx)(`span`,{children:Le(n?.last_redeemed)})]}):null]}),n?.redemption_count>0?(0,Q.jsx)(`a`,{className:`font-semibold text-green`,href:Me(n?.id),children:`See members →`}):null]})]})}),(0,Q.jsxs)(`section`,{className:`mt-2`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{"data-invalid":!!t.name||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-name`,children:`Offer name`}),(0,Q.jsx)(Y,{"aria-invalid":!!t.name||void 0,id:`offer-name`,maxLength:40,placeholder:`Black Friday`,value:n?.name??``,onChange:e=>{m(e.target.value.length),i({name:e.target.value})},onKeyDown:()=>e(`name`)}),t.name?(0,Q.jsx)(E,{children:t.name}):(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Q.jsx)(`span`,{children:`Visible to members on Stripe Checkout page`}),(0,Q.jsxs)(`strong`,{children:[(0,Q.jsx)(`span`,{className:h,children:p(f)}),` / `,p(40)]})]})})]}),(0,Q.jsxs)(A,{className:`group`,"data-invalid":!!t.code||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-code`,children:`Offer code`}),(0,Q.jsxs)(F,{"data-invalid":!!t.code||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!t.code||void 0,id:`offer-code`,placeholder:`black-friday`,value:n?.code??``,onChange:e=>i({code:e.target.value}),onKeyDown:()=>e(`code`)}),n?.code!==``&&(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(P,{onClick:y,children:s?`Copied!`:`Copy link`})})]}),t.code?(0,Q.jsx)(E,{children:t.code}):n?.code!==``&&(0,Q.jsxs)(k,{className:`truncate`,children:[_,(0,Q.jsx)(`span`,{className:`font-bold text-foreground`,children:n?.code})]})]}),(0,Q.jsxs)(A,{"data-invalid":!!t.displayTitle||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{"aria-invalid":!!t.displayTitle||void 0,id:`offer-display-title`,placeholder:`Black Friday Special`,value:n?.display_title??``,onChange:e=>i({display_title:e.target.value}),onKeyDown:()=>e(`displayTitle`)}),t.displayTitle&&(0,Q.jsx)(E,{children:t.displayTitle})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`offer-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`offer-display-description`,placeholder:`Take advantage of this limited-time offer.`,value:n?.display_description??``,onChange:e=>i({display_description:e.target.value})})]})]})]})]}),(0,Q.jsx)(`div`,{className:`mb-2`,children:n?.status===`active`?(0,Q.jsx)(J,{className:`h-auto p-0 text-destructive hover:text-destructive`,type:`button`,variant:`link`,onClick:b,children:`Archive offer`}):(0,Q.jsx)(J,{className:`h-auto p-0 text-green hover:text-green`,type:`button`,variant:`link`,onClick:b,children:`Reactivate offer`})})]})},ze=({id:e})=>{let{siteData:t}=X(),{updateRoute:n}=w(),i=r(),{mutateAsync:c}=l(),[u,f]=(0,Z.useState)(``),{data:{offers:p=[]}={}}=d(e||``),{formState:m,saveState:h,updateForm:g,setFormState:_,handleSave:v,validate:y,errors:b,clearError:x,okProps:S}=s({initialState:p[0],savingDelay:500,onSave:async()=>{await c(m)},onSaveError:i,onValidate:()=>{let e={};return m?.name||(e.name=`Name is required`),m?.display_title||(e.displayTitle=`Display title is required`),m?.code||(e.code=`Please enter a code`),e}});(0,Z.useEffect)(()=>{_(()=>p[0])},[_,p]);let C=(0,Q.jsx)(Re,{clearError:x,errors:b,offer:m,updateOffer:e=>{g(t=>({...t,...e}))},validate:y});(0,Z.useEffect)(()=>{let e=Ce({name:m?.name||``,code:m?.code||``,displayTitle:m?.display_title||``,displayDescription:m?.display_description||``,type:m?.type||``,cadence:m?.cadence||``,amount:m?.amount,duration:m?.duration||``,durationInMonths:m?.duration_in_months||0,currency:m?.currency||``,status:m?.status||``,tierId:m?.tier?.id||``,redemptionType:`signup`},t.url);f(e)},[m,t]);let T=(0,Q.jsx)(ye,{href:u||``,portalParent:`offers`}),E=()=>{n(`offers/edit`)};return p?(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:h===`unsaved`,height:`full`,okLabel:S.label||`Save`,okVariant:S.variant,preview:T,previewToolbarBreadcrumbs:(0,Q.jsx)(be,{current:m?.name||`Offer`,label:`Offers`,onBack:E}),sidebar:C,size:`lg`,testId:`offer-update-modal`,title:`Offer`,width:1140,onCancel:E,onClose:()=>{n(`offers`)},onOk:async()=>{try{if(await v({force:!0}))return}catch(e){let t;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message),o.dismiss(),t&&o.error(`Can't save offer`,{description:`Please try again later`})}}}):null},Be=[{title:`Percentage discount`,description:`Offer a special reduced price`,value:`percent`},{title:`Free month(s)`,description:`Give free access for a limited time`,value:`free_months`}],Ve=[{value:`once`,label:`First-payment`},{value:`repeating`,label:`Multiple-months`},{value:`forever`,label:`Forever`}],He=191,Ue=99,We=`Enter a whole number of months between 1 and ${Ue}.`,Ge=e=>Math.max(1,Number.isFinite(e)?Math.trunc(e):0),Ke=({type:e,percentAmount:t,freeMonths:n,lastPercentAmount:r,lastFreeMonths:i})=>e===`free_months`?n>0?n:i:t>0?t:r,qe=(e=`monthly`)=>({enabled:!1,displayTitle:``,displayDescription:``,type:e===`yearly`?`percent`:`free_months`,percentAmount:20,duration:`once`,durationInMonths:1,freeMonths:1}),Je=e=>e.type===`percent`&&e.amount===100&&e.duration===`repeating`,Ye=(e,t=`monthly`)=>{let n=qe(t);if(!e)return n;let r=Je(e),i=e.type===`percent`&&!r,a=e.duration===`repeating`&&e.duration_in_months?e.duration_in_months:n.durationInMonths;return{enabled:e.status===`active`,displayTitle:e.display_title||``,displayDescription:e.display_description||``,type:r?`free_months`:`percent`,percentAmount:i?e.amount:n.percentAmount,duration:i?e.duration:n.duration,durationInMonths:a,freeMonths:r&&e.duration_in_months||n.freeMonths}},Xe=({formState:e,lastPercentAmount:t,lastFreeMonths:n})=>{let r=Ke({type:e.type,percentAmount:e.percentAmount,freeMonths:e.freeMonths,lastPercentAmount:t,lastFreeMonths:n});if(e.type===`free_months`)return{type:`percent`,amount:100,duration:`repeating`,durationInMonths:Ge(r)};let i=e.duration;return{type:`percent`,amount:r,duration:i,durationInMonths:i===`repeating`?Ge(e.durationInMonths):0}},Ze=e=>{if(!e)return null;let t=e.duration_in_months??0;return{type:`percent`,amount:e.amount,duration:e.duration,durationInMonths:t}},Qe=e=>e?`${e.type}:${e.amount}:${e.duration}:${e.durationInMonths}`:``,$e=e=>Number.isInteger(e)&&e>0&&e<=Ue,et=(e,t)=>e.displayTitle!==t.displayTitle||e.displayDescription!==t.displayDescription||e.type!==t.type||e.percentAmount!==t.percentAmount||e.duration!==t.duration||e.durationInMonths!==t.durationInMonths||e.freeMonths!==t.freeMonths,tt=({formState:e,updateForm:t,clearError:n,errors:r,cadence:i,lastRedeemed:a,membersFilterUrl:o,redemptions:s})=>{let c=i===`yearly`?Ve.filter(e=>e.value!==`repeating`):Ve;return(0,Q.jsx)(`div`,{className:`flex grow flex-col pt-2`,children:(0,Q.jsxs)(T,{className:`mb-10 grow gap-8`,children:[(0,Q.jsx)(`section`,{children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-5 rounded-md border border-grey-300 p-4 pb-3.5 dark:border-grey-800`,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Performance`}),(0,Q.jsxs)(`span`,{children:[p(s),` `,s===1?`redemption`:`redemptions`]})]}),s>0&&a?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Last redemption`}),(0,Q.jsx)(`span`,{children:Ae(a)})]}):null]}),s>0&&o?(0,Q.jsx)(`a`,{className:`font-semibold text-green`,href:o,children:`See members →`}):null]})})})}),(0,Q.jsx)(`section`,{className:`mt-2`,children:(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsxs)(D,{children:[(0,Q.jsxs)(O,{htmlFor:`${i}-retention-enabled`,children:[`Enable `,i,` retention`]}),(0,Q.jsx)(k,{children:i===`monthly`?`Applied to monthly plans`:`Applied to annual plans`})]}),(0,Q.jsx)(g,{checked:e.enabled,id:`${i}-retention-enabled`,onCheckedChange:e=>t(t=>({...t,enabled:e}))})]})}),e.enabled&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`section`,{className:`mt-2`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`retention-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{id:`retention-display-title`,maxLength:He,placeholder:`Before you go`,value:e.displayTitle,onChange:e=>{t(t=>({...t,displayTitle:e.target.value}))}})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`retention-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`retention-display-description`,maxLength:He,placeholder:`We'd hate to see you leave. How about a special offer to stay?`,value:e.displayDescription,onChange:e=>{t(t=>({...t,displayDescription:e.target.value}))}})]})]})]}),(0,Q.jsxs)(`section`,{className:`mt-4`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`Details`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[i===`monthly`&&(0,Q.jsx)(L,{"aria-label":`${i} retention offer type`,className:`rounded-md border border-border-default p-4`,value:e.type,onValueChange:e=>{n(`amount`),n(`durationInMonths`),t(t=>({...t,type:e}))},children:Be.map(e=>{let t=`${i}-retention-type-${e.value}`;return(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsx)(I,{id:t,value:e.value}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(O,{className:`cursor-pointer`,htmlFor:t,children:e.title}),(0,Q.jsx)(k,{children:e.description})]})]},e.value)})}),e.type===`percent`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(A,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`retention-amount`,children:`Amount off`}),(0,Q.jsxs)(F,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.amount||void 0,id:`retention-amount`,type:`number`,value:e.percentAmount===0?``:String(e.percentAmount),onChange:e=>{let n=Number(e.target.value),r=Number.isNaN(n)?0:n;t(e=>({...e,percentAmount:r}))},onKeyDown:()=>n(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:`%`})})]}),r.amount&&(0,Q.jsx)(E,{children:r.amount})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Duration`}),(0,Q.jsxs)(x,{value:e.duration,onValueChange:e=>{n(`durationInMonths`),t(t=>({...t,duration:e}))},children:[(0,Q.jsx)(y,{"aria-label":`Duration`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:c.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),e.duration===`repeating`&&(0,Q.jsx)(`div`,{className:`-mt-4`,children:(0,Q.jsxs)(A,{"data-invalid":!!r.durationInMonths||void 0,children:[(0,Q.jsxs)(F,{"data-invalid":!!r.durationInMonths||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.durationInMonths||void 0,"data-testid":`duration-months-input`,type:`number`,value:e.durationInMonths===0?``:String(e.durationInMonths),onChange:e=>{let n=Number(e.target.value);t(e=>({...e,durationInMonths:Number.isNaN(n)?0:n}))},onKeyDown:()=>n(`durationInMonths`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:e.durationInMonths===1?`month`:`months`})})]}),r.durationInMonths&&(0,Q.jsx)(E,{children:r.durationInMonths})]})})]}),e.type===`free_months`&&(0,Q.jsxs)(A,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`retention-free-months`,children:`Free months`}),(0,Q.jsxs)(F,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.amount||void 0,id:`retention-free-months`,type:`number`,value:e.freeMonths===0?``:String(e.freeMonths),onChange:e=>{let n=Number(e.target.value);t(e=>({...e,freeMonths:Number.isNaN(n)?0:n}))},onKeyDown:()=>n(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:e.freeMonths===1?`month`:`months`})})]}),r.amount&&(0,Q.jsx)(E,{children:r.amount})]})]})]})]})]})})},nt=({id:e})=>{let{updateRoute:t}=w(),{siteData:n}=X(),{data:{tiers:r=[]}={}}=fe(),{data:{offers:i=[]}={},isFetched:d,isFetching:p}=u(),{mutateAsync:m}=f(),{mutateAsync:h}=l(),g=c(),[_,v]=(0,Z.useState)(``),y=e===`monthly`?`monthly`:`yearly`,b=y===`monthly`?`Monthly retention`:`Yearly retention`,x=y===`monthly`?`month`:`year`,S=pe(r||[]),C=(0,Z.useMemo)(()=>i.filter(e=>e.redemption_type===`retention`&&e.cadence===x).sort((e,t)=>{let n=e.created_at?new Date(e.created_at).getTime():0;return(t.created_at?new Date(t.created_at).getTime():0)-n}),[i,x]),T=(0,Z.useMemo)(()=>C.find(e=>e.status===`active`)||null,[C]),E=C[0]||null,D=T||E,O=(0,Z.useMemo)(()=>C.reduce((e,t)=>e+(t.redemption_count||0),0),[C]),k=(0,Z.useMemo)(()=>C.map(e=>e.id),[C]),A=(0,Z.useMemo)(()=>C.map(e=>e.last_redeemed).filter(e=>!!e).sort((e,t)=>new Date(t).getTime()-new Date(e).getTime())[0]||null,[C]),j=(0,Z.useMemo)(()=>O===0||k.length===0?null:je(k),[k,O]),[M,N]=(0,Z.useState)(20),[P,F]=(0,Z.useState)(1),[I,L]=(0,Z.useState)(null),{formState:R,setFormState:z,updateForm:B,handleSave:V,saveState:H,okProps:U,errors:W,clearError:G}=s({initialState:qe(y),savingDelay:500,onSave:async()=>{let e=!1,t=Xe({formState:R,lastPercentAmount:M,lastFreeMonths:P}),n=Qe(Ze(D))!==Qe(t),r=R.enabled?`active`:`archived`,i=R.displayTitle||``,a=R.displayDescription||``,o=D?i!==(D.display_title||``)||a!==(D.display_description||``):i!==``||a!==``,s=qe(y),c=!R.enabled&&!D&&et(R,s),l=async n=>{let r=crypto.getRandomValues(new Uint32Array(1))[0].toString(16).padStart(8,`0`),o=Ie(t,r);await m({name:o,code:r,display_title:i,display_description:a,cadence:x,amount:t.amount,duration:t.duration,duration_in_months:t.duration===`repeating`?t.durationInMonths:null,currency:null,status:n,redemption_type:`retention`,tier:null,type:t.type,currency_restriction:!1}),e=!0},u=async()=>{e&&await g()};if(!(!D&&!R.enabled&&!c)){if(n){!R.enabled&&T&&(await h({...T,status:`archived`}),e=!0),await l(r),await u();return}if(D){let t=D.status!==r;(o||t)&&(await h({...D,display_title:i,display_description:a,status:r}),e=!0),await u();return}(R.enabled||c)&&await l(r),await u()}},onSaveError:e=>{let t=`Please try again later`;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message||t),o.dismiss(),o.error(`Failed to save offer`,{description:t})},onValidate:()=>{let e={};return R.enabled?(R.type===`percent`&&((R.percentAmount<1||R.percentAmount>100)&&(e.amount=`Enter an amount between 1 and 100%.`),R.duration===`repeating`&&!$e(R.durationInMonths)&&(e.durationInMonths=We)),R.type===`free_months`&&($e(R.freeMonths)||(e.amount=We)),e):e}}),K=`${e}:${D?.id||`none`}`;(0,Z.useEffect)(()=>{!d||p||H===`unsaved`||I===K||(z(()=>Ye(D,y)),L(K))},[y,K,D,d,I,p,H,z]),(0,Z.useEffect)(()=>{R.percentAmount>0&&N(R.percentAmount)},[R.percentAmount]),(0,Z.useEffect)(()=>{R.freeMonths>0&&F(R.freeMonths)},[R.freeMonths]);let q=()=>{t(`offers/edit`)},J=(0,Q.jsx)(tt,{cadence:y,clearError:G,errors:W,formState:R,lastRedeemed:A,membersFilterUrl:j,redemptions:O,updateForm:B}),ee=async()=>{try{await V({force:!0})&&q()}catch{}},te=(0,Z.useMemo)(()=>{let e=Xe({formState:R,lastPercentAmount:M,lastFreeMonths:P}),t=S.find(e=>x===`month`?e.monthly_price:e.yearly_price);return{enabled:R.enabled,name:`${y} retention`,code:`${y}-retention`,displayTitle:R.displayTitle||``,displayDescription:R.displayDescription||``,type:e.type,cadence:x,amount:e.amount,duration:e.duration,durationInMonths:e.durationInMonths,currency:``,status:`active`,tierId:t?.id||``,redemptionType:`retention`}},[S,y,R,P,M,x]);(0,Z.useEffect)(()=>{if(!n.url){v(``);return}let e=Ce(te,n.url);v(e)},[te,n.url]);let ne=(0,Q.jsx)(ye,{href:_||``,portalParent:`offers`});return(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:H===`unsaved`,height:`full`,okLabel:U.label||`Save`,okVariant:U.variant,preview:ne,previewToolbarBreadcrumbs:(0,Q.jsx)(be,{current:b,label:`Offers`,onBack:q}),sidebar:J,size:`lg`,testId:`retention-offer-modal`,title:`Offer`,width:1140,onCancel:q,onClose:()=>t(`offers`),onOk:ee})},rt=({id:e})=>{let{updateRoute:t}=w(),{data:{offers:n=[]}={}}=d(e||``),[r,i]=(0,Z.useState)(),[a,o]=(0,Z.useState)(``),{siteData:s}=X();(0,Z.useEffect)(()=>{if(n.length>0){let e=n[0],t=`${de(s)}${e?.code}`;o(t),i(e)}},[n,s]);let[c,l]=(0,Z.useState)(!1),u=()=>{let e=``;switch(r?.type){case`percent`:e=r?.amount+`% discount`;break;case`fixed`:e=p(Se(r?.amount),{maximumFractionDigits:2})+` `+r?.currency+` discount`;break;case`trial`:e=r?.amount+` days free trial`;break;default:break}return`${encodeURIComponent(r?.name||``)} — Check out ${encodeURIComponent(e)} on:`};return(0,Q.jsx)(S,{animate:!1,backDropClick:!1,footer:!1,height:`full`,size:`lg`,testId:`offer-success-modal`,topRightContent:`close`,width:1140,onClose:()=>{t(`offers`)},children:(0,Q.jsxs)(`div`,{className:`-mt-6 flex h-full flex-col items-center justify-center text-center`,children:[(0,Q.jsx)(be,{className:`absolute top-5 left-6`,current:r?.name||``,label:`Offers`,onBack:()=>t(`offers/edit`)}),(0,Q.jsx)(ae,{className:`-mt-4 size-10 text-grey-700`}),(0,Q.jsx)(`h1`,{className:`mt-6 text-4xl`,children:`Your new offer is live!`}),(0,Q.jsx)(`p`,{className:`mt-3 max-w-[510px] text-[1.6rem]`,children:`You can share the link anywhere. In your newsletter, social media, a podcast, or in-person. It all just works.`}),(0,Q.jsxs)(`div`,{className:`mt-8 flex w-full max-w-md flex-col gap-8`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2`,children:[(0,Q.jsx)(Y,{name:`offer-url`,type:`url`,value:a,disabled:!0}),(0,Q.jsx)(J,{className:`w-full`,type:`button`,onClick:async()=>{await navigator.clipboard.writeText(a),l(!0),setTimeout(()=>l(!1),2e3)},children:c?`Copied!`:`Copy link`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 text-sm font-medium before:h-px before:grow before:bg-grey-300 before:content-[""] after:h-px after:grow after:bg-grey-300 after:content-[""] dark:before:bg-grey-800 dark:after:bg-grey-800`,children:`OR`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{"aria-label":`Share on X`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`https://twitter.com/intent/tweet?url=${encodeURI(a)}&text=${u()}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`twitter-x`})}),(0,Q.jsx)(J,{"aria-label":`Share on Facebook`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURI(a)}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`facebook`})}),(0,Q.jsx)(J,{"aria-label":`Share on LinkedIn`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`http://www.linkedin.com/shareArticle?mini=true&url=${encodeURI(a)}&title=${u()}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`linkedin`})})]})]})]})})},it=(e,t)=>e.find(e=>e.redemption_type===`retention`&&e.cadence===t&&e.status===`active`)||null,at=(e,t)=>e.reduce((e,n)=>n.redemption_type!==`retention`||n.cadence!==t?e:e+(n.redemption_count||0),0),ot=(e,t)=>e.filter(e=>e.redemption_type===`retention`&&e.cadence===t).map(e=>e.id),st=(e,t)=>{let n=e.filter(e=>e.redemption_type===`retention`&&e.cadence===t&&e.created_at).map(e=>new Date(e.created_at).getTime()).filter(e=>!Number.isNaN(e));return n.length===0?null:new Date(Math.max(...n)).toISOString()},ct=e=>e.type===`percent`&&e.amount===100&&e.duration===`repeating`,lt=e=>{if(!e)return null;if(ct(e)){let t=e.duration_in_months||0,n=t===1?`month`:`months`;return`${p(t)} ${n} free`}return e.type===`percent`?`${p(e.amount)}% OFF`:null},ut=e=>{if(!e)return null;if(ct(e))return``;if(e.duration===`once`)return`First payment`;if(e.duration===`repeating`&&e.duration_in_months){let t=e.duration_in_months===1?`month`:`months`;return`For ${p(e.duration_in_months)} ${t}`}return e.duration===`forever`?`Forever`:null},dt=e=>{let t=it(e,`month`),n=it(e,`year`),r=ot(e,`month`),i=ot(e,`year`),a=at(e,`month`),o=at(e,`year`);return[{id:`monthly`,name:`Monthly retention`,description:`Applied to monthly plans`,terms:lt(t),termsDetail:ut(t),redemptionOfferIds:r,redemptions:a,status:t?`active`:`inactive`,createdAt:st(e,`month`)},{id:`yearly`,name:`Yearly retention`,description:`Applied to annual plans`,terms:lt(n),termsDetail:ut(n),redemptionOfferIds:i,redemptions:o,status:n?`active`:`inactive`,createdAt:st(e,`year`)}]},ft=e=>e===`month`?`monthly`:`yearly`,pt=e=>e===`once`?`First payment`:e===`repeating`?`Repeating`:`Forever`,mt=(e,t,n,r,i)=>{let a=``,o=n===`month`?i?.monthly_price??0:i?.yearly_price??0,s=o,c=e=>parseFloat(e.toFixed(2)),l=e=>p(c(Se(e)),{maximumFractionDigits:2}),u=xe(r)+l(o);switch(e){case`percent`:a=`${p(t)}% off`,s=o-o*t/100;break;case`fixed`:a=`${l(t)} ${r} off`,s=o-t;break;case`trial`:a=`${p(t)} days free`,u=``;break;default:break}s<0&&(s=0);let d=xe(r)+l(s);return{discountOffer:a,originalPriceWithCurrency:u,updatedPriceWithCurrency:d}},ht=({showArchived:e,setShowArchived:t,sortOption:n,sortDirection:r,onSortChange:i,onDirectionChange:a})=>(0,Q.jsxs)(ne,{children:[(0,Q.jsx)(ie,{asChild:!0,children:(0,Q.jsx)(J,{"aria-label":`Filter options`,className:`text-muted-foreground hover:text-foreground`,size:`icon`,type:`button`,variant:`ghost`,children:(0,Q.jsx)(oe,{size:16,strokeWidth:1.5})})}),(0,Q.jsxs)(re,{align:`end`,className:`z-[9999] min-w-[200px] normal-case`,children:[(0,Q.jsx)(se,{className:`text-xs tracking-wide text-muted-foreground uppercase`,children:`Sort by`}),(0,Q.jsxs)(ue,{value:n,onValueChange:i,children:[(0,Q.jsx)(ce,{value:`date-added`,children:`Date added`}),(0,Q.jsx)(ce,{value:`name`,children:`Name`}),(0,Q.jsx)(ce,{value:`redemptions`,children:`Redemptions`})]}),(0,Q.jsxs)(K,{onSelect:a,children:[r===`asc`?(0,Q.jsx)(ee,{className:`size-3`}):(0,Q.jsx)(q,{className:`size-3`}),r===`asc`?`Ascending`:`Descending`]}),(0,Q.jsx)(le,{}),(0,Q.jsx)(te,{checked:e,onCheckedChange:e=>t(!!e),children:`Show archived`})]})]}),gt=({offer:e,onClick:t})=>{let n=e.redemptions>0&&e.redemptionOfferIds.length>0?je(e.redemptionOfferIds):void 0;return(0,Q.jsxs)(z,{"data-testid":`retention-offer-item`,children:[(0,Q.jsx)(V,{className:`sticky left-0 z-10 bg-background p-0`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:e.terms?(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium uppercase`,children:e.terms}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.termsDetail})]}):(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`–`})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`–`})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:n?(0,Q.jsx)(`a`,{className:`block cursor-pointer p-5 hover:underline`,"data-testid":`retention-redemptions-link-${e.id}`,href:n,children:p(e.redemptions)}):(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,"data-testid":`retention-redemptions-link-${e.id}`,type:`button`,onClick:t,children:p(e.redemptions)})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:e.status===`active`?(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`success`,children:`Active`}):(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`secondary`,children:`Inactive`})})})]})},_t=({archived:e,offer:t,tier:n,onClick:r})=>{let{discountOffer:i,originalPriceWithCurrency:a,updatedPriceWithCurrency:o}=mt(t.type,t.amount,t.cadence,t.currency||`USD`,n);return(0,Q.jsxs)(z,{className:e?`opacity-60`:void 0,"data-testid":`offer-item`,children:[(0,Q.jsx)(V,{className:`sticky left-0 z-10 bg-background p-0`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:t.name}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[n.name,` `,ft(t.cadence)]})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium uppercase`,children:i}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:t.type===`trial`?`Trial period`:pt(t.duration)})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsxs)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:o}),` `,t.type===`trial`?null:(0,Q.jsx)(`span`,{className:`relative text-sm text-muted-foreground before:absolute before:-inset-x-0.5 before:top-1/2 before:rotate-[-20deg] before:border-t before:content-[""]`,children:a})]})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:t.redemption_count>0&&t.id?(0,Q.jsx)(`a`,{className:`block cursor-pointer p-5 hover:underline`,href:Me(t.id),children:p(t.redemption_count)}):(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:p(t.redemption_count)})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:e?(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`secondary`,children:`Archived`}):(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`success`,children:`Active`})})})]})},vt=e=>e.offer.name,yt=e=>e.kind===`retention`?e.offer.redemptions:e.offer.redemption_count,bt=e=>e.kind===`retention`?e.offer.createdAt:e.offer.created_at||null,xt=(e,t,n)=>{let r=n===`desc`?-1:1;return[...e].sort((e,n)=>{let i;switch(t){case`name`:i=vt(e).localeCompare(vt(n));break;case`redemptions`:i=yt(e)-yt(n);break;default:{let t=bt(e),r=bt(n);if(!t&&!r)i=0;else if(!t)return 1;else if(r)i=new Date(t).getTime()-new Date(r).getTime();else return-1;break}}return(i||vt(e).localeCompare(vt(n)))*r})},St=()=>{let{updateRoute:e}=w(),{data:{offers:t=[]}={}}=u(),{data:{tiers:n}={}}=fe(),r=t.filter(e=>e.redemption_type===`signup`),i=dt(t),{sortingState:a,setSortingState:s}=ge(),c=a?.find(e=>e.type===`offers`),{offersShowArchived:l,setOffersShowArchived:d}=_e(),f=c?.option||`date-added`,p=c?.direction||`desc`,g=t=>{t&&e(`offers/edit/${t}`)},_=t=>{e(`offers/edit/retention/${t}`)},v=pe(n||[]),y=r.filter(e=>{let t=n?.find(t=>t.id===e?.tier?.id),r=e.status===`active`&&t&&t.active===!0,i=e.status===`archived`||t&&t.active===!1;return!!(r||l&&i)}),b=xt([...i.map(e=>({kind:`retention`,offer:e})),...y.map(e=>({kind:`signup`,offer:e}))],f,p),x=e=>{s?.([{type:`offers`,option:e,direction:p}])},C=()=>{s?.([{type:`offers`,option:f,direction:p===`asc`?`desc`:`asc`}])},T=e=>{let t=n?.find(t=>t.id===e?.tier?.id);return e.status===`archived`||t?.active===!1};return(0,Q.jsx)(S,{animate:!1,backDropClick:!1,cancelLabel:``,footer:!1,height:`full`,size:`lg`,testId:`offers-modal`,title:`Offers`,topRightContent:(0,Q.jsxs)(m,{gap:`md`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>{e(`offers`)},children:`Close`}),(0,Q.jsx)(J,{type:`button`,onClick:()=>{v.length===0?o.info(`You must have an active tier to create an offer.`):e(`offers/new`)},children:`New offer`})]}),width:1140,onClose:()=>{e(`offers`)},children:(0,Q.jsx)(h,{className:`h-full pt-8`,children:(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(U,{className:`m-0 min-w-[900px]`,children:[(0,Q.jsxs)(`colgroup`,{children:[(0,Q.jsx)(`col`,{className:`w-[25%]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[220px]`})]}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(z,{children:[(0,Q.jsx)(R,{className:`sticky left-0 z-10 h-auto bg-background p-0 pb-2.5 pl-5 uppercase`,children:`Name`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Terms`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Price`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Redemptions`}),(0,Q.jsx)(R,{className:`h-auto p-0 px-5 pb-2.5 uppercase`,children:(0,Q.jsxs)(m,{align:`center`,justify:`between`,children:[`Status`,(0,Q.jsx)(ht,{setShowArchived:d,showArchived:l,sortDirection:p,sortOption:f,onDirectionChange:C,onSortChange:x})]})})]})}),(0,Q.jsx)(B,{"data-testid":`offers-table-body`,children:b.map(e=>{if(e.kind===`retention`)return(0,Q.jsx)(gt,{offer:e.offer,onClick:()=>_(e.offer.id)},`retention-${e.offer.id}`);let t=e.offer,r=n?.find(e=>e.id===t?.tier?.id);if(!r)return null;let i=T(t);return(0,Q.jsx)(_t,{archived:i,offer:t,tier:r,onClick:()=>g(t.id)},`signup-${t.id}`)})})]})})})})},Ct=({route:e})=>{if(e===`offers/new`)return(0,Q.jsx)(ke,{});if(e.startsWith(`offers/edit/retention/`)&&e.length>22){let t=e.split(`/`).pop();return(0,Q.jsx)(nt,{id:t||``})}else if(e===`offers/edit/retention/`||e===`offers/edit/retention`)return(0,Q.jsx)(St,{});else if(e.startsWith(`offers/edit/`)&&e.length>12){let t=e.split(`/`).pop();return(0,Q.jsx)(ze,{id:t||``})}else if(e.startsWith(`offers/success/`)&&e.length>15){let t=e.split(`/`).pop();return(0,Q.jsx)(rt,{id:t||``})}else if(e===`offers/edit`||e===`offers/edit/`)return(0,Q.jsx)(St,{})},wt=()=>{let{route:e}=w();return(0,Q.jsx)(Ct,{route:e})};export{wt as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{m as r,p as i,v as a}from"./hooks-D6EE7BIt.js";import{n as o}from"./dist-Ndy-PuGN.js";import{t as s}from"./use-form-vRjI0Kwk.js";import{a as c,i as l,n as u,r as d,t as f}from"./offers-Um6ab71O.js";import{f as p}from"./dist-Cb5RSHSg.js";import{t as m}from"./inline-Cw-gigDW.js";import{t as h}from"./stack-CIfOAAVf.js";import{t as g}from"./switch-CE2NuMn-.js";import{i as _,n as v,o as y,s as b,t as x}from"./select-CkXqNJDJ.js";import{o as S,s as C,t as w}from"./use-settings-navigation-BmROPrls.js";import{a as T,i as E,n as D,o as O,r as k,t as A}from"./field-B3OPenbP.js";import{a as j,i as M,n as N,r as P,t as F}from"./input-group-2XU-iuh_.js";import{n as I,t as L}from"./radio-group-CI5_Kf_d.js";import{a as R,c as z,n as B,r as V,s as H,t as U}from"./table-BtLcEi1M.js";import{t as W}from"./textarea-d9qEkMOP.js";import{$n as G,$r as K,Ds as q,Pr as J,Ss as ee,Xr as te,Yr as ne,Zr as re,ai as ie,bs as ae,co as oe,cr as Y,ei as se,ni as ce,ri as le,ti as ue,wn as de}from"./index-DUXM0NlS.js";import{a as fe,r as pe}from"./tiers-Da6kxHQP.js";import{n as me}from"./confirmation-modal-CYD7x3UQ.js";import{n as X}from"./global-data-provider-RzW6Bnlf.js";import{t as he}from"./brand-icon-09YqFZjV.js";import{o as ge,r as _e}from"./zapier-modal-Bp507Um7.js";import{t as ve}from"./preview-modal-DctYx20m.js";import{t as ye}from"./portal-frame-D4D4nEO6.js";import{t as be}from"./settings-breadcrumbs-DIq31FwA.js";import{i as xe,r as Se}from"./currency-Dy4Tc2R2.js";var Ce=(e,t)=>{let{disableBackground:n=!1,name:r,code:i,displayTitle:a=``,displayDescription:o=``,type:s,cadence:c,amount:l=0,duration:u,durationInMonths:d,currency:f=`usd`,status:p,tierId:m,redemptionType:h=`signup`}=e;t=t.replace(/\/$/,``);let g=new URLSearchParams;return g.append(`disableBackground`,`false`),g.append(`name`,encodeURIComponent(r)),g.append(`code`,encodeURIComponent(i)),g.append(`display_title`,encodeURIComponent(a)),g.append(`display_description`,encodeURIComponent(o)),g.append(`type`,encodeURIComponent(s)),g.append(`cadence`,encodeURIComponent(c)),g.append(`amount`,encodeURIComponent(l)),g.append(`duration`,encodeURIComponent(u)),g.append(`duration_in_months`,encodeURIComponent(d)),g.append(`currency`,encodeURIComponent(f)),g.append(`status`,encodeURIComponent(p)),g.append(`tier_id`,encodeURIComponent(m)),g.append(`redemption_type`,encodeURIComponent(h)),n&&g.append(`disableBackground`,`true`),g.append(`admin_toolbar`,`0`),`${t}/?v=modal-portal-offer#/portal/preview/offer?${g.toString()}`},we=e=>{let t=[];return e.forEach(e=>{t.push({label:`${e.name} - Monthly`,value:`${e.id}-month-${e.currency}`}),t.push({label:`${e.name} - Yearly`,value:`${e.id}-year-${e.currency}`})}),t},Z=e(t(),1),Q=n();function Te(e){return e.toString().toLowerCase().trim().replace(/\s+/g,`-`).replace(/[^\w-]+/g,``).replace(/--+/g,`-`)}var Ee=191,De=e=>{let{fixedAmount:t=0,percentAmount:n=0,trialAmount:r=0,amount:i=0}=e;switch(e.type){case`fixed`:return t*100;case`percent`:return n;case`trial`:return r;default:return i}},Oe=({tierOptions:e,handleTierChange:t,selectedTier:n,typeOptions:r,durationOptions:i,handleTypeChange:a,handleDurationChange:o,overrides:s,handleAmountTypeChange:c,handleNameInput:l,handleTextAreaInput:u,handleDisplayTitleInput:d,handleDurationInMonthsInput:f,handleAmountInput:m,handleCodeInput:h,clearError:g,errors:S,testId:C,handleTrialAmountInput:w,amountOptions:P})=>{let R=s.cadence===`year`,z=R?i.filter(e=>e.value!==`repeating`):i,[B,V]=(0,Z.useState)(0),H=B>40?`text-red`:`text-green`,{siteData:U}=X(),[G,K]=(0,Z.useState)(!1),q=de(U),ee=`${q}${s.code.value}`;return(0,Q.jsx)(`div`,{className:`pt-7`,"data-testid":C,children:(0,Q.jsxs)(T,{className:`mb-10 gap-8`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{"data-invalid":!!S.name||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-name`,children:`Offer name`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.name||void 0,id:`offer-name`,maxLength:40,placeholder:`Black Friday`,onChange:e=>{l(e),V(e.target.value.length)},onKeyDown:()=>g(`name`)}),S.name?(0,Q.jsx)(E,{children:S.name}):(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Q.jsx)(`span`,{children:`Visible to members on Stripe Checkout page`}),(0,Q.jsxs)(`strong`,{children:[(0,Q.jsx)(`span`,{className:H,children:p(B)}),` / `,p(40)]})]})})]}),(0,Q.jsxs)(A,{"data-invalid":!!S.displayTitle||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.displayTitle||void 0,id:`offer-display-title`,maxLength:Ee,placeholder:`Black Friday Special`,value:s.displayTitle.value,onChange:e=>{d(e)},onKeyDown:()=>g(`displayTitle`)}),S.displayTitle&&(0,Q.jsx)(E,{children:S.displayTitle})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`offer-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`offer-display-description`,maxLength:Ee,placeholder:`Take advantage of this limited-time offer.`,value:s.displayDescription,onChange:e=>{u(e)}})]})]})]}),(0,Q.jsxs)(`section`,{className:`mt-4`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`Details`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsx)(L,{"aria-label":`Offer type`,className:`rounded-md border border-border-default p-4`,value:s.type===`trial`?`trial`:`percent`,onValueChange:a,children:r.map(e=>{let t=`offer-type-${e.value}`;return(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsx)(I,{id:t,value:e.value}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(O,{className:`cursor-pointer`,htmlFor:t,children:e.title}),(0,Q.jsx)(k,{children:e.description})]})]},e.value)})}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Tier — Cadence`}),(0,Q.jsxs)(x,{value:n.value,onValueChange:n=>{let r=e.find(e=>e.value===n);r&&t(r)},children:[(0,Q.jsx)(y,{"aria-label":`Tier — Cadence`,"data-testid":`tier-cadence-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:e.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),s.type!==`trial`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(A,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-amount`,children:`Amount off`}),(0,Q.jsxs)(F,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(M,{id:`offer-amount`,type:`number`,value:s.type===`fixed`?s.fixedAmount===0?``:s.fixedAmount?.toString():s.percentAmount===0?``:s.percentAmount?.toString(),onChange:e=>{m(e)},onKeyDown:()=>g(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsxs)(x,{value:s.type===`percent`?P[0].value:P[1].value,onValueChange:c,children:[(0,Q.jsx)(y,{"aria-label":`Amount type`,className:`h-7 w-20 border-0 bg-transparent px-2 shadow-none focus-visible:ring-0`,"data-testid":`amount-type-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{align:`end`,children:P.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})})]}),S.amount&&(0,Q.jsx)(E,{children:S.amount})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Duration`}),(0,Q.jsxs)(x,{value:s.duration,onValueChange:e=>{g(`durationInMonths`),o(e)},children:[(0,Q.jsx)(y,{"aria-label":`Duration`,"data-testid":`duration-select-offers`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:z.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),s.duration===`repeating`&&!R&&(0,Q.jsx)(`div`,{className:`-mt-4`,children:(0,Q.jsxs)(A,{"data-invalid":!!S.durationInMonths||void 0,children:[(0,Q.jsxs)(F,{"data-invalid":!!S.durationInMonths||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!S.durationInMonths||void 0,"data-testid":`duration-months-input`,type:`number`,value:s.durationInMonths===0?``:String(s.durationInMonths),onChange:e=>{f(e)},onKeyDown:()=>g(`durationInMonths`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:s.durationInMonths===1?`month`:`months`})})]}),S.durationInMonths&&(0,Q.jsx)(E,{children:S.durationInMonths})]})})]}),s.type===`trial`&&(0,Q.jsxs)(A,{"data-invalid":!!S.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`trial-duration`,children:`Trial duration`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.amount||void 0,id:`trial-duration`,type:`number`,value:s.trialAmount?.toString(),onChange:e=>{w(e)},onKeyDown:()=>g(`amount`)}),S.amount&&(0,Q.jsx)(E,{children:S.amount})]}),(0,Q.jsxs)(A,{"data-invalid":!!S.code||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-code`,children:`Offer code`}),(0,Q.jsx)(Y,{"aria-invalid":!!S.code||void 0,id:`offer-code`,placeholder:`black-friday`,value:s.code.value,onChange:e=>{h(e)},onKeyDown:()=>g(`code`)}),S.code?(0,Q.jsx)(E,{children:S.code}):s.code.value!==``&&(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{children:[q,(0,Q.jsx)(`span`,{className:`font-bold`,children:s.code.value})]}),(0,Q.jsx)(J,{className:`h-auto p-0 text-sm text-green hover:text-green`,size:`sm`,type:`button`,variant:`link`,onClick:async()=>{await navigator.clipboard.writeText(ee),K(!0),setTimeout(()=>K(!1),2e3)},children:G?`Copied`:`Copy`})]})})]})]})]})]})})},$=e=>{let[t,n,r]=e.split(`-`);if(!t||!n||!r)throw Error(`Invalid input format. Expected format is: id-period-currency`);return{id:t,period:n,currency:r}},ke=()=>{let{siteData:e}=X(),t=[{title:`Discount`,description:`Offer a special reduced price`,value:`percent`},{title:`Free trial`,description:`Give free access for a limited time`,value:`trial`}],n=[{value:`once`,label:`First-payment`},{value:`repeating`,label:`Multiple-months`},{value:`forever`,label:`Forever`}],[r,i]=(0,Z.useState)(``),{updateRoute:c}=w(),{data:{tiers:l}={}}=fe(),d=pe(l||[]),p=we(d),{mutateAsync:m}=f(),[h,g]=(0,Z.useState)({tier:p[0]||{},dataset:{id:p[0]?.value?$(p[0]?.value).id:``,period:p[0]?.value?$(p[0]?.value).period:``,currency:p[0]?.value?$(p[0]?.value).currency:``}}),{data:{offers:_=[]}={}}=u(),{formState:v,updateForm:y,handleSave:b,saveState:x,okProps:S,validate:C,errors:T,clearError:E}=s({initialState:{disableBackground:!1,name:``,code:{isDirty:!1,value:``},displayTitle:{isDirty:!1,value:``},displayDescription:``,type:`percent`,cadence:h?.dataset?.period||``,amount:0,duration:`once`,durationInMonths:1,currency:h?.dataset?.currency||`USD`,status:`active`,tierId:h?.dataset?.id||``,trialAmount:7,fixedAmount:0,percentAmount:0},onSave:async()=>{let e=v.type===`trial`?`trial`:v.duration,t={name:v.name,code:v.code.value,display_title:v.displayTitle.value,display_description:v.displayDescription,cadence:v.cadence,amount:De(v)||0,duration:e,...e===`repeating`?{duration_in_months:v.durationInMonths}:{},currency:v.currency,status:v.status,redemption_type:`signup`,tier:{id:v.tierId},type:v.type,currency_restriction:!1},n=await m(t);n&&n.offers&&n.offers.length>0&&c(`offers/success/${n.offers[0].id}`)},onSaveError:()=>{},onValidate:()=>{let e={};return!v.name&&v.name.length===0&&(e.name=`Name is required`),!v.code.value&&v.code.value.length===0&&(e.code=`Code is required`),!v.displayTitle.value&&v.displayTitle.value.length===0&&(e.displayTitle=`Display title is required`),v.type===`percent`&&v.percentAmount===0&&(e.amount=`Enter an amount greater than 0.`),v.type===`percent`&&(v.percentAmount<1||v.percentAmount>100)&&(e.amount=`Enter an amount between 1 and 100%.`),(v.type===`fixed`&&v.fixedAmount===0||v.type===`fixed`&&v.fixedAmount<1)&&(e.amount=`Enter an amount greater than 0.`),v.type===`trial`&&v.trialAmount===0&&(e.amount=`Enter an amount greater than 0.`),v.type===`trial`&&v.trialAmount<1&&(e.amount=`Free trial must be at least 1 day.`),v.type!==`trial`&&v.duration===`repeating`&&(!Number.isInteger(v.durationInMonths)||v.durationInMonths<1)&&(e.durationInMonths=`Enter a whole number of months (1 or more).`),e},savingDelay:500}),D=[{value:`percent`,label:`%`},{value:`fixed`,label:v.currency}],O=e=>{let t=$(e.value),n=t.period===`year`;g({tier:e,dataset:t}),y(e=>({...e,cadence:t.period,currency:t.currency,tierId:t.id,duration:n&&e.duration===`repeating`?`once`:e.duration})),n&&E(`durationInMonths`)},k=e=>{e===`trial`&&(E(`amount`),E(`durationInMonths`)),y(t=>({...t,type:e}))},A=e=>{y(t=>({...t,type:e===`percent`?`percent`:`fixed`}))},j=e=>{let t=e.target;v.type===`fixed`?y(e=>({...e,fixedAmount:Number(t.value)})):v.type===`percent`?y(e=>({...e,percentAmount:Number(t.value)})):y(e=>({...e,amount:Number(t.value)}))},M=e=>{let t=e.target,n=Number(t.value);y(e=>({...e,durationInMonths:Number.isNaN(n)?0:n}))},N=e=>{let t=e.target.value;y(e=>{let n={...e};return n.name=t,e.code.isDirty||(E(`code`),n.code={...e.code,value:Te(t)}),e.displayTitle.isDirty||(E(`displayTitle`),n.displayTitle={...e.displayTitle,value:t}),n})},P=e=>{let t=e.target;y(e=>({...e,displayTitle:{...e.displayTitle,isDirty:!0,value:t.value}}))},F=e=>{let t=e.target;y(e=>({...e,displayDescription:t.value}))},I=e=>{let t=e.target;y(e=>({...e,trialAmount:Number(t.value)}))},L=e=>{y(t=>({...t,duration:e}))},R=e=>{let t=e.target;y(e=>({...e,code:{...e.code,isDirty:!0,value:t.value}}))},z=()=>{_.length>0?c(`offers/edit`):c(`offers`)},B=(0,Z.useMemo)(()=>({name:v.name||``,code:v.code.value||``,displayTitle:v.displayTitle.value||``,displayDescription:v.displayDescription||``,type:v.type||`percent`,cadence:v.cadence||`month`,amount:De(v)||0,duration:v.type===`trial`?`trial`:v.duration||`once`,durationInMonths:v.durationInMonths||0,currency:v.currency||`USD`,status:v.status||`active`,tierId:v.tierId||d[0]?.id,redemptionType:`signup`}),[v,d]);(0,Z.useEffect)(()=>{let t=Ce(B,e.url);i(t)},[v,e.url,v.type,B]);let V=(0,Q.jsx)(Oe,{amountOptions:D,clearError:E,durationOptions:n,errors:T,handleAmountInput:j,handleAmountTypeChange:A,handleCodeInput:R,handleDisplayTitleInput:P,handleDurationChange:L,handleDurationInMonthsInput:M,handleNameInput:N,handleTextAreaInput:F,handleTierChange:O,handleTrialAmountInput:I,handleTypeChange:k,overrides:v,selectedTier:h.tier,testId:`add-offer-sidebar`,tierOptions:p,typeOptions:t,validate:C}),H=(0,Q.jsx)(ye,{href:r||``,portalParent:`offers`});return(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:x===`unsaved`,height:`full`,okLabel:`Publish`,okVariant:S.variant,preview:H,previewToolbar:!1,sidebar:V,size:`lg`,testId:`add-offer-modal`,title:`Offer`,width:1140,onCancel:z,onClose:()=>{c(`offers`)},onOk:async()=>{if(C(),!Object.values(T).every(e=>!e)){o.dismiss(),o.info(`Can't save offer`,{description:`Make sure you filled all required fields`});return}try{if(await b({force:!0}))return}catch(e){let t;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message),o.dismiss(),t&&o.error(`Can't save offer`,{description:t||`Please try again later`})}}})},Ae=e=>new Date(e).toLocaleDateString(`default`,{year:`numeric`,month:`short`,day:`2-digit`}),je=e=>{let t=`${i().adminRoot}#/members`,n=`offer_redemptions:[${e.join(`,`)}]`;return`${t}?filter=${encodeURIComponent(n)}`},Me=e=>je([e]),Ne=({amount:e,duration:t})=>e===100&&t===`repeating`,Pe=(e,t)=>`Retention ${e} (${t})`,Fe=({amount:e,duration:t,durationInMonths:n})=>Ne({amount:e,duration:t})?`${n} ${n===1?`month`:`months`} free`:t===`once`?`${e}% off once`:t===`repeating`?`${e}% off for ${n} mo`:`${e}% off forever`,Ie=(e,t)=>{let n=t.trim(),r=Fe(e),i=Pe(r,n);if(i.length<=40)return i;let a=i.length-40,o=Math.max(3,n.length-a);return Pe(r,n.slice(0,o))};function Le(e){return new Date(e).toLocaleDateString(`default`,{year:`numeric`,month:`short`,day:`2-digit`})}var Re=({clearError:e,errors:t,offer:n,updateOffer:i})=>{let{siteData:a}=X(),[s,c]=(0,Z.useState)(!1),u=r(),{mutateAsync:d}=l(),[f,m]=(0,Z.useState)(n?.name.length||0),h=f>40?`text-red`:`text-green`,{updateRoute:g}=w();(0,Z.useEffect)(()=>{n?.name&&m(n?.name.length)},[n?.name]);let _=de(a),v=`${_}${n?.code}`,y=async()=>{await navigator.clipboard.writeText(v),c(!0),setTimeout(()=>c(!1),2e3)},b=async()=>{n?.status===`active`?C.show(me,{title:`Archive offer`,prompt:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{children:`New members will no longer be able to subscribe using this offer.`}),(0,Q.jsxs)(`p`,{children:[`All members that previously redeemed `,(0,Q.jsx)(`strong`,{children:n?.name}),` will remain unchanged.`]})]}),okLabel:`Archive`,okVariant:`destructive`,onOk:async e=>{try{await d({...n,status:`archived`}),e?.remove(),o.success(`Offer archived`),g(`offers/edit`)}catch(e){u(e)}}}):C.show(me,{title:`Reactivate offer`,prompt:(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`p`,{children:[`Reactivating `,(0,Q.jsx)(`strong`,{children:n?.name}),` will allow new members to subscribe using this offer. Existing members will remain unchanged.`]})}),okLabel:`Reactivate`,onOk:async e=>{try{await d({...n,status:`active`}),e?.remove(),o.success(`Offer reactivated`),g(`offers/edit`)}catch(e){u(e)}}})};return(0,Q.jsxs)(`div`,{className:`flex grow flex-col pt-2`,children:[(0,Q.jsxs)(T,{className:`mb-10 grow gap-8`,children:[(0,Q.jsx)(`section`,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5 rounded-md border border-grey-300 p-4 pb-3.5 dark:border-grey-800`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Created on`}),(0,Q.jsx)(`span`,{children:Le(n?.created_at?n.created_at:``)})]}),(0,Q.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Performance`}),(0,Q.jsxs)(`span`,{children:[p(n?.redemption_count||0),` `,n?.redemption_count===1?`redemption`:`redemptions`]})]}),n?.redemption_count>0&&n?.last_redeemed?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Last redemption`}),(0,Q.jsx)(`span`,{children:Le(n?.last_redeemed)})]}):null]}),n?.redemption_count>0?(0,Q.jsx)(`a`,{className:`font-semibold text-green`,href:Me(n?.id),children:`See members →`}):null]})]})}),(0,Q.jsxs)(`section`,{className:`mt-2`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{"data-invalid":!!t.name||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-name`,children:`Offer name`}),(0,Q.jsx)(Y,{"aria-invalid":!!t.name||void 0,id:`offer-name`,maxLength:40,placeholder:`Black Friday`,value:n?.name??``,onChange:e=>{m(e.target.value.length),i({name:e.target.value})},onKeyDown:()=>e(`name`)}),t.name?(0,Q.jsx)(E,{children:t.name}):(0,Q.jsx)(k,{children:(0,Q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Q.jsx)(`span`,{children:`Visible to members on Stripe Checkout page`}),(0,Q.jsxs)(`strong`,{children:[(0,Q.jsx)(`span`,{className:h,children:p(f)}),` / `,p(40)]})]})})]}),(0,Q.jsxs)(A,{className:`group`,"data-invalid":!!t.code||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-code`,children:`Offer code`}),(0,Q.jsxs)(F,{"data-invalid":!!t.code||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!t.code||void 0,id:`offer-code`,placeholder:`black-friday`,value:n?.code??``,onChange:e=>i({code:e.target.value}),onKeyDown:()=>e(`code`)}),n?.code!==``&&(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(P,{onClick:y,children:s?`Copied!`:`Copy link`})})]}),t.code?(0,Q.jsx)(E,{children:t.code}):n?.code!==``&&(0,Q.jsxs)(k,{className:`truncate`,children:[_,(0,Q.jsx)(`span`,{className:`font-bold text-foreground`,children:n?.code})]})]}),(0,Q.jsxs)(A,{"data-invalid":!!t.displayTitle||void 0,children:[(0,Q.jsx)(O,{htmlFor:`offer-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{"aria-invalid":!!t.displayTitle||void 0,id:`offer-display-title`,placeholder:`Black Friday Special`,value:n?.display_title??``,onChange:e=>i({display_title:e.target.value}),onKeyDown:()=>e(`displayTitle`)}),t.displayTitle&&(0,Q.jsx)(E,{children:t.displayTitle})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`offer-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`offer-display-description`,placeholder:`Take advantage of this limited-time offer.`,value:n?.display_description??``,onChange:e=>i({display_description:e.target.value})})]})]})]})]}),(0,Q.jsx)(`div`,{className:`mb-2`,children:n?.status===`active`?(0,Q.jsx)(J,{className:`h-auto p-0 text-destructive hover:text-destructive`,type:`button`,variant:`link`,onClick:b,children:`Archive offer`}):(0,Q.jsx)(J,{className:`h-auto p-0 text-green hover:text-green`,type:`button`,variant:`link`,onClick:b,children:`Reactivate offer`})})]})},ze=({id:e})=>{let{siteData:t}=X(),{updateRoute:n}=w(),i=r(),{mutateAsync:c}=l(),[u,f]=(0,Z.useState)(``),{data:{offers:p=[]}={}}=d(e||``),{formState:m,saveState:h,updateForm:g,setFormState:_,handleSave:v,validate:y,errors:b,clearError:x,okProps:S}=s({initialState:p[0],savingDelay:500,onSave:async()=>{await c(m)},onSaveError:i,onValidate:()=>{let e={};return m?.name||(e.name=`Name is required`),m?.display_title||(e.displayTitle=`Display title is required`),m?.code||(e.code=`Please enter a code`),e}});(0,Z.useEffect)(()=>{_(()=>p[0])},[_,p]);let C=(0,Q.jsx)(Re,{clearError:x,errors:b,offer:m,updateOffer:e=>{g(t=>({...t,...e}))},validate:y});(0,Z.useEffect)(()=>{let e=Ce({name:m?.name||``,code:m?.code||``,displayTitle:m?.display_title||``,displayDescription:m?.display_description||``,type:m?.type||``,cadence:m?.cadence||``,amount:m?.amount,duration:m?.duration||``,durationInMonths:m?.duration_in_months||0,currency:m?.currency||``,status:m?.status||``,tierId:m?.tier?.id||``,redemptionType:`signup`},t.url);f(e)},[m,t]);let T=(0,Q.jsx)(ye,{href:u||``,portalParent:`offers`}),E=()=>{n(`offers/edit`)};return p?(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:h===`unsaved`,height:`full`,okLabel:S.label||`Save`,okVariant:S.variant,preview:T,previewToolbarBreadcrumbs:(0,Q.jsx)(be,{current:m?.name||`Offer`,label:`Offers`,onBack:E}),sidebar:C,size:`lg`,testId:`offer-update-modal`,title:`Offer`,width:1140,onCancel:E,onClose:()=>{n(`offers`)},onOk:async()=>{try{if(await v({force:!0}))return}catch(e){let t;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message),o.dismiss(),t&&o.error(`Can't save offer`,{description:`Please try again later`})}}}):null},Be=[{title:`Percentage discount`,description:`Offer a special reduced price`,value:`percent`},{title:`Free month(s)`,description:`Give free access for a limited time`,value:`free_months`}],Ve=[{value:`once`,label:`First-payment`},{value:`repeating`,label:`Multiple-months`},{value:`forever`,label:`Forever`}],He=191,Ue=99,We=`Enter a whole number of months between 1 and ${Ue}.`,Ge=e=>Math.max(1,Number.isFinite(e)?Math.trunc(e):0),Ke=({type:e,percentAmount:t,freeMonths:n,lastPercentAmount:r,lastFreeMonths:i})=>e===`free_months`?n>0?n:i:t>0?t:r,qe=(e=`monthly`)=>({enabled:!1,displayTitle:``,displayDescription:``,type:e===`yearly`?`percent`:`free_months`,percentAmount:20,duration:`once`,durationInMonths:1,freeMonths:1}),Je=e=>e.type===`percent`&&e.amount===100&&e.duration===`repeating`,Ye=(e,t=`monthly`)=>{let n=qe(t);if(!e)return n;let r=Je(e),i=e.type===`percent`&&!r,a=e.duration===`repeating`&&e.duration_in_months?e.duration_in_months:n.durationInMonths;return{enabled:e.status===`active`,displayTitle:e.display_title||``,displayDescription:e.display_description||``,type:r?`free_months`:`percent`,percentAmount:i?e.amount:n.percentAmount,duration:i?e.duration:n.duration,durationInMonths:a,freeMonths:r&&e.duration_in_months||n.freeMonths}},Xe=({formState:e,lastPercentAmount:t,lastFreeMonths:n})=>{let r=Ke({type:e.type,percentAmount:e.percentAmount,freeMonths:e.freeMonths,lastPercentAmount:t,lastFreeMonths:n});if(e.type===`free_months`)return{type:`percent`,amount:100,duration:`repeating`,durationInMonths:Ge(r)};let i=e.duration;return{type:`percent`,amount:r,duration:i,durationInMonths:i===`repeating`?Ge(e.durationInMonths):0}},Ze=e=>{if(!e)return null;let t=e.duration_in_months??0;return{type:`percent`,amount:e.amount,duration:e.duration,durationInMonths:t}},Qe=e=>e?`${e.type}:${e.amount}:${e.duration}:${e.durationInMonths}`:``,$e=e=>Number.isInteger(e)&&e>0&&e<=Ue,et=(e,t)=>e.displayTitle!==t.displayTitle||e.displayDescription!==t.displayDescription||e.type!==t.type||e.percentAmount!==t.percentAmount||e.duration!==t.duration||e.durationInMonths!==t.durationInMonths||e.freeMonths!==t.freeMonths,tt=({formState:e,updateForm:t,clearError:n,errors:r,cadence:i,lastRedeemed:a,membersFilterUrl:o,redemptions:s})=>{let c=i===`yearly`?Ve.filter(e=>e.value!==`repeating`):Ve;return(0,Q.jsx)(`div`,{className:`flex grow flex-col pt-2`,children:(0,Q.jsxs)(T,{className:`mb-10 grow gap-8`,children:[(0,Q.jsx)(`section`,{children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-5 rounded-md border border-grey-300 p-4 pb-3.5 dark:border-grey-800`,children:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Performance`}),(0,Q.jsxs)(`span`,{children:[p(s),` `,s===1?`redemption`:`redemptions`]})]}),s>0&&a?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm leading-none font-semibold text-grey-700`,children:`Last redemption`}),(0,Q.jsx)(`span`,{children:Ae(a)})]}):null]}),s>0&&o?(0,Q.jsx)(`a`,{className:`font-semibold text-green`,href:o,children:`See members →`}):null]})})})}),(0,Q.jsx)(`section`,{className:`mt-2`,children:(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsxs)(D,{children:[(0,Q.jsxs)(O,{htmlFor:`${i}-retention-enabled`,children:[`Enable `,i,` retention`]}),(0,Q.jsx)(k,{children:i===`monthly`?`Applied to monthly plans`:`Applied to annual plans`})]}),(0,Q.jsx)(g,{checked:e.enabled,id:`${i}-retention-enabled`,onCheckedChange:e=>t(t=>({...t,enabled:e}))})]})}),e.enabled&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`section`,{className:`mt-2`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`General`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`retention-display-title`,children:`Display title`}),(0,Q.jsx)(Y,{id:`retention-display-title`,maxLength:He,placeholder:`Before you go`,value:e.displayTitle,onChange:e=>{t(t=>({...t,displayTitle:e.target.value}))}})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{htmlFor:`retention-display-description`,children:`Display description`}),(0,Q.jsx)(W,{id:`retention-display-description`,maxLength:He,placeholder:`We'd hate to see you leave. How about a special offer to stay?`,value:e.displayDescription,onChange:e=>{t(t=>({...t,displayDescription:e.target.value}))}})]})]})]}),(0,Q.jsxs)(`section`,{className:`mt-4`,children:[(0,Q.jsx)(`h2`,{className:`mb-4 text-lg`,children:`Details`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[i===`monthly`&&(0,Q.jsx)(L,{"aria-label":`${i} retention offer type`,className:`rounded-md border border-border-default p-4`,value:e.type,onValueChange:e=>{n(`amount`),n(`durationInMonths`),t(t=>({...t,type:e}))},children:Be.map(e=>{let t=`${i}-retention-type-${e.value}`;return(0,Q.jsxs)(A,{orientation:`horizontal`,children:[(0,Q.jsx)(I,{id:t,value:e.value}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(O,{className:`cursor-pointer`,htmlFor:t,children:e.title}),(0,Q.jsx)(k,{children:e.description})]})]},e.value)})}),e.type===`percent`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(A,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`retention-amount`,children:`Amount off`}),(0,Q.jsxs)(F,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.amount||void 0,id:`retention-amount`,type:`number`,value:e.percentAmount===0?``:String(e.percentAmount),onChange:e=>{let n=Number(e.target.value),r=Number.isNaN(n)?0:n;t(e=>({...e,percentAmount:r}))},onKeyDown:()=>n(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:`%`})})]}),r.amount&&(0,Q.jsx)(E,{children:r.amount})]}),(0,Q.jsxs)(A,{children:[(0,Q.jsx)(O,{children:`Duration`}),(0,Q.jsxs)(x,{value:e.duration,onValueChange:e=>{n(`durationInMonths`),t(t=>({...t,duration:e}))},children:[(0,Q.jsx)(y,{"aria-label":`Duration`,children:(0,Q.jsx)(b,{})}),(0,Q.jsx)(v,{children:c.map(e=>(0,Q.jsx)(_,{value:e.value,children:e.label},e.value))})]})]}),e.duration===`repeating`&&(0,Q.jsx)(`div`,{className:`-mt-4`,children:(0,Q.jsxs)(A,{"data-invalid":!!r.durationInMonths||void 0,children:[(0,Q.jsxs)(F,{"data-invalid":!!r.durationInMonths||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.durationInMonths||void 0,"data-testid":`duration-months-input`,type:`number`,value:e.durationInMonths===0?``:String(e.durationInMonths),onChange:e=>{let n=Number(e.target.value);t(e=>({...e,durationInMonths:Number.isNaN(n)?0:n}))},onKeyDown:()=>n(`durationInMonths`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:e.durationInMonths===1?`month`:`months`})})]}),r.durationInMonths&&(0,Q.jsx)(E,{children:r.durationInMonths})]})})]}),e.type===`free_months`&&(0,Q.jsxs)(A,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(O,{htmlFor:`retention-free-months`,children:`Free months`}),(0,Q.jsxs)(F,{"data-invalid":!!r.amount||void 0,children:[(0,Q.jsx)(M,{"aria-invalid":!!r.amount||void 0,id:`retention-free-months`,type:`number`,value:e.freeMonths===0?``:String(e.freeMonths),onChange:e=>{let n=Number(e.target.value);t(e=>({...e,freeMonths:Number.isNaN(n)?0:n}))},onKeyDown:()=>n(`amount`)}),(0,Q.jsx)(N,{align:`inline-end`,children:(0,Q.jsx)(j,{children:e.freeMonths===1?`month`:`months`})})]}),r.amount&&(0,Q.jsx)(E,{children:r.amount})]})]})]})]})]})})},nt=({id:e})=>{let{updateRoute:t}=w(),{siteData:n}=X(),{data:{tiers:r=[]}={}}=fe(),{data:{offers:i=[]}={},isFetched:d,isFetching:p}=u(),{mutateAsync:m}=f(),{mutateAsync:h}=l(),g=c(),[_,v]=(0,Z.useState)(``),y=e===`monthly`?`monthly`:`yearly`,b=y===`monthly`?`Monthly retention`:`Yearly retention`,x=y===`monthly`?`month`:`year`,S=pe(r||[]),C=(0,Z.useMemo)(()=>i.filter(e=>e.redemption_type===`retention`&&e.cadence===x).sort((e,t)=>{let n=e.created_at?new Date(e.created_at).getTime():0;return(t.created_at?new Date(t.created_at).getTime():0)-n}),[i,x]),T=(0,Z.useMemo)(()=>C.find(e=>e.status===`active`)||null,[C]),E=C[0]||null,D=T||E,O=(0,Z.useMemo)(()=>C.reduce((e,t)=>e+(t.redemption_count||0),0),[C]),k=(0,Z.useMemo)(()=>C.map(e=>e.id),[C]),A=(0,Z.useMemo)(()=>C.map(e=>e.last_redeemed).filter(e=>!!e).sort((e,t)=>new Date(t).getTime()-new Date(e).getTime())[0]||null,[C]),j=(0,Z.useMemo)(()=>O===0||k.length===0?null:je(k),[k,O]),[M,N]=(0,Z.useState)(20),[P,F]=(0,Z.useState)(1),[I,L]=(0,Z.useState)(null),{formState:R,setFormState:z,updateForm:B,handleSave:V,saveState:H,okProps:U,errors:W,clearError:G}=s({initialState:qe(y),savingDelay:500,onSave:async()=>{let e=!1,t=Xe({formState:R,lastPercentAmount:M,lastFreeMonths:P}),n=Qe(Ze(D))!==Qe(t),r=R.enabled?`active`:`archived`,i=R.displayTitle||``,a=R.displayDescription||``,o=D?i!==(D.display_title||``)||a!==(D.display_description||``):i!==``||a!==``,s=qe(y),c=!R.enabled&&!D&&et(R,s),l=async n=>{let r=crypto.getRandomValues(new Uint32Array(1))[0].toString(16).padStart(8,`0`),o=Ie(t,r);await m({name:o,code:r,display_title:i,display_description:a,cadence:x,amount:t.amount,duration:t.duration,duration_in_months:t.duration===`repeating`?t.durationInMonths:null,currency:null,status:n,redemption_type:`retention`,tier:null,type:t.type,currency_restriction:!1}),e=!0},u=async()=>{e&&await g()};if(!(!D&&!R.enabled&&!c)){if(n){!R.enabled&&T&&(await h({...T,status:`archived`}),e=!0),await l(r),await u();return}if(D){let t=D.status!==r;(o||t)&&(await h({...D,display_title:i,display_description:a,status:r}),e=!0),await u();return}(R.enabled||c)&&await l(r),await u()}},onSaveError:e=>{let t=`Please try again later`;e instanceof a&&e.data&&e.data.errors[0]&&(t=e.data.errors[0].context||e.data.errors[0].message||t),o.dismiss(),o.error(`Failed to save offer`,{description:t})},onValidate:()=>{let e={};return R.enabled?(R.type===`percent`&&((R.percentAmount<1||R.percentAmount>100)&&(e.amount=`Enter an amount between 1 and 100%.`),R.duration===`repeating`&&!$e(R.durationInMonths)&&(e.durationInMonths=We)),R.type===`free_months`&&($e(R.freeMonths)||(e.amount=We)),e):e}}),K=`${e}:${D?.id||`none`}`;(0,Z.useEffect)(()=>{!d||p||H===`unsaved`||I===K||(z(()=>Ye(D,y)),L(K))},[y,K,D,d,I,p,H,z]),(0,Z.useEffect)(()=>{R.percentAmount>0&&N(R.percentAmount)},[R.percentAmount]),(0,Z.useEffect)(()=>{R.freeMonths>0&&F(R.freeMonths)},[R.freeMonths]);let q=()=>{t(`offers/edit`)},J=(0,Q.jsx)(tt,{cadence:y,clearError:G,errors:W,formState:R,lastRedeemed:A,membersFilterUrl:j,redemptions:O,updateForm:B}),ee=async()=>{try{await V({force:!0})&&q()}catch{}},te=(0,Z.useMemo)(()=>{let e=Xe({formState:R,lastPercentAmount:M,lastFreeMonths:P}),t=S.find(e=>x===`month`?e.monthly_price:e.yearly_price);return{enabled:R.enabled,name:`${y} retention`,code:`${y}-retention`,displayTitle:R.displayTitle||``,displayDescription:R.displayDescription||``,type:e.type,cadence:x,amount:e.amount,duration:e.duration,durationInMonths:e.durationInMonths,currency:``,status:`active`,tierId:t?.id||``,redemptionType:`retention`}},[S,y,R,P,M,x]);(0,Z.useEffect)(()=>{if(!n.url){v(``);return}let e=Ce(te,n.url);v(e)},[te,n.url]);let ne=(0,Q.jsx)(ye,{href:_||``,portalParent:`offers`});return(0,Q.jsx)(ve,{backDropClick:!1,cancelLabel:`Cancel`,dirty:H===`unsaved`,height:`full`,okLabel:U.label||`Save`,okVariant:U.variant,preview:ne,previewToolbarBreadcrumbs:(0,Q.jsx)(be,{current:b,label:`Offers`,onBack:q}),sidebar:J,size:`lg`,testId:`retention-offer-modal`,title:`Offer`,width:1140,onCancel:q,onClose:()=>t(`offers`),onOk:ee})},rt=({id:e})=>{let{updateRoute:t}=w(),{data:{offers:n=[]}={}}=d(e||``),[r,i]=(0,Z.useState)(),[a,o]=(0,Z.useState)(``),{siteData:s}=X();(0,Z.useEffect)(()=>{if(n.length>0){let e=n[0],t=`${de(s)}${e?.code}`;o(t),i(e)}},[n,s]);let[c,l]=(0,Z.useState)(!1),u=()=>{let e=``;switch(r?.type){case`percent`:e=r?.amount+`% discount`;break;case`fixed`:e=p(Se(r?.amount),{maximumFractionDigits:2})+` `+r?.currency+` discount`;break;case`trial`:e=r?.amount+` days free trial`;break;default:break}return`${encodeURIComponent(r?.name||``)} — Check out ${encodeURIComponent(e)} on:`};return(0,Q.jsx)(S,{animate:!1,backDropClick:!1,footer:!1,height:`full`,size:`lg`,testId:`offer-success-modal`,topRightContent:`close`,width:1140,onClose:()=>{t(`offers`)},children:(0,Q.jsxs)(`div`,{className:`-mt-6 flex h-full flex-col items-center justify-center text-center`,children:[(0,Q.jsx)(be,{className:`absolute top-5 left-6`,current:r?.name||``,label:`Offers`,onBack:()=>t(`offers/edit`)}),(0,Q.jsx)(ae,{className:`-mt-4 size-10 text-grey-700`}),(0,Q.jsx)(`h1`,{className:`mt-6 text-4xl`,children:`Your new offer is live!`}),(0,Q.jsx)(`p`,{className:`mt-3 max-w-[510px] text-[1.6rem]`,children:`You can share the link anywhere. In your newsletter, social media, a podcast, or in-person. It all just works.`}),(0,Q.jsxs)(`div`,{className:`mt-8 flex w-full max-w-md flex-col gap-8`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2`,children:[(0,Q.jsx)(Y,{name:`offer-url`,type:`url`,value:a,disabled:!0}),(0,Q.jsx)(J,{className:`w-full`,type:`button`,onClick:async()=>{await navigator.clipboard.writeText(a),l(!0),setTimeout(()=>l(!1),2e3)},children:c?`Copied!`:`Copy link`})]}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4 text-sm font-medium before:h-px before:grow before:bg-grey-300 before:content-[""] after:h-px after:grow after:bg-grey-300 after:content-[""] dark:before:bg-grey-800 dark:after:bg-grey-800`,children:`OR`}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(J,{"aria-label":`Share on X`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`https://twitter.com/intent/tweet?url=${encodeURI(a)}&text=${u()}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`twitter-x`})}),(0,Q.jsx)(J,{"aria-label":`Share on Facebook`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURI(a)}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`facebook`})}),(0,Q.jsx)(J,{"aria-label":`Share on LinkedIn`,className:`h-8 flex-1`,size:`sm`,type:`button`,variant:`outline`,onClick:()=>{window.open(`http://www.linkedin.com/shareArticle?mini=true&url=${encodeURI(a)}&title=${u()}`,`_blank`)},children:(0,Q.jsx)(he,{className:`size-3.5!`,name:`linkedin`})})]})]})]})})},it=(e,t)=>e.find(e=>e.redemption_type===`retention`&&e.cadence===t&&e.status===`active`)||null,at=(e,t)=>e.reduce((e,n)=>n.redemption_type!==`retention`||n.cadence!==t?e:e+(n.redemption_count||0),0),ot=(e,t)=>e.filter(e=>e.redemption_type===`retention`&&e.cadence===t).map(e=>e.id),st=(e,t)=>{let n=e.filter(e=>e.redemption_type===`retention`&&e.cadence===t&&e.created_at).map(e=>new Date(e.created_at).getTime()).filter(e=>!Number.isNaN(e));return n.length===0?null:new Date(Math.max(...n)).toISOString()},ct=e=>e.type===`percent`&&e.amount===100&&e.duration===`repeating`,lt=e=>{if(!e)return null;if(ct(e)){let t=e.duration_in_months||0,n=t===1?`month`:`months`;return`${p(t)} ${n} free`}return e.type===`percent`?`${p(e.amount)}% OFF`:null},ut=e=>{if(!e)return null;if(ct(e))return``;if(e.duration===`once`)return`First payment`;if(e.duration===`repeating`&&e.duration_in_months){let t=e.duration_in_months===1?`month`:`months`;return`For ${p(e.duration_in_months)} ${t}`}return e.duration===`forever`?`Forever`:null},dt=e=>{let t=it(e,`month`),n=it(e,`year`),r=ot(e,`month`),i=ot(e,`year`),a=at(e,`month`),o=at(e,`year`);return[{id:`monthly`,name:`Monthly retention`,description:`Applied to monthly plans`,terms:lt(t),termsDetail:ut(t),redemptionOfferIds:r,redemptions:a,status:t?`active`:`inactive`,createdAt:st(e,`month`)},{id:`yearly`,name:`Yearly retention`,description:`Applied to annual plans`,terms:lt(n),termsDetail:ut(n),redemptionOfferIds:i,redemptions:o,status:n?`active`:`inactive`,createdAt:st(e,`year`)}]},ft=e=>e===`month`?`monthly`:`yearly`,pt=e=>e===`once`?`First payment`:e===`repeating`?`Repeating`:`Forever`,mt=(e,t,n,r,i)=>{let a=``,o=n===`month`?i?.monthly_price??0:i?.yearly_price??0,s=o,c=e=>parseFloat(e.toFixed(2)),l=e=>p(c(Se(e)),{maximumFractionDigits:2}),u=xe(r)+l(o);switch(e){case`percent`:a=`${p(t)}% off`,s=o-o*t/100;break;case`fixed`:a=`${l(t)} ${r} off`,s=o-t;break;case`trial`:a=`${p(t)} days free`,u=``;break;default:break}s<0&&(s=0);let d=xe(r)+l(s);return{discountOffer:a,originalPriceWithCurrency:u,updatedPriceWithCurrency:d}},ht=({showArchived:e,setShowArchived:t,sortOption:n,sortDirection:r,onSortChange:i,onDirectionChange:a})=>(0,Q.jsxs)(ne,{children:[(0,Q.jsx)(ie,{asChild:!0,children:(0,Q.jsx)(J,{"aria-label":`Filter options`,className:`text-muted-foreground hover:text-foreground`,size:`icon`,type:`button`,variant:`ghost`,children:(0,Q.jsx)(oe,{size:16,strokeWidth:1.5})})}),(0,Q.jsxs)(re,{align:`end`,className:`z-[9999] min-w-[200px] normal-case`,children:[(0,Q.jsx)(se,{className:`text-xs tracking-wide text-muted-foreground uppercase`,children:`Sort by`}),(0,Q.jsxs)(ue,{value:n,onValueChange:i,children:[(0,Q.jsx)(ce,{value:`date-added`,children:`Date added`}),(0,Q.jsx)(ce,{value:`name`,children:`Name`}),(0,Q.jsx)(ce,{value:`redemptions`,children:`Redemptions`})]}),(0,Q.jsxs)(K,{onSelect:a,children:[r===`asc`?(0,Q.jsx)(ee,{className:`size-3`}):(0,Q.jsx)(q,{className:`size-3`}),r===`asc`?`Ascending`:`Descending`]}),(0,Q.jsx)(le,{}),(0,Q.jsx)(te,{checked:e,onCheckedChange:e=>t(!!e),children:`Show archived`})]})]}),gt=({offer:e,onClick:t})=>{let n=e.redemptions>0&&e.redemptionOfferIds.length>0?je(e.redemptionOfferIds):void 0;return(0,Q.jsxs)(z,{"data-testid":`retention-offer-item`,children:[(0,Q.jsx)(V,{className:`sticky left-0 z-10 bg-background p-0`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:e.terms?(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium uppercase`,children:e.terms}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.termsDetail})]}):(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`–`})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`–`})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:n?(0,Q.jsx)(`a`,{className:`block cursor-pointer p-5 hover:underline`,"data-testid":`retention-redemptions-link-${e.id}`,href:n,children:p(e.redemptions)}):(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,"data-testid":`retention-redemptions-link-${e.id}`,type:`button`,onClick:t,children:p(e.redemptions)})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:t,children:e.status===`active`?(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`success`,children:`Active`}):(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`secondary`,children:`Inactive`})})})]})},_t=({archived:e,offer:t,tier:n,onClick:r})=>{let{discountOffer:i,originalPriceWithCurrency:a,updatedPriceWithCurrency:o}=mt(t.type,t.amount,t.cadence,t.currency||`USD`,n);return(0,Q.jsxs)(z,{className:e?`opacity-60`:void 0,"data-testid":`offer-item`,children:[(0,Q.jsx)(V,{className:`sticky left-0 z-10 bg-background p-0`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:t.name}),(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[n.name,` `,ft(t.cadence)]})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:(0,Q.jsxs)(h,{gap:`none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium uppercase`,children:i}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:t.type===`trial`?`Trial period`:pt(t.duration)})]})})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsxs)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:o}),` `,t.type===`trial`?null:(0,Q.jsx)(`span`,{className:`relative text-sm text-muted-foreground before:absolute before:-inset-x-0.5 before:top-1/2 before:rotate-[-20deg] before:border-t before:content-[""]`,children:a})]})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:t.redemption_count>0&&t.id?(0,Q.jsx)(`a`,{className:`block cursor-pointer p-5 hover:underline`,href:Me(t.id),children:p(t.redemption_count)}):(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:p(t.redemption_count)})}),(0,Q.jsx)(V,{className:`p-0 whitespace-nowrap`,children:(0,Q.jsx)(`button`,{className:`block w-full cursor-pointer p-5 text-left`,type:`button`,onClick:r,children:e?(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`secondary`,children:`Archived`}):(0,Q.jsx)(G,{className:`rounded-full uppercase`,variant:`success`,children:`Active`})})})]})},vt=e=>e.offer.name,yt=e=>e.kind===`retention`?e.offer.redemptions:e.offer.redemption_count,bt=e=>e.kind===`retention`?e.offer.createdAt:e.offer.created_at||null,xt=(e,t,n)=>{let r=n===`desc`?-1:1;return[...e].sort((e,n)=>{let i;switch(t){case`name`:i=vt(e).localeCompare(vt(n));break;case`redemptions`:i=yt(e)-yt(n);break;default:{let t=bt(e),r=bt(n);if(!t&&!r)i=0;else if(!t)return 1;else if(r)i=new Date(t).getTime()-new Date(r).getTime();else return-1;break}}return(i||vt(e).localeCompare(vt(n)))*r})},St=()=>{let{updateRoute:e}=w(),{data:{offers:t=[]}={}}=u(),{data:{tiers:n}={}}=fe(),r=t.filter(e=>e.redemption_type===`signup`),i=dt(t),{sortingState:a,setSortingState:s}=ge(),c=a?.find(e=>e.type===`offers`),{offersShowArchived:l,setOffersShowArchived:d}=_e(),f=c?.option||`date-added`,p=c?.direction||`desc`,g=t=>{t&&e(`offers/edit/${t}`)},_=t=>{e(`offers/edit/retention/${t}`)},v=pe(n||[]),y=r.filter(e=>{let t=n?.find(t=>t.id===e?.tier?.id),r=e.status===`active`&&t&&t.active===!0,i=e.status===`archived`||t&&t.active===!1;return!!(r||l&&i)}),b=xt([...i.map(e=>({kind:`retention`,offer:e})),...y.map(e=>({kind:`signup`,offer:e}))],f,p),x=e=>{s?.([{type:`offers`,option:e,direction:p}])},C=()=>{s?.([{type:`offers`,option:f,direction:p===`asc`?`desc`:`asc`}])},T=e=>{let t=n?.find(t=>t.id===e?.tier?.id);return e.status===`archived`||t?.active===!1};return(0,Q.jsx)(S,{animate:!1,backDropClick:!1,cancelLabel:``,footer:!1,height:`full`,size:`lg`,testId:`offers-modal`,title:`Offers`,topRightContent:(0,Q.jsxs)(m,{gap:`md`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>{e(`offers`)},children:`Close`}),(0,Q.jsx)(J,{type:`button`,onClick:()=>{v.length===0?o.info(`You must have an active tier to create an offer.`):e(`offers/new`)},children:`New offer`})]}),width:1140,onClose:()=>{e(`offers`)},children:(0,Q.jsx)(h,{className:`h-full pt-8`,children:(0,Q.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Q.jsxs)(U,{className:`m-0 min-w-[900px]`,children:[(0,Q.jsxs)(`colgroup`,{children:[(0,Q.jsx)(`col`,{className:`w-[25%]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[200px]`}),(0,Q.jsx)(`col`,{className:`w-[220px]`})]}),(0,Q.jsx)(H,{children:(0,Q.jsxs)(z,{children:[(0,Q.jsx)(R,{className:`sticky left-0 z-10 h-auto bg-background p-0 pb-2.5 pl-5 uppercase`,children:`Name`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Terms`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Price`}),(0,Q.jsx)(R,{className:`h-auto p-0 pb-2.5 pl-5 uppercase`,children:`Redemptions`}),(0,Q.jsx)(R,{className:`h-auto p-0 px-5 pb-2.5 uppercase`,children:(0,Q.jsxs)(m,{align:`center`,justify:`between`,children:[`Status`,(0,Q.jsx)(ht,{setShowArchived:d,showArchived:l,sortDirection:p,sortOption:f,onDirectionChange:C,onSortChange:x})]})})]})}),(0,Q.jsx)(B,{"data-testid":`offers-table-body`,children:b.map(e=>{if(e.kind===`retention`)return(0,Q.jsx)(gt,{offer:e.offer,onClick:()=>_(e.offer.id)},`retention-${e.offer.id}`);let t=e.offer,r=n?.find(e=>e.id===t?.tier?.id);if(!r)return null;let i=T(t);return(0,Q.jsx)(_t,{archived:i,offer:t,tier:r,onClick:()=>g(t.id)},`signup-${t.id}`)})})]})})})})},Ct=({route:e})=>{if(e===`offers/new`)return(0,Q.jsx)(ke,{});if(e.startsWith(`offers/edit/retention/`)&&e.length>22){let t=e.split(`/`).pop();return(0,Q.jsx)(nt,{id:t||``})}else if(e===`offers/edit/retention/`||e===`offers/edit/retention`)return(0,Q.jsx)(St,{});else if(e.startsWith(`offers/edit/`)&&e.length>12){let t=e.split(`/`).pop();return(0,Q.jsx)(ze,{id:t||``})}else if(e.startsWith(`offers/success/`)&&e.length>15){let t=e.split(`/`).pop();return(0,Q.jsx)(rt,{id:t||``})}else if(e===`offers/edit`||e===`offers/edit/`)return(0,Q.jsx)(St,{})},wt=()=>{let{route:e}=w();return(0,Q.jsx)(Ct,{route:e})};export{wt as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{g as r}from"./chunk-KS7C4IRE-DG9HTHQ3.js";import{a as i,t as a}from"./router-provider-DSQfprxH.js";import{Dn as o,Pr as s,Tn as c,ba as l,jn as u,n as d,r as f,rs as p,vo as m,ws as h}from"./index-BHy2DZX-.js";import{t as g}from"./share-modal-ClIyPzc5.js";var _=e(t(),1),v=``+new URL(`logo-loader-dark-CuSPz-zc.mp4`,import.meta.url).href,y=``+new URL(`logo-loader-88VPEpXE.mp4`,import.meta.url).href,b=n();function x(){return(0,b.jsxs)(`div`,{className:`relative mb-6 size-20`,children:[(0,b.jsx)(`video`,{"aria-hidden":`true`,className:`size-20 dark:hidden`,height:80,preload:`metadata`,role:`presentation`,tabIndex:-1,width:80,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,children:(0,b.jsx)(`source`,{src:y,type:`video/mp4`})}),(0,b.jsx)(`video`,{"aria-hidden":`true`,className:`hidden size-20 dark:block`,height:80,preload:`metadata`,role:`presentation`,tabIndex:-1,width:80,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,children:(0,b.jsx)(`source`,{src:v,type:`video/mp4`})}),(0,b.jsx)(`div`,{className:`pointer-events-none absolute inset-0 hidden bg-[hsl(216deg_11%_70%/1%)] dark:block`})]})}function S({complete:e,id:t,isBeforeNext:n,isLast:r,isNext:i,onClick:a,step:o}){let s=o.icon;return(0,b.jsxs)(`button`,{className:`group ${i?`relative z-10 -mx-8 flex w-[calc(100%+64px)] items-center justify-between rounded-md bg-background px-8 py-6 text-left shadow-[0_1px_0_rgba(17,17,26,0.05),0_0_8px_rgba(17,17,26,0.10)] transition-none dark:ring-1 dark:ring-border ${r?`-mb-[18px]`:`mb-1.5`}`:`relative flex w-full items-center justify-between bg-transparent py-6 text-left ${r||n||i?``:`after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:content-['']`}`}`,"data-testid":`onboarding-step-${o.id}`,id:t,type:`button`,onClick:a,children:[(0,b.jsxs)(`span`,{className:`flex min-w-0 items-center ${e?`opacity-20 group-hover:opacity-25`:`group-hover:opacity-90`}`,children:[(0,b.jsx)(s,{className:`mr-4 size-5 shrink-0 text-purple`}),(0,b.jsxs)(`span`,{className:`min-w-0 text-left`,children:[(0,b.jsx)(`span`,{className:`block truncate pr-8 text-[16px] leading-[1.3] font-bold text-foreground`,children:o.title}),i&&(0,b.jsx)(`span`,{className:`mt-1 block pr-8 text-[15px] leading-[1.4] text-muted-foreground`,children:o.description})]})]}),(0,b.jsx)(`span`,{className:`flex shrink-0 items-center transition-transform group-hover:translate-x-[5px] ${e?`text-green`:`text-purple`}`,children:e?(0,b.jsx)(p,{className:`size-5`}):(0,b.jsx)(h,{className:`size-3.5`})})]})}function C({allStepsCompleted:e,completedSteps:t,nextStep:n,onComplete:r,onDismiss:i,onStepClick:a,siteTitle:o}){let c=new Set(t);return(0,b.jsx)(`main`,{className:`relative flex min-h-screen flex-col items-center justify-center px-6 py-8`,children:(0,b.jsxs)(`section`,{className:`mt-[-48px] flex w-full flex-col items-center`,"data-test-dashboard":`onboarding-checklist`,"data-testid":`onboarding-checklist`,children:[(0,b.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center`,children:[(0,b.jsx)(x,{}),e?(0,b.jsx)(`h1`,{className:`text-[32px] leading-[1.15] font-bold tracking-normal text-foreground max-[480px]:text-[24px]`,children:`You're all set.`}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`h1`,{className:`text-[32px] leading-[1.15] font-bold tracking-normal text-foreground max-[480px]:text-[24px]`,children:`Let's get started!`}),(0,b.jsxs)(`p`,{className:`mt-2 mb-0 text-[15px] text-muted-foreground max-[480px]:m-0 max-[480px]:text-[14px]`,children:[`Welcome! It's time to set up `,o,`.`]})]})]}),(0,b.jsxs)(`div`,{className:`w-full max-w-[540px] rounded-md border border-border bg-background px-6 pt-4 pb-1`,children:[(0,b.jsxs)(`div`,{className:`mt-[-12px] flex items-center justify-between py-6 ${n===`customize-design`?`border-b-0`:`border-b border-border`}`,children:[(0,b.jsxs)(`span`,{className:`flex min-w-0 items-center opacity-20`,children:[(0,b.jsx)(l,{className:`mr-4 size-5 shrink-0 text-purple`}),(0,b.jsx)(`span`,{className:`truncate pr-8 text-[16px] leading-[1.3] font-bold text-foreground`,children:`Start a new Ghost publication`})]}),(0,b.jsx)(`span`,{className:`shrink-0 text-green`,children:(0,b.jsx)(p,{className:`size-5`})})]}),f.map((e,t)=>(0,b.jsx)(S,{complete:c.has(e.id),id:`ob-${e.id}`,isBeforeNext:f[t+1]?.id===n,isLast:t===f.length-1,isNext:n===e.id,step:e,onClick:()=>a(e.id)},e.id))]}),e&&(0,b.jsx)(s,{className:`mt-6 h-auto w-full max-w-[540px] p-3 text-[16px] max-[480px]:text-[15px]`,"data-testid":`onboarding-complete`,id:`ob-completed`,type:`button`,onClick:r,children:`Explore your dashboard`}),(0,b.jsxs)(`p`,{className:`mt-8 mb-0 text-[15px] text-muted-foreground max-[480px]:text-[14px]`,children:[`More questions? Check out our`,` `,(0,b.jsx)(s,{className:`h-auto p-0 align-baseline text-[15px] text-green hover:text-green/90 max-[480px]:text-[14px]`,variant:`link`,asChild:!0,children:(0,b.jsx)(`a`,{href:`https://ghost.org/help?utm_source=admin&utm_campaign=onboarding`,id:`ob-help-center`,rel:`noreferrer`,target:`_blank`,children:`Help Center`})}),`.`]}),!e&&(0,b.jsx)(s,{className:`mt-6 h-[38px] overflow-hidden px-3.5 py-px text-[15px] font-normal whitespace-nowrap text-muted-foreground hover:border-gray-300 hover:text-foreground`,"data-testid":`onboarding-skip`,id:`ob-skip`,type:`button`,variant:`outline`,onClick:i,children:`Skip onboarding`})]})})}function w({description:e,imageUrl:t,onOpenChange:n,open:r,siteTitle:i,siteUrl:a}){let o=encodeURIComponent(a),c=[{href:`https://twitter.com/intent/tweet?url=${o}`,id:`ob-share-on-x`,label:`Share your publication on X`,service:`x`},{href:`https://threads.net/intent/post?text=${o}`,id:`ob-share-on-threads`,label:`Share your publication on Threads`,service:`threads`},{href:`https://www.facebook.com/sharer/sharer.php?u=${o}`,id:`ob-share-on-fb`,label:`Share your publication on Facebook`,service:`facebook`},{href:`https://www.linkedin.com/feed/?shareActive=true&text=${o}`,id:`ob-share-on-li`,label:`Share your publication on LinkedIn`,service:`linkedin`}];return(0,b.jsx)(g.Root,{open:r,onOpenChange:n,children:(0,b.jsxs)(g.Content,{className:`dark:bg-surface-elevated`,"data-test-modal":`onboarding-share`,"data-testid":`onboarding-share-modal`,children:[(0,b.jsxs)(g.Header,{className:`flex-row items-center justify-between gap-4 space-y-0 text-left`,children:[(0,b.jsx)(g.Title,{className:`text-2xl`,children:`Share your publication`}),(0,b.jsx)(g.CloseButton,{id:`ob-close-share-modal`,onClick:()=>n(!1)})]}),(0,b.jsxs)(g.Preview,{className:`rounded-lg bg-card`,href:a,children:[t?(0,b.jsx)(`div`,{className:`aspect-video bg-cover bg-center`,style:{backgroundImage:`url(${t})`}}):(0,b.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-muted text-muted-foreground`,children:(0,b.jsx)(m,{className:`size-8`})}),(0,b.jsxs)(`div`,{className:`p-5`,children:[(0,b.jsx)(`div`,{className:`text-lg font-semibold`,children:i}),e&&(0,b.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e})]})]}),(0,b.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Set your publication's cover image and description in`,` `,(0,b.jsx)(s,{className:`h-auto p-0 align-baseline text-sm text-green hover:text-green/90`,variant:`link`,asChild:!0,children:(0,b.jsx)(`a`,{href:`#/settings/design/edit?ref=setup`,id:`ob-share-modal-design-settings`,children:`Design settings`})}),`.`]}),(0,b.jsxs)(g.Footer,{children:[(0,b.jsx)(g.SocialLinks,{links:c}),(0,b.jsx)(g.CopyButton,{className:`ml-0! grow cursor-pointer`,copyURL:a,"data-testid":`onboarding-copy-link`,icon:`link`,id:`ob-copy-publication-link`,label:`Copy link`})]})]})})}function T(e){return e&&/^\/analytics(?:\/|\?|$)/.test(e)?e:`/analytics`}function E(){let e=i(),[t]=r(),n=T(t.get(`returnTo`)),s=d(),l=u(),p=c(),m=(0,_.useRef)(!1),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(!1),x=String(o(l.data?.settings,`title`)||p.data?.site.title||`your publication`),S=String(o(l.data?.settings,`description`)||p.data?.site.description||``),E=String(o(l.data?.settings,`cover_image`)||``),D=p.data?.site.url||`/`,{allStepsCompleted:O,completeChecklist:k,completedSteps:A,dismissChecklist:j,shouldShowChecklist:M,isLoading:N,markStepCompleted:P,nextStep:F}=s;if(N||p.isLoading||h||m.current)return null;if(!M)return(0,b.jsx)(a,{to:n,replace:!0});let I=async t=>{m.current=!0,g(!0);try{await t(),e(n,{replace:!0})}catch(e){m.current=!1,g(!1),console.error(e)}},L=async t=>{if(t===`share-publication`){await P(t),y(!0);return}await P(t);let n=f.find(({id:e})=>e===t);n?.route&&e(n.route)};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(C,{allStepsCompleted:O,completedSteps:A,nextStep:F,siteTitle:x,onComplete:()=>{I(k)},onDismiss:()=>{I(j)},onStepClick:e=>{L(e)}}),(0,b.jsx)(w,{description:S,imageUrl:E,open:v,siteTitle:x,siteUrl:D,onOpenChange:y})]})}export{E as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{g as r}from"./chunk-KS7C4IRE-DG9HTHQ3.js";import{a as i,t as a}from"./router-provider-DSQfprxH.js";import{Dn as o,Pr as s,Tn as c,ba as l,jn as u,n as d,r as f,rs as p,vo as m,ws as h}from"./index-DUXM0NlS.js";import{t as g}from"./share-modal-BNj14g79.js";var _=e(t(),1),v=``+new URL(`logo-loader-dark-CuSPz-zc.mp4`,import.meta.url).href,y=``+new URL(`logo-loader-88VPEpXE.mp4`,import.meta.url).href,b=n();function x(){return(0,b.jsxs)(`div`,{className:`relative mb-6 size-20`,children:[(0,b.jsx)(`video`,{"aria-hidden":`true`,className:`size-20 dark:hidden`,height:80,preload:`metadata`,role:`presentation`,tabIndex:-1,width:80,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,children:(0,b.jsx)(`source`,{src:y,type:`video/mp4`})}),(0,b.jsx)(`video`,{"aria-hidden":`true`,className:`hidden size-20 dark:block`,height:80,preload:`metadata`,role:`presentation`,tabIndex:-1,width:80,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,children:(0,b.jsx)(`source`,{src:v,type:`video/mp4`})}),(0,b.jsx)(`div`,{className:`pointer-events-none absolute inset-0 hidden bg-[hsl(216deg_11%_70%/1%)] dark:block`})]})}function S({complete:e,id:t,isBeforeNext:n,isLast:r,isNext:i,onClick:a,step:o}){let s=o.icon;return(0,b.jsxs)(`button`,{className:`group ${i?`relative z-10 -mx-8 flex w-[calc(100%+64px)] items-center justify-between rounded-md bg-background px-8 py-6 text-left shadow-[0_1px_0_rgba(17,17,26,0.05),0_0_8px_rgba(17,17,26,0.10)] transition-none dark:ring-1 dark:ring-border ${r?`-mb-[18px]`:`mb-1.5`}`:`relative flex w-full items-center justify-between bg-transparent py-6 text-left ${r||n||i?``:`after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border after:content-['']`}`}`,"data-testid":`onboarding-step-${o.id}`,id:t,type:`button`,onClick:a,children:[(0,b.jsxs)(`span`,{className:`flex min-w-0 items-center ${e?`opacity-20 group-hover:opacity-25`:`group-hover:opacity-90`}`,children:[(0,b.jsx)(s,{className:`mr-4 size-5 shrink-0 text-purple`}),(0,b.jsxs)(`span`,{className:`min-w-0 text-left`,children:[(0,b.jsx)(`span`,{className:`block truncate pr-8 text-[16px] leading-[1.3] font-bold text-foreground`,children:o.title}),i&&(0,b.jsx)(`span`,{className:`mt-1 block pr-8 text-[15px] leading-[1.4] text-muted-foreground`,children:o.description})]})]}),(0,b.jsx)(`span`,{className:`flex shrink-0 items-center transition-transform group-hover:translate-x-[5px] ${e?`text-green`:`text-purple`}`,children:e?(0,b.jsx)(p,{className:`size-5`}):(0,b.jsx)(h,{className:`size-3.5`})})]})}function C({allStepsCompleted:e,completedSteps:t,nextStep:n,onComplete:r,onDismiss:i,onStepClick:a,siteTitle:o}){let c=new Set(t);return(0,b.jsx)(`main`,{className:`relative flex min-h-screen flex-col items-center justify-center px-6 py-8`,children:(0,b.jsxs)(`section`,{className:`mt-[-48px] flex w-full flex-col items-center`,"data-test-dashboard":`onboarding-checklist`,"data-testid":`onboarding-checklist`,children:[(0,b.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center`,children:[(0,b.jsx)(x,{}),e?(0,b.jsx)(`h1`,{className:`text-[32px] leading-[1.15] font-bold tracking-normal text-foreground max-[480px]:text-[24px]`,children:`You're all set.`}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`h1`,{className:`text-[32px] leading-[1.15] font-bold tracking-normal text-foreground max-[480px]:text-[24px]`,children:`Let's get started!`}),(0,b.jsxs)(`p`,{className:`mt-2 mb-0 text-[15px] text-muted-foreground max-[480px]:m-0 max-[480px]:text-[14px]`,children:[`Welcome! It's time to set up `,o,`.`]})]})]}),(0,b.jsxs)(`div`,{className:`w-full max-w-[540px] rounded-md border border-border bg-background px-6 pt-4 pb-1`,children:[(0,b.jsxs)(`div`,{className:`mt-[-12px] flex items-center justify-between py-6 ${n===`customize-design`?`border-b-0`:`border-b border-border`}`,children:[(0,b.jsxs)(`span`,{className:`flex min-w-0 items-center opacity-20`,children:[(0,b.jsx)(l,{className:`mr-4 size-5 shrink-0 text-purple`}),(0,b.jsx)(`span`,{className:`truncate pr-8 text-[16px] leading-[1.3] font-bold text-foreground`,children:`Start a new Ghost publication`})]}),(0,b.jsx)(`span`,{className:`shrink-0 text-green`,children:(0,b.jsx)(p,{className:`size-5`})})]}),f.map((e,t)=>(0,b.jsx)(S,{complete:c.has(e.id),id:`ob-${e.id}`,isBeforeNext:f[t+1]?.id===n,isLast:t===f.length-1,isNext:n===e.id,step:e,onClick:()=>a(e.id)},e.id))]}),e&&(0,b.jsx)(s,{className:`mt-6 h-auto w-full max-w-[540px] p-3 text-[16px] max-[480px]:text-[15px]`,"data-testid":`onboarding-complete`,id:`ob-completed`,type:`button`,onClick:r,children:`Explore your dashboard`}),(0,b.jsxs)(`p`,{className:`mt-8 mb-0 text-[15px] text-muted-foreground max-[480px]:text-[14px]`,children:[`More questions? Check out our`,` `,(0,b.jsx)(s,{className:`h-auto p-0 align-baseline text-[15px] text-green hover:text-green/90 max-[480px]:text-[14px]`,variant:`link`,asChild:!0,children:(0,b.jsx)(`a`,{href:`https://ghost.org/help?utm_source=admin&utm_campaign=onboarding`,id:`ob-help-center`,rel:`noreferrer`,target:`_blank`,children:`Help Center`})}),`.`]}),!e&&(0,b.jsx)(s,{className:`mt-6 h-[38px] overflow-hidden px-3.5 py-px text-[15px] font-normal whitespace-nowrap text-muted-foreground hover:border-gray-300 hover:text-foreground`,"data-testid":`onboarding-skip`,id:`ob-skip`,type:`button`,variant:`outline`,onClick:i,children:`Skip onboarding`})]})})}function w({description:e,imageUrl:t,onOpenChange:n,open:r,siteTitle:i,siteUrl:a}){let o=encodeURIComponent(a),c=[{href:`https://twitter.com/intent/tweet?url=${o}`,id:`ob-share-on-x`,label:`Share your publication on X`,service:`x`},{href:`https://threads.net/intent/post?text=${o}`,id:`ob-share-on-threads`,label:`Share your publication on Threads`,service:`threads`},{href:`https://www.facebook.com/sharer/sharer.php?u=${o}`,id:`ob-share-on-fb`,label:`Share your publication on Facebook`,service:`facebook`},{href:`https://www.linkedin.com/feed/?shareActive=true&text=${o}`,id:`ob-share-on-li`,label:`Share your publication on LinkedIn`,service:`linkedin`}];return(0,b.jsx)(g.Root,{open:r,onOpenChange:n,children:(0,b.jsxs)(g.Content,{className:`dark:bg-surface-elevated`,"data-test-modal":`onboarding-share`,"data-testid":`onboarding-share-modal`,children:[(0,b.jsxs)(g.Header,{className:`flex-row items-center justify-between gap-4 space-y-0 text-left`,children:[(0,b.jsx)(g.Title,{className:`text-2xl`,children:`Share your publication`}),(0,b.jsx)(g.CloseButton,{id:`ob-close-share-modal`,onClick:()=>n(!1)})]}),(0,b.jsxs)(g.Preview,{className:`rounded-lg bg-card`,href:a,children:[t?(0,b.jsx)(`div`,{className:`aspect-video bg-cover bg-center`,style:{backgroundImage:`url(${t})`}}):(0,b.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-muted text-muted-foreground`,children:(0,b.jsx)(m,{className:`size-8`})}),(0,b.jsxs)(`div`,{className:`p-5`,children:[(0,b.jsx)(`div`,{className:`text-lg font-semibold`,children:i}),e&&(0,b.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e})]})]}),(0,b.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Set your publication's cover image and description in`,` `,(0,b.jsx)(s,{className:`h-auto p-0 align-baseline text-sm text-green hover:text-green/90`,variant:`link`,asChild:!0,children:(0,b.jsx)(`a`,{href:`#/settings/design/edit?ref=setup`,id:`ob-share-modal-design-settings`,children:`Design settings`})}),`.`]}),(0,b.jsxs)(g.Footer,{children:[(0,b.jsx)(g.SocialLinks,{links:c}),(0,b.jsx)(g.CopyButton,{className:`ml-0! grow cursor-pointer`,copyURL:a,"data-testid":`onboarding-copy-link`,icon:`link`,id:`ob-copy-publication-link`,label:`Copy link`})]})]})})}function T(e){return e&&/^\/analytics(?:\/|\?|$)/.test(e)?e:`/analytics`}function E(){let e=i(),[t]=r(),n=T(t.get(`returnTo`)),s=d(),l=u(),p=c(),m=(0,_.useRef)(!1),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(!1),x=String(o(l.data?.settings,`title`)||p.data?.site.title||`your publication`),S=String(o(l.data?.settings,`description`)||p.data?.site.description||``),E=String(o(l.data?.settings,`cover_image`)||``),D=p.data?.site.url||`/`,{allStepsCompleted:O,completeChecklist:k,completedSteps:A,dismissChecklist:j,shouldShowChecklist:M,isLoading:N,markStepCompleted:P,nextStep:F}=s;if(N||p.isLoading||h||m.current)return null;if(!M)return(0,b.jsx)(a,{to:n,replace:!0});let I=async t=>{m.current=!0,g(!0);try{await t(),e(n,{replace:!0})}catch(e){m.current=!1,g(!1),console.error(e)}},L=async t=>{if(t===`share-publication`){await P(t),y(!0);return}await P(t);let n=f.find(({id:e})=>e===t);n?.route&&e(n.route)};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(C,{allStepsCompleted:O,completedSteps:A,nextStep:F,siteTitle:x,onComplete:()=>{I(k)},onDismiss:()=>{I(j)},onStepClick:e=>{L(e)}}),(0,b.jsx)(w,{description:S,imageUrl:E,open:v,siteTitle:x,siteUrl:D,onOpenChange:y})]})}export{E as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./use-tinybird-query-GSa32hVw.js";import{i,o as a}from"./post-helpers-C5OQMBoi.js";import{m as o}from"./chunk-KS7C4IRE-DG9HTHQ3.js";import{a as s}from"./router-provider-DSQfprxH.js";import{f as c,p as l}from"./dist-Cb5RSHSg.js";import{a as u,i as d,t as f}from"./chart-helpers-CZElTGYL.js";import{a as p,n as m,o as h,t as g}from"./card-aUHX0hyR.js";import{c as _,l as v,n as y,o as b,r as ee,s as x,t as S,u as C}from"./data-list-CupF7bjM.js";import{t as w}from"./empty-indicator-WB1WgT9h.js";import{$a as te,Co as T,Kr as ne,Pr as E,Ps as D,So as O,Vs as re,Wr as ie,Xn as k,da as ae,ir as A,lo as j,or as M,qr as oe,u as se}from"./index-BHy2DZX-.js";import{t as ce}from"./disabled-sources-indicator-iMHrkyV3.js";import{n as N,r as P,t as F}from"./kpi-card-DOUnkZcN.js";import{t as I}from"./use-analytics-data-B-b4wNSC.js";import{a as L,n as R,r as z,t as B}from"./kpi-card-IHDo8Q56.js";import{n as le,r as ue,t as de}from"./post-analytics-header-ChzjXVPt.js";import{t as fe}from"./gift-links-CVuqLhsZ.js";import{r as pe,t as me}from"./gift-link-modal-zMtlJhLQ.js";import{n as he}from"./post-analytics-context-D0Mw-Pmv.js";import{n as ge,t as _e}from"./use-post-referrers-C2mXyrp-.js";import{a as V,o as H,r as U,t as W}from"./link-helpers-Bzkk68GD.js";import{n as ve,r as G}from"./kpi-helpers-CjUdECAK.js";var K=e(t(),1),q=n(),ye=({post:e,isNewsletterStatsLoading:t,isWebShown:n})=>{let{postId:r}=o(),i=s(),a=(0,K.useMemo)(()=>{let t=e.email?.opened_count||0,n=e.email?.email_count||0,r=e.count?.clicks||0;return{opened:t,clicked:r,openedRate:n>0?t/n:0,clickedRate:n>0?r/n:0,sent:n}},[e]),{data:u}=V({searchParams:{filter:`post_id:'${r}'`}}),d=(0,K.useMemo)(()=>U(u),[u]),f=[{datatype:`Clicked`,value:a.clickedRate,fill:`url(#gradientTeal)`,color:`var(--chart-teal)`},{datatype:`Opened`,value:a.openedRate,fill:`url(#gradientBlue)`,color:`var(--chart-blue)`}],w={percentage:{label:`Opened`},Average:{label:`Clicked`},"This newsletter":{label:`Opened`}},T=e.email_only||!n;return(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${T&&`col-span-2`}`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(te,{size:16,strokeWidth:1.5}),`Newsletter performance`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{i(`/posts/analytics/${r}/newsletter`)},children:`View more`})]}),t?(0,q.jsx)(m,{children:(0,q.jsx)(`div`,{className:`mx-auto flex min-h-[250px] items-center justify-center xl:size-full`,children:(0,q.jsx)(A,{})})}):(0,q.jsxs)(m,{className:`${T&&`grid grid-cols-2`}`,children:[(0,q.jsxs)(`div`,{className:`${T&&`border-r pr-6`}`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-blue)`,children:`Open rate`}),(0,q.jsx)(P,{value:l(a.openedRate)})]})}),(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-teal)`,children:`Click rate`}),(0,q.jsx)(P,{value:l(a.clickedRate)})]})})]}),!T&&(0,q.jsx)(k,{}),(0,q.jsx)(`div`,{className:`mx-auto my-6 h-[240px]`,children:(0,q.jsx)(H,{className:`pointer-events-none aspect-square h-[240px]`,config:w,data:f,tooltip:!1})})]}),(0,q.jsxs)(`div`,{className:`${T&&`pl-6`}`,children:[!T&&(0,q.jsx)(k,{}),(0,q.jsxs)(`div`,{className:T?``:`pt-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 ${T?`pb-3`:`py-3`}`,children:[(0,q.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`Top clicked links in this email`}),(0,q.jsx)(D,{children:`Members`})]}),d.length>0?(0,q.jsx)(S,{className:``,children:(0,q.jsx)(ee,{children:d.slice(0,T?10:5).map(e=>{let t=a.clicked>0?e.count/a.clicked:0;return(0,q.jsxs)(C,{children:[(0,q.jsx)(y,{style:{width:`${t?Math.round(t*100):0}%`}}),(0,q.jsx)(b,{children:(0,q.jsxs)(`div`,{className:`flex items-center space-x-2 overflow-hidden`,children:[(0,q.jsx)(j,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),(0,q.jsx)(`a`,{className:`block truncate font-medium hover:underline`,href:e.link.to,rel:`noreferrer`,target:`_blank`,title:e.link.to,children:W(e.link.to,!0)})]})}),(0,q.jsxs)(x,{children:[(0,q.jsx)(_,{children:c(e.count||0)}),(0,q.jsx)(v,{children:l(t)})]})]},e.link.link_id)})})}):(0,q.jsx)(`div`,{className:`py-20 text-center text-sm text-gray-700`,children:`You have no links in your post.`})]})]})]})]})},be=({chartData:e,range:t,isLoading:n,visitors:r,sourcesData:i,isNewsletterShown:a=!0})=>{let{postId:l}=o(),d=s(),{site:f}=I(),_=f.url,v=f.icon,y=(0,K.useMemo)(()=>i?i.reduce((e,t)=>e+Number(t.visits||0),0):0,[i]);return(0,q.jsx)(q.Fragment,{children:(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${!a&&`col-span-2`}`,"data-testid":`web-performance`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(O,{size:16,strokeWidth:1.5}),`Web performance`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{d(`/posts/analytics/${l}/web`)},children:`View more`})]}),(0,q.jsxs)(m,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,"data-testid":`unique-visitors`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-blue)`,children:`Unique visitors`}),(0,q.jsx)(P,{value:c(r)})]})}),(0,q.jsx)(k,{}),(0,q.jsx)(`div`,{className:`max-h-[288px] py-6 [&_.recharts-cartesian-axis-tick-value]:fill-gray-500`,children:n?(0,q.jsx)(`div`,{className:`flex h-[16vw] min-h-[240px] items-center justify-center`,children:(0,q.jsx)(A,{})}):(0,q.jsx)(u,{className:`aspect-auto h-[240px] w-full`,color:`var(--chart-blue)`,data:e||[],id:`visitors`,range:t,syncId:`overview-charts`})})]}),a&&(0,q.jsxs)(`div`,{className:a?`border-t pt-3`:`-mt-3`,children:[(0,q.jsx)(`div`,{children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[(0,q.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`How readers found this post`}),(0,q.jsx)(D,{children:`Visitors`})]})}),i&&i.length>0?(0,q.jsx)(G,{data:i,range:t,siteIcon:v,siteUrl:_,tableOnly:!0,topSourcesLimit:5,totalVisitors:y}):(0,q.jsx)(w,{className:`h-full py-10`,description:`Once someone visits this post, sources will show here`,title:`No visitors since you published this post`,children:(0,q.jsx)(O,{strokeWidth:1.5})})]})]})]})})},J=()=>{let e=s(),{statsConfig:t,isLoading:n}=I(),{post:o,isPostLoading:l,postId:u}=he(),{totals:_,isLoading:v,currencySymbol:y}=_e(u),{appSettings:b}=re(),{emailTrackClicks:ee,emailTrackOpens:x}=b?.analytics||{},S=b?.analytics?.webAnalytics===!0,C=le(o),{token:w,isLoading:te,error:D}=fe(u,{enabled:C}),{usage:O,loading:k,error:j}=pe({postUuid:o?.uuid,token:w,tokenLoading:te,tokenError:D,enabled:C}),[N,P]=(0,K.useState)(!1),F=(0,K.useMemo)(()=>o?.published_at?oe(o.published_at):se.allTime.value,[o?.published_at]),{startDate:V,endDate:H,timezone:U}=ne(F),W=(0,K.useMemo)(()=>{let e={site_uuid:t?.id||``,date_from:ie(V),date_to:ie(H),timezone:U,post_uuid:``};return!l&&o?.uuid?{...e,post_uuid:o.uuid}:e},[l,o,t?.id,V,H,U]),{data:G,loading:J}=r({endpoint:`api_kpis`,statsConfig:t,params:W}),xe=(0,K.useMemo)(()=>G?.length?G.reduce((e,t)=>{let n=Number(t.visits);return e+(isNaN(n)?0:n)},0):0,[G]),Y=ve.visits,Se=f(F,G||[],{fieldName:Y.dataKey}),Ce=d(G||[],F,Y.dataKey,`sum`)?.map(e=>{let t=Number(e[Y.dataKey]);return{date:String(e.date),value:t,formattedValue:Y.formatter(t),label:Y.label}}),{data:we,loading:Te}=r({endpoint:`api_top_sources`,statsConfig:t,params:W}),Ee=n||v||l||J,De=l||n||J,X=a(o)&&x&&ee,Z=!o?.email_only&&S,Q=b?.analytics.membersTrackSources,$=!!(C&&o&&b?.analytics.webAnalytics);return(0,K.useEffect)(()=>{!l&&o&&i(o)&&!S&&Q&&e(`/posts/analytics/${u}/growth`,{replace:!0})},[l,o,S,e,u,Q]),l?(0,q.jsx)(A,{}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(de,{currentTab:`Overview`}),(0,q.jsx)(ue,{children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-6 lg:grid lg:grid-cols-2`,children:[Z&&(0,q.jsx)(be,{chartData:Ce,isLoading:De||Ee||Te,isNewsletterShown:X,range:Se,sourcesData:we,visitors:xe}),X&&(0,q.jsx)(ye,{isNewsletterStatsLoading:l,isWebShown:Z,post:o}),(Q||$)&&(0,q.jsxs)(`div`,{className:`col-span-2 flex flex-col gap-6 lg:grid lg:grid-cols-3`,children:[Q&&(0,q.jsxs)(g,{className:`group overflow-hidden p-0 ${$?`lg:col-span-2`:`lg:col-span-3`}`,"data-testid":`growth`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(ae,{size:16,strokeWidth:1.5}),`Growth`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{e(`/posts/analytics/${u}/growth`)},children:`View more`})]}),(0,q.jsx)(m,{className:`flex flex-col gap-6 px-0 md:grid md:grid-cols-3 md:items-stretch md:gap-0`,children:Ee?Array.from({length:3},(e,t)=>(0,q.jsxs)(`div`,{className:`h-[98px] gap-1 border-r px-6 py-5 last:border-r-0`,children:[(0,q.jsx)(M,{className:`w-2/3`}),(0,q.jsx)(M,{className:`h-7 w-12`})]},t)):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`Free members`}),(0,q.jsx)(R,{children:(0,q.jsx)(L,{className:`text-[2.2rem]`,children:c(_?.free_members||0)})})]}),b?.paidMembersEnabled&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`Paid members`}),(0,q.jsx)(R,{children:(0,q.jsx)(L,{className:`text-[2.2rem]`,children:c(_?.paid_members||0)})})]}),(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`MRR impact`}),(0,q.jsx)(R,{children:(0,q.jsxs)(L,{className:`text-[2.2rem]`,children:[y,c(ge(_?.mrr||0))]})})]})]})]})})]}),$&&(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${Q?`lg:col-span-1`:`lg:col-span-3`}`,"data-testid":`gift-link-card`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(T,{size:16,strokeWidth:1.5}),`Gift link`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>P(!0),children:`Share`})]}),!k&&!j&&(0,q.jsxs)(m,{className:`flex flex-col gap-1`,children:[(0,q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Visitors`}),(0,q.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold`,"data-testid":`gift-link-card-visitors`,children:c(O?.visits??0)})]})]})]}),!Z&&!X&&!Q&&!$&&(0,q.jsx)(ce,{className:`col-span-2 py-20`})]})}),$&&(0,q.jsx)(me,{open:N,postId:u,source:`gift-link-card`,onOpenChange:P},u)]})};export{J as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./use-tinybird-query-DP2dMaq7.js";import{i,o as a}from"./post-helpers-C5OQMBoi.js";import{m as o}from"./chunk-KS7C4IRE-DG9HTHQ3.js";import{a as s}from"./router-provider-DSQfprxH.js";import{f as c,p as l}from"./dist-Cb5RSHSg.js";import{a as u,i as d,t as f}from"./chart-helpers-DGxvWnBT.js";import{a as p,n as m,o as h,t as g}from"./card-aUHX0hyR.js";import{c as _,l as v,n as y,o as b,r as ee,s as x,t as S,u as C}from"./data-list-CupF7bjM.js";import{t as w}from"./empty-indicator-WB1WgT9h.js";import{$a as te,Co as T,Kr as ne,Pr as E,Ps as D,So as O,Vs as re,Wr as ie,Xn as k,da as ae,ir as A,lo as j,or as M,qr as oe,u as se}from"./index-DUXM0NlS.js";import{t as ce}from"./disabled-sources-indicator-uIzbWL7K.js";import{n as N,r as P,t as F}from"./kpi-card-awos0BMH.js";import{t as I}from"./use-analytics-data-BiWvcf1u.js";import{a as L,n as R,r as z,t as B}from"./kpi-card-J8Mj1sDX.js";import{n as le,r as ue,t as de}from"./post-analytics-header-DK27VjJm.js";import{t as fe}from"./gift-links-CVuqLhsZ.js";import{r as pe,t as me}from"./gift-link-modal-BKRuqo-k.js";import{n as he}from"./post-analytics-context-D0Mw-Pmv.js";import{n as ge,t as _e}from"./use-post-referrers-pxIHTXFs.js";import{a as V,o as H,r as U,t as W}from"./link-helpers-Bzkk68GD.js";import{n as ve,r as G}from"./kpi-helpers-SEhvH-8E.js";var K=e(t(),1),q=n(),ye=({post:e,isNewsletterStatsLoading:t,isWebShown:n})=>{let{postId:r}=o(),i=s(),a=(0,K.useMemo)(()=>{let t=e.email?.opened_count||0,n=e.email?.email_count||0,r=e.count?.clicks||0;return{opened:t,clicked:r,openedRate:n>0?t/n:0,clickedRate:n>0?r/n:0,sent:n}},[e]),{data:u}=V({searchParams:{filter:`post_id:'${r}'`}}),d=(0,K.useMemo)(()=>U(u),[u]),f=[{datatype:`Clicked`,value:a.clickedRate,fill:`url(#gradientTeal)`,color:`var(--chart-teal)`},{datatype:`Opened`,value:a.openedRate,fill:`url(#gradientBlue)`,color:`var(--chart-blue)`}],w={percentage:{label:`Opened`},Average:{label:`Clicked`},"This newsletter":{label:`Opened`}},T=e.email_only||!n;return(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${T&&`col-span-2`}`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(te,{size:16,strokeWidth:1.5}),`Newsletter performance`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{i(`/posts/analytics/${r}/newsletter`)},children:`View more`})]}),t?(0,q.jsx)(m,{children:(0,q.jsx)(`div`,{className:`mx-auto flex min-h-[250px] items-center justify-center xl:size-full`,children:(0,q.jsx)(A,{})})}):(0,q.jsxs)(m,{className:`${T&&`grid grid-cols-2`}`,children:[(0,q.jsxs)(`div`,{className:`${T&&`border-r pr-6`}`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,children:[(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-blue)`,children:`Open rate`}),(0,q.jsx)(P,{value:l(a.openedRate)})]})}),(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-teal)`,children:`Click rate`}),(0,q.jsx)(P,{value:l(a.clickedRate)})]})})]}),!T&&(0,q.jsx)(k,{}),(0,q.jsx)(`div`,{className:`mx-auto my-6 h-[240px]`,children:(0,q.jsx)(H,{className:`pointer-events-none aspect-square h-[240px]`,config:w,data:f,tooltip:!1})})]}),(0,q.jsxs)(`div`,{className:`${T&&`pl-6`}`,children:[!T&&(0,q.jsx)(k,{}),(0,q.jsxs)(`div`,{className:T?``:`pt-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 ${T?`pb-3`:`py-3`}`,children:[(0,q.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`Top clicked links in this email`}),(0,q.jsx)(D,{children:`Members`})]}),d.length>0?(0,q.jsx)(S,{className:``,children:(0,q.jsx)(ee,{children:d.slice(0,T?10:5).map(e=>{let t=a.clicked>0?e.count/a.clicked:0;return(0,q.jsxs)(C,{children:[(0,q.jsx)(y,{style:{width:`${t?Math.round(t*100):0}%`}}),(0,q.jsx)(b,{children:(0,q.jsxs)(`div`,{className:`flex items-center space-x-2 overflow-hidden`,children:[(0,q.jsx)(j,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),(0,q.jsx)(`a`,{className:`block truncate font-medium hover:underline`,href:e.link.to,rel:`noreferrer`,target:`_blank`,title:e.link.to,children:W(e.link.to,!0)})]})}),(0,q.jsxs)(x,{children:[(0,q.jsx)(_,{children:c(e.count||0)}),(0,q.jsx)(v,{children:l(t)})]})]},e.link.link_id)})})}):(0,q.jsx)(`div`,{className:`py-20 text-center text-sm text-gray-700`,children:`You have no links in your post.`})]})]})]})]})},be=({chartData:e,range:t,isLoading:n,visitors:r,sourcesData:i,isNewsletterShown:a=!0})=>{let{postId:l}=o(),d=s(),{site:f}=I(),_=f.url,v=f.icon,y=(0,K.useMemo)(()=>i?i.reduce((e,t)=>e+Number(t.visits||0),0):0,[i]);return(0,q.jsx)(q.Fragment,{children:(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${!a&&`col-span-2`}`,"data-testid":`web-performance`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(O,{size:16,strokeWidth:1.5}),`Web performance`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{d(`/posts/analytics/${l}/web`)},children:`View more`})]}),(0,q.jsxs)(m,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(F,{className:`group relative flex grow flex-row items-start justify-between gap-5 border-none px-0 pt-0`,"data-testid":`unique-visitors`,children:(0,q.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,q.jsx)(N,{color:`var(--chart-blue)`,children:`Unique visitors`}),(0,q.jsx)(P,{value:c(r)})]})}),(0,q.jsx)(k,{}),(0,q.jsx)(`div`,{className:`max-h-[288px] py-6 [&_.recharts-cartesian-axis-tick-value]:fill-gray-500`,children:n?(0,q.jsx)(`div`,{className:`flex h-[16vw] min-h-[240px] items-center justify-center`,children:(0,q.jsx)(A,{})}):(0,q.jsx)(u,{className:`aspect-auto h-[240px] w-full`,color:`var(--chart-blue)`,data:e||[],id:`visitors`,range:t,syncId:`overview-charts`})})]}),a&&(0,q.jsxs)(`div`,{className:a?`border-t pt-3`:`-mt-3`,children:[(0,q.jsx)(`div`,{children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[(0,q.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:`How readers found this post`}),(0,q.jsx)(D,{children:`Visitors`})]})}),i&&i.length>0?(0,q.jsx)(G,{data:i,range:t,siteIcon:v,siteUrl:_,tableOnly:!0,topSourcesLimit:5,totalVisitors:y}):(0,q.jsx)(w,{className:`h-full py-10`,description:`Once someone visits this post, sources will show here`,title:`No visitors since you published this post`,children:(0,q.jsx)(O,{strokeWidth:1.5})})]})]})]})})},J=()=>{let e=s(),{statsConfig:t,isLoading:n}=I(),{post:o,isPostLoading:l,postId:u}=he(),{totals:_,isLoading:v,currencySymbol:y}=_e(u),{appSettings:b}=re(),{emailTrackClicks:ee,emailTrackOpens:x}=b?.analytics||{},S=b?.analytics?.webAnalytics===!0,C=le(o),{token:w,isLoading:te,error:D}=fe(u,{enabled:C}),{usage:O,loading:k,error:j}=pe({postUuid:o?.uuid,token:w,tokenLoading:te,tokenError:D,enabled:C}),[N,P]=(0,K.useState)(!1),F=(0,K.useMemo)(()=>o?.published_at?oe(o.published_at):se.allTime.value,[o?.published_at]),{startDate:V,endDate:H,timezone:U}=ne(F),W=(0,K.useMemo)(()=>{let e={site_uuid:t?.id||``,date_from:ie(V),date_to:ie(H),timezone:U,post_uuid:``};return!l&&o?.uuid?{...e,post_uuid:o.uuid}:e},[l,o,t?.id,V,H,U]),{data:G,loading:J}=r({endpoint:`api_kpis`,statsConfig:t,params:W}),xe=(0,K.useMemo)(()=>G?.length?G.reduce((e,t)=>{let n=Number(t.visits);return e+(isNaN(n)?0:n)},0):0,[G]),Y=ve.visits,Se=f(F,G||[],{fieldName:Y.dataKey}),Ce=d(G||[],F,Y.dataKey,`sum`)?.map(e=>{let t=Number(e[Y.dataKey]);return{date:String(e.date),value:t,formattedValue:Y.formatter(t),label:Y.label}}),{data:we,loading:Te}=r({endpoint:`api_top_sources`,statsConfig:t,params:W}),Ee=n||v||l||J,De=l||n||J,X=a(o)&&x&&ee,Z=!o?.email_only&&S,Q=b?.analytics.membersTrackSources,$=!!(C&&o&&b?.analytics.webAnalytics);return(0,K.useEffect)(()=>{!l&&o&&i(o)&&!S&&Q&&e(`/posts/analytics/${u}/growth`,{replace:!0})},[l,o,S,e,u,Q]),l?(0,q.jsx)(A,{}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(de,{currentTab:`Overview`}),(0,q.jsx)(ue,{children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-6 lg:grid lg:grid-cols-2`,children:[Z&&(0,q.jsx)(be,{chartData:Ce,isLoading:De||Ee||Te,isNewsletterShown:X,range:Se,sourcesData:we,visitors:xe}),X&&(0,q.jsx)(ye,{isNewsletterStatsLoading:l,isWebShown:Z,post:o}),(Q||$)&&(0,q.jsxs)(`div`,{className:`col-span-2 flex flex-col gap-6 lg:grid lg:grid-cols-3`,children:[Q&&(0,q.jsxs)(g,{className:`group overflow-hidden p-0 ${$?`lg:col-span-2`:`lg:col-span-3`}`,"data-testid":`growth`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(ae,{size:16,strokeWidth:1.5}),`Growth`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>{e(`/posts/analytics/${u}/growth`)},children:`View more`})]}),(0,q.jsx)(m,{className:`flex flex-col gap-6 px-0 md:grid md:grid-cols-3 md:items-stretch md:gap-0`,children:Ee?Array.from({length:3},(e,t)=>(0,q.jsxs)(`div`,{className:`h-[98px] gap-1 border-r px-6 py-5 last:border-r-0`,children:[(0,q.jsx)(M,{className:`w-2/3`}),(0,q.jsx)(M,{className:`h-7 w-12`})]},t)):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`Free members`}),(0,q.jsx)(R,{children:(0,q.jsx)(L,{className:`text-[2.2rem]`,children:c(_?.free_members||0)})})]}),b?.paidMembersEnabled&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`Paid members`}),(0,q.jsx)(R,{children:(0,q.jsx)(L,{className:`text-[2.2rem]`,children:c(_?.paid_members||0)})})]}),(0,q.jsxs)(B,{className:`grow gap-1 py-0`,children:[(0,q.jsx)(z,{children:`MRR impact`}),(0,q.jsx)(R,{children:(0,q.jsxs)(L,{className:`text-[2.2rem]`,children:[y,c(ge(_?.mrr||0))]})})]})]})]})})]}),$&&(0,q.jsxs)(g,{className:`group/datalist overflow-hidden ${Q?`lg:col-span-1`:`lg:col-span-3`}`,"data-testid":`gift-link-card`,children:[(0,q.jsxs)(`div`,{className:`relative flex items-center justify-between gap-6`,children:[(0,q.jsx)(p,{children:(0,q.jsxs)(h,{className:`flex items-center gap-1.5 text-lg`,children:[(0,q.jsx)(T,{size:16,strokeWidth:1.5}),`Gift link`]})}),(0,q.jsx)(E,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-300 group-hover/datalist:translate-x-0 group-hover/datalist:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:()=>P(!0),children:`Share`})]}),!k&&!j&&(0,q.jsxs)(m,{className:`flex flex-col gap-1`,children:[(0,q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Visitors`}),(0,q.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold`,"data-testid":`gift-link-card-visitors`,children:c(O?.visits??0)})]})]})]}),!Z&&!X&&!Q&&!$&&(0,q.jsx)(ce,{className:`col-span-2 py-20`})]})}),$&&(0,q.jsx)(me,{open:N,postId:u,source:`gift-link-card`,onOpenChange:P},u)]})};export{J as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./use-tinybird-query-GSa32hVw.js";import{f as i,g as a,s as o}from"./stats-D8nZCTy5.js";import{n as s}from"./posts-CxG7v0-M.js";import{t as c}from"./analytics-53FOa2wq.js";import{a as l,t as u}from"./post-helpers-C5OQMBoi.js";import{a as d}from"./router-provider-DSQfprxH.js";import{c as f,f as p,l as m,p as h,s as g}from"./dist-Cb5RSHSg.js";import{a as _,i as v,n as y,t as b}from"./chart-helpers-CZElTGYL.js";import{a as x,n as S,o as C,r as w,s as T,t as E}from"./card-aUHX0hyR.js";import{t as D}from"./empty-indicator-WB1WgT9h.js";import{Ba as O,Bo as k,Ei as A,Fa as ee,Kr as j,Ms as M,Ni as te,Pr as N,Ri as P,So as F,Vr as I,Vs as L,Wr as R,ga as z,i as ne,ir as re,is as ie,jo as B,ls as ae,or as V,p as H,pa as oe,ro as U,sr as se,ss as ce,u as W,vo as G,za as K}from"./index-BHy2DZX-.js";import{i as le,n as ue,r as de,t as fe}from"./stats-view-CugFVf0g.js";import{t as pe}from"./use-growth-stats-DPU5rt3W.js";import{n as me,r as he,t as ge}from"./kpi-card-DOUnkZcN.js";import{t as q}from"./use-analytics-data-B-b4wNSC.js";import{n as _e}from"./audience-DTJtXXWY.js";import{n as J}from"./url-helpers-CCyfRrKj.js";import{t as ve}from"./post-share-modal-B9Vmk_XM.js";var Y=e(t(),1),ye=()=>{let{data:{posts:[e]}={posts:[]},isLoading:t}=s({searchParams:{filter:`status:[published,sent]`,order:`published_at DESC`,limit:`1`,include:`authors,email,count.clicks`}}),n=e,{data:r,isLoading:i}=o(n?.id||``,{enabled:!!n?.id});return{data:(0,Y.useMemo)(()=>{if(!n)return null;let e=r?.stats?.[0]||{id:n.id,recipient_count:null,opened_count:null,open_rate:null,member_delta:0,free_members:0,paid_members:0,visitors:0};return{id:n.id,uuid:n.uuid,title:n.title||``,slug:n.slug||``,feature_image:n.feature_image||null,published_at:n.published_at||``,url:n.url||``,excerpt:n.excerpt||``,email_only:n.email_only||!1,status:n.status,email:n.email,count:n.count,authors:n.authors||[],recipient_count:e.recipient_count,opened_count:e.opened_count,open_rate:e.open_rate,member_delta:e.member_delta,free_members:e.free_members,paid_members:e.paid_members,visitors:e.visitors,click_rate:null}},[n,r]),isLoading:t||!!n?.id&&i}},X=n(),be=e=>e.email_only?`Sent`:e.email?`Published and sent`:`Published`,xe=({latestPostStats:e,isLoading:t})=>{let n=d(),[r,i]=(0,Y.useState)(!1),{site:a,settings:o}=q(),{appSettings:s}=L(),{emailTrackClicks:l,emailTrackOpens:g,webAnalytics:_=!1,membersTrackSources:v=!1}=s?.analytics||{};(0,Y.useEffect)(()=>{r&&c(`Share Modal Opened`,{giftLinkShown:!1,source:`stats-overview`})},[r]);let y=a.title||String(o.find(e=>e.key===`title`)?.value||`Ghost Site`),b=String(o.find(e=>e.key===`timezone`)?.value||`Etc/UTC`),T=e?u(e,{membersTrackSources:v}):null,k=`group mr-2 flex flex-col gap-1.5 hover:cursor-pointer`,A=!!e?.email,j=J({postId:e?.id,hasEmailData:A,analytics:{webAnalytics:_,membersTrackSources:v}}),M=j.startsWith(`/editor/`);return(0,X.jsxs)(E,{className:`group/card`,"data-testid":`latest-post`,children:[(0,X.jsxs)(x,{children:[(0,X.jsx)(C,{className:`flex items-baseline justify-between leading-snug font-medium text-muted-foreground`,children:`Latest post performance`}),(0,X.jsx)(w,{className:`hidden`,children:`How your last post did`})]}),(0,X.jsxs)(S,{className:`flex flex-col gap-6 px-0 lg:flex-row xl:grid xl:grid-cols-3`,children:[t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex w-full items-center gap-6 px-6 xl:col-span-2`,children:[(0,X.jsx)(`div`,{className:`w-full max-w-[232px] grow`,children:(0,X.jsx)(V,{className:`aspect-[16/10] rounded-md`})}),(0,X.jsxs)(`div`,{className:`w-full grow`,children:[(0,X.jsx)(V,{className:`w-full max-w-[420px]`}),(0,X.jsx)(V,{className:`w-1/2`})]})]}),(0,X.jsx)(`div`,{className:`flex flex-col items-stretch gap-2 px-6`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]})]})})]}),!t&&e&&T?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 px-6 transition-all md:flex-row md:items-start xl:col-span-2`,children:[e.feature_image&&(0,X.jsx)(`div`,{className:`aspect-[16/10] w-full min-w-[100px] rounded-sm bg-cover bg-center sm:max-w-[170px] lg:max-w-[170px] xl:max-w-[232px]`,style:{backgroundImage:`url(${e.feature_image})`}}),(0,X.jsxs)(`div`,{className:`flex grow flex-col items-start justify-center self-stretch`,children:[(0,X.jsx)(`div`,{className:`text-md leading-tighter font-semibold tracking-tight hover:cursor-pointer hover:opacity-75`,onClick:()=>{!t&&e&&n(j,{crossApp:!0})},children:e.title}),(0,X.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.authors&&e.authors.length>0&&(0,X.jsxs)(`div`,{children:[`By `,e.authors.map(e=>e.name).join(`, `),` – `,m(e.published_at,b)]}),(0,X.jsx)(`div`,{className:`mt-0.5`,children:be(e)})]}),(0,X.jsxs)(`div`,{className:`mt-6 flex items-center gap-2`,children:[!e.email_only&&(0,X.jsx)(ve,{author:e.authors?.map(e=>e.name).join(`, `)||``,description:``,faviconURL:a.icon||``,featureImageURL:e.feature_image||``,open:r,postExcerpt:e.excerpt||``,postTitle:e.title,postURL:e.url||``,siteTitle:y,onClose:()=>i(!1),onOpenChange:i,children:(0,X.jsxs)(N,{onClick:()=>i(!0),children:[(0,X.jsx)(oe,{}),` Share post`]})}),(0,X.jsx)(N,{className:e.email_only?`w-full`:``,variant:`outline`,onClick:()=>{n(j,{crossApp:!0})},children:M?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ee,{}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Edit post`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ce,{}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:e.email_only?`Post analytics`:`Analytics`})]})})]})]})]}),(0,X.jsx)(`div`,{className:`-ml-4 flex w-full flex-col items-stretch gap-2 pr-6 xl:h-full xl:max-w-none`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-6 pl-10 lg:border-l xl:h-full`,children:[T.showWebMetrics&&_&&(0,X.jsxs)(`div`,{className:k,"data-testid":`latest-post-visitors`,onClick:()=>{n(`/posts/analytics/${e.id}/web`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(F,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Visitors`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:p(e.visitors)})]}),T.showMemberGrowth&&(0,X.jsxs)(`div`,{className:f(k,T.showEmailMetrics&&(!T.showWebMetrics||!_)&&`col-[1/2] row-[2/3]`),"data-testid":`latest-post-members`,onClick:()=>{n(`/posts/analytics/${e.id}/growth`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(P,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Members`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.member_delta?(0,X.jsxs)(X.Fragment,{children:[`+`,p(e.member_delta)]}):0})]}),T.showEmailMetrics&&e.email&&(0,X.jsxs)(X.Fragment,{children:[g&&(0,X.jsxs)(`div`,{className:k,onClick:()=>{n(`/posts/analytics/${e.id}/newsletter`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(U,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden whitespace-nowrap md:visible! md:block!`,children:`Opens`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.email.email_count?h((e.email.opened_count||0)/e.email.email_count):`0%`})]}),l&&(0,X.jsxs)(`div`,{className:k,onClick:()=>{n(`/posts/analytics/${e.id}/newsletter`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(O,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden whitespace-nowrap md:visible! md:block!`,children:`Clicks`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.email.email_count&&e.count?.clicks?h((e.count.clicks||0)/e.email.email_count):`0%`})]})]})]})})]}):!t&&(0,X.jsx)(D,{actions:(0,X.jsx)(N,{variant:`secondary`,onClick:()=>{n(`/editor/post`,{crossApp:!0})},children:`New post`}),className:`w-full pb-10 xl:col-span-3`,description:`Once it's live, you can track performance here`,title:`Publish your first post`,children:(0,X.jsx)(B,{strokeWidth:1.5})})]})]})},Se=()=>{let{config:e}=q();return{isLimited:t=>e?.hostSettings?.limits&&t===`limitAnalytics`?e.hostSettings.limits.limitAnalytics?.disabled===!0:!1}},Z=({title:e,iconName:t,description:n,color:r,diffDirection:i,diffValue:a,formattedValue:o,trendingFromValue:s,children:c,onClick:l})=>{let{range:u}=H(),d=t&&A[t],f=Y.useMemo(()=>{if(!i||i===`empty`||u===W.allTime.value||!a)return``;let e=i===`up`?`up`:i===`down`?`down`:`at`,t=y(u).replace(`in the `,``).replace(/^\(|\)$/g,``);return i===`same`?(0,X.jsxs)(`span`,{children:[`You're trending at the same level as `,(0,X.jsx)(`span`,{className:`font-semibold`,children:o}),` compared to the `,(0,X.jsx)(`span`,{className:`font-semibold`,children:t})]}):(0,X.jsxs)(`span`,{children:[`You're trending `,(0,X.jsxs)(`span`,{className:`font-semibold`,children:[e,` `,a]}),` from `,(0,X.jsx)(`span`,{className:`font-semibold`,children:s}),` compared to the `,t]})},[i,a,s,o,u]);return(0,X.jsxs)(E,{className:`group`,"data-testid":e,children:[(0,X.jsxs)(x,{className:`hidden`,children:[(0,X.jsx)(C,{children:e}),(0,X.jsx)(w,{children:n})]}),(0,X.jsxs)(ge,{className:`relative flex grow flex-row items-start justify-between gap-5 border-none pb-2 xl:pb-4`,children:[(0,X.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,X.jsxs)(me,{className:l&&`transition-all group-hover:text-foreground`,children:[r&&(0,X.jsx)(`span`,{className:`inline-block size-2 rounded-full opacity-50`,style:{backgroundColor:r}}),d&&(0,X.jsx)(d,{size:16,strokeWidth:1.5}),e]}),(0,X.jsx)(he,{diffDirection:u===W.allTime.value?`hidden`:i,diffTooltip:f,diffValue:a,value:o})]}),l&&(0,X.jsx)(N,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:l,children:`View more`})]}),(0,X.jsx)(S,{children:c})]})},Ce=({kpiValues:e,visitorsChartData:t,visitorsChartRange:n,visitorsYRange:r,growthTotals:i,membersChartData:a,mrrChartData:o,growthChartRange:s,currencySymbol:c,isLoading:l})=>{let u=d(),{appSettings:f}=L(),m=Se().isLimited(`limitAnalytics`),h=`-mb-3 h-[10vw] max-h-[200px] min-h-[100px] hover:cursor-pointer!`;if(l)return(0,X.jsx)(T,{className:`flex h-[calc(10vw+116px)] max-h-[416px] min-h-20 items-center justify-center hover:cursor-pointer!`,children:(0,X.jsx)(re,{})});let g=f?.analytics.webAnalytics,v=m&&!g,y=f?.paidMembersEnabled,b=[g,v,!0,y].filter(Boolean).length,O=`lg:grid-cols-3`;return b===2?O=`lg:grid-cols-2`:b===1&&(O=`lg:grid-cols-1`),(0,X.jsxs)(`div`,{className:`flex flex-col lg:grid ${O} gap-6`,children:[g&&!v&&(0,X.jsx)(Z,{description:`Number of individual people who visited your website`,diffDirection:`empty`,formattedValue:e.visits,iconName:`Globe`,linkto:`/analytics/web/`,title:`Unique visitors`,onClick:()=>{u(`/analytics/web/`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-blue)`,data:t,id:`visitors`,range:n,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`,yAxisRange:r})}),v&&(0,X.jsxs)(E,{children:[(0,X.jsxs)(x,{className:`hidden`,children:[(0,X.jsx)(C,{children:`Unlock web analytics`}),(0,X.jsx)(w,{children:`Get the full picture of what's working with detailed, cookie-free traffic analytics.`})]}),(0,X.jsx)(S,{className:`flex h-full items-center justify-center p-6`,children:(0,X.jsx)(D,{actions:(0,X.jsx)(N,{variant:`outline`,onClick:()=>u(`/pro`,{crossApp:!0}),children:`Upgrade now`}),className:`py-10`,description:`Get the full picture of what's working with detailed, cookie-free traffic analytics.`,title:`Unlock web analytics`,children:(0,X.jsx)(ie,{})})})]}),(0,X.jsx)(Z,{description:`How number of members of your publication changed over time`,diffDirection:i.directions.total,diffValue:i.percentChanges.total,formattedValue:p(i.totalMembers),iconName:`User`,linkto:`/analytics/growth/`,title:`Members`,trendingFromValue:`${p(a[0]?.value??0)}`,onClick:()=>{u(`/analytics/growth/?tab=total-members`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-darkblue)`,data:a,id:`members`,range:s,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`})}),y&&(0,X.jsx)(Z,{description:`Monthly recurring revenue changes over time`,diffDirection:i.directions.mrr,diffValue:i.percentChanges.mrr,formattedValue:`${c}${p(I(i.mrr))}`,iconName:`Coins`,linkto:`/analytics/growth/`,title:`MRR`,trendingFromValue:`${c}${p(o[0]?.value??0)}`,onClick:()=>{u(`/analytics/growth/?tab=mrr`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-teal)`,data:o,id:`mrr`,range:s,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`})})]})},we=({className:e})=>(0,X.jsx)(`div`,{className:f(`flex flex-col items-center justify-center gap-1 rounded-sm bg-muted p-6 dark:bg-surface-elevated-2`,e),children:(0,X.jsx)(G,{className:`text-muted-foreground/50`,size:18,strokeWidth:1.5})}),Q=({className:e,metrics:t,title:n})=>(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:f(`pointer-events-none absolute bottom-[calc(100%+2px)] left-1/2 z-50 min-w-[160px] -translate-x-1/2 rounded-md bg-background p-3 text-sm opacity-0 shadow-md transition-all group-hover/tooltip:bottom-[calc(100%+12px)] group-hover/tooltip:opacity-100`,e),children:[(0,X.jsx)(`div`,{className:`mb-1.5 border-b pr-10 pb-1.5 font-medium whitespace-nowrap text-muted-foreground`,children:n}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t?.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 whitespace-nowrap`,children:[e.icon,e.label]}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.metric})]},e.label))})]})}),Te=({topPostsData:e,isLoading:t})=>{let n=d(),{range:r}=H(),{settings:i}=q(),{appSettings:a}=L(),o=String(i.find(e=>e.key===`timezone`)?.value||`Etc/UTC`),{webAnalytics:s=!1,membersTrackSources:c=!1,emailTrackClicks:u=!1,emailTrackOpens:f=!1}=a?.analytics||{},h=`flex items-center justify-end gap-1 rounded-md px-2 py-1 font-mono text-gray-800 hover:bg-muted-foreground/10 group-hover:text-foreground`;return(0,X.jsxs)(E,{className:`group/card w-full lg:col-span-2`,"data-testid":`top-posts-card`,children:[(0,X.jsxs)(x,{children:[(0,X.jsxs)(C,{className:`flex items-baseline justify-between leading-snug font-medium text-muted-foreground`,children:[`Top posts `,y(r)]}),(0,X.jsx)(w,{className:`hidden`,children:`Most viewed posts in this period`})]}),(0,X.jsx)(S,{children:t?(0,X.jsx)(se,{className:`mt-6`}):(0,X.jsxs)(X.Fragment,{children:[e?.stats?.map(e=>(0,X.jsxs)(`div`,{className:`group relative flex w-full items-start justify-between gap-5 border-t border-border/50 py-4 before:absolute before:-inset-x-4 before:inset-y-0 before:z-0 before:hidden before:rounded-md before:bg-table-row-hover before:content-[""] first:border-border! hover:cursor-pointer hover:border-transparent hover:before:block md:items-center [&+div]:hover:border-transparent`,children:[(0,X.jsxs)(`div`,{className:`z-10 flex min-w-[160px] grow items-start gap-4 md:items-center lg:min-w-[320px]`,onClick:()=>{n(J({postId:e.post_id,hasEmailData:e.sent_count!==null,analytics:{webAnalytics:s,membersTrackSources:c}}),{crossApp:!0})},children:[e.feature_image?(0,X.jsx)(`div`,{className:`hidden aspect-[16/10] w-[80px] shrink-0 rounded-sm bg-cover bg-center sm:visible! sm:block! lg:w-[100px]`,style:{backgroundImage:`url(${e.feature_image})`}}):(0,X.jsx)(we,{className:`hidden aspect-[16/10] w-[80px] shrink-0 group-hover:bg-muted-foreground/10 sm:visible! sm:flex! lg:w-[100px]`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsx)(`span`,{className:`line-clamp-2 text-md font-semibold`,children:e.title}),(0,X.jsxs)(`span`,{className:`text text-muted-foreground`,children:[`By `,e.authors,` – `,m(e.published_at,o)]}),(0,X.jsx)(`span`,{className:`text text-muted-foreground`,children:l(e)})]})]}),(0,X.jsxs)(`div`,{className:`z-10 flex flex-col items-end justify-center gap-0.5 text-sm md:flex-row md:items-center md:justify-end md:gap-3`,children:[s&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,"data-testid":`statistics-visitors`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/web`,{crossApp:!0})},children:[(0,X.jsx)(Q,{metrics:[{icon:(0,X.jsx)(F,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Unique visitors`,metric:p(e.views)}],title:`Web traffic`}),(0,X.jsxs)(`div`,{className:h,children:[(0,X.jsx)(F,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),g(e.views)]})]}),e.sent_count!==null&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/newsletter`,{crossApp:!0})},children:[(0,X.jsx)(Q,{className:`${c?``:`right-0 left-auto translate-x-0`}`,metrics:[{icon:(0,X.jsx)(z,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Sent`,metric:p(e.sent_count||0)},...f?[{icon:(0,X.jsx)(U,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Opens`,metric:p(e.opened_count||0)}]:[],...u?[{icon:(0,X.jsx)(K,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Clicks`,metric:p(e.clicked_count||0)}]:[]],title:`Newsletter performance`}),(0,X.jsx)(`div`,{className:h,children:f?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(U,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.open_rate?`${Math.round(e.open_rate)}%`:`0%`]}):u?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(K,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.click_rate?`${Math.round(e.click_rate)}%`:`0%`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),g(e.sent_count||0)]})})]}),c&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,"data-testid":`statistics-members`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/growth`,{crossApp:!0})},children:[(0,X.jsx)(Q,{className:`right-0 left-auto translate-x-0`,metrics:[{icon:(0,X.jsx)(te,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Free`,metric:e.free_members>0?`+${p(e.free_members)}`:`0`},...a?.paidMembersEnabled?[{icon:(0,X.jsx)(k,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Paid`,metric:e.paid_members>0?`+${p(e.paid_members)}`:`0`}]:[]],title:`New members`}),(0,X.jsxs)(`div`,{className:h,children:[(0,X.jsx)(P,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.members>0?`+${p(e.members)}`:`0`]})]})]})]},e.post_id)),(!e?.stats||e.stats.length===0)&&(0,X.jsx)(D,{className:`w-full pb-10`,title:`No posts ${y(r)}`,children:(0,X.jsx)(B,{strokeWidth:1.5})})]})})]})},$=({className:e,title:t,description:n,url:r,children:i})=>(0,X.jsx)(`a`,{className:f(`group/card block rounded-xl border bg-card p-6 transition-all hover:bg-table-row-hover hover:shadow-xs`,e),href:r,rel:`noreferrer`,target:`_blank`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-6`,children:[i,(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 leading-tight`,children:[(0,X.jsx)(`span`,{className:`text-base font-semibold`,children:t}),(0,X.jsx)(`span`,{className:`text-sm font-normal text-gray-700`,children:n})]})]})}),Ee=()=>{let{appSettings:e}=L(),{range:t}=H(),{statsConfig:n,isLoading:o}=q(),{startDate:s,endDate:c,timezone:l}=j(t),{isLoading:u,chartData:d,totals:f,currencySymbol:m}=pe(t),{data:h,isLoading:g}=ye(),{data:_,isLoading:y}=i({searchParams:{date_from:R(s),date_to:R(c),limit:`5`,timezone:l}}),{data:x,loading:S}=r({endpoint:`api_kpis`,statsConfig:n,params:{site_uuid:n?.id||``,date_from:R(s),date_to:R(c),timezone:l,member_status:_e(ne)}}),C=(0,Y.useMemo)(()=>v(x||[],t,`visits`,`sum`)?.map(e=>{let t=Number(e.visits),n=isNaN(t)?0:t;return{date:String(e.date),value:n,formattedValue:p(n),label:`Visitors`}}),[x,t]),w=(0,Y.useMemo)(()=>b(t,x||[],{fieldName:`visits`}),[x,t]),T=(0,Y.useMemo)(()=>{let e=[0,1];if(!C||C.length===0)return e;let t=C.map(e=>e.value).filter(e=>e>=0);return t.length===0?e:[0,Math.max(...t)||e[1]]},[C]),E=(0,Y.useMemo)(()=>b(t,d||[]),[d,t]),D=(0,Y.useMemo)(()=>{if(!d||d.length===0)return[];let e=[];return e=v(d,t,`value`,`exact`),e.map(e=>({date:e.date,value:e.free+e.paid,formattedValue:p(e.free+e.paid),label:`Members`}))},[d,t]),O=(0,Y.useMemo)(()=>{if(!e?.paidMembersEnabled||!d||d.length===0)return[];let n=[];return n=v(d,t,`mrr`,`exact`),n.map(e=>({date:e.date,value:I(e.mrr),formattedValue:`${m}${p(I(e.mrr))}`,label:`MRR`}))},[d,t,m,e]),k=(0,Y.useMemo)(()=>x?.length?{visits:p(x.reduce((e,t)=>{let n=Number(t.visits);return e+(isNaN(n)?0:n)},0))}:{visits:`0`},[x]);return(0,X.jsxs)(ue,{children:[(0,X.jsx)(de,{children:(0,X.jsx)(a,{children:(0,X.jsx)(le,{excludeRanges:[`today`]})})}),(0,X.jsxs)(fe,{isLoading:o,loadingComponent:(0,X.jsx)(X.Fragment,{}),children:[(0,X.jsx)(Ce,{currencySymbol:m,growthChartRange:E,growthTotals:f,isLoading:S||u,kpiValues:k,membersChartData:D,mrrChartData:O,visitorsChartData:C,visitorsChartRange:w,visitorsYRange:T}),(0,X.jsx)(xe,{isLoading:g,latestPostStats:h}),(0,X.jsx)(Te,{isLoading:y,topPostsData:_}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,X.jsx)(M,{className:`mt-4 -mb-4 lg:col-span-2`,children:`Grow your audience`}),(0,X.jsx)($,{description:`Find out how to review the performance of your content and get the most out of post analytics in Ghost.`,title:`Understanding analytics in Ghost`,url:`https://ghost.org/help/native-analytics`,children:(0,X.jsx)(`div`,{className:`flex h-18 w-[100px] min-w-[100px] items-center justify-center rounded-md bg-gradient-to-tr from-[#14B8FF]/20 to-[#00BBA7]/20 p-4 opacity-80 transition-all group-hover/card:opacity-100`,children:(0,X.jsx)(ae,{className:`text-[#00BBA7]`,size:20,strokeWidth:1.5})})}),(0,X.jsx)($,{description:`Use these content distribution tactics to get more people to discover your work and increase engagement.`,title:`How to get your content seen online`,url:`https://ghost.org/resources/content-distribution/`,children:(0,X.jsx)(`div`,{className:`flex h-18 w-[100px] min-w-[100px] items-center justify-center rounded-md bg-gradient-to-tl from-[#FDC700]/20 to-[#FF2056]/20 p-4 opacity-80 transition-all group-hover/card:opacity-100`,children:(0,X.jsx)(F,{className:`text-[#FE9A00]`,size:20,strokeWidth:1.5})})})]})]})]})};export{Ee as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./use-tinybird-query-DP2dMaq7.js";import{f as i,g as a,s as o}from"./stats-B2KW8E2y.js";import{n as s}from"./posts-CxG7v0-M.js";import{t as c}from"./analytics-53FOa2wq.js";import{a as l,t as u}from"./post-helpers-C5OQMBoi.js";import{a as d}from"./router-provider-DSQfprxH.js";import{c as f,f as p,l as m,p as h,s as g}from"./dist-Cb5RSHSg.js";import{a as _,i as v,n as y,t as b}from"./chart-helpers-DGxvWnBT.js";import{a as x,n as S,o as C,r as w,s as T,t as E}from"./card-aUHX0hyR.js";import{t as D}from"./empty-indicator-WB1WgT9h.js";import{Ba as O,Bo as k,Ei as A,Fa as ee,Kr as j,Ms as M,Ni as te,Pr as N,Ri as P,So as F,Vr as I,Vs as L,Wr as R,ga as z,i as ne,ir as re,is as ie,jo as B,ls as ae,or as V,p as H,pa as oe,ro as U,sr as se,ss as ce,u as W,vo as G,za as K}from"./index-DUXM0NlS.js";import{i as le,n as ue,r as de,t as fe}from"./stats-view-CVzU2-p5.js";import{t as pe}from"./use-growth-stats-Dom8xVzo.js";import{n as me,r as he,t as ge}from"./kpi-card-awos0BMH.js";import{t as q}from"./use-analytics-data-BiWvcf1u.js";import{n as _e}from"./audience-DkknNqhZ.js";import{n as J}from"./url-helpers-CCyfRrKj.js";import{t as ve}from"./post-share-modal-DtFAC132.js";var Y=e(t(),1),ye=()=>{let{data:{posts:[e]}={posts:[]},isLoading:t}=s({searchParams:{filter:`status:[published,sent]`,order:`published_at DESC`,limit:`1`,include:`authors,email,count.clicks`}}),n=e,{data:r,isLoading:i}=o(n?.id||``,{enabled:!!n?.id});return{data:(0,Y.useMemo)(()=>{if(!n)return null;let e=r?.stats?.[0]||{id:n.id,recipient_count:null,opened_count:null,open_rate:null,member_delta:0,free_members:0,paid_members:0,visitors:0};return{id:n.id,uuid:n.uuid,title:n.title||``,slug:n.slug||``,feature_image:n.feature_image||null,published_at:n.published_at||``,url:n.url||``,excerpt:n.excerpt||``,email_only:n.email_only||!1,status:n.status,email:n.email,count:n.count,authors:n.authors||[],recipient_count:e.recipient_count,opened_count:e.opened_count,open_rate:e.open_rate,member_delta:e.member_delta,free_members:e.free_members,paid_members:e.paid_members,visitors:e.visitors,click_rate:null}},[n,r]),isLoading:t||!!n?.id&&i}},X=n(),be=e=>e.email_only?`Sent`:e.email?`Published and sent`:`Published`,xe=({latestPostStats:e,isLoading:t})=>{let n=d(),[r,i]=(0,Y.useState)(!1),{site:a,settings:o}=q(),{appSettings:s}=L(),{emailTrackClicks:l,emailTrackOpens:g,webAnalytics:_=!1,membersTrackSources:v=!1}=s?.analytics||{};(0,Y.useEffect)(()=>{r&&c(`Share Modal Opened`,{giftLinkShown:!1,source:`stats-overview`})},[r]);let y=a.title||String(o.find(e=>e.key===`title`)?.value||`Ghost Site`),b=String(o.find(e=>e.key===`timezone`)?.value||`Etc/UTC`),T=e?u(e,{membersTrackSources:v}):null,k=`group mr-2 flex flex-col gap-1.5 hover:cursor-pointer`,A=!!e?.email,j=J({postId:e?.id,hasEmailData:A,analytics:{webAnalytics:_,membersTrackSources:v}}),M=j.startsWith(`/editor/`);return(0,X.jsxs)(E,{className:`group/card`,"data-testid":`latest-post`,children:[(0,X.jsxs)(x,{children:[(0,X.jsx)(C,{className:`flex items-baseline justify-between leading-snug font-medium text-muted-foreground`,children:`Latest post performance`}),(0,X.jsx)(w,{className:`hidden`,children:`How your last post did`})]}),(0,X.jsxs)(S,{className:`flex flex-col gap-6 px-0 lg:flex-row xl:grid xl:grid-cols-3`,children:[t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex w-full items-center gap-6 px-6 xl:col-span-2`,children:[(0,X.jsx)(`div`,{className:`w-full max-w-[232px] grow`,children:(0,X.jsx)(V,{className:`aspect-[16/10] rounded-md`})}),(0,X.jsxs)(`div`,{className:`w-full grow`,children:[(0,X.jsx)(V,{className:`w-full max-w-[420px]`}),(0,X.jsx)(V,{className:`w-1/2`})]})]}),(0,X.jsx)(`div`,{className:`flex flex-col items-stretch gap-2 px-6`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`w-3/4`}),(0,X.jsx)(V,{className:`h-10 w-1/3`})]})]})})]}),!t&&e&&T?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-6 px-6 transition-all md:flex-row md:items-start xl:col-span-2`,children:[e.feature_image&&(0,X.jsx)(`div`,{className:`aspect-[16/10] w-full min-w-[100px] rounded-sm bg-cover bg-center sm:max-w-[170px] lg:max-w-[170px] xl:max-w-[232px]`,style:{backgroundImage:`url(${e.feature_image})`}}),(0,X.jsxs)(`div`,{className:`flex grow flex-col items-start justify-center self-stretch`,children:[(0,X.jsx)(`div`,{className:`text-md leading-tighter font-semibold tracking-tight hover:cursor-pointer hover:opacity-75`,onClick:()=>{!t&&e&&n(j,{crossApp:!0})},children:e.title}),(0,X.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.authors&&e.authors.length>0&&(0,X.jsxs)(`div`,{children:[`By `,e.authors.map(e=>e.name).join(`, `),` – `,m(e.published_at,b)]}),(0,X.jsx)(`div`,{className:`mt-0.5`,children:be(e)})]}),(0,X.jsxs)(`div`,{className:`mt-6 flex items-center gap-2`,children:[!e.email_only&&(0,X.jsx)(ve,{author:e.authors?.map(e=>e.name).join(`, `)||``,description:``,faviconURL:a.icon||``,featureImageURL:e.feature_image||``,open:r,postExcerpt:e.excerpt||``,postTitle:e.title,postURL:e.url||``,siteTitle:y,onClose:()=>i(!1),onOpenChange:i,children:(0,X.jsxs)(N,{onClick:()=>i(!0),children:[(0,X.jsx)(oe,{}),` Share post`]})}),(0,X.jsx)(N,{className:e.email_only?`w-full`:``,variant:`outline`,onClick:()=>{n(j,{crossApp:!0})},children:M?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ee,{}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Edit post`})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ce,{}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:e.email_only?`Post analytics`:`Analytics`})]})})]})]})]}),(0,X.jsx)(`div`,{className:`-ml-4 flex w-full flex-col items-stretch gap-2 pr-6 xl:h-full xl:max-w-none`,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-6 pl-10 lg:border-l xl:h-full`,children:[T.showWebMetrics&&_&&(0,X.jsxs)(`div`,{className:k,"data-testid":`latest-post-visitors`,onClick:()=>{n(`/posts/analytics/${e.id}/web`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(F,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Visitors`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:p(e.visitors)})]}),T.showMemberGrowth&&(0,X.jsxs)(`div`,{className:f(k,T.showEmailMetrics&&(!T.showWebMetrics||!_)&&`col-[1/2] row-[2/3]`),"data-testid":`latest-post-members`,onClick:()=>{n(`/posts/analytics/${e.id}/growth`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(P,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden md:visible! md:block!`,children:`Members`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.member_delta?(0,X.jsxs)(X.Fragment,{children:[`+`,p(e.member_delta)]}):0})]}),T.showEmailMetrics&&e.email&&(0,X.jsxs)(X.Fragment,{children:[g&&(0,X.jsxs)(`div`,{className:k,onClick:()=>{n(`/posts/analytics/${e.id}/newsletter`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(U,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden whitespace-nowrap md:visible! md:block!`,children:`Opens`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.email.email_count?h((e.email.opened_count||0)/e.email.email_count):`0%`})]}),l&&(0,X.jsxs)(`div`,{className:k,onClick:()=>{n(`/posts/analytics/${e.id}/newsletter`,{crossApp:!0})},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground transition-all group-hover:text-foreground`,children:[(0,X.jsx)(O,{size:16,strokeWidth:1.25}),(0,X.jsx)(`span`,{className:`hidden whitespace-nowrap md:visible! md:block!`,children:`Clicks`})]}),(0,X.jsx)(`span`,{className:`text-[2.2rem] leading-none font-semibold tracking-tighter`,children:e.email.email_count&&e.count?.clicks?h((e.count.clicks||0)/e.email.email_count):`0%`})]})]})]})})]}):!t&&(0,X.jsx)(D,{actions:(0,X.jsx)(N,{variant:`secondary`,onClick:()=>{n(`/editor/post`,{crossApp:!0})},children:`New post`}),className:`w-full pb-10 xl:col-span-3`,description:`Once it's live, you can track performance here`,title:`Publish your first post`,children:(0,X.jsx)(B,{strokeWidth:1.5})})]})]})},Se=()=>{let{config:e}=q();return{isLimited:t=>e?.hostSettings?.limits&&t===`limitAnalytics`?e.hostSettings.limits.limitAnalytics?.disabled===!0:!1}},Z=({title:e,iconName:t,description:n,color:r,diffDirection:i,diffValue:a,formattedValue:o,trendingFromValue:s,children:c,onClick:l})=>{let{range:u}=H(),d=t&&A[t],f=Y.useMemo(()=>{if(!i||i===`empty`||u===W.allTime.value||!a)return``;let e=i===`up`?`up`:i===`down`?`down`:`at`,t=y(u).replace(`in the `,``).replace(/^\(|\)$/g,``);return i===`same`?(0,X.jsxs)(`span`,{children:[`You're trending at the same level as `,(0,X.jsx)(`span`,{className:`font-semibold`,children:o}),` compared to the `,(0,X.jsx)(`span`,{className:`font-semibold`,children:t})]}):(0,X.jsxs)(`span`,{children:[`You're trending `,(0,X.jsxs)(`span`,{className:`font-semibold`,children:[e,` `,a]}),` from `,(0,X.jsx)(`span`,{className:`font-semibold`,children:s}),` compared to the `,t]})},[i,a,s,o,u]);return(0,X.jsxs)(E,{className:`group`,"data-testid":e,children:[(0,X.jsxs)(x,{className:`hidden`,children:[(0,X.jsx)(C,{children:e}),(0,X.jsx)(w,{children:n})]}),(0,X.jsxs)(ge,{className:`relative flex grow flex-row items-start justify-between gap-5 border-none pb-2 xl:pb-4`,children:[(0,X.jsxs)(`div`,{className:`flex grow flex-col gap-1.5 border-none pb-0`,children:[(0,X.jsxs)(me,{className:l&&`transition-all group-hover:text-foreground`,children:[r&&(0,X.jsx)(`span`,{className:`inline-block size-2 rounded-full opacity-50`,style:{backgroundColor:r}}),d&&(0,X.jsx)(d,{size:16,strokeWidth:1.5}),e]}),(0,X.jsx)(he,{diffDirection:u===W.allTime.value?`hidden`:i,diffTooltip:f,diffValue:a,value:o})]}),l&&(0,X.jsx)(N,{className:`absolute right-6 translate-x-10 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 focus-visible:translate-x-0 focus-visible:opacity-100`,size:`sm`,variant:`outline`,onClick:l,children:`View more`})]}),(0,X.jsx)(S,{children:c})]})},Ce=({kpiValues:e,visitorsChartData:t,visitorsChartRange:n,visitorsYRange:r,growthTotals:i,membersChartData:a,mrrChartData:o,growthChartRange:s,currencySymbol:c,isLoading:l})=>{let u=d(),{appSettings:f}=L(),m=Se().isLimited(`limitAnalytics`),h=`-mb-3 h-[10vw] max-h-[200px] min-h-[100px] hover:cursor-pointer!`;if(l)return(0,X.jsx)(T,{className:`flex h-[calc(10vw+116px)] max-h-[416px] min-h-20 items-center justify-center hover:cursor-pointer!`,children:(0,X.jsx)(re,{})});let g=f?.analytics.webAnalytics,v=m&&!g,y=f?.paidMembersEnabled,b=[g,v,!0,y].filter(Boolean).length,O=`lg:grid-cols-3`;return b===2?O=`lg:grid-cols-2`:b===1&&(O=`lg:grid-cols-1`),(0,X.jsxs)(`div`,{className:`flex flex-col lg:grid ${O} gap-6`,children:[g&&!v&&(0,X.jsx)(Z,{description:`Number of individual people who visited your website`,diffDirection:`empty`,formattedValue:e.visits,iconName:`Globe`,linkto:`/analytics/web/`,title:`Unique visitors`,onClick:()=>{u(`/analytics/web/`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-blue)`,data:t,id:`visitors`,range:n,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`,yAxisRange:r})}),v&&(0,X.jsxs)(E,{children:[(0,X.jsxs)(x,{className:`hidden`,children:[(0,X.jsx)(C,{children:`Unlock web analytics`}),(0,X.jsx)(w,{children:`Get the full picture of what's working with detailed, cookie-free traffic analytics.`})]}),(0,X.jsx)(S,{className:`flex h-full items-center justify-center p-6`,children:(0,X.jsx)(D,{actions:(0,X.jsx)(N,{variant:`outline`,onClick:()=>u(`/pro`,{crossApp:!0}),children:`Upgrade now`}),className:`py-10`,description:`Get the full picture of what's working with detailed, cookie-free traffic analytics.`,title:`Unlock web analytics`,children:(0,X.jsx)(ie,{})})})]}),(0,X.jsx)(Z,{description:`How number of members of your publication changed over time`,diffDirection:i.directions.total,diffValue:i.percentChanges.total,formattedValue:p(i.totalMembers),iconName:`User`,linkto:`/analytics/growth/`,title:`Members`,trendingFromValue:`${p(a[0]?.value??0)}`,onClick:()=>{u(`/analytics/growth/?tab=total-members`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-darkblue)`,data:a,id:`members`,range:s,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`})}),y&&(0,X.jsx)(Z,{description:`Monthly recurring revenue changes over time`,diffDirection:i.directions.mrr,diffValue:i.percentChanges.mrr,formattedValue:`${c}${p(I(i.mrr))}`,iconName:`Coins`,linkto:`/analytics/growth/`,title:`MRR`,trendingFromValue:`${c}${p(o[0]?.value??0)}`,onClick:()=>{u(`/analytics/growth/?tab=mrr`)},children:(0,X.jsx)(_,{className:h,color:`var(--chart-teal)`,data:o,id:`mrr`,range:s,showHorizontalLines:!0,showYAxisValues:!1,syncId:`overview-charts`})})]})},we=({className:e})=>(0,X.jsx)(`div`,{className:f(`flex flex-col items-center justify-center gap-1 rounded-sm bg-muted p-6 dark:bg-surface-elevated-2`,e),children:(0,X.jsx)(G,{className:`text-muted-foreground/50`,size:18,strokeWidth:1.5})}),Q=({className:e,metrics:t,title:n})=>(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)(`div`,{className:f(`pointer-events-none absolute bottom-[calc(100%+2px)] left-1/2 z-50 min-w-[160px] -translate-x-1/2 rounded-md bg-background p-3 text-sm opacity-0 shadow-md transition-all group-hover/tooltip:bottom-[calc(100%+12px)] group-hover/tooltip:opacity-100`,e),children:[(0,X.jsx)(`div`,{className:`mb-1.5 border-b pr-10 pb-1.5 font-medium whitespace-nowrap text-muted-foreground`,children:n}),(0,X.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t?.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 whitespace-nowrap`,children:[e.icon,e.label]}),(0,X.jsx)(`span`,{className:`font-mono`,children:e.metric})]},e.label))})]})}),Te=({topPostsData:e,isLoading:t})=>{let n=d(),{range:r}=H(),{settings:i}=q(),{appSettings:a}=L(),o=String(i.find(e=>e.key===`timezone`)?.value||`Etc/UTC`),{webAnalytics:s=!1,membersTrackSources:c=!1,emailTrackClicks:u=!1,emailTrackOpens:f=!1}=a?.analytics||{},h=`flex items-center justify-end gap-1 rounded-md px-2 py-1 font-mono text-gray-800 hover:bg-muted-foreground/10 group-hover:text-foreground`;return(0,X.jsxs)(E,{className:`group/card w-full lg:col-span-2`,"data-testid":`top-posts-card`,children:[(0,X.jsxs)(x,{children:[(0,X.jsxs)(C,{className:`flex items-baseline justify-between leading-snug font-medium text-muted-foreground`,children:[`Top posts `,y(r)]}),(0,X.jsx)(w,{className:`hidden`,children:`Most viewed posts in this period`})]}),(0,X.jsx)(S,{children:t?(0,X.jsx)(se,{className:`mt-6`}):(0,X.jsxs)(X.Fragment,{children:[e?.stats?.map(e=>(0,X.jsxs)(`div`,{className:`group relative flex w-full items-start justify-between gap-5 border-t border-border/50 py-4 before:absolute before:-inset-x-4 before:inset-y-0 before:z-0 before:hidden before:rounded-md before:bg-table-row-hover before:content-[""] first:border-border! hover:cursor-pointer hover:border-transparent hover:before:block md:items-center [&+div]:hover:border-transparent`,children:[(0,X.jsxs)(`div`,{className:`z-10 flex min-w-[160px] grow items-start gap-4 md:items-center lg:min-w-[320px]`,onClick:()=>{n(J({postId:e.post_id,hasEmailData:e.sent_count!==null,analytics:{webAnalytics:s,membersTrackSources:c}}),{crossApp:!0})},children:[e.feature_image?(0,X.jsx)(`div`,{className:`hidden aspect-[16/10] w-[80px] shrink-0 rounded-sm bg-cover bg-center sm:visible! sm:block! lg:w-[100px]`,style:{backgroundImage:`url(${e.feature_image})`}}):(0,X.jsx)(we,{className:`hidden aspect-[16/10] w-[80px] shrink-0 group-hover:bg-muted-foreground/10 sm:visible! sm:flex! lg:w-[100px]`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsx)(`span`,{className:`line-clamp-2 text-md font-semibold`,children:e.title}),(0,X.jsxs)(`span`,{className:`text text-muted-foreground`,children:[`By `,e.authors,` – `,m(e.published_at,o)]}),(0,X.jsx)(`span`,{className:`text text-muted-foreground`,children:l(e)})]})]}),(0,X.jsxs)(`div`,{className:`z-10 flex flex-col items-end justify-center gap-0.5 text-sm md:flex-row md:items-center md:justify-end md:gap-3`,children:[s&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,"data-testid":`statistics-visitors`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/web`,{crossApp:!0})},children:[(0,X.jsx)(Q,{metrics:[{icon:(0,X.jsx)(F,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Unique visitors`,metric:p(e.views)}],title:`Web traffic`}),(0,X.jsxs)(`div`,{className:h,children:[(0,X.jsx)(F,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),g(e.views)]})]}),e.sent_count!==null&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/newsletter`,{crossApp:!0})},children:[(0,X.jsx)(Q,{className:`${c?``:`right-0 left-auto translate-x-0`}`,metrics:[{icon:(0,X.jsx)(z,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Sent`,metric:p(e.sent_count||0)},...f?[{icon:(0,X.jsx)(U,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Opens`,metric:p(e.opened_count||0)}]:[],...u?[{icon:(0,X.jsx)(K,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Clicks`,metric:p(e.clicked_count||0)}]:[]],title:`Newsletter performance`}),(0,X.jsx)(`div`,{className:h,children:f?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(U,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.open_rate?`${Math.round(e.open_rate)}%`:`0%`]}):u?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(K,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.click_rate?`${Math.round(e.click_rate)}%`:`0%`]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),g(e.sent_count||0)]})})]}),c&&(0,X.jsxs)(`div`,{className:`group/tooltip relative flex w-[66px] lg:w-[92px]`,"data-testid":`statistics-members`,onClick:t=>{t.stopPropagation(),n(`/posts/analytics/${e.post_id}/growth`,{crossApp:!0})},children:[(0,X.jsx)(Q,{className:`right-0 left-auto translate-x-0`,metrics:[{icon:(0,X.jsx)(te,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Free`,metric:e.free_members>0?`+${p(e.free_members)}`:`0`},...a?.paidMembersEnabled?[{icon:(0,X.jsx)(k,{className:`shrink-0 text-muted-foreground`,size:16,strokeWidth:1.5}),label:`Paid`,metric:e.paid_members>0?`+${p(e.paid_members)}`:`0`}]:[]],title:`New members`}),(0,X.jsxs)(`div`,{className:h,children:[(0,X.jsx)(P,{className:`text-muted-foreground group-hover:text-foreground`,size:16,strokeWidth:1.5}),e.members>0?`+${p(e.members)}`:`0`]})]})]})]},e.post_id)),(!e?.stats||e.stats.length===0)&&(0,X.jsx)(D,{className:`w-full pb-10`,title:`No posts ${y(r)}`,children:(0,X.jsx)(B,{strokeWidth:1.5})})]})})]})},$=({className:e,title:t,description:n,url:r,children:i})=>(0,X.jsx)(`a`,{className:f(`group/card block rounded-xl border bg-card p-6 transition-all hover:bg-table-row-hover hover:shadow-xs`,e),href:r,rel:`noreferrer`,target:`_blank`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-6`,children:[i,(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 leading-tight`,children:[(0,X.jsx)(`span`,{className:`text-base font-semibold`,children:t}),(0,X.jsx)(`span`,{className:`text-sm font-normal text-gray-700`,children:n})]})]})}),Ee=()=>{let{appSettings:e}=L(),{range:t}=H(),{statsConfig:n,isLoading:o}=q(),{startDate:s,endDate:c,timezone:l}=j(t),{isLoading:u,chartData:d,totals:f,currencySymbol:m}=pe(t),{data:h,isLoading:g}=ye(),{data:_,isLoading:y}=i({searchParams:{date_from:R(s),date_to:R(c),limit:`5`,timezone:l}}),{data:x,loading:S}=r({endpoint:`api_kpis`,statsConfig:n,params:{site_uuid:n?.id||``,date_from:R(s),date_to:R(c),timezone:l,member_status:_e(ne)}}),C=(0,Y.useMemo)(()=>v(x||[],t,`visits`,`sum`)?.map(e=>{let t=Number(e.visits),n=isNaN(t)?0:t;return{date:String(e.date),value:n,formattedValue:p(n),label:`Visitors`}}),[x,t]),w=(0,Y.useMemo)(()=>b(t,x||[],{fieldName:`visits`}),[x,t]),T=(0,Y.useMemo)(()=>{let e=[0,1];if(!C||C.length===0)return e;let t=C.map(e=>e.value).filter(e=>e>=0);return t.length===0?e:[0,Math.max(...t)||e[1]]},[C]),E=(0,Y.useMemo)(()=>b(t,d||[]),[d,t]),D=(0,Y.useMemo)(()=>{if(!d||d.length===0)return[];let e=[];return e=v(d,t,`value`,`exact`),e.map(e=>({date:e.date,value:e.free+e.paid,formattedValue:p(e.free+e.paid),label:`Members`}))},[d,t]),O=(0,Y.useMemo)(()=>{if(!e?.paidMembersEnabled||!d||d.length===0)return[];let n=[];return n=v(d,t,`mrr`,`exact`),n.map(e=>({date:e.date,value:I(e.mrr),formattedValue:`${m}${p(I(e.mrr))}`,label:`MRR`}))},[d,t,m,e]),k=(0,Y.useMemo)(()=>x?.length?{visits:p(x.reduce((e,t)=>{let n=Number(t.visits);return e+(isNaN(n)?0:n)},0))}:{visits:`0`},[x]);return(0,X.jsxs)(ue,{children:[(0,X.jsx)(de,{children:(0,X.jsx)(a,{children:(0,X.jsx)(le,{excludeRanges:[`today`]})})}),(0,X.jsxs)(fe,{isLoading:o,loadingComponent:(0,X.jsx)(X.Fragment,{}),children:[(0,X.jsx)(Ce,{currencySymbol:m,growthChartRange:E,growthTotals:f,isLoading:S||u,kpiValues:k,membersChartData:D,mrrChartData:O,visitorsChartData:C,visitorsChartRange:w,visitorsYRange:T}),(0,X.jsx)(xe,{isLoading:g,latestPostStats:h}),(0,X.jsx)(Te,{isLoading:y,topPostsData:_}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,X.jsx)(M,{className:`mt-4 -mb-4 lg:col-span-2`,children:`Grow your audience`}),(0,X.jsx)($,{description:`Find out how to review the performance of your content and get the most out of post analytics in Ghost.`,title:`Understanding analytics in Ghost`,url:`https://ghost.org/help/native-analytics`,children:(0,X.jsx)(`div`,{className:`flex h-18 w-[100px] min-w-[100px] items-center justify-center rounded-md bg-gradient-to-tr from-[#14B8FF]/20 to-[#00BBA7]/20 p-4 opacity-80 transition-all group-hover/card:opacity-100`,children:(0,X.jsx)(ae,{className:`text-[#00BBA7]`,size:20,strokeWidth:1.5})})}),(0,X.jsx)($,{description:`Use these content distribution tactics to get more people to discover your work and increase engagement.`,title:`How to get your content seen online`,url:`https://ghost.org/resources/content-distribution/`,children:(0,X.jsx)(`div`,{className:`flex h-18 w-[100px] min-w-[100px] items-center justify-center rounded-md bg-gradient-to-tl from-[#FDC700]/20 to-[#FF2056]/20 p-4 opacity-80 transition-all group-hover/card:opacity-100`,children:(0,X.jsx)(F,{className:`text-[#FE9A00]`,size:20,strokeWidth:1.5})})})]})]})]})};export{Ee as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{c as r}from"./dist-Cb5RSHSg.js";import{t as i}from"./inline-Cw-gigDW.js";import{t as a}from"./stack-CIfOAAVf.js";import{t as o}from"./text-DU9Hv33_.js";import{As as s,Yr as c,Zr as l,ai as u}from"./index-BHy2DZX-.js";var d=e(t(),1),f=n();function p({className:e,children:t}){return(0,f.jsx)(i,{align:`center`,className:r(`pt-1 text-sm text-muted-foreground`,e),"data-page-header":`breadcrumb`,gap:`sm`,children:t})}function m({className:e,children:t}){return(0,f.jsx)(o,{as:`span`,className:r(`ml-1 text-base tabular-nums`,e),"data-page-header":`count`,tone:`secondary`,weight:`regular`,children:t})}function h({className:e,children:t}){return(0,f.jsx)(o,{as:`p`,className:e,"data-page-header":`description`,size:`sm`,tone:`secondary`,children:t})}function g({className:e,children:t}){return(0,f.jsx)(o,{as:`p`,className:r(`mt-0.5`,e),"data-page-header":`meta`,size:`sm`,tone:`secondary`,children:t})}function _({className:e,children:t}){let n=[],i=[];d.Children.forEach(t,e=>{if(!d.isValidElement(e)){n.push(e);return}switch(e.type){case h:case g:i.push(e);break;default:n.push(e)}});let o=(0,f.jsx)(s,{className:r(`text-lg font-semibold tracking-[0.1px] whitespace-nowrap`,e),"data-page-header":`title`,children:n});return i.length>0?(0,f.jsxs)(a,{"data-page-header":`title-body`,gap:`none`,children:[o,i]}):o}function v({className:e,children:t}){return(0,f.jsx)(a,{className:r(`h-full min-h-(--control-height) min-w-0`,e),"data-page-header":`left`,gap:`xs`,justify:`center`,children:t})}function y({children:e}){return(0,f.jsx)(f.Fragment,{children:e})}function b({children:e}){return(0,f.jsx)(c,{children:e})}function x({children:e,...t}){return(0,f.jsx)(u,{asChild:!0,...t,children:e})}function S({children:e,...t}){return(0,f.jsx)(l,{align:`end`,sideOffset:8,...t,children:e})}var C=640,w=e=>typeof window>`u`?!1:window.innerWidth<e,T=e=>{let[t,n]=d.useState(()=>w(e));return d.useEffect(()=>{let t=()=>{n(w(e))};return t(),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`resize`,t)}},[e]),t},E=Object.assign(function({className:e,children:t,mobileMenuBreakpoint:n=C}){let r=d.Children.toArray(t),a=[],o=null,s=null,c=T(n);return r.forEach(e=>{if(!d.isValidElement(e)){a.push(e);return}let t=e;if(t.type===b){o=t;return}if(t.type===y){s=t.props.children??null,a.push(t.props.children??null);return}a.push(t)}),o?c?(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:(0,f.jsxs)(i,{align:`center`,className:`ml-auto`,"data-page-header":`action-group-mobile`,gap:`sm`,children:[o,s&&(0,f.jsx)(`div`,{"data-page-header":`action-group-mobile-primary`,children:s})]})}):(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:(0,f.jsx)(i,{align:`center`,"data-page-header":`action-group-desktop`,gap:`sm`,justify:`end`,children:a})}):(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:t})},{Primary:y,MobileMenu:b,MobileMenuTrigger:x,MobileMenuContent:S});function D({className:e,children:t}){return(0,f.jsx)(i,{align:`center`,className:r(`min-h-(--control-height) shrink-0`,e),"data-page-header":`actions`,gap:`lg`,children:t})}var O=Object.assign(function({className:e,children:t,sticky:n=!0,blurredBackground:a=!0}){return(0,f.jsx)(`header`,{className:r(`flex flex-col`,n&&`sticky top-0 z-50`,a&&`bg-gradient-to-b from-background via-background/70 to-background/70 backdrop-blur-md dark:bg-black`,e),"data-page-header":`page-header`,children:(0,f.jsx)(i,{align:`start`,className:`w-full`,"data-page-header":`main`,gap:`lg`,justify:`between`,children:t})})},{Left:v,Breadcrumb:p,Title:_,Count:m,Description:h,Meta:g,Actions:D,ActionGroup:E});export{O as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{c as r}from"./dist-Cb5RSHSg.js";import{t as i}from"./inline-Cw-gigDW.js";import{t as a}from"./stack-CIfOAAVf.js";import{t as o}from"./text-DU9Hv33_.js";import{As as s,Yr as c,Zr as l,ai as u}from"./index-DUXM0NlS.js";var d=e(t(),1),f=n();function p({className:e,children:t}){return(0,f.jsx)(i,{align:`center`,className:r(`pt-1 text-sm text-muted-foreground`,e),"data-page-header":`breadcrumb`,gap:`sm`,children:t})}function m({className:e,children:t}){return(0,f.jsx)(o,{as:`span`,className:r(`ml-1 text-base tabular-nums`,e),"data-page-header":`count`,tone:`secondary`,weight:`regular`,children:t})}function h({className:e,children:t}){return(0,f.jsx)(o,{as:`p`,className:e,"data-page-header":`description`,size:`sm`,tone:`secondary`,children:t})}function g({className:e,children:t}){return(0,f.jsx)(o,{as:`p`,className:r(`mt-0.5`,e),"data-page-header":`meta`,size:`sm`,tone:`secondary`,children:t})}function _({className:e,children:t}){let n=[],i=[];d.Children.forEach(t,e=>{if(!d.isValidElement(e)){n.push(e);return}switch(e.type){case h:case g:i.push(e);break;default:n.push(e)}});let o=(0,f.jsx)(s,{className:r(`text-lg font-semibold tracking-[0.1px] whitespace-nowrap`,e),"data-page-header":`title`,children:n});return i.length>0?(0,f.jsxs)(a,{"data-page-header":`title-body`,gap:`none`,children:[o,i]}):o}function v({className:e,children:t}){return(0,f.jsx)(a,{className:r(`h-full min-h-(--control-height) min-w-0`,e),"data-page-header":`left`,gap:`xs`,justify:`center`,children:t})}function y({children:e}){return(0,f.jsx)(f.Fragment,{children:e})}function b({children:e}){return(0,f.jsx)(c,{children:e})}function x({children:e,...t}){return(0,f.jsx)(u,{asChild:!0,...t,children:e})}function S({children:e,...t}){return(0,f.jsx)(l,{align:`end`,sideOffset:8,...t,children:e})}var C=640,w=e=>typeof window>`u`?!1:window.innerWidth<e,T=e=>{let[t,n]=d.useState(()=>w(e));return d.useEffect(()=>{let t=()=>{n(w(e))};return t(),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`resize`,t)}},[e]),t},E=Object.assign(function({className:e,children:t,mobileMenuBreakpoint:n=C}){let r=d.Children.toArray(t),a=[],o=null,s=null,c=T(n);return r.forEach(e=>{if(!d.isValidElement(e)){a.push(e);return}let t=e;if(t.type===b){o=t;return}if(t.type===y){s=t.props.children??null,a.push(t.props.children??null);return}a.push(t)}),o?c?(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:(0,f.jsxs)(i,{align:`center`,className:`ml-auto`,"data-page-header":`action-group-mobile`,gap:`sm`,children:[o,s&&(0,f.jsx)(`div`,{"data-page-header":`action-group-mobile-primary`,children:s})]})}):(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:(0,f.jsx)(i,{align:`center`,"data-page-header":`action-group-desktop`,gap:`sm`,justify:`end`,children:a})}):(0,f.jsx)(i,{align:`center`,className:e,"data-page-header":`action-group`,gap:`sm`,justify:`end`,children:t})},{Primary:y,MobileMenu:b,MobileMenuTrigger:x,MobileMenuContent:S});function D({className:e,children:t}){return(0,f.jsx)(i,{align:`center`,className:r(`min-h-(--control-height) shrink-0`,e),"data-page-header":`actions`,gap:`lg`,children:t})}var O=Object.assign(function({className:e,children:t,sticky:n=!0,blurredBackground:a=!0}){return(0,f.jsx)(`header`,{className:r(`flex flex-col`,n&&`sticky top-0 z-50`,a&&`bg-gradient-to-b from-background via-background/70 to-background/70 backdrop-blur-md dark:bg-black`,e),"data-page-header":`page-header`,children:(0,f.jsx)(i,{align:`start`,className:`w-full`,"data-page-header":`main`,gap:`lg`,justify:`between`,children:t})})},{Left:v,Breadcrumb:p,Title:_,Count:m,Description:h,Meta:g,Actions:D,ActionGroup:E});export{O as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{m as r,n as i}from"./hooks-D6EE7BIt.js";import{n as a}from"./dist-Ndy-PuGN.js";import{t as o}from"./switch-CE2NuMn-.js";import{t as s}from"./dropzone-hNxmUvwD.js";import{o as c,t as l}from"./use-settings-navigation-Bf1g1rEh.js";import{a as u,c as d,n as f,o as p,r as m,s as h,t as g}from"./field-Dh_lwk13.js";import{Nn as _,On as v}from"./index-BHy2DZX-.js";import{n as y}from"./global-data-provider-B949LDXJ.js";import{t as b}from"./integration-header-B4DyXV06.js";import{t as x}from"./brand-icon-09YqFZjV.js";``+new URL(`pintura-screenshot-DTzk1LjU.png`,import.meta.url).href;var S=e(t(),1),C=i({method:`POST`,path:()=>`/files/upload/`,body:({file:e})=>{let t=new FormData;return t.append(`file`,e),t}}),w=n();function T(){let{updateRoute:e}=l(),[t,n]=(0,S.useState)({js:!1,css:!1}),{settings:i,config:T}=y(),[E]=v(i,[`pintura`]),{mutateAsync:D}=_(),{mutateAsync:O}=C(),k=r();(0,S.useEffect)(()=>{N(E||!1)},[E]);let[A,j]=(0,S.useState)(`Save`),[M,N]=(0,S.useState)(!!E),P=async()=>{let e=[{key:`pintura`,value:M}];try{j(`Saving...`),await Promise.all([D(e),new Promise(e=>{setTimeout(e,1e3)})]),j(`Saved`)}catch(e){k(e)}finally{setTimeout(()=>j(`Save`),1e3)}},F=async(e,t)=>{try{n(e=>({...e,[t]:!0}));let{files:r}=await O({file:e}),i=r[0].url,o=[{key:`pintura_${t}_url`,value:i}];await D(o),a.success(`Pintura ${t} uploaded`)}catch(e){k(e)}finally{n(e=>({...e,[t]:!1}))}};return(0,w.jsxs)(c,{cancelLabel:`Close`,dirty:M!==E,okLabel:A,okVariant:`default`,testId:`pintura-modal`,title:``,onClose:()=>{e(`integrations`)},onOk:P,children:[(0,w.jsx)(b,{detail:`Advanced image editing`,icon:(0,w.jsx)(x,{name:`pintura`,size:48}),title:`Pintura`}),(0,w.jsxs)(`div`,{className:`mt-7`,children:[!T.pintura&&(0,w.jsxs)(`div`,{className:`mb-7 flex flex-col items-stretch justify-between gap-4 rounded-sm bg-grey-50 p-4 md:flex-row md:p-7 dark:bg-grey-950`,children:[(0,w.jsxs)(`div`,{className:`md:basis-1/2`,children:[(0,w.jsx)(`p`,{className:`mb-4 text-md font-semibold`,children:`Add advanced image editing to Ghost, with Pintura`}),(0,w.jsx)(`p`,{className:`mb-4`,children:`Pintura is a powerful JavaScript image editor that allows you to crop, rotate, annotate and modify images directly inside Ghost.`}),(0,w.jsx)(`p`,{children:`Try a demo, purchase a license, and download the required CSS/JS files from pqina.nl/pintura/ to activate this feature.`})]}),(0,w.jsxs)(`div`,{className:`flex grow flex-col items-end justify-between gap-2 md:basis-1/2`,children:[(0,w.jsx)(`img`,{alt:`Pintura screenshot`,src:``+new URL(`pintura-screenshot-DTzk1LjU.png`,import.meta.url).href}),(0,w.jsx)(`a`,{className:`-mb-1 font-medium text-green`,href:`https://pqina.nl/pintura/ghost/?ref=ghost.org`,rel:`noopener noreferrer`,target:`_blank`,children:`Find out more →`})]})]}),(0,w.jsxs)(d,{className:`gap-0`,children:[(0,w.jsx)(h,{className:`mb-3 text-md! leading-supertight font-bold md:text-lg!`,children:`Pintura configuration`}),(0,w.jsxs)(u,{className:`gap-8 rounded-sm border border-border-default p-4 md:p-7`,children:[(0,w.jsxs)(g,{orientation:`horizontal`,children:[(0,w.jsxs)(f,{children:[(0,w.jsx)(p,{htmlFor:`pintura-enabled`,children:`Enable Pintura`}),(0,w.jsxs)(m,{children:[`Enable `,(0,w.jsx)(`a`,{className:`text-green`,href:`https://pqina.nl/pintura/ghost/?ref=ghost.org`,rel:`noopener noreferrer`,target:`_blank`,children:`Pintura`}),` for editing your images in Ghost`]})]}),(0,w.jsx)(o,{checked:M,id:`pintura-enabled`,onCheckedChange:N})]}),M&&!T.pintura&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`flex flex-col justify-between gap-1 md:flex-row md:items-center`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{children:`Upload Pintura script`}),(0,w.jsxs)(`div`,{className:`text-sm text-grey-600`,children:[`Upload the `,(0,w.jsx)(`code`,{children:`pintura-umd.js`}),` file from the Pintura package`]})]}),(0,w.jsx)(s,{accept:{"text/javascript":[`.js`],"application/javascript":[`.js`]},disabled:t.js,variant:`button`,onDropAccepted:e=>F(e[0],`js`),children:t.js?`Uploading...`:`Upload`})]}),(0,w.jsxs)(`div`,{className:`flex flex-col justify-between gap-1 md:flex-row md:items-center`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{children:`Upload Pintura styles`}),(0,w.jsxs)(`div`,{className:`text-sm text-grey-600`,children:[`Upload the `,(0,w.jsx)(`code`,{children:`pintura.css`}),` file from the Pintura package`]})]}),(0,w.jsx)(s,{accept:{"text/css":[`.css`]},disabled:t.css,variant:`button`,onDropAccepted:e=>F(e[0],`css`),children:t.css?`Uploading...`:`Upload`})]})]})]})]})]})]})}export{T as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{m as r,n as i}from"./hooks-D6EE7BIt.js";import{n as a}from"./dist-Ndy-PuGN.js";import{t as o}from"./switch-CE2NuMn-.js";import{t as s}from"./dropzone-CzhP33wa.js";import{o as c,t as l}from"./use-settings-navigation-BmROPrls.js";import{a as u,c as d,n as f,o as p,r as m,s as h,t as g}from"./field-B3OPenbP.js";import{Nn as _,On as v}from"./index-DUXM0NlS.js";import{n as y}from"./global-data-provider-RzW6Bnlf.js";import{t as b}from"./integration-header-B4DyXV06.js";import{t as x}from"./brand-icon-09YqFZjV.js";``+new URL(`pintura-screenshot-DTzk1LjU.png`,import.meta.url).href;var S=e(t(),1),C=i({method:`POST`,path:()=>`/files/upload/`,body:({file:e})=>{let t=new FormData;return t.append(`file`,e),t}}),w=n();function T(){let{updateRoute:e}=l(),[t,n]=(0,S.useState)({js:!1,css:!1}),{settings:i,config:T}=y(),[E]=v(i,[`pintura`]),{mutateAsync:D}=_(),{mutateAsync:O}=C(),k=r();(0,S.useEffect)(()=>{N(E||!1)},[E]);let[A,j]=(0,S.useState)(`Save`),[M,N]=(0,S.useState)(!!E),P=async()=>{let e=[{key:`pintura`,value:M}];try{j(`Saving...`),await Promise.all([D(e),new Promise(e=>{setTimeout(e,1e3)})]),j(`Saved`)}catch(e){k(e)}finally{setTimeout(()=>j(`Save`),1e3)}},F=async(e,t)=>{try{n(e=>({...e,[t]:!0}));let{files:r}=await O({file:e}),i=r[0].url,o=[{key:`pintura_${t}_url`,value:i}];await D(o),a.success(`Pintura ${t} uploaded`)}catch(e){k(e)}finally{n(e=>({...e,[t]:!1}))}};return(0,w.jsxs)(c,{cancelLabel:`Close`,dirty:M!==E,okLabel:A,okVariant:`default`,testId:`pintura-modal`,title:``,onClose:()=>{e(`integrations`)},onOk:P,children:[(0,w.jsx)(b,{detail:`Advanced image editing`,icon:(0,w.jsx)(x,{name:`pintura`,size:48}),title:`Pintura`}),(0,w.jsxs)(`div`,{className:`mt-7`,children:[!T.pintura&&(0,w.jsxs)(`div`,{className:`mb-7 flex flex-col items-stretch justify-between gap-4 rounded-sm bg-grey-50 p-4 md:flex-row md:p-7 dark:bg-grey-950`,children:[(0,w.jsxs)(`div`,{className:`md:basis-1/2`,children:[(0,w.jsx)(`p`,{className:`mb-4 text-md font-semibold`,children:`Add advanced image editing to Ghost, with Pintura`}),(0,w.jsx)(`p`,{className:`mb-4`,children:`Pintura is a powerful JavaScript image editor that allows you to crop, rotate, annotate and modify images directly inside Ghost.`}),(0,w.jsx)(`p`,{children:`Try a demo, purchase a license, and download the required CSS/JS files from pqina.nl/pintura/ to activate this feature.`})]}),(0,w.jsxs)(`div`,{className:`flex grow flex-col items-end justify-between gap-2 md:basis-1/2`,children:[(0,w.jsx)(`img`,{alt:`Pintura screenshot`,src:``+new URL(`pintura-screenshot-DTzk1LjU.png`,import.meta.url).href}),(0,w.jsx)(`a`,{className:`-mb-1 font-medium text-green`,href:`https://pqina.nl/pintura/ghost/?ref=ghost.org`,rel:`noopener noreferrer`,target:`_blank`,children:`Find out more →`})]})]}),(0,w.jsxs)(d,{className:`gap-0`,children:[(0,w.jsx)(h,{className:`mb-3 text-md! leading-supertight font-bold md:text-lg!`,children:`Pintura configuration`}),(0,w.jsxs)(u,{className:`gap-8 rounded-sm border border-border-default p-4 md:p-7`,children:[(0,w.jsxs)(g,{orientation:`horizontal`,children:[(0,w.jsxs)(f,{children:[(0,w.jsx)(p,{htmlFor:`pintura-enabled`,children:`Enable Pintura`}),(0,w.jsxs)(m,{children:[`Enable `,(0,w.jsx)(`a`,{className:`text-green`,href:`https://pqina.nl/pintura/ghost/?ref=ghost.org`,rel:`noopener noreferrer`,target:`_blank`,children:`Pintura`}),` for editing your images in Ghost`]})]}),(0,w.jsx)(o,{checked:M,id:`pintura-enabled`,onCheckedChange:N})]}),M&&!T.pintura&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`flex flex-col justify-between gap-1 md:flex-row md:items-center`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{children:`Upload Pintura script`}),(0,w.jsxs)(`div`,{className:`text-sm text-grey-600`,children:[`Upload the `,(0,w.jsx)(`code`,{children:`pintura-umd.js`}),` file from the Pintura package`]})]}),(0,w.jsx)(s,{accept:{"text/javascript":[`.js`],"application/javascript":[`.js`]},disabled:t.js,variant:`button`,onDropAccepted:e=>F(e[0],`js`),children:t.js?`Uploading...`:`Upload`})]}),(0,w.jsxs)(`div`,{className:`flex flex-col justify-between gap-1 md:flex-row md:items-center`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{children:`Upload Pintura styles`}),(0,w.jsxs)(`div`,{className:`text-sm text-grey-600`,children:[`Upload the `,(0,w.jsx)(`code`,{children:`pintura.css`}),` file from the Pintura package`]})]}),(0,w.jsx)(s,{accept:{"text/css":[`.css`]},disabled:t.css,variant:`button`,onDropAccepted:e=>F(e[0],`css`),children:t.css?`Uploading...`:`Upload`})]})]})]})]})]})]})}export{T as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./inline-Cw-gigDW.js";import{ar as i}from"./index-BHy2DZX-.js";var a=e(t(),1),o=n(),s=({href:e,onDestroyed:t,selectedTab:n,portalParent:s})=>{n||=`signup`;let c=(0,a.useRef)(null),[l,u]=(0,a.useState)(!1),[d,f]=(0,a.useState)(!0),p=(0,a.useCallback)(()=>{setTimeout(()=>{c.current&&f(!1)},300)},[c]);if((0,a.useEffect)(()=>{let n=t=>{e&&new URL(t.origin).origin===new URL(e).origin&&t?.data?.type===`portal-preview-ready`&&p()};return window.addEventListener(`message`,n,!0),()=>{window.removeEventListener(`message`,n,!0),t?.()}},[e,t,p,l]),!e)return null;let m=`mt-[-7%] flex h-screen items-center justify-center`,h=`hidden`;return s===`preview`?(m=`pointer-events-none absolute inset-0 z-50`,h=`invisible`):s===`offers`&&(m=`absolute inset-0 z-50`,h=`invisible`),(0,o.jsxs)(o.Fragment,{children:[d&&(0,o.jsx)(r,{align:`center`,className:m,justify:`center`,children:(0,o.jsx)(i,{size:`lg`})}),(0,o.jsx)(`iframe`,{ref:c,className:!d&&l?``:h,"data-testid":`portal-preview`,height:`100%`,src:e,title:`Portal Preview`,width:`100%`,onLoad:()=>{u(!0)}})]})};export{s as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{t}from"./react-Bb3IsNbi.js";import{t as n}from"./jsx-runtime-DX3WBWVO.js";import{t as r}from"./inline-Cw-gigDW.js";import{ar as i}from"./index-DUXM0NlS.js";var a=e(t(),1),o=n(),s=({href:e,onDestroyed:t,selectedTab:n,portalParent:s})=>{n||=`signup`;let c=(0,a.useRef)(null),[l,u]=(0,a.useState)(!1),[d,f]=(0,a.useState)(!0),p=(0,a.useCallback)(()=>{setTimeout(()=>{c.current&&f(!1)},300)},[c]);if((0,a.useEffect)(()=>{let n=t=>{e&&new URL(t.origin).origin===new URL(e).origin&&t?.data?.type===`portal-preview-ready`&&p()};return window.addEventListener(`message`,n,!0),()=>{window.removeEventListener(`message`,n,!0),t?.()}},[e,t,p,l]),!e)return null;let m=`mt-[-7%] flex h-screen items-center justify-center`,h=`hidden`;return s===`preview`?(m=`pointer-events-none absolute inset-0 z-50`,h=`invisible`):s===`offers`&&(m=`absolute inset-0 z-50`,h=`invisible`),(0,o.jsxs)(o.Fragment,{children:[d&&(0,o.jsx)(r,{align:`center`,className:m,justify:`center`,children:(0,o.jsx)(i,{size:`lg`})}),(0,o.jsx)(`iframe`,{ref:c,className:!d&&l?``:h,"data-testid":`portal-preview`,height:`100%`,src:e,title:`Portal Preview`,width:`100%`,onLoad:()=>{u(!0)}})]})};export{s as t};