import { W3cCredentialRecord } from '@credo-ts/core';
import { BrandingOverlayType } from '@hyperledger/aries-oca/build/legacy';
import React, { useEffect, useState } from 'react';
import { TOKENS, useServices } from '../../container-api';
import { useTheme } from '../../contexts/theme';
import CredentialCard10 from './CredentialCard10';
import CredentialCard11 from './CredentialCard11';
import { getCredentialForDisplay } from '../../modules/openid/display';
import { buildOverlayFromW3cCredential } from '../../utils/oca';
import { useTranslation } from 'react-i18next';
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] = useServices([TOKENS.UTIL_OCA_RESOLVER]);
  const {
    ColorPallet
  } = useTheme();
  const [overlay, setOverlay] = useState({});
  const {
    i18n
  } = useTranslation();
  useEffect(() => {
    const resolveOverlay = async w3cCred => {
      const credentialDisplay = getCredentialForDisplay(w3cCred);
      const resolvedOverlay = await buildOverlayFromW3cCredential({
        credentialDisplay,
        language: i18n.language,
        resolver: bundleResolver
      });
      setOverlay(resolvedOverlay);
    };
    if (credential instanceof W3cCredentialRecord) {
      resolveOverlay(credential);
    }
  }, [credential, bundleResolver, i18n.language]);
  const getCredOverlayType = type => {
    if (proof) {
      return /*#__PURE__*/React.createElement(CredentialCard11, {
        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 === BrandingOverlayType.Branding01) {
        return /*#__PURE__*/React.createElement(CredentialCard10, {
          credential: credential,
          style: style,
          onPress: onPress
        });
      } else {
        return /*#__PURE__*/React.createElement(CredentialCard11, {
          credential: credential,
          style: style,
          onPress: onPress,
          credentialErrors: credentialErrors ?? []
        });
      }
    } else {
      return /*#__PURE__*/React.createElement(CredentialCard11, {
        credDefId: credDefId,
        schemaId: schemaId,
        credName: credName,
        displayItems: displayItems,
        style: style,
        onPress: onPress,
        credentialErrors: credentialErrors ?? []
      });
    }
  };
  if (credential instanceof W3cCredentialRecord) {
    return /*#__PURE__*/React.createElement(CredentialCard11, {
      credential: undefined,
      style: style,
      onPress: onPress,
      brandingOverlay: overlay,
      credentialErrors: credentialErrors ?? []
    });
  } else {
    return getCredOverlayType(bundleResolver.getBrandingOverlayType());
  }
};
export default CredentialCard;
//# sourceMappingURL=CredentialCard.js.map