import { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiArrowDownSLine, RiCheckLine, } from '@remixicon/react' import { AUTO_UPDATE_STRATEGY } from './types' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import Button from '@/app/components/base/button' const i18nPrefix = 'plugin.autoUpdate.strategy' type Props = { value: AUTO_UPDATE_STRATEGY onChange: (value: AUTO_UPDATE_STRATEGY) => void } const StrategyPicker = ({ value, onChange, }: Props) => { const { t } = useTranslation() const [open, setOpen] = useState(false) const options = [ { value: AUTO_UPDATE_STRATEGY.disabled, label: t(`${i18nPrefix}.disabled.name`), description: t(`${i18nPrefix}.disabled.description`), }, { value: AUTO_UPDATE_STRATEGY.fixOnly, label: t(`${i18nPrefix}.fixOnly.name`), description: t(`${i18nPrefix}.fixOnly.description`), }, { value: AUTO_UPDATE_STRATEGY.latest, label: t(`${i18nPrefix}.latest.name`), description: t(`${i18nPrefix}.latest.description`), }, ] const selectedOption = options.find(option => option.value === value) return ( { e.stopPropagation() e.nativeEvent.stopImmediatePropagation() setOpen(v => !v) }}>
{ options.map(option => (
{ e.stopPropagation() e.nativeEvent.stopImmediatePropagation() onChange(option.value) setOpen(false) }} >
{ value === option.value && ( ) }
{option.label}
{option.description}
)) }
) } export default StrategyPicker