import { ExtendifyCodeConnector } from '@auto-launch/components/ExtendifyCodeConnector';
import { Launch } from '@auto-launch/components/Launch';
import { LaunchUpdate } from '@auto-launch/components/LaunchUpdate';
import { Logo } from '@auto-launch/components/Logo';
import { MigrateChoice } from '@auto-launch/components/MigrateChoice';
import { MovingGradient } from '@auto-launch/components/MovingGradients';
import { NeedsTheme } from '@auto-launch/components/NeedsTheme';
import { RestartLaunchModal } from '@auto-launch/components/RestartLaunchModal';
import { ViewportPulse } from '@auto-launch/components/ViewportPulse';
import { getAbTest } from '@auto-launch/functions/getAbTest';
import { preLaunchFunctions } from '@auto-launch/functions/setup';
import { updateOption } from '@auto-launch/functions/wp';
import { useLaunchDataStore } from '@auto-launch/state/launch-data';
import { digest } from '@shared/api/digest';
import { registerCoreBlocks } from '@wordpress/block-library';
import { getBlockTypes } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { chevronLeft, Icon } from '@wordpress/icons';
import classNames from 'classnames';
import { AnimatePresence, motion } from 'framer-motion';
import { checkIn, reportRestApiStatus } from './functions/insights';
export const LaunchPage = () => {
const theme = useSelect((select) => select('core').getCurrentTheme());
// Checking `theme` here makes sure the data is populated
const needsTheme = theme && theme?.textdomain !== 'extendable';
const oldPages = window.extLaunchData.resetSiteInformation.pagesIds ?? [];
const needsToReset = oldPages.length > 0;
const pluginUpdateNeeded = Boolean(window.extLaunchData?.pluginUpdateNeeded);
const themeUpdateNeeded = Boolean(window.extLaunchData?.themeUpdateNeeded);
const pluginUpdateViaRest = Boolean(
window.extLaunchData?.pluginUpdateViaRest,
);
const launchUpdateNeeded = pluginUpdateNeeded || themeUpdateNeeded;
const launchUpdateAttempt = window.extLaunchData?.launchUpdateAttempt ?? 0;
const launchUpdateStale = window.extLaunchData?.launchUpdateStale ?? {};
const launchUpdateGaveUp = Object.keys(launchUpdateStale).length > 0;
const {
title,
descriptionRaw,
go,
urlParams,
designBuild,
setData,
showExtendifyCodeScreen,
} = useLaunchDataStore();
const skipDescription =
Boolean(urlParams?.['build-id']) ||
designBuild ||
((title || descriptionRaw) && go);
const showConnector = !skipDescription && showExtendifyCodeScreen;
const showExitLink =
!skipDescription && !window.extLaunchData?.hideAutoLaunchExitLink;
const inMigrateVariant =
getAbTest('AutoLaunch.MigrateScreen').variant === 'B';
const [choosingMigration, setChoosingMigration] = useState(inMigrateVariant);
const showMigrateChoice = !skipDescription && choosingMigration;
const containerRef = useRef(null);
useEffect(() => {
if (launchUpdateNeeded) return;
if (launchUpdateGaveUp) {
digest({
error: new Error('Launch went ahead without the pending update'),
details: {
source: 'auto-launch',
caller: 'launch-update',
stale: launchUpdateStale,
},
});
}
// translators: Launch is a noun.
document.title = __('Launch - AI-Powered Web Creation', 'extendify-local');
updateOption('extendify_launch_loaded', new Date().toISOString());
// We load core blocks so we can parse them
if (getBlockTypes().length === 0) registerCoreBlocks();
preLaunchFunctions();
checkIn({ stage: 'launch_page' });
reportRestApiStatus();
}, [launchUpdateNeeded, launchUpdateGaveUp]);
if (launchUpdateNeeded) {
return (
{__( "Share your vision, and we'll craft a website that's perfectly tailored to your needs, ready to launch in no time.", 'extendify-local', )}