import type { ChangeEvent, ReactNode } from 'react'; import { getPlatformPillBadgeClassName } from './platformPillBadgeModel'; export type PlatformToggleRowSurface = 'soft' | 'plain'; export type PlatformToggleRowMode = 'checkbox' | 'status'; export type PlatformToggleRowProps = { label: ReactNode; checked: boolean; onChange?: (checked: boolean) => void; disabled?: boolean; mode?: PlatformToggleRowMode; icon?: ReactNode; onLabel?: ReactNode; offLabel?: ReactNode; onClick?: () => void; className?: string; labelClassName?: string; surface?: PlatformToggleRowSurface; }; const PLATFORM_TOGGLE_ROW_SURFACE_CLASS: Record< PlatformToggleRowSurface, string > = { soft: 'bg-white/74', plain: 'bg-white/78', }; function renderToggleStatus({ checked, offLabel, onLabel, }: { checked: boolean; offLabel: ReactNode; onLabel: ReactNode; }) { return ( {checked ? onLabel : offLabel} ); } /** * 平台整行开关。 * 统一承接设置面板和结果页配置里的白底 label + checkbox / 状态行。 */ export function PlatformToggleRow({ label, checked, onChange, disabled = false, mode = 'checkbox', icon, onLabel = '开启', offLabel = '关闭', onClick, className, labelClassName, surface = 'soft', }: PlatformToggleRowProps) { const handleChange = (event: ChangeEvent) => { onChange?.(event.target.checked); }; const rowClassName = [ 'flex min-h-12 items-center justify-between gap-3 rounded-[1rem] border border-[var(--platform-subpanel-border)] px-3', PLATFORM_TOGGLE_ROW_SURFACE_CLASS[surface], disabled ? 'opacity-60' : null, className, ] .filter(Boolean) .join(' '); const labelNode = ( {icon ? {icon} : null} {label} ); if (mode === 'status') { if (onClick) { return ( ); } return (
{labelNode} {renderToggleStatus({ checked, onLabel, offLabel })}
); } return ( ); }