"use strict";

import { Image, Pressable, View } from "react-native";
import Animated from "react-native-reanimated";
import { useIOTheme } from "../../context";
import { IOColors, IOListItemStyles, IOListItemVisualParams, IOSelectionListItemVisualParams, IOVisualCostants } from "../../core";
import { useListItemAnimation } from "../../hooks";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { Avatar } from "../avatar";
import { Badge } from "../badge";
import { Icon } from "../icons";
import { HSpacer, VSpacer } from "../layout";
import { LoadingSpinner } from "../loadingSpinner";
import { BodySmall, Caption, H6 } from "../typography";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export const ListItemNav = ({
  value,
  description,
  onPress,
  icon,
  iconColor,
  avatarProps: avatar,
  paymentLogoUri,
  accessibilityLabel,
  accessibilityHint,
  testID,
  hideChevron = false,
  topElement,
  loading,
  numberOfLines
}) => {
  const {
    onPressIn,
    onPressOut,
    scaleAnimatedStyle,
    backgroundAnimatedStyle
  } = useListItemAnimation();
  const theme = useIOTheme();
  const defaultIconColor = iconColor ?? theme["icon-decorative"];
  const interactiveColor = theme["interactiveElem-default"];
  const {
    dynamicFontScale,
    hugeFontEnabled
  } = useIOFontDynamicScale();
  const listItemNavContent = /*#__PURE__*/_jsxs(_Fragment, {
    children: [topElement && /*#__PURE__*/_jsxs(_Fragment, {
      children: [topElement.badgeProps && /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(View, {
          style: {
            alignSelf: "flex-start"
          },
          children: /*#__PURE__*/_jsx(Badge, {
            ...topElement.badgeProps
          })
        }), /*#__PURE__*/_jsx(VSpacer, {
          size: 8
        })]
      }), topElement.dateValue && /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsxs(View, {
          style: {
            alignSelf: "flex-start",
            flexDirection: "row"
          },
          children: [/*#__PURE__*/_jsx(Icon, {
            allowFontScaling: true,
            name: "calendar",
            size: 16,
            color: "grey-300"
          }), /*#__PURE__*/_jsx(HSpacer, {
            size: 4
          }), /*#__PURE__*/_jsx(Caption, {
            color: theme["textBody-tertiary"],
            children: topElement.dateValue
          })]
        }), /*#__PURE__*/_jsx(VSpacer, {
          size: 4
        })]
      })]
    }), typeof value === "string" ? /*#__PURE__*/_jsx(H6, {
      color: theme["textBody-default"],
      numberOfLines: numberOfLines,
      children: value
    }) : value, description && /*#__PURE__*/_jsx(_Fragment, {
      children: typeof description === "string" ? /*#__PURE__*/_jsx(BodySmall, {
        weight: "Regular",
        color: theme["textBody-tertiary"],
        children: description
      }) : description
    })]
  });
  const handleOnPress = event => {
    if (!loading) {
      onPress(event);
    }
  };
  return /*#__PURE__*/_jsx(Pressable, {
    onPress: handleOnPress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    onTouchEnd: onPressOut,
    accessible: true,
    accessibilityState: {
      busy: loading
    },
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    accessibilityRole: "button",
    testID: testID,
    children: /*#__PURE__*/_jsx(Animated.View, {
      style: [IOListItemStyles.listItem, backgroundAnimatedStyle],
      children: /*#__PURE__*/_jsxs(Animated.View, {
        style: [IOListItemStyles.listItemInner, scaleAnimatedStyle],
        children: [icon && !hugeFontEnabled && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(Icon, {
            allowFontScaling: true,
            name: icon,
            color: defaultIconColor,
            size: IOListItemVisualParams.iconSize
          }), /*#__PURE__*/_jsx(HSpacer, {
            allowScaleSpacing: true,
            size: IOVisualCostants.iconMargin
          })]
        }), paymentLogoUri && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(Image, {
            accessibilityIgnoresInvertColors: true,
            source: {
              uri: paymentLogoUri
            },
            style: {
              width: IOSelectionListItemVisualParams.iconSize * dynamicFontScale,
              height: IOSelectionListItemVisualParams.iconSize * dynamicFontScale
            }
          }), /*#__PURE__*/_jsx(HSpacer, {
            allowScaleSpacing: true,
            size: IOVisualCostants.iconMargin
          })]
        }), avatar && /*#__PURE__*/_jsxs(_Fragment, {
          children: [/*#__PURE__*/_jsx(Avatar, {
            size: "small",
            ...avatar
          }), /*#__PURE__*/_jsx(HSpacer, {
            allowScaleSpacing: true,
            size: IOVisualCostants.iconMargin
          })]
        }), /*#__PURE__*/_jsx(View, {
          style: {
            flexGrow: 1,
            flexShrink: 1
          },
          children: listItemNavContent
        }), loading && /*#__PURE__*/_jsx(LoadingSpinner, {
          color: IOColors[interactiveColor]
        }), !loading && !hideChevron && /*#__PURE__*/_jsx(Icon, {
          allowFontScaling: true,
          name: "chevronRightListItem",
          color: interactiveColor,
          size: IOListItemVisualParams.chevronSize
        })]
      })
    })
  });
};
//# sourceMappingURL=ListItemNav.js.map