"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.SidePanelFieldActionsRow = void 0;
var _react = _interopRequireDefault(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _FieldActions = require("../FieldActions");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomColumnsPanel/SidePanelFieldActionsRow.tsx";
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 _SidePanelFieldActionsRow({
  column,
  state
}) {
  const {
    handlers: fieldActions,
    permissions
  } = state;
  const handlers = {};
  if (fieldActions != null && fieldActions.editField) {
    handlers.editField = id => fieldActions.editField(id, {});
  }
  if (fieldActions != null && fieldActions.makePrimary) {
    handlers.makePrimary = id => state.makePrimary(id);
  }
  if (fieldActions != null && fieldActions.duplicateField) {
    handlers.duplicateField = id => state.duplicate(id);
  }
  if (fieldActions != null && fieldActions.duplicateFieldWithContent) {
    handlers.duplicateFieldWithContent = id => state.duplicateWithContent(id);
  }
  if (fieldActions != null && fieldActions.deleteField) {
    handlers.delete = id => state.confirmDelete(id);
  }
  const groups = (0, _FieldActions.buildFieldActionGroups)({
    column: toFieldActionColumn(column),
    permissions,
    handlers,
    loading: {
      makePrimary: state.isMakingPrimary,
      duplicateField: state.isDuplicating,
      duplicateFieldWithContent: state.isDuplicatingWithContent
    },
    groups: SIDE_PANEL_ACTION_GROUPS
  });
  if (groups.length === 0) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_FieldActions.HeaderActionsPopover, {
    actions: groups,
    dataHook: `side-panel-field-actions-${column.id}`,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 76,
      columnNumber: 5
    }
  });
}
const SidePanelFieldActionsRow = exports.SidePanelFieldActionsRow = (0, _mobxReactLite.observer)(_SidePanelFieldActionsRow);
//# sourceMappingURL=SidePanelFieldActionsRow.js.map