1import type { ServerSettings } from "@t3tools/contracts";
2import type { ComponentProps } from "react";
3
4import { Switch } from "../ui/switch";
5import { useScopedSettingsMixed } from "./useScopedSettings";
6
7/**
8 * A switch for a server setting that renders the mixed state when the
9 * selected targets disagree on `settingKeys`. Clicking a mixed switch turns
10 * it on everywhere, the macOS mixed-checkbox convention.
11 */
12export function ScopedSwitch({
13 settingKeys,
14 checked,
15 ...props
16}: ComponentProps<typeof Switch> & { settingKeys: readonly (keyof ServerSettings)[] }) {
17 const mixed = useScopedSettingsMixed(settingKeys);
18 return <Switch {...props} mixed={mixed} checked={mixed ? false : checked} />;
19}