<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

?>

<style>
    select {
        width: 300px;
        max-width: 100%;
    }
</style>

<div class="wrap">
    <h1><?php esc_html_e( 'Customers', 'wiaas' ); ?> </h1>

    <br class="clear" />
    <div id="col-container">

        <div id="col-right">
            <div class="col-wrap">
                <table class="widefat wp-list-table striped" style="width:100%">
                    <thead>
                    <tr>
                        <th scope="col"><?php esc_html_e( 'Name', 'wiaas' ); ?></th>
                        <th scope="col"><?php esc_html_e( 'Order type', 'wiaas' ); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                        foreach ($customers as $customer) {
                            $name = wiaas_get_organization_name($customer['customer_id']);
                            ?>
                                <tr>
                                    <td>
                                        <h2><?php esc_html_e($name, 'wiaas') ?></h2>
                                    </td>
                                    <td>
                                        <?php
                                        esc_html_e(
	                                        $customer['order_type']=== 'commercial_lead' ? 'Commercial Lead' : 'Reseller',
                                                'wiaas'
                                        )
                                        ?>
                                    </td>
                                </tr>
                            <?php
                        }
                    ?>
                    </tbody>
                </table>
            </div>
        </div>

        <div id="col-left">
            <div class="col-wrap">
                <div class="inside">
                    <div class="form-wrap">
                        <h2><?php esc_html_e('Default order type:', 'wiaas') ?></h2>
                        <form class="form" action="" method="post">
                            <input type="hidden" name="page" value="wiaas-cl-customers"/>
                            <div class="form-field">
                                <select class="form-control" name="default_order_type">
                                    <option
                                        value="commercial_lead"
                                        <?php selected('commercial_lead', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
                                    >
                                        <?php esc_html_e('Commercial Lead', 'wiaas') ?>
                                    </option>
                                    <option
                                        value="reseller"
                                        <?php selected('reseller', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
                                    >
                                        <?php esc_html_e('Reseller', 'wiaas') ?>
                                    </option>
                                </select>
                            </div>
                            <input class="button button-primary button-large"  type="submit" value="Change"/>
	                        <?php wp_nonce_field( 'wiaas_update_cl_default_order_type', 'wiaas_update_cl_default_order_type_nonce' ); ?>
                        </form>
                    </div>
                    <hr style="margin: 30px 0;" />

                    <div class="form-wrap">
                        <h2><?php esc_html_e('Update order type for customer', 'wiaas') ?></h2>
                        <form class="form" action="" method="post">
                            <div class="form-field">
                                <label><?php esc_html_e('Customer:', 'wiaas') ?> </label>
                                <select class="form-control" name="customer_order_type[customer_id]">
                                    <?php
                                        foreach ($customers as $customer) {
                                            $name = wiaas_get_organization_name($customer['customer_id']);
                                            ?>
                                                <option
                                                    value="<?php esc_html_e($customer['customer_id'], 'wiaas') ?>"
                                                >
                                                    <?php esc_html_e($name, 'wiaas') ?>
                                                </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                            <div class="form-field">
                                <label><?php esc_html_e('Order type:', 'wiaas') ?> </label>
                                <select class="form-control" name="customer_order_type[order_type]">
                                    <option value="commercial_lead">
                                        <?php esc_html_e('Commercial Lead', 'wiaas') ?>
                                    </option>
                                    <option value="reseller">
                                        <?php esc_html_e('Reseller', 'wiaas') ?>
                                    </option>
                                </select>
                            </div>
                            <input class="button button-large"  type="submit" value="Update"/>
	                        <?php wp_nonce_field( 'wiaas_update_cl_customer_order_type', 'wiaas_update_cl_customer_order_type_nonce' ); ?>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
