<?php

use WpBookingEvent\Factory;
use WpBookingEvent\Html\WpBookingEventHtmlBackend;
use WpBookingEvent\Language\Text;
use WpBookingEvent\Mvc\Model\Model;
use WpBookingEvent\Utilities\Utility;

defined('_WPBOOKINGEVENT_EXEC') or die;
extract($displayData);
$doc = Factory::getDocument();
WpBookingEventHtmlBackend::load_jquery_library('select2');
$doc->addLessStyleSheet('admin/app/layouts/WooBooking/form/field/tags/tags.less');
$modelTags = Model::getInstance('tags');
$list_tags = $modelTags->getList();
$id_by_name = "element_field_" . str_replace(array('[', ']'), '_', $name);
$list_selected = is_array($value) ? $value : array();
?>
    <div id="<?php esc_attr_e($id_by_name) ?>" class="field-tags">
        <select name="<?php esc_attr_e($name); ?>" <?php echo ($multiple ? ' multiple ' : ""); ?> class="form-control list-tags">
            <option value=""> <?php esc_html_e('Select tags','wpbookingevent') ?></option>
            <?php foreach ($list_tags as $tag) { ?>
                <option <?php echo (in_array($tag->id, $list_selected) ? " selected " : "") ?>
                        value="<?php esc_attr_e($tag->id); ?>"><?php esc_html_e($tag->name); ?></option>
            <?php } ?>
        </select>
    </div>
<?php
$doc->addScriptApplySelector('.field-tags', 'field_tags', array(
    "tags" => $list_tags,
    "tags_selected" => $value,
), 'admin/app/layouts/WooBooking/form/field/tags/jquery.tags.js');
