"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Toggle = _interopRequireDefault(require("../../components/Toggle"));

var _Input = _interopRequireDefault(require("../../components/Input"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// Style
var classes = {};
/* istanbul ignore next */

if (typeof window !== 'undefined') classes = require("./style.module.scss");

var LabeledCheckbox = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(LabeledCheckbox, _React$Component);

  var _super = _createSuper(LabeledCheckbox);

  function LabeledCheckbox(props) {
    (0, _classCallCheck2["default"])(this, LabeledCheckbox);
    return _super.call(this, props, 'Box');
  }

  (0, _createClass2["default"])(LabeledCheckbox, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          style = _this$props.style,
          children = _this$props.children,
          label = _this$props.label,
          attrs = (0, _objectWithoutProperties2["default"])(_this$props, ["style", "children", "label"]);

      if (this.props.type === 'text' || this.props.type === 'number' || this.props.type === 'password') {
        return /*#__PURE__*/_react["default"].createElement("label", {
          className: [classes.LabeledCheckbox, classes.LabeledCheckbox_text, 'Flex Flex_row'].join(' '),
          style: style
        }, children || /*#__PURE__*/_react["default"].createElement("span", null, label), /*#__PURE__*/_react["default"].createElement(_Input["default"], (0, _extends2["default"])({}, attrs, {
          style: {
            flex: 1
          }
        })));
      }

      return /*#__PURE__*/_react["default"].createElement("label", {
        className: classes.LabeledCheckbox,
        style: style
      }, /*#__PURE__*/_react["default"].createElement(_Toggle["default"], attrs), children || /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          flex: 1
        }
      }, label));
    }
  }]);
  return LabeledCheckbox;
}(_react["default"].Component);

exports["default"] = LabeledCheckbox;
(0, _defineProperty2["default"])(LabeledCheckbox, "propTypes", {
  children: _propTypes["default"].object,
  id: _propTypes["default"].string.isRequired,
  label: _propTypes["default"].string.isRequired,
  name: _propTypes["default"].string.isRequired,
  required: _propTypes["default"].bool,
  style: _propTypes["default"].object,
  type: _propTypes["default"].oneOf(['radio', 'checkbox', 'toggle', 'text', 'number', 'password']),
  value: _propTypes["default"].any
});
(0, _defineProperty2["default"])(LabeledCheckbox, "defaultProps", {
  label: 'Label Text',
  type: 'checkbox'
});