<?php

use WpBookingEvent\Factory;
use WpBookingEvent\Language\Text;
defined('_WPBOOKINGEVENT_EXEC') or die;
use WpBookingEvent\Utilities\Utility;
extract($displayData);

WpBookingEventHtmlBackend::load_jquery_library('select2');


$id_by_name = "element_field_". $name;
$data = $displayData['field']->getForm()->getData();
$modelPackages = Model::getInstance('packages');
$list = $modelPackages->getList();
$list_time = [];
$list_package_id = [];
if (!is_array($value)) {
	$list_package_id[] = $value;
} else {
	$list_package_id = $value;
}
?>
    <div id="<?php esc_attr_e($id_by_name) ?>" class="<?php esc_attr_e($class); ?> field-packages">
        <select name="<?php esc_attr_e($name); ?>" <?php echo ($multiple ? ' multiple ' : ""); ?>
                class="list-package">
            <option value=""><?php esc_html_e('Select package','wpbookingevent'); ?></option>
			<?php foreach ($list as $item) { ?>
                <option <?php echo (in_array($item->id, $list_package_id) ? ' selected ' : null) ?>
                        value="<?php esc_attr_e($item->id); ?>"><?php esc_html_e($item->name); ?></option>
			<?php } ?>
        </select>
    </div>
<?php
$doc = Factory::getDocument();
$doc->addScriptApplySelector('.field-packages','field_categories',array(
),'admin/nb_apps/nb_woobooking/layouts/WooBooking/form/field/packages/packages.jquery.js');