"use strict";

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

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

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

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

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

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 _index = _interopRequireDefault(require("@readme/emojis/unicode/index.json"));

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 EmojiPicker = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(EmojiPicker, _React$Component);

  var _super = _createSuper(EmojiPicker);

  function EmojiPicker(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, EmojiPicker);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onClick", function (value) {
      _this.setState({
        value: value
      });
      /* istanbul ignore else */


      if (typeof _this.props.onClick === 'function') _this.props.onClick(value);
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "renderEmoji", function () {
      // filter emoji by iOS version https://developer.apple.com/support/app-store/
      var filteredEmoji = _index["default"].filter(function (obj) {
        return obj.ios_version <= 12;
      });

      return filteredEmoji.map(function (emoji) {
        var EmojiClasses = [classes['EmojiPicker-Button'], emoji.emoji === _this.state.value && classes['EmojiPicker-Button_active']].filter(function (e) {
          return e;
        }).join(' ');
        return /*#__PURE__*/_react["default"].createElement("button", {
          key: emoji.aliases,
          className: EmojiClasses,
          disabled: emoji.emoji === _this.state.value,
          onClick: function onClick() {
            return _this.onClick(emoji.emoji);
          },
          type: "button"
        }, /*#__PURE__*/_react["default"].createElement("span", {
          "aria-label": emoji.aliases,
          role: "img"
        }, emoji.emoji));
      });
    });
    _this.state = {
      value: props.value
    };
    return _this;
  }

  (0, _createClass2["default"])(EmojiPicker, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var ButtonClasses = [classes['EmojiPicker-Button'], classes['EmojiPicker-Button_none'], this.state.value === '' && classes['EmojiPicker-Button_active']].filter(function (e) {
        return e;
      }).join(' ');
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: classes.EmojiPicker
      }, /*#__PURE__*/_react["default"].createElement("button", {
        className: ButtonClasses,
        disabled: this.state.value === '',
        onClick: function onClick() {
          return _this2.onClick('');
        },
        type: "button"
      }, "None"), this.renderEmoji());
    }
  }]);
  return EmojiPicker;
}(_react["default"].Component);

exports["default"] = EmojiPicker;
(0, _defineProperty2["default"])(EmojiPicker, "propTypes", {
  onClick: _propTypes["default"].func,
  value: _propTypes["default"].string
});