"use strict";

exports.__esModule = true;
exports.CustomColumnsPanel = void 0;
exports._CustomColumnsPanel = _CustomColumnsPanel;
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _bexCore = require("@wix/bex-core");
var _react2 = require("@wix/bex-core/react");
var _mobxReactLite = require("mobx-react-lite");
var _ColumnsList = require("./ColumnsList");
var _CustomColumnsSearch = require("./CustomColumnsSearch");
var _CustomColumnsNoResults = require("./CustomColumnsNoResults");
var _useRafRender = require("../../hooks/useRafRender");
var _bi = require("@wix/bex-core/bi");
var _ScrollableContent = require("../ScrollableContent");
var _PatternsSidePanel = require("../SidePanel/PatternsSidePanel");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomColumnsPanel/CustomColumnsPanel.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); }
function _CustomColumnsPanel({
  state
}) {
  var _collectionDataExtens, _collectionDataExtens2, _collectionDataExtens3;
  const entered = (0, _useRafRender.useRafRender)();
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const {
    table,
    dragAndDrop
  } = state;
  const {
    sidePanel,
    collectionDataExtension
  } = table;
  (0, _react.useEffect)(() => state.init(), []);
  if (!entered) {
    return null;
  }
  const hasSearchResults = state.columnsCollection.result.items.length > 0;
  const hasSearchValue = state.searchValue.trim().length > 0;
  const totalColumns = state.orderedColumns.length;
  const isUsingDataExtension = !!collectionDataExtension;

  // Show search if they're using DEx OR if there are more than 5 columns
  const shouldShowSearch = isUsingDataExtension || totalColumns > 5;
  return /*#__PURE__*/_react.default.createElement(_PatternsSidePanel.PatternsSidePanel, {
    dataHook: "custom-columns-panel",
    width: "100%",
    onClose: () => {
      table.reportBi((0, _bexCore.withoutDefaults)(_bi.cairoFiltersPanelUsed)({
        isOpened: false,
        feature: 'Custom Columns',
        origin: 'X Button'
      }));
      sidePanel.close();
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 43,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.SidePanel.Header, {
    title: t('cairo.table.custom-columns.title'),
    subtitle: dragAndDrop ? t('cairo.table.custom-columns.dragAndDrop.subtitle') : t('cairo.table.custom-columns.subtitle'),
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 57,
      columnNumber: 7
    }
  }, shouldShowSearch && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    padding: "0 SP3 SP2 SP3",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 66,
      columnNumber: 11
    }
  }, /*#__PURE__*/_react.default.createElement(_CustomColumnsSearch.CustomColumnsSearch, {
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 67,
      columnNumber: 13
    }
  }))), /*#__PURE__*/_react.default.createElement(_ScrollableContent.ScrollableContent, {
    overflowY: true,
    dataHook: "custom-columns-panel-scroll-container",
    ref: e => {
      if (state.dragAndDrop) {
        state.dragAndDrop.listRect.element = e;
      }
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 71,
      columnNumber: 7
    }
  }, hasSearchValue && !hasSearchResults ? /*#__PURE__*/_react.default.createElement(_CustomColumnsNoResults.CustomColumnsNoResults, {
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 81,
      columnNumber: 11
    }
  }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (collectionDataExtension == null || (_collectionDataExtens = collectionDataExtension.dataExtension) == null ? void 0 : _collectionDataExtens.shouldDisplayArchive) && (collectionDataExtension == null || (_collectionDataExtens2 = collectionDataExtension.DataExtension) == null ? void 0 : _collectionDataExtens2.CustomColumnsArchivedItemsCTAButton) && /*#__PURE__*/_react.default.createElement(collectionDataExtension.DataExtension.CustomColumnsArchivedItemsCTAButton, {
    dataExtension: collectionDataExtension.dataExtension,
    onCloseSidePanel: () => sidePanel.close(),
    dataHook: "custom-columns",
    actionContainerProps: {
      paddingInlineEnd: '12px'
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 87,
      columnNumber: 17
    }
  }), /*#__PURE__*/_react.default.createElement(_ColumnsList.ColumnsList, {
    state: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 94,
      columnNumber: 13
    }
  }))), (collectionDataExtension == null || (_collectionDataExtens3 = collectionDataExtension.DataExtension) == null ? void 0 : _collectionDataExtens3.CustomColumnsAddCustomFieldCTAButton) && /*#__PURE__*/_react.default.createElement(collectionDataExtension.DataExtension.CustomColumnsAddCustomFieldCTAButton, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 100,
      columnNumber: 9
    }
  }));
}
const CustomColumnsPanel = exports.CustomColumnsPanel = (0, _mobxReactLite.observer)(_CustomColumnsPanel);
//# sourceMappingURL=CustomColumnsPanel.js.map