import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { isUltimateActive } from '../../Helpers';
import { showUpgradePopup } from '../../utils/upgrade';
import { Card, Delta, SeverityChip, StatusBadge } from './common';
import { BarList, Heatmap, LineChart, Sparkline } from './charts';
import { ForecastChart, ForecastTable, HorizonBar } from './Forecast';
import { ResultTable } from './Reports';
import { money, num, pct } from './format';
import { Icon, SheetDemoModal, SheetMock } from './SheetDemo';

const TEXT_DOMAIN = 'stock-sync-with-google-sheet-for-woocommerce';

/*
 * Locked preview for FlexStock Free / no valid licence: each tab shows built-in SAMPLE data (never the store's),
 * readable but inert, under a slim banner that offers the upgrade. No AJAX calls are made here.
 */

const CUR = 'USD';
const m = ( v ) => money( v, CUR );

// Deterministic "random" numbers so the sample never changes between renders.
const wave = ( n, base, amp, seed = 1 ) => Array.from( { length: n }, ( _, i ) => Math.max( 0, Math.round( base + amp * Math.sin( ( i + seed ) / 2.3 ) + ( ( ( i * 7 + seed * 13 ) % 11 ) - 5 ) * ( amp / 8 ) ) ) );
const sampleDates = ( n, endOffset = 0 ) => Array.from( { length: n }, ( _, i ) => {
	const d = new Date( Date.UTC( 2026, 0, 1 ) );
	d.setUTCDate( d.getUTCDate() + i + endOffset );
	return d.toISOString().slice( 0, 10 );
} );

const SAMPLE_SKUS = [
	[ 'SAMPLE-001', 'Sample product A', 184, 4416, 12.4, 'instock', 42 ],
	[ 'SAMPLE-002', 'Sample product B', 151, 3624, -6.1, 'lowstock', 4 ],
	[ 'SAMPLE-003', 'Sample product C', 122, 2440, 21.8, 'instock', 96 ],
	[ 'SAMPLE-004', 'Sample product D', 97, 2910, 3.2, 'outofstock', 0 ],
	[ 'SAMPLE-005', 'Sample product E', 76, 1520, -14.5, 'instock', 210 ],
	[ 'SAMPLE-006', 'Sample product F', 58, 870, 0, 'instock', 33 ],
];

const SAMPLE_INSIGHTS = [
	[ 'critical', __( 'Sample: SAMPLE-002 runs out in 3 days', TEXT_DOMAIN ), __( 'At the current pace this SKU sells out before a reorder can arrive.', TEXT_DOMAIN ) ],
	[ 'warning', __( 'Sample: refunds are up', TEXT_DOMAIN ), __( 'Refunds in the last 7 days were twice the usual rate.', TEXT_DOMAIN ) ],
	[ 'info', __( 'Sample: Saturday is your best day', TEXT_DOMAIN ), __( 'Saturdays bring 24% of weekly revenue.', TEXT_DOMAIN ) ],
	[ 'info', __( 'Sample: SAMPLE-003 is growing fast', TEXT_DOMAIN ), __( 'Units are up 22% on the previous period.', TEXT_DOMAIN ) ],
];

// One benefit line per tab, shown in the banner (12 words at most).
const BENEFIT = {
	overview: __( 'Revenue, orders, refunds and stock alerts for any period.', TEXT_DOMAIN ),
	skus: __( 'Units, revenue and a 7-day trend for every SKU.', TEXT_DOMAIN ),
	'stock-health': __( 'See what is out, at risk or dead, then reorder.', TEXT_DOMAIN ),
	trends: __( 'Find your best days, hours and weekly sales swings.', TEXT_DOMAIN ),
	forecast: __( 'Predict demand per SKU and the day each one runs out.', TEXT_DOMAIN ),
	insights: __( 'Plain-language alerts on the stock and sales that need you.', TEXT_DOMAIN ),
	'ask-ai': __( 'Ask about your sales in plain words with your AI key.', TEXT_DOMAIN ),
	reports: __( 'Build any report by SKU, category or date, then export it.', TEXT_DOMAIN ),
	vendors: __( 'Sales, refunds and stock health for every vendor.', TEXT_DOMAIN ),
	stores: __( 'Sales and stock of all connected stores in one view.', TEXT_DOMAIN ),
	settings: __( 'Daily Auto Sync, stock rules, AI and email briefings.', TEXT_DOMAIN ),
};

