/** * External dependencies */ import clsx from 'clsx'; import { doesNetworkSupport, getNetworkLabel } from '@nelio-content/networks'; import type { SocialNetworkName } from '@nelio-content/types'; /** * Internal dependencies */ import { useAvailableProfiles, useSelectedProfiles } from '../../../hooks'; import { isUuid } from '@nelio-content/utils'; export type SocialNetworkProps = { readonly disabled?: boolean; readonly isActive: boolean; readonly isSelected: boolean; readonly network: SocialNetworkName; readonly onSelect: () => void; }; export const SocialNetwork = ( { disabled, isActive, isSelected, network, onSelect, }: SocialNetworkProps ): JSX.Element => { const availableProfiles = useAvailableProfiles(); const [ profileIds, toggleProfile ] = useSelectedProfiles(); const isMultiTarget = doesNetworkSupport( 'multi-target', network ); const selectedProfiles = profileIds.filter( isUuid ); const profilesOfNetwork = availableProfiles.filter( ( profile ) => profile.network === network ); const toggleAllProfiles = () => { if ( isMultiTarget ) { return; } const selectedProfilesOfNetwork = profilesOfNetwork.filter( ( p ) => selectedProfiles.includes( p.id ) ); const areAllProfilesSelected = selectedProfilesOfNetwork.length === profilesOfNetwork.length; if ( areAllProfilesSelected ) { profilesOfNetwork.forEach( ( p ) => toggleProfile( p.id ) ); } else { profilesOfNetwork.forEach( ( p ) => selectedProfiles.includes( p.id ) || toggleProfile( p.id ) ); } //end }; return (