"use client"; import { Group, Select } from "@mantine/core"; import { IconCheck } from "@tabler/icons-react"; import { translateIfNecessary } from "@homarr/translation"; import type { stringOrTranslation } from "@homarr/translation"; import { useI18n } from "@homarr/translation/client"; import type { TablerIcon } from "@homarr/ui"; import type { CommonWidgetInputProps } from "./common"; import { useWidgetInputTranslation } from "./common"; import { useFormContext } from "./form"; export type SelectOption = | { icon?: TablerIcon; value: string; label: stringOrTranslation; } | string; export type inferSelectOptionValue = TOption extends { value: infer TValue; } ? TValue : TOption; const getIconFor = (options: SelectOption[], value: string) => { const current = options.find((option) => (typeof option === "string" ? option : option.value) === value); if (!current) return null; if (typeof current === "string") return null; return current.icon; }; export const WidgetSelectInput = ({ property, kind, options }: CommonWidgetInputProps<"select">) => { const t = useI18n(); const tWidget = useWidgetInputTranslation(kind, property); const form = useFormContext(); const inputProps = form.getInputProps(`options.${property}`); const CurrentIcon = getIconFor(options.options, inputProps.value as string); return (