import { Button, ScreenReaderText, Gridicon } from '@automattic/components';
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import { find, includes } from 'lodash';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import PopoverMenu from 'calypso/components/popover-menu';
import PopoverMenuItem from 'calypso/components/popover-menu/item';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { canCurrentUser } from 'calypso/state/selectors/can-current-user';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import GooglePhotosIcon from './google-photos-icon';
import OpenverseIcon from './openverse-icon';
import PexelsIcon from './pexels-icon';
export class MediaLibraryDataSource extends Component {
static propTypes = {
source: PropTypes.string.isRequired,
onSourceChange: PropTypes.func.isRequired,
disabledSources: PropTypes.array,
ignorePermissions: PropTypes.bool,
};
static defaultProps = {
disabledSources: [],
ignorePermissions: false,
};
state = { popover: false };
storeButtonRef = ( ref ) => ( this.buttonRef = ref );
togglePopover = () => {
const nextValue = ! this.state.popover;
this.setState( { popover: nextValue } );
recordTracksEvent( 'calypso_media_data_source_toggle', { expanded: nextValue } );
};
changeSource = ( newSource ) => () => {
if ( newSource !== this.props.source ) {
this.props.onSourceChange( newSource );
recordTracksEvent( 'calypso_media_data_source_change', {
old_source: this.props.source,
new_source: newSource,
} );
}
};
getSources = () => {
const { disabledSources, translate, ignorePermissions, canUserUploadFiles } = this.props;
const includeExternalMedia = ignorePermissions || canUserUploadFiles;
const sources = [
{
value: '',
label: translate( 'Media library' ),
icon: