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