import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { hyphenate, isPresent, _findBy, noop } from '@bigbinary/neeto-cist';
import Dropdown from '@bigbinary/neetoui/Dropdown';
import Spinner from '@bigbinary/neetoui/Spinner';
import { memo } from 'react';
import { jsx, jsxs } from 'react/jsx-runtime';
import { n } from './inject-css-C2dztUxs.js';
import Down from '@bigbinary/neeto-icons/Down';
import Close from '@bigbinary/neeto-icons/Close';
import Typography from '@bigbinary/neetoui/Typography';
import { isNil } from 'ramda';
import { useTranslation } from 'react-i18next';

var NeetoUIMenu = Dropdown.Menu,
  MenuItem = Dropdown.MenuItem;
var Menu = function Menu(_ref) {
  var onItemClick = _ref.onItemClick,
    options = _ref.options,
    _ref$shouldShowAllOpt = _ref.shouldShowAllOptions,
    shouldShowAllOptions = _ref$shouldShowAllOpt === void 0 ? false : _ref$shouldShowAllOpt,
    _ref$hiddenStatuses = _ref.hiddenStatuses,
    hiddenStatuses = _ref$hiddenStatuses === void 0 ? [] : _ref$hiddenStatuses;
  var allowedOptions = shouldShowAllOptions ? options : options.filter(function (status) {
    return !hiddenStatuses.includes(status.value);
  });
  return /*#__PURE__*/jsx(NeetoUIMenu, {
    "data-testid": "status-dropdown-menu",
    children: allowedOptions === null || allowedOptions === void 0 ? void 0 : allowedOptions.map(function (option) {
      return /*#__PURE__*/jsx(MenuItem.Button, {
        className: "status-dropdown-item--".concat(option.color),
        "data-testid": "status-dropdown-item-".concat(hyphenate(option.value)),
        onClick: function onClick() {
          return onItemClick(option);
        },
        children: option.label
      }, option.value);
    })
  });
};
var Menu$1 = /*#__PURE__*/memo(Menu);

