'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var React = require('react');
var SmileFaceGrey = require('@bigbinary/neeto-icons/SmileFaceGrey');
var Dropdown = require('@bigbinary/neetoui/Dropdown');
var reactI18next = require('react-i18next');
var emojiMart = require('emoji-mart');
var reactQuery = require('@tanstack/react-query');
var axios = require('axios');
var jsxRuntime = require('react/jsx-runtime');

var fetch = function fetch() {
  return axios.get("https://cdn.jsdelivr.net/npm/@emoji-mart/data");
};
var emojiPickerApi = {
  fetch: fetch
};

var QUERY_KEYS = {
  EMOJI_DATA: "emoji-data"
};

var useEmojiData = function useEmojiData() {
  return reactQuery.useQuery({
    queryKey: [QUERY_KEYS.EMOJI_DATA],
    queryFn: emojiPickerApi.fetch
  });
};

var EmojiPickerMenu = function EmojiPickerMenu(_ref) {
  var onEmojiSelect = _ref.onEmojiSelect;
  var _useEmojiData = useEmojiData(),
    data = _useEmojiData.data;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var createPicker = function createPicker(ref) {
    new emojiMart.Picker({
      autoFocus: true,
      data: data,
      "native": true,
      onEmojiSelect: onEmojiSelect,
      previewPosition: "none",
      ref: {
        current: ref
      },
      skinTonePosition: "none",
      style: {
        maxWidth: "100%"
      },
      theme: "light"
    });
  };
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    "aria-label": t("neetoMolecules.common.emojiPicker"),
    ref: createPicker,
    role: "dialog",
    style: {
      minWidth: "350px"
    }
  });
};

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var EmojiPicker = function EmojiPicker(_ref) {
  var onSelect = _ref.onSelect,
    dropdownProps = _ref.dropdownProps,
    _ref$open = _ref.open,
    open = _ref$open === void 0 ? false : _ref$open;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useState = React.useState(open),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  var onEmojiClick = function onEmojiClick(emoji) {
    setIsOpen(false);
    onSelect(emoji);
  };
  return /*#__PURE__*/jsxRuntime.jsx(Dropdown, _objectSpread(_objectSpread({
    isOpen: isOpen,
    closeOnEsc: true,
    closeOnSelect: false,
    dropdownProps: {
      className: "neeto-ui-shadow-s z-10 overflow-x-hidden"
    },
    position: "bottom-start",
    strategy: "fixed",
    buttonProps: {
      "data-testid": "emoji-picker-dropdown-icon",
      "aria-haspopup": "dialog",
      icon: SmileFaceGrey,
      tooltipProps: {
        content: t("neetoMolecules.common.emojiPicker"),
        position: "top",
        touch: ["hold", 500]
      },
      onClick: function onClick() {
        return setIsOpen(true);
      },
      style: "text"
    },
    onClickOutside: function onClickOutside() {
      return setIsOpen(false);
    },
    onClose: function onClose() {
      return setIsOpen(false);
    }
  }, dropdownProps), {}, {
    children: /*#__PURE__*/jsxRuntime.jsx(EmojiPickerMenu, {
      onEmojiSelect: onEmojiClick
    })
  }));
};

module.exports = EmojiPicker;
//# sourceMappingURL=EmojiPicker.js.map
