import React from "react";
import { Pressable, Switch, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { useColorScheme } from "nativewind";
import { cn } from "../utils/cn";
import { MutedText, Text } from "./text";
export interface SettingsRowProps {
icon: keyof typeof Ionicons.glyphMap;
label: string;
subtitle?: string;
onPress?: () => void;
showChevron?: boolean;
toggle?: boolean;
value?: boolean;
onValueChange?: (value: boolean) => void;
destructive?: boolean;
}
/**
* Horizontal row used inside settings dialogs / panels. Combines an icon
* tile, label + optional subtitle, and a trailing switch *or* chevron.
* `destructive` recolors the label + icon to the destructive token.
*/
export function SettingsRow({
icon,
label,
subtitle,
onPress,
showChevron,
toggle,
value,
onValueChange,
destructive,
}: SettingsRowProps) {
const { colorScheme } = useColorScheme();
const isDark = colorScheme === "dark";
const Wrapper = onPress ? Pressable : View;
// Toggle-mode rows tap-to-switch and also surface the switch
// itself — both surfaces need the label as their accessible name
// so a screen reader doesn't announce "Switch, on" with no
// context. The Switch carries `accessibilityState` so AT can
// announce the on/off state.
const wrapperProps = onPress
? ({
onPress,
accessibilityRole: "button" as const,
accessibilityLabel: label,
...(subtitle ? { accessibilityHint: subtitle } : {}),
} as const)
: {};
let iconColor: string;
if (destructive) {
iconColor = "#EF4444";
} else if (isDark) {
iconColor = "#FFFFFF";
} else {
iconColor = "#000000";
}
return (
{label}
{subtitle ? {subtitle} : null}
{toggle ? (
) : null}
{showChevron ? (
) : null}
);
}
export interface SettingsSectionProps {
title: string;
destructive?: boolean;
children: React.ReactNode;
}
/** Group container for `SettingsRow`s. Renders the section title + a
* bordered card around its children. */
export function SettingsSection({ title, destructive, children }: SettingsSectionProps) {
return (
{title}
{children}
);
}