@anker-in/campaign-ui 0.5.0-beta.10 → 0.5.0-beta.11

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.
@@ -1,2 +1,2 @@
1
- "use strict";"use client";var B=Object.create;var g=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var K=(e,i)=>{for(var n in i)g(e,n,{get:i[n],enumerable:!0})},M=(e,i,n,u)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of q(i))!J.call(e,l)&&l!==n&&g(e,l,{get:()=>i[l],enumerable:!(u=W(i,l))||u.enumerable});return e};var d=(e,i,n)=>(n=e!=null?B(G(e)):{},M(i||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),Q=e=>M(g({},"__esModule",{value:!0}),e);var pe={};K(pe,{MemberPopup:()=>re});module.exports=Q(pe);var t=require("react/jsx-runtime"),r=require("react"),O=require("@anker-in/headless-ui"),f=require("@anker-in/lib"),s=require("./type"),A=require("./context/provider"),V=require("./context/provider"),R=require("./context/viewStack"),a=require("./icons"),H=require("../../constants");const X=(0,r.lazy)(()=>import("./panels/EarnCredits")),Y=(0,r.lazy)(()=>import("./panels/ConsumeCredits")),Z=(0,r.lazy)(()=>import("./panels/Referral")),$=(0,r.lazy)(()=>import("./panels/EarnCredits/CompleteProfilePanel")),ee=(0,r.lazy)(()=>import("./panels/ActivitiesSubscribePanel")),te=(0,r.lazy)(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),se=(0,r.lazy)(()=>import("./panels/EarnCredits/ActivatePanel")),oe=(0,r.lazy)(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function re({copy:e,bottomOffset:i="24px",...n}){return(0,t.jsx)(A.MemberPopupProvider,{...n,earnCreditsCopy:e.earnCredits,children:(0,t.jsx)(ie,{copy:e,bottomOffset:i})})}function ie({copy:e,bottomOffset:i}){const{profile:n,openSignInPopup:u,openSignUpPopup:l}=(0,V.useMemberPopupContext)(),{brand:x,storeDomain:C}=(0,f.useHeadlessContext)(),v=H.ROUNDED_BRANDS.includes(x),z=!!n,[S,w]=(0,r.useState)(!1),[h,P]=(0,r.useState)([]),[E,T]=(0,r.useState)(!1),[j,_]=(0,r.useState)(!1),[D,F]=(0,r.useState)(!1),[L,N]=(0,r.useState)(!1),o=h[h.length-1]??null;if(!(0,r.useMemo)(()=>{const p=e.pageConfig;if(!p)return!0;const m=typeof window<"u"?window.location.pathname:"",I=p.pages.some(k=>m===k||m.startsWith(k+"/"));switch(p.scope){case s.MemberPopupPageScope.Include:return I;case s.MemberPopupPageScope.Exclude:return!I;default:return!0}},[e.pageConfig]))return null;const b=(0,r.useCallback)(p=>{P(m=>[...m,p])},[]),c=(0,r.useCallback)(()=>{P(p=>p.slice(0,-1))},[]);function U(p,m){switch(p){case s.MemberPopupActionType.ExternalLink:m&&window.open(m,"_blank","noopener,noreferrer");break;case s.MemberPopupActionType.OpenEarnCredits:b({type:s.MemberPopupPanelType.EarnCredits});break;case s.MemberPopupActionType.OpenConsumeCredits:b({type:s.MemberPopupPanelType.ConsumeCredits});break;case s.MemberPopupActionType.OpenReferral:b({type:s.MemberPopupPanelType.Referral});break;case s.MemberPopupActionType.OpenSubscribe:b({type:s.MemberPopupPanelType.Subscribe});break}}function y(){w(!1),P([]),N(!1)}return(0,t.jsxs)(R.ViewStackContext.Provider,{value:{pushView:b,popView:c},children:[S&&(0,t.jsx)("div",{className:"fixed inset-0 z-[998]",onClick:y}),(0,t.jsxs)("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:i},children:[S&&(0,t.jsxs)("div",{className:(0,f.classNames)("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",v?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:p=>p.stopPropagation(),children:[(0,t.jsx)("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),(0,t.jsxs)("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[o!==null&&(0,t.jsx)("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:c,"aria-label":"Back",children:(0,t.jsx)(a.IconSwitch,{})}),(0,t.jsx)("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:y,"aria-label":"Close",children:(0,t.jsx)(a.IconClose,{})})]}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[o===null&&(0,t.jsxs)(t.Fragment,{children:[(e.title||e.subtitle)&&(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[e.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((p,m)=>(0,t.jsx)(ne,{item:p,onAction:U,rounded:v},m))]}),o!==null&&(0,t.jsxs)(r.Suspense,{fallback:(0,t.jsx)("div",{className:"flex items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[o.type===s.MemberPopupPanelType.EarnCredits&&e.earnCredits&&(0,t.jsx)(X,{copy:e.earnCredits,onClose:c,isSubscribeSuccess:E,isActivateSuccess:j,isProfileCompleteSuccess:D,onSubscribeSuccess:()=>T(!0),onActivateSuccess:()=>_(!0),onProfileCompleteSuccess:()=>F(!0)}),o.type===s.MemberPopupPanelType.ConsumeCredits&&e.consumeCredits&&(0,t.jsx)(Y,{copy:e.consumeCredits,onClose:c}),o.type===s.MemberPopupPanelType.Referral&&e.referral&&(0,t.jsx)(Z,{copy:e.referral,onClose:c}),o.type===s.MemberPopupPanelType.CompleteProfile&&e.earnCredits&&(0,t.jsx)($,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:C,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.Subscribe&&e.activitiesSubscribe&&(0,t.jsx)(ee,{copy:e.activitiesSubscribe,email:n?.email,onSuccess:o.props?.onSuccess,hideForm:L,onHideForm:()=>N(!0)}),o.type===s.MemberPopupPanelType.SubscribeEmail&&e.earnCredits&&(0,t.jsx)(te,{copy:e.earnCredits.subscribe,email:n?.email,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.Activate&&e.earnCredits&&(0,t.jsx)(se,{copy:e.earnCredits.authCodeActivate,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.RedeemCoupon&&o.props&&e.consumeCredits&&(0,t.jsx)(oe,{itemTitle:o.props.itemTitle,itemCredits:o.props.itemCredits,itemImage:o.props.itemImage,itemValue:o.props.itemValue,itemOff:o.props.itemOff,itemRules:o.props.itemRules,redeemId:o.props.redeemId,userId:o.props.userId,alpcConfig:o.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.pointUnit,onClose:c})]})]}),e.footer&&!z&&(0,t.jsx)("div",{className:"border-t border-[#dadce0] p-[16px]",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-[16px]",children:[(0,t.jsxs)("div",{className:"flex items-center gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),(0,t.jsx)("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:u,children:e.footer.loginLabel})]}),(0,t.jsx)("div",{className:"flex shrink-0 items-center gap-[8px]",children:(0,t.jsx)("button",{className:(0,f.classNames)("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",v?"rounded-[4px]":"rounded-none"),onClick:l,children:e.footer.joinLabel})})]})})]}),(0,t.jsx)("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>w(p=>!p),"aria-label":e.triggerImg.alt??"Open member popup",children:(0,t.jsx)(O.Picture,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function ne({item:e,onAction:i,rounded:n}){const u={[s.MemberPopupActionType.OpenEarnCredits]:a.IconCredit,[s.MemberPopupActionType.OpenConsumeCredits]:a.IconBag,[s.MemberPopupActionType.OpenReferral]:a.IconReferral,[s.MemberPopupActionType.OpenSubscribe]:a.IconSubscription};return(0,t.jsxs)("div",{className:(0,f.classNames)("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",n?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[(0,t.jsx)("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&(0,t.jsx)("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),(0,t.jsx)("div",{className:"flex flex-col gap-[16px]",children:e.links.map((l,x)=>{const C=u[l.type];return(0,t.jsxs)("div",{children:[x>0&&(0,t.jsx)("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),(0,t.jsxs)("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>i(l.type,l.url),children:[C&&(0,t.jsx)(C,{className:"size-[24px] shrink-0"}),(0,t.jsx)("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:l.label}),(0,t.jsx)(a.IconArrow,{className:"size-[16px] shrink-0"})]})]},x)})})]})}
1
+ "use strict";"use client";var W=Object.create;var g=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var Q=(e,i)=>{for(var n in i)g(e,n,{get:i[n],enumerable:!0})},O=(e,i,n,u)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of G(i))!K.call(e,l)&&l!==n&&g(e,l,{get:()=>i[l],enumerable:!(u=q(i,l))||u.enumerable});return e};var d=(e,i,n)=>(n=e!=null?W(J(e)):{},O(i||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),X=e=>O(g({},"__esModule",{value:!0}),e);var ae={};Q(ae,{MemberPopup:()=>ie});module.exports=X(ae);var t=require("react/jsx-runtime"),r=require("react"),V=require("@anker-in/headless-ui"),f=require("@anker-in/lib"),s=require("./type"),R=require("./context/provider"),H=require("./context/provider"),z=require("./context/viewStack"),a=require("./icons"),E=require("../../constants");const Y=(0,r.lazy)(()=>import("./panels/EarnCredits")),Z=(0,r.lazy)(()=>import("./panels/ConsumeCredits")),$=(0,r.lazy)(()=>import("./panels/Referral")),ee=(0,r.lazy)(()=>import("./panels/EarnCredits/CompleteProfilePanel")),te=(0,r.lazy)(()=>import("./panels/ActivitiesSubscribePanel")),se=(0,r.lazy)(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),oe=(0,r.lazy)(()=>import("./panels/EarnCredits/ActivatePanel")),re=(0,r.lazy)(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function ie({copy:e,bottomOffset:i="24px",...n}){return(0,t.jsx)(R.MemberPopupProvider,{...n,earnCreditsCopy:e.earnCredits,children:(0,t.jsx)(ne,{copy:e,bottomOffset:i})})}function ne({copy:e,bottomOffset:i}){const{profile:n,openSignInPopup:u,openSignUpPopup:l}=(0,H.useMemberPopupContext)(),{brand:x,storeDomain:C}=(0,f.useHeadlessContext)(),v=E.ROUNDED_BRANDS.includes(x),T=!!n,[P,w]=(0,r.useState)(!1),[h,S]=(0,r.useState)([]),[j,_]=(0,r.useState)(!1),[N,D]=(0,r.useState)(!1),[F,L]=(0,r.useState)(!1),[U,y]=(0,r.useState)(!1),o=h[h.length-1]??null,I=(0,r.useMemo)(()=>{const p=e.pageConfig;if(!p)return!0;const m=typeof window<"u"?window.location.pathname:"",M=p.pages.some(A=>m===A||m.startsWith(A+"/"));switch(p.scope){case s.MemberPopupPageScope.Include:return M;case s.MemberPopupPageScope.Exclude:return!M;default:return!0}},[e.pageConfig]),b=(0,r.useCallback)(p=>{S(m=>[...m,p])},[]),c=(0,r.useCallback)(()=>{S(p=>p.slice(0,-1))},[]);if(console.log("isVisible",I),!I)return null;function B(p,m){switch(p){case s.MemberPopupActionType.ExternalLink:m&&window.open(m,"_blank","noopener,noreferrer");break;case s.MemberPopupActionType.OpenEarnCredits:b({type:s.MemberPopupPanelType.EarnCredits});break;case s.MemberPopupActionType.OpenConsumeCredits:b({type:s.MemberPopupPanelType.ConsumeCredits});break;case s.MemberPopupActionType.OpenReferral:b({type:s.MemberPopupPanelType.Referral});break;case s.MemberPopupActionType.OpenSubscribe:b({type:s.MemberPopupPanelType.Subscribe});break}}function k(){w(!1),S([]),y(!1)}return(0,t.jsxs)(z.ViewStackContext.Provider,{value:{pushView:b,popView:c},children:[P&&(0,t.jsx)("div",{className:"fixed inset-0 z-[998]",onClick:k}),(0,t.jsxs)("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:i},children:[P&&(0,t.jsxs)("div",{className:(0,f.classNames)("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",v?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:p=>p.stopPropagation(),children:[(0,t.jsx)("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),(0,t.jsxs)("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[o!==null&&(0,t.jsx)("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:c,"aria-label":"Back",children:(0,t.jsx)(a.IconSwitch,{})}),(0,t.jsx)("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:k,"aria-label":"Close",children:(0,t.jsx)(a.IconClose,{})})]}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[o===null&&(0,t.jsxs)(t.Fragment,{children:[(e.title||e.subtitle)&&(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[e.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((p,m)=>(0,t.jsx)(pe,{item:p,onAction:B,rounded:v},m))]}),o!==null&&(0,t.jsxs)(r.Suspense,{fallback:(0,t.jsx)("div",{className:"flex items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[o.type===s.MemberPopupPanelType.EarnCredits&&e.earnCredits&&(0,t.jsx)(Y,{copy:e.earnCredits,onClose:c,isSubscribeSuccess:j,isActivateSuccess:N,isProfileCompleteSuccess:F,onSubscribeSuccess:()=>_(!0),onActivateSuccess:()=>D(!0),onProfileCompleteSuccess:()=>L(!0)}),o.type===s.MemberPopupPanelType.ConsumeCredits&&e.consumeCredits&&(0,t.jsx)(Z,{copy:e.consumeCredits,onClose:c,isActivateSuccess:N}),o.type===s.MemberPopupPanelType.Referral&&e.referral&&(0,t.jsx)($,{copy:e.referral,onClose:c}),o.type===s.MemberPopupPanelType.CompleteProfile&&e.earnCredits&&(0,t.jsx)(ee,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:C,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.Subscribe&&e.activitiesSubscribe&&(0,t.jsx)(te,{copy:e.activitiesSubscribe,email:n?.email,onSuccess:o.props?.onSuccess,hideForm:U,onHideForm:()=>y(!0)}),o.type===s.MemberPopupPanelType.SubscribeEmail&&e.earnCredits&&(0,t.jsx)(se,{copy:e.earnCredits.subscribe,email:n?.email,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.Activate&&e.earnCredits&&(0,t.jsx)(oe,{copy:e.earnCredits.authCodeActivate,onClose:c,onSuccess:o.props?.onSuccess}),o.type===s.MemberPopupPanelType.RedeemCoupon&&o.props&&e.consumeCredits&&(0,t.jsx)(re,{itemTitle:o.props.itemTitle,itemCredits:o.props.itemCredits,itemImage:o.props.itemImage,itemValue:o.props.itemValue,itemOff:o.props.itemOff,itemRules:o.props.itemRules,redeemId:o.props.redeemId,userId:o.props.userId,alpcConfig:o.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.pointUnit,onClose:c})]})]}),e.footer&&!T&&(0,t.jsx)("div",{className:"border-t border-[#dadce0] p-[16px]",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-[16px]",children:[(0,t.jsxs)("div",{className:"flex items-center gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),(0,t.jsx)("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:u,children:e.footer.loginLabel})]}),(0,t.jsx)("div",{className:"flex shrink-0 items-center gap-[8px]",children:(0,t.jsx)("button",{className:(0,f.classNames)("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",v?"rounded-[4px]":"rounded-none"),onClick:l,children:e.footer.joinLabel})})]})})]}),(0,t.jsx)("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>w(p=>!p),"aria-label":e.triggerImg.alt??"Open member popup",children:(0,t.jsx)(V.Picture,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function pe({item:e,onAction:i,rounded:n}){const u={[s.MemberPopupActionType.OpenEarnCredits]:a.IconCredit,[s.MemberPopupActionType.OpenConsumeCredits]:a.IconBag,[s.MemberPopupActionType.OpenReferral]:a.IconReferral,[s.MemberPopupActionType.OpenSubscribe]:a.IconSubscription};return(0,t.jsxs)("div",{className:(0,f.classNames)("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",n?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[4px]",children:[(0,t.jsx)("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&(0,t.jsx)("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),(0,t.jsx)("div",{className:"flex flex-col gap-[16px]",children:e.links.map((l,x)=>{const C=u[l.type];return(0,t.jsxs)("div",{children:[x>0&&(0,t.jsx)("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),(0,t.jsxs)("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>i(l.type,l.url),children:[C&&(0,t.jsx)(C,{className:"size-[24px] shrink-0"}),(0,t.jsx)("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:l.label}),(0,t.jsx)(a.IconArrow,{className:"size-[16px] shrink-0"})]})]},x)})})]})}
2
2
  //# sourceMappingURL=MemberPopup.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/memberPopup/MemberPopup.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n return (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n )\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n if (!isVisible) return null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n onSubscribeSuccess={() => setIsSubscribeSuccess(true)}\n onActivateSuccess={() => setIsActivateSuccess(true)}\n onProfileCompleteSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits copy={copy.consumeCredits} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={currentView.props?.onSuccess}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.pointUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
5
- "mappings": "ukBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,iBAAAE,KAAA,eAAAC,EAAAH,IAqCM,IAAAI,EAAA,6BAnCNC,EAA+D,iBAC/DC,EAAwB,iCACxBC,EAA0E,yBAC1EC,EAOO,kBACPC,EAAoC,8BACpCA,EAAsC,8BACtCC,EAAmD,+BACnDC,EAAsG,mBACtGC,EAA+B,2BAE/B,MAAMC,KAAc,QAAK,IAAM,OAAO,sBAAsB,CAAC,EACvDC,KAAiB,QAAK,IAAM,OAAO,yBAAyB,CAAC,EAC7DC,KAAW,QAAK,IAAM,OAAO,mBAAmB,CAAC,EACjDC,KAAkB,QAAK,IAAM,OAAO,2CAA2C,CAAC,EAChFC,MAAsB,QAAK,IAAM,OAAO,mCAAmC,CAAC,EAC5EC,MAAiB,QAAK,IAAM,OAAO,0CAA0C,CAAC,EAC9EC,MAAW,QAAK,IAAM,OAAO,oCAAoC,CAAC,EAClEC,MAAe,QAAK,IAAM,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AEnC,mBAAC,WAAQ,OAAQA,EAAK,WAAW,IAAK,IAAKA,EAAK,WAAW,KAAO,GAAI,UAAU,cAAc,EAChG,GACF,GACF,CAEJ,CAQA,SAASwC,GAAS,CAAE,KAAAF,EAAM,SAAAG,EAAU,QAAAhC,CAAQ,EAAkB,CAC5D,MAAMiC,EAAyE,CAC7E,CAAC,wBAAsB,eAAe,EAAG,aACzC,CAAC,wBAAsB,kBAAkB,EAAG,UAC5C,CAAC,wBAAsB,YAAY,EAAG,eACtC,CAAC,wBAAsB,aAAa,EAAG,kBACzC,EAEA,SACE,QAAC,OAAI,aAAW,EAAAN,YAAG,iDAAkD3B,EAAU,gBAAkB,cAAc,EAC7G,qBAAC,OAAI,UAAU,0BACb,oBAAC,MAAG,UAAU,sDAAuD,SAAA6B,EAAK,MAAM,EAC/EA,EAAK,gBAAe,OAAC,KAAE,UAAU,uDAAwD,SAAAA,EAAK,YAAY,GAC7G,KAEA,OAAC,OAAI,UAAU,2BACZ,SAAAA,EAAK,MAAM,IAAI,CAACK,EAAMJ,IAAM,CAC3B,MAAMK,EAAgBF,EAAYC,EAAK,IAAI,EAC3C,SACE,QAAC,OACE,UAAAJ,EAAI,MAAK,OAAC,OAAI,UAAU,8BAA8B,KACvD,QAAC,UACC,UAAU,qDACV,QAAS,IAAME,EAASE,EAAK,KAAMA,EAAK,GAAG,EAE1C,UAAAC,MAAiB,OAACA,EAAA,CAAc,UAAU,uBAAuB,KAClE,OAAC,QAAK,UAAU,yDAA0D,SAAAD,EAAK,MAAM,KACrF,OAAC,aAAU,UAAU,uBAAuB,GAC9C,IATQJ,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
6
- "names": ["MemberPopup_exports", "__export", "MemberPopup", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_type", "import_provider", "import_viewStack", "import_icons", "import_constants", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "copy", "bottomOffset", "providerProps", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "config", "pathname", "matches", "page", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "cn", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
4
+ "sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n return (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n )\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n console.log('isVisible', isVisible)\n if (!isVisible) return null\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n onSubscribeSuccess={() => setIsSubscribeSuccess(true)}\n onActivateSuccess={() => setIsActivateSuccess(true)}\n onProfileCompleteSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={currentView.props?.onSuccess}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.pointUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
5
+ "mappings": "ukBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,iBAAAE,KAAA,eAAAC,EAAAH,IAqCM,IAAAI,EAAA,6BAnCNC,EAA+D,iBAC/DC,EAAwB,iCACxBC,EAA0E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MAAK,OAAC,OAAI,UAAU,8BAA8B,KACvD,QAAC,UACC,UAAU,qDACV,QAAS,IAAME,EAASE,EAAK,KAAMA,EAAK,GAAG,EAE1C,UAAAC,MAAiB,OAACA,EAAA,CAAc,UAAU,uBAAuB,KAClE,OAAC,QAAK,UAAU,yDAA0D,SAAAD,EAAK,MAAM,KACrF,OAAC,aAAU,UAAU,uBAAuB,GAC9C,IATQJ,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
6
+ "names": ["MemberPopup_exports", "__export", "MemberPopup", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_type", "import_provider", "import_viewStack", "import_icons", "import_constants", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "copy", "bottomOffset", "providerProps", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "isVisible", "config", "pathname", "matches", "page", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "cn", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
7
7
  }
@@ -2,6 +2,7 @@ import { type ConsumeCreditsopy } from '../../type';
2
2
  type Props = {
3
3
  copy: ConsumeCreditsopy;
4
4
  onClose: () => void;
5
+ isActivateSuccess: boolean;
5
6
  };
6
- declare function ConsumeCredits({ copy, onClose }: Props): import("react/jsx-runtime").JSX.Element;
7
+ declare function ConsumeCredits({ copy, isActivateSuccess, onClose }: Props): import("react/jsx-runtime").JSX.Element;
7
8
  export default ConsumeCredits;
@@ -1,2 +1,2 @@
1
- "use strict";var I=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var K=(a,r)=>{for(var s in r)I(a,s,{get:r[s],enumerable:!0})},Q=(a,r,s,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of q(r))!J.call(a,p)&&p!==s&&I(a,p,{get:()=>r[p],enumerable:!(l=H(r,p))||l.enumerable});return a};var W=a=>Q(I({},"__esModule",{value:!0}),a);var Z={};K(Z,{default:()=>Y});module.exports=W(Z);var t=require("react/jsx-runtime"),f=require("react"),v=require("@anker-in/headless-ui"),o=require("@anker-in/lib"),B=require("../../context/provider"),D=require("../../context/viewStack"),S=require("./hooks/useRedeemableList"),A=require("./hooks/useRedeemAndBuy"),n=require("../../type"),c=require("../../../credits/context/utils"),U=require("../../../../constants");function X({copy:a,onClose:r}){const{profile:s,creditInfo:l,openSignUpPopup:p,alpcConfig:b}=(0,B.useMemberPopupContext)(),{pushView:P}=(0,D.useViewStack)(),{brand:L}=(0,o.useHeadlessContext)(),N=U.ROUNDED_BRANDS.includes(L),[y,k]=(0,f.useState)(""),[M,w]=(0,f.useState)(null),[O,E]=(0,f.useState)(!1),x=!!s,{redeemableList:R,listLoading:$}=(0,S.useRedeemableList)(b),{trigger:z}=(0,A.useRedeemAndBuy)(b),F=a.list.map(e=>e.product?.handle).filter(Boolean),{data:_}=(0,o.useProductsByHandles)({handles:F}),T=(0,f.useMemo)(()=>a.list.map(e=>{const i=R.find(m=>String(m.id)===String(e.redeemId));if(!i)return null;const d=Number(l?.available_credit??0),C=x&&!!s?.activated&&i.consume_credits>d,g=i.is_limited&&(!i.remaining_inventory||i.remaining_inventory<=0);let u,h;return(e.type===n.ConsumeCreditsItemType.RedeemAndBuy||e.type===n.ConsumeCreditsItemType.Product)&&e.product&&(u=_?.find(m=>m.handle===e.product.handle),h=u?.variants?.find(m=>m.sku===e.product.sku)??u?.variants?.[0],e.type===n.ConsumeCreditsItemType.RedeemAndBuy&&(!u||!h))?null:{...e,alpcData:i,insufficient:C,soldOut:g,product:u,variant:h}}).filter(Boolean),[a.list,R,l,s,x,_]);function V(e){return x?e.soldOut?a.soldOut:a.btnRedeem:a.unlockRewards}function j(e){return e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product?e.insufficient:e.soldOut||e.insufficient}async function G(e){if(!x){p();return}if(!s?.activated&&!O){P({type:n.MemberPopupPanelType.Activate,props:{onSuccess:()=>E(!0)}});return}if(e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product){a.creditsPage?.url&&window.open(a.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===n.ConsumeCreditsItemType.Coupon)P({type:n.MemberPopupPanelType.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:a.imageMapping?.[e.type]?{url:a.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:a.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:s?.user_id,alpcConfig:b}});else{k(""),w(e.redeemId);try{await z({productVariant:e.variant,redeemId:Number(e.redeemId),userId:s?.user_id})}catch(i){k(i?.message??a.redeemModal.commonError)}finally{w(null)}}}return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px]",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[8px]",children:[a.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:a.title}),a.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:a.subtitle})]}),x&&(0,t.jsxs)("div",{className:(0,o.classNames)("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",N?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.balanceLabel??"AnkerCredits Balance"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,c.numberFormat)(l?.available_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??a.pointUnit??"ankercredits"})]})]}),(0,t.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.comingSoonLabel??"Coming Soon"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,c.numberFormat)(l?.pending_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??a.pointUnit??"ankercredits"}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]}),(0,t.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.comingSoonLabel??"Coming Soon"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,c.numberFormat)(l?.pending_credit??0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]}),y&&(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:y}),$?(0,t.jsx)("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):(0,t.jsx)("div",{className:"flex flex-col",children:T.map((e,i)=>{const d=!!e.product;return(0,t.jsxs)("div",{className:"relative py-[16px]",children:[i>0&&(0,t.jsx)("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex items-center gap-[12px]",children:[(()=>{const C=a.imageMapping?.[e.type]?.url,g=d?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:C??e.image?.url,u=d?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return g?(0,t.jsxs)("div",{className:(0,o.classNames)("relative size-[64px] shrink-0 overflow-hidden",N?"rounded-[4px]":"rounded-none"),children:[(0,t.jsx)(v.Picture,{source:g,alt:u,className:"flex size-full items-center justify-center",imgClassName:d?"object-cover":"h-full w-auto object-contain"}),!d&&e.value&&(0,t.jsxs)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",a.off]})]}):null})(),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:d&&e.product?.title?e.product.title:e.title}),(0,t.jsx)("div",{className:"mt-[4px] text-[14px] text-[#666]",children:d&&e.price!=null?`${(0,c.numberFormat)(e.alpcData.consume_credits)} ${a.pointUnit??""} + $${Number(e.price).toFixed(2)}`:`${(0,c.numberFormat)(e.alpcData.consume_credits)} ${a.pointUnit??""}`})]}),(0,t.jsxs)("div",{className:"relative group",children:[(0,t.jsx)(v.Button,{className:(0,o.classNames)("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",N?"rounded-[4px]":"rounded-none"),disabled:j(e),loading:M===e.redeemId,onClick:()=>G(e),children:V(e)}),e.insufficient&&(0,t.jsx)("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:(0,t.jsxs)("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[(0,t.jsx)("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:a.insufficientCredits}),(0,t.jsx)("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},i)})}),a.creditsPage?.url&&(0,t.jsx)("a",{href:a.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:a.creditsPage.label??"Go to Credits Page"})]})})}var Y=X;
1
+ "use strict";var y=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var J=(a,s)=>{for(var u in s)y(a,u,{get:s[u],enumerable:!0})},K=(a,s,u,l)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of H(s))!q.call(a,i)&&i!==u&&y(a,i,{get:()=>s[i],enumerable:!(l=G(s,i))||l.enumerable});return a};var Q=a=>K(y({},"__esModule",{value:!0}),a);var Y={};J(Y,{default:()=>X});module.exports=Q(Y);var t=require("react/jsx-runtime"),x=require("react"),v=require("@anker-in/headless-ui"),o=require("@anker-in/lib"),B=require("../../context/provider"),D=require("../../context/viewStack"),A=require("./hooks/useRedeemableList"),U=require("./hooks/useRedeemAndBuy"),n=require("../../type"),m=require("../../../credits/context/utils"),S=require("../../../../constants");function W({copy:a,isActivateSuccess:s,onClose:u}){const{profile:l,creditInfo:i,openSignUpPopup:L,alpcConfig:b}=(0,B.useMemberPopupContext)(),{pushView:I}=(0,D.useViewStack)(),{brand:M}=(0,o.useHeadlessContext)(),N=S.ROUNDED_BRANDS.includes(M),[P,R]=(0,x.useState)(""),[O,k]=(0,x.useState)(null),c=!!l,{redeemableList:w,listLoading:E}=(0,A.useRedeemableList)(b),{trigger:$}=(0,U.useRedeemAndBuy)(b),z=a.list.map(e=>e.product?.handle).filter(Boolean),{data:_}=(0,o.useProductsByHandles)({handles:z}),F=(0,x.useMemo)(()=>a.list.map(e=>{const r=w.find(f=>String(f.id)===String(e.redeemId));if(!r)return null;const d=Number(i?.available_credit??0),C=c&&!!l?.activated&&r.consume_credits>d,g=r.is_limited&&(!r.remaining_inventory||r.remaining_inventory<=0);let p,h;return(e.type===n.ConsumeCreditsItemType.RedeemAndBuy||e.type===n.ConsumeCreditsItemType.Product)&&e.product&&(p=_?.find(f=>f.handle===e.product.handle),h=p?.variants?.find(f=>f.sku===e.product.sku)??p?.variants?.[0],e.type===n.ConsumeCreditsItemType.RedeemAndBuy&&(!p||!h))?null:{...e,alpcData:r,insufficient:C,soldOut:g,product:p,variant:h}}).filter(Boolean),[a.list,w,i,l,c,_]);function T(e){return c?e.soldOut?a.soldOut:a.btnRedeem:a.unlockRewards}function V(e){return e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product?e.insufficient:e.soldOut||e.insufficient}async function j(e){if(!c){L();return}if(!l?.activated&&!s){I({type:n.MemberPopupPanelType.Activate,props:{}});return}if(e.type===n.ConsumeCreditsItemType.GiftCard||e.type===n.ConsumeCreditsItemType.Product){a.creditsPage?.url&&window.open(a.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===n.ConsumeCreditsItemType.Coupon)I({type:n.MemberPopupPanelType.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:a.imageMapping?.[e.type]?{url:a.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:a.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:l?.user_id,alpcConfig:b}});else{R(""),k(e.redeemId);try{await $({productVariant:e.variant,redeemId:Number(e.redeemId),userId:l?.user_id})}catch(r){R(r?.message??a.redeemModal.commonError)}finally{k(null)}}}return(0,t.jsx)(t.Fragment,{children:(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[12px]",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-[8px]",children:[a.title&&(0,t.jsx)("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:a.title}),a.subtitle&&(0,t.jsx)("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:a.subtitle})]}),c&&(0,t.jsxs)("div",{className:(0,o.classNames)("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",N?"rounded-[8px]":"rounded-none"),children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.balanceLabel??"AnkerCredits Balance"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,m.numberFormat)(i?.available_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??a.pointUnit??"ankercredits"})]})]}),(0,t.jsx)("div",{className:"h-full w-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-[4px]",children:[(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:a.comingSoonLabel??"Coming Soon"}),(0,t.jsxs)("div",{className:"flex items-end gap-[4px]",children:[(0,t.jsx)("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:(0,m.numberFormat)(i?.pending_credit||0)}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??a.pointUnit??"ankercredits"}),(0,t.jsx)("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:a.creditUnit??"ankercredits"})]})]})]}),P&&(0,t.jsx)("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:P}),E?(0,t.jsx)("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:(0,t.jsx)("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):(0,t.jsx)("div",{className:"flex flex-col",children:F.map((e,r)=>{const d=!!e.product;return(0,t.jsxs)("div",{className:"relative py-[16px]",children:[r>0&&(0,t.jsx)("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),(0,t.jsxs)("div",{className:"flex items-center gap-[12px]",children:[(()=>{const C=a.imageMapping?.[e.type]?.url,g=d?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:C??e.image?.url,p=d?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return g?(0,t.jsxs)("div",{className:(0,o.classNames)("relative size-[64px] shrink-0 overflow-hidden",N?"rounded-[4px]":"rounded-none"),children:[(0,t.jsx)(v.Picture,{source:g,alt:p,className:"flex size-full items-center justify-center",imgClassName:d?"object-cover":"h-full w-auto object-contain"}),!d&&e.value&&(0,t.jsxs)("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",a.off]})]}):null})(),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:d&&e.product?.title?e.product.title:e.title}),(0,t.jsx)("div",{className:"mt-[4px] text-[14px] text-[#666]",children:d&&e.price!=null?`${(0,m.numberFormat)(e.alpcData.consume_credits)} ${a.pointUnit??""} + $${Number(e.price).toFixed(2)}`:`${(0,m.numberFormat)(e.alpcData.consume_credits)} ${a.pointUnit??""}`})]}),(0,t.jsxs)("div",{className:"relative group",children:[(0,t.jsx)(v.Button,{className:(0,o.classNames)("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",N?"rounded-[4px]":"rounded-none"),disabled:V(e),loading:O===e.redeemId,onClick:()=>j(e),children:T(e)}),e.insufficient&&(0,t.jsx)("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:(0,t.jsxs)("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[(0,t.jsx)("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:a.insufficientCredits}),(0,t.jsx)("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},r)})}),a.creditsPage?.url&&(0,t.jsx)("a",{href:a.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:a.creditsPage.label??"Go to Credits Page"})]})})}var X=W;
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/components/memberPopup/panels/ConsumeCredits/index.tsx"],
4
- "sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n}\n\nfunction ConsumeCredits({ copy, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: { onSuccess: () => setIsActivateSuccess(true) },\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GA2II,IAAAI,EAAA,6BA3IJC,EAAkC,iBAClCC,EAAgC,iCAChCC,EAA2E,yBAC3EC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAAkC,qCAClCC,EAAgC,mCAChCC,EAKO,sBACPC,EAA6B,0CAE7BC,EAA+B,iCAe/B,SAASC,EAAe,CAAE,KAAAC,EAAM,QAAAC,CAAQ,EAAU,CAChD,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,CAAW,KAAI,yBAAsB,EAC7E,CAAE,SAAAC,CAAS,KAAI,gBAAa,EAC5B,CAAE,MAAAC,CAAM,KAAI,sBAAmB,EAC/BC,EAAU,iBAAe,SAASD,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,KAAI,YAAS,EAAE,EACvD,CAACC,EAAWC,CAAY,KAAI,YAAiC,IAAI,EACjE,CAACC,EAAmBC,CAAoB,KAAI,YAAS,EAAK,EAE1DC,EAAU,CAAC,CAACb,EACZ,CAAE,eAAAc,EAAgB,YAAAC,CAAY,KAAI,qBAAkBZ,CAAU,EAC9D,CAAE,QAASa,CAAa,KAAI,mBAAgBb,CAAU,EAEtDc,EAAUnB,EAAK,KAAK,IAAIoB,GAAQA,EAAK,SAAS,MAAM,EAAE,OAAO,OAAO,EACpE,CAAE,KAAMC,CAAS,KAAI,wBAAqB,CAAE,QAAAF,CAAQ,CAAC,EAErDG,KAAO,WAAQ,IACZtB,EAAK,KACT,IAAIoB,GAAQ,CACX,MAAMG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oBAAoB,KACpF,OAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQqC,CAiEV,CAEJ,CAAC,EACH,EAGDrC,EAAK,aAAa,QACjB,OAAC,KACC,KAAMA,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOd,EAAQa",
6
- "names": ["ConsumeCredits_exports", "__export", "ConsumeCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_provider", "import_viewStack", "import_useRedeemableList", "import_useRedeemAndBuy", "import_type", "import_utils", "import_constants", "ConsumeCredits", "copy", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isActivateSuccess", "setIsActivateSuccess", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "p", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "cn", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt"]
4
+ "sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GA2II,IAAAI,EAAA,6BA3IJC,EAAkC,iBAClCC,EAAgC,iCAChCC,EAA2E,yBAC3EC,EAAsC,kCACtCC,EAA6B,mCAC7BC,EAAkC,qCAClCC,EAAgC,mCAChCC,EAKO,sBACPC,EAA6B,0CAE7BC,EAA+B,iCAgB/B,SAASC,EAAe,CAAE,KAAAC,EAAM,kBAAAC,EAAmB,QAAAC,CAAQ,EAAU,CACnE,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,CAAW,KAAI,yBAAsB,EAC7E,CAAE,SAAAC,CAAS,KAAI,gBAAa,EAC5B,CAAE,MAAAC,CAAM,KAAI,sBAAmB,EAC/BC,EAAU,iBAAe,SAASD,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,KAAI,YAAS,EAAE,EACvD,CAACC,EAAWC,CAAY,KAAI,YAAiC,IAAI,EAEjEC,EAAU,CAAC,CAACX,EACZ,CAAE,eAAAY,EAAgB,YAAAC,CAAY,KAAI,qBAAkBV,CAAU,EAC9D,CAAE,QAASW,CAAa,KAAI,mBAAgBX,CAAU,EAEtDY,EAAUlB,EAAK,KAAK,IAAImB,GAAQA,EAAK,SAAS,MAAM,EAAE,OAAO,OAAO,EACpE,CAAE,KAAMC,CAAS,KAAI,wBAAqB,CAAE,QAAAF,CAAQ,CAAC,EAErDG,KAAO,WAAQ,IACZrB,EAAK,KACT,IAAImB,GAAQ,CACX,MAAMG,EAAWP,EAAe,KAAKQ,GAAK,OAAOA,EAAE,E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ACL,UAAU,6CACV,aAAcH,EAAa,eAAiB,+BAC9C,EACC,CAACA,GAAclB,EAAK,UACnB,QAAC,OAAI,UAAU,mFACZ,UAAAA,EAAK,MAAM,IAAEnB,EAAK,KACrB,GAEJ,EAnBkB,IAqBtB,GAAG,KACH,QAAC,OAAI,UAAU,iBACb,oBAAC,OAAI,UAAU,qDACZ,SAAAqC,GAAclB,EAAK,SAAS,MAAQA,EAAK,QAAQ,MAAQA,EAAK,MACjE,KACA,OAAC,OAAI,UAAU,mCACZ,SAAAkB,GAAclB,EAAK,OAAS,KACzB,MAAG,gBAAaA,EAAK,SAAS,eAAe,CAAC,IAAInB,EAAK,WAAa,EAAE,OAAO,OAAOmB,EAAK,KAAK,EAAE,QAAQ,CAAC,CAAC,GAC1G,MAAG,gBAAaA,EAAK,SAAS,eAAe,CAAC,IAAInB,EAAK,WAAa,EAAE,GAC5E,GACF,KACA,QAAC,OAAI,UAAU,iBACb,oBAAC,UACC,aAAW,EAAAmC,YACT,6FACA1B,EAAU,gBAAkB,cAC9B,EACA,SAAUuB,EAAWb,CAAI,EACzB,QAASP,IAAcO,EAAK,SAC5B,QAAS,IAAMc,EAAad,CAAI,EAE/B,SAAAY,EAAeZ,CAAI,EACtB,EACCA,EAAK,iBACJ,OAAC,OAAI,UAAU,qGACb,oBAAC,OAAI,UAAU,0EACb,oBAAC,KAAE,UAAU,6CAA8C,SAAAnB,EAAK,oBAAoB,KACpF,OAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQoC,CAiEV,CAEJ,CAAC,EACH,EAGDpC,EAAK,aAAa,QACjB,OAAC,KACC,KAAMA,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOd,EAAQa",
6
+ "names": ["ConsumeCredits_exports", "__export", "ConsumeCredits_default", "__toCommonJS", "import_jsx_runtime", "import_react", "import_headless_ui", "import_lib", "import_provider", "import_viewStack", "import_useRedeemableList", "import_useRedeemAndBuy", "import_type", "import_utils", "import_constants", "ConsumeCredits", "copy", "isActivateSuccess", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "p", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "cn", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use client";import{Fragment as ce,jsx as t,jsxs as r}from"react/jsx-runtime";import{lazy as l,Suspense as D,useState as d,useCallback as M,useMemo as F}from"react";import{Picture as L}from"@anker-in/headless-ui";import{useHeadlessContext as U,classNames as P}from"@anker-in/lib";import{MemberPopupActionType as a,MemberPopupPageScope as O,MemberPopupPanelType as i}from"./type";import{MemberPopupProvider as B}from"./context/provider";import{useMemberPopupContext as W}from"./context/provider";import{ViewStackContext as q}from"./context/viewStack";import{IconClose as G,IconArrow as J,IconCredit as K,IconBag as Q,IconReferral as X,IconSwitch as Y,IconSubscription as Z}from"./icons";import{ROUNDED_BRANDS as $}from"../../constants";const ee=l(()=>import("./panels/EarnCredits")),te=l(()=>import("./panels/ConsumeCredits")),se=l(()=>import("./panels/Referral")),oe=l(()=>import("./panels/EarnCredits/CompleteProfilePanel")),re=l(()=>import("./panels/ActivitiesSubscribePanel")),ie=l(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),ne=l(()=>import("./panels/EarnCredits/ActivatePanel")),pe=l(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function Se({copy:e,bottomOffset:u="24px",...c}){return t(B,{...c,earnCreditsCopy:e.earnCredits,children:t(ae,{copy:e,bottomOffset:u})})}function ae({copy:e,bottomOffset:u}){const{profile:c,openSignInPopup:C,openSignUpPopup:m}=W(),{brand:b,storeDomain:x}=U(),g=$.includes(b),A=!!c,[S,w]=d(!1),[h,v]=d([]),[V,R]=d(!1),[H,z]=d(!1),[E,T]=d(!1),[j,N]=d(!1),s=h[h.length-1]??null;if(!F(()=>{const o=e.pageConfig;if(!o)return!0;const p=typeof window<"u"?window.location.pathname:"",I=o.pages.some(k=>p===k||p.startsWith(k+"/"));switch(o.scope){case O.Include:return I;case O.Exclude:return!I;default:return!0}},[e.pageConfig]))return null;const f=M(o=>{v(p=>[...p,o])},[]),n=M(()=>{v(o=>o.slice(0,-1))},[]);function _(o,p){switch(o){case a.ExternalLink:p&&window.open(p,"_blank","noopener,noreferrer");break;case a.OpenEarnCredits:f({type:i.EarnCredits});break;case a.OpenConsumeCredits:f({type:i.ConsumeCredits});break;case a.OpenReferral:f({type:i.Referral});break;case a.OpenSubscribe:f({type:i.Subscribe});break}}function y(){w(!1),v([]),N(!1)}return r(q.Provider,{value:{pushView:f,popView:n},children:[S&&t("div",{className:"fixed inset-0 z-[998]",onClick:y}),r("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:u},children:[S&&r("div",{className:P("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",g?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:o=>o.stopPropagation(),children:[t("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),r("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[s!==null&&t("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:n,"aria-label":"Back",children:t(Y,{})}),t("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:y,"aria-label":"Close",children:t(G,{})})]}),r("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[s===null&&r(ce,{children:[(e.title||e.subtitle)&&r("div",{className:"flex flex-col gap-[4px]",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&t("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((o,p)=>t(le,{item:o,onAction:_,rounded:g},p))]}),s!==null&&r(D,{fallback:t("div",{className:"flex items-center justify-center py-[32px]",children:t("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[s.type===i.EarnCredits&&e.earnCredits&&t(ee,{copy:e.earnCredits,onClose:n,isSubscribeSuccess:V,isActivateSuccess:H,isProfileCompleteSuccess:E,onSubscribeSuccess:()=>R(!0),onActivateSuccess:()=>z(!0),onProfileCompleteSuccess:()=>T(!0)}),s.type===i.ConsumeCredits&&e.consumeCredits&&t(te,{copy:e.consumeCredits,onClose:n}),s.type===i.Referral&&e.referral&&t(se,{copy:e.referral,onClose:n}),s.type===i.CompleteProfile&&e.earnCredits&&t(oe,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:x,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.Subscribe&&e.activitiesSubscribe&&t(re,{copy:e.activitiesSubscribe,email:c?.email,onSuccess:s.props?.onSuccess,hideForm:j,onHideForm:()=>N(!0)}),s.type===i.SubscribeEmail&&e.earnCredits&&t(ie,{copy:e.earnCredits.subscribe,email:c?.email,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.Activate&&e.earnCredits&&t(ne,{copy:e.earnCredits.authCodeActivate,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.RedeemCoupon&&s.props&&e.consumeCredits&&t(pe,{itemTitle:s.props.itemTitle,itemCredits:s.props.itemCredits,itemImage:s.props.itemImage,itemValue:s.props.itemValue,itemOff:s.props.itemOff,itemRules:s.props.itemRules,redeemId:s.props.redeemId,userId:s.props.userId,alpcConfig:s.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.pointUnit,onClose:n})]})]}),e.footer&&!A&&t("div",{className:"border-t border-[#dadce0] p-[16px]",children:r("div",{className:"flex items-center justify-between gap-[16px]",children:[r("div",{className:"flex items-center gap-[4px]",children:[t("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),t("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:C,children:e.footer.loginLabel})]}),t("div",{className:"flex shrink-0 items-center gap-[8px]",children:t("button",{className:P("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",g?"rounded-[4px]":"rounded-none"),onClick:m,children:e.footer.joinLabel})})]})})]}),t("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>w(o=>!o),"aria-label":e.triggerImg.alt??"Open member popup",children:t(L,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function le({item:e,onAction:u,rounded:c}){const C={[a.OpenEarnCredits]:K,[a.OpenConsumeCredits]:Q,[a.OpenReferral]:X,[a.OpenSubscribe]:Z};return r("div",{className:P("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",c?"rounded-[8px]":"rounded-none"),children:[r("div",{className:"flex flex-col gap-[4px]",children:[t("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&t("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),t("div",{className:"flex flex-col gap-[16px]",children:e.links.map((m,b)=>{const x=C[m.type];return r("div",{children:[b>0&&t("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),r("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>u(m.type,m.url),children:[x&&t(x,{className:"size-[24px] shrink-0"}),t("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:m.label}),t(J,{className:"size-[16px] shrink-0"})]})]},b)})})]})}export{Se as MemberPopup};
1
+ "use client";import{Fragment as me,jsx as t,jsxs as r}from"react/jsx-runtime";import{lazy as l,Suspense as F,useState as d,useCallback as O,useMemo as L}from"react";import{Picture as U}from"@anker-in/headless-ui";import{useHeadlessContext as B,classNames as S}from"@anker-in/lib";import{MemberPopupActionType as a,MemberPopupPageScope as V,MemberPopupPanelType as i}from"./type";import{MemberPopupProvider as W}from"./context/provider";import{useMemberPopupContext as q}from"./context/provider";import{ViewStackContext as G}from"./context/viewStack";import{IconClose as J,IconArrow as K,IconCredit as Q,IconBag as X,IconReferral as Y,IconSwitch as Z,IconSubscription as $}from"./icons";import{ROUNDED_BRANDS as ee}from"../../constants";const te=l(()=>import("./panels/EarnCredits")),se=l(()=>import("./panels/ConsumeCredits")),oe=l(()=>import("./panels/Referral")),re=l(()=>import("./panels/EarnCredits/CompleteProfilePanel")),ie=l(()=>import("./panels/ActivitiesSubscribePanel")),ne=l(()=>import("./panels/EarnCredits/SubscribeEmailPanel")),pe=l(()=>import("./panels/EarnCredits/ActivatePanel")),ae=l(()=>import("./panels/ConsumeCredits/RedeemCouponPanel"));function Pe({copy:e,bottomOffset:u="24px",...c}){return t(W,{...c,earnCreditsCopy:e.earnCredits,children:t(le,{copy:e,bottomOffset:u})})}function le({copy:e,bottomOffset:u}){const{profile:c,openSignInPopup:C,openSignUpPopup:m}=q(),{brand:b,storeDomain:x}=B(),g=ee.includes(b),R=!!c,[P,w]=d(!1),[h,v]=d([]),[H,z]=d(!1),[N,E]=d(!1),[T,j]=d(!1),[_,y]=d(!1),s=h[h.length-1]??null,I=L(()=>{const o=e.pageConfig;if(!o)return!0;const p=typeof window<"u"?window.location.pathname:"",M=o.pages.some(A=>p===A||p.startsWith(A+"/"));switch(o.scope){case V.Include:return M;case V.Exclude:return!M;default:return!0}},[e.pageConfig]),f=O(o=>{v(p=>[...p,o])},[]),n=O(()=>{v(o=>o.slice(0,-1))},[]);if(console.log("isVisible",I),!I)return null;function D(o,p){switch(o){case a.ExternalLink:p&&window.open(p,"_blank","noopener,noreferrer");break;case a.OpenEarnCredits:f({type:i.EarnCredits});break;case a.OpenConsumeCredits:f({type:i.ConsumeCredits});break;case a.OpenReferral:f({type:i.Referral});break;case a.OpenSubscribe:f({type:i.Subscribe});break}}function k(){w(!1),v([]),y(!1)}return r(G.Provider,{value:{pushView:f,popView:n},children:[P&&t("div",{className:"fixed inset-0 z-[998]",onClick:k}),r("div",{className:"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0",style:{bottom:u},children:[P&&r("div",{className:S("relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]",g?"rounded-[12px]":"rounded-none"),style:{maxHeight:"min(80vh, 606px)"},onClick:o=>o.stopPropagation(),children:[t("div",{className:"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white"}),r("div",{className:"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]",children:[s!==null&&t("button",{className:"mr-auto flex size-[24px] cursor-pointer items-center justify-center",onClick:n,"aria-label":"Back",children:t(Z,{})}),t("button",{className:"flex size-[24px] cursor-pointer items-center justify-center",onClick:k,"aria-label":"Close",children:t(J,{})})]}),r("div",{className:"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]",children:[s===null&&r(me,{children:[(e.title||e.subtitle)&&r("div",{className:"flex flex-col gap-[4px]",children:[e.title&&t("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:e.title}),e.subtitle&&t("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:e.subtitle})]}),e.list.map((o,p)=>t(ce,{item:o,onAction:D,rounded:g},p))]}),s!==null&&r(F,{fallback:t("div",{className:"flex items-center justify-center py-[32px]",children:t("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}),children:[s.type===i.EarnCredits&&e.earnCredits&&t(te,{copy:e.earnCredits,onClose:n,isSubscribeSuccess:H,isActivateSuccess:N,isProfileCompleteSuccess:T,onSubscribeSuccess:()=>z(!0),onActivateSuccess:()=>E(!0),onProfileCompleteSuccess:()=>j(!0)}),s.type===i.ConsumeCredits&&e.consumeCredits&&t(se,{copy:e.consumeCredits,onClose:n,isActivateSuccess:N}),s.type===i.Referral&&e.referral&&t(oe,{copy:e.referral,onClose:n}),s.type===i.CompleteProfile&&e.earnCredits&&t(re,{copy:e.earnCredits.completeProfile,shopifyStoreDomain:x,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.Subscribe&&e.activitiesSubscribe&&t(ie,{copy:e.activitiesSubscribe,email:c?.email,onSuccess:s.props?.onSuccess,hideForm:_,onHideForm:()=>y(!0)}),s.type===i.SubscribeEmail&&e.earnCredits&&t(ne,{copy:e.earnCredits.subscribe,email:c?.email,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.Activate&&e.earnCredits&&t(pe,{copy:e.earnCredits.authCodeActivate,onClose:n,onSuccess:s.props?.onSuccess}),s.type===i.RedeemCoupon&&s.props&&e.consumeCredits&&t(ae,{itemTitle:s.props.itemTitle,itemCredits:s.props.itemCredits,itemImage:s.props.itemImage,itemValue:s.props.itemValue,itemOff:s.props.itemOff,itemRules:s.props.itemRules,redeemId:s.props.redeemId,userId:s.props.userId,alpcConfig:s.props.alpcConfig,copy:e.consumeCredits.redeemModal,pointUnit:e.consumeCredits.pointUnit,onClose:n})]})]}),e.footer&&!R&&t("div",{className:"border-t border-[#dadce0] p-[16px]",children:r("div",{className:"flex items-center justify-between gap-[16px]",children:[r("div",{className:"flex items-center gap-[4px]",children:[t("span",{className:"text-[14px] font-[700] text-[#080a0f]",children:e.footer.loginHint}),t("button",{className:"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline",onClick:C,children:e.footer.loginLabel})]}),t("div",{className:"flex shrink-0 items-center gap-[8px]",children:t("button",{className:S("cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]",g?"rounded-[4px]":"rounded-none"),onClick:m,children:e.footer.joinLabel})})]})})]}),t("button",{className:"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]",onClick:()=>w(o=>!o),"aria-label":e.triggerImg.alt??"Open member popup",children:t(U,{source:e.triggerImg.url,alt:e.triggerImg.alt??"",className:"size-[58px]"})})]})]})}function ce({item:e,onAction:u,rounded:c}){const C={[a.OpenEarnCredits]:Q,[a.OpenConsumeCredits]:X,[a.OpenReferral]:Y,[a.OpenSubscribe]:$};return r("div",{className:S("flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]",c?"rounded-[8px]":"rounded-none"),children:[r("div",{className:"flex flex-col gap-[4px]",children:[t("h3",{className:"text-[20px] font-[700] leading-[1.2] text-[#1e2024]",children:e.title}),e.description&&t("p",{className:"text-[14px] font-[700] leading-[1.43] text-[#1e2024]",children:e.description})]}),t("div",{className:"flex flex-col gap-[16px]",children:e.links.map((m,b)=>{const x=C[m.type];return r("div",{children:[b>0&&t("div",{className:"mb-[16px] h-px bg-[#dadce0]"}),r("button",{className:"flex w-full cursor-pointer items-center gap-[12px]",onClick:()=>u(m.type,m.url),children:[x&&t(x,{className:"size-[24px] shrink-0"}),t("span",{className:"flex-1 text-left text-[14px] font-[700] text-[#1e2024]",children:m.label}),t(K,{className:"size-[16px] shrink-0"})]})]},b)})})]})}export{Pe as MemberPopup};
2
2
  //# sourceMappingURL=MemberPopup.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/memberPopup/MemberPopup.tsx"],
4
- "sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n return (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n )\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n if (!isVisible) return null\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n onSubscribeSuccess={() => setIsSubscribeSuccess(true)}\n onActivateSuccess={() => setIsActivateSuccess(true)}\n onProfileCompleteSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits copy={copy.consumeCredits} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={currentView.props?.onSuccess}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.pointUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
5
- "mappings": "aAqCM,OAiHU,YAAAA,GAjHV,OAAAC,EA4FM,QAAAC,MA5FN,oBAnCN,OAAS,QAAAC,EAAM,YAAAC,EAAU,YAAAC,EAAU,eAAAC,EAAa,WAAAC,MAAe,QAC/D,OAAS,WAAAC,MAAe,wBACxB,OAA8B,sBAAAC,EAAoB,cAAcC,MAAU,gBAC1E,OACE,yBAAAC,EACA,wBAAAC,EACA,wBAAAC,MAIK,SACP,OAAS,uBAAAC,MAA2B,qBACpC,OAAS,yBAAAC,MAA6B,qBACtC,OAAS,oBAAAC,MAA0C,sBACnD,OAAS,aAAAC,EAAW,aAAAC,EAAW,cAAAC,EAAY,WAAAC,EAAS,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/EA,EAAK,aAAetE,EAAC,KAAE,UAAU,uDAAwD,SAAAsE,EAAK,YAAY,GAC7G,EAEAtE,EAAC,OAAI,UAAU,2BACZ,SAAAsE,EAAK,MAAM,IAAI,CAACK,EAAMJ,IAAM,CAC3B,MAAMK,EAAgBF,EAAYC,EAAK,IAAI,EAC3C,OACE1E,EAAC,OACE,UAAAsE,EAAI,GAAKvE,EAAC,OAAI,UAAU,8BAA8B,EACvDC,EAAC,UACC,UAAU,qDACV,QAAS,IAAMwE,EAASE,EAAK,KAAMA,EAAK,GAAG,EAE1C,UAAAC,GAAiB5E,EAAC4E,EAAA,CAAc,UAAU,uBAAuB,EAClE5E,EAAC,QAAK,UAAU,yDAA0D,SAAA2E,EAAK,MAAM,EACrF3E,EAACiB,EAAA,CAAU,UAAU,uBAAuB,GAC9C,IATQsD,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
6
- "names": ["Fragment", "jsx", "jsxs", "lazy", "Suspense", "useState", "useCallback", "useMemo", "Picture", "useHeadlessContext", "cn", "MemberPopupActionType", "MemberPopupPageScope", "MemberPopupPanelType", "MemberPopupProvider", "useMemberPopupContext", "ViewStackContext", "IconClose", "IconArrow", "IconCredit", "IconBag", "IconReferral", "IconSwitch", "IconSubscription", "ROUNDED_BRANDS", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "MemberPopup", "copy", "bottomOffset", "providerProps", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "config", "pathname", "matches", "page", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
4
+ "sourcesContent": ["'use client'\n\nimport { lazy, Suspense, useState, useCallback, useMemo } from 'react'\nimport { Picture } from '@anker-in/headless-ui'\nimport { type HeadlessConfig, useHeadlessContext, classNames as cn } from '@anker-in/lib'\nimport {\n MemberPopupActionType,\n MemberPopupPageScope,\n MemberPopupPanelType,\n type MemberPopupCopy,\n type MemberPopupContextValue,\n type MemberPopupItem,\n} from './type'\nimport { MemberPopupProvider } from './context/provider'\nimport { useMemberPopupContext } from './context/provider'\nimport { ViewStackContext, type ViewPayload } from './context/viewStack'\nimport { IconClose, IconArrow, IconCredit, IconBag, IconReferral, IconSwitch, IconSubscription } from './icons'\nimport { ROUNDED_BRANDS } from '../../constants'\n\nconst EarnCredits = lazy(() => import('./panels/EarnCredits'))\nconst ConsumeCredits = lazy(() => import('./panels/ConsumeCredits'))\nconst Referral = lazy(() => import('./panels/Referral'))\nconst CompleteProfile = lazy(() => import('./panels/EarnCredits/CompleteProfilePanel'))\nconst ActivitiesSubscribe = lazy(() => import('./panels/ActivitiesSubscribePanel'))\nconst SubscribeEmail = lazy(() => import('./panels/EarnCredits/SubscribeEmailPanel'))\nconst Activate = lazy(() => import('./panels/EarnCredits/ActivatePanel'))\nconst RedeemCoupon = lazy(() => import('./panels/ConsumeCredits/RedeemCouponPanel'))\n\ntype MemberPopupProps = MemberPopupContextValue & {\n headlessConfig: HeadlessConfig\n copy: MemberPopupCopy\n bottomOffset?: string\n}\n\nexport function MemberPopup({ copy, bottomOffset = '24px', ...providerProps }: MemberPopupProps) {\n return (\n <MemberPopupProvider {...providerProps} earnCreditsCopy={copy.earnCredits}>\n <MemberPopupContent copy={copy} bottomOffset={bottomOffset} />\n </MemberPopupProvider>\n )\n}\n\ntype MemberPopupContentProps = {\n copy: MemberPopupCopy\n bottomOffset: string\n}\n\nfunction MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {\n const { profile, openSignInPopup, openSignUpPopup } = useMemberPopupContext()\n const { brand, storeDomain } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n const isLogin = !!profile\n const [isOpen, setIsOpen] = useState(false)\n const [viewStack, setViewStack] = useState<ViewPayload[]>([])\n const [isSubscribeSuccess, setIsSubscribeSuccess] = useState(false)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n const [isProfileCompleteSuccess, setIsProfileCompleteSuccess] = useState(false)\n const [isSubscribeFormHidden, setIsSubscribeFormHidden] = useState(false)\n\n const currentView = viewStack[viewStack.length - 1] ?? null\n\n const isVisible = useMemo(() => {\n const config = copy.pageConfig\n if (!config) return true\n const pathname = typeof window !== 'undefined' ? window.location.pathname : ''\n const matches = config.pages.some(page => pathname === page || pathname.startsWith(page + '/'))\n switch (config.scope) {\n case MemberPopupPageScope.Include:\n return matches\n case MemberPopupPageScope.Exclude:\n return !matches\n default:\n return true\n }\n }, [copy.pageConfig])\n\n const pushView = useCallback((view: ViewPayload) => {\n setViewStack(prev => [...prev, view])\n }, [])\n\n const popView = useCallback(() => {\n setViewStack(prev => prev.slice(0, -1))\n }, [])\n\n console.log('isVisible', isVisible)\n if (!isVisible) return null\n\n function handleAction(type: MemberPopupActionType, url?: string) {\n switch (type) {\n case MemberPopupActionType.ExternalLink:\n if (url) window.open(url, '_blank', 'noopener,noreferrer')\n break\n case MemberPopupActionType.OpenEarnCredits:\n pushView({ type: MemberPopupPanelType.EarnCredits })\n break\n case MemberPopupActionType.OpenConsumeCredits:\n pushView({ type: MemberPopupPanelType.ConsumeCredits })\n break\n case MemberPopupActionType.OpenReferral:\n pushView({ type: MemberPopupPanelType.Referral })\n break\n case MemberPopupActionType.OpenSubscribe:\n pushView({ type: MemberPopupPanelType.Subscribe })\n break\n }\n }\n\n function handleClose() {\n setIsOpen(false)\n setViewStack([])\n setIsSubscribeFormHidden(false)\n }\n\n return (\n <ViewStackContext.Provider value={{ pushView, popView }}>\n {isOpen && <div className=\"fixed inset-0 z-[998]\" onClick={handleClose} />}\n <div\n className=\"fixed right-0 z-[999] flex flex-row items-end pr-[16px] md:flex-col md:items-end md:right-0 md:w-screen md:pr-0 md:pl-0\"\n style={{ bottom: bottomOffset }}\n >\n {isOpen && (\n <div\n className={cn(\n 'relative mr-[8px] flex w-[420px] max-w-[calc(100vw-32px)] min-h-[500px] flex-col overflow-hidden bg-white shadow-[0_8px_32px_rgba(0,0,0,0.16)] md:mr-0 md:mb-[8px] md:mx-[16px] md:w-[calc(100vw-32px)] md:max-w-[400px]',\n rounded ? 'rounded-[12px]' : 'rounded-none'\n )}\n style={{ maxHeight: 'min(80vh, 606px)' }}\n onClick={e => e.stopPropagation()}\n >\n <div className=\"absolute right-[-8px] top-[24px] size-0 border-y-8 border-l-8 border-y-transparent border-l-white md:bottom-[-8px] md:left-auto md:right-[29px] md:top-auto md:border-x-8 md:border-b-transparent md:border-t-white\" />\n <div className=\"flex items-center justify-end pl-[10px] pr-[16px] pb-[8px] pt-[16px]\">\n {currentView !== null && (\n <button\n className=\"mr-auto flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={popView}\n aria-label=\"Back\"\n >\n <IconSwitch />\n </button>\n )}\n <button\n className=\"flex size-[24px] cursor-pointer items-center justify-center\"\n onClick={handleClose}\n aria-label=\"Close\"\n >\n <IconClose />\n </button>\n </div>\n\n <div className=\"flex flex-1 flex-col gap-[12px] overflow-y-auto p-[16px]\">\n {currentView === null && (\n <>\n {(copy.title || copy.subtitle) && (\n <div className=\"flex flex-col gap-[4px]\">\n {copy.title && (\n <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>\n )}\n {copy.subtitle && (\n <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>\n )}\n </div>\n )}\n {copy.list.map((item, i) => (\n <HomeCard key={i} item={item} onAction={handleAction} rounded={rounded} />\n ))}\n </>\n )}\n\n {currentView !== null && (\n <Suspense\n fallback={\n <div className=\"flex items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n }\n >\n {currentView.type === MemberPopupPanelType.EarnCredits && copy.earnCredits && (\n <EarnCredits\n copy={copy.earnCredits}\n onClose={popView}\n isSubscribeSuccess={isSubscribeSuccess}\n isActivateSuccess={isActivateSuccess}\n isProfileCompleteSuccess={isProfileCompleteSuccess}\n onSubscribeSuccess={() => setIsSubscribeSuccess(true)}\n onActivateSuccess={() => setIsActivateSuccess(true)}\n onProfileCompleteSuccess={() => setIsProfileCompleteSuccess(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (\n <ConsumeCredits\n copy={copy.consumeCredits}\n onClose={popView}\n isActivateSuccess={isActivateSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Referral && copy.referral && (\n <Referral copy={copy.referral} onClose={popView} />\n )}\n {currentView.type === MemberPopupPanelType.CompleteProfile && copy.earnCredits && (\n <CompleteProfile\n copy={copy.earnCredits.completeProfile}\n shopifyStoreDomain={storeDomain}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Subscribe && copy.activitiesSubscribe && (\n <ActivitiesSubscribe\n copy={copy.activitiesSubscribe}\n email={profile?.email}\n onSuccess={currentView.props?.onSuccess}\n hideForm={isSubscribeFormHidden}\n onHideForm={() => setIsSubscribeFormHidden(true)}\n />\n )}\n {currentView.type === MemberPopupPanelType.SubscribeEmail && copy.earnCredits && (\n <SubscribeEmail\n copy={copy.earnCredits.subscribe}\n email={profile?.email}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.Activate && copy.earnCredits && (\n <Activate\n copy={copy.earnCredits.authCodeActivate}\n onClose={popView}\n onSuccess={currentView.props?.onSuccess}\n />\n )}\n {currentView.type === MemberPopupPanelType.RedeemCoupon &&\n currentView.props &&\n copy.consumeCredits && (\n <RedeemCoupon\n itemTitle={currentView.props.itemTitle}\n itemCredits={currentView.props.itemCredits}\n itemImage={currentView.props.itemImage}\n itemValue={currentView.props.itemValue}\n itemOff={currentView.props.itemOff}\n itemRules={currentView.props.itemRules}\n redeemId={currentView.props.redeemId}\n userId={currentView.props.userId}\n alpcConfig={currentView.props.alpcConfig}\n copy={copy.consumeCredits.redeemModal}\n pointUnit={copy.consumeCredits.pointUnit}\n onClose={popView}\n />\n )}\n </Suspense>\n )}\n </div>\n\n {copy.footer && !isLogin && (\n <div className=\"border-t border-[#dadce0] p-[16px]\">\n <div className=\"flex items-center justify-between gap-[16px]\">\n <div className=\"flex items-center gap-[4px]\">\n <span className=\"text-[14px] font-[700] text-[#080a0f]\">{copy.footer.loginHint}</span>\n <button\n className=\"cursor-pointer text-[14px] font-[700] text-[#080a0f] underline\"\n onClick={openSignInPopup}\n >\n {copy.footer.loginLabel}\n </button>\n </div>\n <div className=\"flex shrink-0 items-center gap-[8px]\">\n <button\n className={cn(\n 'cursor-pointer border-[1.6px] border-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-[#080a0f]',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n onClick={openSignUpPopup}\n >\n {copy.footer.joinLabel}\n </button>\n </div>\n </div>\n </div>\n )}\n </div>\n )}\n\n <button\n className=\"flex cursor-pointer items-center justify-center rounded-full bg-white shadow-lg md:ml-auto md:mr-[16px]\"\n onClick={() => setIsOpen(prev => !prev)}\n aria-label={copy.triggerImg.alt ?? 'Open member popup'}\n >\n <Picture source={copy.triggerImg.url} alt={copy.triggerImg.alt ?? ''} className=\"size-[58px]\" />\n </button>\n </div>\n </ViewStackContext.Provider>\n )\n}\n\ntype HomeCardProps = {\n item: MemberPopupItem\n onAction: (type: MemberPopupActionType, url?: string) => void\n rounded: boolean\n}\n\nfunction HomeCard({ item, onAction, rounded }: HomeCardProps) {\n const ACTION_ICON: Partial<Record<MemberPopupActionType, typeof IconCredit>> = {\n [MemberPopupActionType.OpenEarnCredits]: IconCredit,\n [MemberPopupActionType.OpenConsumeCredits]: IconBag,\n [MemberPopupActionType.OpenReferral]: IconReferral,\n [MemberPopupActionType.OpenSubscribe]: IconSubscription,\n }\n\n return (\n <div className={cn('flex flex-col gap-[16px] bg-[#f5f6f7] p-[16px]', rounded ? 'rounded-[8px]' : 'rounded-none')}>\n <div className=\"flex flex-col gap-[4px]\">\n <h3 className=\"text-[20px] font-[700] leading-[1.2] text-[#1e2024]\">{item.title}</h3>\n {item.description && <p className=\"text-[14px] font-[700] leading-[1.43] text-[#1e2024]\">{item.description}</p>}\n </div>\n\n <div className=\"flex flex-col gap-[16px]\">\n {item.links.map((link, i) => {\n const IconComponent = ACTION_ICON[link.type]\n return (\n <div key={i}>\n {i > 0 && <div className=\"mb-[16px] h-px bg-[#dadce0]\" />}\n <button\n className=\"flex w-full cursor-pointer items-center gap-[12px]\"\n onClick={() => onAction(link.type, link.url)}\n >\n {IconComponent && <IconComponent className=\"size-[24px] shrink-0\" />}\n <span className=\"flex-1 text-left text-[14px] font-[700] text-[#1e2024]\">{link.label}</span>\n <IconArrow className=\"size-[16px] shrink-0\" />\n </button>\n </div>\n )\n })}\n </div>\n </div>\n )\n}\n"],
5
+ "mappings": "aAqCM,OAkHU,YAAAA,GAlHV,OAAAC,EA6FM,QAAAC,MA7FN,oBAnCN,OAAS,QAAAC,EAAM,YAAAC,EAAU,YAAAC,EAAU,eAAAC,EAAa,WAAAC,MAAe,QAC/D,OAAS,WAAAC,MAAe,wBACxB,OAA8B,sBAAAC,EAAoB,cAAcC,MAAU,gBAC1E,OACE,yBAAAC,EACA,wBAAAC,EACA,wBAAAC,MAIK,SACP,OAAS,uBAAAC,MAA2B,qBACpC,OAAS,yBAAAC,MAA6B,qBACtC,OAAS,oBAAAC,MAA0C,sBACnD,OAAS,aAAAC,EAAW,aAAAC,EAAW,cAAAC,EAAY,WAAAC,EAAS,gBAAAC,EAAc,cAAAC,EAAY,oBAAAC,MAAwB,UACtG,OAAS,kBAAAC,OAAsB,kBAE/B,MA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U,uDAAwD,SAAAuE,EAAK,YAAY,GAC7G,EAEAvE,EAAC,OAAI,UAAU,2BACZ,SAAAuE,EAAK,MAAM,IAAI,CAACK,EAAMJ,IAAM,CAC3B,MAAMK,EAAgBF,EAAYC,EAAK,IAAI,EAC3C,OACE3E,EAAC,OACE,UAAAuE,EAAI,GAAKxE,EAAC,OAAI,UAAU,8BAA8B,EACvDC,EAAC,UACC,UAAU,qDACV,QAAS,IAAMyE,EAASE,EAAK,KAAMA,EAAK,GAAG,EAE1C,UAAAC,GAAiB7E,EAAC6E,EAAA,CAAc,UAAU,uBAAuB,EAClE7E,EAAC,QAAK,UAAU,yDAA0D,SAAA4E,EAAK,MAAM,EACrF5E,EAACiB,EAAA,CAAU,UAAU,uBAAuB,GAC9C,IATQuD,CAUV,CAEJ,CAAC,EACH,GACF,CAEJ",
6
+ "names": ["Fragment", "jsx", "jsxs", "lazy", "Suspense", "useState", "useCallback", "useMemo", "Picture", "useHeadlessContext", "cn", "MemberPopupActionType", "MemberPopupPageScope", "MemberPopupPanelType", "MemberPopupProvider", "useMemberPopupContext", "ViewStackContext", "IconClose", "IconArrow", "IconCredit", "IconBag", "IconReferral", "IconSwitch", "IconSubscription", "ROUNDED_BRANDS", "EarnCredits", "ConsumeCredits", "Referral", "CompleteProfile", "ActivitiesSubscribe", "SubscribeEmail", "Activate", "RedeemCoupon", "MemberPopup", "copy", "bottomOffset", "providerProps", "MemberPopupContent", "profile", "openSignInPopup", "openSignUpPopup", "brand", "storeDomain", "rounded", "isLogin", "isOpen", "setIsOpen", "viewStack", "setViewStack", "isSubscribeSuccess", "setIsSubscribeSuccess", "isActivateSuccess", "setIsActivateSuccess", "isProfileCompleteSuccess", "setIsProfileCompleteSuccess", "isSubscribeFormHidden", "setIsSubscribeFormHidden", "currentView", "isVisible", "config", "pathname", "matches", "page", "pushView", "view", "prev", "popView", "handleAction", "type", "url", "handleClose", "e", "item", "i", "HomeCard", "onAction", "ACTION_ICON", "link", "IconComponent"]
7
7
  }
@@ -2,6 +2,7 @@ import { type ConsumeCreditsopy } from '../../type';
2
2
  type Props = {
3
3
  copy: ConsumeCreditsopy;
4
4
  onClose: () => void;
5
+ isActivateSuccess: boolean;
5
6
  };
6
- declare function ConsumeCredits({ copy, onClose }: Props): import("react/jsx-runtime").JSX.Element;
7
+ declare function ConsumeCredits({ copy, isActivateSuccess, onClose }: Props): import("react/jsx-runtime").JSX.Element;
7
8
  export default ConsumeCredits;
@@ -1,2 +1,2 @@
1
- import{Fragment as W,jsx as a,jsxs as n}from"react/jsx-runtime";import{useMemo as z,useState as b}from"react";import{Picture as F,Button as T}from"@anker-in/headless-ui";import{classNames as N,useProductsByHandles as V,useHeadlessContext as j}from"@anker-in/lib";import{useMemberPopupContext as G}from"../../context/provider";import{useViewStack as H}from"../../context/viewStack";import{useRedeemableList as q}from"./hooks/useRedeemableList";import{useRedeemAndBuy as J}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as r,MemberPopupPanelType as w}from"../../type";import{numberFormat as c}from"../../../credits/context/utils";import{ROUNDED_BRANDS as K}from"../../../../constants";function Q({copy:t,onClose:X}){const{profile:d,creditInfo:o,openSignUpPopup:R,alpcConfig:x}=G(),{pushView:C}=H(),{brand:_}=j(),m=K.includes(_),[h,I]=b(""),[B,P]=b(null),[D,S]=b(!1),p=!!d,{redeemableList:y,listLoading:A}=q(x),{trigger:U}=J(x),L=t.list.map(e=>e.product?.handle).filter(Boolean),{data:k}=V({handles:L}),M=z(()=>t.list.map(e=>{const s=y.find(u=>String(u.id)===String(e.redeemId));if(!s)return null;const i=Number(o?.available_credit??0),g=p&&!!d?.activated&&s.consume_credits>i,f=s.is_limited&&(!s.remaining_inventory||s.remaining_inventory<=0);let l,v;return(e.type===r.RedeemAndBuy||e.type===r.Product)&&e.product&&(l=k?.find(u=>u.handle===e.product.handle),v=l?.variants?.find(u=>u.sku===e.product.sku)??l?.variants?.[0],e.type===r.RedeemAndBuy&&(!l||!v))?null:{...e,alpcData:s,insufficient:g,soldOut:f,product:l,variant:v}}).filter(Boolean),[t.list,y,o,d,p,k]);function O(e){return p?e.soldOut?t.soldOut:t.btnRedeem:t.unlockRewards}function E(e){return e.type===r.GiftCard||e.type===r.Product?e.insufficient:e.soldOut||e.insufficient}async function $(e){if(!p){R();return}if(!d?.activated&&!D){C({type:w.Activate,props:{onSuccess:()=>S(!0)}});return}if(e.type===r.GiftCard||e.type===r.Product){t.creditsPage?.url&&window.open(t.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===r.Coupon)C({type:w.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:t.imageMapping?.[e.type]?{url:t.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:t.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:d?.user_id,alpcConfig:x}});else{I(""),P(e.redeemId);try{await U({productVariant:e.variant,redeemId:Number(e.redeemId),userId:d?.user_id})}catch(s){I(s?.message??t.redeemModal.commonError)}finally{P(null)}}}return a(W,{children:n("div",{className:"flex flex-1 flex-col gap-[12px]",children:[n("div",{className:"flex flex-col gap-[8px]",children:[t.title&&a("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:t.title}),t.subtitle&&a("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:t.subtitle})]}),p&&n("div",{className:N("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",m?"rounded-[8px]":"rounded-none"),children:[n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.balanceLabel??"AnkerCredits Balance"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:c(o?.available_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??t.pointUnit??"ankercredits"})]})]}),a("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:c(o?.pending_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??t.pointUnit??"ankercredits"}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]}),a("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:c(o?.pending_credit??0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]})]}),h&&a("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:h}),A?a("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:a("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):a("div",{className:"flex flex-col",children:M.map((e,s)=>{const i=!!e.product;return n("div",{className:"relative py-[16px]",children:[s>0&&a("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),n("div",{className:"flex items-center gap-[12px]",children:[(()=>{const g=t.imageMapping?.[e.type]?.url,f=i?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:g??e.image?.url,l=i?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return f?n("div",{className:N("relative size-[64px] shrink-0 overflow-hidden",m?"rounded-[4px]":"rounded-none"),children:[a(F,{source:f,alt:l,className:"flex size-full items-center justify-center",imgClassName:i?"object-cover":"h-full w-auto object-contain"}),!i&&e.value&&n("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",t.off]})]}):null})(),n("div",{className:"min-w-0 flex-1",children:[a("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:i&&e.product?.title?e.product.title:e.title}),a("div",{className:"mt-[4px] text-[14px] text-[#666]",children:i&&e.price!=null?`${c(e.alpcData.consume_credits)} ${t.pointUnit??""} + $${Number(e.price).toFixed(2)}`:`${c(e.alpcData.consume_credits)} ${t.pointUnit??""}`})]}),n("div",{className:"relative group",children:[a(T,{className:N("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",m?"rounded-[4px]":"rounded-none"),disabled:E(e),loading:B===e.redeemId,onClick:()=>$(e),children:O(e)}),e.insufficient&&a("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:n("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[a("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:t.insufficientCredits}),a("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},s)})}),t.creditsPage?.url&&a("a",{href:t.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:t.creditsPage.label??"Go to Credits Page"})]})})}var de=Q;export{de as default};
1
+ import{Fragment as Q,jsx as a,jsxs as n}from"react/jsx-runtime";import{useMemo as $,useState as R}from"react";import{Picture as z,Button as F}from"@anker-in/headless-ui";import{classNames as b,useProductsByHandles as T,useHeadlessContext as V}from"@anker-in/lib";import{useMemberPopupContext as j}from"../../context/provider";import{useViewStack as G}from"../../context/viewStack";import{useRedeemableList as H}from"./hooks/useRedeemableList";import{useRedeemAndBuy as q}from"./hooks/useRedeemAndBuy";import{ConsumeCreditsItemType as i,MemberPopupPanelType as k}from"../../type";import{numberFormat as f}from"../../../credits/context/utils";import{ROUNDED_BRANDS as J}from"../../../../constants";function K({copy:t,isActivateSuccess:w,onClose:W}){const{profile:d,creditInfo:u,openSignUpPopup:_,alpcConfig:m}=j(),{pushView:N}=G(),{brand:B}=V(),x=J.includes(B),[C,h]=R(""),[D,y]=R(null),o=!!d,{redeemableList:I,listLoading:A}=H(m),{trigger:U}=q(m),S=t.list.map(e=>e.product?.handle).filter(Boolean),{data:P}=T({handles:S}),L=$(()=>t.list.map(e=>{const s=I.find(p=>String(p.id)===String(e.redeemId));if(!s)return null;const r=Number(u?.available_credit??0),g=o&&!!d?.activated&&s.consume_credits>r,c=s.is_limited&&(!s.remaining_inventory||s.remaining_inventory<=0);let l,v;return(e.type===i.RedeemAndBuy||e.type===i.Product)&&e.product&&(l=P?.find(p=>p.handle===e.product.handle),v=l?.variants?.find(p=>p.sku===e.product.sku)??l?.variants?.[0],e.type===i.RedeemAndBuy&&(!l||!v))?null:{...e,alpcData:s,insufficient:g,soldOut:c,product:l,variant:v}}).filter(Boolean),[t.list,I,u,d,o,P]);function M(e){return o?e.soldOut?t.soldOut:t.btnRedeem:t.unlockRewards}function O(e){return e.type===i.GiftCard||e.type===i.Product?e.insufficient:e.soldOut||e.insufficient}async function E(e){if(!o){_();return}if(!d?.activated&&!w){N({type:k.Activate,props:{}});return}if(e.type===i.GiftCard||e.type===i.Product){t.creditsPage?.url&&window.open(t.creditsPage.url,"_blank","noopener,noreferrer");return}if(e.type===i.Coupon)N({type:k.RedeemCoupon,props:{itemTitle:e.title,itemCredits:e.alpcData.consume_credits,itemImage:t.imageMapping?.[e.type]?{url:t.imageMapping[e.type].url,alt:e.image?.alt}:e.image,itemValue:e.value,itemOff:t.off,itemRules:e.rules,redeemId:Number(e.redeemId),userId:d?.user_id,alpcConfig:m}});else{h(""),y(e.redeemId);try{await U({productVariant:e.variant,redeemId:Number(e.redeemId),userId:d?.user_id})}catch(s){h(s?.message??t.redeemModal.commonError)}finally{y(null)}}}return a(Q,{children:n("div",{className:"flex flex-1 flex-col gap-[12px]",children:[n("div",{className:"flex flex-col gap-[8px]",children:[t.title&&a("h2",{className:"text-[24px] font-[700] leading-[1.2] text-[#080a0f]",children:t.title}),t.subtitle&&a("p",{className:"text-[16px] font-[700] leading-snug text-[#4a4c56]",children:t.subtitle})]}),o&&n("div",{className:b("flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]",x?"rounded-[8px]":"rounded-none"),children:[n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.balanceLabel??"AnkerCredits Balance"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:f(u?.available_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??t.pointUnit??"ankercredits"})]})]}),a("div",{className:"h-full w-px bg-[#dadce0]"}),n("div",{className:"flex flex-1 flex-col gap-[4px]",children:[a("div",{className:"text-[14px] font-[700] text-[#1e2024]",children:t.comingSoonLabel??"Coming Soon"}),n("div",{className:"flex items-end gap-[4px]",children:[a("span",{className:"text-[24px] font-[700] leading-[1.2] text-[#1e2024]",children:f(u?.pending_credit||0)}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??t.pointUnit??"ankercredits"}),a("span",{className:"text-[14px] font-[700] leading-[1.4] text-[#1e2024]",children:t.creditUnit??"ankercredits"})]})]})]}),C&&a("div",{className:"text-[14px] font-[700] text-[#f84d4f]",children:C}),A?a("div",{className:"flex flex-1 items-center justify-center py-[32px]",children:a("div",{className:"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent"})}):a("div",{className:"flex flex-col",children:L.map((e,s)=>{const r=!!e.product;return n("div",{className:"relative py-[16px]",children:[s>0&&a("div",{className:"absolute inset-x-0 top-0 h-px bg-[#dadce0]"}),n("div",{className:"flex items-center gap-[12px]",children:[(()=>{const g=t.imageMapping?.[e.type]?.url,c=r?e.variant?.image?.url??e.product?.images?.[0]?.url??e.image?.url:g??e.image?.url,l=r?e.variant?.image?.altText??e.product?.images?.[0]?.alt??e.image?.alt??"":e.image?.alt??"";return c?n("div",{className:b("relative size-[64px] shrink-0 overflow-hidden",x?"rounded-[4px]":"rounded-none"),children:[a(z,{source:c,alt:l,className:"flex size-full items-center justify-center",imgClassName:r?"object-cover":"h-full w-auto object-contain"}),!r&&e.value&&n("div",{className:"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white",children:[e.value," ",t.off]})]}):null})(),n("div",{className:"min-w-0 flex-1",children:[a("div",{className:"text-[16px] font-[700] text-[#1e2024] line-clamp-2",children:r&&e.product?.title?e.product.title:e.title}),a("div",{className:"mt-[4px] text-[14px] text-[#666]",children:r&&e.price!=null?`${f(e.alpcData.consume_credits)} ${t.pointUnit??""} + $${Number(e.price).toFixed(2)}`:`${f(e.alpcData.consume_credits)} ${t.pointUnit??""}`})]}),n("div",{className:"relative group",children:[a(F,{className:b("bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white",x?"rounded-[4px]":"rounded-none"),disabled:O(e),loading:D===e.redeemId,onClick:()=>E(e),children:M(e)}),e.insufficient&&a("div",{className:"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block",children:n("div",{className:"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow",children:[a("p",{className:"text-pretty tracking-[-0.02em] text-[14px]",children:t.insufficientCredits}),a("div",{className:"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]"})]})})]})]})]},s)})}),t.creditsPage?.url&&a("a",{href:t.creditsPage.url,target:"_blank",rel:"noopener noreferrer",className:"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline",children:t.creditsPage.label??"Go to Credits Page"})]})})}var le=K;export{le as default};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/components/memberPopup/panels/ConsumeCredits/index.tsx"],
4
- "sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n}\n\nfunction ConsumeCredits({ copy, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n const [isActivateSuccess, setIsActivateSuccess] = useState(false)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: { onSuccess: () => setIsActivateSuccess(true) },\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit ?? 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
5
- "mappings": "AA2II,mBAAAA,EAGqB,OAAAC,EADjB,QAAAC,MAFJ,oBA3I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C,EAAC,OAAI,UAAU,0EACb,UAAAD,EAAC,KAAE,UAAU,6CAA8C,SAAAkB,EAAK,oBAAoB,EACpFlB,EAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQsD,CAiEV,CAEJ,CAAC,EACH,EAGDpC,EAAK,aAAa,KACjBlB,EAAC,KACC,KAAMkB,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOyC,GAAQ1C",
6
- "names": ["Fragment", "jsx", "jsxs", "useMemo", "useState", "Picture", "Button", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isActivateSuccess", "setIsActivateSuccess", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "p", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt", "ConsumeCredits_default"]
4
+ "sourcesContent": ["import { useMemo, useState } from 'react'\nimport { Picture, Button } from '@anker-in/headless-ui'\nimport { classNames as cn, useProductsByHandles, useHeadlessContext } from '@anker-in/lib'\nimport { useMemberPopupContext } from '../../context/provider'\nimport { useViewStack } from '../../context/viewStack'\nimport { useRedeemableList } from './hooks/useRedeemableList'\nimport { useRedeemAndBuy } from './hooks/useRedeemAndBuy'\nimport {\n ConsumeCreditsItemType,\n MemberPopupPanelType,\n type ConsumeCreditsopy,\n type ConsumeCreditsItem,\n} from '../../type'\nimport { numberFormat } from '../../../credits/context/utils'\nimport type { ConsumeCreditRuleResponse } from '../../../credits/context/response'\nimport { ROUNDED_BRANDS } from '../../../../constants'\n\ntype EnrichedItem = ConsumeCreditsItem & {\n alpcData: ConsumeCreditRuleResponse\n insufficient: boolean\n soldOut: boolean\n product?: any\n variant?: any\n}\n\ntype Props = {\n copy: ConsumeCreditsopy\n onClose: () => void\n isActivateSuccess: boolean\n}\n\nfunction ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {\n const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()\n const { pushView } = useViewStack()\n const { brand } = useHeadlessContext()\n const rounded = ROUNDED_BRANDS.includes(brand)\n\n const [redeemAndBuyError, setRedeemAndBuyError] = useState('')\n const [loadingId, setLoadingId] = useState<string | number | null>(null)\n\n const isLogin = !!profile\n const { redeemableList, listLoading } = useRedeemableList(alpcConfig)\n const { trigger: redeemAndBuy } = useRedeemAndBuy(alpcConfig)\n\n const handles = copy.list.map(item => item.product?.handle).filter(Boolean) as string[]\n const { data: products } = useProductsByHandles({ handles })\n\n const list = useMemo(() => {\n return copy.list\n .map(item => {\n const alpcData = redeemableList.find(r => String(r.id) === String(item.redeemId))\n if (!alpcData) return null\n\n const availableCredit = Number(creditInfo?.available_credit ?? 0)\n const insufficient = isLogin && !!profile?.activated && alpcData.consume_credits > availableCredit\n const soldOut = alpcData.is_limited && (!alpcData.remaining_inventory || alpcData.remaining_inventory <= 0)\n\n let product\n let variant\n if (\n (item.type === ConsumeCreditsItemType.RedeemAndBuy || item.type === ConsumeCreditsItemType.Product) &&\n item.product\n ) {\n product = products?.find((p: any) => p.handle === item.product!.handle)\n variant = product?.variants?.find((v: any) => v.sku === item.product!.sku) ?? product?.variants?.[0]\n if (item.type === ConsumeCreditsItemType.RedeemAndBuy && (!product || !variant)) return null\n }\n\n return { ...item, alpcData, insufficient, soldOut, product, variant }\n })\n .filter(Boolean) as EnrichedItem[]\n }, [copy.list, redeemableList, creditInfo, profile, isLogin, products])\n\n function getButtonLabel(item: (typeof list)[number]) {\n if (!isLogin) return copy.unlockRewards\n if (item.soldOut) return copy.soldOut\n return copy.btnRedeem\n }\n\n function isDisabled(item: (typeof list)[number]) {\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n return item.insufficient\n }\n return item.soldOut || item.insufficient\n }\n\n async function handleRedeem(item: (typeof list)[number]) {\n if (!isLogin) {\n openSignUpPopup()\n return\n }\n if (!profile?.activated && !isActivateSuccess) {\n pushView({\n type: MemberPopupPanelType.Activate,\n props: {},\n })\n return\n }\n if (item.type === ConsumeCreditsItemType.GiftCard || item.type === ConsumeCreditsItemType.Product) {\n if (copy.creditsPage?.url) {\n window.open(copy.creditsPage.url, '_blank', 'noopener,noreferrer')\n }\n return\n }\n if (item.type === ConsumeCreditsItemType.Coupon) {\n pushView({\n type: MemberPopupPanelType.RedeemCoupon,\n props: {\n itemTitle: item.title,\n itemCredits: item.alpcData.consume_credits,\n itemImage: copy.imageMapping?.[item.type]\n ? { url: copy.imageMapping[item.type]!.url, alt: item.image?.alt }\n : item.image,\n itemValue: item.value,\n itemOff: copy.off,\n itemRules: item.rules,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n alpcConfig,\n },\n })\n } else {\n setRedeemAndBuyError('')\n setLoadingId(item.redeemId)\n try {\n await redeemAndBuy({\n productVariant: item.variant,\n redeemId: Number(item.redeemId),\n userId: profile?.user_id,\n })\n } catch (e: any) {\n setRedeemAndBuyError(e?.message ?? copy.redeemModal.commonError)\n } finally {\n setLoadingId(null)\n }\n }\n }\n\n return (\n <>\n <div className=\"flex flex-1 flex-col gap-[12px]\">\n <div className=\"flex flex-col gap-[8px]\">\n {copy.title && <h2 className=\"text-[24px] font-[700] leading-[1.2] text-[#080a0f]\">{copy.title}</h2>}\n {copy.subtitle && <p className=\"text-[16px] font-[700] leading-snug text-[#4a4c56]\">{copy.subtitle}</p>}\n </div>\n\n {isLogin && (\n <div\n className={cn(\n 'flex items-center gap-[12px] bg-[#f5f6f7] p-[16px]',\n rounded ? 'rounded-[8px]' : 'rounded-none'\n )}\n >\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.balanceLabel ?? 'AnkerCredits Balance'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.available_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n <div className=\"h-full w-px bg-[#dadce0]\" />\n <div className=\"flex flex-1 flex-col gap-[4px]\">\n <div className=\"text-[14px] font-[700] text-[#1e2024]\">{copy.comingSoonLabel ?? 'Coming Soon'}</div>\n <div className=\"flex items-end gap-[4px]\">\n <span className=\"text-[24px] font-[700] leading-[1.2] text-[#1e2024]\">\n {numberFormat(creditInfo?.pending_credit || 0)}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? copy.pointUnit ?? 'ankercredits'}\n </span>\n <span className=\"text-[14px] font-[700] leading-[1.4] text-[#1e2024]\">\n {copy.creditUnit ?? 'ankercredits'}\n </span>\n </div>\n </div>\n </div>\n )}\n {redeemAndBuyError && <div className=\"text-[14px] font-[700] text-[#f84d4f]\">{redeemAndBuyError}</div>}\n\n {listLoading ? (\n <div className=\"flex flex-1 items-center justify-center py-[32px]\">\n <div className=\"size-[32px] animate-spin rounded-full border-[3px] border-[#080a0f] border-t-transparent\" />\n </div>\n ) : (\n <div className=\"flex flex-col\">\n {list.map((item, idx) => {\n const hasProduct = !!item.product\n return (\n <div key={idx} className=\"relative py-[16px]\">\n {idx > 0 && <div className=\"absolute inset-x-0 top-0 h-px bg-[#dadce0]\" />}\n <div className=\"flex items-center gap-[12px]\">\n {(() => {\n const mappedImgUrl = copy.imageMapping?.[item.type]?.url\n const imgUrl = hasProduct\n ? (item.variant?.image?.url ?? item.product?.images?.[0]?.url ?? item.image?.url)\n : (mappedImgUrl ?? item.image?.url)\n const imgAlt = hasProduct\n ? (item.variant?.image?.altText ?? item.product?.images?.[0]?.alt ?? item.image?.alt ?? '')\n : (item.image?.alt ?? '')\n if (!imgUrl) return null\n return (\n <div\n className={cn(\n 'relative size-[64px] shrink-0 overflow-hidden',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n >\n <Picture\n source={imgUrl}\n alt={imgAlt}\n className=\"flex size-full items-center justify-center\"\n imgClassName={hasProduct ? 'object-cover' : 'h-full w-auto object-contain'}\n />\n {!hasProduct && item.value && (\n <div className=\"absolute bottom-[16px] left-[4px] text-[12px] font-[800] leading-none text-white\">\n {item.value} {copy.off}\n </div>\n )}\n </div>\n )\n })()}\n <div className=\"min-w-0 flex-1\">\n <div className=\"text-[16px] font-[700] text-[#1e2024] line-clamp-2\">\n {hasProduct && item.product?.title ? item.product.title : item.title}\n </div>\n <div className=\"mt-[4px] text-[14px] text-[#666]\">\n {hasProduct && item.price != null\n ? `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''} + $${Number(item.price).toFixed(2)}`\n : `${numberFormat(item.alpcData.consume_credits)} ${copy.pointUnit ?? ''}`}\n </div>\n </div>\n <div className=\"relative group\">\n <Button\n className={cn(\n 'bg-[#080a0f] px-[20px] pb-[10px] pt-[11px] text-[14px] font-[700] leading-[1.2] text-white',\n rounded ? 'rounded-[4px]' : 'rounded-none'\n )}\n disabled={isDisabled(item)}\n loading={loadingId === item.redeemId}\n onClick={() => handleRedeem(item)}\n >\n {getButtonLabel(item)}\n </Button>\n {item.insufficient && (\n <div className=\"pointer-events-none absolute right-0 top-full z-[100] mt-[10px] hidden w-[200px] group-hover:block\">\n <div className=\"relative bg-[#6D6D6F] p-[16px] text-[14px] font-[700] text-white shadow\">\n <p className=\"text-pretty tracking-[-0.02em] text-[14px]\">{copy.insufficientCredits}</p>\n <div className=\"absolute -top-[8px] right-[20px] size-[16px] origin-top-left rotate-45 rounded-[2px] bg-[#6D6D6F]\" />\n </div>\n </div>\n )}\n </div>\n </div>\n </div>\n )\n })}\n </div>\n )}\n\n {copy.creditsPage?.url && (\n <a\n href={copy.creditsPage.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"mt-auto self-start text-[14px] font-[700] text-[#080a0f] underline\"\n >\n {copy.creditsPage.label ?? 'Go to Credits Page'}\n </a>\n )}\n </div>\n </>\n )\n}\n\nexport default ConsumeCredits\n"],
5
+ "mappings": "AA2II,mBAAAA,EAGqB,OAAAC,EADjB,QAAAC,MAFJ,oBA3IJ,OAAS,WAAAC,EAAS,YAAAC,MAAgB,QAClC,OAAS,WAAAC,EAAS,UAAAC,MAAc,wBAChC,OAAS,cAAcC,EAAI,wBAAAC,EAAsB,sBAAAC,MAA0B,gBAC3E,OAAS,yBAAAC,MAA6B,yBACtC,OAAS,gBAAAC,MAAoB,0BAC7B,OAAS,qBAAAC,MAAyB,4BAClC,OAAS,mBAAAC,MAAuB,0BAChC,OACE,0BAAAC,EACA,wBAAAC,MAGK,aACP,OAAS,gBAAAC,MAAoB,iCAE7B,OAAS,kBAAAC,MAAsB,wBAgB/B,SAASC,EAAe,CAAE,KAAAC,EAAM,kBAAAC,EAAmB,QAAAC,CAAQ,EAAU,CACnE,KAAM,CAAE,QAAAC,EAAS,WAAAC,EAAY,gBAAAC,EAAiB,WAAAC,CAAW,EAAIf,EAAsB,EAC7E,CAAE,SAAAgB,CAAS,EAAIf,EAAa,EAC5B,CAAE,MAAAgB,CAAM,EAAIlB,EAAmB,EAC/BmB,EAAUX,EAAe,SAASU,CAAK,EAEvC,CAACE,EAAmBC,CAAoB,EAAI1B,EAAS,EAAE,EACvD,CAAC2B,EAAWC,CAAY,EAAI5B,EAAiC,IAAI,EAEjE6B,EAAU,CAAC,CAACX,EACZ,CAAE,eAAAY,EAAgB,YAAAC,CAAY,EAAIvB,EAAkBa,CAAU,EAC9D,CA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AI,UAAU,qGACb,SAAAC,EAAC,OAAI,UAAU,0EACb,UAAAD,EAAC,KAAE,UAAU,6CAA8C,SAAAkB,EAAK,oBAAoB,EACpFlB,EAAC,OAAI,UAAU,oGAAoG,GACrH,EACF,GAEJ,GACF,IAhEQoD,CAiEV,CAEJ,CAAC,EACH,EAGDlC,EAAK,aAAa,KACjBlB,EAAC,KACC,KAAMkB,EAAK,YAAY,IACvB,OAAO,SACP,IAAI,sBACJ,UAAU,qEAET,SAAAA,EAAK,YAAY,OAAS,qBAC7B,GAEJ,EACF,CAEJ,CAEA,IAAOuC,GAAQxC",
6
+ "names": ["Fragment", "jsx", "jsxs", "useMemo", "useState", "Picture", "Button", "cn", "useProductsByHandles", "useHeadlessContext", "useMemberPopupContext", "useViewStack", "useRedeemableList", "useRedeemAndBuy", "ConsumeCreditsItemType", "MemberPopupPanelType", "numberFormat", "ROUNDED_BRANDS", "ConsumeCredits", "copy", "isActivateSuccess", "onClose", "profile", "creditInfo", "openSignUpPopup", "alpcConfig", "pushView", "brand", "rounded", "redeemAndBuyError", "setRedeemAndBuyError", "loadingId", "setLoadingId", "isLogin", "redeemableList", "listLoading", "redeemAndBuy", "handles", "item", "products", "list", "alpcData", "r", "availableCredit", "insufficient", "soldOut", "product", "variant", "v", "getButtonLabel", "isDisabled", "handleRedeem", "e", "idx", "hasProduct", "mappedImgUrl", "imgUrl", "imgAlt", "ConsumeCredits_default"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anker-in/campaign-ui",
3
- "version": "0.5.0-beta.10",
3
+ "version": "0.5.0-beta.11",
4
4
  "description": "Campaign UI components and utilities for Anker projects",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -74,8 +74,6 @@ function MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {
74
74
  }
75
75
  }, [copy.pageConfig])
76
76
 
77
- if (!isVisible) return null
78
-
79
77
  const pushView = useCallback((view: ViewPayload) => {
80
78
  setViewStack(prev => [...prev, view])
81
79
  }, [])
@@ -84,6 +82,9 @@ function MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {
84
82
  setViewStack(prev => prev.slice(0, -1))
85
83
  }, [])
86
84
 
85
+ console.log('isVisible', isVisible)
86
+ if (!isVisible) return null
87
+
87
88
  function handleAction(type: MemberPopupActionType, url?: string) {
88
89
  switch (type) {
89
90
  case MemberPopupActionType.ExternalLink:
@@ -186,7 +187,11 @@ function MemberPopupContent({ copy, bottomOffset }: MemberPopupContentProps) {
186
187
  />
187
188
  )}
188
189
  {currentView.type === MemberPopupPanelType.ConsumeCredits && copy.consumeCredits && (
189
- <ConsumeCredits copy={copy.consumeCredits} onClose={popView} />
190
+ <ConsumeCredits
191
+ copy={copy.consumeCredits}
192
+ onClose={popView}
193
+ isActivateSuccess={isActivateSuccess}
194
+ />
190
195
  )}
191
196
  {currentView.type === MemberPopupPanelType.Referral && copy.referral && (
192
197
  <Referral copy={copy.referral} onClose={popView} />
@@ -26,9 +26,10 @@ type EnrichedItem = ConsumeCreditsItem & {
26
26
  type Props = {
27
27
  copy: ConsumeCreditsopy
28
28
  onClose: () => void
29
+ isActivateSuccess: boolean
29
30
  }
30
31
 
31
- function ConsumeCredits({ copy, onClose }: Props) {
32
+ function ConsumeCredits({ copy, isActivateSuccess, onClose }: Props) {
32
33
  const { profile, creditInfo, openSignUpPopup, alpcConfig } = useMemberPopupContext()
33
34
  const { pushView } = useViewStack()
34
35
  const { brand } = useHeadlessContext()
@@ -36,7 +37,6 @@ function ConsumeCredits({ copy, onClose }: Props) {
36
37
 
37
38
  const [redeemAndBuyError, setRedeemAndBuyError] = useState('')
38
39
  const [loadingId, setLoadingId] = useState<string | number | null>(null)
39
- const [isActivateSuccess, setIsActivateSuccess] = useState(false)
40
40
 
41
41
  const isLogin = !!profile
42
42
  const { redeemableList, listLoading } = useRedeemableList(alpcConfig)
@@ -92,7 +92,7 @@ function ConsumeCredits({ copy, onClose }: Props) {
92
92
  if (!profile?.activated && !isActivateSuccess) {
93
93
  pushView({
94
94
  type: MemberPopupPanelType.Activate,
95
- props: { onSuccess: () => setIsActivateSuccess(true) },
95
+ props: {},
96
96
  })
97
97
  return
98
98
  }
@@ -177,18 +177,6 @@ function ConsumeCredits({ copy, onClose }: Props) {
177
177
  </span>
178
178
  </div>
179
179
  </div>
180
- <div className="h-full w-px bg-[#dadce0]" />
181
- <div className="flex flex-1 flex-col gap-[4px]">
182
- <div className="text-[14px] font-[700] text-[#1e2024]">{copy.comingSoonLabel ?? 'Coming Soon'}</div>
183
- <div className="flex items-end gap-[4px]">
184
- <span className="text-[24px] font-[700] leading-[1.2] text-[#1e2024]">
185
- {numberFormat(creditInfo?.pending_credit ?? 0)}
186
- </span>
187
- <span className="text-[14px] font-[700] leading-[1.4] text-[#1e2024]">
188
- {copy.creditUnit ?? 'ankercredits'}
189
- </span>
190
- </div>
191
- </div>
192
180
  </div>
193
181
  )}
194
182
  {redeemAndBuyError && <div className="text-[14px] font-[700] text-[#f84d4f]">{redeemAndBuyError}</div>}