"use strict";

exports.__esModule = true;
exports.useSidePanelFieldActions = useSidePanelFieldActions;
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@wix/bex-core/react");
var _FieldActionsState = require("../../state/FieldActionsState");
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 SidePanelFieldActionsRow = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "SidePanelFieldActions" */'./SidePanelFieldActionsRow'))).then(m => ({
  default: m.SidePanelFieldActionsRow
})));
const SidePanelFieldActionsModal = /*#__PURE__*/(0, _react.lazy)(() => Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "SidePanelFieldActions" */'./SidePanelFieldActionsModal'))));
function useSidePanelFieldActions(columns, fieldActions, refresh, permissions) {
  const {
    translate,
    showToast
  } = (0, _react2.useWixPatternsContainer)();
  const [fieldActionsState] = (0, _react.useState)(() => new _FieldActionsState.FieldActionsState(translate, fieldActions, permissions, showToast, refresh));
  (0, _react.useEffect)(() => {
    fieldActionsState.setHandlers(fieldActions);
  }, [fieldActionsState, fieldActions]);
  (0, _react.useEffect)(() => {
    fieldActionsState.setPermissions(permissions);
  }, [fieldActionsState, permissions]);
  (0, _react.useEffect)(() => {
    fieldActionsState.setRefresh(refresh);
  }, [fieldActionsState, refresh]);
  const fieldActionsByColumn = (0, _react.useMemo)(() => {
    const result = {};
    for (const col of columns) {
      result[col.id] = /*#__PURE__*/_react.default.createElement(_react.Suspense, {
        fallback: null,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 71,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react.default.createElement(SidePanelFieldActionsRow, {
        column: col,
        state: fieldActionsState,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 72,
          columnNumber: 11
        }
      }));
    }
    return result;
  }, [columns, fieldActionsState]);
  const fieldActionsModal = /*#__PURE__*/_react.default.createElement(_react.Suspense, {
    fallback: null,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 81,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(SidePanelFieldActionsModal, {
    state: fieldActionsState,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 82,
      columnNumber: 7
    }
  }));
  return {
    fieldActionsByColumn,
    fieldActionsModal
  };
}
//# sourceMappingURL=useSidePanelFieldActions.js.map