"use strict";

import React, { memo, useMemo } from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
// @ts-ignore - MaterialCommunityIcons is available at runtime
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { useColorScheme } from '../hooks/use-color-scheme';
import { useHapticPress } from '../hooks/use-haptic-press';
import { darkenColor } from '../utils/colorUtils';
import { normalizeColorScheme } from '../utils/themeUtils';
import { Colors } from '../constants/theme';

/**
 * Maps Ionicons-style icon names to valid MaterialCommunityIcons names
 */
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const mapIconName = iconName => {
  const iconMap = {
    'person': 'account',
    'person-circle': 'account-circle',
    'person-outline': 'account-outline',
    'person-add': 'account-plus',
    'shield-checkmark': 'shield-check',
    'notifications': 'bell',
    'people': 'account-group',
    'time': 'clock',
    'time-outline': 'clock-outline',
    'trash': 'delete',
    'trash-outline': 'delete-outline',
    'search': 'magnify',
    'language': 'translate',
    'language-outline': 'translate',
    'settings': 'cog',
    'document-text': 'file-document',
    'information-circle': 'information',
    'information-circle-outline': 'information-outline',
    'log-out': 'logout'
  };
  return iconMap[iconName] || iconName;
};
const GroupedItemComponent = ({
  icon,
  iconColor,
  title,
  subtitle,
  onPress,
  isFirst = false,
  isLast = false,
  showChevron = false,
  disabled = false,
  customContent,
  customIcon
}) => {
  const hookColorScheme = useColorScheme();
  const colorScheme = normalizeColorScheme(hookColorScheme);
  // GroupedItem is a leaf component without a theme prop, so it should directly use Colors
  // instead of useThemeStyles which expects a theme prop from screen components
  const colors = Colors[colorScheme];
  // Use fallback color when iconColor is not provided
  const finalIconColor = iconColor || colors.iconSecurity;
  const itemStyles = useMemo(() => [styles.groupedItem, isFirst && styles.firstGroupedItem, isLast && styles.lastGroupedItem, {
    backgroundColor: colors.card
  }], [colors.card, isFirst, isLast]);
  const content = /*#__PURE__*/_jsxs(View, {
    style: styles.groupedItemContent,
    children: [customIcon ? /*#__PURE__*/_jsx(View, {
      style: styles.actionIcon,
      children: customIcon
    }) : icon ? /*#__PURE__*/_jsx(View, {
      style: [styles.iconContainer, {
        backgroundColor: finalIconColor
      }],
      children: /*#__PURE__*/_jsx(MaterialCommunityIcons, {
        name: mapIconName(icon),
        size: 22,
        color: darkenColor(finalIconColor)
      })
    }) : null, /*#__PURE__*/_jsxs(View, {
      style: styles.actionTextContainer,
      children: [/*#__PURE__*/_jsx(Text, {
        style: [styles.actionButtonText, {
          color: colors.text
        }],
        children: title
      }), subtitle && /*#__PURE__*/_jsx(Text, {
        style: [styles.actionButtonSubtext, {
          color: colors.secondaryText
        }],
        children: subtitle
      })]
    }), customContent, showChevron && /*#__PURE__*/_jsx(Ionicons, {
      name: "chevron-forward",
      size: 20,
      color: colors.icon
    })]
  });
  const handlePressIn = useHapticPress();
  if (onPress && !disabled) {
    return /*#__PURE__*/_jsx(TouchableOpacity, {
      style: itemStyles,
      onPressIn: disabled ? undefined : handlePressIn,
      onPress: onPress,
      activeOpacity: 0.7,
      children: content
    });
  }
  return /*#__PURE__*/_jsx(View, {
    style: itemStyles,
    children: content
  });
};
GroupedItemComponent.displayName = 'GroupedItem';
export const GroupedItem = /*#__PURE__*/memo(GroupedItemComponent);
const styles = StyleSheet.create({
  groupedItem: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    overflow: 'hidden',
    width: '100%'
  },
  firstGroupedItem: {
    borderTopLeftRadius: 18,
    borderTopRightRadius: 18
  },
  lastGroupedItem: {
    borderBottomLeftRadius: 18,
    borderBottomRightRadius: 18
  },
  groupedItemContent: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingVertical: 8,
    paddingHorizontal: 10,
    width: '100%',
    gap: 10
  },
  actionIcon: {
    // marginRight handled by gap
  },
  iconContainer: {
    width: 36,
    height: 36,
    borderRadius: 18,
    alignItems: 'center',
    justifyContent: 'center'
    // marginRight handled by gap
  },
  actionTextContainer: {
    flex: 1
  },
  actionButtonText: {
    fontSize: 14,
    fontWeight: '400'
  },
  actionButtonSubtext: {
    fontSize: 12,
    marginTop: 2
  }
});
export default GroupedItem;
//# sourceMappingURL=GroupedItem.js.map