var css = ":root{--neeto-molecules-status-color-open:9,90,186;--neeto-molecules-status-color-done:189,100,13;--neeto-molecules-status-color-waiting:47,57,65;--neeto-molecules-status-color-red:187,18,26;--neeto-molecules-status-color-yellow:255,204,112;--neeto-molecules-status-color-violet:157,98,162;--neeto-molecules-status-color-pink:225,62,230;--neeto-molecules-status-color-teal:38,87,124;--neeto-molecules-status-color-cyan:66,160,157;--neeto-molecules-status-color-green:16,113,84;--neeto-molecules-status-bg-open:226,241,255;--neeto-molecules-status-bg-done:250,241,225;--neeto-molecules-status-bg-waiting:233,235,237;--neeto-molecules-status-bg-red:254,236,240;--neeto-molecules-status-bg-yellow:255,247,233;--neeto-molecules-status-bg-violet:235,222,255;--neeto-molecules-status-bg-pink:254,233,255;--neeto-molecules-status-bg-teal:228,244,255;--neeto-molecules-status-bg-cyan:224,255,254;--neeto-molecules-status-bg-green:224,244,238}.neeto-ui-theme--dark{--neeto-molecules-status-color-open:144,194,255;--neeto-molecules-status-bg-open:24,42,66;--neeto-molecules-status-color-done:255,194,121;--neeto-molecules-status-bg-done:54,38,18;--neeto-molecules-status-color-waiting:255,255,255;--neeto-molecules-status-bg-waiting:16,24,40;--neeto-molecules-status-color-red:255,119,130;--neeto-molecules-status-bg-red:60,20,24;--neeto-molecules-status-color-yellow:255,221,138;--neeto-molecules-status-bg-yellow:60,48,20;--neeto-molecules-status-color-violet:218,170,255;--neeto-molecules-status-bg-violet:49,27,63;--neeto-molecules-status-color-pink:255,155,255;--neeto-molecules-status-bg-pink:56,30,60;--neeto-molecules-status-color-teal:139,205,255;--neeto-molecules-status-bg-teal:22,42,55;--neeto-molecules-status-color-cyan:130,255,247;--neeto-molecules-status-bg-cyan:14,49,48;--neeto-molecules-status-color-green:117,255,195;--neeto-molecules-status-bg-green:15,50,36}.status-dropdown-target--open{background-color:#e2f1ff;background-color:rgb(var(--neeto-molecules-status-bg-open));color:#095aba;color:rgb(var(--neeto-molecules-status-color-open))}.status-dropdown-target--done{background-color:#faf1e1;background-color:rgb(var(--neeto-molecules-status-bg-done));color:#bd640d;color:rgb(var(--neeto-molecules-status-color-done))}.status-dropdown-target--waiting{background-color:#e9ebed;background-color:rgb(var(--neeto-molecules-status-bg-waiting));color:#2f3941;color:rgb(var(--neeto-molecules-status-color-waiting))}.status-dropdown-target--red{background-color:#feecf0;background-color:rgb(var(--neeto-molecules-status-bg-red));color:#bb121a;color:rgb(var(--neeto-molecules-status-color-red))}.status-dropdown-target--yellow{background-color:#fff7e9;background-color:rgb(var(--neeto-molecules-status-bg-yellow));color:#ffcc70;color:rgb(var(--neeto-molecules-status-color-yellow))}.status-dropdown-target--violet{background-color:#ebdeff;background-color:rgb(var(--neeto-molecules-status-bg-violet));color:#9d62a2;color:rgb(var(--neeto-molecules-status-color-violet))}.status-dropdown-target--pink{background-color:#fee9ff;background-color:rgb(var(--neeto-molecules-status-bg-pink));color:#e13ee6;color:rgb(var(--neeto-molecules-status-color-pink))}.status-dropdown-target--teal{background-color:#e4f4ff;background-color:rgb(var(--neeto-molecules-status-bg-teal));color:#26577c;color:rgb(var(--neeto-molecules-status-color-teal))}.status-dropdown-target--cyan{background-color:#e0fffe;background-color:rgb(var(--neeto-molecules-status-bg-cyan));color:#42a09d;color:rgb(var(--neeto-molecules-status-color-cyan))}.status-dropdown-target--green{background-color:#e0f4ee;background-color:rgb(var(--neeto-molecules-status-bg-green));color:#107154;color:rgb(var(--neeto-molecules-status-color-green))}.status-dropdown-item--open{color:#095aba!important;color:rgb(var(--neeto-molecules-status-color-open))!important}.status-dropdown-item--done{color:#bd640d!important;color:rgb(var(--neeto-molecules-status-color-done))!important}.status-dropdown-item--waiting{color:#2f3941!important;color:rgb(var(--neeto-molecules-status-color-waiting))!important}.status-dropdown-item--red{color:#bb121a!important;color:rgb(var(--neeto-molecules-status-color-red))!important}.status-dropdown-item--yellow{color:#ffcc70!important;color:rgb(var(--neeto-molecules-status-color-yellow))!important}.status-dropdown-item--violet{color:#9d62a2!important;color:rgb(var(--neeto-molecules-status-color-violet))!important}.status-dropdown-item--pink{color:#e13ee6!important;color:rgb(var(--neeto-molecules-status-color-pink))!important}.status-dropdown-item--teal{color:#26577c!important;color:rgb(var(--neeto-molecules-status-color-teal))!important}.status-dropdown-item--cyan{color:#42a09d!important;color:rgb(var(--neeto-molecules-status-color-cyan))!important}.status-dropdown-item--green{color:#107154!important;color:rgb(var(--neeto-molecules-status-color-green))!important}";
n(css,{});

var ICON_SIZE = 16;

