{"version":3,"file":"Affiliate_Code.D7ASaCuF.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/MnknSb1TGLG2a4VrCFCf/gsMUHYJA7PxheeQPsngo/Affiliate_Code.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";const API_URL=\"https://n8n.h1.liloplus.de/webhook/getCode\";export default function AffiliateCode({email=\"\",firstName=\"\",style}){const[state,setState]=useState({status:\"idle\"});const[copied,setCopied]=useState(false);useEffect(()=>{const trimmed=email.trim();if(!trimmed||!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)){setState({status:\"idle\"});return;}const controller=new AbortController;setState({status:\"loading\"});fetch(`${API_URL}?email=${encodeURIComponent(trimmed)}&firstName=${encodeURIComponent(firstName)}`,{signal:controller.signal}).then(async res=>{if(!res.ok)throw new Error(`Server error (${res.status})`);const data=await res.json();if(!data||typeof data.code!==\"string\"||!data.code.trim()){throw new Error(\"No code returned\");}setState({status:\"success\",code:data.code});}).catch(err=>{if(err instanceof Error&&err.name===\"AbortError\")return;setState({status:\"error\",message:err instanceof Error?err.message:\"Unknown error\"});});return()=>controller.abort();},[email,firstName]);const copyToClipboard=async text=>{try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(text);}else{const ta=document.createElement(\"textarea\");ta.value=text;ta.style.position=\"fixed\";ta.style.left=\"-9999px\";document.body.appendChild(ta);ta.select();document.execCommand(\"copy\");document.body.removeChild(ta);}setCopied(true);setTimeout(()=>setCopied(false),2e3);}catch{/* silently fail */}};const retryFetch=()=>{const trimmed=email.trim();if(!trimmed)return;setState({status:\"loading\"});fetch(`${API_URL}?email=${encodeURIComponent(trimmed)}&firstName=${encodeURIComponent(firstName)}`).then(async res=>{if(!res.ok)throw new Error(`Server error (${res.status})`);const data=await res.json();if(!data||typeof data.code!==\"string\"||!data.code.trim()){throw new Error(\"No code returned\");}setState({status:\"success\",code:data.code});}).catch(err=>{setState({status:\"error\",message:err instanceof Error?err.message:\"Unknown error\"});});};/* ---------- styles ---------- */const card={width:\"100%\",background:\"#fff\",borderRadius:12,border:\"1px solid #E5E7EB\",boxShadow:\"0 1px 3px rgba(0,0,0,.08)\",padding:\"24px 28px\",fontFamily:'-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif'};const heading={margin:0,marginBottom:16,fontSize:16,fontWeight:600,color:\"#111827\"};const codeRow={display:\"flex\",alignItems:\"center\",gap:10};const codeBox={flex:1,padding:\"10px 14px\",fontFamily:\"'SF Mono', SFMono-Regular, Consolas, monospace\",fontSize:15,fontWeight:600,letterSpacing:.5,color:\"#111827\",background:\"#F9FAFB\",border:\"1px solid #E5E7EB\",borderRadius:8,userSelect:\"all\"};const btn={display:\"inline-flex\",alignItems:\"center\",gap:6,padding:\"9px 16px\",fontSize:13,fontWeight:600,border:\"none\",borderRadius:8,cursor:\"pointer\",transition:\"background .15s\",color:\"#fff\",background:copied?\"#16A34A\":\"#2563EB\"};const spinner={width:20,height:20,border:\"2.5px solid #E5E7EB\",borderTopColor:\"#2563EB\",borderRadius:\"50%\",animation:\"spin .6s linear infinite\"};/* ---------- render ---------- */if(state.status===\"idle\"){return /*#__PURE__*/_jsx(\"div\",{style:{...card,...style,textAlign:\"center\",color:\"#9CA3AF\"},children:/*#__PURE__*/_jsx(\"p\",{style:{margin:0,fontSize:14},children:\"Enter your email to see your affiliate code.\"})});}if(state.status===\"loading\"){return /*#__PURE__*/_jsxs(\"div\",{style:{...card,...style,display:\"flex\",alignItems:\"center\",justifyContent:\"center\",gap:12},children:[/*#__PURE__*/_jsx(\"style\",{children:`@keyframes spin{to{transform:rotate(360deg)}}`}),/*#__PURE__*/_jsx(\"div\",{style:spinner}),/*#__PURE__*/_jsx(\"span\",{style:{color:\"#6B7280\",fontSize:14},children:\"Loading...\"})]});}if(state.status===\"error\"){return /*#__PURE__*/_jsxs(\"div\",{style:{...card,...style},children:[/*#__PURE__*/_jsx(\"p\",{style:{margin:0,marginBottom:12,color:\"#DC2626\",fontSize:14},children:state.message}),/*#__PURE__*/_jsx(\"button\",{onClick:retryFetch,style:{...btn,background:\"#DC2626\"},children:\"Retry\"})]});}if(state.code===\"NOFILE\")return null;return /*#__PURE__*/_jsxs(\"div\",{style:{...card,...style},children:[/*#__PURE__*/_jsx(\"h3\",{style:heading,children:\"Dein Aktionscode\"}),/*#__PURE__*/_jsxs(\"div\",{style:codeRow,children:[/*#__PURE__*/_jsx(\"div\",{style:codeBox,children:state.code}),!state.code.includes(\"wird gepr\\xfcft\")&&/*#__PURE__*/_jsx(\"button\",{onClick:()=>copyToClipboard(state.code),style:btn,children:copied?\"Kopiert!\":\"Kopieren\"})]})]});}addPropertyControls(AffiliateCode,{email:{type:ControlType.String,title:\"Email\",defaultValue:\"\",description:\"The affiliate partner's email address\"},firstName:{type:ControlType.String,title:\"First Name\",defaultValue:\"\",description:\"The affiliate partner's first name\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AffiliateCode\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Affiliate_Code.map"],"mappings":"uMAA8M,SAAwB,EAAc,CAAC,QAAM,GAAG,YAAU,GAAG,SAAO,CAAC,GAAK,CAAC,EAAM,GAAUA,EAAS,CAAC,OAAO,OAAO,CAAC,CAAM,CAAC,EAAO,GAAWA,EAAS,GAAM,CAAC,MAAc,CAAC,IAAM,EAAQ,EAAM,MAAM,CAAC,GAAG,CAAC,GAAS,CAAC,6BAA6B,KAAK,EAAQ,CAAC,CAAC,EAAS,CAAC,OAAO,OAAO,CAAC,CAAC,OAAQ,IAAM,EAAW,IAAI,gBAA6jB,OAA7iB,EAAS,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,GAAG,EAAQ,SAAS,mBAAmB,EAAQ,CAAC,aAAa,mBAAmB,EAAU,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