/* * Copyright (C) Contributors to the Suwayomi project * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import type { ReactNode } from 'react'; import { useMemo } from 'react'; import Button from '@mui/material/Button'; import { useLingui } from '@lingui/react/macro'; import { CustomTooltip } from '@/base/components/CustomTooltip.tsx'; import { getNextRotationValue } from '@/base/utils/ValueRotationButton.utils.ts'; import { Superscript } from '@/base/components/texts/Superscript.tsx'; import type { ValueToDisplayData } from '@/base/Base.types.ts'; export interface ValueRotationButtonBaseProps { tooltip?: string; value: Value; defaultValue?: Value; values: Value[]; setValue: (value: Value) => void; valueToDisplayData: ValueToDisplayData; } export interface ValueRotationButtonDefaultableProps extends OptionalProperty< ValueRotationButtonBaseProps, 'value' > { isDefaultable?: boolean; onDefault?: () => void; } export type ValueRotationButtonProps = | (ValueRotationButtonBaseProps & PropertiesNever>) | ValueRotationButtonDefaultableProps; export const ValueRotationButton = ({ tooltip, value, defaultValue, values, setValue, valueToDisplayData, isDefaultable, onDefault, defaultIcon, }: ValueRotationButtonProps & { defaultIcon?: ReactNode }) => { const { t } = useLingui(); const isDefault = value === undefined; const indexOfValue = useMemo(() => { if (isDefault) { return -1; } return values.indexOf(value); }, [value, values]); return ( {isDefault ? ( ) : ( )} ); };