<?php
/**
 * Blog layout section.
 *
 * Author:          Andrei Baicus <andrei@themeisle.com>
 * Created on:      20/08/2018
 *
 * @package Neve\Customizer\Options
 */

namespace Neve\Customizer\Options;

use Neve\Core\Settings\Config;
use Neve\Core\Settings\Mods;
use Neve\Customizer\Base_Customizer;
use Neve\Customizer\Defaults\Layout;
use Neve\Customizer\Defaults\Utils;
use Neve\Customizer\Types\Control;
use Neve\Customizer\Types\Section;

/**
 * Class Layout_Blog
 *
 * @package Neve\Customizer\Options
 */
class Layout_Blog extends Base_Customizer {
	use Layout;
	use Utils;

	/**
	 * Holds the section name.
	 *
	 * @var string $section
	 */
	private $section = 'neve_blog_archive_layout';

	/**
	 * Function that should be extended to add customizer controls.
	 *
	 * @return void
	 */
	public function add_controls() {
		$this->section_blog();
		$this->add_layout_controls();
		$this->add_post_structure();
		$this->add_post_meta_controls();
		$this->add_featured_post();
		$this->add_design_controls();

		add_action( 'customize_register', [ $this, 'adapt_old_pro' ], PHP_INT_MAX );
	}

	/**
	 * Adapting old pro versions to make them still usable with the old theme version.
	 */
	public function adapt_old_pro() {
		if ( ! defined( 'NEVE_PRO_VERSION' ) ) {
			return;
		}

		if ( version_compare( NEVE_PRO_VERSION, '1.2.8', '>' ) ) {
			return;
		}

		$changes = [
			'neve_posts_order'                   => [ 'priority' => 51 ],
			'neve_post_content_ordering'         => [ 'active_callback' => '__return_true' ],
			'neve_blog_ordering_content_heading' => [ 'controls_to_wrap' => 6 ],
			'neve_blog_post_meta_heading'        => [ 'controls_to_wrap' => 3 ],
			'neve_read_more_options'             => [
				'accordion' => true,
				'expanded'  => false,
				'class'     => 'read-more-options-accordion',
			],
		];

		foreach ( $changes as $control_slug => $props ) {
			foreach ( $props as $prop => $new_value ) {
				$this->change_customizer_object( 'control', $control_slug, $prop, $new_value );
			}
		}

		$this->wpc->remove_control( 'neve_metadata_options' );
	}

	/**
	 * Get the tab slotting for the controls.
	 *
	 * @return array
	 */
	private function get_tabs_slotting() {
		$tab_slotting = [
			'general' => [
				'neve_blog_layout_heading',
				'neve_blog_archive_sidebar_layout',
				'neve_blog_archive_content_width',
				$this->section,
				'neve_grid_layout',
				'neve_archive_hide_title',

				'neve_enable_masonry',
				Config::OPTION_POSTS_PER_PAGE,

				'neve_enable_featured_post',
				'neve_featured_post_target',

				'neve_post_content_ordering',
				'neve_post_excerpt_length',

				'neve_blog_post_meta_fields',

				'neve_blog_archive_upsell_control_features',
			],
			'style'   => [
				'neve_blog_content_padding',

				'neve_enable_card_style',
				'neve_blog_grid_card_bg_color',
				'neve_blog_grid_text_color',
				'neve_blog_card_shadow',
				'neve_blog_covers_text_color',
				'neve_blog_items_border_radius',

				'neve_archive_typography_post_title_accordion_wrap',
				'neve_archive_typography_post_title',
				'neve_archive_typography_post_excerpt_accordion_wrap',
				'neve_archive_typography_post_excerpt',
				'neve_archive_typography_post_meta_accordion_wrap',
				'neve_archive_typography_post_meta',

				'neve_blog_archive_upsell_control_features',
			],
		];

		foreach ( $tab_slotting as $tab_key => $tab_data ) {
			$tab_slotting[ $tab_key ] = array_fill_keys( $tab_data, [] );
		}

		return $tab_slotting;
	}


