import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { useState } from 'react';
import SmileFaceGrey from '@bigbinary/neeto-icons/SmileFaceGrey';
import Dropdown from '@bigbinary/neetoui/Dropdown';
import { useTranslation } from 'react-i18next';
import { Picker } from 'emoji-mart';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { jsx } from '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 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 = useTranslation(),
    t = _useTranslation.t;
  var createPicker = function createPicker(ref) {
    new Picker({
      autoFocus: true,
      data: data,
      "native": true,
      onEmojiSelect: onEmojiSelect,
      previewPosition: "none",
      ref: {
        current: ref
      },
      skinTonePosition: "none",
      style: {
        maxWidth: "100%"
      },
      theme: "light"
    });
  };
  return /*#__PURE__*/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 = useTranslation(),
    t = _useTranslation.t;
  var _useState = useState(open),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  var onEmojiClick = function onEmojiClick(emoji) {
    setIsOpen(false);
    onSelect(emoji);
  };
  return /*#__PURE__*/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__*/jsx(EmojiPickerMenu, {
      onEmojiSelect: onEmojiClick
    })
  }));
};

export { EmojiPicker as default };
//# sourceMappingURL=EmojiPicker.js.map
