var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SwitchControl=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireWildcard(require("react"));var _index=require("../../../index");var _CodePreviewProvider=require("../CodePreviewProvider");var _jsxRuntime=require("react/jsx-runtime");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}var SwitchControl=function SwitchControl(_ref){var defaultValue=_ref.defaultValue,componentProp=_ref.componentProp;var _React$useState=_react.default.useState(defaultValue!=null?defaultValue:false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),value=_React$useState2[0],setValue=_React$useState2[1];var _useContext=(0,_react.useContext)(_CodePreviewProvider.CodePreviewContext),propsString=_useContext.propsString,updatePropsString=_useContext.updatePropsString;var toggleSwitch=function toggleSwitch(val){setValue(function(previousState){return!previousState;});var componentPropsValueRegex=new RegExp(componentProp+'={(.*?)}','g');if(propsString.match(componentPropsValueRegex)){updatePropsString(propsString.replace(componentPropsValueRegex,`${componentProp}={${val}}`));}};return(0,_jsxRuntime.jsxs)(_index.FormControl,{children:[(0,_jsxRuntime.jsx)(_index.FormControl.Label,{mb:"$3",children:(0,_jsxRuntime.jsx)(_index.FormControl.Label.Text,{fontSize:"$xs",lineHeight:"$xs",color:"$textDark400",fontWeight:"$normal",children:componentProp})}),(0,_jsxRuntime.jsx)(_index.Switch,{trackColor:{true:'#005DB4',false:'#d4d4d4'},thumbColor:"#fafafa",activeThumbColor:"#fafafa",value:value,onValueChange:toggleSwitch})]});};exports.SwitchControl=SwitchControl;
//# sourceMappingURL=SwitchControl.js.map