"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CustomFieldsViewWidget = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _mobxReactLite = require("mobx-react-lite");
var _react = _interopRequireDefault(require("react"));
var _designSystem = require("@wix/design-system");
var _CustomFieldsViewWidgetContent = require("./CustomFieldsViewWidgetContent");
var _useCustomFieldsViewWidget = require("./useCustomFieldsViewWidget");
var _CustomFieldsViewWidgetInline = require("./CustomFieldsViewWidgetInline");
var _CardContainer = require("../CardContainer");
var _useWidgetPageStatus = require("../useWidgetPageStatus");
var _EmptyStateViewContent = require("./EmptyStateViewContent");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomFieldsWidget/CustomFieldsViewWidget.tsx";
const _CustomFieldsViewWidget = ({
  dataHook,
  fqdn,
  extendedFields,
  title,
  userFieldsTitle,
  extensionPoint,
  theme = 'card'
}) => {
  const customFieldsViewWidget = (0, _useCustomFieldsViewWidget.useCustomFieldsViewWidget)({
    fqdn,
    extendedFields,
    extensionPoint,
    theme
  });
  const {
    state,
    userCustomFields,
    appsCustomFields,
    container,
    areAllCustomFieldsEmpty
  } = customFieldsViewWidget;
  const {
    translate: t
  } = container;
  const {
    status
  } = (0, _useWidgetPageStatus.useWidgetPageStatus)(state.initTask.status.status);
  if (!state.isLoading && !state.isError && !userCustomFields.length && !appsCustomFields.length) {
    return null;
  }
  if (theme === 'inline') {
    return /*#__PURE__*/_react.default.createElement(_CustomFieldsViewWidgetInline.CustomFieldsViewWidgetInline, (0, _extends2.default)({
      dataHook: dataHook,
      extendedFields: extendedFields,
      userFieldsTitle: userFieldsTitle
    }, customFieldsViewWidget, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 88,
        columnNumber: 7
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_CardContainer.CardContainer, {
    stretchVertically: true,
    dataHook: dataHook,
    status: status,
    errorState: {
      dataHook: 'error-state',
      action: {
        text: t('cairo.entityPage.widgetError.TPAconnectionFail.CTA'),
        onClick: () => state.retry()
      }
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 98,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Card.Header, {
    dataHook: "custom-fields-view-widget-header",
    title: /*#__PURE__*/_react.default.createElement(HeaderTitle, {
      title: title ?? t('cairo.customFields.entityPage.title'),
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 113,
        columnNumber: 11
      }
    }),
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 110,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.Card.Divider, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 118,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.Card.Content, {
    dataHook: "custom-fields-view-widget-content",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 119,
      columnNumber: 7
    }
  }, areAllCustomFieldsEmpty ? /*#__PURE__*/_react.default.createElement(_EmptyStateViewContent.EmptyStateViewContent, {
    title: t('cairo.customFields.entityPage.emptyState.title'),
    subtitle: t('cairo.customFields.entityPage.emptyState.subtitle'),
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 121,
      columnNumber: 11
    }
  }) : /*#__PURE__*/_react.default.createElement(_CustomFieldsViewWidgetContent.CustomFieldsViewWidgetContent, {
    state: state,
    extendedFields: extendedFields,
    userFieldsTitle: userFieldsTitle,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 126,
      columnNumber: 11
    }
  })));
};
const CustomFieldsViewWidget = exports.CustomFieldsViewWidget = (0, _mobxReactLite.observer)(_CustomFieldsViewWidget);
const HeaderTitle = ({
  title
}) => {
  return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    gap: "SP1",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 141,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Heading, {
    size: "medium",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 142,
      columnNumber: 7
    }
  }, title));
};
//# sourceMappingURL=CustomFieldsViewWidget.js.map