<?php
if ( ! 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 = 'Legal & Privacy — Avision';
$avi_meta_desc  = function_exists( 'avi_get_content' )
	? avi_get_content( 'legal', 'meta_desc', 'Legal, privacy, API data policy, cookies and GDPR information for Avision.' )
	: 'Legal, privacy, API data policy, cookies and GDPR information for Avision.';
$avi_schema_json = array(
	'@context' => 'https://schema.org',
	'@type'    => 'WebPage',
	'name'     => 'Legal & Privacy — Avision',
	'url'      => 'https://avision.org/legal/',
);
$avi_last_updated = date_i18n( 'Y-m-d' );

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

$hero = array(
	'badge'    => 'Legal & Compliance',
	'title'    => function_exists( 'avi_get_content' ) ? avi_get_content( 'legal', 'hero_title', 'Legal & Privacy' ) : 'Legal & Privacy',
	'subtitle' => function_exists( 'avi_get_content' ) ? avi_get_content( 'legal', 'hero_sub', 'Advantage Synergies LLP — Registered in England & Wales' ) : 'Advantage Synergies LLP — Registered in England & Wales',
	'size'     => 'small',
);

Avision_Page_Template::render(
	'legal',
	$hero,
	static function () use ( $avi_schema_json, $avi_last_updated ) {
		?>
		<section class="avi-content-section">
			<div class="avi-content-block">
				<?php
				$avi_body_override = function_exists( 'avi_get_content' ) ? avi_get_content( 'legal', 'body', '' ) : '';
				if ( $avi_body_override !== '' ) {
					echo wp_kses_post( $avi_body_override );
				} else {
					?>
				<nav style="display:flex;gap:14px;flex-wrap:wrap;padding:10px 0 20px;">
					<a href="#privacy" class="avi-nav-link">Privacy Policy</a>
					<a href="#terms" class="avi-nav-link">Terms of Use</a>
					<a href="#api-data" class="avi-nav-link">API Data Policy</a>
					<a href="#cookies" class="avi-nav-link">Cookie Policy</a>
					<a href="#gdpr" class="avi-nav-link">GDPR</a>
				</nav>
				<section id="privacy">
					<h2>Privacy Policy</h2>
					<p>We process service data only to provide requested features, maintain security, and improve platform reliability.</p>
				</section>
				<section id="terms">
					<h2>Terms of Use</h2>
					<p>By using Avision, you agree to use the platform lawfully and in accordance with Google platform policies and our service terms.</p>
				</section>
				<section id="api-data">
					<h2>API Data Policy</h2>
					<p>Avision collects only Google Business Profile data for authorized locations connected through OAuth 2.0 user consent.</p>
					<ul>
						<li>Storage: encrypted at rest on EU-hosted servers.</li>
						<li>Retention: active account lifetime + 30 days after deletion.</li>
						<li>User rights: access, export, and deletion on request.</li>
						<li>Roles: Google is controller of source account data; Avision acts as data processor for service delivery.</li>
					</ul>
					<p>Google policy reference: <a href="https://policies.google.com/privacy" target="_blank" rel="noopener">Google Privacy Policy</a>.</p>
					<p>Data requests: <a href="/contact/" style="color:var(--avi-primary-light,#6B9FE8)">Contact us</a> (fallback: <a href="/contact/">Contact us</a>).</p>
				</section>
				<section id="cookies">
					<h2>Cookie Policy</h2>
					<p>Cookies are used for session continuity, security, and product analytics required for service operation.</p>
				</section>
				<section id="gdpr">
					<h2>GDPR</h2>
					<p>Data handling follows GDPR principles including purpose limitation, minimization, and security controls for processing activities.</p>
				</section>
				<section style="margin-top:26px;color:var(--avi-text-muted);font-size:13px;">
					<p>Last updated: <?php echo esc_html( $avi_last_updated ); ?></p>
					<p>Governing law: England &amp; Wales</p>
				</section>
					<?php
				}
				?>
			</div>
		</section>
		<script type="application/ld+json"><?php echo wp_json_encode( $avi_schema_json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); ?></script>
		<?php
	}
);
