"use strict";

import React, { memo, useMemo } from 'react';
import { Pressable, StyleSheet, View } from 'react-native';
import { useTheme } from "../theme/use-theme.js";
import { useInteractionState } from "../hooks/useInteractionState.js";
import { Text } from "../typography/index.js";
import { borderRadius, fontSize, space } from "../styles/tokens.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const DENSITY = {
  comfortable: {
    paddingVertical: 10,
    minHeight: 44
  },
  compact: {
    paddingVertical: 6,
    minHeight: 36
  }
};

/**
 * A generic list row — the building block shared by settings lists, menus,
 * combobox/command option lists, etc. Leading + trailing slots flank a
 * title/subtitle text column (or arbitrary `children`). Pressable when an
 * `onPress` is supplied; otherwise a static container.
 */
const ItemComponent = function Item({
  title,
  subtitle,
  children,
  leading,
  trailing,
  onPress,
  onLongPress,
  disabled = false,
  destructive = false,
  selected = false,
  active = false,
  density = 'comfortable',
  style,
  titleStyle,
  subtitleStyle,
  accessibilityLabel,
  accessibilityHint,
  accessibilityRole,
  role,
  testID
}) {
  const theme = useTheme();
  const {
    state: pressed,
    onIn: onPressIn,
    onOut: onPressOut
  } = useInteractionState();
  const titleColor = destructive ? theme.colors.error : theme.colors.text;
  const cfg = DENSITY[density];
  const containerStyle = useMemo(() => {
    const base = {
      flexDirection: 'row',
      alignItems: 'center',
      gap: space.md,
      paddingHorizontal: space.lg,
      paddingVertical: cfg.paddingVertical,
      minHeight: cfg.minHeight,
      borderRadius: borderRadius.sm
    };
    if (selected || active) {
      base.backgroundColor = active ? theme.colors.primaryLight : theme.colors.backgroundSecondary;
    }
    return base;
  }, [cfg, selected, active, theme]);
  const body = children != null ? children : /*#__PURE__*/_jsxs(View, {
    style: styles.textColumn,
    children: [title != null ? typeof title === 'string' ? /*#__PURE__*/_jsx(Text, {
      numberOfLines: 1,
      style: [styles.title, {
        color: titleColor
      }, titleStyle],
      children: title
    }) : title : null, subtitle != null ? typeof subtitle === 'string' ? /*#__PURE__*/_jsx(Text, {
      numberOfLines: 2,
      style: [styles.subtitle, {
        color: theme.colors.textSecondary
      }, subtitleStyle],
      children: subtitle
    }) : subtitle : null]
  });
  const content = /*#__PURE__*/_jsxs(View, {
    style: [containerStyle, style],
    testID: testID,
    children: [leading != null ? /*#__PURE__*/_jsx(View, {
      style: styles.slot,
      children: leading
    }) : null, body, trailing != null ? /*#__PURE__*/_jsx(View, {
      style: styles.slot,
      children: trailing
    }) : null]
  });
  if (onPress || onLongPress) {
    const resolvedRole = accessibilityRole ?? 'button';
    const handlePress = disabled || !onPress ? undefined : onPress;
    const handleLongPress = disabled || !onLongPress ? undefined : onLongPress;
    return /*#__PURE__*/_jsx(Pressable, {
      onPress: handlePress,
      onLongPress: handleLongPress,
      onPressIn: disabled ? undefined : onPressIn,
      onPressOut: disabled ? undefined : onPressOut,
      disabled: disabled,
      android_ripple: {
        color: theme.colors.border
      },
      accessibilityRole: resolvedRole,
      ...(role ? {
        role
      } : {}),
      accessibilityLabel: accessibilityLabel ?? (typeof title === 'string' ? title : undefined),
      accessibilityHint: accessibilityHint,
      accessibilityState: {
        disabled,
        selected
      },
      style: [disabled && styles.disabled, pressed && !disabled && styles.pressed],
      children: content
    });
  }
  return /*#__PURE__*/_jsx(View, {
    accessibilityRole: accessibilityRole ?? 'none',
    ...(role ? {
      role
    } : {}),
    accessibilityLabel: accessibilityLabel ?? (typeof title === 'string' ? title : undefined),
    accessibilityHint: accessibilityHint,
    accessibilityState: disabled ? {
      disabled: true
    } : undefined,
    style: disabled ? styles.disabled : undefined,
    children: content
  });
};
const styles = StyleSheet.create({
  slot: {
    alignItems: 'center',
    justifyContent: 'center'
  },
  textColumn: {
    flex: 1,
    minWidth: 0
  },
  title: {
    fontSize: fontSize.md,
    fontWeight: '500',
    lineHeight: fontSize.md * 1.3
  },
  subtitle: {
    fontSize: fontSize.sm,
    lineHeight: fontSize.sm * 1.3
  },
  disabled: {
    opacity: 0.5
  },
  pressed: {
    opacity: 0.6
  }
});
export const Item = /*#__PURE__*/memo(ItemComponent);
Item.displayName = 'Item';
//# sourceMappingURL=Item.js.map