{"version":3,"file":"Calendly_migration.BbRTXbAx.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/N4JF8LNl8bzPM2chvbxM/9tx968r3zm1ZJrrFm2sF/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(\"div\",{...props,// onClick={handleMigrateClick}\ndisabled:loading,\"data-cal-link\":\"amit/quick-chat\",\"data-cal-namespace\":\"quick-chat\",\"data-cal-config\":JSON.stringify({layout:\"month_view\",useSlotsViewOnSmallScreen:true}),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\":{\"withMigration\":{\"type\":\"reactHoc\",\"name\":\"withMigration\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withMigrationMessage\":{\"type\":\"reactHoc\",\"name\":\"withMigrationMessage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Calendly_migration.map"],"mappings":"iLAAqN,SAAgB,EAAc,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAQ,GAAYA,EAAS,EAAK,EAAO,CAAC,EAAgB,GAAoBA,EAAS,MAAM,EAAO,CAAC,EAAM,GAAU,EAAS,EAE7Y,EAAW,cAAyL,OAAxK,EAAS,EAAW,gBAAyB,IAAkB,UAAW,EAAW,uBAAgC,IAAkB,UAAS,EAAW,aAAiC,EAAK,MAAM,CAAC,GAAG,EAC3O,SAAS,EAAQ,gBAAgB,kBAAkB,qBAAqB,aAAa,kBAAkB,KAAK,UAAU,CAAC,OAAO,aAAa,0BAA0B,EAAI,CAAC,EAAE,MAAM,CAAC,GAAG,EAAM,MAAM,QAAQ,EAAQ,GAAG,EAAE,OAAO,EAAQ,cAAc,SAAS,EAAE,SAAS,CAAU,CAAC,CAAE,CAAE,CAAC,SAAgB,EAAqB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,GAAO,EAAS,EAAyC,OAAnC,EAAM,iBAAiD,EAAK,EAAU,CAAC,MAAM,CAAC,GAAG,EAAM,MAAM,MAAM,EAAM,kBAAkB,QAAQ,UAAU,IAAA,EAAS,EAAE,GAAG,EAAM,KAAK,EAAM,gBAAgB,CAAC,EAA/J,IAAiK,CAAE,uBAH1gB,IAA4B,IAAqE,EAAO,EAAS,EAAY,CAAC,iBAAiB,GAAG,gBAAgB,MAAM,CAAC"}