"use strict";

exports.__esModule = true;
exports.default = void 0;

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

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

var _lodash = require("lodash");

var _ = require("./..");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category containers
 * @component select-option
 * @variations collab-ui-react
 */
var SelectOption =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(SelectOption, _React$Component);

  function SelectOption() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.state = {
      id: (0, _lodash.uniqueId)(_this.props.id && _this.props.id + "-" || 'cui-select-option-')
    };
    return _this;
  }

  var _proto = SelectOption.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        className = _this$props.className,
        isMulti = _this$props.isMulti,
        active = _this$props.active,
        children = _this$props.children,
        label = _this$props.label,
        title = _this$props.title,
        props = _objectWithoutProperties(_this$props, ["className", "isMulti", "active", "children", "label", "title"]);

    var id = this.state.id;
    var separateChildren = isMulti ? _react.default.createElement(_.Checkbox, {
      htmlId: id + "__checkbox",
      label: label,
      checked: active,
      onChange: function onChange() {}
    }) : [_react.default.createElement(_.ListItemSection, {
      key: "child-0",
      position: "center"
    }, label || children), _react.default.createElement(_.ListItemSection, {
      key: "child-1",
      position: "right"
    }, active && _react.default.createElement(_.Icon, {
      color: "blue",
      name: "check_20"
    }))];
    return _react.default.createElement(_.ListItem, _extends({
      className: "" + (className && " " + className || ''),
      id: id,
      title: title || label
    }, props), separateChildren);
  };

  return SelectOption;
}(_react.default.Component);

SelectOption.displayName = 'SelectOption';
SelectOption.defaultProps = {
  active: false,
  children: null,
  className: '',
  id: '',
  isMulti: false,
  label: '',
  title: ''
};
SelectOption.propTypes = {
  /** SelectOption Boolean that describes active state */
  active: _propTypes.default.bool,

  /** SelectOption Children */
  children: _propTypes.default.node,

  /** HTML Class for ListItem */
  className: _propTypes.default.string,

  /** SelectOption id */
  id: _propTypes.default.string,

  /** SelectOption Boolean that modifies adds checkboxes */
  isMulti: _propTypes.default.bool,

  /** SelectOption string alternative to children nodes */
  label: _propTypes.default.string,

  /** ListItem Title */
  title: _propTypes.default.string
};
var _default = SelectOption;
exports.default = _default;