/** * WordPress dependencies */ import { Tooltip } from '@safe-wordpress/components'; import { useDispatch } from '@safe-wordpress/data'; /** * External dependencies */ import clsx from 'clsx'; import { SocialProfileIcon } from '@nelio-content/components'; import { useSocialProfile } from '@nelio-content/data'; import { doesNetworkSupport, getTargetLabel } from '@nelio-content/networks'; import { isAutoSelectedUuid, isUuid } from '@nelio-content/utils'; import type { Uuid } from '@nelio-content/types'; /** * Internal dependencies */ import { store as NC_SOCIAL_EDITOR } from '../../../store'; import { useSelectedProfiles, useSelectedTargetsInProfile, } from '../../../hooks'; export type SocialProfileProps = { readonly disabled?: boolean; readonly profileId: Uuid; }; export const SocialProfile = ( { disabled, profileId, }: SocialProfileProps ): JSX.Element => { const profile = useSocialProfile( profileId ); const [ profileIds, toggleProfile ] = useSelectedProfiles(); const selectedTargets = useSelectedTargetsInProfile( profileId ); const { openTargetSelector } = useDispatch( NC_SOCIAL_EDITOR ); const selectedProfiles = profileIds.filter( isUuid ); const numberOfSelectedTargets = selectedTargets.length; const hasSelectedTargets = !! numberOfSelectedTargets; const isAutoSelected = isAutoSelectedUuid( profileIds[ 0 ] ); const isPulsing = ! isAutoSelected && ! selectedProfiles.length; const isSelected = selectedProfiles.includes( profileId ) || hasSelectedTargets; const { alias, displayName = '', network } = profile || {}; const isMultiTarget = doesNetworkSupport( 'multi-target', network ); return (
  • { `${ alias ?? displayName }: ` } { !! isMultiTarget ? ( openTargetSelector( profileId ) } /> ) : ( toggleProfile( profileId ) } /> ) }
  • ); };