<?php

use function Seventhqueen\Typer\typer;

if ( $query->have_posts() ) {

	$key = 1;
	while ( $query->have_posts() ) {
		$query->the_post();

		typer()->set_post_data( 'media_width', $params['typer_settings']['media_width'] );
		typer()->set_post_data( 'media_size', $params['typer_settings']['media_size'] );
		typer()->set_post_data( 'media_aspect_ratio', $params['typer_settings']['media_aspect_ratio'] );
		typer()->set_post_data( 'show_category', (bool) $params['typer_settings']['show_category'] );
		typer()->set_post_data( 'show_meta', (bool) $params['typer_settings']['show_meta'] );
		typer()->set_post_data( 'show_excerpt', (bool) $params['typer_settings']['show_excerpt'] );

		if ( $params['typer_settings']['listing'] === 'list' ) {
			typer()->set_post_data( 'media_position', $params['typer_settings']['image_position'] );
		}

		if ( $params['typer_settings']['listing'] === 'grid' ) {
			typer()->set_post_data( 'grid_span', 'svq-grid-span-2' );
		}

		if ( $key === 1 && $params['typer_settings']['listing'] === 'masonry' && $params['typer_settings']['big_post'] ) {
			typer()->set_post_data( 'grid_span', 'svq-masonry-span' );
		}

		if ( $params['typer_settings']['listing'] === 'list-big' ) {
			$components = [
				'categories',
				'title',
				'meta',
				'media',
				'excerpt'
			];
			typer()->get_template_part( 'template-parts/archive/article-box', null, compact( 'components' ) );
		} else {
			typer()->get_template_part( 'template-parts/archive/article-box' );
		}

		$key ++;
	}
}
