"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 _react2 = require("@wix/bex-core/react");
var _fieldTypePrefixIcons = require("../../utils/fieldTypePrefixIcons");
var _FieldIndications = require("./FieldIndications");
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 _column$validation, _collectionDataExtens;
  const {
    column,
    state,
    showDivider,
    fieldActions,
    domRef,
    dragging,
    dragHandleProps,
    index,
    rowIndex,
    columnIndex,
    droppable,
    ...rest
  } = props;
  const {
    select
  } = state;
  const {
    collectionDataExtension
  } = state;
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const showFieldTypeIcons = state.showFieldTypeIcons;
  const {
    infoTooltipProps
  } = column;
  const prefixIcon = showFieldTypeIcons ? (0, _fieldTypePrefixIcons.getFieldTypeIcon)({
    fieldType: column.fieldType
  }) : null;
  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 isRequired = ((_column$validation = column.validation) == null ? void 0 : _column$validation.some(r => r.type === 'required')) ?? false;
  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: 69,
      columnNumber: 7
    }
  });
  const hasIndications = column.isPii || column.isPrimary || column.isSystem || !!column.dataExtension;
  const hasRightContent = hasIndications || !!dataExtensionsCTA || !!fieldActions;
  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: 83,
      columnNumber: 5
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.TableListItem, (0, _extends2.default)({
    showDivider: showDivider,
    checkbox: true,
    checked: checked,
    verticalPadding: "tiny",
    horizontalPadding: "small",
    dragHandleSize: "small",
    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, (0, _extends2.default)({}, prefixIcon ? {
        verticalAlign: 'middle'
      } : {}, {
        minWidth: 0,
        flexGrow: 1,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 138,
          columnNumber: 15
        }
      }), /*#__PURE__*/_react.default.createElement("div", {
        style: {
          ...(prefixIcon ? {
            display: 'flex',
            alignItems: 'center'
          } : {}),
          padding: '0',
          cursor: checkboxDisabled ? undefined : 'pointer',
          overflow: 'hidden',
          minWidth: 0
        },
        onClick: () => {
          if (checkboxDisabled) {
            return;
          }
          state.onColumnCheckboxToggle(column);
        },
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 143,
          columnNumber: 17
        }
      }, prefixIcon && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        align: "center",
        verticalAlign: "middle",
        marginRight: "SP1",
        flexShrink: 0,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 161,
          columnNumber: 21
        }
      }, prefixIcon), /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
        size: "small",
        weight: "normal",
        dataHook: "tableListItem-label",
        ellipsis: true,
        appendTo: "window",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 170,
          columnNumber: 19
        }
      }, column.name || column.title || column.id), isRequired && /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
        size: "tiny",
        skin: "error",
        weight: "bold",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 180,
          columnNumber: 21
        }
      }, "\xA0*")), /*#__PURE__*/_react.default.createElement("div", {
        style: {
          cursor: 'default'
        },
        onPointerDown: e => e.stopPropagation(),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 186,
          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: 191,
          columnNumber: 21
        }
      }))))
    }, ...(hasRightContent ? [{
      value: /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        gap: "SP1",
        verticalAlign: "middle",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 207,
          columnNumber: 21
        }
      }, /*#__PURE__*/_react.default.createElement(_FieldIndications.FieldIndications, {
        column: column,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 208,
          columnNumber: 23
        }
      }), dataExtensionsCTA, fieldActions),
      align: 'right',
      width: 'auto'
    }] : [])],
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 89,
      columnNumber: 7
    }
  })));
}
const ColumnListTableListItem = exports.ColumnListTableListItem = (0, _mobxReactLite.observer)(_ColumnListTableListItem);
//# sourceMappingURL=ColumnListTableListItem.js.map