"use strict";

require("core-js/modules/es.symbol.js");
require("core-js/modules/es.array.filter.js");
require("core-js/modules/es.array.for-each.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/es.object.define-properties.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.get-own-property-descriptors.js");
require("core-js/modules/es.object.keys.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/web.dom-collections.for-each.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ActionBarItemWithPopover = exports.ActionBarItem = void 0;
require("core-js/modules/es.array.includes.js");
require("core-js/modules/es.string.includes.js");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classnames = _interopRequireDefault(require("classnames"));
var _react = require("react");
var _popover = require("../popover");
var _icon = require("../icon");
var _ = require(".");
var _jsxRuntime = require("react/jsx-runtime");
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) { (0, _defineProperty2["default"])(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 ActionBarItem = exports.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 = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var ref = (0, _react.useRef)(null);
  var _useContext = (0, _react.useContext)(_.actionBarCollapesContext),
    setItem = _useContext.setItem,
    visibleList = _useContext.visibleList;
  var visible = visibleList.includes(id);
  (0, _react.useEffect)(function () {
    if (ref.current) {
      setItem({
        name: id,
        width: ref.current.offsetWidth,
        order: order || 0
      });
    }
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, others), {}, {
    ref: ref,
    style: {
      display: visible ? 'block' : 'none'
    },
    className: (0, _classnames["default"])('fcr-action-bar-item-wrapper', className),
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      onClick: function onClick() {
        !disabled && (_onClick === null || _onClick === void 0 ? void 0 : _onClick());
      },
      className: (0, _classnames["default"])('fcr-action-bar-item', {
        'fcr-action-bar-item-active': active,
        'fcr-action-bar-item-disabled': disabled
      }),
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "fcr-action-bar-item-icon",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icon.FcrIcon, {
          size: 32,
          type: icon,
          colors: iconColors
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "fcr-action-bar-item-text",
        children: title
      })]
    })
  }));
};
var ActionBarItemWithPopover = exports.ActionBarItemWithPopover = function ActionBarItemWithPopover(props) {
  var icon = props.icon,
    title = props.title,
    popoverProps = props.popoverProps,
    id = props.id,
    order = props.order;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    popoverOpened = _useState2[0],
    setPopoverOpend = _useState2[1];
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_popover.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__*/(0, _jsxRuntime.jsx)(ActionBarItem, {
      id: id,
      order: order,
      active: popoverOpened,
      icon: icon,
      title: title,
      iconColors: props.iconColors
    })
  }));
};