"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ColumnListTableListItem = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _ToolbarCollectionContext = require("../ToolbarCollectionContext");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomColumnsPanel/ColumnListTableListItem.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 _ColumnListTableListItem(props) {
  var _collectionDataExtens;
  const {
    column,
    state,
    showDivider,
    domRef,
    dragging,
    dragHandleProps,
    index,
    rowIndex,
    columnIndex,
    droppable,
    ...rest
  } = props;
  const {
    select
  } = state;
  const {
    collectionDataExtension
  } = (0, _ToolbarCollectionContext.useToolbarCollectionContext)();
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const {
    infoTooltipProps
  } = column;
  const checkboxDisabled = !column.hideable;
  const hasSearchValue = state.searchValue.trim().length > 0;
  const dragDisabled = column.reorderDisabled || hasSearchValue;
  const checked = select.isChecked(column.id);
  const infoContent = (infoTooltipProps == null ? void 0 : infoTooltipProps.panelContent) || (infoTooltipProps == null ? void 0 : infoTooltipProps.content);
  const style = (0, _react.useMemo)(() => ({
    display: 'flex',
    flexDirection: 'column',
    position: 'relative'
  }), []);
  const dataExtensionsCTA = (collectionDataExtension == null || (_collectionDataExtens = collectionDataExtension.DataExtension) == null ? void 0 : _collectionDataExtens.CustomColumnsEditCustomFieldCTAButton) && column.dataExtension && column.dataExtension.editable && /*#__PURE__*/_react.default.createElement(collectionDataExtension.DataExtension.CustomColumnsEditCustomFieldCTAButton, {
    field: column.dataExtension,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 61,
      columnNumber: 7
    }
  });
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
    ref: domRef,
    style: style,
    "data-hook": `column-item-${column.id}`,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 67,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.TableListItem, (0, _extends2.default)({
    showDivider: showDivider,
    checkbox: true,
    checked: checked,
    verticalPadding: "tiny",
    checkboxDisabled: checkboxDisabled,
    checkboxTooltipContent: checkboxDisabled ? dragDisabled ? t('cairo.table.custom-columns.disabled.tooltip') : t('cairo.table.custom-columns.hidden.disabled.tooltip') : undefined,
    checkboxTooltipProps: {
      maxWidth: '400px',
      appendTo: 'window',
      disabled: !checkboxDisabled
    },
    onCheckboxChange: () => {
      if (checkboxDisabled) {
        return;
      }
      state.onColumnCheckboxToggle(column);
      state.customizeColumnsInSidePanelBi({
        actionName: 'visibility'
      });
    }
  }, hasSearchValue ? {} : {
    draggable: true,
    dragging,
    dragDisabled,
    dragHandleProps: {
      ...dragHandleProps,
      tooltipContent: dragDisabled ? checkboxDisabled ? t('cairo.table.custom-columns.disabled.tooltip') : t('cairo.table.custom-columns.move.disabled.tooltip') : undefined,
      tooltipProps: {
        maxWidth: '400px',
        appendTo: 'window'
      }
    }
  }, {
    options: [{
      value: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 120,
          columnNumber: 15
        }
      }, /*#__PURE__*/_react.default.createElement("div", {
        style: {
          padding: '0 6px',
          cursor: checkboxDisabled ? undefined : 'pointer',
          wordBreak: 'break-word'
        },
        onClick: () => {
          if (checkboxDisabled) {
            return;
          }
          state.onColumnCheckboxToggle(column);
        },
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 121,
          columnNumber: 17
        }
      }, /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
        size: "small",
        dataHook: "tableListItem-label",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 134,
          columnNumber: 19
        }
      }, column.name || column.title || column.id)), /*#__PURE__*/_react.default.createElement("div", {
        style: {
          cursor: 'default'
        },
        onPointerDown: e => e.stopPropagation(),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 139,
          columnNumber: 17
        }
      }, infoContent && /*#__PURE__*/_react.default.createElement(_designSystem.InfoIcon, (0, _extends2.default)({
        size: "small"
      }, infoTooltipProps, {
        dataHook: "info-icon",
        content: infoContent,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 144,
          columnNumber: 21
        }
      }))))
    }, ...(dataExtensionsCTA ? [{
      value: dataExtensionsCTA,
      align: 'right'
    }] : [])],
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 73,
      columnNumber: 7
    }
  })));
}
const ColumnListTableListItem = exports.ColumnListTableListItem = (0, _mobxReactLite.observer)(_ColumnListTableListItem);
//# sourceMappingURL=ColumnListTableListItem.js.map