function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-13 15:39:29
 * @LastEditTime: 2021-09-09 16:23:27
 * @FilePath: \my-remax-ui\components\Switch\index.tsx
 */
import * as React from 'react';
import classNames from 'classnames';
import { View } from 'remax/one';
import { getPrefixCls } from './../common';
import { addUnit } from './../_utils';
var prefixCls = getPrefixCls('switch');

var Switch = function Switch(props) {
  var _classNames;

  var _props$checked = props.checked,
      checked = _props$checked === void 0 ? false : _props$checked,
      _props$activeColor = props.activeColor,
      activeColor = _props$activeColor === void 0 ? '#108ee9' : _props$activeColor,
      _props$inactiveColor = props.inactiveColor,
      inactiveColor = _props$inactiveColor === void 0 ? '#dcdee0' : _props$inactiveColor,
      disabled = props.disabled,
      _props$size = props.size,
      size = _props$size === void 0 ? 24 : _props$size,
      onChange = props.onChange;
  var style = {
    fontSize: addUnit(size),
    backgroundColor: checked ? activeColor : inactiveColor
  };

  var handleChange = function handleChange() {
    if (disabled) {
      return;
    }

    onChange === null || onChange === void 0 ? void 0 : onChange(!checked);
  };

  return /*#__PURE__*/React.createElement(View, {
    className: classNames("".concat(prefixCls), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames)),
    onTap: handleChange,
    style: style
  }, /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-checkbox")
  }));
};

export default Switch;