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

import React from 'react';
import PropTypes from 'prop-types';
import classes from './style.module.scss';

import emojiData from '@readme/emojis/unicode/index.json';

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 = emojiData.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 React.createElement(
          'button',
          {
            key: emoji.aliases,
            className: EmojiClasses,
            disabled: emoji.emoji === _this.state.value,
            onClick: function onClick() {
              return _this.onClick(emoji.emoji);
            },
            type: 'button'
          },
          React.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 = [classes['EmojiPicker-Button'], classes['EmojiPicker-Button_none'], this.state.value === '' && classes['EmojiPicker-Button_active']].filter(function (e) {
      return e;
    }).join(' ');
    return React.createElement(
      'div',
      { className: classes.EmojiPicker },
      React.createElement(
        'button',
        {
          className: ButtonClasses,
          disabled: this.state.value === '',
          onClick: function onClick() {
            return _this2.onClick('');
          },
          type: 'button'
        },
        'None'
      ),
      this.renderEmoji()
    );
  };

  return EmojiPicker;
}(React.Component);

export { EmojiPicker as default };
EmojiPicker.propTypes = process.env.NODE_ENV !== "production" ? {
  onClick: PropTypes.func,
  value: PropTypes.string
} : {};