"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.CredentialErrors = 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");
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; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
let CredentialErrors = exports.CredentialErrors = /*#__PURE__*/function (CredentialErrors) {
  CredentialErrors[CredentialErrors["Revoked"] = 0] = "Revoked";
  CredentialErrors[CredentialErrors["NotInWallet"] = 1] = "NotInWallet";
  CredentialErrors[CredentialErrors["PredicateError"] = 2] = "PredicateError";
  return CredentialErrors;
}({}); // Credential requested for proof contains a predicate match that is not satisfied
/*
  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$metaOverlay15, _overlay$metaOverlay16;
  const [dimensions, setDimensions] = (0, _react.useState)({
    cardWidth: 0,
    cardHeight: 0
  });
  const {
    i18n,
    t
  } = (0, _reactI18next.useTranslation)();
  const {
    ColorPallet,
    ListItems
  } = (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)(() => {
    var _overlay$bundle;
    return (_overlay$bundle = overlay.bundle) === null || _overlay$bundle === void 0 ? void 0 : _overlay$bundle.bundle.attributes.map(attr => {
      return {
        name: attr.name,
        format: attr.format
      };
    }).reduce((prev, curr) => {
      return {
        ...prev,
        [curr.name]: curr.format
      };
    }, {});
  }, [overlay]);
  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 backgroundColorIfRevoked = backgroundColor => credentialErrors.includes(CredentialErrors.Revoked) ? ColorPallet.notification.errorBorder : backgroundColor;
  const fontColorWithHighContrast = () => {
    var _overlay$brandingOver3;
    if (proof && brandingOverlayType === _legacy.BrandingOverlayType.Branding10) {
      return ColorPallet.grayscale.mediumGrey;
    }
    const c = backgroundColorIfRevoked((_overlay$brandingOver3 = overlay.brandingOverlay) === null || _overlay$brandingOver3 === void 0 ? void 0 : _overlay$brandingOver3.primaryBackgroundColor) ?? ColorPallet.grayscale.lightGrey;
    const shade = (0, _luminance.shadeIsLightOrDark)(c);
    return shade == _luminance.Shade.Light ? ColorPallet.grayscale.darkGrey : ColorPallet.grayscale.lightGrey;
  };
  const parseAttribute = (0, _react.useCallback)(item => {
    var _parsedItem, _parsedItem2, _parsedItem3;
    let parsedItem = item;
    if (item && item.pValue != null) {
      var _overlay$bundle2;
      parsedItem = (0, _helpers.pTypeToText)(item, t, (_overlay$bundle2 = overlay.bundle) === null || _overlay$bundle2 === void 0 ? void 0 : _overlay$bundle2.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 _Object$values;
        setFlaggedAttributes(bundle.bundle.bundle.flaggedAttributes.map(attr => attr.name));
        const credHelpUrl = bundle.bundle.bundle.metadata.credentialSupportUrl[params.language] ?? ((_Object$values = Object.values(bundle.bundle.bundle.metadata.credentialSupportUrl)) === 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 (credHelpUrl) {
          setHelpAction(() => () => {
            _reactNative.Linking.openURL(credHelpUrl);
          });
        }
      }
      setOverlay(o => ({
        ...o,
        ...bundle,
        brandingOverlay: bundle.brandingOverlay
      }));
    });
  }, [credential, schemaId, credDefId, credName, credentialConnectionLabel, i18n.language, bundleResolver, proof, credHelpActionOverrides, navigation, brandingOverlay]);
  const AttributeLabel = ({
    label
  }) => {
    var _overlay$bundle3;
    const ylabel = ((_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);
    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 ? ColorPallet.notification.warnText : styles.textContainer.color
      }],
      testID: (0, _testable.testIdWithKey)('AttributeValue')
    }, value));
  };
  const renderCardAttribute = item => {
    var _overlay$bundle4;
    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(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(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: ColorPallet.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(CredentialErrors.NotInWallet) && item.hasError && /*#__PURE__*/_react.default.createElement(AttributeErrorLabel, {
      errorMessage: t('ProofRequest.MissingAttribute', {
        name: ((_overlay$bundle4 = overlay.bundle) === null || _overlay$bundle4 === void 0 || (_overlay$bundle4 = _overlay$bundle4.labelOverlay) === null || _overlay$bundle4 === void 0 ? void 0 : _overlay$bundle4.attributeLabels[label]) ?? (0, _lodash.default)(label)
      })
    }), !credentialErrors.includes(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)(ColorPallet, (_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)(ColorPallet, (_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 ? ColorPallet.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(CredentialErrors.Revoked) && Boolean(proof) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      style: styles.errorIcon,
      name: "close",
      size: 30
    }), /*#__PURE__*/_react.default.createElement(_ThemedText.ThemedText, {
      style: styles.errorText,
      testID: (0, _testable.testIdWithKey)('RevokedOrNotAvailable'),
      numberOfLines: 1
    }, t('CredentialDetails.Revoked'))), credentialErrors.includes(CredentialErrors.NotInWallet) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      style: styles.errorIcon,
      name: "close",
      size: 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))
    }));
  };
  function getSliceBackgroundColor() {
    var _overlay$brandingOver6;
    if (hideSlice) return 'transparent';
    return brandingOverlayType === _legacy.BrandingOverlayType.Branding10 ? backgroundColorIfRevoked(styles.secondaryBodyContainer.backgroundColor) : (_overlay$brandingOver6 = overlay.brandingOverlay) === null || _overlay$brandingOver6 === void 0 ? void 0 : _overlay$brandingOver6.secondaryBackgroundColor;
  }
  const CredentialCardSecondaryBody = () => {
    var _overlay$brandingOver7, _overlay$brandingOver8;
    return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      testID: (0, _testable.testIdWithKey)('CredentialCardSecondaryBody'),
      style: [styles.secondaryBodyContainer, {
        backgroundColor: getSliceBackgroundColor() ?? ColorPallet.brand.secondaryBackground,
        overflow: 'hidden'
      }]
    }, (_overlay$brandingOver7 = overlay.brandingOverlay) !== null && _overlay$brandingOver7 !== void 0 && _overlay$brandingOver7.backgroundImageSlice && (!displayItems || brandingOverlayType === _legacy.BrandingOverlayType.Branding11) && !hideSlice ? /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, {
      source: (0, _credential.toImageSource)((_overlay$brandingOver8 = overlay.brandingOverlay) === null || _overlay$brandingOver8 === void 0 ? void 0 : _overlay$brandingOver8.backgroundImageSlice),
      style: {
        flexGrow: 1
      },
      imageStyle: {
        borderTopLeftRadius: borderRadius,
        borderBottomLeftRadius: borderRadius
      }
    }) : !(Boolean(credentialErrors.length) || proof || (0, _helpers.getSecondaryBackgroundColor)(overlay, proof)) && !hideSlice && /*#__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' ? ColorPallet.notification.error : ColorPallet.notification.warn
      }]
    }, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      size: 0.7 * logoHeight,
      style: {
        color: status === 'error' ? ColorPallet.semantic.error : ColorPallet.notification.warnIcon
      },
      name: status
    })) : /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.statusContainer
    }));
  };
  const CredentialCard = ({
    status
  }) => {
    var _overlay$metaOverlay9, _overlay$metaOverlay10, _overlay$metaOverlay11, _overlay$metaOverlay12, _overlay$metaOverlay13, _overlay$metaOverlay14, _overlay$brandingOver9, _overlay$brandingOver10;
    const issuerAccessibilityLabel = (_overlay$metaOverlay9 = overlay.metaOverlay) !== null && _overlay$metaOverlay9 !== void 0 && _overlay$metaOverlay9.issuer ? `${t('Credentials.IssuedBy')} ${(_overlay$metaOverlay10 = overlay.metaOverlay) === null || _overlay$metaOverlay10 === void 0 ? void 0 : _overlay$metaOverlay10.issuer}` : '';
    const watermarkLabel = (_overlay$metaOverlay11 = overlay.metaOverlay) !== null && _overlay$metaOverlay11 !== void 0 && _overlay$metaOverlay11.watermark ? ((_overlay$metaOverlay12 = overlay.metaOverlay) === null || _overlay$metaOverlay12 === void 0 ? void 0 : _overlay$metaOverlay12.watermark) + ',' : '';
    const accessibilityLabel = isBranding11 ? `${watermarkLabel} ${((_overlay$metaOverlay13 = overlay.metaOverlay) === null || _overlay$metaOverlay13 === void 0 ? void 0 : _overlay$metaOverlay13.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$metaOverlay14 = overlay.metaOverlay) === null || _overlay$metaOverlay14 === void 0 ? void 0 : _overlay$metaOverlay14.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$brandingOver9 = overlay.brandingOverlay) !== null && _overlay$brandingOver9 !== void 0 && _overlay$brandingOver9.backgroundImage && hideSlice ? /*#__PURE__*/_react.default.createElement(_reactNative.ImageBackground, {
      source: (0, _credential.toImageSource)((_overlay$brandingOver10 = overlay.brandingOverlay) === null || _overlay$brandingOver10 === void 0 ? void 0 : _overlay$brandingOver10.backgroundImage)
    }, /*#__PURE__*/_react.default.createElement(MainCredentialBody, null)) : /*#__PURE__*/_react.default.createElement(MainCredentialBody, null));
  };
  const getCredentialStatus = () => {
    if (brandingOverlayType === _legacy.BrandingOverlayType.Branding10) {
      if (credentialErrors.includes(CredentialErrors.Revoked) && !proof) {
        return 'error';
      } else if (allPI && proof) {
        return 'warning';
      }
      return undefined;
    }
    if (credentialErrors.includes(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$metaOverlay15 = overlay.metaOverlay) === null || _overlay$metaOverlay15 === void 0 ? void 0 : _overlay$metaOverlay15.watermark) && /*#__PURE__*/_react.default.createElement(_CardWatermark.default, {
    width: dimensions.cardWidth,
    height: dimensions.cardHeight,
    style: {
      color: fontColorWithHighContrast()
    },
    watermark: (_overlay$metaOverlay16 = overlay.metaOverlay) === null || _overlay$metaOverlay16 === void 0 ? void 0 : _overlay$metaOverlay16.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