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