"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Item = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _useInteractionState = require("../hooks/useInteractionState.js");
var _index = require("../typography/index.js");
var _tokens = require("../styles/tokens.js");
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); }
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 = (0, _useTheme.useTheme)();
  const {
    state: pressed,
    onIn: onPressIn,
    onOut: onPressOut
  } = (0, _useInteractionState.useInteractionState)();
  const titleColor = destructive ? theme.colors.error : theme.colors.text;
  const cfg = DENSITY[density];
  const containerStyle = (0, _react.useMemo)(() => {
    const base = {
      flexDirection: 'row',
      alignItems: 'center',
      gap: _tokens.space.md,
      paddingHorizontal: _tokens.space.lg,
      paddingVertical: cfg.paddingVertical,
      minHeight: cfg.minHeight,
      borderRadius: _tokens.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__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: styles.textColumn,
    children: [title != null ? typeof title === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Text, {
      numberOfLines: 1,
      style: [styles.title, {
        color: titleColor
      }, titleStyle],
      children: title
    }) : title : null, subtitle != null ? typeof subtitle === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Text, {
      numberOfLines: 2,
      style: [styles.subtitle, {
        color: theme.colors.textSecondary
      }, subtitleStyle],
      children: subtitle
    }) : subtitle : null]
  });
  const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: [containerStyle, style],
    testID: testID,
    children: [leading != null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.slot,
      children: leading
    }) : null, body, trailing != null ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.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__*/(0, _jsxRuntime.jsx)(_reactNative.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__*/(0, _jsxRuntime.jsx)(_reactNative.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 = _reactNative.StyleSheet.create({
  slot: {
    alignItems: 'center',
    justifyContent: 'center'
  },
  textColumn: {
    flex: 1,
    minWidth: 0
  },
  title: {
    fontSize: _tokens.fontSize.md,
    fontWeight: '500',
    lineHeight: _tokens.fontSize.md * 1.3
  },
  subtitle: {
    fontSize: _tokens.fontSize.sm,
    lineHeight: _tokens.fontSize.sm * 1.3
  },
  disabled: {
    opacity: 0.5
  },
  pressed: {
    opacity: 0.6
  }
});
const Item = exports.Item = /*#__PURE__*/(0, _react.memo)(ItemComponent);
Item.displayName = 'Item';
//# sourceMappingURL=Item.js.map