'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var React = require('react');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var primitives = require('@bigbinary/neeto-atoms/primitives');
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 createLucideIcon = require('../createLucideIcon-DBDhE7kE.js');

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["path", { d: "M8 14s1.5 2 4 2 4-2 4-2", key: "1y1vjs" }],
  ["line", { x1: "9", x2: "9.01", y1: "9", y2: "9", key: "yxxnd0" }],
  ["line", { x1: "15", x2: "15.01", y1: "9", y2: "9", key: "1p4y9e" }]
];
const Smile = createLucideIcon.createLucideIcon("smile", __iconNode);

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$defaultOpen = _ref.defaultOpen,
    defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useState = React.useState(defaultOpen),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  var onEmojiClick = function onEmojiClick(emoji) {
    setIsOpen(false);
    onSelect(emoji);
  };
  return /*#__PURE__*/jsxRuntime.jsxs(primitives.Popover, {
    open: isOpen,
    onOpenChange: setIsOpen,
    children: [/*#__PURE__*/jsxRuntime.jsx(primitives.PopoverTrigger, {
      asChild: true,
      children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
        "aria-haspopup": "dialog",
        "aria-label": t("neetoMolecules.common.emojiPicker"),
        "data-testid": "emoji-picker-dropdown-icon",
        icon: Smile,
        size: "icon-sm",
        variant: "ghost"
      })
    }), /*#__PURE__*/jsxRuntime.jsx(primitives.PopoverContent, _objectSpread(_objectSpread({
      align: "start",
      className: "w-fit overflow-x-hidden p-0",
      side: "bottom"
    }, dropdownProps), {}, {
      children: /*#__PURE__*/jsxRuntime.jsx(EmojiPickerMenu, {
        onEmojiSelect: onEmojiClick
      })
    }))]
  });
};

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