<?php

use Bookingor\Backend\Controller\Notification\NotificationControl;
// Exit if accessed directly
if (! defined('ABSPATH')) exit; ?>
<style>
.bookingor-required-license {
    position: relative !important;
}
.bookingor-required-license::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 10;
    border-radius: 12px;
}
.bookingor-required-license::after {
    content: '🔒 Pro Version Required';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    padding: 14px 28px;
    border-radius: 30px;
    font-weight: 700;
    box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    white-space: nowrap;
}
.bookingor-required-license * {
    pointer-events: none !important;
    user-select: none !important;
}
</style>
<div class="bookingor containers">



  <ul class="nav nav-pills mb-3 n-tabs">
    <li class="nav-item" role="presentation">
      <button class=" tab-btn active active-tbs" id="email-notification-tab" data-bs-toggle="pill" data-bs-target="#email-notification" type="button" aria-controls="email-notification"><?php esc_html_e("Email Notifications", "bookingor");  ?>
      </button>
      <?php if (class_exists('Bookingor\Backend\Controller\Twilio\TwilioController')) { ?>
        <button class="tab-btn" id="sms-notification-tab" data-bs-toggle="pill" data-bs-target="#sms-notification" type="button" aria-controls="sms-notification"><?php esc_html_e("SMS Notifications", "bookingor");  ?>
        </button>
      <?php }
      if (class_exists('Bookingor\Backend\Whatsapp\WhatsappControl')) { ?>
        <button class="tab-btn" id="whatsapp-notification-tab" data-bs-toggle="pill" data-bs-target="#whatsapp-notification" type="button" aria-controls="whatsapp-notification"><?php esc_html_e("Whatsapp Notifications", "bookingor");  ?>
        </button>
      <?php } ?>
    </li>
  </ul>
  <div class="tab-content" id="pills-tabContent">

    <div class=" tab-pane fade show active" id="email-notification" aria-labelledby="email-notification-tab">
      <form id="email-notification-all">
        <input type="hidden" id="get-email-id" name="get_email_id" value="" />
        <input type="hidden" id="notification-type" name="notification_type" value="email" />
        <div class="row">
          <div class="bookingor-col-xl-3 bookingor-col-lg-12 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12">
            <div class="lg-bk mb-2">
              <div class="tab-content" id="pills-tabContent">
                <form action="" id="bkinz-send-emails">
                  <div>
                    <ul class="nav nav-pills mb-3 u-tbs">
                      <li class="nav-item tg-button">
                        <button class="tb-btn active active-tb" id="pills-customer-tab" data-bs-toggle="pill" data-bs-target="#pills-customer" type="button" aria-controls="pills-customer"><?php esc_html_e("To Customer", "bookingor"); ?></button>
                      </li>
                      <li class="nav-item tg-button">
                        <button class="tb-btn" id="pills-Employee-tab" data-bs-toggle="pill"
                          data-bs-target="#pills-Employee" type="button" aria-controls="pills-Employee"><?php esc_html_e("To Employee", "bookingor"); ?></button>
                        </button>
                      </li>
                    </ul>
                    <div class="tab-content" id="pills-tabContent">
                      <div class="tab-pane fade show active" id="pills-customer" aria-labelledby="pills-customer-tab">
                        <div>
                          <h6><?php esc_html_e("Customer Notifications", "bookingor"); ?></h6>
                        </div>
                        <div class="c-level">
                          <div class="all-pd">
                            <ul class="nav nav-ct nav-pills mb-3">
                              <?php foreach (
                                NotificationControl::bp_get_emails_all() as $key =>
                                $value
                              ) {
                                if ($value->send_to === "customer") { ?>
                                  <li class="nt-emails" data-email-id="<?php echo esc_attr($value->id); ?>">
                                    <div class="bookingor-active" id="<?php echo esc_attr($value->name_action); ?>-tab">
                                      <div class="m-b">
                                        <label class="lb-ap">
                                          <a href="" class="s-hf"><?php echo esc_html($value->name); ?></a>
                                        </label>
                                      </div>
                                    </div>
                                  </li>
                              <?php
                                }
                              } ?>
                            </ul>
                          </div>
                        </div>
                      </div>
                      <div class="tab-pane fade" id="pills-Employee" aria-labelledby="pills-Employee-tab">
                        <div>
                          <h6><?php esc_html_e("Employee Notifications", "bookingor"); ?></h6>
                        </div>
                        <div class="c-level">
                          <div class="all-pd">
                            <ul class="nav nav-ct nav-pills mb-3">
                              <?php foreach (
                                NotificationControl::bp_get_emails_all() as $key =>
                                $value
                              ) {
                                if ($value->send_to === "employee") { ?>
                                  <li class="nt-emails" data-email-id="<?php echo esc_attr($value->id); ?>">
                                    <div id="<?php echo esc_attr($value->name_action); ?>-tab">
                                      <div class="m-b">
                                        <label class="lb-ap">
                                          <a href="" class="s-hf"><?php echo esc_html($value->name); ?></a>
                                        </label>
                                      </div>
                                    </div>
                                  </li>
                              <?php
                                }
                              } ?>
                            </ul>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </div>
          <div class="bookingor-col-xl-9 bookingor-col-lg-12 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12 bookingor-g-0">
            <div class="row ">
              <div class="bookingor-col-xl-9 bookingor-col-lg-9 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12">
                <div class="tab-content" id="get-all-emails">
                  <?php foreach (
                    NotificationControl::bp_get_emails_all() as $key =>
                    $value
                  ) { 
                    $is_license_required = in_array($value->name_action, [
                      'customer_email_rescheduled',
                      'employee_email_rescheduled',
                      'customer_email_next_day_reminder',
                      'employee_email_next_day_reminder',
                      'customer_email_follow_up',
                      'employee_email_follow_up'
                    ]);
                  ?>
                    <div class="bookingor-ac-email tab-pane fade <?php echo $is_license_required ? 'bookingor-required-license' : ''; ?>" data-email-id="<?php echo esc_attr($value->id); ?>" id="<?php echo esc_attr($value->name_action); ?>">
                      <div class="lg-bk">
                        <div>
                          <h6><?php echo esc_html($value->name); ?></h6>
                        </div>
                        <div class="pb-4">
                          <label><?php esc_html_e("Subject", "bookingor"); ?></label>
                          <input type="text" name="cs_email_subject[]" id="cs-email-subject-<?php echo esc_attr($value->id); ?>"
                            class="form-control s-ip" value="<?php echo esc_attr($value->subject); ?>" <?php echo $is_license_required ? 'disabled' : ''; ?> />
                        </div>
                        <div id="customer-email-text-<?php echo esc_attr($value->id); ?>">
                          <div id="<?php echo esc_attr($value->name_action); ?>_text" data-text="">
                            <div class="ql-editor" data-gramm="false" contenteditable="<?php echo $is_license_required ? 'false' : 'true'; ?>" spellcheck="false">
                              <?php echo wp_kses_decode_entities($value->text); ?></div>
                          </div>
                        </div>
                        <div>
                          <div class="pb-4 bookingor-col-2 ">
                            <label><?php esc_html_e("Status", "bookingor"); ?></label>
                            <select name="status" id="cs-email-status-<?php echo esc_attr($value->id); ?>" class="form-select s-ip" <?php echo $is_license_required ? 'disabled' : ''; ?>>
                              <option value="1" <?php selected($value->status, '1'); ?>><?php esc_html_e("Active", "bookingor"); ?></option>
                              <option value="0" <?php selected($value->status, '0'); ?>><?php esc_html_e("Inactive", "bookingor"); ?></option>
                            </select>
                          </div>
                          <?php if (strpos($value->name_action, 'next_day_reminder') !== false) { ?>
                            <div class="pb-4">
                              <label for="send-on-time-<?php echo esc_attr($value->id); ?>"><?php esc_html_e("Send at", "bookingor"); ?></label>
                              <select name="send_on_time" id="send-on-time-<?php echo esc_attr($value->id); ?>" class="form-select s-ip" <?php echo $is_license_required ? 'disabled' : ''; ?>>
                                <?php
                                $current_time = !empty($value->send_on_time) ? substr($value->send_on_time, 0, 5) : '09:00';
                                for ($h = 0; $h < 24; $h++) {
                                  for ($m = 0; $m < 60; $m += 30) {
                                    $time_val = sprintf('%02d:%02d', $h, $m);
                                    $time_label = date("g:i a", strtotime($time_val));
                                    $selected = ($current_time === $time_val) ? 'selected' : '';
                                    echo '<option value="' . esc_attr($time_val) . '" ' . $selected . '>' . esc_html($time_label) . '</option>';
                                  }
                                }
                                ?>
                              </select>
                            </div>
                            <?php
                            $admin_ajax_url = admin_url('admin-ajax.php');
                            $cron_url = add_query_arg([
                              'action' => 'bookingor_api',
                              'call' => '/notifications/scheduled/send'
                            ], $admin_ajax_url);
                            ?>
                            <div class="cron-config-container mt-3 p-3 rounded" style="background: linear-gradient(135deg, #1e293b, #0f172a); border: 1px solid #334155; color: #f8fafc; font-family: 'Outfit', sans-serif; box-shadow: 0 4px 20px rgba(0,0,0,0.15); margin-bottom: 20px;">
                              <div class="d-flex align-items-center mb-2">
                                <span style="font-size: 1.2rem; margin-right: 8px;">⏰</span>
                                <h6 class="m-0" style="color: #38bdf8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;"><?php esc_html_e("Cron Job Configuration", "bookingor"); ?></h6>
                              </div>
                              <p style="font-size: 0.85rem; color: #94a3b8; margin-bottom: 12px; line-height: 1.4;">
                                <?php esc_html_e("To automate next-day reminders, configure a system cron job on your server using the crontab command or URL below:", "bookingor"); ?>
                              </p>

                              <div class="mb-3">
                                <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; text-transform: uppercase; display: block; margin-bottom: 4px;"><?php esc_html_e("Crontab Command (Updates dynamically based on Send at)", "bookingor"); ?></label>
                                <div class="position-relative">
                                  <code class="cron-command-block d-block p-2 rounded" style="padding:0 !important; background-color: #020617; border: 1px solid #1e293b; color: #34d399; font-size: 0.85rem; white-space: pre-wrap; word-break: break-all; padding-right: 40px !important;" id="cron-command-<?php echo esc_attr($value->id); ?>" data-base-url="<?php echo esc_url($cron_url); ?>"></code>
                                  <button type="button" class="btn-copy-cron position-absolute top-50 translate-middle-y end-0 me-2" style="background: none; border: none; color: #94a3b8; cursor: pointer; transition: color 0.2s;" data-target="cron-command-<?php echo esc_attr($value->id); ?>" title="<?php esc_attr_e("Copy to clipboard", "bookingor"); ?>">
                                    <i class="fa fa-clone"></i>
                                  </button>
                                </div>
                              </div>

                              <div>
                                <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; text-transform: uppercase; display: block; margin-bottom: 4px;"><?php esc_html_e("Direct Cron URL", "bookingor"); ?></label>
                                <div class="position-relative">
                                  <code class="cron-url-block d-block p-2 rounded" style="padding:0 !important; background-color: #020617; border: 1px solid #1e293b; color: #38bdf8; font-size: 0.85rem; white-space: pre-wrap; word-break: break-all; padding-right: 40px !important;" id="cron-url-<?php echo esc_attr($value->id); ?>"><?php echo esc_url($cron_url); ?></code>
                                  <button type="button" class="btn-copy-cron position-absolute top-50 translate-middle-y end-0 me-2" style="background: none; border: none; color: #94a3b8; cursor: pointer; transition: color 0.2s;" data-target="cron-url-<?php echo esc_attr($value->id); ?>" title="<?php esc_attr_e("Copy to clipboard", "bookingor"); ?>">
                                    <i class="fa fa-clone"></i>
                                  </button>
                                </div>
                              </div>
                            </div>
                          <?php } ?>
                        </div>
                      </div>
                    </div>
                  <?php
                  }
                  ?>
                </div>
                <div class="st-btns mt-3">
                  <button type="submit" class="status main-top-buttons btn_blue ml-2 valid"><?php esc_html_e("Save", "bookingor"); ?></button>
                </div>
              </div>
              <div class="bookingor-col-xl-3 bookingor-col-lg-3 bookingor-col-md-12 bookingor-col-sm-12 bookingor-col-12">
                <div class="accordion accordion-flush" id="accordionFlushExample">
                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-headingOne">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-category" aria-expanded="false" aria-controls="string-category">
                        <?php esc_html_e("Category", "bookingor"); ?>
                      </button>
                    </h2>
                    <div id="string-category" class="accordion-collapse collapse" aria-labelledby="flush-headingOne"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#category_name]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-headingTwo">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-services" aria-expanded="false" aria-controls="string-services">
                        <?php esc_html_e("Services", "bookingor"); ?>
                      </button>
                    </h2>
                    <div id="string-services" class="accordion-collapse collapse" aria-labelledby="string-services"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#currency_symbol]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_description]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_cost]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_deposit]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_deposit_type]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_tax]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_duration]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_duration_type]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#timeslot_length]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_slot_increment]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#padding_before]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#padding_after]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_capacity_min]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#service_capacity_max]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#recurring_status]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#recurring_type]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#recurring_payment]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#status]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#zoom_meeting_url]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#zoom_join_url]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>

                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-heading6">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-location" aria-expanded="false" aria-controls="string-location">
                        <?php esc_html_e("Location", "bookingor"); ?>
                      </button>
                    </h2>
                    <div id="string-location" class="accordion-collapse collapse" aria-labelledby="string-location"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#location_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#location_country]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#location_city]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#location_address]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#location_phone]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-heading5">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-staff" aria-expanded="false" aria-controls="string-staff">
                        <?php esc_html_e("Employee", "bookingor"); ?>
                      </button>
                    </h2>
                    <div id="string-staff" class="accordion-collapse collapse" aria-labelledby="string-staff"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#staff_first_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#staff_last_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#staff_email]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#staff_phone]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                  <div class="g-api-acodin">
                    <h2 class="accordion-header">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-customer" aria-expanded="false" aria-controls="string-customer">
                        <?php esc_html_e("Customer", "bookingor"); ?>
                      </button>
                    </h2>
                    <div id="string-customer" class="accordion-collapse collapse" aria-labelledby="string-customer"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#customer_first_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#customer_last_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#customer_phone]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#customer_email]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-headingThree">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-appointment" aria-expanded="false"
                        aria-controls="string-appointment"><?php esc_html_e("Appointment", "bookingor"); ?></button>
                    </h2>
                    <div id="string-appointment" class="accordion-collapse collapse" aria-labelledby="string-appointment"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#book_start_time]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#book_end_time]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#book_date]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#book_payment_method]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#book_paid_amount]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                  <div class="g-api-acodin">
                    <h2 class="accordion-header" id="flush-headingFour">
                      <button class="accordion-button acc-btn collapsed" type="button" data-bs-toggle="collapse"
                        data-bs-target="#string-business" aria-expanded="false"
                        aria-controls="string-business"><?php esc_html_e("Business", "bookingor"); ?></button>
                    </h2>
                    <div id="string-business" class="accordion-collapse collapse" aria-labelledby="string-business"
                      data-bs-parent="#accordionFlushExample">
                      <div>
                        <ul>
                          <li><?php esc_html_e("[#business_name]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#business_email]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#business_phone]", "bookingor"); ?></li>
                          <li><?php esc_html_e("[#business_website]", "bookingor"); ?></li>
                        </ul>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
    <?php if (class_exists('Bookingor\Backend\Controller\Twilio\TwilioController')) {

      require_once(ABSPATH . 'wp-content/plugins/bookingor-sms/admin/partials/bookingor-sms-admin-display.php');
    }
    if (class_exists('Bookingor\Backend\Whatsapp\WhatsappControl')) {
      require_once(ABSPATH . 'wp-content/plugins/bookingor-whatsapp/app/Backend/View/Whatsapp/whatsapp-notification.php');
    }
    ?>

  </div>

</div>