{"version":3,"file":"Calendly_migration.DO-mMEAx.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/N4JF8LNl8bzPM2chvbxM/MxTyC1Yl9x7kVyRjiJQO/Calendly_migration.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const useStore=createStore({migrationMessage:\"\",migrationStatus:\"idle\"});export function withMigration(Component){return props=>{const[loading,setLoading]=useState(false);const[migrationStatus,setMigrationStatus]=useState(\"idle\");const[store,setStore]=useStore();const handleMigrateClick=async()=>{setLoading(true);setMigrationStatus(\"loading\");setStore({migrationStatus:\"loading\",migrationMessage:\"\"});try{// Fetch token from Cal.com API\nconst response=await fetch(\"https://cal.com/api/integuru/initialize-token\",{method:\"GET\",headers:{\"Content-Type\":\"application/json\"},credentials:\"include\"});if(!response.ok){throw new Error(\"Failed to get token\");}const data=await response.json();const accessToken=data.access_token;if(window.Taiki&&accessToken){const TaikiModal=window.Taiki.Create({token:accessToken,platform:\"calendly\",environment:\"production\",onSuccess:()=>handleAuthSuccess(accessToken),onExit:handleAuthExit});TaikiModal.open();}else{throw new Error(\"Taiki not loaded or token missing\");}}catch(error){console.error(\"Error initializing token:\",error);setMigrationStatus(\"error\");setStore({migrationStatus:\"error\",migrationMessage:\"Failed to authenticate with Calendly. Please try again.\"});setLoading(false);}};const handleAuthSuccess=async accessToken=>{try{const response=await fetch(\"/api/integuru/migrate-calendly\",{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},credentials:\"include\",body:JSON.stringify({token:accessToken})});if(!response.ok){throw new Error(\"Migration failed\");}const data=await response.json();if(data.failed>0){setMigrationStatus(\"error\");setStore({migrationStatus:\"error\",migrationMessage:`Migration partially completed. Created: ${data.created}, Failed: ${data.failed}`});}else{setMigrationStatus(\"success\");setStore({migrationMessage:`Successfully migrated ${data.created} event type${data.created!==1?\"s\":\"\"}!`,migrationStatus:\"success\"});}}catch(error){console.error(\"Error migrating event types:\",error);setMigrationStatus(\"error\");setStore({migrationMessage:\"Failed to migrate events. Please try again or contact support.\",migrationStatus:\"error\"});}finally{setLoading(false);}};const handleAuthExit=()=>{if(migrationStatus!==\"idle\"&&migrationStatus!==\"loading\"){return;}setMigrationStatus(\"error\");setStore({migrationMessage:\"Authentication cancelled. Please try again.\",migrationStatus:\"error\"});setLoading(false);};// Determine button text based on state\nlet buttonText=\"Migrate Now\";if(loading){buttonText=\"Processing...\";}else if(migrationStatus===\"success\"){buttonText=\"✓ Migration Complete\";}else if(migrationStatus===\"error\"){buttonText=\"Try Again\";}return /*#__PURE__*/_jsx(Component,{...props,onClick:handleMigrateClick,disabled:loading,style:{...props.style,opacity:loading?.6:1,cursor:loading?\"not-allowed\":\"pointer\"},children:buttonText});};}export function withMigrationMessage(Component){return props=>{const[store]=useStore();if(!store.migrationMessage)return null;return /*#__PURE__*/_jsx(Component,{style:{...props.style,color:store.migrationStatus===\"error\"?\"#EF4444\":undefined},...props,text:store.migrationMessage});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withMigrationMessage\":{\"type\":\"reactHoc\",\"name\":\"withMigrationMessage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withMigration\":{\"type\":\"reactHoc\",\"name\":\"withMigration\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Calendly_migration.map"],"mappings":"wLAAqN,SAAgB,EAAc,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAM,CAAC,EAAgB,GAAoBA,EAAS,OAAO,CAAM,CAAC,EAAM,GAAU,GAAU,CAAO,EAAmB,SAAS,CAAC,EAAW,GAAK,CAAC,EAAmB,UAAU,CAAC,EAAS,CAAC,gBAAgB,UAAU,iBAAiB,GAAG,CAAC,CAAC,GAAG,CACliB,IAAM,EAAS,MAAM,MAAM,gDAAgD,CAAC,OAAO,MAAM,QAAQ,CA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