/* eslint-disable wpcalypso/jsx-classname-namespace */ import { recordTracksEvent } from '@automattic/calypso-analytics'; import { LoadingPlaceholder } from '@automattic/components'; import { HelpCenterSelect } from '@automattic/data-stores'; import styled from '@emotion/styled'; import { Button, ExternalLink } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { createElement, createInterpolateElement } from '@wordpress/element'; import { sprintf } from '@wordpress/i18n'; import { useI18n } from '@wordpress/react-i18n'; import React, { useEffect, useMemo, useState } from 'react'; import stripTags from 'striptags'; import { useJetpackSearchAIQuery } from '../data/use-jetpack-search-ai'; import { useTyper } from '../hooks'; import { HELP_CENTER_STORE } from '../stores'; import HelpCenterSearchResults from './help-center-search-results'; import type { JetpackSearchAIResult } from '../data/use-jetpack-search-ai'; import type { SearchResult } from '../types'; import './help-center-gpt.scss'; const GPTResponsePlaceholder = styled( LoadingPlaceholder )< { width?: string } >` :not( :last-child ) { margin-block-end: 0.5rem; } width: ${ ( { width = '100%' } ) => width }; `; const GPTResponseDisclaimer = styled.div` color: var( --studio-gray-50 ); font-size: 11px; text-align: right; @media ( min-width: 600px ) { padding: 0 0 15px; } `; interface LoadingPlaceholderProps { loadingMessage: string; } const LoadingPlaceholders: React.FC< LoadingPlaceholderProps > = ( { loadingMessage } ) => ( <>
{ loadingMessage }
{ __( 'Our system is currently generating a possible solution for you, which typically takes about 30 seconds.', __i18n_text_domain__ ) }
{ createInterpolateElement( sprintf( /* translators: the cancelButtonLabel is the already translated "Cancel" button label */ __( 'We know your time is valuable. If you prefer not to wait, you can click the %(cancelButtonLabel)s button below to go back and submit your message right away.' ), { cancelButtonLabel: __( 'Cancel', __i18n_text_domain__ ) } ), { em: createElement( 'em' ), } ) }
> ) } { ! data?.response && LoadingPlaceholders( { loadingMessage } ) } { data?.response && ( <> { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events */ }{ createInterpolateElement( __( 'Need more help? Click the button below to send your message. For reference, here is what you wrote:', __i18n_text_domain__ ), { strong: createElement( 'strong' ), } ) }
{ line }
) ) }