{"version":3,"file":"LineConnect.DsJOrgGH.mjs","names":["useStore","useState","useRef","useState","TermAccept","BtnForm"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/m793UoHur2fyR4HxGDzP/KKJlE3y7hY8Jgb46fRS5/LineConnect.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})});// Create a set function that updates the state\nconst setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});};// Store the initial state, copy the object if it's an object\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;// Update all the listeners / setters with the new value\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState);// If we unmount the component using this hook, we need to remove the listener\n// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[]);// If Data context exists, use Data, otherwise use vanilla React state\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef,useState}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import BtnForm from\"https://framer.com/m/BtnForm-A2MpqR.js@OMs61AXOjrcbjzTE4OT7\";import TermAccept from\"https://framer.com/m/TermAccept-vRTS4B.js@rLlhKwoMLm1Bp6Al8YuF\";import axios from\"https://esm.sh/axios\";// Learn more: https://www.framer.com/developers/overrides/\nconst LIFF_ID=\"2009517887-lIAgFysj\";const REDIRECT_PATH_KEY=\"liff_redirect_path\";const useStore=createStore({uid:\"\"});// fn_get_sha256('xxxx').then((text_sha256) => console.log(text_sha256));\nasync function fn_get_sha256(message){const msgUint8=new TextEncoder().encode(message)// encode as (utf-8) Uint8Array\n;const hashBuffer=await window.crypto.subtle.digest(\"SHA-256\",msgUint8)// hash the message\n;const hashArray=Array.from(new Uint8Array(hashBuffer))// convert buffer to byte array\n;const hashHex=hashArray.map(b=>b.toString(16).padStart(2,\"0\")).join(\"\");return hashHex;}function formatPhoneNumber(phone){let cleanNumber=phone.replace(/\\D/g,\"\");let result=cleanNumber;if(result.startsWith(\"+66\")){result=result.substring(3);}if(result.startsWith(\"66\")){result=result.substring(2);}if(result.startsWith(\"0\")){result=result.substring(1);}return result;}function fn_get_baseConfig_form1(dataFormBase){let configBase={method:\"post\",maxBodyLength:Infinity,url:\"https://n8n.digi-team.work/webhook/xpeng-form1\",headers:{\"Content-Type\":\"application/json\",\"x-api-key\":\"xpeng-123456\"},data:dataFormBase};return configBase;}function fn_get_baseConfig_form2(dataFormBase){let configBase={method:\"post\",maxBodyLength:Infinity,url:\"https://n8n.digi-team.work/webhook/xpeng-form2\",headers:{\"Content-Type\":\"application/json\",\"x-api-key\":\"xpeng-123456\"},data:dataFormBase};return configBase;}export function withLineConnectGetUID(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();useEffect(()=>{// 1. ฟังก์ชันสำหรับ Initialize LIFF\nconst initLiff=async()=>{try{// ตรวจสอบว่ามี liff object หรือยัง (ถ้าใช้ CDN ในหน้าโปรเจกต์)\nif(window.liff){await window.liff.init({liffId:LIFF_ID});if(window.liff.isLoggedIn()){const profile=await window.liff.getProfile();setStore({uid:profile.userId});const redirectPath=sessionStorage.getItem(REDIRECT_PATH_KEY);if(redirectPath&&redirectPath!==window.location.pathname){sessionStorage.removeItem(REDIRECT_PATH_KEY);window.location.replace(redirectPath);}}else{if(window.location.pathname!==\"/liff\"){sessionStorage.setItem(REDIRECT_PATH_KEY,window.location.pathname);}// ถ้ายังไม่ Login ให้เด้งไปหน้า Login ของ LINE\nwindow.liff.login();}}}catch(error){console.error(\"LIFF Initialization failed\",error);// setStore({ uid: \"Error: \" + error.message })\nsetStore({uid:\"\"});}};initLiff();},[]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withClickDownloadG6(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:()=>{// model\nconst brochure_model=\"G6\";// push datalayer\nif(window.dataLayer){window.dataLayer.push({event:`Click Download Brochure ${brochure_model}`,uid:store.uid});}// push form\nconst config=fn_get_baseConfig_form1(JSON.stringify({line_uid:store.uid,download_model:brochure_model}));axios.request(config).then(response=>{console.log(JSON.stringify(response.data));}).catch(error=>{console.log(error);});}});});}export function withClickDownloadX9(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:()=>{// model\nconst brochure_model=\"X9\";// push datalayer\nif(window.dataLayer){window.dataLayer.push({event:`Click Download Brochure ${brochure_model}`,uid:store.uid});}// push form\nconst config=fn_get_baseConfig_form1(JSON.stringify({line_uid:store.uid,download_model:brochure_model}));axios.request(config).then(response=>{console.log(JSON.stringify(response.data));}).catch(error=>{console.log(error);});}});});}export function withFormDriveBookBag(Component){return /*#__PURE__*/forwardRef((props,ref)=>{const[store,setStore]=useStore();const redirectDelay=1e3;const formRef=useRef(null);const[acceptStatus,setAcceptStatus]=useState(false)// false : Normal, true : Active\n;const[btnStatus,setBtnStatus]=useState(\"Default\")// Default, Loading, Disabled, Success, Error\n;const handleSubmitForm=e=>{e.preventDefault();// veridate\nif(!acceptStatus){return false;}const params=new URLSearchParams(window.location.search);const type=params.get(\"type\")||\"none\";const formData=new FormData(e.currentTarget);const data=Object.fromEntries(formData.entries());// show loading\nsetBtnStatus(\"Loading\");// call api\n// console.log(\"Serialized Home Data:\", data)\nlet dataFormBase={line_uid:store.uid,phone_number:`${data.telephone}`,type:type};let solitPhone=formatPhoneNumber(`${data.telephone}`);fn_get_sha256(dataFormBase.phone_number).then(sha256_phone_number=>{let hash_phone_66=`66${solitPhone}`;fn_get_sha256(hash_phone_66).then(sha256_hash_phone_66=>{let hash_phone_plus_66=`+66${solitPhone}`;fn_get_sha256(hash_phone_plus_66).then(sha256_hash_phone_plus_66=>{let dataSet1={event:\"submit_drive_book_bag\",uid:store.uid,phone_number:sha256_phone_number,hash_phone_66:sha256_hash_phone_66,hash_phone_plus_66:sha256_hash_phone_plus_66,type:dataFormBase.type};let dataSet2={event:\"web_form_submit_drive_book_bag\",form_type:\"form_submit_drive_book_bag\",form_data:{uid:store.uid,phone_number:dataFormBase.phone_number,type:dataFormBase.type}};let config=fn_get_baseConfig_form2(JSON.stringify(dataFormBase));axios.request(config).then(response=>{// thankyou\nsetBtnStatus(\"Success\");// push datalayer\nif(window.dataLayer){window.dataLayer.push(dataSet1);window.dataLayer.push(dataSet2);}// redirect\nsetTimeout(function(){// window.location.href = \"https://your-target-page.com\"\nwindow.location.replace(\"/thankyou-all\");},redirectDelay);}).catch(error=>{// error\nsetBtnStatus(\"Error\");});});});});return false;};return /*#__PURE__*/_jsxs(\"form\",{style:{display:\"block\",width:\"100%\"},ref:formRef,action:\"\",onSubmit:handleSubmitForm,children:[/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",width:\"100%\",justifyContent:\"center\"},children:/*#__PURE__*/_jsx(Component,{ref:ref,...props})}),/*#__PURE__*/_jsx(TermAccept,{style:{margin:\"auto\",width:\"1014px\",maxWidth:\"100%\"},variant:acceptStatus?\"Active\":\"Normal\",onClick:()=>{if(btnStatus==\"Default\"){setAcceptStatus(!acceptStatus);}}}),/*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",justifyContent:\"center\",alignItems:\"center\",margin:\"auto\",pointerEvents:`${acceptStatus?\"auto\":\"none\"}`,userSelect:`${acceptStatus?\"auto\":\"none\"}`},children:/*#__PURE__*/_jsx(BtnForm,{label:\"ตกลง\",variant:acceptStatus?btnStatus:\"Disabled\",type:\"submit\"})})]});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withLineConnectGetUID\":{\"type\":\"reactHoc\",\"name\":\"withLineConnectGetUID\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFormDriveBookBag\":{\"type\":\"reactHoc\",\"name\":\"withFormDriveBookBag\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClickDownloadX9\":{\"type\":\"reactHoc\",\"name\":\"withClickDownloadX9\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClickDownloadG6\":{\"type\":\"reactHoc\",\"name\":\"withClickDownloadG6\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LineConnect.map"],"mappings":"4RAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,CAAC,CAClD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,MAAM,EAAE,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG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