var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SelectControl=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 SelectControl=function SelectControl(_ref){var defaultValue=_ref.defaultValue,componentProp=_ref.componentProp,options=_ref.options;var _useContext=(0,_react.useContext)(_CodePreviewProvider.CodePreviewContext),propsString=_useContext.propsString,updatePropsString=_useContext.updatePropsString;var _useState=(0,_react.useState)(defaultValue!=null?defaultValue:''),_useState2=(0,_slicedToArray2.default)(_useState,2),value=_useState2[0],setValue=_useState2[1];var handleChange=function handleChange(val){var componentPropsValueRegex=new RegExp(componentProp+'="(.*?)"','g');setValue(val);if(propsString.match(componentPropsValueRegex)){updatePropsString(propsString.replace(componentPropsValueRegex,`${componentProp}="${val}"`));}else{updatePropsString(`${propsString} ${componentProp}="${val}"`);}if(val===''){updatePropsString(propsString.replace(componentPropsValueRegex,''));}};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.jsxs)(_index.Select,{onValueChange:handleChange,value:value,defaultValue:defaultValue,children:[(0,_jsxRuntime.jsxs)(_index.Select.Trigger,{variant:"underlined",sx:{_light:{'color':'$textLight900',':hover':{borderColor:'$borderLight400'}},_dark:{'color':'$textDark50',':hover':{borderColor:'$borderDark600'}}},children:[(0,_jsxRuntime.jsx)(_index.Select.Input,{placeholder:`Select ${componentProp}`,fontSize:"$sm",fontWeight:"$normal",sx:{_light:{color:'$textLight900'},_dark:{color:'$textDark50'}}}),(0,_jsxRuntime.jsx)(_index.Select.Icon,{mr:"$3",children:(0,_jsxRuntime.jsx)(_index.ChevronDownIcon,{h:"$4",w:"$4",sx:{_light:{color:'$backgroundLight500'},_dark:{color:'$backgroundDark400'}}})})]}),(0,_jsxRuntime.jsxs)(_index.Select.Portal,{children:[(0,_jsxRuntime.jsx)(_index.Select.Backdrop,{}),(0,_jsxRuntime.jsxs)(_index.Select.Content,{children:[(0,_jsxRuntime.jsx)(_index.Select.DragIndicatorWrapper,{children:(0,_jsxRuntime.jsx)(_index.Select.DragIndicator,{})}),options==null?void 0:options.map(function(option,index){return(0,_jsxRuntime.jsx)(_index.Select.Item,{value:option,label:option,fontWeight:"$normal"},index);})]})]})]})]});};exports.SelectControl=SelectControl;
//# sourceMappingURL=SelectControl.js.map