<?php

use Bookingor\Backend\Controller\Staff\StaffControl;


// Exit if accessed directly
if (! defined('ABSPATH')) exit; ?>
<div class="wrap bookingor">
  <header>
    <div class="bookingor-header">
      <div class="bookingor-flex bookingor-justify-b bookingor-width bookingor-align-items-c p-0-1">
        <div class="bookingor-flex bookingor-align-items-c">
          <div class="bookingor-m-0 p-r up-heading"><?php esc_html_e("Staff", "bookingor"); ?></div>
          <?php
          $staff = StaffControl::bp_view_staff();
          $staff_count = is_array($staff) ? count($staff) : (is_object($staff) ? count((array)$staff) : 0);
          $is_pro = class_exists('Bookingor\Backend\Controller\LocationTimeSheet\LocationTimeSheetControl');
          $add_staff_url = sanitize_text_field(isset($_SERVER['REQUEST_URI'])) ? esc_url(sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'] . '&type=add-team'))) : '';
          ?>
          <a href="<?php echo esc_url($add_staff_url); ?>" class="bookingor-btn bookingor-btn-primary bookingor-flex" id="bk_add_staff_btn"
            data-count="<?php echo esc_attr(intval($staff_count)); ?>"
            data-is-pro="<?php echo esc_attr($is_pro ? 'true' : 'false'); ?>">
            <span><?php esc_html_e("Add Staff", "bookingor"); ?></span>
          </a>
        </div>
      </div>
    </div>
  </header>
  <div class="tcn">
    <div id="myTable" class="bookingor-admin-bg t-p-all bookingor-d-none">
      <table id="example" class="table table-sm cards">
        <thead class="bookingor-t-head bookingor-t-h-r">
          <tr>
            <th></th>
          </tr>
        </thead>
        <tbody class="row">
          <?php
          foreach (StaffControl::bp_view_staff() as $key => $row) { ?>
            <tr class="bookingor-col-sm-6 bookingor-col-lg-4 bookingor-col-xxl-3  ">

              <td class="card-inner card card-bordered  bookingor-staff-border ">
                <div class="bookingor-d-flex flex-column align-items-center  text-center">
                  <div class="user-avatar-staff">
                    <?php if ($row->staff_icon) { ?>
                      <img class="memeber-ava" src="<?php echo esc_attr(wp_get_attachment_url($row->staff_icon));  ?>" alt="" />
                    <?php } else { ?>
                      <img class="memeber-ava" src=""
                        data-avatar="<?php echo esc_attr($row->staff_first_name . " " . $row->staff_last_name); ?>" alt="" />
                    <?php } ?>
                  </div>
                  <div class="bookingor-staff-name"><?php echo esc_html($row->staff_first_name . " " . $row->staff_last_name); ?></div>
                  <div class=""><?php echo esc_html($row->staff_email); ?></div>
                  <?php if (!empty($row->staff_phone)) { ?>
                    <div class=""><?php echo esc_html($row->staff_phone); ?></div>
                  <?php } else { ?>
                    <div>-</div>
                  <?php    } ?>
                  <div class="bookingor-f-12">
                    <?php echo esc_html($row->location_address); ?>
                  </div>
                  <div class=""><?php esc_html_e("activated", "bookingor"); ?></div>
                  <div class="bookingor-backend-staff-dropdown">
                    <div class="bookignor-backend-staff-ids"><?php echo esc_html__('ID:', 'bookingor') . ' ' . esc_html($row->staff_id); ?> </div>
                    <div class=" dropdown c-drop">
                      <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
                        <div class="bkingor-svg">
                          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                            <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>
                      </a>
                      <div class="dropdown-menu bookingor-dropdown">
                        <ul class="bookingor-list-link">
                          <li>
                            <a class="bp-staff_update"
                              href="<?php echo sanitize_text_field(isset($_SERVER['REQUEST_URI'])) ? esc_url(sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'] . '&type=edit-team&id=' . (isset($row->staff_id) ? $row->staff_id : '')))) : ''; ?>"
                              name="bp_staff_id" data-id="<?php echo esc_attr($row->staff_id); ?>"><?php esc_html_e("Edit", "bookingor"); ?></a>
                          </li>
                          <li>
                            <a class="bkinz-delete-staff" name="bp_staff_delete"
                              data-id="<?php echo esc_attr($row->staff_id); ?>"><?php esc_html_e("Remove", "bookingor"); ?></a>
                          </li>
                        </ul>
                      </div>

                    </div>
                  </div>

                </div>
              </td>
            </tr>
          <?php } ?>
        </tbody>
      </table>
    </div>
  </div>
  <div class="mt-2 bookingor-d-flex bookingor-g-5 bookingor-doc-help">
    <a href="https://bookingor.com/documentation/add-staff" target="_blank" class=" bookingor-f-13">Documentation</a>
    <div> | </div>
    <a href="https://bookingor.com/contact-support" target="_blank" class="bookingor-f-13">Need Help?</a>
  </div>

  <!-- Pro Plan Modal -->
  <div class="modal fade" id="proStaffModal" tabindex="-1" aria-labelledby="proStaffModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content bkings_pro-model">
        <div class="modal-header flex-column">
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          <div class="boookingor-popup-text text-center w-100">
            <box-icon name="crown" type="solid" color="#ffb800" size="lg"></box-icon>
            <h3 class="modal-title mt-2" id="proStaffModalLabel"><?php esc_html_e("Upgrade to Pro", "bookingor"); ?></h3>
            <p class="mb-0"><?php esc_html_e("The free version allows only 2 staff members.", "bookingor"); ?></p>
          </div>
        </div>
        <div class="modal-body px-4 py-4">
          <p class="text-center mb-4"><?php esc_html_e("Upgrade to our Pro plan to add unlimited staff members and unlock powerful features.", "bookingor"); ?></p>
          <ul class="list-group list-group-flush mb-4 bookingor-pro-list">
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Unlimited Staff Members", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Unlmited Staff Asigned", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Each Staff have Own Working Hours", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Staff Signup/login", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Staff Dashboard & Management", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Premium Support", "bookingor"); ?></li>
          </ul>
        </div>
        <div class="modal-footer justify-content-center">
          <a href="https://bookingor.com/pricing" target="_blank" class="bookingor-btn bookingor-btn-primary w-100 text-center bookingor-pro-btn"><?php esc_html_e("Buy Pro Plan", "bookingor"); ?></a>
        </div>
      </div>
    </div>
  </div>
</div>