"use strict";

exports.__esModule = true;
exports.useCreateWSRColumnBase = useCreateWSRColumnBase;
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _fieldTypePrefixIcons = require("../utils/fieldTypePrefixIcons");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/hooks/useCreateWSRColumnBase.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 useCreateWSRColumnBase({
  horizontalScroll,
  showFieldTypeIcons
}) {
  return (0, _react.useCallback)((column, index, length) => {
    const {
      id,
      title,
      width,
      sortable,
      infoTooltipProps,
      fieldType
    } = column;
    const lastColumn = index === length - 1;
    const lastColumnStyleNoHorizontalScroll = width != null ? {
      flexBasis: width,
      flexGrow: 1
    } : {
      flex: 1
    };
    const lastColumnStyle = horizontalScroll ? {
      flexBasis: width ?? 0,
      flexShrink: 0,
      flexGrow: 1
    } : lastColumnStyleNoHorizontalScroll;
    const columnStyle = width == null ? {
      flex: 1
    } : undefined;
    const style = lastColumn ? lastColumnStyle : columnStyle;
    const renderedTitle = title && showFieldTypeIcons ? /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      gap: "SP1",
      verticalAlign: "middle",
      minWidth: 0,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 49,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      flexShrink: 0,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 50,
        columnNumber: 13
      }
    }, (0, _fieldTypePrefixIcons.getFieldTypeIcon)({
      fieldType
    })), typeof title === 'string' ? /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
      size: "small",
      ellipsis: true,
      appendTo: "window",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 52,
        columnNumber: 15
      }
    }, title) : title) : title;
    return {
      id,
      key: id ?? index,
      title: renderedTitle,
      style,
      width: lastColumn && !horizontalScroll ? undefined : width,
      sortable: id && sortable ? true : undefined,
      infoTooltipProps: infoTooltipProps != null && infoTooltipProps.content ? infoTooltipProps : undefined
    };
  }, [horizontalScroll, showFieldTypeIcons]);
}
//# sourceMappingURL=useCreateWSRColumnBase.js.map