import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["className", "title", "icon", "iconColors", "active", "onClick", "disabled", "order", "id"];
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), !0).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; }
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import classnames from 'classnames';
import { useContext, useEffect, useRef, useState } from 'react';
import { FcrPopover } from '../popover';
import { FcrIcon } from '../icon';
import { actionBarCollapesContext } from '.';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var ActionBarItem = function ActionBarItem(props) {
  var className = props.className,
    title = props.title,
    icon = props.icon,
    iconColors = props.iconColors,
    _props$active = props.active,
    active = _props$active === void 0 ? false : _props$active,
    _onClick = props.onClick,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled,
    order = props.order,
    id = props.id,
    others = _objectWithoutProperties(props, _excluded);
  var ref = useRef(null);
  var _useContext = useContext(actionBarCollapesContext),
    setItem = _useContext.setItem,
    visibleList = _useContext.visibleList;
  var visible = visibleList.includes(id);
  useEffect(function () {
    if (ref.current) {
      setItem({
        name: id,
        width: ref.current.offsetWidth,
        order: order || 0
      });
    }
  }, []);
  return /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({}, others), {}, {
    ref: ref,
    style: {
      display: visible ? 'block' : 'none'
    },
    className: classnames('fcr-action-bar-item-wrapper', className),
    children: /*#__PURE__*/_jsxs("div", {
      onClick: function onClick() {
        !disabled && (_onClick === null || _onClick === void 0 ? void 0 : _onClick());
      },
      className: classnames('fcr-action-bar-item', {
        'fcr-action-bar-item-active': active,
        'fcr-action-bar-item-disabled': disabled
      }),
      children: [/*#__PURE__*/_jsx("div", {
        className: "fcr-action-bar-item-icon",
        children: /*#__PURE__*/_jsx(FcrIcon, {
          size: 32,
          type: icon,
          colors: iconColors
        })
      }), /*#__PURE__*/_jsx("div", {
        className: "fcr-action-bar-item-text",
        children: title
      })]
    })
  }));
};
export var ActionBarItemWithPopover = function ActionBarItemWithPopover(props) {
  var icon = props.icon,
    title = props.title,
    popoverProps = props.popoverProps,
    id = props.id,
    order = props.order;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    popoverOpened = _useState2[0],
    setPopoverOpend = _useState2[1];
  return /*#__PURE__*/_jsx(FcrPopover, _objectSpread(_objectSpread({}, popoverProps), {}, {
    afterVisibleChange: function afterVisibleChange(visible) {
      var _popoverProps$afterVi;
      setPopoverOpend(visible);
      popoverProps === null || popoverProps === void 0 || (_popoverProps$afterVi = popoverProps.afterVisibleChange) === null || _popoverProps$afterVi === void 0 || _popoverProps$afterVi.call(popoverProps, visible);
    },
    children: /*#__PURE__*/_jsx(ActionBarItem, {
      id: id,
      order: order,
      active: popoverOpened,
      icon: icon,
      title: title,
      iconColors: props.iconColors
    })
  }));
};