import { ExternalLink } from '@automattic/components';
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import { filter, find } from 'lodash';
import { createRef, Component } from 'react';
import titleCase from 'to-title-case';
import SectionNav from 'calypso/components/section-nav';
import NavItem from 'calypso/components/section-nav/item';
import NavTabs from 'calypso/components/section-nav/tabs';
import { gaRecordEvent } from 'calypso/lib/analytics/ga';
import safeProtocolUrl from 'calypso/lib/safe-protocol-url';
import { PluginFeaturedVideo } from '../plugin-featured-video';
import './style.scss';
class PluginSections extends Component {
static displayName = 'PluginSections';
constructor( props ) {
super( props );
this.descriptionContent = createRef();
}
state = {
selectedSection: false,
descriptionHeight: 0,
};
_COLLAPSED_DESCRIPTION_HEIGHT = 140;
recordEvent = ( eventAction ) => {
gaRecordEvent( 'Plugins', eventAction, 'Plugin Name', this.props.plugin.slug );
};
componentDidMount() {
this.calculateDescriptionHeight();
}
componentDidUpdate() {
this.calculateDescriptionHeight();
}
calculateDescriptionHeight() {
if ( this.descriptionContent ) {
const node = this.descriptionContent.current;
if ( node && node.offsetHeight && node.offsetHeight !== this.state.descriptionHeight ) {
this.setState( { descriptionHeight: node.offsetHeight } );
}
}
}
getFilteredSections = () => {
if ( this.props.isWpcom ) {
return this.getWpcomFilteredSections();
}
return [
{
key: 'description',
title: this.props.translate( 'Description', {
context: 'Navigation item',
textOnly: true,
} ),
},
{
key: 'installation',
title: this.props.translate( 'Installation', {
context: 'Navigation item',
textOnly: true,
} ),
},
{
key: 'changelog',
title: this.props.translate( 'Changelog', {
context: 'Navigation item',
textOnly: true,
} ),
},
{
key: 'faq',
title: this.props.translate( 'FAQs', {
context: 'Navigation item',
textOnly: true,
} ),
},
{
key: 'other_notes',
title: this.props.translate( 'Other Notes', {
context: 'Navigation item',
textOnly: true,
} ),
},
];
};
getWpcomFilteredSections = () => {
return [
{
key: 'description',
title: this.props.translate( 'Description', {
context: 'Navigation item',
textOnly: true,
} ),
},
{
key: 'faq',
title: this.props.translate( 'FAQs', {
context: 'Navigation item',
textOnly: true,
} ),
},
];
};
getWpcomSupportContent = () => {
const supportedAuthors = [ 'Automattic', 'WooCommerce' ];
const { translate, plugin } = this.props;
if ( supportedAuthors.indexOf( plugin.author_name ) > -1 ) {
return;
}
const linkToAuthor = (
{ translate( 'Support for this plugin is provided by the plugin author. You may find additional documentation here:' ) }