<?php
use WpBookingHotel\Factory;
use WpBookingHotel\Html\WpBookingHotelHtmlFrontend;
use WpBookingHotel\Language\Text;
use WpBookingHotel\Mvc\Model\Model;

defined('_WPBOOKINGHOTEL_EXEC') or die;
extract($displayData);

$id_by_name = "element_field_" . str_replace(array('[', ']'), '_', $name);
$name_format = str_replace(array('[', ']'), '_', $name);
$servicesModel = Model::getInstance('services');
$list_services = $servicesModel->getList();

$list_selected = is_array($value) ? $value : array();

?>
    <div id="<?php echo (esc_attr($id_by_name)) ?>"
         class="<?php echo (esc_attr($class)); ?> field-services-<?php echo (esc_attr($name_format)) ?> field-services">
        <select name="<?php echo (esc_attr($name)); ?>" <?php echo ($multiple ? ' multiple ' : ""); ?> class="form-control list-services">
            <option value=""> <?php esc_html_e('Select services','wpbookinghotel') ?></option>
			<?php foreach ($list_services as $service) { ?>
                <option <?php echo (in_array($service->id, $list_selected) ? " selected " : "") ?>
                        value="<?php echo (esc_attr($service->id)); ?>"><?php esc_html_e($service->name,'wpbookinghotel'); ?></option>
			<?php } ?>
        </select>
    </div>
<?php
$doc = Factory::getDocument();
WpBookingHotelHtmlFrontend::load_jquery_library('select2');
$doc->addLessStylesheet('admin/app/layouts/WooBooking/form/field/services/services.less');
$doc->addScriptApplySelector('.field-services','field_services',array(
    "field_name"=>  $name,
),'admin/app/layouts/WooBooking/form/field/services/services.jquery.js');