function SampleKpis( { items } ) {
	return (
		<div className="ssgsw-kpis">
			{ items.map( ( [ label, value, change, invert ] ) => (
				<div key={ label } className="ssgsw-kpi">
					<span className="ssgsw-kpi__label">{ label }</span>
					<strong className="ssgsw-kpi__value">{ value }</strong>
					{ change !== undefined && <span className="ssgsw-kpi__meta"><Delta value={ change } invert={ invert } /></span> }
				</div>
			) ) }
		</div>
	);
}

function SampleOverview() {
	const days = sampleDates( 28 );
	const rev = wave( 28, 420, 160, 3 );
	return (
		<>
			<SampleKpis
				items={ [
					[ __( 'Revenue', TEXT_DOMAIN ), m( 12480 ), 8.2 ],
					[ __( 'Orders', TEXT_DOMAIN ), num( 312 ), 5.1 ],
					[ __( 'Units sold', TEXT_DOMAIN ), num( 688 ), 6.4 ],
					[ __( 'Average order value', TEXT_DOMAIN ), m( 40 ), 2.9 ],
					[ __( 'Refunds', TEXT_DOMAIN ), m( 310 ), -12, true ],
					[ __( 'Refund rate', TEXT_DOMAIN ), pct( 2.5 ), -0.4, true ],
				] }
			/>
			<div className="ssgsw-an-cols">
				<Card title={ __( 'Revenue per day', TEXT_DOMAIN ) } className="ssgsw-an-cols__wide">
					<LineChart labels={ days.map( ( d ) => d.slice( 5 ) ) } series={ [ { name: __( 'Revenue', TEXT_DOMAIN ), values: rev, area: true } ] } format={ m } ariaLabel={ __( 'Sample revenue per day', TEXT_DOMAIN ) } />
				</Card>
				<Card title={ __( 'Stock alerts', TEXT_DOMAIN ) }>
					<ul className="ssgsw-alerts">
						{ [ [ 3, __( 'Out of stock', TEXT_DOMAIN ), 'bad' ], [ 7, __( 'Low stock', TEXT_DOMAIN ), 'warn' ], [ 4, __( 'At risk', TEXT_DOMAIN ), 'warn' ], [ 12, __( 'Overstock', TEXT_DOMAIN ), 'info' ], [ 9, __( 'Dead stock', TEXT_DOMAIN ), 'muted' ] ].map( ( [ n, l, t ] ) => (
							<li key={ l } className={ `ssgsw-alerts__item ssgsw-alerts__item--${ t }` }><strong>{ n }</strong><span>{ l }</span></li>
						) ) }
					</ul>
				</Card>
			</div>
			<div className="ssgsw-an-cols">
				<Card title={ __( 'Top SKUs by revenue', TEXT_DOMAIN ) }>
					<BarList rows={ SAMPLE_SKUS.map( ( s ) => ( { label: s[ 0 ], sub: s[ 1 ], value: s[ 3 ] } ) ) } format={ m } ariaLabel={ __( 'Sample top SKUs', TEXT_DOMAIN ) } />
				</Card>
				<SampleInsightList compact />
			</div>
		</>
	);
}

