<?php

use Bookingor\Backend\Controller\Category\CategoryControl;

// 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="bkinz-m-0 p-r up-heading">
            <?php esc_html_e('Category', 'bookingor'); ?>
          </div>
          <a href="#categoryModal" id="category-add-btn" class="bookingor-btn bookingor-btn-primary bookingor-flex shw-bkdrp" data-bs-toggle="modal" data-bs-target="#categoryModal">
            <span><?php esc_html_e('Add Category', 'bookingor'); ?></span>
          </a>
        </div>

      </div>
      <!-- Modal -->
    </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('ID', 'bookingor'); ?>

            </th>
            <th class="bookingor-t-h-f">
              <?php esc_html_e('Category Icon', 'bookingor'); ?>
            </th>
            <th class="bookingor-t-h-f">
              <?php esc_html_e('Category Name', 'bookingor'); ?>
            </th>
            <?php if (class_exists('Bookingor\Frontend\Controller\ServiceSubcategory\ServiceSubcategoryControl')) {
            ?>
              <th class="bookingor-t-h-f">
                <?php esc_html_e('Subcategory', 'bookingor'); ?>
              </th>
            <?php
            } ?>
            <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 (CategoryControl::bp_category_view() as $key => $row) { ?>
            <tr class="bookingor-t-row">
              <td class="bookingor-t-f">
                <?php echo esc_html($row->category_id); ?>
              </td>
              <td class="bookingor-t-f">
                <div class="bookingor-category-icon">
                  <img class="bookingor-cate-icon" src="<?php echo esc_attr(!empty($row->icon) ? wp_get_attachment_url($row->icon) : CategoryControl::$view_icon); ?> " data-img-id="<?php echo esc_attr(($row->icon)); ?>" alt="">
                </div>
              </td>
              <td class="bookingor-t-f">
                <?php echo esc_html($row->category_name); ?>
              </td>
              <?php if (class_exists('Bookingor\Frontend\Controller\ServiceSubcategory\ServiceSubcategoryControl')) {
              ?>
                <td class="bookingor-t-f">
                  <?php echo esc_html($row->subcategory); ?>
                </td>
              <?php
              } ?>
              <td class="bookingor-t-f">
                <?php echo esc_html(($row->status === '1') ? 'Active' : 'Draft'); ?>
              </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="tcn_category_edit" data-id="<?php echo esc_attr($row->category_id); ?>" data-bs-toggle="modal" data-bs-target="#editModal" class="bp-category-view-update shw-bkdrp bookingor-gap-5">
                          <i class="dashicons dashicons-edit"></i><?php esc_html_e('Edit', 'bookingor'); ?>
                        </a>
                      </li>
                      <li>
                        <a class="bp-delete-category bookingor-gap-5" name="tcn_category_delete" data-id="<?php echo esc_attr($row->category_id); ?>">
                          <i class="dashicons dashicons-trash"></i><?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/documentation/add-category" target="_blank" class=" bookingor-f-13">Documentation</a>
    <div> | </div>
    <a href="https://youtu.be/15hzR33FmwU" target="_blank" class="bookingor-f-13">Video Tutorial</a>
    <div> | </div>
    <a href="https://bookingor.com/contact-support" target="_blank" class="bookingor-f-13">Need Help?</a>
  </div>
</div>