"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BadgePosition = void 0;
exports.Overview = Overview;
function _react() {
  const data = _interopRequireWildcard(require("react"));
  _react = function () {
    return data;
  };
  return data;
}
function _classnames() {
  const data = _interopRequireDefault(require("classnames"));
  _classnames = function () {
    return data;
  };
  return data;
}
function _lodash() {
  const data = require("lodash");
  _lodash = function () {
    return data;
  };
  return data;
}
function _component() {
  const data = require("@teambit/component");
  _component = function () {
    return data;
  };
  return data;
}
function _previewUi() {
  const data = require("@teambit/preview.ui.component-preview");
  _previewUi = function () {
    return data;
  };
  return data;
}
function _componentUi() {
  const data = require("@teambit/component.ui.component-meta");
  _componentUi = function () {
    return data;
  };
  return data;
}
function _compositionsPanels() {
  const data = require("@teambit/compositions.panels.composition-gallery");
  _compositionsPanels = function () {
    return data;
  };
  return data;
}
function _baseReactThemes() {
  const data = require("@teambit/base-react.themes.theme-switcher");
  _baseReactThemes = function () {
    return data;
  };
  return data;
}
function _readmeSkeleton() {
  const data = require("./readme-skeleton");
  _readmeSkeleton = function () {
    return data;
  };
  return data;
}
function _overviewModule() {
  const data = _interopRequireDefault(require("./overview.module.scss"));
  _overviewModule = function () {
    return data;
  };
  return data;
}
const _excluded = ["onLoad", "style"]; // import { Icon } from '@teambit/design.elements.icon';
// import { LinkedHeading } from '@teambit/documenter.ui.linked-heading';
// import { StatusMessageCard } from '@teambit/design.ui.surfaces.status-message-card';
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
let BadgePosition = exports.BadgePosition = /*#__PURE__*/function (BadgePosition) {
  BadgePosition[BadgePosition["Title"] = 0] = "Title";
  BadgePosition[BadgePosition["SubTitle"] = 1] = "SubTitle";
  BadgePosition[BadgePosition["Labels"] = 2] = "Labels";
  BadgePosition[BadgePosition["Package"] = 3] = "Package";
  return BadgePosition;
}({});
function Overview({
  titleBadges,
  overviewOptions,
  previewProps,
  getEmptyState,
  TaggedAPI
}) {
  const component = (0, _react().useContext)(_component().ComponentContext);
  const componentDescriptor = (0, _component().useComponentDescriptor)();
  const theme = (0, _baseReactThemes().useThemePicker)();
  const currentTheme = theme?.current;
  const overviewProps = (0, _lodash().flatten)(overviewOptions.values())[0];
  const showHeader = !component.preview?.legacyHeader;
  const EmptyState = getEmptyState && getEmptyState();
  const buildFailed = component.buildStatus?.toLowerCase() !== 'succeed' && component?.host === 'teambit.scope/scope';
  const isScaling = Boolean(component.preview?.isScaling);
  const includesEnvTemplate = Boolean(component.preview?.includesEnvTemplate);
  const defaultLoadingState = _react().default.useMemo(() => {
    return isScaling && !includesEnvTemplate;
  }, [isScaling, includesEnvTemplate]);
  const [isLoading, setLoading] = (0, _react().useState)(defaultLoadingState);
  const iframeQueryParams = `onlyOverview=${component.preview?.onlyOverview || 'false'}&skipIncludes=${component.preview?.skipIncludes || component.preview?.onlyOverview}`;
  const overviewPropsValues = overviewProps && overviewProps();
  const themeParams = currentTheme?.themeName ? `theme=${currentTheme?.themeName}` : '';

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  const _ref = previewProps || {},
    {
      onLoad,
      style
    } = _ref,
    rest = _objectWithoutProperties(_ref, _excluded);
  const onPreviewLoad = _react().default.useCallback((e, props) => {
    setLoading(false);
    onLoad?.(e, props);
  }, [onLoad]);
  _react().default.useEffect(() => {
    if (!isLoading && defaultLoadingState) setLoading(true);
    if (isLoading && !defaultLoadingState) setLoading(false);
  }, [component.id.toString(), defaultLoadingState]);
  return /*#__PURE__*/_react().default.createElement("div", {
    className: (0, _classnames().default)(_overviewModule().default.overviewWrapper, isLoading && _overviewModule().default.noOverflow),
    key: `${component.id.toString()}`
  }, showHeader && /*#__PURE__*/_react().default.createElement(_componentUi().ComponentOverview, {
    className: (0, _classnames().default)(_overviewModule().default.componentOverviewBlock, !isScaling && _overviewModule().default.legacyPreview),
    displayName: component.displayName,
    version: component.version,
    abstract: component.description,
    labels: component.labels,
    packageName: component.packageName,
    titleBadges: (0, _lodash().flatten)(titleBadges.values()),
    componentDescriptor: componentDescriptor,
    component: component
  }), !buildFailed && /*#__PURE__*/_react().default.createElement("div", {
    className: _overviewModule().default.readme
  }, isLoading && /*#__PURE__*/_react().default.createElement(_readmeSkeleton().ReadmeSkeleton, null, /*#__PURE__*/_react().default.createElement(_compositionsPanels().CompositionGallerySkeleton, {
    compositionsLength: Math.min(component.compositions.length, 3)
  })), /*#__PURE__*/_react().default.createElement(_previewUi().ComponentPreview, _extends({
    onLoad: onPreviewLoad,
    previewName: "overview",
    pubsub: true,
    queryParams: [iframeQueryParams, themeParams, overviewPropsValues?.queryParams || ''],
    viewport: null,
    fullContentHeight: true,
    disableScroll: true
  }, rest, {
    component: component,
    style: {
      width: '100%',
      height: '100%',
      minHeight: !isScaling ? 500 : undefined
    }
  })), component.preview?.onlyOverview && !isLoading && /*#__PURE__*/_react().default.createElement(_compositionsPanels().CompositionGallery, {
    component: component
  }), component.preview?.onlyOverview && !isLoading && TaggedAPI && /*#__PURE__*/_react().default.createElement(TaggedAPI, {
    componentId: component.id.toString()
  })), buildFailed && EmptyState && /*#__PURE__*/_react().default.createElement(EmptyState, null));
}

//# sourceMappingURL=overview.js.map