<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$avi_meta_title = 'How It Works — Avision';
$avi_meta_desc  = function_exists( 'avi_get_content' )
	? avi_get_content( 'how-it-works', 'meta_desc', 'Local SEO execution, running 24/7 with Guardian Mode, Growth Radar and AVI Intelligence.' )
	: 'Local SEO execution, running 24/7 with Guardian Mode, Growth Radar and AVI Intelligence.';
$avi_schema_json = array(
	'@context' => 'https://schema.org',
	'@graph'   => array(
		array(
			'@type' => 'WebPage',
			'name'  => 'How It Works — Avision',
			'url'   => 'https://avision.org/how-it-works/',
		),
		array(
			'@type' => 'HowTo',
			'name'  => 'How Google Integration Works',
			'step'  => array(
				array( '@type' => 'HowToStep', 'name' => 'Create your Avision account (2 minutes)' ),
				array( '@type' => 'HowToStep', 'name' => 'Authorize Google Business Profile via OAuth 2.0' ),
				array( '@type' => 'HowToStep', 'name' => 'AVI scans and analyzes your profile (60 seconds)' ),
				array( '@type' => 'HowToStep', 'name' => 'Guardian activates and protection starts immediately' ),
			),
		),
	),
);

if ( ! class_exists( 'Avision_Page_Template' ) ) {
	require_once AVISION_PLUGIN_DIR . 'includes/class-avision-page-template.php';
}

$hero = array(
	'badge'         => 'Simple. Powerful. Automated.',
	'title'         => function_exists( 'avi_get_content' ) ? avi_get_content( 'how-it-works', 'hero_title', 'Local SEO Execution, Running 24/7' ) : 'Local SEO Execution, Running 24/7',
	'subtitle'      => function_exists( 'avi_get_content' ) ? avi_get_content( 'how-it-works', 'hero_sub', 'Connect your Google Business Profile. AVI does the rest.' ) : 'Connect your Google Business Profile. AVI does the rest.',
	'cta_primary'   => array(
		'label' => function_exists( 'avi_get_content' ) ? avi_get_content( 'how-it-works', 'cta_label', 'See Plans' ) : 'See Plans',
		'url'   => function_exists( 'avi_get_content' ) ? avi_get_content( 'how-it-works', 'cta_url', '/agency-pricing/' ) : '/agency-pricing/',
	),
	'cta_secondary' => array(
		'label' => 'See Agency Plans',
		'url'   => '/agency-pricing/',
	),
);

Avision_Page_Template::render(
	'how-it-works',
	$hero,
	static function () use ( $avi_schema_json ) {
		?>
		<section class="avi-content-section">
			<div class="avi-content-block">
				<?php
				$avi_body_override = function_exists( 'avi_get_content' ) ? avi_get_content( 'how-it-works', 'body', '' ) : '';
				if ( $avi_body_override !== '' ) {
					echo wp_kses_post( $avi_body_override );
				} else {
					?>
				<h2>Three Products, One Platform</h2>
				<div class="avi-split avi-split--3" style="padding:0;">
					<article class="avi-info-card" style="margin:0;">
						<h3>Guardian Mode</h3>
						<ul>
							<li>24/7 monitoring of your GBP</li>
							<li>Auto-responds to reviews with AVI Intelligence</li>
							<li>Detects and corrects unauthorized changes</li>
							<li>Publishes optimized posts on schedule</li>
						</ul>
					</article>
					<article class="avi-info-card" style="margin:0;">
						<h3>Growth Radar</h3>
						<ul>
							<li>Tracks keyword positions weekly or daily</li>
							<li>Competitor intelligence</li>
							<li>DataForSEO-powered real data</li>
							<li>Alerts when rankings drop</li>
						</ul>
					</article>
					<article class="avi-info-card" style="margin:0;">
						<h3>AVI Intelligence Chat</h3>
						<ul>
							<li>Ask your local SEO consultant anything</li>
							<li>Personalized to your business, city, sector</li>
							<li>Progression levels tailored to each business context</li>
							<li>Powered by OpenRouter multi-model engine</li>
						</ul>
					</article>
				</div>
				<h2>How Google Integration Works</h2>
				<ol class="avi-steps">
					<li>Create your Avision account (2 minutes)</li>
					<li>Authorize Google Business Profile via OAuth 2.0</li>
					<li>AVI scans and analyzes your profile (60 seconds)</li>
					<li>Guardian activates — protection starts immediately</li>
				</ol>
				<?php
				$avi_lang = 'en';
				include __DIR__ . '/../partials/avi-gbp-notice.php';
				?>
				<h2>For Agencies</h2>
				<p>Manage local SEO at fleet scale with agency dashboards, tiered wholesale plans and centralized monitoring.</p>
				<a class="avi-btn avi-btn--primary" href="<?php echo esc_url( home_url( '/agency-pricing/' ) ); ?>">View Agency Plans</a>
					<?php
				}
				?>
			</div>
		</section>
		<script type="application/ld+json"><?php echo wp_json_encode( $avi_schema_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); ?></script>
		<?php
	}
);
