"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableSkeleton = void 0;
exports._TableSkeleton = _TableSkeleton;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _state = require("../../state");
var _mobxReactLite = require("mobx-react-lite");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TableSkeleton/TableSkeleton.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 _TableSkeleton(props) {
  const {
    state,
    dataHook,
    rowsCount = 7,
    showTitleBar,
    ...rest
  } = props;
  const [{
    columnCount,
    minItemWidth,
    itemsContentWidth
  }] = (0, _react.useState)(() => new _state.ResponsiveColumnsState({
    gridState: {
      gap: 24
    },
    minItemWidth: 192,
    rectState: state.toolbarRect,
    containerPadding: 48
  }));
  const data = (0, _react.useMemo)(() => new Array(rowsCount).fill(null).map((_, i) => ({
    id: `skeleton-row-${i}`
  })), [rowsCount]);
  const columns = (0, _react.useMemo)(() => new Array(columnCount).fill(null).map((_, i) => ({
    title: '',
    key: `skeleton-column-${i}`,
    dataHook: `skeleton-column-${i}`,
    render: () => /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      direction: "vertical",
      width: "100%",
      minWidth: `${minItemWidth}px`,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 53,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.SkeletonGroup, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 54,
        columnNumber: 13
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.SkeletonLine, {
      width: "100%",
      marginTop: "SP1",
      marginBottom: "SP1",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 55,
        columnNumber: 15
      }
    })))
  })), [columnCount]);
  const [TrElementType] = (0, _react.useState)(() => /*#__PURE__*/(0, _react.forwardRef)(({
    rowData: _rowData,
    ...trProps
  }, ref) => {
    // <TableSkeleton/> is rendered inside the main <Table/> component, so we need to remove the data-table-row attribute from the <tr/> element to make testkit not to consider skeleton rows as real rows
    return /*#__PURE__*/_react.default.createElement("tr", (0, _extends2.default)({
      ref: ref
    }, trProps, {
      "data-table-row": undefined,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 73,
        columnNumber: 16
      }
    }));
  }));
  if (!itemsContentWidth && process.env.NODE_ENV !== 'test') {
    return null;
  }
  return (
    /*#__PURE__*/
    // <Box/> wrapper always aligns the skeleton to the top of the table
    _react.default.createElement(_designSystem.Box, {
      marginBottom: "auto",
      dataHook: dataHook,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 82,
        columnNumber: 5
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Table, (0, _extends2.default)({
      skin: "neutral",
      data: data,
      columns: columns,
      withWrapper: false,
      TrElementType
    }, rest, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 83,
        columnNumber: 7
      }
    }), /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      direction: "vertical",
      backgroundColor: "D80",
      borderRadius: "0px 0px 8px 8px",
      overflow: "hidden",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 91,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Table.Content, {
      titleBarVisible: showTitleBar && state.collection.showInitialLoader,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 97,
        columnNumber: 11
      }
    }))))
  );
}
const TableSkeleton = exports.TableSkeleton = (0, _mobxReactLite.observer)(_TableSkeleton);
//# sourceMappingURL=TableSkeleton.js.map