'use strict';

exports.__esModule = true;
exports.default = undefined;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styleModule = require('./style.module.scss');

var _styleModule2 = _interopRequireDefault(_styleModule);

var _index = require('@readme/emojis/unicode/index.json');

var _index2 = _interopRequireDefault(_index);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var EmojiPicker = function (_React$Component) {
  _inherits(EmojiPicker, _React$Component);

  function EmojiPicker(props) {
    _classCallCheck(this, EmojiPicker);

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    _this.onClick = function (value) {
      _this.setState({ value: value });
      /* istanbul ignore else */
      if (typeof _this.props.onClick === 'function') _this.props.onClick(value);
    };

    _this.renderEmoji = function () {
      // filter emoji by iOS version https://developer.apple.com/support/app-store/
      var filteredEmoji = _index2.default.filter(function (obj) {
        return obj.ios_version <= 12;
      });
      return filteredEmoji.map(function (emoji) {
        var EmojiClasses = [_styleModule2.default['EmojiPicker-Button'], emoji.emoji === _this.state.value && _styleModule2.default['EmojiPicker-Button_active']].filter(function (e) {
          return e;
        }).join(' ');
        return _react2.default.createElement(
          'button',
          {
            key: emoji.aliases,
            className: EmojiClasses,
            disabled: emoji.emoji === _this.state.value,
            onClick: function onClick() {
              return _this.onClick(emoji.emoji);
            },
            type: 'button'
          },
          _react2.default.createElement(
            'span',
            { 'aria-label': emoji.aliases, role: 'img' },
            emoji.emoji
          )
        );
      });
    };

    _this.state = {
      value: props.value
    };
    return _this;
  }

  EmojiPicker.prototype.render = function render() {
    var _this2 = this;

    var ButtonClasses = [_styleModule2.default['EmojiPicker-Button'], _styleModule2.default['EmojiPicker-Button_none'], this.state.value === '' && _styleModule2.default['EmojiPicker-Button_active']].filter(function (e) {
      return e;
    }).join(' ');
    return _react2.default.createElement(
      'div',
      { className: _styleModule2.default.EmojiPicker },
      _react2.default.createElement(
        'button',
        {
          className: ButtonClasses,
          disabled: this.state.value === '',
          onClick: function onClick() {
            return _this2.onClick('');
          },
          type: 'button'
        },
        'None'
      ),
      this.renderEmoji()
    );
  };

  return EmojiPicker;
}(_react2.default.Component);

exports.default = EmojiPicker;
EmojiPicker.propTypes = process.env.NODE_ENV !== "production" ? {
  onClick: _propTypes2.default.func,
  value: _propTypes2.default.string
} : {};
module.exports = exports['default'];