<?php
defined( 'ABSPATH' ) || exit;
$avi_lang = 'en';
if ( function_exists( 'avi_get_current_lang' ) ) { $avi_lang = avi_get_current_lang(); }
if ( $avi_lang === 'en' && isset( $_SERVER['REQUEST_URI'] ) ) {
    $req = $_SERVER['REQUEST_URI'];
    if ( strpos( $req, '/fr/' ) === 0 ) { $avi_lang = 'fr'; }
    elseif ( strpos( $req, '/es/' ) === 0 ) { $avi_lang = 'es'; }
}
if ( $avi_lang !== 'en' ) { set_query_var( 'avi_lang', $avi_lang ); }
$is_fr = ( $avi_lang === 'fr' );
$is_es = ( $avi_lang === 'es' );

$avi_meta_title = function_exists( 'avi_get_content' )
	? avi_get_content( 'refer', 'meta_title', 'Refer — Avision' )
	: 'Refer — Avision';
$avi_meta_desc  = function_exists( 'avi_get_content' )
	? avi_get_content( 'refer', 'meta_desc', 'Invite agencies and local businesses to Avision.' )
	: 'Invite agencies and local businesses to Avision.';

avi_get_layout( 'header' );
?>

<?php
avi_component(
	'hero',
	array(
		'badge'       => 'Refer',
		'title'       => function_exists( 'avi_get_content' ) ? avi_get_content( 'refer', 'hero_title', 'Refer Avision' ) : 'Refer Avision',
		'subtitle'    => function_exists( 'avi_get_content' ) ? avi_get_content( 'refer', 'hero_sub', 'Share Avision with peers who manage Google Business Profiles and want consistent, scalable operations.' ) : 'Share Avision with peers who manage Google Business Profiles and want consistent, scalable operations.',
		'cta_primary' => array(
			'label' => 'Agency Access',
			'url'   => '/connexion/',
		),
		'align' => 'center',
		'size'  => 'small',
	)
);
?>

<section class="avi-content-section">
	<div class="avi-content-block">
		<?php
		$avi_body_override = function_exists( 'avi_get_content' ) ? (string) avi_get_content( 'refer', 'body', '' ) : '';
		if ( $avi_body_override !== '' ) {
			echo wp_kses_post( $avi_body_override );
		} else {
			?>
			<h2>For agencies</h2>
			<p>Log in to access your referral details and share your agency access link with partners.</p>

			<h2>For local businesses</h2>
			<p>Send them to the free audit to start with a visibility snapshot, then upgrade when ready.</p>

			<div class="avi-split" style="margin-top:18px">
				<div class="avi-info-card">
					<h3 style="margin-top:0">Agency Access</h3>
					<p style="margin:0 0 12px">For teams managing multiple locations.</p>
					<a class="avi-btn avi-btn--primary" href="<?php echo esc_url( home_url( '/connexion/' ) ); ?>">Agency Access →</a>
				</div>
				<div class="avi-info-card">
					<h3 style="margin-top:0">Start Free Audit</h3>
					<p style="margin:0 0 12px">For a first snapshot on one location.</p>
					<a class="avi-btn avi-btn--primary" href="<?php echo esc_url( home_url( '/local-audit/' ) ); ?>">Start Free Audit →</a>
				</div>
			</div>
			<?php
		}
		?>
	</div>
</section>

<?php avi_get_layout( 'footer' ); ?>

