text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = void 0;
  
  var _propTypes = _interopRequireDefault(require("prop-types"));
  
  var _react = _interopRequireDefault(require("react"));
  
  var _defaultStyle = _interopRequireDefault(require("part:@sanity/components/selects/default-style"));
  
  var _angleDownIcon = _interopRequireDefault(require("part:@sanity/base/angle-down-icon"));
  
  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 = _objectWithoutPropertiesLoose(source, excluded); var key, i; 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 _objectWithoutPropertiesLoose(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]; } return target; }
  
  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; }
  
  class DefaultSelect extends _react.default.Component {
    constructor() {
      super(...arguments);
  
      _defineProperty(this, "handleChange", event => {
        this.props.onChange(this.props.items[event.target.value]);
      });
  
      _defineProperty(this, "setInput", el => {
        this._input = el;
      });
    }
  
    focus() {
      if (this._input) {
        this._input.focus();
      }
    }
  
    render() {
      var _this$props = this.props,
          hasError = _this$props.hasError,
          items = _this$props.items,
          value = _this$props.value,
          disabled = _this$props.disabled,
          hasFocus = _this$props.hasFocus,
          readOnly = _this$props.readOnly,
          rest = _objectWithoutProperties(_this$props, ["hasError", "items", "value", "disabled", "hasFocus", "readOnly"]);
  
      return /*#__PURE__*/_react.default.createElement("div", {
        className: "\n          ".concat(disabled || readOnly ? _defaultStyle.default.disabled : '', "\n          ").concat(hasFocus ? _defaultStyle.default.hasFocus : _defaultStyle.default.root, "\n        ")
      }, /*#__PURE__*/_react.default.createElement("select", _extends({}, rest, {
        className: "".concat(_defaultStyle.default.select, " ").concat(hasError ? _defaultStyle.default.invalid : ''),
        onChange: this.handleChange,
        disabled: disabled || readOnly,
        value: value && items.indexOf(value) || '',
        autoComplete: "off",
        ref: this.setInput
      }), !value && /*#__PURE__*/_react.default.createElement("option", null), items.length && items.map((item, i) => {
        return /*#__PURE__*/_react.default.createElement("option", {
          key: i,
          value: i
        }, item.title);
      })), /*#__PURE__*/_react.default.createElement("div", {
        className: _defaultStyle.default.functions
      }, /*#__PURE__*/_react.default.createElement("span", {
        className: _defaultStyle.default.arrow
      }, /*#__PURE__*/_react.default.createElement(_angleDownIcon.default, {
        color: "inherit"
      }))));
    }
  
  }
  
  exports.default = DefaultSelect;
  
  _defineProperty(DefaultSelect, "propTypes", {
    onChange: _propTypes.default.func,
    value: _propTypes.default.object,
    hasError: _propTypes.default.bool,
    onFocus: _propTypes.default.func,
    onBlur: _propTypes.default.func,
    hasFocus: _propTypes.default.bool,
    disabled: _propTypes.default.bool,
    readOnly: _propTypes.default.bool,
    items: _propTypes.default.arrayOf(_propTypes.default.shape({
      title: _propTypes.default.string
    }))
  });
  
  _defineProperty(DefaultSelect, "defaultProps", {
    onChange() {},
  
    onBlur() {},
  
    onFocus() {},
  
    readOnly: false,
    hasError: false,
    hasFocus: false,
    value: {},
    items: []
  });