<?php
if(!defined('ABSPATH')) exit; 
if(!empty($args['args']['type']) && $args['args']['type'] == 'input'){
    // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$args['args']['model_suffix'] = '_value';
	setrio_bizcal_get_template_part('vue/part/input', $args);
	return;
}
$bizcalendar_web_attach = isset($args['rargs']) && isset($args['rargs']['attach']) ? $args['rargs']['attach'] : false;
$bizcalendar_web_a = shortcode_atts(array_replace(array(
	'label' => setrio_bizcal_message('txtUnknown'),
	'text_no_items' => setrio_bizcal_message('txtNoItems'),
	'atts' => 'auto-select-first',
	'class' => 'mb-3',
	'locale' => 'ro',
	'hide-details' => "'auto'",
	'placeholder' => '',
	'type' => 'autocomplete',
	'texts' => array(
		'required' => setrio_bizcal_message('lblFieldMissing'),
	),
	'rules' => "",
), (isset($args['wargs']) ? $args['wargs'] : array())), (isset($args['args']) ? $args['args'] : array()), (isset($args['tag']) ? $args['tag'] : ''));
$bizcalendar_web_key = $args['key'];
$bizcalendar_web_global_selecttype = get_option('setrio_bizcal_selecttype', 'autocomplete');
$bizcalendar_web_selecttype = get_option('setrio_bizcal_selecttype_' . $bizcalendar_web_key, $bizcalendar_web_global_selecttype);
if(!in_array($bizcalendar_web_selecttype, ['select', 'autocomplete'])){
    $bizcalendar_web_selecttype = 'autocomplete';
}
?>
<v-<?php echo esc_attr($bizcalendar_web_selecttype); ?> 
	v-bind="props('autocomplete')"
	<?php if($bizcalendar_web_attach){ ?>
	attach="<?php echo esc_attr($bizcalendar_web_attach); ?>"
	<?php } ?>
	<?php if($bizcalendar_web_key == 'physician' || $bizcalendar_web_key == 'location'){ ?>
	:clearable="!!<?php echo esc_attr($bizcalendar_web_key); ?>_value"
	<?php } ?>
	<?php echo esc_attr($bizcalendar_web_a['atts']); ?>
	locale="<?php echo esc_attr($bizcalendar_web_a['locale']); ?>" 
	label="<?php echo esc_attr($bizcalendar_web_a['label']); ?>"
	class="<?php echo esc_attr($bizcalendar_web_a['class']); ?>"
	:class="{'sbc-<?php echo esc_attr($bizcalendar_web_key); ?>': true,'d-none': <?php 
	if($bizcalendar_web_key == 'payment_type'){ ?>(!speciality_value || (payment_type_list.length == 1 && payment_type_value))<?php 
	} elseif($bizcalendar_web_key == 'physician'){ ?>!$data.allow_search_physician || !speciality_value || !payment_type_value<?php 
	} elseif($bizcalendar_web_key == 'service'){ ?>1 != payment_type_value<?php 
	} elseif($bizcalendar_web_key == 'location'){ ?>!speciality_value <?php 
	} else { ?>false<?php } 
	?>}" 
	:hide-details="<?php echo esc_attr($bizcalendar_web_a['hide-details']); ?>"
	:loading="<?php echo esc_attr($bizcalendar_web_key); ?>_lock"
	:disabled="<?php echo esc_attr($bizcalendar_web_key); ?>_lock"
	ref="<?php echo esc_attr($bizcalendar_web_key); ?>" 
	v-model="<?php echo esc_attr($bizcalendar_web_key); ?>_value" 
	:items="<?php echo esc_attr($bizcalendar_web_key); ?>_list||[]" 
	:item-text="'label'" 
	:item-value="'value'" 
	<?php if ($bizcalendar_web_a['placeholder']) { ?>placeholder="<?php echo esc_attr($bizcalendar_web_a['placeholder']); ?>"<?php } ?>
	<?php if ($bizcalendar_web_a['rules']) { ?>:rules="<?php echo esc_attr($bizcalendar_web_a['rules']); ?>"<?php } ?>
