"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CardContainer = void 0;
exports._CardContainer = _CardContainer;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _designSystem = require("@wix/design-system");
var _mobxReactLite = require("mobx-react-lite");
var _SkeletonCard = require("../SkeletonCard");
var _ErrorCard = require("../ErrorCard");
var _react2 = require("@wix/bex-core/react");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _CardContainerStCss = require("./CardContainer.st.css.js");
var _useIsMobile = require("../../hooks/useIsMobile");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CardContainer/CardContainer.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 _CardContainer(props) {
  const {
    status,
    minHeight,
    children,
    errorState,
    ...rest
  } = props;
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const isMobile = (0, _useIsMobile.useIsMobile)();
  const className = (0, _CardContainerStCss.st)(_CardContainerStCss.classes.root, {
    mobile: isMobile
  });
  if (status === 'idle' || status === 'loading') {
    return /*#__PURE__*/_react.default.createElement(_SkeletonCard.SkeletonCard, (0, _extends2.default)({
      minHeight: minHeight
    }, rest, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 40,
        columnNumber: 12
      }
    }));
  }
  if (status === 'error') {
    const hasCardHeader = _react.Children.toArray(children).some(el => {
      var _el$type;
      return /*#__PURE__*/(0, _react.isValidElement)(el) && ((_el$type = el.type) == null ? void 0 : _el$type.displayName) === 'Card.Header';
    });
    return /*#__PURE__*/_react.default.createElement(_ErrorCard.ErrorCard, (0, _extends2.default)({
      className: className,
      title: (errorState == null ? void 0 : errorState.title) ?? (!hasCardHeader ? t('cairo.entityPage.widgetError.TPAconnectionFail.title') : undefined),
      subtitle: (errorState == null ? void 0 : errorState.subtitle) ?? t('cairo.entityPage.widgetError.TPAconnectionFail.description'),
      action: {
        onClick: () => {},
        text: t('cairo.entityPage.widgetError.TPAconnectionFail.CTA'),
        prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Refresh, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 64,
            columnNumber: 23
          }
        }),
        ...(errorState == null ? void 0 : errorState.action)
      }
    }, rest, {
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 49,
        columnNumber: 7
      }
    }), children);
  }
  return /*#__PURE__*/_react.default.createElement(_designSystem.Card, (0, _extends2.default)({}, rest, {
    className: className,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 75,
      columnNumber: 5
    }
  }), children);
}
_CardContainer.displayName = 'CardContainer';
const CardContainer = exports.CardContainer = (0, _mobxReactLite.observer)(_CardContainer);
//# sourceMappingURL=CardContainer.js.map