	/**
	 * Add customize section
	 */
	private function section_blog() {
		$this->add_section(
			new Section(
				$this->section,
				array(
					'priority' => 35,
					'title'    => esc_html__( 'Blog / Archive', 'neve' ),
					'panel'    => 'neve_blog',
				)
			)
		);
		$this->add_control(
			new Control(
				$this->section . '_tabs',
				[
					'transport' => 'refresh',
				],
				[
					'priority' => -100,
					'section'  => $this->section,
					'tabs'     => [
						'general' => [
							'label' => __( 'General', 'neve' ),
							'icon'  => 'layout',
						],
						'style'   => [
							'label' => __( 'Design', 'neve' ),
							'icon'  => 'admin-customizer',
						],
					],
					'controls' => $this->get_tabs_slotting(),
				],
				'Neve\Customizer\Controls\Tabs'
			)
		);
	}


	/**
	 * Add blog layout controls.
	 */
	private function add_layout_controls() {
		$layout_id = 'neve_blog_archive_sidebar_layout';
		$width_id  = 'neve_blog_archive_content_width';

		$this->add_control(
			new Control(
				$layout_id,
				array(
					'sanitize_callback' => array( $this, 'sanitize_sidebar_layout' ),
					'default'           => $this->sidebar_layout_alignment_default( $layout_id ),
				),
				array(
					'label'       => __( 'Sidebar Layout', 'neve' ),
					'description' => $this->get_sidebar_control_description( $layout_id ),
					'section'     => $this->section,
					'priority'    => 10,
					'choices'     => $this->sidebar_layout_choices( $layout_id ),
				),
				'\Neve\Customizer\Controls\React\Radio_Image'
			)
		);

		$width_default = $this->sidebar_layout_width_default( $width_id );

		$this->add_control(
			new Control(
				$width_id,
				array(
					'sanitize_callback' => 'absint',
					'transport'         => $this->selective_refresh,
					'default'           => $width_default,
				),
				array(
					'label'       => esc_html__( 'Content Width (%)', 'neve' ),
					'section'     => $this->section,
					'type'        => 'neve_range_control',
					'input_attrs' => [
						'min'        => 50,
						'max'        => 100,
						'defaultVal' => $width_default,
					],
					'priority'    => 20,
				),
				'Neve\Customizer\Controls\React\Range'
			)
		);

		$this->add_control(
			new Control(
				$this->section,
				[
					'default'           => 'grid',
					'sanitize_callback' => [ $this, 'sanitize_blog_layout' ],
				],
				[
					'section'  => $this->section,
					'label'    => esc_html__( 'Post Cards Layout', 'neve' ),
					'priority' => 30,
					'choices'  => [
						'default' => [
							'name'  => __( 'List', 'neve' ),
							'image' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF4AAAB5CAYAAACwe5bgAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5AkBDC0qBiacfQAABqdJREFUeNrtXU1T40YQfT2WLS/s4kqR5UAK36jiAKdQ+/8vnOKcIIeEG6RSKZZDcIqwXmA6B0nWSOZjbI00Gqn7YooCWXp601/zZoaYmSHWuCmBQIAX4MUEeAFeTIAX4MUEeAFerAngnde8Or90wwV109+nKoFN7m8nuzwRdZrxkc0ffX8Ebh+AhBS8BCZhSXWAfvwIxIOa3qUl25t+0ZHN8F88Kfw5Z4ApgYY4xZ8cPDTwaZwAvwIAN/MmfIyuyGb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rQikHuAyXCm6sICxNE2ONFCC9CeBHCixBehPAihBchvAjhRQgvQniR8O3kJ0Nx/wAXONq4kNEpFQAAAABJRU5ErkJggg==',
						],
						'grid'    => [
							'name'  => __( 'Grid', 'neve' ),
							'image' => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAB5AF4DAREAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+/igAoAKACgAoAKACgAoAKACgAoAKACgD5d8deO/FuleLNZ0/T9ZmtrO2nhWCBYLN1jVrS3kYBpLd3OXdm+Zj1x0w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N8Q7yzi8Z67G/iD9pezdbiDdbeCYJJPC0RNlbHGjsIGBhOd0uGOLppx2oA4v8AtCx/6Gn9sH/wFl/+R6APX/D/AMK7jxDo1hrUHxZ+PenRahEZo7LWPEiWGp26iR49t3Ztp7tBIdm8IWJMbI38WKAJfinbRaDpXgnS7rxJ8cHeytNTtRqXw9Y32paobdNJRrnxbcRwYluj8rWMuyPzXl1NgvUAA8b/ALQsf+hp/bB/8BZf/kegDvfBXg7/AIThdRez+JH7SmhjTWtVk/4SjU/7FNybsXBX7EJbGX7SIfs5+0EbfK82DOfMGAD0jUPCTeC/AfiqG68a/FjxCt19juP7RtdTGr+MtPCXNtH5Xhxo7WExiViDdR7H3W5uGyBQB89f2hY/9DT+2D/4Cy//ACPQBteHbS38SazY6Jb+Nv2rtOmv5JI0vdZd9P0yAxwyzlru8e0dYEYRFEYqd0rRp/FmgD3zwx8L7rw3rVprEnxL+JniJLVbhTpHiPxHHqGkXP2i2ltwbm1WxhMjQGUXEBEi7LiKJ+QuCAer0AFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFABQAUAD/2Q==',
						],
					],
				],
				'\Neve\Customizer\Controls\React\Radio_Image'
			)
		);

		$grid_layout_default = '{"desktop":3,"tablet":2,"mobile":1}';

		$this->add_control(
			new Control(
				'neve_grid_layout',
				array(
					'sanitize_callback' => 'neve_sanitize_range_value',
					'default'           => $grid_layout_default,
				),
				array(
					'label'           => esc_html__( 'Columns', 'neve' ),
					'section'         => $this->section,
					'units'           => array(
						'items',
					),
					'input_attrs'     => [
						'min'        => 1,
						'max'        => 4,
						'defaultVal' => json_decode( $grid_layout_default, true ),
					],
					'priority'        => 50,
					'active_callback' => array( $this, 'is_column_layout' ),
				),
				'Neve\Customizer\Controls\React\Responsive_Range'
			)
		);

		$posts_per_page = get_option( Config::OPTION_POSTS_PER_PAGE );

		$this->wpc->add_setting(
			Config::OPTION_POSTS_PER_PAGE,
			[
				'type'              => 'option',
				'sanitize_callback' => 'absint',
				'default'           => absint( $posts_per_page ),
			]
		);

		$this->wpc->add_control(
			new \Neve\Customizer\Controls\React\Range(
				$this->wpc,
				Config::OPTION_POSTS_PER_PAGE,
				[
					'type'        => 'neve_range_control',
					'priority'    => 52,
					'section'     => $this->section,
					'label'       => esc_html__( 'Posts per Page', 'neve' ),
					'input_attrs' => [
						'min'        => 1,
						'max'        => 100,
						'defaultVal' => absint( $posts_per_page ),
					],
					'setting'     => Config::OPTION_POSTS_PER_PAGE,
					'default'     => absint( $posts_per_page ),
				]
			)
		);

		$this->add_control(
			new Control(
				'neve_archive_hide_title',
				[
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => $this->get_v4_defaults( 'neve_archive_hide_title', false ),
				],
				[
					'label'           => esc_html__( 'Disable Title', 'neve' ),
					'section'         => $this->section,
					'type'            => 'neve_toggle_control',
					'priority'        => 70,
					'active_callback' => function () {
						return get_option( 'show_on_front' ) !== 'posts';
					},
				],
				'Neve\Customizer\Controls\Checkbox'
			)
		);

		$this->add_control(
			new Control(
				'neve_enable_masonry',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'type'            => 'neve_toggle_control',
					'priority'        => 55,
					'section'         => $this->section,
					'label'           => esc_html__( 'Enable Masonry', 'neve' ),
					'active_callback' => array( $this, 'should_show_masonry' ),
				)
			)
		);
	}

	/**
	 * Add featured post controls.
	 */
	private function add_featured_post() {
		$this->add_control(
			new Control(
				'neve_enable_featured_post',
				[
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				],
				[
					'label'    => esc_html__( 'Enable featured post section', 'neve' ),
					'section'  => $this->section,
					'type'     => 'neve_toggle_control',
					'priority' => 260,
				],
				'Neve\Customizer\Controls\Checkbox'
			)
		);

		$this->add_control(
			new Control(
				'neve_featured_post_target',
				array(
					'default'           => 'latest',
					'sanitize_callback' => array( $this, 'sanitize_featured_post_target' ),
				),
				array(
					'label'           => esc_html__( 'Featured Post', 'neve' ),
					'section'         => $this->section,
					'priority'        => 270,
					'type'            => 'select',
					'choices'         => [
						'latest' => esc_html__( 'Latest Post', 'neve' ),
						'sticky' => esc_html__( 'Sticky Post', 'neve' ),
					],
					'active_callback' => function () {
						return get_theme_mod( 'neve_enable_featured_post', false );
					},
				)
			)
		);
	}

	/**
	 * Add post structure controls.
	 */
	private function add_post_structure() {
		$order_default_components = array(
			'thumbnail',
			'title-meta',
			'excerpt',
		);


		$ar_choices = [
			'original' => esc_html__( 'Original', 'neve' ),
			'1-1'      => '1:1',
			'4-3'      => '4:3',
			'16-9'     => '16:9',
			'2-1'      => '2:1',
			'4-5'      => '4:5',
			'3-4'      => '3:4',
			'2-3'      => '2:3',
		];

		$excerpt_length_default = $this->get_v4_defaults( 'neve_post_excerpt_length', 25 );

		$components = array(
			'thumbnail'  => [
				'label'    => __( 'Thumbnail', 'neve' ),
				'controls' => [
					'neve_blog_archive_aspect_ratio' => [
						'label'   => esc_html__( 'Image Aspect Ratio', 'neve' ),
						'type'    => 'select',
						'choices' => $ar_choices,
					],
				],
			],
			'title-meta' => [
				'label'    => __( 'Title & Meta', 'neve' ),
				'controls' => [
					'neve_metadata_separator'     => [
						'label'       => esc_html__( 'Meta Separator', 'neve' ),
						'description' => esc_html__( 'For special characters make sure to use Unicode. For example > can be displayed using \003E.', 'neve' ),
						'type'        => 'text',
					],
					'neve_show_last_updated_date' => [
						'label' => esc_html__( 'Show Last Updated Date', 'neve' ),
						'type'  => 'toggle',
					],
					'neve_author_avatar'          => [
						'label' => esc_html__( 'Show Author Avatar', 'neve' ),
						'type'  => 'toggle',
					],
					'neve_author_avatar_size'     => [
						'type'  => 'responsive-range',
						'label' => esc_html__( 'Author Avatar Size', 'neve' ),
					],
				],
			],
			'excerpt'    => [
				'label'    => __( 'Excerpt', 'neve' ),
				'controls' => [
					'neve_post_excerpt_length' => [
						'label' => esc_html__( 'Excerpt Length', 'neve' ),
						'type'  => 'range',
						'attrs' => [
							'min'        => 5,
							'max'        => 300,
							'defaultVal' => $excerpt_length_default,
							'step'       => 5,
						],
					],
				],
			],
		);

		$this->add_control(
			new Control(
				'neve_post_content_ordering',
				array(
					'sanitize_callback' => array( $this, 'sanitize_post_content_ordering' ),
					'default'           => wp_json_encode( $order_default_components ),
				),
				array(
					'label'      => esc_html__( 'Post Content Order', 'neve' ),
					'section'    => $this->section,
					'components' => $components,
					'priority'   => 65,
				),
				'Neve\Customizer\Controls\React\Ordering'
			)
		);

		$this->add_control(
			new Control(
				'neve_blog_archive_aspect_ratio',
				[
					'default'           => $this->get_v4_defaults( 'neve_blog_archive_aspect_ratio', 'original' ),
					'sanitize_callback' => function( $value ) use ( $ar_choices ) {
						return array_key_exists( $value, $ar_choices ) ? $value : 'original';
					},
				],
				[
					'section'         => $this->section,
					'type'            => 'hidden',
					'active_callback' => function() {
						return get_theme_mod( $this->section, 'grid' ) !== 'default' || get_theme_mod( 'neve_blog_list_image_position', 'left' ) !== 'no';
					},
				]
			)
		);

		$this->add_control(
			new Control(
				'neve_post_excerpt_length',
				array(
					'sanitize_callback' => 'absint',
					'default'           => $excerpt_length_default,
				),
				array(
					'section' => $this->section,
					'type'    => 'hidden',
				)
			)
		);



		$this->add_control(
			new Control(
				'neve_metadata_separator',
				array(
					'sanitize_callback' => 'sanitize_text_field',
					'default'           => esc_html( '/' ),
				),
				array(
					'section' => $this->section,
					'type'    => 'hidden',
				)
			)
		);


		$this->add_control(
			new Control(
				'neve_author_avatar',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'   => esc_html__( 'Show Author Avatar', 'neve' ),
					'section' => $this->section,
					'type'    => 'hidden',
				)
			)
		);


		$this->add_control(
			new Control(
				'neve_author_avatar_size',
				array(
					'sanitize_callback' => 'neve_sanitize_range_value',
					'default'           => '{ "mobile": 20, "tablet": 20, "desktop": 20 }',
				),
				array(
					'label'           => esc_html__( 'Avatar Size', 'neve' ),
					'type'            => 'hidden',
					'section'         => $this->section,
					'units'           => array(
						'px',
					),
					'input_attr'      => array(
						'mobile'  => array(
							'min'          => 20,
							'max'          => 50,
							'default'      => 20,
							'default_unit' => 'px',
						),
						'tablet'  => array(
							'min'          => 20,
							'max'          => 50,
							'default'      => 20,
							'default_unit' => 'px',
						),
						'desktop' => array(
							'min'          => 20,
							'max'          => 50,
							'default'      => 20,
							'default_unit' => 'px',
						),
					),
					'input_attrs'     => [
						'units'      => [ 'px', 'em', 'rem' ],
						'min'        => self::RELATIVE_CSS_UNIT_SUPPORTED_MIN_VALUE,
						'max'        => 50,
						'defaultVal' => [
							'mobile'  => 20,
							'tablet'  => 20,
							'desktop' => 20,
							'suffix'  => [
								'mobile'  => 'px',
								'tablet'  => 'px',
								'desktop' => 'px',
							],
						],
					],
					'priority'        => 170,
					'active_callback' => function () {
						return get_theme_mod( 'neve_author_avatar', false ) && $this->is_meta_enabled();
					},
					'responsive'      => true,
				),
				'Neve\Customizer\Controls\React\Responsive_Range'
			)
		);

		$this->add_control(
			new Control(
				'neve_show_last_updated_date',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => false,
				),
				array(
					'label'           => esc_html__( 'Use last updated date instead of the published one', 'neve' ),
					'section'         => $this->section,
					'type'            => 'hidden',
					'priority'        => 180,
					'active_callback' => [ $this, 'is_meta_enabled' ],
				)
			)
		);

	}

	/**
	 * Add controls for post meta.
	 */
	private function add_post_meta_controls() {
		$default       = wp_json_encode( [ 'author', 'date', 'comments' ] );
		$default_value = neve_get_default_meta_value( 'neve_post_meta_ordering', $default );
		$this->add_control(
			new Control(
				'neve_blog_post_meta_fields',
				[
					'sanitize_callback' => 'neve_sanitize_meta_repeater',
					'default'           => wp_json_encode( $default_value ),
				],
				[
					'label'            => esc_html__( 'Post Meta Order', 'neve' ),
					'section'          => $this->section,
					'fields'           => [
						'hide_on_mobile' => [
							'type'  => 'checkbox',
							'label' => __( 'Hide on mobile', 'neve' ),
						],
					],
					'components'       => apply_filters(
						'neve_meta_filter',
						array(
							'author'   => __( 'Author', 'neve' ),
							'category' => __( 'Category', 'neve' ),
							'date'     => __( 'Date', 'neve' ),
							'comments' => __( 'Comments', 'neve' ),
						)
					),
					'allow_new_fields' => 'no',
					'priority'         => 65,
					'active_callback'  => [ $this, 'is_meta_enabled' ],
				],
				'\Neve\Customizer\Controls\React\Repeater'
			)
		);
	}

	/**
	 * Sanitize the container layout value
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_blog_layout( $value ) {
		$allowed_values = array( 'default', 'covers', 'grid' );
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'grid';
		}

		return sanitize_text_field( $value );
	}

	/**
	 * Sanitize featured post target
	 *
	 * @param string $value value from the control.
	 *
	 * @return string
	 */
	public function sanitize_featured_post_target( $value ) {
		$allowed_values = [ 'sticky', 'latest' ];
		if ( ! in_array( $value, $allowed_values, true ) ) {
			return 'latest';
		}

		return esc_html( $value );
	}

	/**
	 * Sanitize content order control.
	 */
	public function sanitize_post_content_ordering( $value ) {
		$allowed = array(
			'thumbnail',
			'title-meta',
			'excerpt',
		);

		if ( empty( $value ) ) {
			return wp_json_encode( $allowed );
		}

		$decoded = json_decode( $value, true );

		foreach ( $decoded as $val ) {
			if ( ! in_array( $val, $allowed, true ) ) {
				return wp_json_encode( $allowed );
			}
		}

		return $value;
	}

	/**
	 * Checks if the post meta is enabled.
	 *
	 * @return bool
	 */
	public function is_meta_enabled() {
		return in_array( 'title-meta', $this->get_post_elements_order(), true );
	}

	/**
	 * Checks if the excerpt is enabled.
	 *
	 * @return bool
	 */
	public function is_excerpt_enabled() {
		return in_array( 'excerpt', $this->get_post_elements_order(), true );
	}

	/**
	 * Checks if the thumbnail is enabled.
	 *
	 * @return bool
	 */
	public function is_thumbnail_enabled() {
		return in_array( 'thumbnail', $this->get_post_elements_order(), true );
	}

	/**
	 * Get the post elements order.
	 *
	 * @return array
	 */
	private function get_post_elements_order() {
		$default       = array(
			'thumbnail',
			'title-meta',
			'excerpt',
		);
		$content_order = get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default ) );
		$content_order = json_decode( $content_order, true );

		return is_array( $content_order ) ? $content_order : $default;
	}

	/**
	 * Callback to show grid columns control.
	 *
	 * @return bool
	 */
	public function is_column_layout() {
		$blog_layout = get_theme_mod( $this->section, 'grid' );

		return in_array( $blog_layout, [ 'grid', 'covers' ], true );
	}

	/**
	 * Checks if the layout is covers.
	 *
	 * @return bool
	 */
	public function is_covers_layout() {
		return get_theme_mod( $this->section, 'grid' ) === 'covers';
	}


	/**
	 * Callback to show masonry control.
	 *
	 * @return bool
	 */
	public function should_show_masonry() {
		if ( ! $this->is_column_layout() ) {
			return false;
		}

		$columns = json_decode( get_theme_mod( 'neve_grid_layout', $this->grid_columns_default() ), true );
		$columns = array_filter(
			array_values( $columns ),
			function ( $value ) {
				return $value > 1;
			}
		);

		if ( empty( $columns ) ) {
			return false;
		}

		return true;
	}


	/**
	 * Adds design tab controls.
	 */
	private function add_design_controls() {
		$this->add_control(
			new Control(
				'neve_blog_covers_text_color',
				array(
					'sanitize_callback' => 'neve_sanitize_colors',
					'default'           => '#ffffff',
					'transport'         => 'postMessage',
				),
				array(
					'label'                 => esc_html__( 'Text Color', 'neve' ),
					'section'               => $this->section,
					'priority'              => 220,
					'default'               => '#ffffff',
					'active_callback'       => function () {
						return get_theme_mod( $this->section ) === 'covers';
					},
					'live_refresh_selector' => true,
					'live_refresh_css_prop' => [
						'cssVar' => [
							'vars'     => '--color',
							'selector' => '.neve-main',
						],
					],
				),
				'Neve\Customizer\Controls\React\Color'
			)
		);

		$this->add_control(
			new Control(
				'neve_blog_items_border_radius',
				[
					'sanitize_callback' => 'neve_sanitize_range_value',
					'transport'         => 'postMessage',
					'default'           => $this->get_v4_defaults( 'neve_blog_items_border_radius', 0 ),
				],
				[
					'label'                 => esc_html__( 'Border Radius', 'neve' ),
					'section'               => $this->section,
					'type'                  => 'neve_range_control',
					'input_attrs'           => [
						'min'        => 0,
						'max'        => 100,
						'defaultVal' => $this->get_v4_defaults( 'neve_blog_items_border_radius', 0 ),
					],
					'priority'              => 190,
					'live_refresh_selector' => true,
					'live_refresh_css_prop' => [
						'cssVar'   => [
							'vars'     => '--borderradius',
							'suffix'   => 'px',
							'fallback' => '0',
							'selector' => '.posts-wrapper, .nv-ft-post',
						],
						'fallback' => 0,
						'template' =>
						'body .cover-post, body .layout-grid .article-content-col .content {
							    border-radius: {{value}}px;
					    	}',
					],
				],
				'\Neve\Customizer\Controls\React\Range'
			)
		);

		$content_padding_default = $this->get_v4_defaults( 'neve_blog_content_padding', $this->blog_archive_card_padding_default() );

		$this->add_control(
			new Control(
				'neve_blog_content_padding',
				array(
					'sanitize_callback' => array( $this, 'sanitize_spacing_array' ),
					'transport'         => 'refresh',
					'default'           => $content_padding_default,
				),
				array(
					'label'       => esc_html__( 'Content Padding', 'neve' ),
					'section'     => $this->section,
					'priority'    => 80,
					'input_attrs' => array(
						'units' => [ 'px', 'em', 'rem' ],
						'min'   => 0,
					),
					'default'     => $content_padding_default,
				),
				'\Neve\Customizer\Controls\React\Spacing'
			)
		);

		// If this gets enabled, we remove the toggle.
		$this->add_control(
			new Control(
				'neve_enable_card_style',
				array(
					'sanitize_callback' => 'neve_sanitize_checkbox',
					'default'           => $this->get_v4_defaults( 'neve_enable_card_style', false ),
				),
				array(
					'type'     => $this->is_card_style_enabled() ? 'hidden' : 'neve_toggle_control',
					'priority' => 0,
					'section'  => $this->section,
					'label'    => esc_html__( 'Enable Card Style', 'neve' ),
				)
			)
		);


		$card_bg_default = $this->get_v4_defaults( 'neve_blog_grid_card_bg_color', '#333333' );
		$this->add_control(
			new Control(
				'neve_blog_grid_card_bg_color',
				array(
					'sanitize_callback' => 'neve_sanitize_colors',
					'default'           => $card_bg_default,
					'transport'         => 'postMessage',
				),
				array(
					'label'                 => esc_html__( 'Card Background Color', 'neve' ),
					'section'               => $this->section,
					'priority'              => 220,
					'default'               => $card_bg_default,
					'active_callback'       => function () {
						return ( ! $this->is_covers_layout() && $this->is_card_style_enabled() );
					},
					'input_attrs'           => [
						'allow_gradient' => true,
					],
					'live_refresh_selector' => true,
					'live_refresh_css_prop' => [
						'cssVar'   => [
							'vars'     => '--cardbgcolor',
							'selector' => '.posts-wrapper',
						],
						'template' =>
						'.layout-grid .article-content-col .content {
							background: {{value}};
						}',
					],
				),
				'Neve\Customizer\Controls\React\Color'
			)
		);

		$card_text_default = $this->get_v4_defaults( 'neve_blog_grid_text_color', '#ffffff' );
		$this->add_control(
			new Control(
				'neve_blog_grid_text_color',
				array(
					'sanitize_callback' => 'neve_sanitize_colors',
					'default'           => $card_text_default,
					'transport'         => 'postMessage',
				),
				array(
					'label'                 => esc_html__( 'Text Color', 'neve' ),
					'section'               => $this->section,
					'priority'              => 230,
					'default'               => $card_text_default,
					'active_callback'       => function () {
						return ( ! $this->is_covers_layout() && $this->is_card_style_enabled() );
					},
					'live_refresh_selector' => true,
					'live_refresh_css_prop' => [
						'cssVar'   => [
							'vars'     => '--cardcolor',
							'selector' => '.posts-wrapper',
						],
						'template' =>
						'.layout-grid .article-content-col .content, .layout-grid .article-content-col .content a:not(.button), .layout-grid .article-content-col .content li {
							color: {{value}};
						}',
					],
				),
				'Neve\Customizer\Controls\React\Color'
			)
		);


		$shadow_default = $this->get_v4_defaults( 'neve_blog_card_shadow', 0 );
		$this->add_control(
			new Control(
				'neve_blog_card_shadow',
				[
					'sanitize_callback' => 'neve_sanitize_range_value',
					'transport'         => 'refresh',
					'default'           => $shadow_default,
				],
				[
					'label'                 => esc_html__( 'Card Box Shadow', 'neve' ),
					'section'               => $this->section,
					'type'                  => 'neve_range_control',
					'input_attrs'           => [
						'min'        => 0,
						'max'        => 5,
						'defaultVal' => $shadow_default,
						'step'       => 0.1,
					],
					'priority'              => 240,
					'active_callback'       => [ $this, 'is_card_style_enabled' ],
					'live_refresh_selector' => true,
					'live_refresh_css_prop' => [
						'fallback' => 0,
						'template' =>
						'body .layout-grid .article-content-col .content {
							    box-shadow: 0 0 calc({{value}}px * 4) 0 rgba(0,0,0,calc(0.1 + 0.{{value}}));
					    	}',
					],
				],
				'\Neve\Customizer\Controls\React\Range'
			)
		);
	}

	/**
	 * Check if the card style is enabled.
	 *
	 * @return bool
	 */
	public function is_card_style_enabled() {
		$card_style_default = $this->get_v4_defaults( 'neve_enable_card_style', false );
		return Mods::get( 'neve_enable_card_style', $card_style_default ) === true;
	}
}
