"use client"; import { useState } from "react"; import { Group, Loader, Select } from "@mantine/core"; import { useDebouncedValue } from "@mantine/hooks"; import { IconCheck } from "@tabler/icons-react"; import { translateIfNecessary } from "@homarr/translation"; import { useI18n } from "@homarr/translation/client"; import type { CommonWidgetInputProps } from "./common"; import { useWidgetInputTranslation } from "./common"; import { useFormContext } from "./form"; export interface DynamicSelectOption { value: string; label: string; } export const WidgetDynamicSelectInput = ({ property, kind, options }: CommonWidgetInputProps<"dynamicSelect">) => { const t = useI18n(); const tWidget = useWidgetInputTranslation(kind, property); const form = useFormContext(); const inputProps = form.getInputProps(`options.${property}`); const [search, setSearch] = useState(""); const [debouncedSearch] = useDebouncedValue(search, 300); const { isPending, options: selectOptions } = options.useOptions(debouncedSearch, form.values.integrationIds); const currentOption = inputProps.value as DynamicSelectOption | null; const onChange = inputProps.onChange as (value: DynamicSelectOption | null) => void; const getLabelForValue = (selectedValue: string) => { const matched = selectOptions.find((option) => typeof option === "string" ? option === selectedValue : option.value === selectedValue, ); if (!matched) { return selectedValue; } if (typeof matched === "string") { return matched; } return translateIfNecessary(t, matched.label) ?? selectedValue; }; return (