{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/WHAwRhDFm10rIiCunTFc/YqZhTTiPfPmB6oLdww2d/WithApr.js", "ssg:https://framerusercontent.com/modules/8DS8UFNXCBoa8h9Va0ps/RfgNEHZchhs1i7LFC8iR/CalculateFinanceBasedOnDynamicAPR.js"],
  "sourcesContent": ["import{jsx as _jsx}from\"react/jsx-runtime\";import React,{useEffect,useState}from\"react\";const DEFAULT_APR=\"xx.x\";function containsAprPlaceholder(children){if(typeof children===\"string\"){return children.includes(\"{apr}\");}if(Array.isArray(children)){return children.some(child=>containsAprPlaceholder(child));}if(children&&typeof children===\"object\"){const element=children;if(element.props&&element.props.children){return containsAprPlaceholder(element.props.children);}}return false;}function replaceAprInChildren(children,apr,defaultApr=DEFAULT_APR){if(typeof children===\"string\"){return children.replace(/{apr}/g,apr||defaultApr);}if(Array.isArray(children)){return children.map(child=>replaceAprInChildren(child,apr,defaultApr));}if(children&&typeof children===\"object\"){const element=children;if(element.props&&element.props.children){const updatedChildren=replaceAprInChildren(element.props.children,apr,defaultApr);return /*#__PURE__*/React.cloneElement(element,{...element.props,children:updatedChildren});}return element;}return children;}export async function getFinanceConstants(){const isProd=window.location.hostname===\"www.oodlecarfinance.com\";try{const response=await fetch(`https://${!isProd?\"staging.\":\"\"}webeng.oodlefinance.com/finance-constants-service/finance-constants`,{method:\"GET\",headers:{\"Content-Type\":\"application/json\"}});const result=await response.json();return result===null||result===void 0?void 0:result.LOAN_DEFAULTS;}catch{return DEFAULT_APR;}}export function withApr(Component){return props=>{const[apr,setApr]=useState(DEFAULT_APR);useEffect(()=>{async function fetchApr(){if(containsAprPlaceholder(props.children)){const financeConstants=await getFinanceConstants();const fetchedApr=(financeConstants===null||financeConstants===void 0?void 0:financeConstants.APR)||DEFAULT_APR;setApr(fetchedApr);}}fetchApr();},[props.children]);const updatedChildren=replaceAprInChildren(props.children,apr);return /*#__PURE__*/_jsx(Component,{...props,children:updatedChildren});};}\nexport const __FramerMetadata__ = {\"exports\":{\"getFinanceConstants\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withApr\":{\"type\":\"reactHoc\",\"name\":\"withApr\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithApr.map", "import{jsx as _jsx}from\"react/jsx-runtime\";import React,{useEffect,useState}from\"react\";import{getFinanceConstants}from\"https://framerusercontent.com/modules/WHAwRhDFm10rIiCunTFc/YqZhTTiPfPmB6oLdww2d/WithApr.js\";function formatNumber(value,decimalPlace){if(!value)return\"\";return parseFloat(value).toLocaleString(\"en-GB\",{minimumFractionDigits:2,maximumFractionDigits:2});}function formatRate(value,decimalPlace){if(!value)return\"\";return parseFloat(value).toLocaleString(\"en-GB\",{minimumFractionDigits:1,maximumFractionDigits:1});}function replacePlaceholdersInChildren(children,values){if(typeof children===\"string\"){return children.replace(\"{termInYears}\",formatNumber(values.TERM_IN_YEARS)).replace(\"{monthlyPayment}\",formatNumber(values.DEFAULT_MONTHLY_PAYMENT)).replace(\"{interestRate}\",formatRate(values.FIXED_INTEREST_RATE)).replace(\"{firstPayment}\",formatNumber(values.DEFAULT_FIRST_PAYMENT)).replace(\"{totalCostOfCredit}\",formatNumber(values.DEFAULT_TOTAL_COST_OF_CREDIT)).replace(\"{totalAmountPayable}\",formatNumber(values.DEFAULT_TOTAL_REPAYMENT_AMOUNT)).replace(\"{apr}\",formatRate(values.APR)).replace(\"{minApr}\",formatRate(values.MIN_APR));}if(Array.isArray(children)){return children.map(child=>replacePlaceholdersInChildren(child,values));}if(/*#__PURE__*/React.isValidElement(children)){return /*#__PURE__*/React.cloneElement(children,{children:replacePlaceholdersInChildren(children.props.children,values)});}return children;}export function representativeExample(Component){return props=>{const[calculatedValues,setCalculatedValues]=useState({TERM_IN_YEARS:\"5\",DEFAULT_MONTHLY_PAYMENT:\"232.53\",FIXED_INTEREST_RATE:\"14.71\",DEFAULT_FIRST_PAYMENT:\"282.53\",APR:\"14.7\",MIN_APR:\"10.9\",DEFAULT_TOTAL_COST_OF_CREDIT:\"3900\",DEFAULT_TOTAL_REPAYMENT_AMOUNT:\"13900\"});useEffect(()=>{async function fetchAndCalculate(){const financeConstants=await getFinanceConstants();setCalculatedValues({TERM_IN_YEARS:financeConstants?.TERM_IN_YEARS,DEFAULT_MONTHLY_PAYMENT:financeConstants?.DEFAULT_MONTHLY_PAYMENT,FIXED_INTEREST_RATE:financeConstants?.FIXED_INTEREST_RATE,DEFAULT_FIRST_PAYMENT:financeConstants?.DEFAULT_FIRST_PAYMENT,APR:financeConstants?.APR,MIN_APR:financeConstants?.MIN_APR,DEFAULT_TOTAL_COST_OF_CREDIT:financeConstants?.DEFAULT_TOTAL_COST_OF_CREDIT,DEFAULT_TOTAL_REPAYMENT_AMOUNT:financeConstants?.DEFAULT_TOTAL_REPAYMENT_AMOUNT});}fetchAndCalculate();},[props.children]);const updatedChildren=replacePlaceholdersInChildren(props.children,calculatedValues);return /*#__PURE__*/_jsx(Component,{...props,children:updatedChildren});};}\nexport const __FramerMetadata__ = {\"exports\":{\"representativeExample\":{\"type\":\"reactHoc\",\"name\":\"representativeExample\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CalculateFinanceBasedOnDynamicAPR.map"],
  "mappings": "uGAAwF,IAAMA,EAAY,OAAO,SAASC,EAAuBC,EAAS,CAAC,GAAG,OAAOA,GAAW,SAAU,OAAOA,EAAS,SAAS,OAAO,EAAG,GAAG,MAAM,QAAQA,CAAQ,EAAG,OAAOA,EAAS,KAAKC,GAAOF,EAAuBE,CAAK,CAAC,EAAG,GAAGD,GAAU,OAAOA,GAAW,SAAS,CAAC,IAAME,EAAQF,EAAS,GAAGE,EAAQ,OAAOA,EAAQ,MAAM,SAAU,OAAOH,EAAuBG,EAAQ,MAAM,QAAQ,CAAG,CAAC,MAAO,EAAM,CAAC,SAASC,EAAqBH,EAASI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L,EAAoB,CAAC,cAAcI,GAAkB,cAAc,wBAAwBA,GAAkB,wBAAwB,oBAAoBA,GAAkB,oBAAoB,sBAAsBA,GAAkB,sBAAsB,IAAIA,GAAkB,IAAI,QAAQA,GAAkB,QAAQ,6BAA6BA,GAAkB,6BAA6B,+BAA+BA,GAAkB,8BAA8B,CAAC,CAAE,CAACD,EAAkB,CAAE,EAAE,CAACL,EAAM,QAAQ,CAAC,EAAE,IAAMQ,EAAgBf,EAA8BO,EAAM,SAASC,CAAgB,EAAE,OAAoBQ,EAAKV,EAAU,CAAC,GAAGC,EAAM,SAASQ,CAAe,CAAC,CAAE,CAAE",
  "names": ["DEFAULT_APR", "containsAprPlaceholder", "children", "child", "element", "replaceAprInChildren", "apr", "defaultApr", "updatedChildren", "e", "getFinanceConstants", "isProd", "window", "result", "withApr", "Component", "props", "setApr", "ye", "ue", "fetchApr", "financeConstants", "fetchedApr", "p", "formatNumber", "value", "decimalPlace", "formatRate", "replacePlaceholdersInChildren", "children", "values", "child", "e", "representativeExample", "Component", "props", "calculatedValues", "setCalculatedValues", "ye", "ue", "fetchAndCalculate", "financeConstants", "getFinanceConstants", "updatedChildren", "p"]
}
