/**
 * Thank with Google SetupPublicationActionRequired component.
 *
 * Site Kit by Google, Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { __ } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { MODULES_THANK_WITH_GOOGLE } from '../../datastore/constants';
import Button from '../../../../components/Button';
import SetupPublicationScreen from './SetupPublicationScreen';
const { useSelect } = Data;

export default function SetupPublicationActionRequired() {
	const currentPublication = useSelect( ( select ) =>
		select( MODULES_THANK_WITH_GOOGLE ).getCurrentPublication()
	);
	const currentPublicationURL = useSelect( ( select ) =>
		select( MODULES_THANK_WITH_GOOGLE ).getServicePublicationURL(
			// eslint-disable-next-line sitekit/acronym-case
			currentPublication.publicationId
		)
	);

	return (
		<SetupPublicationScreen
			title={ __( 'Complete your account setup', 'google-site-kit' ) }
			description={ __(
				'Finish the setup to customize and add Thank with Google on your site.',
				'google-site-kit'
			) }
		>
			<Button
				href={ currentPublicationURL }
				target="_blank"
				aria-label={ __(
					'Complete your Thank with Google account setup',
					'google-site-kit'
				) }
			>
				{ __( 'Complete setup', 'google-site-kit' ) }
			</Button>
		</SetupPublicationScreen>
	);
}

/**
 * Thank with Google SetupPublicationActionRequired component.
 *
 * Site Kit by Google, Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { __ } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { MODULES_THANK_WITH_GOOGLE } from '../../datastore/constants';
import Button from '../../../../components/Button';
import SetupPublicationScreen from './SetupPublicationScreen';
import { trackEvent } from '../../../../util';
import useViewContext from '../../../../hooks/useViewContext';
const { useSelect } = Data;

export default function SetupPublicationActionRequired() {
	const currentPublication = useSelect( ( select ) =>
		select( MODULES_THANK_WITH_GOOGLE ).getCurrentPublication()
	);
	const currentPublicationURL = useSelect( ( select ) =>
		select( MODULES_THANK_WITH_GOOGLE ).getServicePublicationURL(
			// eslint-disable-next-line sitekit/acronym-case
			currentPublication.publicationId
		)
	);

	const viewContext = useViewContext();

	const onCompleteSetup = useCallback( async () => {
		await trackEvent(
			`${ viewContext }_thank-with-google`,
			'complete_publication_setup'
		);
	}, [ viewContext ] );

	return (
		<SetupPublicationScreen
			title={ __( 'Complete your account setup', 'google-site-kit' ) }
			description={ __(
				'Finish the setup to customize and add Thank with Google on your site.',
				'google-site-kit'
			) }
		>
			<Button
				href={ currentPublicationURL }
				onClick={ onCompleteSetup }
				target="_blank"
				aria-label={ __(
					'Complete your Thank with Google account setup',
					'google-site-kit'
				) }
			>
				{ __( 'Complete setup', 'google-site-kit' ) }
			</Button>
		</SetupPublicationScreen>
	);
}

Add TwG `complete_publication_setup` GA event.