<?php

use Bookingor\Routes\AdminRoute;
use Bookingor\Helper\HelperControl;
use Bookingor\Backend\Controller\Bookings\BookingsControl;
// Exit if accessed directly
if (! defined('ABSPATH')) exit; ?>
<div class="wrap bookingor">
    <header>
        <div class="bookingor-header">
            <div class="bookingor-flex bkinz-justify-b bkinz-width bkinz-align-items-c p-0-1">
                <div class="bookingor-flex bkinz-align-items-c">
                    <div class="bookingor-m-0 p-r up-heading"><?php esc_html_e("Booking", "bookingor"); ?></div>
                </div>

            </div>
        </div>
    </header>
    <div class="bookingor">
        <div id="myTable" class="bookingor-admin-bg t-p-all bookingor-d-none">
            <table aria-label="Tables" id="bookingTable" class="table table-hover mb-0 table table-bordered">
                <thead class="bookingor-t-head bookingor-t-h-r">
                    <tr>
                        <th class="bookingor-t-h-f bookingor-col-1"><?php esc_html_e("Booking Date", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f"><?php esc_html_e("Customer", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f"><?php esc_html_e("Time Slots", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f bookingor-col-2"><?php esc_html_e("Assignee", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f"><?php esc_html_e("Time", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f bookingor-col-2"><?php esc_html_e("Service", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f"><?php esc_html_e("Duration", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f"><?php esc_html_e("Payment", "bookingor"); ?></th>
                        <th class="bookingor-t-h-f bookingor-col-1"><?php esc_html_e("Booking Status", "bookingor"); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $bookingOrder = BookingsControl::bp_booking_order();
                    if (!empty($bookingOrder)) {
                        foreach (
                            $bookingOrder as $key =>
                            $value
                        ) { ?>
                            <tr class="bookingor-t-row">
                                <td class="bookingor-t-f"><?php echo esc_html(date(get_option('bookingor_date_format'), strtotime($value->picked_date))); ?></td>
                                <td class="bookingor-t-f">
                                    <div class="bookingor-flex align-items-center">
                                        <div>
                                            <div class="view-customer-name"><?php echo esc_html($value->customer_first_name . " " . $value->customer_last_name); ?></div>
                                            <div class="view-customer-email"><?php echo esc_html($value->customer_email); ?></div>
                                            <div><?php echo esc_html($value->customer_phone); ?></div>
                                        </div>
                                    </div>
                                </td>
                                <td class="bookingor-t-f"><?php echo esc_html($value->people_count . " / " . $value->service_capacity_max); ?></td>
                                <td class="bookingor-t-f bookingor-flex join-img-txt">
                                    <div class="view-service-image">
                                        <?php if ($value->staff_icon) { ?>
                                            <img class="memeber-ava" src="<?php echo esc_attr(wp_get_attachment_url($value->staff_icon));  ?>" alt="" />
                                        <?php } else { ?>
                                            <img class="memeber-ava" data-avatar="<?php echo esc_attr($value->staff_first_name . " " . $value->staff_last_name); ?>" alt="" />
                                        <?php } ?>
                                    </div>
                                    <div><?php echo esc_html($value->staff_first_name . " " . $value->staff_last_name); ?></div>
                                </td>
                                <td class="bookingor-t-f">
                                    <div><?php echo esc_html(date(get_option('bookingor_time_format'), strtotime($value->start_time)) . " - " . date(get_option('bookingor_time_format'), strtotime($value->end_time))); ?></div>
                                </td>
                                <td class="bookingor-t-f bookingor-flex join-img-txt">
                                    <div class="view-service-image">
                                        <img class="bookingor-cate-icon" src="<?php echo esc_attr(!empty($value->service_icon) ?  wp_get_attachment_url($value->service_icon) : (AdminRoute::$default_img));  ?> " data-img-id="<?php echo esc_attr(($value->service_icon)); ?>" alt="" />
                                    </div>
                                    <div><?php echo esc_html($value->service_name); ?></div>
                                </td>
                                <td class="bookingor-t-f"><?php echo esc_html(HelperControl::convert_duration($value->service_duration)); ?></td>
                                <td class="bookingor-t-f">
                                    <div class="<?php echo esc_attr(get_option('bookingor_currency_position_change')); ?> bookingor-flex">
                                        <div class="<?php echo esc_attr(get_option('bookingor_currency_position_change')); ?>"><?php echo esc_html(get_option("bookingor_settings_currency_symbol")); ?></div>
                                        <div><?php echo esc_html($value->service_get_price); ?></div>
                                    </div>
                                    <?php echo esc_html($value->payment_method); ?>
                                </td>
                                <td class="bookingor-t-f">
                                    <div class="bookingor-flex align-items-center">
                                        <div><?php echo esc_html($value->appoint_status); ?></div>
                                        <div>
                                            <div class="dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown">
                                                <div class="bkingor-svg">
                                                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="svg-menu">
                                                        <path d="M12,7a2,2,0,1,0-2-2A2,2,0,0,0,12,7Zm0,10a2,2,0,1,0,2,2A2,2,0,0,0,12,17Zm0-7a2,2,0,1,0,2,2A2,2,0,0,0,12,10Z"></path>
                                                    </svg>
                                                </div>
                                                <span class="visually-hidden"><?php esc_html_e("Toggle Dropdown", "bookingor"); ?></span>
                                            </div>
                                            <div class="dropdown-menu">
                                                <ul class="bookingor-list-link link-list-opt no-bdr change-booking-status" data-id="<?php echo esc_attr($value->book_id); ?>">
                                                    <li>
                                                        <a href="#" class="pop-size change-order-status booking-status" data-booking-status="pending"><?php esc_html_e("Pending", "bookingor"); ?></a>
                                                    </li>
                                                    <li>
                                                        <a href="#" class="pop-size change-order-status booking-status" data-booking-status="in_process"><?php esc_html_e("In Process", "bookingor"); ?></a>
                                                    </li>
                                                    <li>
                                                        <a href="#" class="pop-size change-order-status booking-status" data-booking-status="approved"><?php esc_html_e("Approved", "bookingor"); ?></a>
                                                    </li>
                                                    <li>
                                                        <a href="#" class="pop-size change-order-status booking-status" data-booking-status="rejected"><?php esc_html_e("Rejected", "bookingor"); ?></a>
                                                    </li>
                                                    <li>
                                                        <a href="#" class="pop-size change-order-status booking-status" data-booking-status="canceled"><?php esc_html_e("Canceled", "bookingor"); ?></a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                    <?php
                        }
                    } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>