function SampleSkuTable() {
	return (
		<Card title={ __( 'SKUs', TEXT_DOMAIN ) }>
			<div className="ssgsw-table-wrap">
				<table className="ssgsw-table">
					<thead>
						<tr>
							<th>{ __( 'SKU', TEXT_DOMAIN ) }</th>
							<th>{ __( 'Product', TEXT_DOMAIN ) }</th>
							<th className="is-num">{ __( 'Units', TEXT_DOMAIN ) }</th>
							<th className="is-num">{ __( 'Revenue', TEXT_DOMAIN ) }</th>
							<th className="is-num">{ __( 'Change', TEXT_DOMAIN ) }</th>
							<th>{ __( 'Last 7 days', TEXT_DOMAIN ) }</th>
							<th>{ __( 'Stock', TEXT_DOMAIN ) }</th>
						</tr>
					</thead>
					<tbody>
						{ SAMPLE_SKUS.map( ( s, i ) => (
							<tr key={ s[ 0 ] }>
								<td>{ s[ 0 ] }</td>
								<td className="ssgsw-table__product"><span>{ s[ 1 ] }</span></td>
								<td className="is-num">{ num( s[ 2 ] ) }</td>
								<td className="is-num">{ m( s[ 3 ] ) }</td>
								<td className="is-num"><Delta value={ s[ 4 ] } /></td>
								<td><Sparkline values={ wave( 7, 20, 8, i + 2 ) } ariaLabel={ __( 'Sample trend', TEXT_DOMAIN ) } /></td>
								<td><StatusBadge status={ s[ 5 ] } /></td>
							</tr>
						) ) }
					</tbody>
				</table>
			</div>
		</Card>
	);
}

function SampleStockHealth() {
	return (
		<>
			<SampleKpis
				items={ [
					[ __( 'Out of stock', TEXT_DOMAIN ), '3' ],
					[ __( 'Low stock', TEXT_DOMAIN ), '7' ],
					[ __( 'At risk of running out', TEXT_DOMAIN ), '4' ],
					[ __( 'Overstock', TEXT_DOMAIN ), '12' ],
					[ __( 'Dead stock', TEXT_DOMAIN ), '9' ],
					[ __( 'Stock value (retail)', TEXT_DOMAIN ), m( 48200 ) ],
				] }
			/>
			<Card title={ __( 'Reorder list', TEXT_DOMAIN ) }>
				<div className="ssgsw-table-wrap">
					<table className="ssgsw-table">
						<thead>
							<tr>
								<th>{ __( 'SKU', TEXT_DOMAIN ) }</th>
								<th>{ __( 'Product', TEXT_DOMAIN ) }</th>
								<th className="is-num">{ __( 'On hand', TEXT_DOMAIN ) }</th>
								<th className="is-num">{ __( 'Sales / day', TEXT_DOMAIN ) }</th>
								<th className="is-num">{ __( 'Cover (days)', TEXT_DOMAIN ) }</th>
								<th className="is-num">{ __( 'Suggested order', TEXT_DOMAIN ) }</th>
								<th>{ __( 'Status', TEXT_DOMAIN ) }</th>
							</tr>
						</thead>
						<tbody>
							{ SAMPLE_SKUS.slice( 0, 4 ).map( ( s ) => (
								<tr key={ s[ 0 ] }>
									<td>{ s[ 0 ] }</td>
									<td className="ssgsw-table__product"><span>{ s[ 1 ] }</span></td>
									<td className="is-num">{ num( s[ 6 ] ) }</td>
									<td className="is-num">{ num( s[ 2 ] / 28, 2 ) }</td>
									<td className="is-num">{ num( s[ 6 ] / ( s[ 2 ] / 28 ), 1 ) }</td>
									<td className="is-num"><strong>{ num( Math.max( 10, Math.round( s[ 2 ] / 2 - s[ 6 ] ) ) ) }</strong></td>
									<td><StatusBadge status={ s[ 6 ] === 0 ? 'out_of_stock' : s[ 6 ] < 10 ? 'low_stock' : 'at_risk' } /></td>
								</tr>
							) ) }
						</tbody>
					</table>
				</div>
			</Card>
		</>
	);
}

