{"version":3,"file":"LuaPopWidget.DCQmb-Hi.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/YYBjXT4xydOciQfRE7f9/Qb68gejmdZgdEDl1AxFg/LuaPopWidget.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef}from\"react\";export function LuaPopWidget({agentId=\"luaAgent\",sessionId,authToken,environment=\"production\",position=\"bottom-right\",buttonText,buttonColor,buttonIcon,chatTitle,chatInputPlaceholder,runtimeContext,voiceModeEnabled=false,welcomeMessage,popupButtonStyles,popupButtonPositionalContainerStyles,chatTitleHeaderStyles,chatHeaderSubtitleBrandName,chatHeaderSubtitleIconUrl,chatHeaderSubtitleLinkUrl}){const chatRef=useRef(null);const widgetInstanceRef=useRef(null);const containerIdRef=useRef(`framer-chat-embed-${agentId?.replace(/[^a-zA-Z0-9]/g,\"-\")||\"default\"}-${Math.random().toString(36).substr(2,9)}`);const containerId=containerIdRef.current;useEffect(()=>{if(!agentId)return;let isMounted=true;let checkReadyInterval=null;// Cleanup function to destroy widget and clear container\nconst cleanup=()=>{if(checkReadyInterval){clearInterval(checkReadyInterval);checkReadyInterval=null;}if(widgetInstanceRef.current){widgetInstanceRef.current.destroy();widgetInstanceRef.current=null;}if(chatRef.current){chatRef.current.innerHTML=\"\";}};// Run cleanup before initializing\ncleanup();const initWidget=async()=>{// Don't initialize if component unmounted\nif(!isMounted)return;// Double-check container is empty before init\nif(chatRef.current&&chatRef.current.children.length>0){chatRef.current.innerHTML=\"\";}// Generate session ID if not provided\nconst resolvedSessionId=sessionId||localStorage.getItem(\"lua_session_id\")||(()=>{const newId=`sess-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;localStorage.setItem(\"lua_session_id\",newId);return newId;})();// Parse JSON style strings safely\nconst parseStyles=styleString=>{if(!styleString)return undefined;try{return JSON.parse(styleString);}catch{return undefined;}};// Build chat header subtitle config if any values provided\nconst chatHeaderSubtitle=chatHeaderSubtitleBrandName||chatHeaderSubtitleIconUrl||chatHeaderSubtitleLinkUrl?{visible:true,brandName:chatHeaderSubtitleBrandName,iconUrl:chatHeaderSubtitleIconUrl,linkUrl:chatHeaderSubtitleLinkUrl}:undefined;// Build config object, only including defined values\nconst config={agentId,sessionId:resolvedSessionId,displayMode:\"embedded\",environment,embeddedDisplayConfig:{targetContainerId:containerId}};// Add optional properties only if they have values\nif(authToken)config.authToken=authToken;if(position)config.position=position;if(buttonText)config.buttonText=buttonText;if(buttonColor)config.buttonColor=buttonColor;if(buttonIcon)config.buttonIcon=buttonIcon;if(chatTitle)config.chatTitle=chatTitle;if(chatInputPlaceholder)config.chatInputPlaceholder=chatInputPlaceholder;if(runtimeContext)config.runtimeContext=runtimeContext;if(voiceModeEnabled)config.voiceModeEnabled=voiceModeEnabled;if(welcomeMessage)config.welcomeMessage=welcomeMessage;if(chatHeaderSubtitle)config.chatHeaderSubtitle=chatHeaderSubtitle;const parsedPopupButtonStyles=parseStyles(popupButtonStyles);const parsedPositionalStyles=parseStyles(popupButtonPositionalContainerStyles);const parsedHeaderStyles=parseStyles(chatTitleHeaderStyles);if(parsedPopupButtonStyles)config.popupButtonStyles=parsedPopupButtonStyles;if(parsedPositionalStyles)config.popupButtonPositionalContainerStyles=parsedPositionalStyles;if(parsedHeaderStyles)config.chatTitleHeaderStyles=parsedHeaderStyles;// Final mount check before async init\nif(!isMounted)return;const instance=await window.LuaPop?.init(config);if(instance&&isMounted){widgetInstanceRef.current=instance;}else if(instance&&!isMounted){// Component unmounted during init, destroy immediately\ninstance.destroy();}};// Check if script is already loaded\nconst existingScript=document.querySelector('script[src=\"https://lua-ai-global.github.io/lua-pop/lua-pop.umd.js\"]');if(existingScript&&window.LuaPop){initWidget();}else if(!existingScript){const script=document.createElement(\"script\");script.src=\"https://lua-ai-global.github.io/lua-pop/lua-pop.umd.js\";script.onload=()=>{if(isMounted)initWidget();};document.body.appendChild(script);}else{// Script exists but LuaPop not ready yet, wait for it\ncheckReadyInterval=setInterval(()=>{if(window.LuaPop){if(checkReadyInterval)clearInterval(checkReadyInterval);checkReadyInterval=null;if(isMounted)initWidget();}},50);}return()=>{isMounted=false;cleanup();};},[agentId,sessionId,authToken,environment,position,buttonText,buttonColor,buttonIcon,chatTitle,chatInputPlaceholder,runtimeContext,voiceModeEnabled,welcomeMessage,popupButtonStyles,popupButtonPositionalContainerStyles,chatTitleHeaderStyles,chatHeaderSubtitleBrandName,chatHeaderSubtitleIconUrl,chatHeaderSubtitleLinkUrl]);return /*#__PURE__*/_jsx(\"div\",{id:containerId,ref:chatRef,style:{width:\"100%\",height:\"auto\",minHeight:\"100%\"}});}addPropertyControls(LuaPopWidget,{agentId:{type:ControlType.String,title:\"Agent ID\",description:\"Required. Your Lua agent identifier.\"},sessionId:{type:ControlType.String,title:\"Session ID\",description:\"Optional. Custom session ID. Auto-generated if not provided.\"},authToken:{type:ControlType.String,title:\"Auth token\",description:\"Optional. Authentication token for the chat session.\"},environment:{type:ControlType.Enum,title:\"Environment\",options:[\"production\",\"staging\"],optionTitles:[\"Production\",\"Staging\"],defaultValue:\"production\"},position:{type:ControlType.Enum,title:\"Position\",options:[\"bottom-right\",\"bottom-left\",\"top-right\",\"top-left\"],optionTitles:[\"Bottom right\",\"Bottom left\",\"Top right\",\"Top left\"],defaultValue:\"bottom-right\"},buttonText:{type:ControlType.String,title:\"Button text\",description:\"Text displayed on the chat button.\"},buttonColor:{type:ControlType.Color,title:\"Button color\",description:\"Background color of the chat button.\"},buttonIcon:{type:ControlType.String,title:\"Button icon URL\",description:\"URL to a custom icon for the chat button.\"},chatTitle:{type:ControlType.String,title:\"Chat title\",description:\"Title displayed in the chat header.\"},chatInputPlaceholder:{type:ControlType.String,title:\"Input placeholder\",description:\"Placeholder text for the chat input field.\",defaultValue:\"How can I help you today?\"},runtimeContext:{type:ControlType.String,title:\"Runtime context\",description:\"Additional context passed to the agent at runtime.\"},voiceModeEnabled:{type:ControlType.Boolean,title:\"Voice mode\",description:\"Enable voice input/output mode.\",defaultValue:false},welcomeMessage:{type:ControlType.String,title:\"Welcome message\",description:\"Initial welcome message shown to users.\"},chatTitleHeaderStyles:{type:ControlType.String,title:\"Header styles (JSON)\",description:'CSS styles for the header as JSON. Example: {\"background\": \"#000\", \"color\": \"#fff\"}'},popupButtonStyles:{type:ControlType.String,title:\"Button styles (JSON)\",description:\"CSS styles for the popup button as JSON.\"},popupButtonPositionalContainerStyles:{type:ControlType.String,title:\"Button container styles (JSON)\",description:\"CSS styles for the button container as JSON.\"},chatHeaderSubtitleBrandName:{type:ControlType.String,title:\"Subtitle brand name\",description:\"Brand name shown in the chat header subtitle.\"},chatHeaderSubtitleIconUrl:{type:ControlType.String,title:\"Subtitle icon URL\",description:\"Icon URL for the chat header subtitle.\"},chatHeaderSubtitleLinkUrl:{type:ControlType.String,title:\"Subtitle link URL\",description:\"Link URL for the chat header subtitle.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"LuaPopWidget\":{\"type\":\"reactComponent\",\"name\":\"LuaPopWidget\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LuaPopWidget.map"],"mappings":"+LAAmI,SAAgB,EAAa,CAAC,UAAQ,WAAW,YAAU,YAAU,cAAY,aAAa,WAAS,eAAe,aAAW,cAAY,aAAW,YAAU,uBAAqB,iBAAe,mBAAiB,GAAM,iBAAe,oBAAkB,uCAAqC,wBAAsB,8BAA4B,4BAA0B,6BAA2B,CAAC,IAAM,EAAQA,EAAO,KAAK,CAAO,EAAkBA,EAAO,KAAK,CAAsJ,EAAhIA,EAAO,qBAAqB,GAAS,QAAQ,gBAAgB,IAAI,EAAE,UAAU,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAkC,QAa5O,OAboP,MAAc,CAAC,GAAG,CAAC,EAAQ,OAAO,IAAI,EAAU,GAAS,EAAmB,KAC50B,MAAY,CAA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