import React from 'react' import {View} from 'react-native' import {InterpretedLabelValueDefinition, LabelPreference} from '@atproto/api' import {useLingui} from '@lingui/react' import {msg, Trans} from '@lingui/macro' import {useGlobalLabelStrings} from '#/lib/moderation/useGlobalLabelStrings' import {useLabelBehaviorDescription} from '#/lib/moderation/useLabelBehaviorDescription' import { usePreferencesQuery, usePreferencesSetContentLabelMutation, } from '#/state/queries/preferences' import {getLabelStrings} from '#/lib/moderation/useLabelInfo' import {useTheme, atoms as a, useBreakpoints} from '#/alf' import {Text} from '#/components/Typography' import {InlineLink} from '#/components/Link' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '../icons/CircleInfo' import * as ToggleButton from '#/components/forms/ToggleButton' export function ModerationLabelPref({ labelValueDefinition, labelerDid, disabled, }: { labelValueDefinition: InterpretedLabelValueDefinition labelerDid: string | undefined disabled?: boolean }) { const {_, i18n} = useLingui() const t = useTheme() const {gtPhone} = useBreakpoints() const isGlobalLabel = !labelValueDefinition.definedBy const {identifier} = labelValueDefinition const {data: preferences} = usePreferencesQuery() const {mutate, variables} = usePreferencesSetContentLabelMutation() const savedPref = labelerDid && !isGlobalLabel ? preferences?.moderationPrefs.labelers.find(l => l.did === labelerDid) ?.labels[identifier] : preferences?.moderationPrefs.labels[identifier] const pref = variables?.visibility ?? savedPref ?? labelValueDefinition.defaultSetting ?? 'warn' // does the 'warn' setting make sense for this label? const canWarn = !( labelValueDefinition.blurs === 'none' && labelValueDefinition.severity === 'none' ) // is this label adult only? const adultOnly = labelValueDefinition.flags.includes('adult') // is this label disabled because it's adult only? const adultDisabled = adultOnly && !preferences?.moderationPrefs.adultContentEnabled // are there any reasons we cant configure this label here? const cantConfigure = isGlobalLabel || adultDisabled const showConfig = !disabled && (gtPhone || !cantConfigure) // adjust the pref based on whether warn is available let prefAdjusted = pref if (adultDisabled) { prefAdjusted = 'hide' } else if (!canWarn && pref === 'warn') { prefAdjusted = 'ignore' } // grab localized descriptions of the label and its settings const currentPrefLabel = useLabelBehaviorDescription( labelValueDefinition, prefAdjusted, ) const hideLabel = useLabelBehaviorDescription(labelValueDefinition, 'hide') const warnLabel = useLabelBehaviorDescription(labelValueDefinition, 'warn') const ignoreLabel = useLabelBehaviorDescription( labelValueDefinition, 'ignore', ) const globalLabelStrings = useGlobalLabelStrings() const labelStrings = getLabelStrings( i18n.locale, globalLabelStrings, labelValueDefinition, ) return ( {labelStrings.name} {labelStrings.description} {cantConfigure && ( {adultDisabled ? ( Adult content is disabled. ) : isGlobalLabel ? ( Configured in{' '} moderation settings . ) : null} )} {showConfig && ( {cantConfigure ? ( {currentPrefLabel} ) : ( mutate({ label: identifier, visibility: newPref[0] as LabelPreference, labelerDid, }) }> {ignoreLabel} {canWarn && ( {warnLabel} )} {hideLabel} )} )} ) }