>
	
	<template v-slot:append v-if="'error' === objVal($refs,'<?php echo esc_attr($bizcalendar_web_key); ?>.validationState')">
		<v-icon
			color="error"
			v-text="'mdi-alert-circle-outline'"
		></v-icon>
	</template>
	<template v-slot:no-data>
		<v-list-item>
			<template v-if="0"></template>
			<?php if(in_array($bizcalendar_web_key, array('location','payment_type','service', 'physician'))){ ?>
			<v-list-item-title v-else-if="!speciality_value"><?php BizCalendar\wp_kses_post(setrio_bizcal_message('lblFieldMissing')); ?> {{ texts.txt_speciality }}</v-list-item-title>
			<?php } ?>
			<?php if($bizcalendar_web_key == 'service'){ ?>
			<v-list-item-title v-else-if="!payment_type_value"><?php BizCalendar\wp_kses_post(setrio_bizcal_message('lblFieldMissing')); ?> {{ texts.txt_payment_type }}</v-list-item-title>
			<?php } ?>
			<?php if($bizcalendar_web_key == 'physician'){ ?>
			<v-list-item-title v-else-if="!payment_type_value"><?php BizCalendar\wp_kses_post(setrio_bizcal_message('lblFieldMissing')); ?> {{ texts.txt_payment_type }}</v-list-item-title>
			<?php } ?>
			<v-list-item-title v-else><?php BizCalendar\wp_kses_post(esc_attr($bizcalendar_web_a['text_no_items'])); ?></v-list-item-title>
		</v-list-item>
	</template>
	<?php if($bizcalendar_web_key == 'service'){ ?>
	<template v-slot:item="data">
	  <v-list-item-content v-if="data.item">
		<v-list-item-title class="text-wrap">{{ data.item.label }} <span class="float-right">{{ data.item.Price }}</span></v-list-item-title>
	  </v-list-item-content>
	</template>
	<?php } ?>
	<?php if($bizcalendar_web_key == 'physician' && !empty($args['rargs']['show_physician_details'])){ ?>
	<template v-slot:item="data">
		<template v-if="data.item">
		  <v-list-item-avatar v-if="data.item.PictureURL">
			<v-img cover :lazy-src="'<?php echo esc_attr(plugins_url( '/css/images/physician-icon.png', BIZCALENDAR_PLUGIN_FILE )); ?>'" :src="data.item.PictureURL">
		  </v-list-item-avatar>
		  <v-list-item-avatar v-else>
			<v-img cover :src="'<?php echo esc_attr(plugins_url( '/css/images/physician-icon.png', BIZCALENDAR_PLUGIN_FILE )); ?>'">
		  </v-list-item-avatar>
		  <v-list-item-content>
			<v-list-item-title v-html="data.item.label"></v-list-item-title>
			<v-list-item-subtitle v-if="data.item.Description" v-html="data.item.Description" class="text-wrap"></v-list-item-subtitle>
		  </v-list-item-content>
		</template>
	</template>
	<?php } ?>
</v-<?php echo esc_attr($bizcalendar_web_selecttype); ?>>
<?php if($bizcalendar_web_key == 'service'){ ?>
	<div class="font-weight-bold text-h6 mb-3 text-center" v-if="$refs.<?php echo esc_attr($bizcalendar_web_key); ?> && objVal($refs,'<?php echo esc_attr($bizcalendar_web_key); ?>.selectedItems.0')">
        {{ $refs.<?php echo esc_attr($bizcalendar_web_key); ?>.selectedItems[0].Price }}
	</div>
<?php } ?>
<component is="script">SetrioBizCalendarVueApps[{{ app_index }}].setData('texts_<?php echo esc_attr($bizcalendar_web_key); ?>',<?php BizCalendar\wp_kses_post(htmlspecialchars(json_encode(array('texts' => array($bizcalendar_web_key => $bizcalendar_web_a['texts']))), ENT_QUOTES, 'UTF-8')); ?>)</component>