function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import { Button, Space } from 'antd';
import classNames from 'classnames';
import "./PisellActionPanel.less";

/**
 * 单条操作项渲染为 Button（带可选 icon）
 * 根据 priority 映射为 antd Button type
 */
function renderActionItem(item, index) {
  var _item$key, _item$priority;
  var visible = item.visible !== false;
  if (!visible) return null;
  var key = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : "action-".concat(index);
  var priority = (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : 'default';
  var buttonType = priority === 'danger' ? 'primary' : priority === 'primary' ? 'primary' : 'default';
  var danger = priority === 'danger';
  return /*#__PURE__*/React.createElement(Button, {
    key: key,
    type: buttonType,
    danger: danger,
    icon: item.icon,
    onClick: item.onClick,
    disabled: item.disabled,
    className: classNames('pisell-action-panel-btn', item.className),
    style: item.style
  }, item.label);
}

/**
 * PisellActionPanel 操作面板
 * 用于统一承载、编排和呈现一组用户可执行操作（Actions）的 Pro 组件。
 * 支持分组、布局、对齐、主/次/危险层级与条件显隐。
 *
 * 设计文档：Action Panel (pcp_ge_actionPanel_V1.0)
 *
 * @param props 组件 Props
 */
export function PisellActionPanel(_ref) {
  var groups = _ref.groups,
    _ref$layout = _ref.layout,
    layout = _ref$layout === void 0 ? 'horizontal' : _ref$layout,
    _ref$align = _ref.align,
    align = _ref$align === void 0 ? 'left' : _ref$align,
    _ref$overflowStrategy = _ref.overflowStrategy,
    overflowStrategy = _ref$overflowStrategy === void 0 ? 'wrap' : _ref$overflowStrategy,
    groupGap = _ref.groupGap,
    itemGap = _ref.itemGap,
    className = _ref.className,
    style = _ref.style;
  /** 过滤可见分组，并过滤每组内可见项 */
  var effectiveGroups = useMemo(function () {
    return groups.filter(function (g) {
      return g.visible !== false;
    }).map(function (g) {
      return _objectSpread(_objectSpread({}, g), {}, {
        items: g.items.filter(function (i) {
          return i.visible !== false;
        })
      });
    }).filter(function (g) {
      return g.items.length > 0;
    });
  }, [groups]);
  var rootStyle = useMemo(function () {
    var s = _objectSpread({}, style);
    if (groupGap !== undefined) {
      s.gap = typeof groupGap === 'number' ? "".concat(groupGap, "px") : groupGap;
    }
    return s;
  }, [style, groupGap]);
  var itemGapValue = typeof itemGap === 'number' ? itemGap : itemGap !== null && itemGap !== void 0 ? itemGap : 8;
  var isVertical = layout === 'vertical';
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-action-panel-root', "pisell-action-panel-layout-".concat(layout), "pisell-action-panel-align-".concat(align), overflowStrategy === 'scroll' && 'pisell-action-panel-overflow-scroll', overflowStrategy === 'wrap' && 'pisell-action-panel-overflow-wrap', className),
    style: rootStyle
  }, effectiveGroups.map(function (group, groupIndex) {
    var _group$key;
    return /*#__PURE__*/React.createElement("div", {
      key: (_group$key = group.key) !== null && _group$key !== void 0 ? _group$key : "group-".concat(groupIndex),
      className: classNames('pisell-action-panel-group', group.className),
      style: group.style
    }, /*#__PURE__*/React.createElement(Space, {
      size: itemGapValue,
      direction: isVertical ? 'vertical' : 'horizontal',
      wrap: !isVertical && overflowStrategy === 'wrap',
      className: "pisell-action-panel-group-space"
    }, group.items.map(function (item, itemIndex) {
      return renderActionItem(item, itemIndex);
    })));
  }));
}