function SampleTrends() {
	const weeks = sampleDates( 12 ).map( ( _, i ) => sprintf( __( 'Week %d', TEXT_DOMAIN ), i + 1 ) );
	const days = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ];
	const hours = Array.from( { length: 24 }, ( _, h ) => h );
	const matrix = days.map( ( _, r ) => hours.map( ( h ) => ( h < 7 ? 0 : Math.max( 0, Math.round( 6 + 5 * Math.sin( ( h - 8 ) / 3 ) + ( r === 5 ? 4 : 0 ) - ( ( h * r ) % 4 ) ) ) ) ) );
	return (
		<>
			<Card title={ __( 'Units per week', TEXT_DOMAIN ) }>
				<LineChart labels={ weeks } series={ [ { name: __( 'Units', TEXT_DOMAIN ), values: wave( 12, 160, 40, 5 ), area: true }, { name: __( 'Previous period', TEXT_DOMAIN ), values: wave( 12, 140, 30, 2 ), dashed: true, color: '#a5a8c9' } ] } format={ ( v ) => num( v ) } ariaLabel={ __( 'Sample units per week', TEXT_DOMAIN ) } />
			</Card>
			<Card title={ __( 'Orders by weekday and hour', TEXT_DOMAIN ) }>
				<Heatmap weekdays={ days } hours={ hours } matrix={ matrix } ariaLabel={ __( 'Sample heatmap', TEXT_DOMAIN ) } />
			</Card>
		</>
	);
}

const SAMPLE_FORECAST = SAMPLE_SKUS.slice( 0, 5 ).map( ( s, i ) => {
	const daily = wave( 30, s[ 2 ] / 28, 2, i + 1 );
	const out = [ null, 4, 21, 0, null ][ i ];
	return {
		sku: s[ 0 ],
		product: s[ 1 ],
		stock: s[ 6 ],
		avg_daily_28: s[ 2 ] / 28,
		forecast_7: daily.slice( 0, 7 ).reduce( ( a, b ) => a + b, 0 ),
		forecast_total: daily.reduce( ( a, b ) => a + b, 0 ),
		daily,
		days_to_stockout: out,
		stockout_date: out === null ? null : sampleDates( 1, 28 + out )[ 0 ],
	};
} );

function SampleForecast() {
	const hist = sampleDates( 28 ).map( ( date, i ) => ( { date, units: wave( 28, 6, 3, 4 )[ i ] } ) );
	const points = sampleDates( 30, 28 ).map( ( date, i ) => {
		const u = 6 + 0.04 * i + 1.5 * Math.sin( i / 2 );
		return { date, units: u, low: Math.max( 0, u - 2 - i * 0.05 ), high: u + 2 + i * 0.05 };
	} );
	return (
		<>
			<HorizonBar value={ 30 } onChange={ () => {} } />
			<SampleKpis
				items={ [
					[ __( 'Units expected, next 30 days', TEXT_DOMAIN ), num( 1240 ) ],
					[ __( 'Run out within 30 days', TEXT_DOMAIN ), '3' ],
					[ __( 'Forecast accuracy', TEXT_DOMAIN ), pct( 82, 0 ) ],
					[ __( 'Forecast style', TEXT_DOMAIN ), __( 'Steady sales', TEXT_DOMAIN ) ],
				] }
			/>
			<Card title={ sprintf( __( 'Forecast for %s', TEXT_DOMAIN ), 'SAMPLE-002' ) }>
				<ForecastChart history={ hist } points={ points } stockoutDate={ points[ 4 ].date } />
			</Card>
			<Card title={ __( 'Best sellers, soonest stock-out first', TEXT_DOMAIN ) }>
				<ForecastTable items={ SAMPLE_FORECAST } horizon={ 30 } />
			</Card>
		</>
	);
}

