import{a as e}from"./rolldown-runtime-COnpUsM8.js";import{At as t,Ht as n,mt as r}from"./vendor-react-N_fu9J_Y.js";import{C as i,R as a,S as o}from"./Storyblok-DGCBwXgG.js";import{n as s}from"./NotificationsContextProvider-gq_W_pl_.js";import{t as c}from"./Button-CfyTBrFT.js";import"./Button-CpxzSFWT.js";var l=e(n()),u=`wx2697dc2bd4ed5e56`,d=`https://open.weixin.qq.com`,f=({handleSubmit:e})=>{let{t}=r(),{addNotification:n}=s(),i=(0,l.useRef)(!1),a=(0,l.useMemo)(()=>{try{return`https%3A%2F%2Fwww.matsuyaginza.com%2Fsign-in-wechat-staging`}catch(e){return console.error(`Error encoding redirect URI:`,e),``}},[]),o=(0,l.useMemo)(()=>`${d}/connect/qrconnect?appid=${u}&redirect_uri=${a}&response_type=code&scope=snsapi_login&state=wechat#wechat_redirect`,[a]),c=(0,l.useCallback)(()=>{if(!o){console.error(`WeChat auth URL is empty`);return}window.location.href=o},[o]);return(0,l.useEffect)(()=>{let r=!0;return(async()=>{if(i.current||(i.current=!0,!r))return;let a,o,s,c;try{a=new URLSearchParams(window.location.search),o=a.get(`code`),s=a.get(`state`),c=a.get(`ErrCode`)}catch(e){console.error(`Error parsing URL parameters:`,e);return}c&&s===`wechat`&&c!==`0`&&n(c===`-4`?{type:`error`,message:t(`wechat.authorizationRejected`,`Authorization rejected by user`)}:c===`-2`?{type:`error`,message:t(`wechat.canceledByUser`,`Canceled by user`)}:{type:`error`,message:t(`wechat.errorOccurred`,`An error occurred`)}),!(!o||s!==`wechat`||!r)&&e&&e({weixin_code:o,email:``,password:``,rememberMe:!0})})(),()=>{r=!1}},[n,e,t]),{onWeChatLogin:c}},p={weChatLogin:`_weChatLogin_ok373_23`,weChatButtonContentModifier:`_weChatButtonContentModifier_ok373_38`,weChatIcon:`_weChatIcon_ok373_55`,modalContentModifier:`_modalContentModifier_ok373_60`,consentSection:`_consentSection_ok373_72`,consentLabel:`_consentLabel_ok373_79`,consentLink:`_consentLink_ok373_85`,consentError:`_consentError_ok373_91`},m=t(),h=(0,l.memo)(({handleSubmit:e,showConsentModal:t=!0})=>{let{t:n,i18n:s}=r(),u=s.language===`jp`||s.language===`cn`,{onWeChatLogin:d}=f({handleSubmit:e}),[h,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!0),[y,b]=(0,l.useState)(!0),x=_&&y;return(0,m.jsxs)(l.Fragment,{children:[(0,m.jsx)(c,{type:`button`,hasAnchorAppearance:!0,classes:{buttonModifier:p.weChatLogin,contentModifier:p.weChatButtonContentModifier},onClick:()=>t?g(!0):d(),children:(0,m.jsx)(`img`,{src:`/icons/wechat-icon-white.svg`,alt:n(`wechat.loginButton`,`Continue with WeChat`),className:p.weChatIcon,width:`24`,height:`24`,loading:`lazy`})}),t&&(0,m.jsxs)(a,{isOpen:h,onCloseModal:()=>g(!1),classes:{contentModifier:p.modalContentModifier},children:[(0,m.jsx)(`article`,{children:h&&(0,m.jsx)(i,{slug:`sign-in-create-account-page/wechat-sign-in-form-story`,disableLoadingIndicator:!0})}),(0,m.jsxs)(`div`,{className:p.consentSection,children:[(0,m.jsx)(o,{field:`wechatAgreeTerms`,initialValue:!0,onChange:e=>v(e.target.checked),classes:{labelModifier:p.consentLabel},label:(0,m.jsxs)(l.Fragment,{children:[u&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`a`,{href:`/policies/terms-and-conditions-page`,target:`_blank`,rel:`noopener noreferrer`,className:p.consentLink,children:n(`checkout.termsAndConditions`,`Terms and Conditions`)}),` `]}),n(`account.agreeToTerms`,`I have reviewed and agree to the`),!u&&(0,m.jsxs)(m.Fragment,{children:[` `,(0,m.jsx)(`a`,{href:`/policies/terms-and-conditions-page`,target:`_blank`,rel:`noopener noreferrer`,className:p.consentLink,children:n(`checkout.termsAndConditions`,`Terms and Conditions`)})]})]})}),(0,m.jsx)(o,{field:`wechatAgreePrivacy`,initialValue:!0,onChange:e=>b(e.target.checked),classes:{labelModifier:p.consentLabel},label:(0,m.jsxs)(l.Fragment,{children:[u&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`a`,{href:`/policies/privacy-policy`,target:`_blank`,rel:`noopener noreferrer`,className:p.consentLink,children:n(`checkout.privacyPolicy`,`Privacy Policy`)}),` `]}),n(`account.agreeToPrivacy`,`I have reviewed and agree to the`),!u&&(0,m.jsxs)(m.Fragment,{children:[` `,(0,m.jsx)(`a`,{href:`/policies/privacy-policy`,target:`_blank`,rel:`noopener noreferrer`,className:p.consentLink,children:n(`checkout.privacyPolicy`,`Privacy Policy`)})]})]})})]}),(0,m.jsxs)(`footer`,{children:[(0,m.jsx)(c,{onClick:d,disabled:!x,children:n(`global.yes`,`Yes`)}),(0,m.jsx)(c,{onClick:()=>g(!1),children:n(`global.cancel`,`Cancel`)})]})]})]})});export{h as default};