"use client"; import { Switch } from "@suphark/ui/components/ui/switch"; import { cn } from "@suphark/ui/lib/utils"; import { type ComponentProps, type ReactNode, useId } from "react"; /** * แถวตั้งค่า: ชื่อ + คำอธิบายด้านซ้าย, control ด้านขวา (จอแคบตกลงมาอยู่ใต้ข้อความ) * ใช้เป็นแถวในหน้าตั้งค่า/โซนอันตราย — ยกจาก Pi Auth/Pi PDF ที่เขียน layout เดียวกันซ้ำ */ export function SettingsRow({ title, description, children, htmlFor, tone = "default", className, }: { title: ReactNode; description?: ReactNode; /** control ด้านขวา (Switch, Button, Select …) */ children?: ReactNode; /** ผูกชื่อแถวกับ control ด้วย id (ทำให้คลิกชื่อแล้วโฟกัส control) */ htmlFor?: string; /** destructive = แถวในโซนอันตราย (ชื่อสีแดง) */ /** `danger` = `destructive`, `neutral` = `default` (ให้ตรงกับ StatusBadge) */ tone?: "default" | "destructive" | "danger" | "neutral"; className?: string; }) { const Title = htmlFor ? "label" : "span"; return (
{title} {description && {description}}
{children &&
{children}
}
); } /** * แถวตั้งค่าแบบเปิด/ปิด — `SettingsRow` + `Switch` ที่ผูก id ให้แล้ว (คลิกชื่อแล้วสลับได้) * * */ export function SwitchRow({ title, description, checked, onCheckedChange, disabled, id, className, ...props }: Omit, "title"> & { title: ReactNode; description?: ReactNode; className?: string; }) { const generatedId = useId(); const switchId = id ?? generatedId; return ( ); } /** * โซนอันตราย (Clerk/GitHub "Danger zone"): กรอบแดงอ่อน + แถวการกระทำที่ย้อนกลับไม่ได้ * แอปใส่ `SettingsRow tone="destructive"` เป็นลูก (ปุ่มจริงใช้ `ConfirmActionButton`/`useConfirm` ของแพ็กเกจ) * ประกาศ `data-surface="destructive"` → ปุ่ม `variant="destructive"` ในโซนใช้ตัวหนังสือสีเข้มกว่าให้ผ่าน AA (กฎใน styles.css) */ export function DangerZone({ title, description, children, className, }: { title?: ReactNode; description?: ReactNode; children: ReactNode; className?: string; }) { return (
{title &&

{title}

} {description &&

{description}

}
{children}
); }