{"version":3,"file":"ConditionalButton.1DJbAyAW.mjs","names":["useState","error"],"sources":["https:/framerusercontent.com/modules/hpLuTH2AC47HL9RfboRG/tswu7TkfqdQbtMI291e9/ConditionalButton.js"],"sourcesContent":["//ConditionalButton.tsx - Fixed imports\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";// FIXED: Dynamic imports for auth and user services\nconst getServices=async()=>{try{// Try AuthService.tsx first\nconst authModule=await import(\"https://framerusercontent.com/modules/rqty3k2pcUdBCQMNuPng/TCdUSQsPenL0hHbFkiqS/AuthService.js\");const authService=authModule.default;// For user service, we'll use the createUserService from firebaseService\nconst firebaseModule=await import(\"https://framerusercontent.com/modules/MVxoUPm9a518STzZ0ZlF/BJkEU4d7izVJkzlH1txJ/firebaseService.js\");const userService=firebaseModule.createUserService();return{authService,userService};}catch(error){console.error(\"Failed to import services:\",error);throw new Error(\"Could not load authentication services\");}};export default function ConditionalButton({buttonText=\"Button\",targetUrl=\"/\",requiredRoles=[],showWhenAuthenticated=\"always\",mobileOnly=false,desktopOnly=false,buttonStyle=\"ghost\",onClick}){const[isAuthenticated,setIsAuthenticated]=useState(false);const[userRole,setUserRole]=useState(\"\");const[loading,setLoading]=useState(true);const[isMobile,setIsMobile]=useState(false);const[services,setServices]=useState(null);const[error,setError]=useState(\"\");// Load services\nuseEffect(()=>{const loadServices=async()=>{try{const loadedServices=await getServices();setServices(loadedServices);}catch(err){setError(err.message);console.error(\"Failed to load services:\",err);}};loadServices();},[]);// Check if mobile/desktop\nuseEffect(()=>{const checkMobile=()=>{setIsMobile(window.innerWidth<=768);};checkMobile();window.addEventListener(\"resize\",checkMobile);return()=>window.removeEventListener(\"resize\",checkMobile);},[]);// Auth state management\nuseEffect(()=>{if(!services)return;let mounted=true;const unsubscribe=services.authService.onAuthStateChanged(async firebaseUser=>{if(!mounted)return;setLoading(true);try{if(firebaseUser){setIsAuthenticated(true);// Get user profile for role\nconst profileResult=await services.userService.getUserProfile(firebaseUser.uid);if(profileResult.success&&mounted){setUserRole(profileResult.data.role||\"user\");}}else{setIsAuthenticated(false);setUserRole(\"\");}}catch(error){console.error(\"Error in auth state change:\",error);if(mounted){setIsAuthenticated(false);setUserRole(\"\");}}finally{if(mounted){setLoading(false);}}});return()=>{mounted=false;unsubscribe();};},[services]);// Determine visibility\nconst shouldShow=()=>{// Show error if services failed to load\nif(error)return true// Show error message\n;// Hide during loading or if services not loaded\nif(loading||!services)return false;// Check mobile/desktop only restrictions\nif(mobileOnly&&!isMobile)return false;if(desktopOnly&&isMobile)return false;// Check authentication requirements\nif(showWhenAuthenticated===\"authenticated\"&&!isAuthenticated)return false;if(showWhenAuthenticated===\"not-authenticated\"&&isAuthenticated)return false;// Check role requirements\nif(requiredRoles.length>0&&!isAuthenticated)return false;if(requiredRoles.length>0&&!requiredRoles.includes(userRole))return false;return true;};// Handle button click\nconst handleClick=()=>{if(onClick){onClick();}else if(targetUrl){window.location.href=targetUrl;}};// Show error if services failed to load\nif(error){return /*#__PURE__*/_jsxs(\"div\",{style:{color:\"red\",fontSize:\"12px\",padding:\"8px\"},children:[\"Service Error: \",error]});}// Don't render if shouldn't show\nif(!shouldShow()){return null;}// Get button styles\nconst getButtonStyles=()=>{const baseStyles={position:\"relative\",padding:\"8px 16px\",borderRadius:\"6px\",cursor:\"pointer\",transition:\"all 0.2s ease\",fontSize:\"14px\",fontWeight:500,border:\"1px solid transparent\",outline:\"none\",fontFamily:\"inherit\",textDecoration:\"none\",display:\"inline-block\",whiteSpace:\"nowrap\"};switch(buttonStyle){case\"primary\":return{...baseStyles,backgroundColor:\"rgb(166, 218, 255)\",color:\"rgb(4, 7, 13)\",borderColor:\"rgb(166, 218, 255)\"};case\"secondary\":return{...baseStyles,backgroundColor:\"rgba(255, 255, 255, 0.05)\",color:\"rgb(255, 255, 255)\",borderColor:\"rgba(216, 231, 242, 0.1)\"};case\"danger\":return{...baseStyles,backgroundColor:\"rgba(239, 68, 68, 0.1)\",color:\"rgb(239, 68, 68)\",borderColor:\"rgba(239, 68, 68, 0.3)\"};case\"ghost\":default:return{...baseStyles,backgroundColor:\"transparent\",color:\"rgb(213, 219, 230)\",borderColor:\"transparent\"};}};const getHoverStyles=()=>{switch(buttonStyle){case\"primary\":return{backgroundColor:\"rgb(147, 197, 253)\",borderColor:\"rgb(147, 197, 253)\"};case\"secondary\":return{backgroundColor:\"rgba(255, 255, 255, 0.1)\",borderColor:\"rgba(216, 231, 242, 0.2)\"};case\"danger\":return{backgroundColor:\"rgba(239, 68, 68, 0.2)\",borderColor:\"rgba(239, 68, 68, 0.5)\"};case\"ghost\":default:return{backgroundColor:\"rgba(255, 255, 255, 0.05)\",color:\"rgb(255, 255, 255)\"};}};const buttonStyles=getButtonStyles();const hoverStyles=getHoverStyles();return /*#__PURE__*/_jsx(\"button\",{style:buttonStyles,onClick:handleClick,onMouseEnter:e=>{Object.assign(e.currentTarget.style,hoverStyles);},onMouseLeave:e=>{Object.assign(e.currentTarget.style,buttonStyles);},children:buttonText});}// Property controls for Framer\naddPropertyControls(ConditionalButton,{buttonText:{type:ControlType.String,defaultValue:\"Button\",title:\"Button Text\"},targetUrl:{type:ControlType.String,defaultValue:\"/\",title:\"Target URL\"},requiredRoles:{type:ControlType.Array,control:{type:ControlType.Enum,options:[\"admin\",\"vendor\",\"user\"]},defaultValue:[],title:\"Required Roles\"},showWhenAuthenticated:{type:ControlType.Enum,options:[\"always\",\"authenticated\",\"not-authenticated\"],optionTitles:[\"Always Show\",\"Only When Signed In\",\"Only When Signed Out\"],defaultValue:\"always\",title:\"Authentication Requirement\"},mobileOnly:{type:ControlType.Boolean,defaultValue:false,title:\"Mobile Only\"},desktopOnly:{type:ControlType.Boolean,defaultValue:false,title:\"Desktop Only\"},buttonStyle:{type:ControlType.Enum,options:[\"primary\",\"secondary\",\"ghost\",\"danger\"],defaultValue:\"ghost\",title:\"Button Style\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default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