{"version":3,"file":"Address.eTiWK6os.mjs","names":["React.useState","result","postcode","houseNumber","error"],"sources":["https:/framerusercontent.com/modules/iEq8iMGewbdUxupubbir/li0IMEedQi5JR1uL9j7Q/Address.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{Frame,addPropertyControls,ControlType}from\"framer\";async function fetchAdditions(area_code,house_number){const response=await fetch(`https://api.energyzero.nl/v2/metering-point/location/check?area_code=${area_code}&house_number=${house_number}`,{headers:{accept:\"application/json, text/plain, */*\",\"content-type\":\"application/json\"},referrerPolicy:\"strict-origin-when-cross-origin\",method:\"POST\",mode:\"cors\",credentials:\"omit\",body:\"{}\"});if(!response.ok){throw new Error(\"Failed to fetch additions\");}const data=await response.json();if(!data.house_additions.length){throw new Error(\"No additions found for this house number.\");}return data;}// Custom debounce function\nconst debounce=(func,delay)=>{let timeoutId;return(...args)=>{clearTimeout(timeoutId);timeoutId=setTimeout(()=>{func(...args);},delay);};};export function LocationCheckForm(props){const[postcode,setPostcode]=React.useState(\"\");const[error,setError]=React.useState(\"\");const[houseNumber,setHouseNumber]=React.useState(\"\");const[result,setResult]=React.useState(null);const[selectedAddition,setSelectedAddition]=React.useState(\"\");const[loading,setLoading]=React.useState(false);const handleInitialSubmit=async(postcode,houseNumber)=>{setLoading(true);try{const result=await fetchAdditions(postcode,houseNumber);setResult(result);setError(\"\");if(result.house_additions.length===0){setError(\"No additions available for this address. Please proceed without selecting an addition.\");}else if(result.house_additions.length===1&&result.house_additions[0]!==\"\"){setSelectedAddition(result.house_additions[0]);}else{setSelectedAddition(\"Geen\");}}catch(error){setError(\"Het opgegeven adres is ongeldig\");}setTimeout(()=>{setLoading(false);},750);};// Wrap the API call with debounce\nconst debouncedFetchAdditionsApiCall=debounce(handleInitialSubmit,750);React.useEffect(()=>{setError(\"\")// Clear previous error\n;setResult(null)// Clear previous additions\n;const cleanPostcode=postcode.trim().toUpperCase();const cleanHouseNumber=parseInt(houseNumber.replace(/[^0-9]/g,\"\"),10);if(/^(?:\\d{0,3}|\\d{4}\\s?[A-Z]{0,2})$/.test(cleanPostcode)&&!isNaN(cleanHouseNumber)){debouncedFetchAdditionsApiCall(cleanPostcode,cleanHouseNumber);}},[houseNumber,postcode]);const handleFinalSubmit=()=>{let url=\"https://get.hegg.energy/entry/address?\"+\"houseNumber=\"+houseNumber+\"&houseNumberAddition=\"+selectedAddition.replace(\"Geen\",\"\")+\"&postalCode=\"+postcode+\"&ref=widget\"+\"&installPartner=\"+props.partnerRef;if(props.collectiveId){url+=\"&collectiveId=\"+props.collectiveId;}window.location.href=url;};return /*#__PURE__*/_jsxs(Frame,{size:\"100%\",style:{background:\"none\",height:\"auto\",position:\"relative\"},children:[/*#__PURE__*/_jsxs(\"style\",{children:[` \n                ::placeholder { \n                    color: #D9D9D9; \n                }`,`\n                    select[disabled] {\n                        filter: opacity(0.75);\n                    }\n                `]}),/*#__PURE__*/_jsxs(\"div\",{style:{display:\"grid\",gridTemplateColumns:props.direction?\"1fr\":\"1fr 1fr\",gap:\"16px\",padding:\"0\"},children:[/*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",flexDirection:\"row\",order:\"1\",gap:\"8px\",padding:\"0\"},children:[/*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\"},children:[/*#__PURE__*/_jsx(\"label\",{style:{position:\"absolute\",top:\"8px\",left:\"8px\",fontSize:\"12px\",fontFamily:\"'DIN Condensed Bold', 'DIN Condensed Bold Placeholder', sans-serif\",textTransform:\"uppercase\"},children:\"Postcode\"}),/*#__PURE__*/_jsx(\"input\",{type:\"text\",value:postcode,onChange:e=>{if(houseNumber!==\"\"){setHouseNumber(\"\");}setPostcode(e.target.value);},placeholder:\"1234AB\",style:{width:\"100%\",height:\"64px\",padding:\"18px 8px 8px 8px\",background:\"#fff\",color:\"#3e4836\",border:\"1px #ddd solid\",fontSize:\"24px\",fontStyle:\"normal\",fontWeight:\"400\",fontFamily:\"'PT Serif', 'PT Serif Placeholder', serif\"}})]}),/*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\"},children:[/*#__PURE__*/_jsx(\"label\",{style:{position:\"absolute\",top:\"8px\",left:\"8px\",fontSize:\"12px\",fontFamily:\"'DIN Condensed Bold', 'DIN Condensed Bold Placeholder', sans-serif\",textTransform:\"uppercase\"},children:\"Huisnummer\"}),/*#__PURE__*/_jsx(\"input\",{type:\"text\",value:houseNumber,onChange:e=>{setHouseNumber(e.target.value);},placeholder:\"12\",style:{width:\"100%\",height:\"64px\",padding:\"18px 8px 8px 8px\",background:\"#fff\",color:\"#3e4836\",border:\"1px #ddd solid\",fontSize:\"24px\",fontStyle:\"normal\",fontWeight:\"400\",fontFamily:\"'PT Serif', 'PT Serif Placeholder', serif\"}})]}),/*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\"},children:[/*#__PURE__*/_jsx(\"label\",{style:{position:\"absolute\",top:\"8px\",left:\"8px\",fontSize:\"12px\",fontFamily:\"'DIN Condensed Bold', 'DIN Condensed Bold Placeholder', sans-serif\",textTransform:\"uppercase\"},children:\"Toevoeging\"}),/*#__PURE__*/_jsx(\"select\",{onChange:e=>setSelectedAddition(e.target.value),value:selectedAddition,style:{width:\"64px\",height:\"64px\",padding:\"18px 8px 8px 8px\",background:\"#fff\",color:\"#3e4836\",border:\"1px #ddd solid\",fontSize:\"24px\",fontStyle:\"normal\",fontWeight:\"400\",fontFamily:\"'PT Serif', 'PT Serif Placeholder', serif\"},disabled:result&&result.house_additions.filter(ha=>ha!==\"\").length>=1?null:\"disabled\",children:result?.house_additions?.map((addition,index)=>addition===\"\"?/*#__PURE__*/_jsx(\"option\",{selected:true,children:\"Geen\"},index):/*#__PURE__*/_jsx(\"option\",{value:addition,children:addition},index))})]})]}),result||error&&!loading?/*#__PURE__*/_jsxs(\"div\",{style:{gridColumn:props.direction?\"span 1\":\"span 2\",order:props.direction?\"1\":\"4\",padding:\"12px\",borderRadius:\"999px\",background:\"#f5f5f5\",fontSize:\"14px\",fontStyle:\"normal\",fontWeight:\"400\",fontFamily:\"'PT Serif', 'PT Serif Placeholder', serif\"},children:[result?.street_name&&result?.house_number&&/*#__PURE__*/_jsxs(\"p\",{children:[result.street_name,\" \",result.house_number,selectedAddition&&selectedAddition!==\"Geen\"?\" \"+selectedAddition:\"\",\", \",postcode,\" \",result.city]}),error&&/*#__PURE__*/_jsx(\"p\",{children:error&&/*#__PURE__*/_jsx(\"div\",{children:error})})]}):null,/*#__PURE__*/_jsx(\"button\",{onClick:handleFinalSubmit,disabled:!selectedAddition,style:{order:\"3\",width:\"100%\",padding:\"12px 16px\",height:\"64px\",cursor:\"pointer\",backgroundColor:\"#3e4836\",color:\"#fff\",border:\"0\",borderRadius:\"999px\",fontSize:\"24px\",fontFamily:\"'DIN Condensed Bold', 'DIN Condensed Bold Placeholder', sans-serif\",textTransform:\"uppercase\"},children:props.buttonTitle})]})]});}addPropertyControls(LocationCheckForm,{direction:{type:ControlType.Boolean,title:\"Toggle\",enabledTitle:\"Vertical\",disabledTitle:\"Horizontal\"},buttonTitle:{type:ControlType.String,title:\"Button title\",defaultValue:\"Check jouw aanbod\"},partnerRef:{type:ControlType.String,title:\"Partner ref\",defaultValue:\"\"},collectiveId:{type:ControlType.String,title:\"Collective ID\",defaultValue:\"\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"LocationCheckForm\":{\"type\":\"reactComponent\",\"name\":\"LocationCheckForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Address.map"],"mappings":"wMAA+I,eAAe,EAAe,EAAU,EAAa,CAAC,IAAM,EAAS,MAAM,MAAM,wEAAwE,EAAU,gBAAgB,IAAe,CAAC,QAAQ,CAAC,OAAO,oCAAoC,eAAe,mBAAmB,CAAC,eAAe,kCAAkC,OAAO,OAAO,KAAK,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,EAAS,GAAI,MAAU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