/**
* WordPress dependencies
*/
import { Button } from '@safe-wordpress/components';
import { useDispatch } from '@safe-wordpress/data';
import { _x, sprintf } from '@safe-wordpress/i18n';
import { MediaUpload } from '@safe-wordpress/media-utils';
/**
* External dependencies
*/
import { isArray } from 'lodash';
import { store as NC_DATA } from '@nelio-content/data';
import type { MediaUploadItem } from '@nelio-content/types';
import {
getNetworkLabel,
getSupportedVideoTypes,
} from '@nelio-content/networks';
/**
* Internal dependencies
*/
import { store as NC_SOCIAL_EDITOR } from '../../store';
import {
useActiveNetworkType,
useActiveSocialNetwork,
useDoesActiveNetworkSupport,
useHasExplicitVideo,
} from '../../hooks';
export type VideoToggleProps = {
readonly disabled?: boolean;
};
export const VideoToggle = ( {
disabled,
}: VideoToggleProps ): JSX.Element | null => {
const supportsVideo = useDoesActiveNetworkSupport( 'video' );
const supportsMultiMedia = useDoesActiveNetworkSupport( 'multi-media' );
const type = useActiveNetworkType();
const activeNetwork = useActiveSocialNetwork();
const hasExplicitVideo = useHasExplicitVideo();
const { setVideos } = useDispatch( NC_SOCIAL_EDITOR );
const { receiveMediaUploadItem } = useDispatch( NC_DATA );
if ( ! supportsVideo ) {
return null;
}
if ( [ 'video', 'multi-media' ].includes( type ) ) {
return ;
}
if ( hasExplicitVideo ) {
return ;
}
return (
) => {
video = isArray( video ) ? video : [ video ];
video.forEach( ( v ) => {
void receiveMediaUploadItem( v );
} );
void setVideos(
activeNetwork,
video.map( ( v ) => v.id ),
video.map( ( v ) => v.url ),
video.map( ( v ) => v.alt )
);
} }
render={ ( { open }: { open: () => void } ) => (
) }
/>
);
};
// ============
// HELPER VIEWS
// ============
const RemoveVideo = ( { disabled }: { disabled?: boolean } ): JSX.Element => {
const { removeVideo } = useDispatch( NC_SOCIAL_EDITOR );
return (
);
};
const AddVideo = ( {
label,
disabled,
onClick,
}: {
label?: string;
disabled?: boolean;
onClick: () => void;
} ) => {
return (
);
};
const UseExistingVideo = ( { disabled }: { disabled?: boolean } ) => {
const network = useActiveSocialNetwork();
const { switchMessageType } = useDispatch( NC_SOCIAL_EDITOR );
return (