"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.GroupedItem = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _vectorIcons = require("@expo/vector-icons");
var _useColorScheme = require("../hooks/use-color-scheme");
var _useHapticPress = require("../hooks/use-haptic-press");
var _colorUtils = require("../utils/colorUtils");
var _themeUtils = require("../utils/themeUtils");
var _theme = require("../constants/theme");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
// @ts-ignore - MaterialCommunityIcons is available at runtime

/**
 * Maps Ionicons-style icon names to valid MaterialCommunityIcons names
 */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 = (0, _useColorScheme.useColorScheme)();
  const colorScheme = (0, _themeUtils.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 = _theme.Colors[colorScheme];
  // Use fallback color when iconColor is not provided
  const finalIconColor = iconColor || colors.iconSecurity;
  const itemStyles = (0, _react.useMemo)(() => [styles.groupedItem, isFirst && styles.firstGroupedItem, isLast && styles.lastGroupedItem, {
    backgroundColor: colors.card
  }], [colors.card, isFirst, isLast]);
  const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: styles.groupedItemContent,
    children: [customIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.actionIcon,
      children: customIcon
    }) : icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: [styles.iconContainer, {
        backgroundColor: finalIconColor
      }],
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.MaterialCommunityIcons, {
        name: mapIconName(icon),
        size: 22,
        color: (0, _colorUtils.darkenColor)(finalIconColor)
      })
    }) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: styles.actionTextContainer,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.actionButtonText, {
          color: colors.text
        }],
        children: title
      }), subtitle && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.actionButtonSubtext, {
          color: colors.secondaryText
        }],
        children: subtitle
      })]
    }), customContent, showChevron && /*#__PURE__*/(0, _jsxRuntime.jsx)(_vectorIcons.Ionicons, {
      name: "chevron-forward",
      size: 20,
      color: colors.icon
    })]
  });
  const handlePressIn = (0, _useHapticPress.useHapticPress)();
  if (onPress && !disabled) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
      style: itemStyles,
      onPressIn: disabled ? undefined : handlePressIn,
      onPress: onPress,
      activeOpacity: 0.7,
      children: content
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: itemStyles,
    children: content
  });
};
GroupedItemComponent.displayName = 'GroupedItem';
const GroupedItem = exports.GroupedItem = /*#__PURE__*/(0, _react.memo)(GroupedItemComponent);
const styles = _reactNative.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
  }
});
var _default = exports.default = GroupedItem;
//# sourceMappingURL=GroupedItem.js.map