function SampleInsightList( { compact = false } ) {
	return (
		<Card title={ compact ? __( 'Top insights', TEXT_DOMAIN ) : __( 'Insights', TEXT_DOMAIN ) }>
			<ul className={ `ssgsw-insight-list${ compact ? ' ssgsw-insight-list--compact' : '' }` }>
				{ SAMPLE_INSIGHTS.map( ( [ sev, title, text ] ) => (
					<li key={ title }>
						<SeverityChip severity={ sev } />
						<div><strong>{ title }</strong><p>{ text }</p></div>
					</li>
				) ) }
			</ul>
		</Card>
	);
}

function SampleAskAi() {
	return (
		<Card title={ __( 'Ask AI', TEXT_DOMAIN ) }>
			<div className="ssgsw-ai">
				<div className="ssgsw-ai__prompts">
					{ [ __( 'What sold best this week?', TEXT_DOMAIN ), __( 'What should I reorder?', TEXT_DOMAIN ), __( 'Why did sales drop?', TEXT_DOMAIN ) ].map( ( p ) => <span key={ p } className="ssgsw-ai__chip">{ p }</span> ) }
				</div>
				<div className="ssgsw-ai__thread" style={ { marginTop: 14 } }>
					<div className="ssgsw-ai__msg is-user"><p className="ssgsw-ai__text">{ __( 'What should I reorder this week?', TEXT_DOMAIN ) }</p></div>
					<div className="ssgsw-ai__msg is-assistant">
						<p className="ssgsw-ai__text">{ __( 'Sample answer: reorder SAMPLE-002 (about 60 units, runs out in 3 days) and SAMPLE-004 (out of stock, sold 97 units in 28 days). SAMPLE-005 has 90+ days of cover, so skip it for now.', TEXT_DOMAIN ) }</p>
					</div>
				</div>
			</div>
		</Card>
	);
}

const SAMPLE_REPORT = {
	currency: CUR,
	columns: [
		{ key: 'category', label: 'Category', type: 'dimension', format: 'text' },
		{ key: 'units', label: 'Units sold', type: 'metric', format: 'number' },
		{ key: 'orders', label: 'Orders', type: 'metric', format: 'number' },
		{ key: 'net', label: 'Net sales', type: 'metric', format: 'money' },
	],
	rows: [
		{ category: 'Sample category 1', units: 412, orders: 188, net: 8240 },
		{ category: 'Sample category 2', units: 236, orders: 121, net: 4720 },
		{ category: 'Sample category 3', units: 140, orders: 77, net: 2380 },
		{ category: 'Sample category 4', units: 64, orders: 40, net: 960 },
	],
	totals: { units: 852, orders: 426, net: 16300 },
};

function SampleReports() {
	return (
		<>
			<Card title={ __( 'Ask in plain words', TEXT_DOMAIN ) }>
				<div className="ssgsw-rb-ask__row">
					<input type="text" className="ssgsw-analytics-input" readOnly value={ __( 'Net sales by category last month', TEXT_DOMAIN ) } tabIndex={ -1 } />
					<span className="ssgsw-analytics-btn ssgsw-analytics-btn--primary">{ __( 'Build report', TEXT_DOMAIN ) }</span>
				</div>
			</Card>
			<Card title={ __( 'Sample: net sales by category', TEXT_DOMAIN ) }>
				<BarList rows={ SAMPLE_REPORT.rows.map( ( r ) => ( { label: r.category, value: r.net } ) ) } format={ m } ariaLabel={ __( 'Sample report chart', TEXT_DOMAIN ) } />
				<ResultTable result={ SAMPLE_REPORT } />
			</Card>
		</>
	);
}

function SampleTable( { title, head, rows } ) {
	return (
		<Card title={ title }>
			<div className="ssgsw-table-wrap">
				<table className="ssgsw-table">
					<thead><tr>{ head.map( ( h, i ) => <th key={ h } className={ i ? 'is-num' : '' }>{ h }</th> ) }</tr></thead>
					<tbody>{ rows.map( ( r ) => <tr key={ r[ 0 ] }>{ r.map( ( c, i ) => <td key={ i } className={ i ? 'is-num' : '' }>{ c }</td> ) }</tr> ) }</tbody>
				</table>
			</div>
		</Card>
	);
}

