"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _core = require("@credo-ts/core");
var _legacy = require("@hyperledger/aries-oca/build/legacy");
var _react = _interopRequireWildcard(require("react"));
var _containerApi = require("../../container-api");
var _theme = require("../../contexts/theme");
var _CredentialCard = _interopRequireDefault(require("./CredentialCard10"));
var _CredentialCard2 = _interopRequireDefault(require("./CredentialCard11"));
var _display = require("../../modules/openid/display");
var _oca = require("../../utils/oca");
var _reactI18next = require("react-i18next");
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; }
const CredentialCard = ({
  credential,
  credDefId,
  schemaId,
  proof,
  displayItems,
  credName,
  hasAltCredentials,
  handleAltCredChange,
  style = {},
  onPress = undefined,
  credentialErrors
}) => {
  // add ability to reference credential by ID, allows us to get past react hook restrictions
  const [bundleResolver] = (0, _containerApi.useServices)([_containerApi.TOKENS.UTIL_OCA_RESOLVER]);
  const {
    ColorPallet
  } = (0, _theme.useTheme)();
  const [overlay, setOverlay] = (0, _react.useState)({});
  const {
    i18n
  } = (0, _reactI18next.useTranslation)();
  (0, _react.useEffect)(() => {
    const resolveOverlay = async w3cCred => {
      const credentialDisplay = (0, _display.getCredentialForDisplay)(w3cCred);
      const resolvedOverlay = await (0, _oca.buildOverlayFromW3cCredential)({
        credentialDisplay,
        language: i18n.language,
        resolver: bundleResolver
      });
      setOverlay(resolvedOverlay);
    };
    if (credential instanceof _core.W3cCredentialRecord) {
      resolveOverlay(credential);
    }
  }, [credential, bundleResolver, i18n.language]);
  const getCredOverlayType = type => {
    if (proof) {
      return /*#__PURE__*/_react.default.createElement(_CredentialCard2.default, {
        displayItems: displayItems,
        style: {
          backgroundColor: ColorPallet.brand.secondaryBackground
        },
        credName: credName,
        credDefId: credDefId,
        schemaId: schemaId,
        credential: credential,
        handleAltCredChange: handleAltCredChange,
        hasAltCredentials: hasAltCredentials,
        proof: true,
        elevated: true,
        credentialErrors: credentialErrors ?? []
      });
    }
    if (credential) {
      if (type === _legacy.BrandingOverlayType.Branding01) {
        return /*#__PURE__*/_react.default.createElement(_CredentialCard.default, {
          credential: credential,
          style: style,
          onPress: onPress
        });
      } else {
        return /*#__PURE__*/_react.default.createElement(_CredentialCard2.default, {
          credential: credential,
          style: style,
          onPress: onPress,
          credentialErrors: credentialErrors ?? []
        });
      }
    } else {
      return /*#__PURE__*/_react.default.createElement(_CredentialCard2.default, {
        credDefId: credDefId,
        schemaId: schemaId,
        credName: credName,
        displayItems: displayItems,
        style: style,
        onPress: onPress,
        credentialErrors: credentialErrors ?? []
      });
    }
  };
  if (credential instanceof _core.W3cCredentialRecord) {
    return /*#__PURE__*/_react.default.createElement(_CredentialCard2.default, {
      credential: undefined,
      style: style,
      onPress: onPress,
      brandingOverlay: overlay,
      credentialErrors: credentialErrors ?? []
    });
  } else {
    return getCredOverlayType(bundleResolver.getBrandingOverlayType());
  }
};
var _default = exports.default = CredentialCard;
//# sourceMappingURL=CredentialCard.js.map