<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$title = isset( $title ) ? (string) $title : '';
$sub = isset( $sub ) ? (string) $sub : '';
$items = ( isset( $items ) && is_array( $items ) ) ? $items : array();
$columns = isset( $columns ) ? (int) $columns : 3;
$columns = in_array( $columns, array( 2, 3, 4 ), true ) ? $columns : 3;
$align = isset( $align ) && $align === 'left' ? 'left' : 'center';
$grid_cols = 'repeat(' . $columns . ', minmax(0, 1fr))';
?>
<section style="padding:60px 0;">
	<?php if ( $title !== '' ) : ?>
		<h2 style="margin:0 0 8px;text-align:<?php echo esc_attr( $align ); ?>;color:#fff;"><?php echo esc_html( $title ); ?></h2>
	<?php endif; ?>
	<?php if ( $sub !== '' ) : ?>
		<p style="margin:0 0 26px;text-align:<?php echo esc_attr( $align ); ?>;color:var(--avi-text-muted);"><?php echo esc_html( $sub ); ?></p>
	<?php endif; ?>
	<div style="display:grid;grid-template-columns:<?php echo esc_attr( $grid_cols ); ?>;gap:16px;">
		<?php foreach ( $items as $item ) : ?>
			<?php
			$icon = isset( $item['icon'] ) ? (string) $item['icon'] : '';
			$item_title = isset( $item['title'] ) ? (string) $item['title'] : '';
			$desc = isset( $item['desc'] ) ? (string) $item['desc'] : '';
			$cta = isset( $item['cta'] ) && is_array( $item['cta'] ) ? $item['cta'] : array();
			$highlight = ! empty( $item['highlight'] );
			$border = $highlight ? '1px solid rgba(59,111,212,0.9)' : '1px solid rgba(255,255,255,0.08)';
			$shadow = $highlight ? '0 0 0 2px rgba(59,111,212,0.2), 0 20px 45px rgba(0,0,0,0.25)' : '0 16px 36px rgba(0,0,0,0.2)';
			?>
			<article style="background:var(--avi-surface);border:<?php echo esc_attr( $border ); ?>;box-shadow:<?php echo esc_attr( $shadow ); ?>;border-radius:14px;padding:18px;">
				<div style="font-size:30px;margin-bottom:8px;"><?php echo esc_html( $icon ); ?></div>
				<h3 style="margin:0 0 8px;color:#fff;"><?php echo esc_html( $item_title ); ?></h3>
				<p style="margin:0;color:var(--avi-text-muted);line-height:1.6;"><?php echo esc_html( $desc ); ?></p>
				<?php if ( ! empty( $cta['label'] ) && ! empty( $cta['url'] ) ) : ?>
					<div style="margin-top:12px;">
						<a class="avi-nav-link" style="color:#fff;" href="<?php echo esc_url( (string) $cta['url'] ); ?>"><?php echo esc_html( (string) $cta['label'] ); ?></a>
					</div>
				<?php endif; ?>
			</article>
		<?php endforeach; ?>
	</div>
</section>