function SampleSettings() {
	const rows = [
		[ __( 'Enable Sales Analytics', TEXT_DOMAIN ), true ],
		[ __( 'Daily Auto Sync to Google Sheets', TEXT_DOMAIN ), true ],
		[ __( 'Re-check the last 7 days every night', TEXT_DOMAIN ), true ],
		[ __( 'Daily email briefing', TEXT_DOMAIN ), false ],
		[ __( 'Stock alerts by email or Slack', TEXT_DOMAIN ), true ],
		[ __( 'Forecast demand', TEXT_DOMAIN ), true ],
	];
	return (
		<>
			<div className="ssgs-dashboard__block ssgsw-analytics-block">
				<h4 className="title">{ __( 'Sales Analytics', TEXT_DOMAIN ) }</h4>
				{ rows.map( ( [ label, on ] ) => (
					<div key={ label } className="ssgsw-locked-row">
						<span className={ `ssgsw-locked-toggle${ on ? ' is-on' : '' }` } aria-hidden="true"></span>
						<span>{ label }</span>
					</div>
				) ) }
			</div>
			<div className="ssgs-dashboard__block ssgsw-analytics-block">
				<h4 className="title">{ __( 'Stock rules', TEXT_DOMAIN ) }</h4>
				<div className="ssgsw-analytics-grid">
					{ [ [ __( 'Low-stock threshold', TEXT_DOMAIN ), '5' ], [ __( 'Supplier lead time (days)', TEXT_DOMAIN ), '7' ], [ __( 'Safety days', TEXT_DOMAIN ), '3' ] ].map( ( [ l, val ] ) => (
						<div key={ l } className="ssgsw-analytics-field">
							<span className="ssgsw-analytics-field__label">{ l }</span>
							<input type="text" className="ssgsw-analytics-input" readOnly value={ val } tabIndex={ -1 } />
						</div>
					) ) }
				</div>
			</div>
		</>
	);
}

const SCREENS = {
	overview: SampleOverview,
	skus: SampleSkuTable,
	'stock-health': SampleStockHealth,
	trends: SampleTrends,
	forecast: SampleForecast,
	insights: () => <SampleInsightList />,
	'ask-ai': SampleAskAi,
	reports: SampleReports,
	vendors: () => (
		<SampleTable
			title={ __( 'Vendors', TEXT_DOMAIN ) }
			head={ [ __( 'Vendor', TEXT_DOMAIN ), __( 'Orders', TEXT_DOMAIN ), __( 'Units', TEXT_DOMAIN ), __( 'Revenue', TEXT_DOMAIN ) ] }
			rows={ [ [ 'Sample vendor 1', 120, 310, m( 6200 ) ], [ 'Sample vendor 2', 84, 190, m( 3800 ) ], [ 'Sample vendor 3', 41, 77, m( 1540 ) ] ] }
		/>
	),
	stores: () => (
		<SampleTable
			title={ __( 'Stores', TEXT_DOMAIN ) }
			head={ [ __( 'Store', TEXT_DOMAIN ), __( 'Units', TEXT_DOMAIN ), __( 'Net sales', TEXT_DOMAIN ), __( 'SKUs sold', TEXT_DOMAIN ) ] }
			rows={ [ [ 'Sample main store', 688, m( 12480 ), 54 ], [ 'Sample store 2', 302, m( 5410 ), 31 ], [ 'Sample store 3', 115, m( 2090 ), 18 ] ] }
		/>
	),
	settings: SampleSettings,
};

/**
 * Readable (lightly veiled) sample screen for one tab, a slim upgrade banner above it, and the
 * "See it in Google Sheets" teaser + demo modal. Nothing here makes a request.
 */