var Target = function Target(_ref) {
  var color = _ref.color,
    value = _ref.value,
    label = _ref.label,
    dataTestid = _ref.dataTestid,
    isClearable = _ref.isClearable,
    onClear = _ref.onClear,
    placeholder = _ref.placeholder;
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var targetClassName = "neeto-ui-rounded-sm inline-flex items-center gap-2 cursor-pointer py-0.5 px-2 status-dropdown-target--".concat(color || "waiting");
  var isOptionSelected = !isNil(value);
  var handleClearClick = function handleClearClick(event) {
    onClear();
    event.stopPropagation();
  };
  var handleClearKeyDown = function handleClearKeyDown(event) {
    if (!(event.key === "Enter" || event.key === " ")) return;
    event.preventDefault();
    handleClearClick(event);
  };
  return /*#__PURE__*/jsxs("button", {
    "aria-haspopup": "listbox",
    className: targetClassName,
    "data-testid": isPresent(dataTestid) ? dataTestid : "status-dropdown",
    type: "button",
    "aria-label": isOptionSelected ? "Selected: ".concat(label) : placeholder || t("neetoMolecules.statusDropdown.placeholder"),
    children: [isOptionSelected ? /*#__PURE__*/jsx(Typography, {
      className: "inline",
      style: "body2",
      children: label
    }) : /*#__PURE__*/jsx(Typography, {
      className: "neeto-ui-text-gray-600 inline",
      style: "body2",
      children: placeholder || t("neetoMolecules.statusDropdown.placeholder")
    }), /*#__PURE__*/jsxs("span", {
      className: "inline-flex items-center gap-1",
      children: [isClearable && isOptionSelected && /*#__PURE__*/jsx("span", {
        "aria-label": t("neetoMolecules.statusDropdown.clear"),
        className: "cursor-pointer",
        "data-testid": "status-dropdown-clear-button",
        role: "button",
        tabIndex: 0,
        onClick: handleClearClick,
        onKeyDown: handleClearKeyDown,
        children: /*#__PURE__*/jsx(Close, {
          size: ICON_SIZE
        })
      }), /*#__PURE__*/jsx(Down, {
        "aria-hidden": "true",
        size: ICON_SIZE
      })]
    })]
  });
};
var Target$1 = /*#__PURE__*/memo(Target);

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 StatusDropdown = function StatusDropdown(_ref) {
  var _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$hiddenStatuses = _ref.hiddenStatuses,
    hiddenStatuses = _ref$hiddenStatuses === void 0 ? [] : _ref$hiddenStatuses,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
    onItemClick = _ref.onItemClick,
    options = _ref.options,
    _ref$placeholder = _ref.placeholder,
    placeholder = _ref$placeholder === void 0 ? null : _ref$placeholder,
    selectedValue = _ref.selectedValue,
    _ref$shouldShowAllOpt = _ref.shouldShowAllOptions,
    shouldShowAllOptions = _ref$shouldShowAllOpt === void 0 ? false : _ref$shouldShowAllOpt,
    _ref$isClearable = _ref.isClearable,
    isClearable = _ref$isClearable === void 0 ? false : _ref$isClearable,
    _ref$onClear = _ref.onClear,
    onClear = _ref$onClear === void 0 ? noop : _ref$onClear,
    _ref$dataTestid = _ref.dataTestid,
    dataTestid = _ref$dataTestid === void 0 ? "status-dropdown" : _ref$dataTestid;
  var selectedOption = _findBy({
    value: selectedValue
  }, options);
  return /*#__PURE__*/jsx(Dropdown, {
    disabled: disabled,
    appendTo: function appendTo() {
      return document.body;
    },
    strategy: "fixed",
    customTarget: function customTarget() {
      return /*#__PURE__*/jsx(Target$1, _objectSpread({
        label: selectedValue
      }, _objectSpread(_objectSpread({}, selectedOption), {}, {
        dataTestid: dataTestid,
        isClearable: isClearable,
        onClear: onClear,
        placeholder: placeholder
      })));
    },
    children: isLoading ? /*#__PURE__*/jsx("div", {
      className: "flex w-full items-center justify-center py-8",
      children: /*#__PURE__*/jsx(Spinner, {})
    }) : /*#__PURE__*/jsx(Menu$1, {
      hiddenStatuses: hiddenStatuses,
      onItemClick: onItemClick,
      options: options,
      shouldShowAllOptions: shouldShowAllOptions
    })
  });
};
StatusDropdown.Menu = Menu$1;

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