import { BrandingOverlayType } from '@bifold/oca/build/legacy';
import React, { useMemo } from 'react';
import { Image, StyleSheet, useWindowDimensions, View } from 'react-native';
import { useTheme } from '../../contexts/theme';
import { toImageSource } from '../../utils/credential';
import { ThemedText } from '../texts/ThemedText';
const CredentialCardLogo = ({
  overlay,
  brandingOverlayType = BrandingOverlayType.Branding10
}) => {
  var _overlay$brandingOver, _overlay$brandingOver2, _overlay$brandingOver3, _overlay$brandingOver4;
  const {
    CredentialCardShadowTheme
  } = useTheme();
  const {
    fontScale
  } = useWindowDimensions();
  const logoHeight = brandingOverlayType === BrandingOverlayType.Branding10 ? 80 : 48;
  const paddingHorizontal = 24;
  const isBranding11 = brandingOverlayType === BrandingOverlayType.Branding11;
  const textColor = (_overlay$brandingOver = overlay.brandingOverlay) !== null && _overlay$brandingOver !== void 0 && _overlay$brandingOver.secondaryBackgroundColor && overlay.brandingOverlay.secondaryBackgroundColor !== '' ? overlay.brandingOverlay.secondaryBackgroundColor : (_overlay$brandingOver2 = overlay.brandingOverlay) === null || _overlay$brandingOver2 === void 0 ? void 0 : _overlay$brandingOver2.primaryBackgroundColor;
  const logoText = useMemo(() => {
    var _overlay$metaOverlay2, _overlay$metaOverlay3;
    if (brandingOverlayType === BrandingOverlayType.Branding11) {
      var _overlay$metaOverlay;
      return (((_overlay$metaOverlay = overlay.metaOverlay) === null || _overlay$metaOverlay === void 0 ? void 0 : _overlay$metaOverlay.issuer) ?? 'I').charAt(0).toUpperCase();
    }
    return (((_overlay$metaOverlay2 = overlay.metaOverlay) === null || _overlay$metaOverlay2 === void 0 ? void 0 : _overlay$metaOverlay2.name) ?? ((_overlay$metaOverlay3 = overlay.metaOverlay) === null || _overlay$metaOverlay3 === void 0 ? void 0 : _overlay$metaOverlay3.issuer) ?? 'C').charAt(0).toUpperCase();
  }, [brandingOverlayType, overlay]);
  const styles = StyleSheet.create({
    logoContainer: {
      width: logoHeight * (fontScale > 1.7 ? 1.2 : 1),
      height: logoHeight * (fontScale > 1.7 ? 1.2 : 1),
      backgroundColor: '#ffffff',
      borderRadius: 8,
      justifyContent: 'center',
      alignItems: 'center',
      ...(brandingOverlayType === BrandingOverlayType.Branding10 && {
        top: -0.5 * logoHeight,
        left: paddingHorizontal,
        marginBottom: -1 * logoHeight,
        ...CredentialCardShadowTheme
      })
    }
  });
  return /*#__PURE__*/React.createElement(View, {
    style: styles.logoContainer
  }, (_overlay$brandingOver3 = overlay.brandingOverlay) !== null && _overlay$brandingOver3 !== void 0 && _overlay$brandingOver3.logo ? /*#__PURE__*/React.createElement(Image, {
    source: toImageSource((_overlay$brandingOver4 = overlay.brandingOverlay) === null || _overlay$brandingOver4 === void 0 ? void 0 : _overlay$brandingOver4.logo),
    style: {
      resizeMode: 'cover',
      width: logoHeight,
      height: logoHeight,
      borderRadius: 8
    }
  }) : /*#__PURE__*/React.createElement(ThemedText, {
    variant: "title",
    style: {
      fontSize: 0.5 * logoHeight,
      color: isBranding11 ? textColor : '#000'
    },
    accessible: false
  }, logoText));
};
export default CredentialCardLogo;
//# sourceMappingURL=CredentialCardLogo.js.map