"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ModuleCredential = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _context = require("../../context");
var _core = require("../../core");
var _accessibility = require("../../utils/accessibility");
var _badge = require("../badge");
var _icons = require("../icons");
var _layout = require("../layout");
var _Stack = require("../layout/Stack");
var _loadingSpinner = require("../loadingSpinner");
var _skeleton = require("../skeleton");
var _typography = require("../typography");
var _ModuleStatic = require("./ModuleStatic");
var _PressableModuleBase = require("./PressableModuleBase");
var _jsxRuntime = require("react/jsx-runtime");
const ModuleCredential = props => props.isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleCredentialSkeleton, {
  loadingAccessibilityLabel: props.loadingAccessibilityLabel
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleCredentialContent, {
  ...props
});
exports.ModuleCredential = ModuleCredential;
const ModuleContent = ({
  icon,
  image,
  label,
  endComponent
}) => {
  const theme = (0, _context.useIOTheme)();
  const {
    hugeFontEnabled
  } = (0, _accessibility.useIOFontDynamicScale)();
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Stack.HStack, {
    space: 8,
    style: {
      alignItems: "center"
    },
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Stack.HStack, {
      space: _core.IOVisualCostants.iconMargin,
      style: {
        flexGrow: 1,
        flexShrink: 1,
        alignItems: "center"
      },
      children: [icon && !hugeFontEnabled ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
        allowFontScaling: true,
        name: icon,
        size: _core.IOSelectionListItemVisualParams.iconSize,
        color: theme["icon-decorative"]
      }) : image && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
        source: image,
        style: styles.image,
        accessibilityIgnoresInvertColors: true
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.BodySmall, {
        color: theme["interactiveElem-default"],
        weight: "Semibold",
        numberOfLines: 2,
        lineBreakMode: "middle",
        style: {
          flexShrink: 1
        },
        children: label
      })]
    }), endComponent]
  });
};
const ModuleCredentialContent = ({
  testID,
  icon,
  image,
  label,
  onPress,
  badge,
  isFetching,
  ...pressableProps
}) => {
  const theme = (0, _context.useIOTheme)();
  const endComponent = (0, _react.useMemo)(() => {
    const activityIndicatorTestID = testID ? `${testID}_activityIndicator` : undefined;
    const chevronTestID = testID ? `${testID}_icon` : undefined;
    const badgeTestID = testID ? `${testID}_badge` : undefined;
    return badge || onPress ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Stack.HStack, {
      style: {
        alignItems: "center"
      },
      children: [badge && /*#__PURE__*/(0, _jsxRuntime.jsx)(_badge.Badge, {
        ...badge,
        testID: badgeTestID
      }), onPress && (isFetching ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.HSpacer, {
          size: 8
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_loadingSpinner.LoadingSpinner, {
          testID: activityIndicatorTestID
        })]
      }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
        testID: chevronTestID,
        name: "chevronRightListItem",
        color: theme["interactiveElem-default"],
        size: _core.IOListItemVisualParams.chevronSize
      }))]
    }) : null;
  }, [testID, theme, isFetching, badge, onPress]);
  return onPress ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_PressableModuleBase.PressableModuleBase, {
    ...pressableProps,
    testID: testID,
    onPress: onPress,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleContent, {
      icon: icon,
      image: image,
      label: label,
      endComponent: endComponent
    })
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ModuleStatic.ModuleStatic, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ModuleContent, {
      icon: icon,
      image: image,
      label: label,
      endComponent: endComponent
    })
  });
};
const ModuleCredentialSkeleton = ({
  loadingAccessibilityLabel
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ModuleStatic.ModuleStatic, {
  accessible: true,
  accessibilityLabel: loadingAccessibilityLabel,
  accessibilityState: {
    busy: true
  },
  startBlock: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Stack.HStack, {
    style: {
      alignItems: "center"
    },
    space: _core.IOVisualCostants.iconMargin,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_skeleton.IOSkeleton, {
      shape: "square",
      size: 24,
      radius: 8
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_skeleton.IOSkeleton, {
      shape: "rectangle",
      width: 96,
      height: 16,
      radius: 8
    })]
  }),
  endBlock: /*#__PURE__*/(0, _jsxRuntime.jsx)(_skeleton.IOSkeleton, {
    shape: "rectangle",
    width: 64,
    height: 24,
    radius: 16
  })
});
const styles = _reactNative.StyleSheet.create({
  image: {
    width: _core.IOSelectionListItemVisualParams.iconSize,
    height: _core.IOSelectionListItemVisualParams.iconSize,
    resizeMode: "contain"
  }
});
//# sourceMappingURL=ModuleCredential.js.map