/* * External dependencies */ import { MenuItem, MenuGroup, ToolbarDropdownMenu } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { title, postContent, postExcerpt, termDescription, post, pencil } from '@wordpress/icons'; import React from 'react'; type PromptTemplatesControlProps = { hasContentBefore: boolean; hasContent: boolean; hasPostTitle: boolean; contentIsLoaded: boolean; onPromptSelect: ( prompt: { original: string; translated: string } ) => void; onSuggestionSelect: ( suggestion: string ) => void; }; type PromptTemplateProps = { description: { original: string; translated: string; }; label: string; }; export const defaultPromptTemplate = { label: __( 'Post about…', 'jetpack' ), description: { original: 'Write a post about ', translated: __( 'Write a post about ', 'jetpack' ), }, }; export const promptTemplates = [ defaultPromptTemplate, { label: __( 'Informative article on…', 'jetpack' ), description: { original: 'Craft an informative article explaining ', translated: __( 'Craft an informative article explaining ', 'jetpack' ), }, }, { label: __( 'Step-by-step tutorial on…', 'jetpack' ), description: { original: 'Write a step-by-step tutorial on ', translated: __( 'Write a step-by-step tutorial on ', 'jetpack' ), }, }, { label: __( 'Motivational post on…', 'jetpack' ), description: { original: 'Create a motivational post on ', translated: __( 'Create a motivational post on ', 'jetpack' ), }, }, ]; export const promptTemplatesForGeneratedContent = [ { label: __( 'Say it differently…', 'jetpack' ), description: { original: 'Rewrite it in a way that ', translated: __( 'Rewrite it in a way that ', 'jetpack' ), }, }, { label: __( 'Add…', 'jetpack' ), description: { original: 'Add more details about ', translated: __( 'Add more details about ', 'jetpack' ), }, }, { label: __( 'Remove…', 'jetpack' ), description: { original: 'Remove unnecessary details about ', translated: __( 'Remove unnecessary details about ', 'jetpack' ), }, }, ]; export default function PromptTemplatesControl( { hasContentBefore, hasContent, hasPostTitle, contentIsLoaded, onPromptSelect, onSuggestionSelect, }: PromptTemplatesControlProps ) { const label = __( 'Write with AI…', 'jetpack' ); return ( { ( { onClose } ) => { return contentIsLoaded ? ( { promptTemplatesForGeneratedContent.map( ( prompt: PromptTemplateProps, i: number ) => ( { onClose(); onPromptSelect( prompt.description ); } } > { prompt.label } ) ) } ) : ( <> { hasContentBefore && ( onSuggestionSelect( 'continue' ) } > { __( 'Continue writing', 'jetpack' ) } onSuggestionSelect( 'correctSpelling' ) } > { __( 'Correct spelling and grammar', 'jetpack' ) } onSuggestionSelect( 'simplify' ) } > { __( 'Simplify', 'jetpack' ) } ) } { hasContent && ( { hasContent && ( onSuggestionSelect( 'summarize' ) } > { __( 'Summarize', 'jetpack' ) } ) } { hasContent && ( onSuggestionSelect( 'generateTitle' ) } > { __( 'Generate a post title', 'jetpack' ) } ) } ) } { hasPostTitle && ( onSuggestionSelect( 'titleSummary' ) } > { __( 'Summary based on title', 'jetpack' ) } ) } { promptTemplates.map( ( prompt: PromptTemplateProps, i: number ) => ( { onClose(); onPromptSelect( prompt.description ); } } > { prompt.label } ) ) } ); } } ); }