"use strict";

exports.__esModule = true;
exports.useSidePanelFieldActions = useSidePanelFieldActions;
var _react = _interopRequireWildcard(require("react"));
var _FieldActions = require("../FieldActions");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomColumnsPanel/useSidePanelFieldActions.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const SIDE_PANEL_ACTION_GROUPS = [['editField'], ['makePrimary', 'duplicateField', 'duplicateFieldWithContent'], ['delete']];
function toFieldActionColumn(col) {
  const isText = col.fieldType === 'SHORT_TEXT' || col.fieldType === 'LONG_TEXT';
  return {
    id: col.id,
    isPrimary: col.isPrimary,
    isSystem: col.isSystem,
    cellType: isText ? 'text' : col.fieldType
  };
}
function useSidePanelFieldActions(columns, fieldActions, permissions) {
  return (0, _react.useMemo)(() => {
    const handlers = {
      editField: fieldActions != null && fieldActions.editField ? id => fieldActions.editField(id, {}) : undefined,
      makePrimary: id => fieldActions == null || fieldActions.makePrimary == null ? void 0 : fieldActions.makePrimary(id),
      duplicateField: fieldActions == null ? void 0 : fieldActions.duplicateField,
      duplicateFieldWithContent: fieldActions == null ? void 0 : fieldActions.duplicateField,
      delete: fieldActions == null ? void 0 : fieldActions.deleteField
    };
    const result = {};
    for (const col of columns) {
      const groups = (0, _FieldActions.buildFieldActionGroups)({
        column: toFieldActionColumn(col),
        permissions,
        handlers,
        groups: SIDE_PANEL_ACTION_GROUPS
      });
      if (groups.length > 0) {
        result[col.id] = /*#__PURE__*/_react.default.createElement(_FieldActions.HeaderActionsPopover, {
          actions: groups,
          dataHook: `side-panel-field-actions-${col.id}`,
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 59,
            columnNumber: 11
          }
        });
      }
    }
    return result;
  }, [columns, fieldActions, permissions]);
}
//# sourceMappingURL=useSidePanelFieldActions.js.map