export default function LockedPreview( { tab, label } ) {
	const ref = useRef( null );
	const [ demoOpen, setDemoOpen ] = useState( false );
	// `inert` keeps keyboard focus out of the sample (React 18 does not know the attribute).
	useEffect( () => {
		if ( ref.current ) {
			ref.current.setAttribute( 'inert', '' );
		}
	}, [ tab ] );
	const Screen = SCREENS[ tab ] || SampleOverview;
	const activate = isUltimateActive();
	const upgradeLabel = activate ? __( 'Activate your Ultimate licence', TEXT_DOMAIN ) : __( 'Upgrade to Ultimate', TEXT_DOMAIN );
	const closeDemo = useCallback( () => setDemoOpen( false ), [] );
	const upgradeFromDemo = useCallback( () => {
		setDemoOpen( false );
		showUpgradePopup();
	}, [] );

	return (
		<div className="ssgsw-locked">
			<div className="ssgsw-locked__banner" role="region" aria-label={ sprintf( /* translators: %s: tab name, e.g. Forecast */ __( '%s is locked', TEXT_DOMAIN ), label ) }>
				<span className="ssgsw-locked__icon" aria-hidden="true"><Icon name="lock" /></span>
				<div className="ssgsw-locked__copy">
					<strong className="ssgsw-locked__headline">
						{ activate ? __( 'Activate your licence to unlock Sales Analytics', TEXT_DOMAIN ) : __( 'Unlock Sales Analytics with Ultimate', TEXT_DOMAIN ) }
					</strong>
					<span className="ssgsw-locked__benefit" aria-live="polite">{ BENEFIT[ tab ] || BENEFIT.overview }</span>
				</div>
				<div className="ssgsw-locked__actions">
					<button type="button" className="ssgsw-link ssgsw-locked__sheets" onClick={ () => setDemoOpen( true ) }>
						{ __( 'See it in Google Sheets', TEXT_DOMAIN ) }
					</button>
					<button type="button" className="ssgsw-analytics-btn ssgsw-analytics-btn--primary" onClick={ showUpgradePopup }>
						{ upgradeLabel }
					</button>
				</div>
			</div>

			<div className="ssgsw-locked__layout">
				<div className="ssgsw-locked__preview">
					<p className="ssgsw-locked__ribbon">
						<span className="ssgsw-locked__pill">{ __( 'Sample data', TEXT_DOMAIN ) }</span>
						<span className="ssgsw-locked__note">
							{ activate
								? __( 'Made-up numbers. Activate your licence to see your store.', TEXT_DOMAIN )
								: __( 'Made-up numbers. With Ultimate you see your own store.', TEXT_DOMAIN ) }
						</span>
					</p>
					<div className="ssgsw-locked__content" aria-hidden="true" ref={ ref }>
						<div className="ssgsw-an-screen">
							<Screen />
						</div>
					</div>
				</div>

				<aside className="ssgsw-locked__teaser" aria-label={ __( 'Analytics in Google Sheets', TEXT_DOMAIN ) }>
					<div className="ssgsw-locked__teaser-mock" aria-hidden="true">
						<SheetMock compact />
					</div>
					<div className="ssgsw-locked__teaser-text">
						<strong>{ __( 'Also inside your Google Sheet', TEXT_DOMAIN ) }</strong>
						<span>{ __( 'The same analytics open as a sidebar in your sheet.', TEXT_DOMAIN ) }</span>
						<button type="button" className="ssgsw-link" onClick={ () => setDemoOpen( true ) }>
							{ __( 'Open the demo', TEXT_DOMAIN ) }
							<span aria-hidden="true"> →</span>
						</button>
					</div>
				</aside>
			</div>

			{ demoOpen && <SheetDemoModal onClose={ closeDemo } onUpgrade={ upgradeFromDemo } upgradeLabel={ upgradeLabel } /> }
		</div>
	);
}
