<?php

use Bookingor\Backend\Controller\Service\ServiceControl;
use Bookingor\Backend\Controller\Payment\PaymentControl;
use Bookingor\Helper\HelperControl;

// 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="bkinz-m-0 p-r up-heading"><?php esc_html_e("Payment", "bookingor"); ?></div>
        </div>

      </div>
    </div>
  </header>
  <div class="bookingor"></div>
  <div class="bookingor">
    <div id="myTable" class="bookingor-admin-bg t-p-all bookingor-d-none">
      <table id="example" class="table mb-0 table table-bordered">
        <thead class="bookingor-t-head bookingor-t-h-r">
          <tr>

            <th class="bookingor-t-h-f"><?php esc_html_e("Payment 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("Service", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Employee", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Booking Date", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Amount", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Due", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Paid", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Payment Status", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Action", "bookingor"); ?></th>
          </tr>
        </thead>
        <tbody>
          <?php
          $customerPaymentViewData = PaymentControl::customer_payment_view();
          if (!empty($customerPaymentViewData)) {
            foreach (
              $customerPaymentViewData as $key => $value
            ) { ?>
              <tr class="bookingor-t-row">

                <td class="bookingor-t-f">
                  <?php echo esc_html($value->created_at ? date(get_option('bookingor_date_format'), strtotime($value->created_at)) : ''); ?>
                </td>
                <td class="bookingor-t-f">
                  <div>
                    <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>
                  </div>
                </td>
                <td class="bookingor-t-f"><?php echo esc_html($value->service_name); ?></td>
                <td class="bookingor-t-f">
                  <div class="bookingor-flex align-items-center">
                    <div class="user-avatar">
                      <?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" src=""
                          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>
                  </div>
                </td>
                <td class="bookingor-t-f">
                  <?php echo esc_html(date(get_option('bookingor_date_format'), strtotime(esc_html($value->picked_date)))) . " " . esc_html(date(get_option('bookingor_time_format'), strtotime(esc_html($value->picked_date_end)))); ?>
                </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(HelperControl::priceDecimal($value->service_get_price + $value->service_tax +  $value->discount_get_price + $value->tax_get_price)); ?>
                    </div>
                  </div>
                </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(HelperControl::priceDecimal(($value->service_get_price +  $value->service_tax  + $value->tax_get_price) - $value->paid_amount)); ?>
                    </div>
                  </div>
                </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(HelperControl::priceDecimal($value->paid_amount)); ?></div>
                  </div>
                </td>
                <td class="bookingor-t-f">
                  <div class="bookingor-flex align-items-center">
                    <div><?php echo esc_html($value->payment_status); ?></div>
                    <div>
                      <div data-id="<?php echo esc_attr($value->pay_id); ?>" 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-pay-status"
                          data-id="<?php echo esc_attr($value->pay_id); ?>">
                          <li>
                            <a href="#" class="pop-size pay-status"><?php esc_html_e("Pending", "bookingor"); ?></a>
                          </li>
                          <li>
                            <a href="#" class="pop-size pay-status"><?php esc_html_e("Rejected", "bookingor"); ?></a>
                          </li>
                          <li>
                            <a href="#" class="pop-size pay-status"><?php esc_html_e("Completed", "bookingor"); ?></a>
                          </li>
                        </ul>
                      </div>
                    </div>
                  </div>
                </td>
                <td class="bookingor-t-f">
                  <div class="payment-details">
                    <div class="btn-group">
                      <input type="hidden" class="pay-id" />
                      <button type="button"
                        class="bookingor-btn bookingor-btn-dim bookingor-btn-secondary bookingor-btn-sm payment-view-update shw-bkdrp"
                        data-id="<?php echo esc_attr($value->pay_id); ?>"
                        data-bs-target="#myModal-<?php echo esc_attr($value->pay_id); ?>" data-bs-toggle="modal">
                        Details
                      </button>
                    </div>
                  </div>
                  <div class="modal fade" id="myModal-<?php echo esc_attr($value->pay_id); ?>" aria-hidden="true"
                    tabindex="-1">
                    <div class="modal-dialog modal-dialog-centered mod-wd">
                      <div class="modal-content">
                        <div class="modal-header bookingor">
                          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body mod-pd">
                          <input type="hidden" name="get_pay_id" value="<?php echo esc_attr($value->pay_id); ?>" />
                          <div class="row m-top">
                            <div class="pay-serv">
                              <div class="bookingor-flex align-items-center">
                                <div class="payment-details-service-icon"> <img class="bookingor-cate-icon" src="<?php echo esc_attr(!empty($value->service_icon) ? wp_get_attachment_url($value->service_icon) :  ServiceControl::$default_img); ?>" data-img-id="<?php echo esc_attr(($value->service_icon)); ?>" alt="" />
                                </div>
                                <div class="row">
                                  <div class="pay-b-h"><?php echo esc_html($value->service_name); ?></div>
                                  <div class="sm-ft"><?php esc_html_e("New York", "bookingor"); ?></div>
                                  <div class="sm-ft"> <?php echo esc_html($value->picked_date . " " . $value->picked_date_end); ?></div>
                                </div>
                              </div>
                            </div>
                            <div class="mb-3">
                              <div class="tot-p">
                                <div class="g-clr"><?php esc_html_e("Booking Date", "bookingor"); ?></div>
                                <div class="g-clr"> <?php echo esc_html($value->picked_date . " " . $value->picked_date_end); ?></div>
                              </div>
                              <div class="tot-p">
                                <div class="g-clr"><?php esc_html_e("Employee Name", "bookingor"); ?></div>
                                <div class="g-clr"> <?php echo esc_html($value->staff_first_name . " " . $value->staff_last_name); ?></div>
                              </div>
                              <div></div>
                              <div></div>
                            </div>
                            <div
                              class="bookingor-col-xl-6 col-lg-6 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12">
                              <div class="pay-n-h"><?php esc_html_e("CUSTOMER", "bookingor"); ?></div>
                              <div class="mt">
                                <div class="sm-ft"> <?php echo esc_html($value->customer_first_name . " " . $value->customer_last_name); ?>
                                </div>
                                <div class="sm-ft bookingor-flex"> <span><i class="bx bx-envelope i-pd"></i></span><?php echo esc_html($value->customer_email); ?>
                                </div>
                                <div class="sm-ft"> <span><i class="bx bx-phone i-pd"></i></span><?php echo esc_html($value->customer_phone); ?>
                                </div>
                              </div>
                            </div>
                            <div
                              class="bookingor-col-xl-6 col-lg-6 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12">
                              <div class="pay-n-h"><?php esc_html_e("PAYMENT", "bookingor"); ?></div>
                              <div class="mt">
                                <div class="sm-ft"> <span><i class="bx bx-calendar-check"></i><?php esc_html_e("Date:", "bookingor"); ?></span>
                                  <?php echo esc_html($value->created_at ? date(get_option('bookingor_date_format'), strtotime($value->created_at)) : ''); ?>
                                </div>
                                <div class="sm-ft"> <span><i class="bx bx-wallet"></i><?php esc_html_e("Method:", "bookingor"); ?></span><?php echo esc_html($value->payment_method); ?>
                                </div>
                                <div class="sm-ft"> Payment Status:<span class="pen-tg"><?php echo esc_html($value->payment_status); ?></span>
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="order-bg">
                            <div class="bookingor-flex update-due-price-n-smry">
                              <h5><?php esc_html_e("Order Summary", "bookingor"); ?></h5>
                              <div><i class="bx bx-dots-vertical-rounded"></i></div>
                            </div>
                            <div class="tot-p">
                              <div class="g-clr"><?php esc_html_e("Services", "bookingor"); ?></div>
                              <div class="g-clr">
                                <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(HelperControl::priceDecimal($value->service_get_price)); ?></div>
                                </div>
                              </div>
                            </div>
                            <!-- <div class="tot-p">
                              <div class="g-clr"><!?php esc_html_e("Extra", "bookingor"); ?></div>
                              <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(HelperControl::priceDecimal($value->extra_get_price)); ?></div>
                              </div>
                            </div> -->
                            <div class="tot-p">
                              <div class="g-clr"><?php esc_html_e("Discount", "bookingor"); ?></div>
                              <div class="g-clr">
                                <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(HelperControl::priceDecimal($value->discount_get_price)); ?> </div>
                                </div>
                              </div>
                            </div>
                            <div class="tot-p">
                              <div class="g-clr"><?php esc_html_e("Tax", "bookingor"); ?></div>
                              <div class="g-clr">
                                <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(HelperControl::priceDecimal($value->service_tax)); ?></div>
                                </div>
                              </div>
                            </div>
                            <div class="tot-p">
                              <div class="g-clr"><?php esc_html_e("Subtotal", "bookingor"); ?></div>
                              <div class="g-clr bookingor-flex">
                                <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 class="subtotal"> <?php echo esc_html(HelperControl::priceDecimal(number_format((floatval($value->service_get_price) + floatval($value->service_tax) + floatval($value->extra_get_price)) - floatval($value->discount_get_price), 2, '.', ''))); ?> </div>
                                </div>
                              </div>
                            </div>
                            <div class="tot-p edit-due-price">
                              <div class="g-clr"><?php esc_html_e("Paid", "bookingor"); ?></div>
                              <div class="g-clr bookingor-flex">
                                <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 class="paying-now"> <?php echo esc_html(HelperControl::priceDecimal($value->paid_amount)); ?></div>
                                </div>
                                <div class="show-paid-icon">
                                  <div class="change-due-pr"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 101 101" class="bookinor-svg-edit">
                                      <path d="M82.2 79.2H18.8c-1.3 0-2.4 1.1-2.4 2.4s1.1 2.4 2.4 2.4h63.4c1.3 0 2.4-1.1 2.4-2.4s-1.1-2.4-2.4-2.4zM16.5 58.2l-.1 11.3c0 .6.2 1.3.7 1.7.5.4 1.1.7 1.7.7l11.3-.1c.6 0 1.2-.3 1.7-.7l38.8-38.8c.9-.9.9-2.5 0-3.4L59.4 17.7c-.9-.9-2.5-.9-3.4 0l-7.8 7.8-31 31c-.5.5-.7 1.1-.7 1.7zm49-27.6L61.1 35l-7.8-7.8 4.4-4.4 7.8 7.8zM21.3 59.2l28.6-28.6 7.8 7.8L29.1 67h-7.8v-7.8z"> </path>
                                    </svg> </div>
                                  <div class="update-due-pr update-pay-now" data-id="<?php echo esc_attr($value->pay_id); ?>"> <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" class="svg-check">
                                      <path fill="none" d="M0 0h24v24H0V0z"></path>
                                      <path d="M9 16.17L5.53 12.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41l4.18 4.18c.39.39 1.02.39 1.41 0L20.29 7.71c.39-.39.39-1.02 0-1.41-.39-.39-1.02-.39-1.41 0L9 16.17z"> </path>
                                    </svg> </div>
                                </div>
                              </div>
                            </div>
                            <div class="tot-p">
                              <div class="g-clr bookingor-flex"><?php esc_html_e("Due", "bookingor"); ?></div>
                              <div class="g-clr bookingor-flex">
                                <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 class="due-remaining-price"> <?php echo esc_html(HelperControl::priceDecimal(($value->service_get_price + $value->service_tax +  $value->discount_get_price + $value->tax_get_price) - $value->paid_amount)); ?> </div>
                                </div>
                              </div>
                            </div>
                            <div class="tot-p">
                              <div class="f-w"><?php esc_html_e("Total", "bookingor"); ?></div>
                              <div class="g-clr bookingor-flex">
                                <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 class="subtotal"> <?php echo esc_html(HelperControl::priceDecimal(number_format((floatval($value->service_get_price) + floatval($value->extra_get_price)) - floatval($value->discount_get_price), 2, '.', ''))); ?> </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </td>
              </tr>
          <?php
            }
          } ?>
        </tbody>
      </table>
    </div>
  </div>
</div>