{"version":3,"file":"Conditional.BiYPkOxo.mjs","names":["useState","useCallback","React","_Fragment"],"sources":["https:/framerusercontent.com/modules/SR9RaiMbrpN9q0lWIRL0/dYIOoFAqJ19scQhaWyqB/Conditional.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import React,{useState,useEffect,useCallback}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * @framerDisableUnlink\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function LogicGate(props){const{condition,content,fallbackContent,debug}=props;const[debugInfo,setDebugInfo]=useState({});const[conditionMet,setConditionMet]=useState(false);const isCanvas=RenderTarget.current()===RenderTarget.canvas;const evaluateCondition=useCallback(()=>{try{let calculatedCondition=condition;let debugVals={};const variableNames=condition.match(/\\b(?![\"'])([a-zA-Z][a-zA-Z0-9_]*)\\b(?![\"'])/g)||[];variableNames.forEach(varName=>{// Check for radio buttons\nconst radioInputs=document.querySelectorAll(`input[type=\"radio\"][name=\"${varName}\"]`);if(radioInputs.length>0){const checkedRadio=Array.from(radioInputs).find(input=>input.checked);if(checkedRadio){debugVals[varName]=checkedRadio.value;calculatedCondition=calculatedCondition.replace(new RegExp(`\\\\b${varName}\\\\b`,\"g\"),`\"${checkedRadio.value}\"`);}else{debugVals[varName]=\"None selected\";}}else{// Handle other input types\nconst inputElement=document.querySelector(`input[name=\"${varName}\"], select[name=\"${varName}\"]`);if(inputElement){let value;if(inputElement.type===\"checkbox\"){value=inputElement.checked;}else if(inputElement.type===\"number\"){value=parseFloat(inputElement.value)||0;}else{// For text inputs, keep the value as a string\nvalue=`\"${inputElement.value}\"`;}debugVals[varName]=inputElement.value;calculatedCondition=calculatedCondition.replace(new RegExp(`\\\\b${varName}\\\\b`,\"g\"),value);}else{debugVals[varName]=`{{${varName}}} input not found`;}}});setDebugInfo(debugVals);const result=new Function(`return (${calculatedCondition})`)();setConditionMet(!!result);}catch(error){console.error(\"Error evaluating condition:\",error);setConditionMet(false);}},[condition]);// Set up a MutationObserver to watch for DOM changes\nuseEffect(()=>{if(!isCanvas){const setupListeners=()=>{// Remove existing listeners first\nconst existingInputs=document.querySelectorAll(\"input, select\");existingInputs.forEach(input=>{input.removeEventListener(\"input\",evaluateCondition);input.removeEventListener(\"change\",evaluateCondition);});// Add listeners to all current inputs\nconst inputs=document.querySelectorAll(\"input, select\");inputs.forEach(input=>{input.addEventListener(\"input\",evaluateCondition);input.addEventListener(\"change\",evaluateCondition);});evaluateCondition();};// Initial setup\nsetupListeners();// Watch for DOM changes (new inputs being added/removed)\nconst observer=new MutationObserver(mutations=>{let shouldResetup=false;mutations.forEach(mutation=>{// Check if any input or select elements were added or removed\nif(mutation.type===\"childList\"){mutation.addedNodes.forEach(node=>{if(node.nodeType===Node.ELEMENT_NODE){if(node.matches&&(node.matches(\"input\")||node.matches(\"select\")||node.querySelector&&(node.querySelector(\"input\")||node.querySelector(\"select\")))){shouldResetup=true;}}});mutation.removedNodes.forEach(node=>{if(node.nodeType===Node.ELEMENT_NODE){if(node.matches&&(node.matches(\"input\")||node.matches(\"select\")||node.querySelector&&(node.querySelector(\"input\")||node.querySelector(\"select\")))){shouldResetup=true;}}});}});if(shouldResetup){// Small delay to ensure DOM is fully updated\nsetTimeout(setupListeners,0);}});// Start observing\nobserver.observe(document.body,{childList:true,subtree:true});return()=>{observer.disconnect();const inputs=document.querySelectorAll(\"input, select\");inputs.forEach(input=>{input.removeEventListener(\"input\",evaluateCondition);input.removeEventListener(\"change\",evaluateCondition);});};}},[condition,isCanvas,evaluateCondition]);const forceFullWidth=children=>{return React.Children.map(children,child=>{if(/*#__PURE__*/React.isValidElement(child)){return /*#__PURE__*/React.cloneElement(child,{style:{...child.props.style,width:\"100%\",maxWidth:\"100%\",minWidth:\"100%\",boxSizing:\"border-box\"}});}return child;});};const DebugDisplay=()=>/*#__PURE__*/_jsxs(\"div\",{style:{background:\"rgba(0,0,0,0.8)\",color:\"white\",padding:\"10px\",fontSize:\"12px\",fontFamily:\"monospace\",marginTop:\"10px\",width:\"100%\"},children:[/*#__PURE__*/_jsxs(\"div\",{children:[\"Condition: \",condition]}),/*#__PURE__*/_jsxs(\"div\",{children:[\"Result: \",conditionMet.toString()]}),/*#__PURE__*/_jsx(\"div\",{children:\"Variables:\"}),Object.entries(debugInfo).map(([key,value])=>/*#__PURE__*/_jsxs(\"div\",{children:[key,\": \",JSON.stringify(value)]},key))]});const contentToRender=conditionMet?content:fallbackContent;const isEmpty=React.Children.count(contentToRender)===0;if(isCanvas){return /*#__PURE__*/_jsxs(_Fragment,{children:[forceFullWidth(content),forceFullWidth(fallbackContent)]});}if(isEmpty){return debug?/*#__PURE__*/_jsx(DebugDisplay,{}):null;}return /*#__PURE__*/_jsxs(_Fragment,{children:[forceFullWidth(contentToRender),debug&&/*#__PURE__*/_jsx(DebugDisplay,{})]});}LogicGate.defaultProps={condition:\"true\",content:null,fallbackContent:null,debug:false};addPropertyControls(LogicGate,{condition:{type:ControlType.String,title:\"Condition\",defaultValue:\"villian_name === 'Thanos'\",description:\"JavaScript condition to evaluate (e.g., 'option1 === \\\"Web\\\"', 'someNumber > 5', 'Newsletter === true', or 'villian_name === \\\"Thanos\\\"')\"},content:{type:ControlType.ComponentInstance,title:\"Content if True\"},fallbackContent:{type:ControlType.ComponentInstance,title:\"Content if False\"},debug:{type:ControlType.Boolean,title:\"Debug Mode\",defaultValue:false,description:\"v1.8\\n[via SegmentUI](https://www.segmentUI.com)\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"LogicGate\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"*\",\"framerSupportedLayoutWidth\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Conditional.map"],"mappings":"oNAKG,SAAwB,EAAU,EAAM,CAAC,GAAK,CAAC,YAAU,U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