<?php

use Bookingor\Backend\Controller\Location\LocationControl;
// Exit if accessed directly
if (! defined('ABSPATH')) exit; ?>
<div class="wrap bookingor">
  <header>
    <div class="bookingor-header" id="bookingor-get-map-key"
      data-google-key="<?php echo esc_attr(get_option('bookingor_settings_google_maps_api_key')); ?>">
      <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("Location", "bookingor"); ?></div>

          <?php
          $locations = Bookingor\Backend\Controller\Location\LocationControl::bp_get_location_view();
          $location_count = is_array($locations) ? count($locations) : (is_object($locations) ? count((array)$locations) : 0);
          $is_pro = class_exists('Bookingor\Backend\Controller\LocationTimeSheet\LocationTimeSheetControl');
          ?>
          <a href="#" class="bookingor-btn bookingor-btn-primary bookingor-flex shw-bkdrp" id="bk_add_location_btn"
            data-count="<?php echo esc_attr(intval($location_count)); ?>"
            data-is-pro="<?php echo esc_attr($is_pro ? 'true' : 'false'); ?>">
            <box-icon name="plus"></box-icon><span><?php esc_html_e("Add Location", "bookingor"); ?></span>
          </a>
        </div>
      </div>
    </div>
  </header>
  <div class="bookingor">
    <div id="myTable" class="bookingor-admin-bg t-p-all bookingor-d-none">
      <table id="example" 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"><?php esc_html_e("Location ID", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Location Title", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("City Name", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Phone", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Address", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Status", "bookingor"); ?></th>
            <th class="bookingor-t-h-f"><?php esc_html_e("Action", "bookingor"); ?></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach (
            LocationControl::bp_get_location_view() as $key =>
            $value
          ) { ?>
            <tr class="bookingor-t-row">
              <td class="bookingor-t-f"><?php echo esc_html($value->location_id); ?></td>
              <td class="bookingor-t-f"><?php echo esc_html($value->location_title); ?></td>
              <td class="bookingor-t-f"><?php echo esc_html($value->location_city); ?></td>
              <td class="bookingor-t-f"><?php echo esc_html($value->location_phone); ?></td>
              <td class="bookingor-t-f"><?php echo esc_html($value->location_address); ?></td>
              <td class="bookingor-t-f"><?php esc_html_e("Activated", "bookingor"); ?></td>
              <td class="bookingor-t-f">
                <div class="dropdown c-drop">
                  <a href="#" class="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 name="bp_location_edit" data-id="<?php echo esc_attr($value->location_id); ?>" data-bs-toggle="modal" data-bs-target="#locationEditModal"
                          class="bp-location-update-b-id shw-bkdrp" class="tcn-location-update">
                          <i class="pop-size bx bx-edit-alt"></i><?php esc_html_e("Edit", "bookingor"); ?></a>
                      </li>
                      <li>
                        <a class="bp-delete-location" name="bp_location_delete" data-id="<?php echo esc_attr($value->location_id); ?>"><?php esc_html_e("Remove", "bookingor"); ?></a>
                      </li>
                    </ul>
                  </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/docs-category/location" 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="proLocationModal" tabindex="-1" aria-labelledby="proLocationModalLabel" 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="proLocationModalLabel"><?php esc_html_e("Upgrade to Pro", "bookingor"); ?></h3>
            <p class="mb-0"><?php esc_html_e("The free version allows only 1 location.", "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 locations 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 Locations", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Location Base Time sheets", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Each Location have Own Working Hours", "bookingor"); ?></li>
            <li class="list-group-item d-flex align-items-center bookingor-pro-list-item"><?php esc_html_e("Extraordinary Features", "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>