"use client" import { ChevronDownIcon } from "lucide-react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { useI18n } from "@/i18n/provider" import { CONTENT_MODE_OPTIONS, type ContentMode, } from "./types" type EditorModeSwitchProps = { value: ContentMode allowedModes?: ReadonlyArray disabled?: boolean onChange: (nextMode: ContentMode) => void } export function EditorModeSwitch({ value, allowedModes = CONTENT_MODE_OPTIONS, disabled = false, onChange, }: EditorModeSwitchProps) { const t = useI18n() const MODE_OPTIONS: Array<{ value: ContentMode; label: string }> = [ { value: "markdown", label: t("editor.modeLabelMarkdown") }, { value: "html", label: t("editor.modeLabelRichText") }, ] const options = MODE_OPTIONS.filter((option) => allowedModes.includes(option.value)) const activeLabel = options.find((option) => option.value === value)?.label ?? value if (options.length <= 1) { return null } return ( } disabled={disabled} aria-label={t("editor.modeSwitchLabel")} > {activeLabel} { if (nextMode !== value) { onChange(nextMode as ContentMode) } }} > {options.map((option) => ( {option.label} ))} ) }