__vite_ssr_exportName__("splitPath", () => { try { return splitPath } catch {} });
__vite_ssr_exportName__("savedValue", () => { try { return savedValue } catch {} });
__vite_ssr_exportName__("currentValue", () => { try { return currentValue } catch {} });
__vite_ssr_exportName__("sameValue", () => { try { return sameValue } catch {} });
__vite_ssr_exportName__("toPatch", () => { try { return toPatch } catch {} });
__vite_ssr_exportName__("presetOf", () => { try { return presetOf } catch {} });
function splitPath(path) {
	const dot = path.indexOf(".");
	return [path.slice(0, dot), path.slice(dot + 1)];
};
function savedValue(values, path) {
	const [section, name] = splitPath(path);
	return values[section]?.[name];
};
function currentValue(values, draft, path) {
	return path in draft ? draft[path] : savedValue(values, path);
};
function sameValue(a, b) {
	return JSON.stringify(a) === JSON.stringify(b);
};
/** `{section: {field: value}}`, the shape PATCH /settings and the tools take. */
function toPatch(draft) {
	const patch = {};
	for (const [path, value] of Object.entries(draft)) {
		const [section, name] = splitPath(path);
		patch[section] = {
			...patch[section],
			[name]: value
		};
	};
	return patch;
};
/** The preset whose knobs the (edited) detection values have, else "custom" (mirrors the server). */
function presetOf(values, draft, presets) {
	const match = presets.find((preset) => Object.entries(preset.values).every(([name, value]) => currentValue(values, draft, `detection.${name}`) === value));
	return match?.name ?? "custom";
}

//# vitestCache=W3siZmlsZSI6IjEiLCJpZCI6IjEiLCJpbXBvcnRzIjoiMiIsIm1hcHBpbmdzIjpmYWxzZSwiZGVwcyI6IjMiLCJkeW5hbWljRGVwcyI6IjQiLCJzdGF0aWNNb2NrcyI6bnVsbCwiaGFzQ292ZXJhZ2VEYXRhIjpmYWxzZX0sIkQ6L0dpdEh1Yi9WaWNlQ3V0L3dlYi9zcmMvZW50aXRpZXMvc2V0dGluZ3MvbW9kZWwudHMiLHsidXJscyI6IjUiLCJpZHMiOiI2In0sW10sW10sW10se31d
//# vitestSourceMap={"version":3,"mappings":"AAAA,CAAA;;;;;;AASO,SAAS,UAAU,MAAgC;CACxD,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,OAAO,CAAC,KAAK,MAAM,GAAG,GAAG,GAAG,KAAK,MAAM,MAAM,CAAC,CAAC;AACjD;AAEO,SAAS,WAAW,QAAwB,MAAuB;CACxE,MAAM,CAAC,SAAS,QAAQ,UAAU,IAAI;CACtC,OAAO,OAAO,QAAQ,GAAG;AAC3B;AAEO,SAAS,aAAa,QAAwB,OAAc,MAAuB;CACxF,OAAO,QAAQ,QAAQ,MAAM,QAAQ,WAAW,QAAQ,IAAI;AAC9D;AAEO,SAAS,UAAU,GAAY,GAAqB;CACzD,OAAO,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AAC/C;;AAGO,SAAS,QAAQ,OAAuD;CAC7E,MAAM,QAAiD,CAAC;CACxD,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,GAAG;EACjD,MAAM,CAAC,SAAS,QAAQ,UAAU,IAAI;EACtC,MAAM,WAAW;GAAE,GAAG,MAAM;IAAW,OAAO;EAAM;CACtD;CACA,OAAO;AACT;;AAGO,SAAS,SAAS,QAAwB,OAAc,SAAoC;CACjG,MAAM,QAAQ,QAAQ,MAAM,WAC1B,OAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,WAAW,aAAa,QAAQ,OAAO,aAAa,MAAM,MAAM,KAAK,CACnH;CACA,OAAO,OAAO,QAAQ;AACxB","names":[],"ignoreList":[],"sources":["model.ts"],"sourcesContent":["import type { Schemas } from \"@/shared/api\";\n\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\nexport type SettingsValues = Schemas[\"SettingsOut\"][\"values\"];\nexport type FieldSpec = Schemas[\"FieldOut\"];\nexport type Preset = Schemas[\"PresetOut\"];\n/** Unsaved values by field path (`section.field`); only fields that differ from the server. */\nexport type Draft = Readonly<Record<string, unknown>>;\n\nexport function splitPath(path: string): [string, string] {\n  const dot = path.indexOf(\".\");\n  return [path.slice(0, dot), path.slice(dot + 1)];\n}\n\nexport function savedValue(values: SettingsValues, path: string): unknown {\n  const [section, name] = splitPath(path);\n  return values[section]?.[name];\n}\n\nexport function currentValue(values: SettingsValues, draft: Draft, path: string): unknown {\n  return path in draft ? draft[path] : savedValue(values, path);\n}\n\nexport function sameValue(a: unknown, b: unknown): boolean {\n  return JSON.stringify(a) === JSON.stringify(b);\n}\n\n/** `{section: {field: value}}`, the shape PATCH /settings and the tools take. */\nexport function toPatch(draft: Draft): Record<string, Record<string, unknown>> {\n  const patch: Record<string, Record<string, unknown>> = {};\n  for (const [path, value] of Object.entries(draft)) {\n    const [section, name] = splitPath(path);\n    patch[section] = { ...patch[section], [name]: value };\n  }\n  return patch;\n}\n\n/** The preset whose knobs the (edited) detection values have, else \"custom\" (mirrors the server). */\nexport function presetOf(values: SettingsValues, draft: Draft, presets: readonly Preset[]): string {\n  const match = presets.find((preset) =>\n    Object.entries(preset.values).every(([name, value]) => currentValue(values, draft, `detection.${name}`) === value),\n  );\n  return match?.name ?? \"custom\";\n}\n"],"file":"/web/src/entities/settings/model.ts"}