"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _legacy = require("@bifold/oca/build/legacy");
var _native = require("@react-navigation/native");
var _lodash = _interopRequireDefault(require("lodash.startcase"));
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _MaterialIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialIcons"));
var _containerApi = require("../../container-api");
var _theme = require("../../contexts/theme");
var _credential = require("../../utils/credential");
var _helpers = require("../../utils/helpers");
var _luminance = require("../../utils/luminance");
var _testable = require("../../utils/testable");
var _CardWatermark = _interopRequireDefault(require("./CardWatermark"));
var _CredentialCard11ActionFooter = _interopRequireDefault(require("./CredentialCard11ActionFooter"));
var _CredentialCard11Logo = _interopRequireDefault(require("./CredentialCard11Logo"));
var _credentialCardStyles = _interopRequireDefault(require("../../hooks/credential-card-styles"));
var _CredentialCard11Issuer = _interopRequireDefault(require("./CredentialCard11Issuer"));
var _ThemedText = require("../texts/ThemedText");
var _credentials = require("../../types/credentials");
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); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*
  A card is defined as a nx8 (height/rows x width/columns) grid.
  | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  | 2 |   |   |   |   |   |   |   |
  | 3 |   |   |   |   |   |   |   |
  | 4 |   |   |   |   |   |   |   |
  ...

  The card width is the full screen width.

  Secondary Body (1):
  Primary Body   (2): Small Logo (1x1) -> L (shifted left by 50%)
                      Issuer Name (1x6)
                      Credential Name (1x6)
                      Primary Attribute 1 (1x6)
                      Primary Attribute 2 (1x6)
  Status         (3): Icon (1x1) -> S

   (1)            (2)           (3)
  | L | Issuer Name            | S |
  |   | Credential Name        |   |
  |   |                        |   |
  |   | Primary Attribute 1    |   |
  |   | Primary Attribute 2    |   |
  ...

  Note: The small logo MUST be provided as 1x1 (height/width) ratio.
 */

