<?php

use WpBookingPro\Factory;
use WpBookingPro\Mvc\Model\Model as ModelAlias;
use WpBookingPro\Utilities\Utility;
use WpBookingPro\Language\Text;
defined('_WPBOOKINGPRO_EXEC') or die;
extract($displayData);



$doc = Factory::getDocument();
if ( class_exists( 'WooCommerce' ) ) {
    $list_order_status_woo = wc_get_order_statuses();
} else {
    $list_order_status_woo = array("pending","completed","processing","on-hold","cancelled","refunded","failed");
}

$id_by_name = $id_by_name = "element_field_" . str_replace(array('[', ']'), '_', $name);
$input = Factory::getInput();
$id = $input->getInt('id',0);
$db = Factory::getDBO();
$query = $db->getQuery(true);
$query->select('order_status.open_source_order_status_id')
    ->from(Utility::getTableName('order_status').' AS order_status')
;
$list_order_status_appointment = $db->setQuery($query)->loadColumn();
?>
    <div id="<?php echo (esc_attr($id_by_name)) ?>" class="field-woocommerceorderstatus">
        <div class="wrapper-woocommerceorderstatus">
            <select class="woocommerceorderstatus" name="<?php echo (esc_attr($name)); ?>">
                <option value=""><?php esc_html_e('Select status','wpbookingpro')?></option>
                <?php foreach ($list_order_status_woo as $key => $item){ ?>
                    <?php
                        if ( class_exists( 'WooCommerce' ) ) {
                            $order_status_key = str_replace('wc-', '', $key);
                        } else {
                            $order_status_key= $item;
                        }

                    ?>
                    <?php if ($id > 0) {?>
                        <option <?php echo (esc_attr($order_status_key===$value?' selected ':'')) ?> value="<?php echo (esc_attr($order_status_key)); ?>" <?php echo (esc_attr($order_status_key===$value?'':'disabled'));?>><?php esc_html_e($item,'wpbookingpro'); ?></option>
                    <?php } else {?>
                        <option <?php echo (esc_attr(in_array($order_status_key,$list_order_status_appointment)?'disabled':'')) ?> value="<?php echo (esc_attr($order_status_key)); ?>"><?php echo (esc_html($item)); ?></option>
                    <?php }?>
                <?php } ?>
            </select>
        </div>
    </div>
<?php
$doc->addScriptApplySelector("#$id_by_name",'field_woocommerceorderstatus',array(
    "input_name"=>  $name,
),'admin/app/layouts/WooBooking/form/field/woocommerceorderstatus/jquery.woocommerceorderstatus.js');
