import React from 'react' import {View} from 'react-native' import {LabelPreference, InterpretedLabelValueDefinition} from '@atproto/api' import {useLingui} from '@lingui/react' import {msg, Trans} from '@lingui/macro' import { usePreferencesQuery, usePreferencesSetContentLabelMutation, } from '#/state/queries/preferences' import {atoms as a, useTheme} from '#/alf' import {Text} from '#/components/Typography' import * as ToggleButton from '#/components/forms/ToggleButton' import {useGlobalLabelStrings} from '#/lib/moderation/useGlobalLabelStrings' export function ModerationOption({ labelValueDefinition, disabled, }: { labelValueDefinition: InterpretedLabelValueDefinition disabled?: boolean }) { const {_} = useLingui() const t = useTheme() const {data: preferences} = usePreferencesQuery() const {mutate, variables} = usePreferencesSetContentLabelMutation() const label = labelValueDefinition.identifier const visibility = variables?.visibility ?? preferences?.moderationPrefs.labels?.[label] const allLabelStrings = useGlobalLabelStrings() const labelStrings = labelValueDefinition.identifier in allLabelStrings ? allLabelStrings[labelValueDefinition.identifier] : { name: labelValueDefinition.identifier, description: `Labeled "${labelValueDefinition.identifier}"`, } const onChange = React.useCallback( (vis: string[]) => { mutate({ label, visibility: vis[0] as LabelPreference, labelerDid: undefined, }) }, [mutate, label], ) const labels = { hide: _(msg`Hide`), warn: _(msg`Warn`), show: _(msg`Show`), } return ( {labelStrings.name} {labelStrings.description} {disabled ? ( Hide ) : ( {labels.show} {labels.warn} {labels.hide} )} ) }