<?php
/**
 * vcex_alert shortcode output.
 *
 * @package Total WordPress Theme
 * @subpackage Total Theme Core
 * @version 2.5
 */

defined( 'ABSPATH' ) || exit;

$active_highlight = vcex_validate_att_boolean( 'active_highlight', $atts );
$style            = ! empty( $atts['style'] ) ? $atts['style'] : '';
$heading_levels   = ! empty( $atts['heading_levels'] ) ? $atts['heading_levels'] : [ 'h2', 'h3' ];

if ( is_string( $heading_levels ) ) {
	$heading_levels = wp_parse_list( $heading_levels );
}

$options = [
	'active_highlight' => $active_highlight ? 1 : 0,
	'heading_levels'   => array_map( 'sanitize_text_field', $heading_levels ),
];

$wrap_class = [
	'vcex-table-of-contents',
];

if ( $active_highlight ) {
	$wrap_class[] = 'wpex-sticky';
}

if ( $style ) {
	$wrap_class[] = sanitize_html_class( "vcex-table-of-contents--{$style}" );
}

$extra_classes = vcex_get_shortcode_extra_classes( $atts, 'vcex_alert' );

if ( $extra_classes ) {
	$wrap_class = array_merge( $wrap_class, $extra_classes );
}

$wrap_class = vcex_parse_shortcode_classes( $wrap_class, 'vcex_alert', $atts );

$output = '<div class="' . esc_attr( trim( $wrap_class ) ) . '"' . vcex_get_unique_id( $atts ) . ' data-vcex-toc-options="' . esc_attr( wp_json_encode( $options ) ) . '">';

	if ( ! empty( $atts['heading'] ) && $heading_safe = vcex_parse_text_safe( $atts['heading'] ) ) {
		$output .= vcex_get_module_header( [
			'tag'     => ! empty( $atts['heading_tag'] ) ? $atts['heading_tag'] : 'div',
			'style'   => ! empty( $atts['heading_style'] ) ? $atts['heading_style'] : '',
			'align'   => ! empty( $atts['heading_align'] ) ? $atts['heading_align'] : '',
			'content' => $heading_safe,
			'classes' => [
				'vcex-table-of-contents__heading',
			],
		] );
	}

	$ol_class = 'vcex-table-of-contents__list wpex-m-0 wpex-list-none';
	switch ( $style ) {
		case 'side-border':
			$ol_class .= ' wpex-border-l wpex-border-solid wpex-border-surface-4 wpex-pl-15';
			break;
	}

	$output .= '<ol class="' . esc_attr( $ol_class ) . '">';
		if ( vcex_is_frontend_edit_mode() ) {
			if ( $active_highlight ) {
				$output .= '<li class="vcex-table-of-contents__item"><a href="#" class="vcex-table-of-contents__link vcex-table-of-contents__link--active wpex-inline-block wpex-text-accent" aria-current="true">' . esc_html__( 'Sample Active Heading', 'total-theme-core' ) . '</a></li>';
			}
			for ( $i = 0; $i < 6; $i++ ) {
				$output .= '<li class="vcex-table-of-contents__item"><a href="#" class="vcex-table-of-contents__link wpex-inline-block wpex-text-current wpex-hover-text-accent">' . esc_html__( 'Sample Heading', 'total-theme-core' ) . '</a></li>';
				if ( 2 == $i ) {
					$output .= '<ol class="vcex-table-of-contents__list wpex-m-0 wpex-list-none wpex-ml-10"><li class="vcex-table-of-contents__item"><a href="#" class="vcex-table-of-contents__link wpex-inline-block wpex-text-current wpex-hover-text-accent">' . esc_html__( 'Sample Sub Heading', 'total-theme-core' ) . '</a></li><li class="vcex-table-of-contents__item"><a href="#" class="vcex-table-of-contents__link wpex-inline-block wpex-text-current wpex-hover-text-accent">' . esc_html__( 'Sample Sub Heading', 'total-theme-core' ) . '</a></li><li class="vcex-table-of-contents__item"><a href="#" class="vcex-table-of-contents__link wpex-inline-block wpex-text-current wpex-hover-text-accent">' . esc_html__( 'Sample Sub Heading', 'total-theme-core' ) . '</a></li></ol>';
				}
			}
		}
	$output .= '</ol>';

$output .= '</div>';

// @codingStandardsIgnoreLine
echo $output;
