<?php 
/**
 * EventCard Event Type html content
 * @version 5.0.7
 */

if( empty($EventData['eventtype'])) return;

$eventtype = $EventData['eventtype'];
if( !isset( $eventtype['terms'] )) return;

$parents = [];
$children = [];

foreach ($eventtype['terms'] as $term_id => $TD) {
    if ($TD['parent'] == 0) {
        $parents[$term_id] = $TD;
    } else {
        $children[$TD['parent']][] = $TD;
    }
}

EVO_Debug($eventtype['terms']);

echo "<div class='evo_metarow_et evorow evcal_evdata_row evcal_evrow_sm ".$end_row_class."'>
		
		<div class='evcal_evdata_cell'>							
			<h3 class='evo_h3'>".evo_lang( 'Event Type')."</h3>";

			echo "<div class='evodfx evofxdrr evogap10 evofxww evofxaic'>";

		$parent_index = 0;
		foreach ($parents as $parent_id => $parent) {
		    $terms = [$parent];
		    if (!empty($children[$parent_id])) {
		        $terms = array_merge($terms, $children[$parent_id]);
		    }

		    $count = count($terms);
		    for ($i = 0; $i < $count; $i++) {
		        $term = $terms[$i];
		        $term_id = $term['id'] ?? $parent_id;
		        $is_child = $i > 0;

		        $icon = !empty($term['i']) ? $term['i'] : '';
		        $color = evo_get_term_meta_field('event_type', $term_id, 'et_color', '', 'dcdcdc');
		        $text_color_class = !eventon_is_hex_dark($color) ? 'evoclw' : 'evocl1';

		        $data = [
		            'sp_title' => evo_lang('Events in') . ' ' . evo_lang($term['tn']),
		            'ajax' => 'yes',
		            'adata' => [
		                'a' => 'eventon_get_instant_cal',
		                'data' => [
		                    'shortcode' => apply_filters('evo_et_events_sc', [
		                        'calendar_type' => 'default',
		                        'hide_past' => 'yes',
		                        'number_of_months' => 2,
		                        'event_type' => $term_id,
		                        'ux_val' => '3'
		                    ], $term, $EVENT),
		                    'process_sc' => true,
		                    'direction' => 'next'
		                ],
		                'uid' => 'evo_et_trigger',
		            ],
		            'uid' => 'evo_et_trigger',
		            'end' => 'client',
		        ];

		        if ($is_child) {
		            echo "<i class='fa fa-chevron-right' style='font-size:10px;'></i>";
		        }

		        echo "<button class='evo_et_trigger evoff_2i evofz14i evobrn evoboxsn evopad10-15 evobr8 evocurp evoHbgci evoHbrc1 evoHcwi evo_transit_all evodfx evofxdrr evogap10 {$text_color_class}' "
		            . "data-d='" . json_encode($data) . "' data-id='{$term_id}' style='background-color:#{$color};'>"
		            . $icon . $term['tn']
		            . "</button>";
		    }

		    $parent_index++;
		}

		echo "</div>";
echo "</div></div>";
?>