import { ChevronDownIcon, DatabaseIcon } from "lucide-react" import { useTranslation } from "react-i18next" import { toast } from "sonner" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { providerStoreActions } from "@/store" export interface UploaderSwitcherConfigItem { id: string name: string } export interface UploaderSwitcherProviderItem { id: string name: string configs: UploaderSwitcherConfigItem[] } export interface UploaderSwitcherValue { providerId: string providerName: string configId: string configName: string } interface UploaderSwitcherProps { current: UploaderSwitcherValue providers: UploaderSwitcherProviderItem[] disabled?: boolean } export function UploaderSwitcher({ current, providers, disabled, }: UploaderSwitcherProps) { const { t } = useTranslation() const handleSelect = async (providerId: string, configId?: string) => { try { await providerStoreActions.selectDashboardProviderConfig( providerId, configId ) } catch (error) { const message = error instanceof Error && error.message.trim().length > 0 ? error.message : t("OPERATION_FAILED") toast.error(message) } } return ( {t("UPLOADER_SWITCHER_SELECT_PROVIDER")} {providers.map((provider) => provider.configs.length <= 1 ? ( { await handleSelect( provider.id, provider.configs[0]?.id ) }} > {provider.name} ) : ( {provider.name} {t("UPLOADER_SWITCHER_CONFIG")} {provider.configs.map((config) => ( { await handleSelect(provider.id, config.id) }} > {config.name} ))} ) )} ) }