const CredentialCard11 = ({
  credential,
  style = {},
  displayItems,
  onPress = undefined,
  elevated = false,
  credName,
  credDefId,
  schemaId,
  proof,
  hasAltCredentials,
  credentialErrors = [],
  handleAltCredChange,
  brandingOverlay,
  hideSlice = false,
  extraOverlayParameter,
  brandingOverlayType = _legacy.BrandingOverlayType.Branding10
}) => {
  var _overlay$metaOverlay13, _overlay$metaOverlay14;
  const [dimensions, setDimensions] = (0, _react.useState)({
    cardWidth: 0,
    cardHeight: 0
  });
  const {
    i18n,
    t
  } = (0, _reactI18next.useTranslation)();
  const {
    ColorPalette,
    ListItems,
    Assets
  } = (0, _theme.useTheme)();
  const [flaggedAttributes, setFlaggedAttributes] = (0, _react.useState)();
  const [allPI, setAllPI] = (0, _react.useState)();
  const credentialConnectionLabel = (0, _helpers.useCredentialConnectionLabel)(credential);
  const [bundleResolver, credHelpActionOverrides] = (0, _containerApi.useServices)([_containerApi.TOKENS.UTIL_OCA_RESOLVER, _containerApi.TOKENS.CRED_HELP_ACTION_OVERRIDES]);
  const isBranding11 = brandingOverlayType === _legacy.BrandingOverlayType.Branding11;
  const [helpAction, setHelpAction] = (0, _react.useState)();
  const [overlay, setOverlay] = (0, _react.useState)({});
  const {
    styles,
    borderRadius,
    logoHeight
  } = (0, _credentialCardStyles.default)(overlay, brandingOverlayType, proof);
  const attributeFormats = (0, _react.useMemo)(() => (0, _helpers.getAttributeFormats)(overlay.bundle), [overlay.bundle]);
  const logoText = (0, _react.useMemo)(() => {
    var _overlay$metaOverlay4, _overlay$metaOverlay5;
    if (isBranding11) {
      var _overlay$metaOverlay, _overlay$metaOverlay2, _overlay$metaOverlay3;
      return (_overlay$metaOverlay = overlay.metaOverlay) !== null && _overlay$metaOverlay !== void 0 && _overlay$metaOverlay.issuer && ((_overlay$metaOverlay2 = overlay.metaOverlay) === null || _overlay$metaOverlay2 === void 0 ? void 0 : _overlay$metaOverlay2.issuer) !== 'Unknown Contact' ? (_overlay$metaOverlay3 = overlay.metaOverlay) === null || _overlay$metaOverlay3 === void 0 ? void 0 : _overlay$metaOverlay3.issuer : t('Contacts.UnknownContact');
    }
    return ((_overlay$metaOverlay4 = overlay.metaOverlay) === null || _overlay$metaOverlay4 === void 0 ? void 0 : _overlay$metaOverlay4.name) ?? ((_overlay$metaOverlay5 = overlay.metaOverlay) === null || _overlay$metaOverlay5 === void 0 ? void 0 : _overlay$metaOverlay5.issuer) ?? 'C';
  }, [overlay, isBranding11, t]);
  const cardData = (0, _react.useMemo)(() => {
    var _overlay$presentation, _overlay$presentation2;
    const fields = displayItems ?? [];
    const primaryField = overlay === null || overlay === void 0 || (_overlay$presentation = overlay.presentationFields) === null || _overlay$presentation === void 0 ? void 0 : _overlay$presentation.find(field => {
      var _overlay$brandingOver;
      return field.name === (overlay === null || overlay === void 0 || (_overlay$brandingOver = overlay.brandingOverlay) === null || _overlay$brandingOver === void 0 ? void 0 : _overlay$brandingOver.primaryAttribute);
    });
    const secondaryField = overlay === null || overlay === void 0 || (_overlay$presentation2 = overlay.presentationFields) === null || _overlay$presentation2 === void 0 ? void 0 : _overlay$presentation2.find(field => {
      var _overlay$brandingOver2;
      return field.name === (overlay === null || overlay === void 0 || (_overlay$brandingOver2 = overlay.brandingOverlay) === null || _overlay$brandingOver2 === void 0 ? void 0 : _overlay$brandingOver2.secondaryAttribute);
    });
    primaryField && fields.push(primaryField);
    secondaryField && fields.push(secondaryField);
    return fields;
  }, [displayItems, overlay]);
  const navigation = (0, _native.useNavigation)();
  const fontColorWithHighContrast = () => {
    var _overlay$brandingOver3;
    if (proof && brandingOverlayType === _legacy.BrandingOverlayType.Branding10) {
      return ColorPalette.grayscale.mediumGrey;
    }
    const c = ((_overlay$brandingOver3 = overlay.brandingOverlay) === null || _overlay$brandingOver3 === void 0 ? void 0 : _overlay$brandingOver3.primaryBackgroundColor) ?? ColorPalette.grayscale.lightGrey;
    const shade = (0, _luminance.shadeIsLightOrDark)(c);
    return shade == _luminance.Shade.Light ? ColorPalette.grayscale.darkGrey : ColorPalette.grayscale.lightGrey;
  };
  const parseAttribute = (0, _react.useCallback)(item => {
    var _parsedItem, _parsedItem2, _parsedItem3;
    let parsedItem = item;
    if (item && item.pValue != null) {
      var _overlay$bundle;
      parsedItem = (0, _helpers.pTypeToText)(item, t, (_overlay$bundle = overlay.bundle) === null || _overlay$bundle === void 0 ? void 0 : _overlay$bundle.captureBase.attributes);
    }
    const parsedValue = (0, _helpers.formatIfDate)(attributeFormats === null || attributeFormats === void 0 ? void 0 : attributeFormats[item.name ?? ''], ((_parsedItem = parsedItem) === null || _parsedItem === void 0 ? void 0 : _parsedItem.value) ?? ((_parsedItem2 = parsedItem) === null || _parsedItem2 === void 0 ? void 0 : _parsedItem2.pValue) ?? null);
    return {
      label: item.label ?? item.name ?? '',
      value: item.value !== undefined && item.value != null ? parsedValue : `${(_parsedItem3 = parsedItem) === null || _parsedItem3 === void 0 ? void 0 : _parsedItem3.pType} ${parsedValue}`
    };
  }, [t, overlay, attributeFormats]);
  (0, _react.useEffect)(() => {
    setAllPI(credential && cardData.every(item => {
      if (item === undefined) {
        return true;
      } else if (item instanceof _legacy.Attribute) {
        const {
          label
        } = parseAttribute(item);
        return flaggedAttributes === null || flaggedAttributes === void 0 ? void 0 : flaggedAttributes.includes(label);
      } else {
        // Predicates are not PII
        return false;
      }
    }));
  }, [credential, cardData, parseAttribute, flaggedAttributes]);
  (0, _react.useEffect)(() => {
    if (brandingOverlay) {
      setOverlay(brandingOverlay);
      return;
    }
    const params = {
      identifiers: credential ? (0, _credential.getCredentialIdentifiers)(credential) : {
        schemaId,
        credentialDefinitionId: credDefId
      },
      attributes: proof ? [] : credential === null || credential === void 0 ? void 0 : credential.credentialAttributes,
      meta: {
        credName,
        credConnectionId: credential === null || credential === void 0 ? void 0 : credential.connectionId,
        alias: credentialConnectionLabel
      },
      language: i18n.language
    };
    bundleResolver.resolveAllBundles(params).then(bundle => {
      if (proof) {
        var _resolvedBundle$captu, _overlayBundle$metada, _Object$values;
        const resolvedBundle = bundle === null || bundle === void 0 ? void 0 : bundle.bundle;
        const overlayBundle = (resolvedBundle === null || resolvedBundle === void 0 ? void 0 : resolvedBundle.bundle) ?? resolvedBundle;
        const flagged = (overlayBundle === null || overlayBundle === void 0 ? void 0 : overlayBundle.flaggedAttributes) ?? (resolvedBundle === null || resolvedBundle === void 0 || (_resolvedBundle$captu = resolvedBundle.captureBase) === null || _resolvedBundle$captu === void 0 ? void 0 : _resolvedBundle$captu.flaggedAttributes);
        const flaggedNames = Array.isArray(flagged) && flagged.every(item => typeof item === 'string') ? flagged : Array.isArray(flagged) ? flagged.map(attr => attr === null || attr === void 0 ? void 0 : attr.name).filter(Boolean) : [];
        setFlaggedAttributes(flaggedNames);
        const issuerUrls = overlayBundle === null || overlayBundle === void 0 || (_overlayBundle$metada = overlayBundle.metadata) === null || _overlayBundle$metada === void 0 ? void 0 : _overlayBundle$metada.issuerUrl;
        const issuerUrl = (issuerUrls === null || issuerUrls === void 0 ? void 0 : issuerUrls[params.language]) ?? ((_Object$values = Object.values(issuerUrls ?? {})) === null || _Object$values === void 0 ? void 0 : _Object$values[0]);

        // Check if there is a help action override for this credential
        const override = credHelpActionOverrides === null || credHelpActionOverrides === void 0 ? void 0 : credHelpActionOverrides.find(override => credDefId && override.credDefIds.includes(credDefId) || schemaId && override.schemaIds.includes(schemaId));
        if (override) {
          setHelpAction(() => () => {
            override.action(navigation);
          });
        } else if (issuerUrl) {
          setHelpAction(() => () => {
            _reactNative.Linking.openURL(issuerUrl);
          });
        }
      }
      setOverlay(o => {
        var _bundle$metaOverlay, _bundle$metaOverlay2;
        return {
          ...o,
          ...bundle,
          brandingOverlay: bundle.brandingOverlay,
          // Apply effective name
          ...(bundle.metaOverlay && {
            metaOverlay: {
              ...bundle.metaOverlay,
              name: credential ? (0, _credential.getEffectiveCredentialName)(credential, (_bundle$metaOverlay = bundle.metaOverlay) === null || _bundle$metaOverlay === void 0 ? void 0 : _bundle$metaOverlay.name) : (_bundle$metaOverlay2 = bundle.metaOverlay) === null || _bundle$metaOverlay2 === void 0 ? void 0 : _bundle$metaOverlay2.name
            }
          })
        };
      });
    });
  }, [credential, schemaId, credDefId, credName, credentialConnectionLabel, i18n.language, bundleResolver, proof, credHelpActionOverrides, navigation, brandingOverlay]);
  const AttributeLabel = ({
    label
  }) => {
    var _overlay$bundle2;
    const ylabel = ((_overlay$bundle2 = overlay.bundle) === null || _overlay$bundle2 === void 0 || (_overlay$bundle2 = _overlay$bundle2.labelOverlay) === null || _overlay$bundle2 === void 0 ? void 0 : _overlay$bundle2.attributeLabels[label]) ?? (0, _lodash.default)(label);
    return /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      variant: "labelSubtitle",
      style: [styles.textContainer, {
        lineHeight: 19,
        opacity: 0.8
      }],
      testID: (0, _testable.testIdWithKey)('AttributeName')
    }, ylabel);
  };
  const AttributeErrorLabel = ({
    errorMessage
  }) => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flexDirection: 'row',
        alignItems: 'center'
      }
    }, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      testID: (0, _testable.testIdWithKey)('AttributeErrorIcon'),
      style: {
        paddingTop: 2,
        paddingHorizontal: 2
      },
      name: "close",
      color: ListItems.proofError.color,
      size: ListItems.recordAttributeText.fontSize
    }), /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      variant: "labelSubtitle",
      testID: (0, _testable.testIdWithKey)('AttributeErrorText'),
      style: [styles.textContainer, {
        lineHeight: 19,
        opacity: 0.8,
        color: ListItems.proofError.color
      }]
    }, errorMessage));
  };
  const AttributeValue = ({
    value,
    warn
  }) => {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _helpers.isDataUrl)(value) ? /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
      style: styles.imageAttr,
      source: {
        uri: value
      }
    }) : /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      variant: "bold",
      style: [styles.textContainer, {
        color: warn ? ColorPalette.notification.warnText : styles.textContainer.color
      }],
      testID: (0, _testable.testIdWithKey)('AttributeValue')
    }, value));
  };
  const renderCardAttribute = item => {
    var _overlay$bundle3;
    const {
      label,
      value
    } = parseAttribute(item);
    const parsedValue = (0, _helpers.formatIfDate)(item.format, value) ?? '';
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.cardAttributeContainer
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flexDirection: 'row',
        alignItems: 'center'
      }
    }, credentialErrors.includes(_credentials.CredentialErrors.NotInWallet) && /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      testID: (0, _testable.testIdWithKey)('AttributeNameErrorIcon'),
      style: {
        paddingTop: 2,
        paddingHorizontal: 2
      },
      name: "close",
      color: ListItems.proofError.color,
      size: ListItems.recordAttributeText.fontSize
    }), /*#__PURE__*/_react.default.createElement(AttributeLabel, {
      label: label
    })), !credentialErrors.includes(_credentials.CredentialErrors.NotInWallet) && !item.hasError && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flexDirection: 'row',
        alignItems: 'center'
      }
    }, (flaggedAttributes === null || flaggedAttributes === void 0 ? void 0 : flaggedAttributes.includes(label)) && !item.pValue && proof && /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      testID: (0, _testable.testIdWithKey)('AttributeNameWarningIcon'),
      style: {
        paddingTop: 2,
        paddingHorizontal: 2
      },
      name: "warning",
      color: ColorPalette.notification.warnIcon,
      size: ListItems.recordAttributeText.fontSize
    }), /*#__PURE__*/_react.default.createElement(AttributeValue, {
      warn: (flaggedAttributes === null || flaggedAttributes === void 0 ? void 0 : flaggedAttributes.includes(label)) && !item.pValue && proof,
      value: parsedValue
    })), !credentialErrors.includes(_credentials.CredentialErrors.NotInWallet) && item.hasError && /*#__PURE__*/_react.default.createElement(AttributeErrorLabel, {
      errorMessage: t('ProofRequest.MissingAttribute', {
        name: ((_overlay$bundle3 = overlay.bundle) === null || _overlay$bundle3 === void 0 || (_overlay$bundle3 = _overlay$bundle3.labelOverlay) === null || _overlay$bundle3 === void 0 ? void 0 : _overlay$bundle3.attributeLabels[label]) ?? (0, _lodash.default)(label)
      })
    }), !credentialErrors.includes(_credentials.CredentialErrors.NotInWallet) && item.satisfied != undefined && item.satisfied === false && /*#__PURE__*/_react.default.createElement(AttributeErrorLabel, {
      errorMessage: t('ProofRequest.PredicateNotSatisfied')
    }));
  };
  const CredentialCardPrimaryBodyFooter = () => {
    if (hasAltCredentials && handleAltCredChange) {
      var _overlay$brandingOver4;
      return /*#__PURE__*/_react.default.createElement(_CredentialCard11ActionFooter.default, {
        onPress: handleAltCredChange,
        text: t('ProofRequest.ChangeCredential'),
        testID: 'ChangeCredential',
        textColor: isBranding11 ? (0, _credential.credentialTextColor)(ColorPalette, (_overlay$brandingOver4 = overlay.brandingOverlay) === null || _overlay$brandingOver4 === void 0 ? void 0 : _overlay$brandingOver4.primaryBackgroundColor) : undefined
      });
    }
    if (Boolean(credentialErrors.length) && helpAction) {
      var _overlay$brandingOver5;
      return /*#__PURE__*/_react.default.createElement(_CredentialCard11ActionFooter.default, {
        onPress: helpAction,
        text: t('ProofRequest.GetThisCredential'),
        testID: 'GetThisCredential',
        textColor: isBranding11 ? (0, _credential.credentialTextColor)(ColorPalette, (_overlay$brandingOver5 = overlay.brandingOverlay) === null || _overlay$brandingOver5 === void 0 ? void 0 : _overlay$brandingOver5.primaryBackgroundColor) : undefined
      });
    }
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
  };
  const CredentialCardPrimaryBody = () => {
    var _overlay$metaOverlay6, _overlay$metaOverlay7, _overlay$metaOverlay8;
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      testID: (0, _testable.testIdWithKey)('CredentialCardPrimaryBody'),
      style: styles.primaryBodyContainer
    }, brandingOverlayType === _legacy.BrandingOverlayType.Branding10 && /*#__PURE__*/_react.default.createElement(_CredentialCard11Issuer.default, {
      overlay: overlay,
      overlayType: brandingOverlayType,
      proof: proof,
      hasBody: !(((_overlay$metaOverlay6 = overlay.metaOverlay) === null || _overlay$metaOverlay6 === void 0 ? void 0 : _overlay$metaOverlay6.issuer) === 'Unknown Contact' && proof)
    }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.primaryBodyNameContainer
    }, /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      variant: "bold",
      testID: (0, _testable.testIdWithKey)('CredentialName'),
      style: [styles.textContainer, styles.credentialName, {
        color: allPI && proof ? ColorPalette.notification.warnText : styles.textContainer.color
      }]
    }, (_overlay$metaOverlay7 = overlay.metaOverlay) === null || _overlay$metaOverlay7 === void 0 ? void 0 : _overlay$metaOverlay7.name)), extraOverlayParameter && !displayItems && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flex: 1,
        justifyContent: 'flex-end'
      }
    }, /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      variant: "caption",
      style: {
        color: styles.textContainer.color
      }
    }, extraOverlayParameter.label ?? (0, _lodash.default)(extraOverlayParameter.name || ''), ":", ' ', extraOverlayParameter.value)), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        flexDirection: 'row',
        alignItems: 'center'
      }
    }, credentialErrors.includes(_credentials.CredentialErrors.Revoked) && Boolean(proof) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Assets.svg.credentialRevoked, {
      height: 30,
      width: 30
    }), /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      style: styles.errorText,
      testID: (0, _testable.testIdWithKey)('RevokedOrNotAvailable'),
      numberOfLines: 1
    }, t('CredentialDetails.Revoked'))), credentialErrors.includes(_credentials.CredentialErrors.NotInWallet) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Assets.svg.credentialNotAvailable, {
      height: 30,
      width: 30
    }), /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      style: styles.errorText,
      testID: (0, _testable.testIdWithKey)('RevokedOrNotAvailable')
    }, t('ProofRequest.NotAvailableInYourWallet')))), /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
      data: cardData,
      scrollEnabled: false,
      initialNumToRender: cardData === null || cardData === void 0 ? void 0 : cardData.length,
      renderItem: ({
        item
      }) => {
        return renderCardAttribute(item);
      },
      ListFooterComponent: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, brandingOverlayType === _legacy.BrandingOverlayType.Branding11 && /*#__PURE__*/_react.default.createElement(_CredentialCard11Issuer.default, {
        overlay: overlay,
        overlayType: brandingOverlayType,
        proof: proof,
        hasBody: !(((_overlay$metaOverlay8 = overlay.metaOverlay) === null || _overlay$metaOverlay8 === void 0 ? void 0 : _overlay$metaOverlay8.issuer) === 'Unknown Contact' && proof)
      }), /*#__PURE__*/_react.default.createElement(CredentialCardPrimaryBodyFooter, null))
    }));
  };

  /**
   * Returns the background color for the slice of the card.
   *
   * @return {ColorValue} - The background color for the slice.
   */
  function getSliceBackgroundColor() {
    var _overlay$brandingOver6;
    if ((_overlay$brandingOver6 = overlay.brandingOverlay) !== null && _overlay$brandingOver6 !== void 0 && _overlay$brandingOver6.secondaryBackgroundColor) {
      return overlay.brandingOverlay.secondaryBackgroundColor;
    }
    if (styles.secondaryBodyContainer.backgroundColor) {
      return styles.secondaryBodyContainer.backgroundColor;
    }
    return 'transparent';
  }
  const CredentialCardSecondaryBody = () => {
    var _overlay$brandingOver7;
    // If the slice is hidden, we return an empty view with the same styles
    if (hideSlice) {
      return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
        testID: (0, _testable.testIdWithKey)('CredentialCardSecondaryBody'),
        style: [styles.secondaryBodyContainer, {
          backgroundColor: 'transparent',
          overflow: 'hidden'
        }]
      });
    }
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      testID: (0, _testable.testIdWithKey)('CredentialCardSecondaryBody'),
      style: [styles.secondaryBodyContainer, {
        backgroundColor: getSliceBackgroundColor(),
        overflow: 'hidden'
      }]
    }, (_overlay$brandingOver7 = overlay.brandingOverlay) !== null && _overlay$brandingOver7 !== void 0 && _overlay$brandingOver7.backgroundImageSlice && (!displayItems || brandingOverlayType === _legacy.BrandingOverlayType.Branding11) ? /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, {
      source: (0, _credential.toImageSource)(overlay.brandingOverlay.backgroundImageSlice),
      style: {
        flexGrow: 1
      },
      imageStyle: {
        borderTopLeftRadius: borderRadius,
        borderBottomLeftRadius: borderRadius
      }
    }) : !(proof || (0, _helpers.getSecondaryBackgroundColor)(overlay, proof)) && /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: [{
        position: 'absolute',
        width: logoHeight,
        height: '100%',
        borderTopLeftRadius: borderRadius,
        borderBottomLeftRadius: borderRadius,
        backgroundColor: 'rgba(0,0,0,0.24)'
      }]
    }));
  };
  const CredentialCardStatus = ({
    status
  }) => {
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      testID: (0, _testable.testIdWithKey)('CredentialCardStatus'),
      style: [styles.statusContainer, {
        position: 'absolute',
        right: 0,
        top: 0
      }]
    }, status ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: [styles.statusContainer, {
        backgroundColor: status === 'error' ? ColorPalette.notification.error : ColorPalette.notification.warn
      }]
    }, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      size: 0.7 * logoHeight,
      style: {
        color: status === 'error' ? ColorPalette.semantic.error : ColorPalette.notification.warnIcon
      },
      name: status
    })) : /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.statusContainer
    }));
  };
  const CredentialCard = ({
    status
  }) => {
    var _overlay$metaOverlay9, _overlay$metaOverlay0, _overlay$metaOverlay1, _overlay$metaOverlay10, _overlay$metaOverlay11, _overlay$metaOverlay12, _overlay$brandingOver8, _overlay$brandingOver9;
    const issuerAccessibilityLabel = (_overlay$metaOverlay9 = overlay.metaOverlay) !== null && _overlay$metaOverlay9 !== void 0 && _overlay$metaOverlay9.issuer ? `${t('Credentials.IssuedBy')} ${(_overlay$metaOverlay0 = overlay.metaOverlay) === null || _overlay$metaOverlay0 === void 0 ? void 0 : _overlay$metaOverlay0.issuer}` : '';
    const watermarkLabel = (_overlay$metaOverlay1 = overlay.metaOverlay) !== null && _overlay$metaOverlay1 !== void 0 && _overlay$metaOverlay1.watermark ? ((_overlay$metaOverlay10 = overlay.metaOverlay) === null || _overlay$metaOverlay10 === void 0 ? void 0 : _overlay$metaOverlay10.watermark) + ',' : '';
    const accessibilityLabel = isBranding11 ? `${watermarkLabel} ${((_overlay$metaOverlay11 = overlay.metaOverlay) === null || _overlay$metaOverlay11 === void 0 ? void 0 : _overlay$metaOverlay11.name) ?? ''} ${t('Credentials.Credential')}${cardData.length > 0 ? ',' : ''}` + cardData.map(item => {
      const {
        label,
        value
      } = parseAttribute(item);
      if (label && value) {
        return ` ${label}, ${value}`;
      }
    }) + `, ${issuerAccessibilityLabel}` : `${issuerAccessibilityLabel}, ${watermarkLabel} ${((_overlay$metaOverlay12 = overlay.metaOverlay) === null || _overlay$metaOverlay12 === void 0 ? void 0 : _overlay$metaOverlay12.name) ?? ''} ${t('Credentials.Credential')}.` + cardData.map(item => {
      const {
        label,
        value
      } = parseAttribute(item);
      if (label && value) {
        return ` ${label}, ${value}`;
      }
    });
    const MainCredentialBody = () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.cardContainer,
      accessible: true,
      accessibilityLabel: accessibilityLabel
    }, /*#__PURE__*/_react.default.createElement(CredentialCardSecondaryBody, null), /*#__PURE__*/_react.default.createElement(_CredentialCard11Logo.default, {
      noLogoText: logoText,
      overlay: overlay,
      elevated: elevated
    }), /*#__PURE__*/_react.default.createElement(CredentialCardPrimaryBody, null), /*#__PURE__*/_react.default.createElement(CredentialCardStatus, {
      status: status
    }));
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (_overlay$brandingOver8 = overlay.brandingOverlay) !== null && _overlay$brandingOver8 !== void 0 && _overlay$brandingOver8.backgroundImage && hideSlice ? /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, {
      source: (0, _credential.toImageSource)((_overlay$brandingOver9 = overlay.brandingOverlay) === null || _overlay$brandingOver9 === void 0 ? void 0 : _overlay$brandingOver9.backgroundImage)
    }, /*#__PURE__*/_react.default.createElement(MainCredentialBody, null)) : /*#__PURE__*/_react.default.createElement(MainCredentialBody, null));
  };
  const getCredentialStatus = () => {
    if (brandingOverlayType === _legacy.BrandingOverlayType.Branding10) {
      if (credentialErrors.includes(_credentials.CredentialErrors.Revoked) && !proof) {
        return 'error';
      } else if (allPI && proof) {
        return 'warning';
      }
      return undefined;
    }
    if (credentialErrors.includes(_credentials.CredentialErrors.Revoked)) {
      return 'error';
    } else if (allPI && proof) {
      return 'warning';
    }
    return undefined;
  };
  return overlay.bundle ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.container, style, {
      elevation: elevated ? 5 : 0,
      overflow: elevated ? 'visible' : 'hidden'
    }, hasAltCredentials ? styles.selectedCred : undefined],
    onLayout: event => {
      setDimensions({
        cardHeight: event.nativeEvent.layout.height,
        cardWidth: event.nativeEvent.layout.width
      });
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    accessible: false,
    accessibilityLabel: typeof onPress === 'undefined' ? undefined : t('Credentials.CredentialDetails'),
    disabled: typeof onPress === 'undefined' ? true : false,
    onPress: onPress,
    style: [styles.container, style],
    testID: (0, _testable.testIdWithKey)('ShowCredentialDetails')
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    testID: (0, _testable.testIdWithKey)('CredentialCard'),
    style: {
      overflow: 'hidden'
    }
  }, ((_overlay$metaOverlay13 = overlay.metaOverlay) === null || _overlay$metaOverlay13 === void 0 ? void 0 : _overlay$metaOverlay13.watermark) && /*#__PURE__*/_react.default.createElement(_CardWatermark.default, {
    width: dimensions.cardWidth,
    height: dimensions.cardHeight,
    style: {
      color: fontColorWithHighContrast()
    },
    watermark: (_overlay$metaOverlay14 = overlay.metaOverlay) === null || _overlay$metaOverlay14 === void 0 ? void 0 : _overlay$metaOverlay14.watermark
  }), /*#__PURE__*/_react.default.createElement(CredentialCard
  // if the credential is revoked and we are not in a proof context
  // display a small error icon in the top right of the credential card
  , {
    status: getCredentialStatus()
  })))) : null;
};
var _default = exports.default = CredentialCard11;
//# sourceMappingURL=CredentialCard11.js.map