import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { useState } from 'react';
import { Button } from '@bigbinary/neeto-atoms';
import { Popover, PopoverTrigger, PopoverContent } from '@bigbinary/neeto-atoms/primitives';
import { useTranslation } from 'react-i18next';
import { Picker } from 'emoji-mart';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { jsx, jsxs } from 'react/jsx-runtime';
import { c as createLucideIcon } from '../createLucideIcon-mNMhCCpf.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("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 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$defaultOpen = _ref.defaultOpen,
    defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useState = useState(defaultOpen),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  var onEmojiClick = function onEmojiClick(emoji) {
    setIsOpen(false);
    onSelect(emoji);
  };
  return /*#__PURE__*/jsxs(Popover, {
    open: isOpen,
    onOpenChange: setIsOpen,
    children: [/*#__PURE__*/jsx(PopoverTrigger, {
      asChild: true,
      children: /*#__PURE__*/jsx(Button, {
        "aria-haspopup": "dialog",
        "aria-label": t("neetoMolecules.common.emojiPicker"),
        "data-testid": "emoji-picker-dropdown-icon",
        icon: Smile,
        size: "icon-sm",
        variant: "ghost"
      })
    }), /*#__PURE__*/jsx(PopoverContent, _objectSpread(_objectSpread({
      align: "start",
      className: "w-fit overflow-x-hidden p-0",
      side: "bottom"
    }, dropdownProps), {}, {
      children: /*#__PURE__*/jsx(EmojiPickerMenu, {
        onEmojiSelect: onEmojiClick
      })
    }))]
  });
};

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