{"version":3,"file":"AppleButton.CmLsMycn.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/KvbKKSrcxpHsvTV9cn5c/B5JgFjmXK5VJCHmaxolO/AppleButton.js"],"sourcesContent":["// Sign in with Apple Button for Framer\n// - Uses Apple JS API\n// - Captures email (when available) from ID token\n// - Calls handleEmailUpdate(email) and handleError(message)\n//\n// IMPORTANT:\n// 1. Replace APPLE_CLIENT_ID and APPLE_REDIRECT_URI with your values.\n// 2. Apple requires you to configure Services ID + redirect URL in Apple Developer.\n// 3. Email is only guaranteed on first authorization; subsequent logins may not include it.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";const APPLE_CLIENT_ID=\"com.thenightsky.save-design-svc\";const APPLE_REDIRECT_URI=\"https://www.thenightsky.com/redirect\";const APPLE_SCOPE=\"name email\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function AppleButton({handleEmailUpdate,handleError,style:cssStyle}){const buttonRef=useRef(null);const[isDisabled,setIsDisabled]=useState(false);const isInitialized=useRef(false);const decodeJWT=token=>{try{const parts=token.split(\".\");if(parts.length!==3)throw new Error(\"Invalid JWT token format\");const payload=parts[1];const base64=payload.replace(/-/g,\"+\").replace(/_/g,\"/\");const paddedBase64=base64+\"=\".repeat((4-base64.length%4)%4);const decodedPayload=atob(paddedBase64);return JSON.parse(decodedPayload);}catch(error){console.error(\"Error decoding Apple ID JWT:\",error);return null;}};const initApple=()=>{try{if(typeof window===\"undefined\")return;if(!window.AppleID?.auth)return;if(isInitialized.current)return;window.AppleID.auth.init({clientId:APPLE_CLIENT_ID,scope:APPLE_SCOPE,redirectURI:APPLE_REDIRECT_URI,usePopup:true});isInitialized.current=true;}catch(error){console.error(\"Error initializing Sign in with Apple:\",error);handleError(\"Sign in with Apple is not available right now.\");}};const ensureScript=()=>{if(typeof window===\"undefined\")return;const existing=document.querySelector('script[src*=\"appleid.cdn-apple.com/appleauth\"]');if(existing){if(window.AppleID?.auth)initApple();else{existing.addEventListener(\"load\",()=>initApple(),{once:true});}return;}const script=document.createElement(\"script\");script.src=\"https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js\";script.async=true;script.onload=()=>{initApple();};script.onerror=()=>{console.error(\"Failed to load Apple Sign In script\");handleError(\"Failed to load Sign in with Apple.\");};document.body.appendChild(script);};const handleAppleClick=async()=>{try{if(!window.AppleID?.auth){handleError(\"Sign in with Apple is not ready yet.\");return;}const response=await window.AppleID.auth.signIn();const idToken=response?.authorization?.id_token;if(!idToken){handleError(\"No ID token returned from Apple.\");return;}const decoded=decodeJWT(idToken);// Apple may return email in:\n// - response.user.email (first time)\n// - decoded.email (from token claims)\nconst email=response.user?.email||decoded?.email||decoded?.emailAddress||null;if(!email){// Common case on subsequent logins:\n// Apple no longer returns email; you should rely on server-side linking.\nhandleError(\"We could not retrieve your email from Apple. Please try another sign-in option.\");return;}handleEmailUpdate(email);}catch(error){console.error(\"Error during Sign in with Apple:\",error);// Apple errors may have a .error property\nconst message=error?.error===\"popup_closed_by_user\"?\"Sign in with Apple was cancelled.\":\"Sign in with Apple failed. Please try again.\";handleError(message);setIsDisabled(true);}};useEffect(()=>{ensureScript();},[]);return /*#__PURE__*/_jsx(\"div\",{style:{...buttonStyle,...cssStyle?{...cssStyle}:{},...isDisabled?{display:\"none\"}:{}},onMouseEnter:e=>{e.currentTarget.style.boxShadow=\"0 2px 6px rgba(0,0,0,0.16)\";e.currentTarget.style.transform=\"translateY(-1px)\";},onMouseLeave:e=>{e.currentTarget.style.boxShadow=\"0 1px 3px rgba(0,0,0,0.12)\";e.currentTarget.style.transform=\"translateY(0)\";},children:/*#__PURE__*/_jsx(\"button\",{ref:buttonRef,onClick:handleAppleClick,style:{display:\"flex\",alignItems:\"center\",justifyContent:\"center\",width:\"38px\",height:\"38px\",cursor:\"pointer\",padding:0,border:\"none\",background:\"none\",boxShadow:\"none\"},\"aria-label\":\"Sign in with Apple\",children:/*#__PURE__*/_jsx(\"svg\",{width:\"22\",height:\"22\",viewBox:\"0 0 24 24\",xmlns:\"http://www.w3.org/2000/svg\",children:/*#__PURE__*/_jsx(\"path\",{d:\"M16.365 1.43c0 1.14-.417 2.097-1.245 2.948-.9.93-1.984 1.47-3.17 1.386-.05-1.09.442-2.118 1.26-2.93.4-.405.9-.744 1.5-1.005.6-.27 1.17-.42 1.655-.46.02.35.04.69.04 1.06zM21.5 17.24c-.32.74-.7 1.42-1.14 2.05-.6.86-1.09 1.45-1.47 1.78-.59.54-1.22.82-1.9.84-.48 0-1.06-.14-1.75-.43-.69-.28-1.33-.43-1.92-.43-.6 0-1.25.15-1.96.43-.71.29-1.28.44-1.71.45-.65.03-1.3-.26-1.96-.86-.42-.36-.94-.98-1.56-1.86-.67-.93-1.22-2.01-1.65-3.26-.46-1.36-.69-2.68-.69-3.95 0-1.46.32-2.72.96-3.8.5-.85 1.16-1.52 1.98-2 .82-.49 1.7-.75 2.63-.77.52 0 1.2.16 2.02.47.82.31 1.35.47 1.59.47.18 0 .77-.19 1.78-.56.95-.34 1.75-.48 2.4-.43 1.78.14 3.12.85 3.99 2.13-1.59.96-2.38 2.31-2.38 4.04 0 1.35.5 2.48 1.51 3.36.45.4.95.71 1.5.93-.12.34-.25.68-.39 1.02z\",fill:\"#000000\"})})})});}const buttonStyle={display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",width:\"40px\",height:\"40px\",borderRadius:\"5px\",border:\"1px solid #121824\",boxShadow:\"0 1px 3px rgba(0,0,0,0.12)\"};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AppleButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AppleButton.map"],"mappings":"8IAYG,SAAwB,EAAY,CAAC,oBAA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