<?php
/**
 * Assets — centralized registration of scripts and styles.
 *
 * Modules request the assets they need via the enqueue_* methods here, so all
 * versioning is tied to PLATFORM_HELM_VERSION in one place and cache-busts on
 * every update. Each module only loads its assets on its own screens.
 *
 * @package Platform\Helm\Core
 */

declare( strict_types = 1 );

namespace Platform\Helm\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class Assets {

	/**
	 * Shared admin CSS. Safe to call multiple times — WordPress de-dupes by
	 * handle, so each module can request it without coordinating.
	 */
	public function enqueue_admin_css(): void {
		wp_enqueue_style(
			'platform-helm-admin',
			PLATFORM_HELM_URL . 'assets/css/admin.css',
			[],
			PLATFORM_HELM_VERSION
		);
	}

	/**
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_link_suggester( array $localize ): void {
		wp_enqueue_script(
			'platform-helm-link-suggester',
			PLATFORM_HELM_URL . 'assets/js/link-suggester.js',
			[ 'jquery' ],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-link-suggester', 'PlatformHelmLS', $localize );
		$this->enqueue_admin_css();
	}

	/**
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_link_architect( array $localize ): void {
		wp_enqueue_script(
			'platform-helm-link-architect',
			PLATFORM_HELM_URL . 'assets/js/link-architect.js',
			[], // Vanilla JS — no jQuery dependency.
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-link-architect', 'PlatformHelmLA', $localize );
		$this->enqueue_admin_css();
	}

	/**
	 * AI Visibility Check (AEO) editor panel assets.
	 */
	public function enqueue_aeo(): void {
		wp_enqueue_style(
			'platform-helm-aeo',
			PLATFORM_HELM_URL . 'assets/css/aeo-check.css',
			[],
			PLATFORM_HELM_VERSION
		);
		wp_enqueue_script(
			'platform-helm-aeo',
			PLATFORM_HELM_URL . 'assets/js/aeo-check.js',
			[],
			PLATFORM_HELM_VERSION,
			true
		);
	}

	/**
	 * Schema meta box (editor panel) assets. Self-contained stylesheet +
	 * vanilla-JS script; the script handle is reused by SchemaMetaBox for
	 * wp_localize_script(), so the handle name must stay 'platform-helm-schema'.
	 */
	public function enqueue_schema_metabox(): void {
		wp_enqueue_style(
			'platform-helm-schema',
			PLATFORM_HELM_URL . 'assets/css/schema-metabox.css',
			[],
			PLATFORM_HELM_VERSION
		);
		wp_enqueue_script(
			'platform-helm-schema',
			PLATFORM_HELM_URL . 'assets/js/schema-metabox.js',
			[],
			PLATFORM_HELM_VERSION,
			true
		);
	}

	/**
	 * Ghost Purge admin screen assets.
	 *
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_ghost_purge( array $localize ): void {
		wp_enqueue_script(
			'platform-helm-ghost-purge',
			PLATFORM_HELM_URL . 'assets/js/ghost-purge.js',
			[ 'jquery' ],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-ghost-purge', 'PlatformHelmGP', $localize );
		$this->enqueue_admin_css();
	}

	/**
	 * Link Assassin admin screen assets.
	 *
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_link_assassin( array $localize ): void {
		wp_enqueue_script(
			'platform-helm-link-assassin',
			PLATFORM_HELM_URL . 'assets/js/link-assassin.js',
			[ 'jquery' ],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-link-assassin', 'PlatformHelmLAS', $localize );
		$this->enqueue_admin_css();
	}

	/**
	 * Shared SEO-reports base styles (Helm admin CSS + GSC stylesheet).
	 */
	public function enqueue_seo_reports(): void {
		$this->enqueue_admin_css();
		wp_enqueue_style(
			'platform-helm-gsc',
			PLATFORM_HELM_URL . 'assets/css/gsc.css',
			[],
			PLATFORM_HELM_VERSION
		);
	}

	/**
	 * Search Console connector screen assets.
	 *
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_gsc( array $localize ): void {
		wp_enqueue_style(
			'platform-helm-gsc',
			PLATFORM_HELM_URL . 'assets/css/gsc.css',
			[],
			PLATFORM_HELM_VERSION
		);
		wp_enqueue_script(
			'platform-helm-gsc',
			PLATFORM_HELM_URL . 'assets/js/gsc.js',
			[],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-gsc', 'PlatformHelmGsc', $localize );
	}

	/**
	 * Index-coverage screen assets.
	 *
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_gsc_index( array $localize ): void {
		$this->enqueue_seo_reports();
		wp_enqueue_script(
			'platform-helm-gsc-index',
			PLATFORM_HELM_URL . 'assets/js/gsc-index.js',
			[],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-gsc-index', 'PlatformHelmGscIndex', $localize );
	}

	/**
	 * Content Auditor screen assets.
	 *
	 * @param array<string,mixed> $localize
	 */
	public function enqueue_content_auditor( array $localize ): void {
		wp_enqueue_style(
			'platform-helm-content-auditor',
			PLATFORM_HELM_URL . 'assets/css/content-auditor.css',
			[],
			PLATFORM_HELM_VERSION
		);
		wp_enqueue_script(
			'platform-helm-content-auditor',
			PLATFORM_HELM_URL . 'assets/js/content-auditor.js',
			[],
			PLATFORM_HELM_VERSION,
			true
		);
		wp_localize_script( 'platform-helm-content-auditor', 'PlatformHelmAudit', $localize );
	}
}
