"use strict";

import { isValidElement } from "react";
import { Image, StyleSheet, View } from "react-native";
import { useIOTheme } from "../../context";
import { IOListItemVisualParams, IOVisualCostants } from "../../core";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { Badge } from "../badge";
import { Icon } from "../icons";
import { HStack, VStack } from "../layout";
import { LoadingSpinner } from "../loadingSpinner";
import { IOSkeleton } from "../skeleton";
import { BodySmall, LabelMini } from "../typography";
import { ModuleStatic } from "./ModuleStatic";
import { PressableModuleBase } from "./PressableModuleBase";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const ModuleNavigationAlt = props => {
  const theme = useIOTheme();
  const {
    hugeFontEnabled
  } = useIOFontDynamicScale();
  const graphicWrapperSize = 48;
  if (props.isLoading) {
    return /*#__PURE__*/_jsx(ModuleNavigationAltSkeleton, {
      loadingAccessibilityLabel: props.loadingAccessibilityLabel
    });
  }
  const {
    testID,
    icon,
    iconColor = theme["interactiveElem-default"],
    image,
    title,
    subtitle,
    onPress,
    badge,
    isFetching,
    rightIcon,
    ...pressableProps
  } = props;
  const iconComponent = icon && /*#__PURE__*/_jsx(Icon, {
    name: icon,
    size: 32,
    color: iconColor
  });
  const imageComponent = () => {
    if (!image) {
      return null;
    }
    if (/*#__PURE__*/isValidElement(image)) {
      return image;
    } else {
      return /*#__PURE__*/_jsx(View, {
        children: /*#__PURE__*/_jsx(Image, {
          source: image,
          style: styles.image,
          accessibilityIgnoresInvertColors: true
        })
      });
    }
  };
  const endComponent = () => {
    if (isFetching) {
      return /*#__PURE__*/_jsx(LoadingSpinner, {
        testID: testID ? `${testID}_activityIndicator` : undefined
      });
    }
    if (onPress) {
      return /*#__PURE__*/_jsx(Icon, {
        testID: testID ? `${testID}_icon` : undefined,
        name: rightIcon ?? "chevronRightListItem",
        color: theme["interactiveElem-default"],
        size: IOListItemVisualParams.chevronSize
      });
    }
    return null;
  };
  return /*#__PURE__*/_jsx(PressableModuleBase, {
    ...pressableProps,
    testID: testID,
    onPress: onPress,
    children: /*#__PURE__*/_jsxs(HStack, {
      space: 8,
      style: {
        alignItems: "center"
      },
      children: [/*#__PURE__*/_jsxs(HStack, {
        space: IOVisualCostants.iconMargin,
        style: {
          alignItems: "center",
          flexGrow: 1,
          flexShrink: 1
        },
        children: [!hugeFontEnabled && /*#__PURE__*/_jsx(View, {
          style: {
            alignItems: "center",
            justifyContent: "center",
            width: graphicWrapperSize,
            height: graphicWrapperSize
          },
          children: iconComponent ?? imageComponent()
        }), /*#__PURE__*/_jsxs(VStack, {
          space: 8,
          style: {
            flexShrink: 1,
            alignItems: "flex-start"
          },
          children: [badge ? /*#__PURE__*/_jsx(Badge, {
            ...badge
          }) : null, /*#__PURE__*/_jsxs(View, {
            children: [/*#__PURE__*/_jsx(BodySmall, {
              color: theme["interactiveElem-default"],
              weight: "Semibold",
              numberOfLines: 2,
              lineBreakMode: "middle",
              style: {
                flexShrink: 1
              },
              children: title
            }), subtitle && /*#__PURE__*/_jsx(LabelMini, {
              weight: "Regular",
              color: theme["textBody-tertiary"],
              children: subtitle
            })]
          })]
        })]
      }), endComponent()]
    })
  });
};
const ModuleNavigationAltSkeleton = ({
  loadingAccessibilityLabel
}) => /*#__PURE__*/_jsx(ModuleStatic, {
  accessible: true,
  accessibilityLabel: loadingAccessibilityLabel,
  accessibilityState: {
    busy: true
  },
  startBlock: /*#__PURE__*/_jsxs(HStack, {
    style: {
      alignItems: "center"
    },
    space: IOVisualCostants.iconMargin,
    children: [/*#__PURE__*/_jsx(IOSkeleton, {
      shape: "square",
      size: 32,
      radius: 8
    }), /*#__PURE__*/_jsxs(VStack, {
      space: 4,
      children: [/*#__PURE__*/_jsx(IOSkeleton, {
        shape: "rectangle",
        width: 52,
        height: 12,
        radius: 8
      }), /*#__PURE__*/_jsx(IOSkeleton, {
        shape: "rectangle",
        width: 96,
        height: 16,
        radius: 8
      }), /*#__PURE__*/_jsx(IOSkeleton, {
        shape: "rectangle",
        width: 160,
        height: 12,
        radius: 8
      })]
    })]
  }),
  endBlock: /*#__PURE__*/_jsx(IOSkeleton, {
    shape: "rectangle",
    width: 64,
    height: 24,
    radius: 16
  })
});
const styles = StyleSheet.create({
  image: {
    width: "100%",
    height: "auto",
    resizeMode: "contain"
  }
});
//# sourceMappingURL=ModuleNavigationAlt.js.map