"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TagsWidgetBase = exports.TagsWidget = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _react2 = require("@wix/bex-core/react");
var _designSystem = require("@wix/design-system");
var _CardContainer = require("../CardContainer");
var _TagsWidgetContext = require("../TagsWidgetContext");
var _TagsWidgetContent = require("./TagsWidgetContent");
var _bexCore = require("@wix/bex-core");
exports.OnSubmitTagsFuncType = _bexCore.OnSubmitTagsFuncType;
var _useWidgetPageStatus = require("../useWidgetPageStatus");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _useTagsWidget = require("../../hooks/useTagsWidget");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TagsWidget/TagsWidget.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); }
const InlineLayoutContent = ({
  dataHook,
  state: _state,
  ...contentProps
}) => {
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const state = _state;
  const {
    status
  } = (0, _useWidgetPageStatus.useWidgetPageStatus)(state.initTask.status.status);
  if (status === 'idle' || status === 'loading') {
    return /*#__PURE__*/_react.default.createElement(_designSystem.Layout, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 119,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Cell, {
      span: 8,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 120,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement("div", {
      "data-hook": dataHook,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 121,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.SkeletonLine, {
      marginBottom: "7px",
      marginTop: "7px",
      dataHook: "tags-widget-skeleton",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 122,
        columnNumber: 13
      }
    }))));
  }
  if (status === 'error') {
    return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      justifyItems: "center",
      gap: "tiny",
      dataHook: dataHook,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 135,
        columnNumber: 7
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Text, {
      dataHook: "tags-widget-error-text",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 136,
        columnNumber: 9
      }
    }, t('cairo.tags.loadTags.error.body')), /*#__PURE__*/_react.default.createElement(_designSystem.TextButton, {
      dataHook: "tags-widget-retry-button",
      onClick: state.retry,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 139,
        columnNumber: 9
      }
    }, t('cairo.tags.loadTags.error.CTA')));
  }
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": dataHook,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 147,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_TagsWidgetContent.TagsWidgetContent, (0, _extends2.default)({}, contentProps, {
    state: state,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 148,
      columnNumber: 7
    }
  })));
};
const _TagsWidgetBase = ({
  subtitle,
  dataHook,
  theme,
  state: _state,
  ...contentProps
}) => {
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const state = _state;
  const {
    status
  } = (0, _useWidgetPageStatus.useWidgetPageStatus)(state.initTask.status.status);
  if (theme === 'inline') {
    return /*#__PURE__*/_react.default.createElement(InlineLayoutContent, (0, _extends2.default)({
      dataHook: dataHook,
      state: state
    }, contentProps, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 167,
        columnNumber: 7
      }
    }));
  }
  return /*#__PURE__*/_react.default.createElement(_CardContainer.CardContainer, {
    dataHook: dataHook,
    status: status,
    errorState: {
      dataHook: 'error-state',
      subtitle: t('cairo.tags.loadTags.error.body'),
      action: {
        text: t('cairo.tags.loadTags.error.CTA'),
        prefixIcon: /*#__PURE__*/_react.default.createElement(_wixUiIconsCommon.Refresh, {
          __self: void 0,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 184,
            columnNumber: 23
          }
        }),
        onClick: state.retry
      }
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 176,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_designSystem.Card.Header, {
    dataHook: "tags-widget-card-header",
    title: t('cairo.tags.tagsWidget.title'),
    subtitle: subtitle || t('cairo.tags.tagsWidget.subtitle'),
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 189,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.Card.Divider, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 194,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react.default.createElement(_designSystem.Card.Content, {
    dataHook: "tags-widget-card-content",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 195,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_TagsWidgetContent.TagsWidgetContent, (0, _extends2.default)({
    state: state
  }, contentProps, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 196,
      columnNumber: 9
    }
  }))));
};
const TagsWidgetBase = exports.TagsWidgetBase = (0, _mobxReactLite.observer)(_TagsWidgetBase);
const _TagsWidget = props => {
  const {
    origin,
    fqdn,
    state: externalState,
    ...baseComponentProps
  } = props;
  const internalState = (0, _useTagsWidget.useTagsWidgetInternal)({
    origin,
    fqdn
  });
  const [state] = (0, _react.useState)(() => externalState ?? internalState);
  return /*#__PURE__*/_react.default.createElement(_TagsWidgetContext.TagsWidgetContextProvider, {
    value: state,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 215,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(TagsWidgetBase, (0, _extends2.default)({
    state: state
  }, baseComponentProps, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 216,
      columnNumber: 7
    }
  })));
};
const TagsWidget = exports.TagsWidget = (0, _mobxReactLite.observer)(_TagsWidget);
//# sourceMappingURL=TagsWidget.js.map