<?php
/**
 * The Upgrade page — the ONE Pro pointer wp.org allows in a free build
 * (Guideline 5). It ships in BOTH builds; it hides itself for users who already
 * have Pro. Every other Pro surface (teasers, the hierarchy UI) is physically
 * stripped from the free build, so this localized landing page is the plugin's
 * whole conversion funnel. It is our own page, never the Freemius pricing app;
 * its buy buttons deep-link into the Freemius CHECKOUT (plan + pricing ids) so
 * a purchase activates the licence automatically.
 *
 * All markup is escaped at echo (esc_ helpers and wp_kses); inline SVG goes
 * through wp_kses() with an explicit allow-list — never a phpcs:ignore.
 *
 * @package SmartCategories
 */

defined( 'ABSPATH' ) || exit;

/**
 * Class SCWC_Upgrade
 */
class SCWC_Upgrade {

	const SLUG = 'scwc-upgrade';

	/**
	 * Freemius plan / pricing ids (Eren Labs store, product 34510). Filterable
	 * so a future price change never requires a code edit.
	 */
	const PLAN_ID        = 56724;
	const PRICING_SINGLE = 74615;
	const PRICING_TEAM   = 74616;
	const PRICING_AGENCY = 74617;

	/**
	 * Wire hooks.
	 */
	public static function init() {
		add_action( 'admin_menu', array( __CLASS__, 'menu' ), 20 );
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) );
		// A landing page must not have other plugins' notices leaking into its
		// hero. WordPress relocates every .notice after the first heading, so we
		// unhook the notice actions on THIS screen only (standard practice for a
		// plugin's own full-screen pages; every other screen is untouched).
		add_action( 'in_admin_header', array( __CLASS__, 'silence_notices' ), 999 );
	}

	/**
	 * Whether the current screen is this Upgrade page.
	 *
	 * @return bool
	 */
	private static function is_upgrade_screen() {
		$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
		return $screen && false !== strpos( (string) $screen->id, self::SLUG );
	}

	/**
	 * Remove all admin notices on the Upgrade screen only.
	 */
	public static function silence_notices() {
		if ( ! self::is_upgrade_screen() ) {
			return;
		}
		remove_all_actions( 'admin_notices' );
		remove_all_actions( 'all_admin_notices' );
		remove_all_actions( 'network_admin_notices' );
		remove_all_actions( 'user_admin_notices' );
	}

	/**
	 * Register the Upgrade submenu under the Smart Categories menu. Hidden once
	 * the user has Pro (they have nothing left to buy here).
	 */
	public static function menu() {
		if ( SCWC_Plugin::is_pro() ) {
			return;
		}
		add_submenu_page(
			'scwc-overview',
			__( 'Upgrade to Pro', 'smart-categories-for-woocommerce' ),
			'<span class="scwc-upgrade-menu">' . esc_html__( 'Upgrade', 'smart-categories-for-woocommerce' ) . '</span>',
			'manage_woocommerce',
			self::SLUG,
			array( __CLASS__, 'render' )
		);
	}

	/**
	 * Load the landing-page stylesheet on this screen only. Cache-bust by file
	 * mtime so a CSS change is never served stale from a proxy.
	 *
	 * @param string $hook Current admin page hook.
	 */
	public static function assets( $hook ) {
		// The submenu hook prefix depends on the parent menu title, so match by the
		// slug substring instead of hard-coding the prefix.
		if ( false === strpos( (string) $hook, self::SLUG ) ) {
			return;
		}
		$path = SCWC_DIR . 'assets/upgrade.css';
		$ver  = file_exists( $path ) ? SCWC_VERSION . '.' . (string) filemtime( $path ) : SCWC_VERSION;
		wp_enqueue_style( 'scwc-upgrade', SCWC_URL . 'assets/upgrade.css', array(), $ver );
	}

	/**
	 * Freemius checkout deep link for a pricing tier. Falls back to the public
	 * product page when the SDK is unavailable (e.g. a raw dev tree).
	 *
	 * @param int  $pricing_id Freemius pricing id (0 = let the checkout choose).
	 * @param bool $trial      Start the free-trial flow instead of a purchase.
	 * @return string
	 */
	private static function checkout_url( $pricing_id = 0, $trial = false ) {
		if ( function_exists( 'scwc_fs' ) && scwc_fs() ) {
			$extra = array(
				/**
				 * Filter the Freemius plan id used by the upgrade page.
				 *
				 * @param int $plan_id Plan id.
				 */
				'plan_id' => (int) apply_filters( 'scwc_freemius_plan_id', self::PLAN_ID ),
			);
			if ( $pricing_id ) {
				$extra['pricing_id'] = (int) $pricing_id;
			}
			return scwc_fs()->checkout_url( WP_FS__PERIOD_ANNUALLY, $trial, $extra );
		}
		return 'https://erenlabs.net/smart-categories-for-woocommerce/';
	}

	/**
	 * The wp_kses allow-list for our inline SVG icons.
	 *
	 * @return array
	 */
	private static function svg_allowed() {
		return array(
			'svg'    => array( 'width' => true, 'height' => true, 'viewbox' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'xmlns' => true, 'aria-hidden' => true, 'class' => true ),
			'path'   => array( 'd' => true, 'fill' => true, 'stroke' => true ),
			'circle' => array( 'cx' => true, 'cy' => true, 'r' => true, 'fill' => true, 'stroke' => true ),
			'rect'   => array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'fill' => true, 'stroke' => true ),
		);
	}

	/**
	 * Echo one inline SVG icon, escaped through wp_kses.
	 *
	 * @param string $name Icon key.
	 */
	private static function icon( $name ) {
		$p    = '<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">';
		$svgs = array(
			'tree'     => $p . '<rect x="9" y="3" width="6" height="4" rx="1"></rect><rect x="3" y="17" width="6" height="4" rx="1"></rect><rect x="15" y="17" width="6" height="4" rx="1"></rect><path d="M12 7v4M6 17v-2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v2"></path></svg>',
			'search'   => $p . '<circle cx="11" cy="11" r="7"></circle><path d="M21 21l-4.3-4.3"></path></svg>',
			'refresh'  => $p . '<path d="M21 12a9 9 0 1 1-2.64-6.36M21 4v5h-5"></path></svg>',
			'template' => $p . '<rect x="3" y="4" width="18" height="16" rx="2"></rect><path d="M3 9h18M8 4v5"></path></svg>',
			'grid'     => $p . '<rect x="3" y="3" width="7" height="7" rx="1"></rect><rect x="14" y="3" width="7" height="7" rx="1"></rect><rect x="3" y="14" width="7" height="7" rx="1"></rect><rect x="14" y="14" width="7" height="7" rx="1"></rect></svg>',
			'tag'      => $p . '<path d="M20.6 13.4 12 22l-8-8V4h10l6.6 6.6a2 2 0 0 1 0 2.8Z"></path><circle cx="8" cy="8" r="1.4" fill="currentColor"></circle></svg>',
			'bolt'     => $p . '<path d="M13 2 3 14h7l-1 8 10-12h-7l1-8Z"></path></svg>',
			'check'    => $p . '<path d="M20 6 9 17l-5-5"></path></svg>',
			'shield'   => $p . '<path d="M12 2 4 5v6c0 5 3.4 9.4 8 11 4.6-1.6 8-6 8-11V5l-8-3Z"></path><path d="M9 12l2 2 4-4"></path></svg>',
			'shirt'    => $p . '<path d="M8 3 4 6l2 4 2-1v12h8V9l2 1 2-4-4-3a4 4 0 0 1-8 0Z"></path></svg>',
			'cpu'      => $p . '<rect x="6" y="6" width="12" height="12" rx="2"></rect><rect x="10" y="10" width="4" height="4"></rect><path d="M12 2v2M12 20v2M2 12h2M20 12h2M6 2v2M18 2v2M6 20v2M18 20v2"></path></svg>',
			'sofa'     => $p . '<path d="M5 10V8a3 3 0 0 1 3-3h8a3 3 0 0 1 3 3v2"></path><path d="M3 12a2 2 0 0 1 4 0v2h10v-2a2 2 0 0 1 4 0v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4Z"></path><path d="M6 18v2M18 18v2"></path></svg>',
			'ball'     => $p . '<circle cx="12" cy="12" r="9"></circle><path d="M12 3a15 15 0 0 1 0 18M3.5 9h17M3.5 15h17"></path></svg>',
			'support'  => $p . '<circle cx="12" cy="12" r="9"></circle><circle cx="12" cy="12" r="4"></circle><path d="M5.6 5.6l3.5 3.5M14.9 14.9l3.5 3.5M18.4 5.6l-3.5 3.5M9.1 14.9l-3.5 3.5"></path></svg>',
		);
		echo wp_kses( isset( $svgs[ $name ] ) ? $svgs[ $name ] : '', self::svg_allowed() );
	}

	/**
	 * Full Free vs Pro comparison, grouped. A row is either
	 * array( 'group', label ) or array( label, in_free, in_pro ).
	 *
	 * @return array
	 */
	private static function comparison() {
		return array(
			array( 'group', __( 'Smart rule engine — free forever', 'smart-categories-for-woocommerce' ) ),
			array( __( 'Unlimited nested AND / OR / NOT rule groups', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( '35+ match fields: price, stock, attributes, dates, custom fields…', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Live preview with matching products and counts while you type', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( '“Why did / didn’t it match?” product tester', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Instant re-evaluation on product save + daily background refresh', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Manual assignments always respected — never removed by the engine', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Rule sets on categories and on product tags', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Ready-made rule templates (On sale, New arrivals, Best sellers…)', 'smart-categories-for-woocommerce' ), true, true ),
			array( 'group', __( 'Storefront & display — free forever', 'smart-categories-for-woocommerce' ) ),
			array( __( 'Per-category shop sorting: best selling, newest, price, rating', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Push out-of-stock products to the end, or hide them', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Gutenberg products block + shortcode', 'smart-categories-for-woocommerce' ), true, true ),
			array( 'group', __( 'SEO page engine — Pro', 'smart-categories-for-woocommerce' ) ),
			array( __( 'Auto-generate a subcategory page per attribute value (Colour, Size, Brand…)', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Two-attribute cross-product: Colour × Size → every valid pairing', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Editable name templates with {value1} {value2} {parent} + free text', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Live example name and combination count before you generate', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'New attribute values grow new pages on their own (daily sync)', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Empty combinations skipped — no thin pages, ever', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Generate as subcategories or as product tags', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Collision guard: never adopts or overwrites your own categories', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Safety cap + idempotent re-sync (re-running never duplicates)', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Products leaving the parent leave their combination pages too', 'smart-categories-for-woocommerce' ), false, true ),
			array( 'group', __( 'Sales intelligence — Pro', 'smart-categories-for-woocommerce' ) ),
			array( __( 'Time-window sales fields: units sold in 7 / 30 / 90 days, revenue, velocity', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( '“Days since last sale” for stale-product cleanup collections', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Ready-made Trending & Stale auto-collection templates', 'smart-categories-for-woocommerce' ), false, true ),
			array( 'group', __( 'Support', 'smart-categories-for-woocommerce' ) ),
			array( __( 'Community forum support', 'smart-categories-for-woocommerce' ), true, true ),
			array( __( 'Priority email support', 'smart-categories-for-woocommerce' ), false, true ),
			array( __( 'Automatic Pro updates + licence management (Freemius)', 'smart-categories-for-woocommerce' ), false, true ),
		);
	}

	/**
	 * Render the landing page. All dynamic output is escaped at echo.
	 */
	public static function render() {
		if ( ! current_user_can( 'manage_woocommerce' ) ) {
			return;
		}
		$trial_url  = self::checkout_url( 0, true );
		$yes        = esc_html__( 'Yes', 'smart-categories-for-woocommerce' );
		?>
		<div class="wrap scwc-lp">

			<?php /* ---- Hero ---- */ ?>
			<section class="scwc-lp-hero">
				<div class="scwc-lp-hero-copy">
					<span class="scwc-lp-pill"><?php esc_html_e( 'Smart Categories Pro', 'smart-categories-for-woocommerce' ); ?></span>
					<h1><?php esc_html_e( 'Turn one category into hundreds of self-updating SEO pages', 'smart-categories-for-woocommerce' ); ?></h1>
					<p class="scwc-lp-lede"><?php esc_html_e( 'Pro’s subcategory generator splits any smart category into a real landing page for every attribute value — or every combination of two — and keeps each one filled and current, automatically.', 'smart-categories-for-woocommerce' ); ?></p>
					<div class="scwc-lp-cta-row">
						<a class="scwc-lp-cta" href="<?php echo esc_url( $trial_url ); ?>"><?php esc_html_e( 'Start free trial', 'smart-categories-for-woocommerce' ); ?></a>
						<span class="scwc-lp-cta-note"><?php esc_html_e( '14-day free trial, no card · 30-day money-back', 'smart-categories-for-woocommerce' ); ?></span>
					</div>
				</div>
				<div class="scwc-lp-hero-visual" aria-hidden="true">
					<div class="scwc-lp-node scwc-lp-parent"><?php esc_html_e( 'Dresses', 'smart-categories-for-woocommerce' ); ?> <b>48</b></div>
					<div class="scwc-lp-fan">
						<span class="scwc-lp-node"><i class="scwc-lp-dot is-r"></i><?php esc_html_e( 'Red XL Dress', 'smart-categories-for-woocommerce' ); ?> <b>6</b></span>
						<span class="scwc-lp-node"><i class="scwc-lp-dot is-b"></i><?php esc_html_e( 'Black M Dress', 'smart-categories-for-woocommerce' ); ?> <b>9</b></span>
						<span class="scwc-lp-node"><i class="scwc-lp-dot is-k"></i><?php esc_html_e( 'Beige S Dress', 'smart-categories-for-woocommerce' ); ?> <b>4</b></span>
						<span class="scwc-lp-node is-ghost">+ <?php esc_html_e( 'new value → new page (auto)', 'smart-categories-for-woocommerce' ); ?></span>
					</div>
				</div>
			</section>

			<?php /* ---- The SEO engine (flagship) ---- */ ?>
			<section class="scwc-lp-seo">
				<div class="scwc-lp-seo-copy">
					<span class="scwc-lp-kicker"><?php self::icon( 'search' ); ?><?php esc_html_e( 'Programmatic SEO', 'smart-categories-for-woocommerce' ); ?></span>
					<h2><?php esc_html_e( 'A long-tail SEO landing page for every attribute combination', 'smart-categories-for-woocommerce' ); ?></h2>
					<p><?php esc_html_e( 'Shoppers don’t search “dresses”. They search “red xl dress”, “black midi dress”, “beige summer dress”. Those long-tail queries convert — but building a page for each by hand is impossible.', 'smart-categories-for-woocommerce' ); ?></p>
					<p><?php esc_html_e( 'Point Pro at a smart category, pick one or two attributes, and it creates a genuine, indexable category page for every combination that actually has products — its own URL, title and product grid — matching exactly what people type into Google.', 'smart-categories-for-woocommerce' ); ?></p>
					<ul class="scwc-lp-ticks">
						<li><?php self::icon( 'check' ); ?><?php esc_html_e( 'Products flow into each page automatically — no manual sorting.', 'smart-categories-for-woocommerce' ); ?></li>
						<li><?php self::icon( 'check' ); ?><?php esc_html_e( 'Add a new colour and its page appears on its own, filled and indexable.', 'smart-categories-for-woocommerce' ); ?></li>
						<li><?php self::icon( 'check' ); ?><?php esc_html_e( 'Combinations with no products are skipped, so you never ship thin pages.', 'smart-categories-for-woocommerce' ); ?></li>
						<li><?php self::icon( 'check' ); ?><?php esc_html_e( 'Works with the SEO plugin you already use — the pages are native category archives.', 'smart-categories-for-woocommerce' ); ?></li>
					</ul>
				</div>
				<div class="scwc-lp-seo-visual" aria-hidden="true">
					<div class="scwc-lp-rulebar"><?php echo esc_html( 'Dresses × Colour × Size' ); ?></div>
					<div class="scwc-lp-arrow">↓</div>
					<div class="scwc-lp-pagegrid">
						<span>/red-xl-dress</span><span>/black-m-dress</span><span>/beige-s-dress</span>
						<span>/red-l-dress</span><span>/black-xl-dress</span><span>/green-s-dress</span>
					</div>
					<div class="scwc-lp-pagegrid-note"><?php esc_html_e( 'real, indexable URLs — one per combination', 'smart-categories-for-woocommerce' ); ?></div>
				</div>
			</section>

			<?php /* ---- Real math band ---- */ ?>
			<section class="scwc-lp-math" aria-hidden="false">
				<div class="scwc-lp-math-item"><b>9 × 6</b><span><?php esc_html_e( 'colours × sizes in a real test store', 'smart-categories-for-woocommerce' ); ?></span></div>
				<div class="scwc-lp-math-sep">→</div>
				<div class="scwc-lp-math-item"><b>54</b><span><?php esc_html_e( 'possible combinations evaluated', 'smart-categories-for-woocommerce' ); ?></span></div>
				<div class="scwc-lp-math-sep">→</div>
				<div class="scwc-lp-math-item"><b>16</b><span><?php esc_html_e( 'pages created — only those with products', 'smart-categories-for-woocommerce' ); ?></span></div>
				<div class="scwc-lp-math-sep">→</div>
				<div class="scwc-lp-math-item"><b>38</b><span><?php esc_html_e( 'empty combinations skipped automatically', 'smart-categories-for-woocommerce' ); ?></span></div>
			</section>

			<?php /* ---- How it works ---- */ ?>
			<section class="scwc-lp-steps">
				<h2 class="scwc-lp-h2"><?php esc_html_e( 'Three clicks, then it runs itself', 'smart-categories-for-woocommerce' ); ?></h2>
				<div class="scwc-lp-steprow">
					<div class="scwc-lp-step"><span class="scwc-lp-num">1</span><strong><?php esc_html_e( 'Pick attributes', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Choose one or two — Colour, Size, Brand, Material…', 'smart-categories-for-woocommerce' ); ?></p></div>
					<div class="scwc-lp-step"><span class="scwc-lp-num">2</span><strong><?php esc_html_e( 'Name the pages', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'A template like {value1} {value2} {parent} → “Red XL Dress”.', 'smart-categories-for-woocommerce' ); ?></p></div>
					<div class="scwc-lp-step"><span class="scwc-lp-num">3</span><strong><?php esc_html_e( 'Generate & forget', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Pages appear instantly and stay in sync as your catalog changes.', 'smart-categories-for-woocommerce' ); ?></p></div>
				</div>
			</section>

			<?php /* ---- Template composer mockup ---- */ ?>
			<section class="scwc-lp-composer">
				<div class="scwc-lp-mock" aria-hidden="true">
					<div class="scwc-lp-mock-bar"><i></i><i></i><i></i><span><?php esc_html_e( 'Auto subcategories', 'smart-categories-for-woocommerce' ); ?></span></div>
					<div class="scwc-lp-mock-body">
						<div class="scwc-lp-mock-row">
							<span class="scwc-lp-mock-field"><em><?php esc_html_e( 'Attribute 1', 'smart-categories-for-woocommerce' ); ?></em><?php esc_html_e( 'Colour (9)', 'smart-categories-for-woocommerce' ); ?></span>
							<span class="scwc-lp-mock-field"><em><?php esc_html_e( 'Attribute 2 (optional)', 'smart-categories-for-woocommerce' ); ?></em><?php esc_html_e( 'Size (6)', 'smart-categories-for-woocommerce' ); ?></span>
						</div>
						<div class="scwc-lp-mock-row">
							<span class="scwc-lp-mock-field is-wide"><em><?php esc_html_e( 'Name template', 'smart-categories-for-woocommerce' ); ?></em><code>{value1} {value2} {parent}</code></span>
						</div>
						<div class="scwc-lp-mock-example"><?php esc_html_e( 'Example:', 'smart-categories-for-woocommerce' ); ?> <b><?php esc_html_e( 'Red XL Dress', 'smart-categories-for-woocommerce' ); ?></b> · <?php esc_html_e( 'up to 54 pages (empty ones skipped)', 'smart-categories-for-woocommerce' ); ?></div>
						<span class="scwc-lp-mock-btn"><?php esc_html_e( 'Generate', 'smart-categories-for-woocommerce' ); ?></span>
					</div>
				</div>
				<div class="scwc-lp-composer-copy">
					<h2><?php esc_html_e( 'You stay in control of every name', 'smart-categories-for-woocommerce' ); ?></h2>
					<p><?php esc_html_e( 'The template composer shows a live example and the exact page count before you commit. Mix the attribute values, the parent name and your own free text — “Cheap {value1} {parent}”, “{value1} {value2} {parent} Collection”, anything.', 'smart-categories-for-woocommerce' ); ?></p>
					<ul class="scwc-lp-ticks">
						<li><?php self::icon( 'shield' ); ?><?php esc_html_e( 'Collision guard: an existing category of yours is never adopted or overwritten.', 'smart-categories-for-woocommerce' ); ?></li>
						<li><?php self::icon( 'shield' ); ?><?php esc_html_e( 'Safety cap and idempotent re-runs: generating twice never duplicates anything.', 'smart-categories-for-woocommerce' ); ?></li>
						<li><?php self::icon( 'shield' ); ?><?php esc_html_e( 'Remove the generator anytime — the pages stay as normal categories you own.', 'smart-categories-for-woocommerce' ); ?></li>
					</ul>
				</div>
			</section>

			<?php /* ---- Use cases ---- */ ?>
			<section class="scwc-lp-uses">
				<h2 class="scwc-lp-h2"><?php esc_html_e( 'Built for every catalog', 'smart-categories-for-woocommerce' ); ?></h2>
				<div class="scwc-lp-userow">
					<div class="scwc-lp-use"><span class="scwc-lp-fico"><?php self::icon( 'shirt' ); ?></span><strong><?php esc_html_e( 'Fashion', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Colour × Size — “Red XL Dress”, “Black M Hoodie”.', 'smart-categories-for-woocommerce' ); ?></p></div>
					<div class="scwc-lp-use"><span class="scwc-lp-fico"><?php self::icon( 'cpu' ); ?></span><strong><?php esc_html_e( 'Electronics', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Brand × Capacity — “Samsung 256GB Phone”.', 'smart-categories-for-woocommerce' ); ?></p></div>
					<div class="scwc-lp-use"><span class="scwc-lp-fico"><?php self::icon( 'sofa' ); ?></span><strong><?php esc_html_e( 'Home & Furniture', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Material × Room — “Oak Living Room Table”.', 'smart-categories-for-woocommerce' ); ?></p></div>
					<div class="scwc-lp-use"><span class="scwc-lp-fico"><?php self::icon( 'ball' ); ?></span><strong><?php esc_html_e( 'Sports', 'smart-categories-for-woocommerce' ); ?></strong><p><?php esc_html_e( 'Brand × Size — “Nike 42 Running Shoes”.', 'smart-categories-for-woocommerce' ); ?></p></div>
				</div>
			</section>

			<?php /* ---- Feature cards ---- */ ?>
			<section class="scwc-lp-features">
				<?php
				$cards = array(
					array( 'tree', __( 'Per-attribute pages', 'smart-categories-for-woocommerce' ), __( 'One subcategory per Colour, Size, Brand or any global attribute.', 'smart-categories-for-woocommerce' ) ),
					array( 'grid', __( 'Two-attribute cross-product', 'smart-categories-for-woocommerce' ), __( 'Colour × Size builds every valid pairing — “Red XL”, “Black M”…', 'smart-categories-for-woocommerce' ) ),
					array( 'template', __( 'Editable name templates', 'smart-categories-for-woocommerce' ), __( 'Compose page names from values, the parent and free text.', 'smart-categories-for-woocommerce' ) ),
					array( 'refresh', __( 'Grows on its own', 'smart-categories-for-woocommerce' ), __( 'New attribute values spawn new pages automatically, every day.', 'smart-categories-for-woocommerce' ) ),
					array( 'tag', __( 'Categories or tags', 'smart-categories-for-woocommerce' ), __( 'Generate the pages as subcategories or as product tags.', 'smart-categories-for-woocommerce' ) ),
					array( 'bolt', __( 'Fast & safe', 'smart-categories-for-woocommerce' ), __( 'One grouped query builds the whole matrix; empty combos are skipped.', 'smart-categories-for-woocommerce' ) ),
				);
				foreach ( $cards as $c ) :
					?>
					<div class="scwc-lp-fcard">
						<span class="scwc-lp-fico"><?php self::icon( $c[0] ); ?></span>
						<strong><?php echo esc_html( $c[1] ); ?></strong>
						<p><?php echo esc_html( $c[2] ); ?></p>
					</div>
				<?php endforeach; ?>
			</section>

			<?php /* ---- Comparison ---- */ ?>
			<section class="scwc-lp-compare">
				<h2 class="scwc-lp-h2"><?php esc_html_e( 'Everything in Free, plus the page engine', 'smart-categories-for-woocommerce' ); ?></h2>
				<table class="scwc-lp-table">
					<thead><tr><th><?php esc_html_e( 'Feature', 'smart-categories-for-woocommerce' ); ?></th><th><?php esc_html_e( 'Free', 'smart-categories-for-woocommerce' ); ?></th><th><?php esc_html_e( 'Pro', 'smart-categories-for-woocommerce' ); ?></th></tr></thead>
					<tbody>
						<?php foreach ( self::comparison() as $row ) : ?>
							<?php if ( 'group' === $row[0] ) : ?>
								<tr class="scwc-lp-tgroup"><th colspan="3"><?php echo esc_html( $row[1] ); ?></th></tr>
							<?php else : ?>
								<tr>
									<td><?php echo esc_html( $row[0] ); ?></td>
									<td class="<?php echo esc_attr( $row[1] ? 'is-on' : 'is-off' ); ?>"><?php echo $row[1] ? esc_html( $yes ) : '—'; ?></td>
									<td class="<?php echo esc_attr( $row[2] ? 'is-on' : 'is-off' ); ?>"><?php echo $row[2] ? esc_html( $yes ) : '—'; ?></td>
								</tr>
							<?php endif; ?>
						<?php endforeach; ?>
					</tbody>
				</table>
			</section>

			<?php /* ---- Pricing ---- */ ?>
			<section class="scwc-lp-pricing">
				<h2 class="scwc-lp-h2"><?php esc_html_e( 'Simple yearly pricing', 'smart-categories-for-woocommerce' ); ?></h2>
				<div class="scwc-lp-tiers">
					<?php
					$tiers = array(
						array( __( 'Single Site', 'smart-categories-for-woocommerce' ), '$59', __( '1 site', 'smart-categories-for-woocommerce' ), false, self::PRICING_SINGLE ),
						array( __( 'Team', 'smart-categories-for-woocommerce' ), '$199', __( '5 sites', 'smart-categories-for-woocommerce' ), true, self::PRICING_TEAM ),
						array( __( 'Agency', 'smart-categories-for-woocommerce' ), '$499', __( '20 sites', 'smart-categories-for-woocommerce' ), false, self::PRICING_AGENCY ),
					);
					foreach ( $tiers as $t ) :
						?>
						<div class="scwc-lp-tier<?php echo $t[3] ? ' is-popular' : ''; ?>">
							<?php if ( $t[3] ) : ?><span class="scwc-lp-badge"><?php esc_html_e( 'Most popular', 'smart-categories-for-woocommerce' ); ?></span><?php endif; ?>
							<div class="scwc-lp-tier-name"><?php echo esc_html( $t[0] ); ?></div>
							<div class="scwc-lp-price"><?php echo esc_html( $t[1] ); ?><span>/<?php esc_html_e( 'year', 'smart-categories-for-woocommerce' ); ?></span></div>
							<div class="scwc-lp-tier-sites"><?php echo esc_html( $t[2] ); ?></div>
							<ul class="scwc-lp-tier-list">
								<li><?php esc_html_e( 'All Pro features', 'smart-categories-for-woocommerce' ); ?></li>
								<li><?php esc_html_e( '1 year of updates & support', 'smart-categories-for-woocommerce' ); ?></li>
								<li><?php esc_html_e( '14-day free trial', 'smart-categories-for-woocommerce' ); ?></li>
							</ul>
							<a class="scwc-lp-cta is-block" href="<?php echo esc_url( self::checkout_url( (int) $t[4] ) ); ?>"><?php esc_html_e( 'Buy now', 'smart-categories-for-woocommerce' ); ?></a>
						</div>
					<?php endforeach; ?>
				</div>
				<p class="scwc-lp-guarantee"><?php esc_html_e( 'Every plan includes a 14-day free trial (no card) and a 30-day money-back guarantee. Secure checkout by Freemius.', 'smart-categories-for-woocommerce' ); ?></p>
			</section>

			<?php /* ---- FAQ ---- */ ?>
			<section class="scwc-lp-faq">
				<h2 class="scwc-lp-h2"><?php esc_html_e( 'Questions', 'smart-categories-for-woocommerce' ); ?></h2>
				<?php
				$faqs = array(
					array( __( 'Is the free version limited?', 'smart-categories-for-woocommerce' ), __( 'No. The complete nested rule engine is free with no caps on the number of categories or rules. Pro adds the subcategory page generator and the time-window sales fields.', 'smart-categories-for-woocommerce' ) ),
					array( __( 'How does this help SEO?', 'smart-categories-for-woocommerce' ), __( 'Each attribute combination becomes a real, indexable category page with its own URL and product grid — the long-tail landing pages shoppers actually search for.', 'smart-categories-for-woocommerce' ) ),
					array( __( 'What happens when my catalog changes?', 'smart-categories-for-woocommerce' ), __( 'Everything stays in sync automatically. New products flow into the right pages, and new attribute values grow new pages on the daily refresh.', 'smart-categories-for-woocommerce' ) ),
					array( __( 'Will it slow down my store?', 'smart-categories-for-woocommerce' ), __( 'No. Generation runs in the background with a single grouped query, and shoppers browse plain category archives — zero extra queries on the storefront.', 'smart-categories-for-woocommerce' ) ),
					array( __( 'What happens if my licence expires?', 'smart-categories-for-woocommerce' ), __( 'Your generated pages keep working as normal categories. You only lose automatic growth, re-sync and updates until you renew.', 'smart-categories-for-woocommerce' ) ),
					array( __( 'How do I get Pro?', 'smart-categories-for-woocommerce' ), __( 'Checkout runs through Freemius right from this page; the licence activates automatically and updates arrive in your dashboard.', 'smart-categories-for-woocommerce' ) ),
				);
				foreach ( $faqs as $f ) :
					?>
					<div class="scwc-lp-q"><strong><?php echo esc_html( $f[0] ); ?></strong><p><?php echo esc_html( $f[1] ); ?></p></div>
				<?php endforeach; ?>
			</section>

			<?php /* ---- Closing CTA ---- */ ?>
			<section class="scwc-lp-band">
				<h2><?php esc_html_e( 'Build your SEO page library on autopilot', 'smart-categories-for-woocommerce' ); ?></h2>
				<a class="scwc-lp-cta is-light" href="<?php echo esc_url( $trial_url ); ?>"><?php esc_html_e( 'Start your 14-day free trial', 'smart-categories-for-woocommerce' ); ?></a>
			</section>
		</div>
		<?php
	}
}
