/**
 * Activate a plugin
 *
 * @return void
 */
function code4rest_starter_activatePlugin() {
	var data = new FormData();
	data.append( 'action', 'code4rest_install_starter' );
	data.append( 'security', code4restDashboardParams.ajax_nonce );
	data.append( 'status', code4restDashboardParams.status );
	jQuery.ajax({
		method:      'POST',
		url:         code4restDashboardParams.ajax_url,
		data:        data,
		contentType: false,
		processData: false,
	})
	.done( function( response, status, stately ) {
		if ( response.success ) {
			location.replace( code4restDashboardParams.starterURL );
		}
	})
	.fail( function( error ) {
		console.log( error );
	});
}
/**
 * WordPress dependencies
 */
import { __ } from '@wordpress/i18n';
import { useState, useEffect, Fragment } from '@wordpress/element';
const { withFilters, TabPanel, Panel, PanelBody, PanelRow, Button, Spinner } = wp.components;
export const StarterTab = () => {
	const [ working, setWorking ] = useState( null );
	const handleClick = () => {
		setWorking( true );
		code4rest_starter_activatePlugin();
	};
	return (
		<Fragment>
			<div className="code4rest-desk-starter-inner" style={{ margin: '20px auto', textAlign:'center' }}>
				<h2>{ __( 'Starter Templates', 'code4rest' ) }</h2>
				<p>{ __( 'Create and customize professionally designed websites in minutes. Simply choose your template, choose your colors, and import. Done!', 'code4rest' ) }</p>
				<div className="image-container">
					<img width="772" height="250" alt={ __( 'Starter Templates', 'code4rest' ) } src={ code4restDashboardParams.starterImage } />
				</div>
				{ code4restDashboardParams.starterTemplates && (
					<a
						className="kt-action-starter code4rest-desk-button"
						href={ code4restDashboardParams.starterURL }
					>
						{ code4restDashboardParams.starterLabel }
					</a>
				) }
				{ ! code4restDashboardParams.starterTemplates && (
					<Button 
						className="kt-action-starter code4rest-desk-button"
						onClick={ () => handleClick() }
					>
						{ code4restDashboardParams.starterLabel }
						{ working && (
							<Spinner />
						) }
					</Button>

				) }
			</div>
		</Fragment>
	);
};

export default withFilters( 'code4rest_theme_starters' )( StarterTab );