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; }

import React, { useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
export default function CountrySelect(_ref) {
  var value = _ref.value,
      onChange = _ref.onChange,
      options = _ref.options,
      className = _ref.className,
      Icon = _ref.iconComponent,
      SelectArrow = _ref.selectArrowComponent,
      rest = _objectWithoutProperties(_ref, ["value", "onChange", "options", "className", "iconComponent", "selectArrowComponent"]);

  var onChange_ = useCallback(function (event) {
    var value = event.target.value;
    onChange(value === 'ZZ' ? undefined : value);
  }, [onChange]);
  var selectedOption = useMemo(function () {
    for (var _iterator = options, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
      var _ref2;

      if (_isArray) {
        if (_i >= _iterator.length) break;
        _ref2 = _iterator[_i++];
      } else {
        _i = _iterator.next();
        if (_i.done) break;
        _ref2 = _i.value;
      }

      var option = _ref2;

      if (!option.divider && option.value === value) {
        return option;
      }
    }
  }, [options, value]);
  return React.createElement("div", {
    className: "PhoneInputCountry"
  }, selectedOption && React.createElement(Icon, {
    country: value
  }), React.createElement("select", _extends({}, rest, {
    value: value || 'ZZ',
    onChange: onChange_,
    className: "PhoneInputCountrySelect"
  }), options.map(function (_ref3) {
    var value = _ref3.value,
        label = _ref3.label,
        divider = _ref3.divider;
    return React.createElement("option", {
      key: divider ? '|' : value || 'ZZ',
      value: divider ? '|' : value || 'ZZ',
      disabled: divider ? true : false,
      className: divider ? 'PhoneInputCountrySelectDivider' : undefined
    }, label);
  })), React.createElement(SelectArrow, null));
}
CountrySelect.propTypes = {
  // A two-letter country code.
  // E.g. "US", "RU", etc.
  value: PropTypes.string,
  // Updates the `value`.
  onChange: PropTypes.func.isRequired,
  // `<select/>` options.
  options: PropTypes.arrayOf(PropTypes.shape({
    value: PropTypes.string,
    label: PropTypes.string,
    divider: PropTypes.bool
  })).isRequired,
  // Country flag component.
  iconComponent: PropTypes.elementType,
  // Select arrow component.
  selectArrowComponent: PropTypes.elementType.isRequired
};
CountrySelect.defaultProps = {
  selectArrowComponent: function selectArrowComponent() {
    return React.createElement("div", {
      className: "PhoneInputCountrySelectArrow"
    });
  }
};
//# sourceMappingURL=CountrySelect.js.map