AlkantarClanX12

Your IP : 216.73.217.24


Current Path : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/lib/
Upload File :
Current File : /www/capitalgmcbuickregina_830/public/wp-content/plugins/leadbox/lib/settings.php

<?php

use function PHPSTORM_META\type;

/**
 * Check if current page is a Leadbox/Dealer settings page or saving settings
 * Used to conditionally load settings registration for performance optimization
 *
 * @return bool True if on Leadbox or Dealer settings page, or saving settings
 */
function leadbox_is_settings_page()
{
    // Check if we're on options.php (saving settings)
    global $pagenow;
    if ($pagenow === 'options.php') {
        // Check if saving a Leadbox/Dealer option
        $option_page = isset($_POST['option_page']) ? sanitize_text_field($_POST['option_page']) : '';
        $leadbox_option_groups = array(
            'custom-css-options-group',
            'leadbox-settings-options-group',
            'dealer-settings-branding-options-group',
            'dealer-settings-web-info-group',
            'dealer-settings-showroom-group',
            'dealer-settings-vdp-payment-group',
            'dealer-settings-used-finance-group',
            'dealer-settings-hours-options-group',
            'dealer-settings-labels-options-group',
            'dealer-settings-my-garage-options-group',
            'dealer-settings-listing-options-group',
            'dealer-settings-used-finance-custom-options-group',
            'dealer-settings-contact-options-group',
            'dealer-settings-socialmedia-options-group',
            'dealer-settings-policies-options-group',
            'dealer-settings-disclaimer-options-group',
            'dealer-settings-filter-options-group',
            'dealer-settings-iboost-options-group',
        );
        if (in_array($option_page, $leadbox_option_groups, true)) {
            return true;
        }
    }

    $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';

    $settings_pages = array(
        // Leadbox Settings pages
        'leadbox-settings',
        'leadbox-settings-genius',
        'leadbox-settings-leads-sent',
        'leadbox-settings-load-dealer-settings',
        'leadbox-logs',
        'custom-css',
        // Dealer Settings pages
        'dealer-settings',
        'dealer-settings-hours',
        'dealer-settings-labels',
        'dealer-settings-contact',
        'dealer-settings-used_finance_custom',
        'dealer-settings-listing',
        'dealer-settings-socialmedia',
        'dealer-settings-disclaimer',
        'dealer-settings-filter',
        'dealer-settings-policies',
        'Backend login',
        'dealer-settings-web-info',
        'dealer-settings-showroom',
        'dealer-settings-my-garage',
        'dealer-settings-vdp-payment',
    );

    return in_array($page, $settings_pages, true);
}

class LeadboxSettings
{
  /**
   * Holds the values to be used in the fields callbacks
   */
  private $branding_options;
  private $hours_options;
  private $labels_options;
  private $my_garage_options;
  private $contact_options;
  private $listing_options;
  private $socialmedia_options;
  private $used_finance_options;
  private $used_finance_custom_options;
  private $disclaimer_options;
  private $filter_options;
  private $iboost_options;
  private $policies_options;
  private $hour_range_options;
  private $font_size_range_options;
  private $newsletter_options;
  private $vdp_payment_options;

  /**
   * Start up
   */
  public function __construct()
  {

		require_once __DIR__ . '/functions.php';

    $this->hour_range_options = array(
      '6:30am',
      '7:00am',
      '7:30am',
      '8:00am',
      '8:30am',
      '9:00am',
      '9:30am',
      '10:00am',
      '10:30am',
      '11:00am',
      '11:30am',
      '12:00pm',
      '12:30pm',
      '1:00pm',
      '1:30pm',
      '2:00pm',
      '2:30pm',
      '3:00pm',
      '3:30pm',
      '4:00pm',
      '4:30pm',
      '5:00pm',
      '5:30pm',
      '6:00pm',
      '6:30pm',
      '7:00pm',
      '7:30pm',
      '8:00pm',
      '8:30pm',
      '9:00pm',
      '9:30pm',
      '10:00pm',
      '10:30pm',
      '11:00pm'
    );

    $this->font_size_range_options = '
    <option value="20px">20px</option>
    <option value="18px">18px</option>
    <option value="16px">16px</option>
    <option value="14px">14px</option>
    <option value="12px">12px</option>
    <option value="10px">10px</option>';

    $this->provinces_options = array('AB','BC','MB','NB','NL','NS','ON','PE','QC','SK','NT','NU','YT');

    $this->oem_program_options = array('Leadbox','Ford','FCA','JLR','Toyota','Lexus','GM','Stellantis');

    // Menu registration - must run on all admin pages
    add_action('admin_menu', array($this, 'add_dealer_menu'));
    add_action('admin_menu', array($this, 'add_leadbox_menu'));
    add_action('admin_menu', array($this, 'add_css_custom'));
    // LBT-1462: LBX Listing Images as its own top-level menu. Priority 11 so it
    // registers after Dealer Settings / Leadbox Settings and lands right after them.
    add_action('admin_menu', array($this, 'add_listing_images_menu'), 11);

    // Settings registration - only on settings pages (performance optimization)
    add_action('admin_init', array($this, 'maybe_register_settings'));

    // Scripts - only enqueue on settings pages
    add_action('admin_enqueue_scripts', array($this, 'enqueue_used_finance_scripts'));
    add_action('admin_enqueue_scripts', array($this, 'enqueue_listing_images_scripts'));
    add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));

    // AJAX handlers - must always be registered
    add_action('wp_ajax_save_custom_finance_options', array($this, 'save_custom_finance_options'));
    add_action('wp_ajax_update_custom_finance_options', array($this, 'update_custom_finance_options'));
    add_action('wp_ajax_delete_finance_entry', array($this, 'delete_finance_entry'));
    add_action('wp_ajax_delete_selected_entries', array($this, 'delete_selected_entries'));
    // LBT-1462 - listing images repeater
    add_action('wp_ajax_save_listing_image', array($this, 'save_listing_image'));
    add_action('wp_ajax_update_listing_images', array($this, 'update_listing_images'));
    add_action('wp_ajax_delete_listing_image', array($this, 'delete_listing_image'));
    add_action('wp_ajax_delete_selected_listing_images', array($this, 'delete_selected_listing_images'));
    add_action('wp_ajax_save_listing_images_config', array($this, 'save_listing_images_config'));
    add_action('wp_ajax_set_data_google_sheet', array($this, 'set_data_google_sheet'));
    add_action('wp_ajax_save_json_file', array($this, 'save_json_file'));
    add_action('wp_ajax_save_json_option', array($this, 'save_json_option'));
    add_action('wp_ajax_get_genius_components', array($this, 'get_genius_components'));
  }

  /**
   * Conditionally register settings only when on Leadbox/Dealer settings pages
   * This optimization saves ~15-25ms on non-settings admin pages by avoiding
   * unnecessary calls to register_setting(), add_settings_section(), and add_settings_field()
   *
   * @return void
   */
  public function maybe_register_settings()
  {
    if (!leadbox_is_settings_page()) {
      return;
    }

    // Register all settings
    $this->register_branding_settings();
    $this->register_hours_settings();
    $this->register_labels_settings();
    $this->register_my_garage_settings();
    $this->register_used_finance_settings();
    $this->register_used_finance_custom_settings();
    $this->register_web_info_settings();
    $this->register_contact_settings();
    $this->register_listing_settings();
    $this->register_socialmedia_settings();
    $this->register_disclaimer_settings();
    $this->register_filter_settings();
    $this->register_iboost_settings();
    $this->register_policies_settings();
    $this->register_vdp_payment_settings();
    $this->register_leadbox_settings();
    $this->register_custom_css();
    $this->register_showroom_settings();
  }

  /**
   * Add options page
   */
  public function add_css_custom()
  {
    global $_wp_last_object_menu;

    $_wp_last_object_menu++;

    add_menu_page(
      'Custom CSS',
      'Custom CSS',
      'manage_options',
      'custom-css',
      array($this, 'create_custom_css_page'),
      'dashicons-admin-settings',
      $_wp_last_object_menu
    );
  }

  public function add_leadbox_menu()
  {
    global $_wp_last_object_menu;

    $_wp_last_object_menu++;

    add_menu_page(
      'Leadbox Settings',
      'Leadbox Settings',
      'leadbox_settings',
      'leadbox-settings',
      array($this, 'create_leadbox_settings_page'),
      'dashicons-admin-settings',
      $_wp_last_object_menu
    );

    add_submenu_page(
      'leadbox-settings',
      __('Genius', 'leadbox-settings'),
      __('Genius', 'leadbox-settings'),
      'leadbox_settings',
      'leadbox-settings-genius',
      array($this, 'create_leadbox_settings_genius_page'),
    );

    add_submenu_page(
      'leadbox-settings',
      __('Failed Leads', 'leadbox-settings'),
      __('Failed Leads', 'leadbox-settings'),
      'leadbox_settings',
      'leadbox-settings-leads-sent',
      array($this, 'create_leadbox_settings_leads_sent_page'),
    );

    add_submenu_page(
      'leadbox-settings',
      __('Load Dealer Settings', 'leadbox-settings'),
      __('Load Dealer Settings', 'leadbox-settings'),
      'leadbox_settings',
      'leadbox-settings-load-dealer-settings',
      array($this, 'create_leadbox_settings_load_dealer_settings'),
    );

    add_submenu_page(
      'leadbox-settings',
      __('Error Logs', 'leadbox-settings'),
      __('Error Logs', 'leadbox-settings'),
      'manage_options',
      'leadbox-logs',
      array($this, 'create_leadbox_logs_page'),
    );

    add_menu_page(
      'Menus',
      'Menus',
      'menus',
      'nav-menus.php',
      '',
      'dashicons-menu',
      $_wp_last_object_menu
    );

    add_menu_page(
      'Widgets',
      'Widgets',
      'widgets',
      'widgets.php',
      '',
      'dashicons-admin-generic',
      $_wp_last_object_menu
    );
  }

  // LBT-1462: top-level "LBX Listing Images" menu, at the same level as Dealer
  // Settings and Leadbox Settings. Registered at admin_menu priority 11 so it is
  // placed after those two. The slug is kept as `dealer-settings-listing` so the
  // page callback, AJAX and enqueue hook keep matching.
  public function add_listing_images_menu()
  {
    global $_wp_last_object_menu;

    $_wp_last_object_menu++;

    add_menu_page(
      __('LBX Listing Images', 'dealer-settings'),
      __('LBX Listing Images', 'dealer-settings'),
      'manage_options',
      'dealer-settings-listing',
      array($this, 'create_listing_image_page'),
      'dashicons-images-alt2',
      $_wp_last_object_menu
    );
  }


  /**
   * Options page callback
   */

  public function create_custom_css_page()
  {
    // Set class property
    $this->custom_css = get_option('custom-css');
    ?>
    <div class="wrap">
      <h1>Custom CSSs</h1>
      <p style="font-size: 14px;color: red; font-style: oblique;">For advanced users only. Adjusting css may cause unintended layout changes. Leadbox is not able to support any css dealer may place in this area.</p>
      <form method="post" action="options.php">
        <?php

        settings_fields('custom-css-options-group');
        do_settings_sections('custom-css');
        submit_button();

        ?>
      </form>
    </div>
  <?php
  }

  public function create_leadbox_settings_page()
  {
    // Set class property
    $this->leadbox_settings = get_option('leadbox-settings');
    ?>
    <div class="wrap">
      <h1>Leadbox Settings</h1>
      <form method="post" action="options.php">
        <?php

        settings_fields('leadbox-settings-options-group');
        do_settings_sections('leadbox-settings');
        submit_button();

        ?>
      </form>
    </div>
  <?php
  }

  public function create_leadbox_settings_genius_page()
  {
    // Set class property
    $this->leadbox_settings = get_option('leadbox-settings');
    ?>
  <link rel="stylesheet" type="text/css" href="<?=plugin_dir_url(__FILE__)?>/addons/toastify.min.css">
  <script type="text/javascript" src="<?=plugin_dir_url(__FILE__)?>/addons/toastify-js.js"></script>
  <div id="saving-backdrop" style="display:none;">
      <div id="saving-message">
          <p>Saving file...</p>
      </div>
  </div>

  <style>
      #saving-backdrop {
          position: fixed;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background-color: rgba(0, 0, 0, 0.5);
          z-index: 9999;
          display: flex;
          align-items: center;
          justify-content: center;
      }

      #saving-message {
          background-color: white;
          padding: 20px;
          border-radius: 5px;
          box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
      }

/* Modal Styles */
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgb(0,0,0);
            background-color: rgba(0,0,0,0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            max-width: 500px;
            border-radius: 10px;
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
        .modal-header, .modal-footer {
            padding: 10px;
            text-align: center;
        }
        .modal-body {
            padding: 10px 20px;
        }
        .btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            margin: 10px 0;
            border: none;
            cursor: pointer;
            border-radius: 5px;
        }
        .btn:hover {
            background-color: #45a049;
        }

        @font-face {
          font-family: "Monaspace Krypton Light";
          src: url("<?=plugin_dir_url(__FILE__)?>/fonts/MonaspaceKrypton-Light.woff");
        }
        /* ---- Genius editor layout ---- */
        .genius-toolbar { display:flex; align-items:center; gap:8px; margin:12px 0; flex-wrap:wrap; }
        .genius-toolbar .genius-hint { color:#646970; font-size:12px; margin-left:4px; }
        #genius-status { font-weight:600; }
        #genius-status.is-error { color:#b32d2e; }
        #genius-status.is-ok { color:#1a7f37; }

        .genius-layout { display:grid; grid-template-columns: minmax(0, 1fr) 380px; gap:16px; align-items:start; }
        @media (max-width: 1200px) { .genius-layout { grid-template-columns: 1fr; } }

        #json-editor { height:640px; width:100%; border:1px solid #1e1e1e; border-radius:8px; overflow:hidden; }
        #json-editor.genius-fallback { padding:0; }
        #json-editor textarea.genius-fallback-area { width:100%; height:640px; box-sizing:border-box; border:0; padding:12px; font-family:"Monaspace Krypton Light", Menlo, Consolas, monospace; font-size:13px; line-height:1.4; resize:none; }

        .genius-sidebar { background:#fff; border:1px solid #e2e4e7; border-radius:8px; max-height:640px; display:flex; flex-direction:column; overflow:hidden; }
        .genius-sidebar-head { padding:12px; border-bottom:1px solid #eee; }
        .genius-sidebar-head h2 { margin:0 0 8px; font-size:13px; text-transform:uppercase; letter-spacing:.04em; color:#1d2327; }
        .genius-sidebar-head input { width:100%; box-sizing:border-box; }

        .genius-filters { display:flex; gap:6px; padding:10px 12px; border-bottom:1px solid #eee; flex-wrap:wrap; }
        .genius-chip { display:inline-flex; align-items:center; gap:6px; border:1px solid #c3c4c7; background:#f6f7f7; color:#1d2327; border-radius:999px; padding:3px 10px; font-size:12px; cursor:pointer; line-height:1.6; }
        .genius-chip.is-active { background:#2271b1; border-color:#2271b1; color:#fff; }
        .genius-count { background:rgba(0,0,0,.12); border-radius:999px; padding:0 6px; font-size:11px; }
        .genius-chip.is-active .genius-count { background:rgba(255,255,255,.25); }

        .genius-list { overflow:auto; padding:8px; flex:1; }
        .genius-card { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px 10px; border:1px solid #e2e4e7; border-radius:8px; margin-bottom:6px; cursor:pointer; transition:border-color .15s, box-shadow .15s; }
        .genius-card:hover { border-color:#2271b1; box-shadow:0 1px 4px rgba(0,0,0,.08); }
        .genius-card-main { min-width:0; flex:1; }
        .genius-card-name { font-weight:600; font-size:13px; color:#1d2327; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
        .genius-card-ver { font-size:12px; color:#646970; margin-top:2px; display:flex; align-items:center; gap:5px; }
        .genius-card-ver .dot { opacity:.55; }
        .genius-card-ver .count { color:#646970; }
        .genius-card-ver .using { color:#1d2327; font-weight:600; }
        .genius-card-right { display:flex; flex-direction:column; align-items:flex-end; gap:5px; }
        .genius-badges { display:flex; gap:4px; flex-wrap:wrap; justify-content:flex-end; }
        .genius-badge { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.03em; border-radius:4px; padding:2px 6px; white-space:nowrap; }
        .genius-badge.custom { background:#e6f0fb; color:#1a5fb4; }
        .genius-badge.missing { background:#fbe6e6; color:#b32d2e; }
        .genius-version-select { font-size:12px; max-width:90px; }
        .genius-empty { color:#646970; padding:12px; text-align:center; }
  </style>

      <div class="wrap">
        <h1>Edit Genius Config</h1>

        <div class="genius-toolbar">
          <button id="save-json" class="button button-primary">Save Genius configuration</button>
          <button id="format-json" class="button button-secondary">Format JSON</button>
          <span class="genius-hint">Press &#8984;/Ctrl + S to save</span>
          <span id="genius-status" class="genius-hint"></span>
        </div>

        <div class="genius-layout">
          <div id="json-editor"></div>

          <aside class="genius-sidebar">
            <div class="genius-sidebar-head">
              <h2>Components</h2>
              <input type="text" id="searchInput" placeholder="Search component…">
            </div>
            <div class="genius-filters">
              <button type="button" class="genius-chip is-active" data-filter="all">All <span class="genius-count" data-count="all">0</span></button>
              <button type="button" class="genius-chip" data-filter="custom">Custom <span class="genius-count" data-count="custom">0</span></button>
              <button type="button" class="genius-chip" data-filter="missing">Not in JSON <span class="genius-count" data-count="missing">0</span></button>
            </div>
            <div id="componentList" class="genius-list">
              <p class="genius-empty">Loading components…</p>
            </div>
          </aside>
        </div>

        <textarea id="json-content" name="json_content" style="display: none;"></textarea>

        <!-- Modal Structure -->
        <div id="myModal" class="modal">
            <div class="modal-content">
                <div class="modal-header">
                    <span class="close">&times;</span>
                    <h2>Information</h2>
                </div>
                <div id="modal-body" class="modal-body">
                    <!-- Dynamic content will be injected here -->
                </div>
                <div class="modal-footer">
                    <button id="close-modal-button" class="btn">Close</button>
                </div>
            </div>
        </div>

      </div>
    <?php
  }

  public function create_leadbox_settings_load_dealer_settings()
  {
    ?>
    <style>
    .file-upload-wrapper {
        position: relative;
        margin-bottom: 15px;
    }
    .file-upload-label {
        display: inline-block;
        padding: 8px 15px;
        background: #2271b1;
        color: #fff;
        border-radius: 3px;
        cursor: pointer;
        transition: background 0.3s;
    }
    .file-upload-label:hover {
        background: #135e96;
    }
    .file-upload-input {
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0;
        width: 100%;
        height: 100%;
        cursor: pointer;
    }
    .file-name {
        margin-left: 10px;
        color: #555;
    }

    .button-green {
      background: #4CAF50 !important;
      border-color: #46b450 !important;
      color: #fff !important;
      text-shadow: none !important;
      box-shadow: 1px 2px 3px black !important;
    }
    .button-green:hover {
      background: #3d8b40 !important;
      border-color: #367a39 !important;
    }
    </style>

    <div class="wrap">
        <h1 style="font-weight: bold;margin-bottom: 10px;">Load Dealer Settings</h1>

        <form method="post" enctype="multipart/form-data">
            <?php wp_nonce_field('upload_dealer_json', 'dealer_json_nonce'); ?>
            
            <div class="file-upload-wrapper">
                <label class="file-upload-label">
                    Select JSON file
                    <input type="file" name="dealer_json_file" accept=".json" class="file-upload-input">
                </label>
                <span class="file-name">No file selected</span>
            </div>
            
            <input type="submit" name="upload_dealer_json" value="Upload JSON file" class="button button-green">
        </form>

        <script>
            document.querySelector('.file-upload-input').addEventListener('change', function(e) {
                const fileName = e.target.files[0] ? e.target.files[0].name : 'No file selected';
                document.querySelector('.file-name').textContent = fileName;
            });
        </script>
        <?php $this->handle_json_upload(); ?>
    </div>
    <?php
  }

  public function handle_json_upload() {
    if (isset($_POST['upload_dealer_json'])) {
        if (!isset($_FILES['dealer_json_file']) || empty($_FILES['dealer_json_file']['tmp_name'])) {
            echo '<div class="notice notice-error"><p>No file was selected.</p></div>';
            return;
        }

        if (!wp_verify_nonce($_POST['dealer_json_nonce'], 'upload_dealer_json')) {
            echo '<div class="notice notice-error"><p>Nonce invalid.</p></div>';
            return;
        }

        $uploaded_file = $_FILES['dealer_json_file'];
        $upload_dir = WP_CONTENT_DIR . '/uploads/';
        $destination = $upload_dir . 'dealer_settings.json';

        if (move_uploaded_file($uploaded_file['tmp_name'], $destination)) {
          $return = $this->update_dealer_settings($destination);
      
          if ($return !== false) {
              echo '<div class="notice notice-success"><p>JSON file uploaded successfully.</p></div>';
              echo $return;
          } else {
              echo '<div class="notice notice-error"><p>Error processing JSON settings.</p></div>';
          }
      } else {
          echo '<div class="notice notice-error"><p>Error uploading the file.</p></div>';
      }
      
    }
  }

  public function isValidTime($time) {
    return preg_match('/^(?:0?[1-9]|1[0-2]):[0-5][0-9](?:am|pm)$/', $time) === 1;
  }

  public function update_dealer_settings($file_path)
  {
    if (!file_exists($file_path)) {
      echo '<div class="notice notice-error"><p>JSON file not found.</p></div>';
      return false;
    }

    $json_data = file_get_contents($file_path);
    $settings = json_decode($json_data, true);

    if (json_last_error() !== JSON_ERROR_NONE) {
      echo '<div class="notice notice-error"><p>JSON format error: ' . json_last_error_msg() . '</p></div>';
      return false;
    }

    // Validar estado de horario de servicio
    $valid_statuses = ['Enabled', 'Disabled'];
    $service_status = $settings['hours']['service']['status'] ?? 'Enabled';

    if (!in_array($service_status, $valid_statuses, true)) {
      echo '<div class="notice notice-error"><p>Invalid service status: must be "Enabled" or "Disabled".</p></div>';
      return false;
    }

    // Validar estado de horario de parts
    $parts_status = $settings['hours']['parts']['status'] ?? 'Enabled';
    if (!in_array($parts_status, $valid_statuses, true)) {
      echo '<div class="notice notice-error"><p>Invalid parts status: must be "Enabled" or "Disabled".</p></div>';
      return false;
    }

    // Validar estado de horario de additional_hours_1
    $additional_hours_1_status = $settings['hours']['additional_hours_1']['status'] ?? 'Enabled';
    if (!in_array($additional_hours_1_status, $valid_statuses, true)) {
      echo '<div class="notice notice-error"><p>Invalid additional_hours_1 status: must be "Enabled" or "Disabled".</p></div>';
      return false;
    }

    // Validar estado de horario de additional_hours_2
    $additional_hours_2_status = $settings['hours']['additional_hours_2']['status'] ?? 'Enabled';
    if (!in_array($additional_hours_2_status, $valid_statuses, true)) {
      echo '<div class="notice notice-error"><p>Invalid additional_hours_2 status: must be "Enabled" or "Disabled".</p></div>';
      return false;
    }

    // Validar estado de horario de additional_hours_3
    $additional_hours_3_status = $settings['hours']['additional_hours_3']['status'] ?? 'Enabled';
    if (!in_array($additional_hours_3_status, $valid_statuses, true)) {
      echo '<div class="notice notice-error"><p>Invalid additional_hours_3 status: must be "Enabled" or "Disabled".</p></div>';
      return false;
    }

    // Guardar cada valor del JSON en las opciones de WordPress
    $contact_settings = get_option('dealer-settings-contact-options', []);
    $social_settings = get_option('dealer-settings-socialmedia-options', []);
    $dealer_settings = get_option('dealer-settings-branding-options', []);
    $leadbox_settings = get_option('leadbox-settings', []);
    $disclaimer_settings = get_option('dealer-settings-disclaimer-options', []);
    $hours_settings = get_option('dealer-settings-hours-options', []);

    /* Hours */
    $days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
    $sections = [
      'sales' => 'sale_hours',
      'service' => 'service_hours',
      'parts' => 'parts_hours',
      'additional_hours_1' => 'additionalone_hours',
      'additional_hours_2' => 'additionaltwo_hours',
      'additional_hours_3' => 'additionalthree_hours'
    ];

    foreach ($sections as $sectionKey => $prefix) {

      $nprefix = preg_replace('/_hours$/', '', $prefix);
      if (in_array($sectionKey, ['additional_hours_1', 'additional_hours_2', 'additional_hours_3'])) {
        $label = $settings['hours'][$sectionKey]['label'] ?? '';
        $label_fr = $settings['hours'][$sectionKey]['label_fr'] ?? '';
        $add_status = $settings['hours'][$sectionKey]['status'] ?? 'Disabled';

        $hours_settings["{$nprefix}"] = $add_status;
        $hours_settings["{$nprefix}label"] = $label;
        $hours_settings["{$nprefix}labelfr"] = $label_fr;
      } 

      foreach ($days as $day) {
        $isClosed = $settings['hours'][$sectionKey][$day]['is_closed'] ?? '';
        $start = $settings['hours'][$sectionKey][$day]['start'] ?? '';
        $end = $settings['hours'][$sectionKey][$day]['end'] ?? '';

        

        if (!$isClosed) {
          if (!$this->isValidTime($start) || !$this->isValidTime($end)) {
            echo '<div class="notice notice-error"><p>Invalid time format for ' . ucfirst($day) . ' in ' . ucfirst($sectionKey) . '.</p></div>';
            return false;
          }
        }

        $hours_settings["{$prefix}_{$day}_start"] = $start;
        $hours_settings["{$prefix}_{$day}_end"] = $end;
        $hours_settings["{$prefix}_{$day}_closed"] = $isClosed;

      }
    }

    /* Contact Settings */
    $contact_settings['dealer_name'] = $settings['name'] ?? '';
    $contact_settings['dealer_url'] = $settings['url'] ?? '';
    $contact_settings['sale_phone'] = $settings['sale_phone'] ?? '';
    $contact_settings['service_phone'] = $settings['service_phone'] ?? '';
    $contact_settings['parts_phone'] = $settings['parts_phone'] ?? '';
    $contact_settings['collision_phone'] = $settings['collision_phone'] ?? '';
    $contact_settings['accessories_phone'] = $settings['accessories_phone'] ?? '';
    $contact_settings['fax'] = $settings['fax'] ?? '';
    $contact_settings['sms'] = $settings['sms'] ?? '';
    $contact_settings['body_shop'] = $settings['body_shop_phone'] ?? '';
    $contact_settings['primary_email'] = $settings['primary_email'] ?? '';
    $contact_settings['secondary_email'] = $settings['secondary_email'] ?? '';
    $contact_settings['address_line_1'] = $settings['address_line_1'] ?? '';
    $contact_settings['address_line_2'] = $settings['address_line_2'] ?? '';
    $contact_settings['address_city'] = $settings['address_city'] ?? '';
    $contact_settings['address_province'] = $settings['address_province'] ?? '';
    $contact_settings['address_postal_code'] = $settings['address_postal_code'] ?? '';
    $contact_settings['address_url_map_iframe'] = $settings['address_url_map'] ?? '';
    $contact_settings['address_timezone'] = $settings['time_zone'] ?? '';

    /* Social Media */
    $social_settings['facebook_socialmedia'] = $settings['social_media']['facebook'] ?? '';
    $social_settings['twitter_socialmedia'] = $settings['social_media']['twitter'] ?? '';
    $social_settings['instagram_socialmedia'] = $settings['social_media']['instagram'] ?? '';
    $social_settings['pinterest_socialmedia'] = $settings['social_media']['pinterest'] ?? '';
    $social_settings['youtube_socialmedia'] = $settings['social_media']['youtube'] ?? '';
    $social_settings['linkedin_socialmedia'] = $settings['social_media']['linkedin'] ?? '';
    $social_settings['tiktok_socialmedia'] = $settings['social_media']['tiktok'] ?? '';

    /* Dealer Settings */
    $dealer_settings['finance_frequency'] = $settings['finance_frequency'] ?? '';
    $dealer_settings['lease_frequency'] = $settings['lease_frequency'] ?? '';
    $dealer_settings['vehicle_count_option'] = $settings['vehicle_count_option'] ?? '';
    $dealer_settings['newsletter_enabled_option'] = $settings['newsletter_footer_form'] ?? '';

    /* Leadbox Settings */
    $leadbox_settings['manufacturer'] = $settings['manufacturer'] ?? '';
    $leadbox_settings['other_brands'] = $settings['other_brands_seo'] ?? '';
    $leadbox_settings['all_brands'] = $settings['other_brands_lineup'] ?? '';
    $leadbox_settings['oem_program'] = $settings['oem_programs'] ?? '';
    $leadbox_settings['oem_models'] = $settings['oem_models'] ?? '';

    /* Disclaimers */
    $disclaimer_settings['disclaimer_new'] = $settings['vdp_disclaimers']['new'] ?? '';
    $disclaimer_settings['disclaimer_used'] = $settings['vdp_disclaimers']['used'] ?? '';
    /*     
      $dealer_settings['oem_program'] = $settings['srp_disclaimers']['new'] ?? '';
      $dealer_settings['oem_program'] = $settings['srp_disclaimers']['used'] ?? ''; 
    */

    update_option('dealer-settings-contact-options', $contact_settings);
    update_option('dealer-settings-socialmedia-options', $social_settings);
    update_option('dealer-settings-branding-options', $dealer_settings);
    update_option('leadbox-settings', $leadbox_settings);
    update_option('dealer-settings-disclaimer-options', $disclaimer_settings);
    update_option('dealer-settings-hours-options', $hours_settings);

    return '<div class="notice notice-success"><p>Settings updated correctly.</p></div>';
  }


  public function create_leadbox_settings_leads_sent_page()
  {
      global $wpdb;
      $table_name = $wpdb->prefix . 'leadbox_leads';

      // Obtener los registros
      $leads = $wpdb->get_results("SELECT * FROM $table_name ORDER BY created_at DESC");

      ?>
      <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
      <div class="wrap">
          <h1 style="font-weight: bold;margin-bottom: 10px;">Failed Leads</h1>

          <table id="leadsTable" class="widefat fixed display" cellspacing="0" width="100%">
              <thead>
                  <tr>
                      <th width="10%">ID</th>
                      <th width="5%">Form ID</th>
                      <th width="5%">NF ID</th>
                      <th width="20%">Lead Data</th>
                      <th width="10%">Retry Count</th>
                      <th width="20%">LBX Lead ID</th>
                      <th width="15%">Created At</th>
                      <th width="15%">Sent At</th>
                  </tr>
              </thead>
              <tbody>
                  <?php if (!empty($leads)) : ?>
                      <?php foreach ($leads as $index => $lead) : ?>
                          <tr class="<?php echo ($index % 2 == 0) ? 'alternate' : ''; ?> <?php echo $lead->lbx_lead_id == NULL ? 'red' : '' ?>">
                              <td><?php echo esc_html($lead->id); ?></td>
                              <td><?php echo esc_html($lead->form_id); ?></td>
                              <td><?php echo esc_html($lead->nf_id); ?></td>
                              <td>
                                <button class="view-json-btn" data-json="<?php echo esc_attr($lead->lead_data); ?>">
                                  <?php echo esc_html(substr($lead->lead_data, 0, 100)) . '...'; ?>
                                </button>
                              </td>
                              <td><?php echo esc_html($lead->retry_count); ?></td>
                              <td><?php echo esc_html($lead->lbx_lead_id ?: 'N/A'); ?></td>
                              <td><?php echo esc_html($lead->created_at); ?></td>
                              <td><?php echo esc_html($lead->sent_at ?: 'Pending'); ?></td>
                          </tr>
                      <?php endforeach; ?>
                  <?php endif; ?>
              </tbody>
          </table>

          <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
          <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
      </div>

      <!-- Modal -->
      <div id="json-modal" class="modal">
          <div class="modal-content">
              <span class="close">&times;</span>
              <pre id="json-content"></pre>
          </div>
      </div>

      <style>
          .red {
            background-color: #ffcccc !important;
          }
          .wrap {
              max-width: 100%;
              overflow-x: auto;
          }
          .widefat th {
              background:rgb(135, 217, 255);
              color: white;
              text-align: left;
              padding: 10px;
              border: 1px solid #f1f1f1;
              font-weight: bold;
          }
          .widefat td {
              padding: 10px;
              border: 1px solid #f1f1f1;
          }
          .alternate {
              background: #f9f9f9;
          }
          button.view-json-btn {
              background: none;
              border: none;
              color: #0073aa;
              text-decoration: underline;
              cursor: pointer;
              font-size: 14px;
              display: contents;
          }
          button.view-json-btn:hover {
              color: #005177;
          }
          /* Estilos del modal */
          .modal {
              display: none;
              position: fixed;
              z-index: 1000;
              left: 0;
              top: 0;
              width: 100%;
              height: 100%;
              background-color: rgba(0, 0, 0, 0.5);
          }
          .modal-content {
              background-color: white;
              margin: 10% auto;
              padding: 20px;
              border-radius: 5px;
              width: 50%;
              max-height: 70vh;
              overflow-y: auto;
              position: relative;
          }
          .close {
              position: absolute;
              top: 10px;
              right: 15px;
              font-size: 24px;
              cursor: pointer;
          }
          pre {
              white-space: pre-wrap;
              word-wrap: break-word;
              font-size: 14px;
              background: #f4f4f4;
              padding: 10px;
              border-radius: 5px;
              overflow-x: auto;
          }
          .dataTables_wrapper .dataTables_length select {
            width: 60px;
          }
      </style>

      <script>
          document.addEventListener("DOMContentLoaded", function () {
              const modal = document.getElementById("json-modal");
              const modalContent = document.getElementById("json-content");
              const closeModal = document.querySelector(".close");

              document.querySelectorAll(".view-json-btn").forEach(button => {
                  button.addEventListener("click", function () {
                      const jsonData = this.getAttribute("data-json");
                      try {
                          const formattedJson = JSON.stringify(JSON.parse(jsonData), null, 4);
                          modalContent.textContent = formattedJson;
                      } catch (error) {
                          modalContent.textContent = "Invalid JSON Data";
                      }
                      modal.style.display = "block";
                  });
              });

              closeModal.addEventListener("click", function () {
                  modal.style.display = "none";
              });

              window.addEventListener("click", function (event) {
                  if (event.target === modal) {
                      modal.style.display = "none";
                  }
              });
          });

          jQuery(document).ready(function($) {
            $('#leadsTable').DataTable({
                "paging": true,
                "pageLength": 20,
                "ordering": true,
                "order": [[0, "asc"]],
                "lengthMenu": [20, 40, 60, 100],
                language: {
                  emptyTable: "No leads found."
                }
            });
          });
      </script>

      <?php
  }

  public function create_leadbox_logs_page()
  {
      global $wpdb;
      $table_name = $wpdb->prefix . 'leadbox_logs';

      // Check if database logging is enabled
      $db_logging_enabled = defined('LEADBOX_LOG_TO_DATABASE') && LEADBOX_LOG_TO_DATABASE;

      // Get logs if database logging is enabled
      $logs = array();
      if ($db_logging_enabled && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name) {
          $logs = $wpdb->get_results(
              "SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT 100",
              ARRAY_A
          );
      }

      ?>
      <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
      <div class="wrap">
          <h1 style="font-weight: bold;margin-bottom: 10px;">Leadbox Error Logs</h1>

          <?php if (!$db_logging_enabled): ?>
              <div class="notice notice-info">
                  <p><strong>Database logging is disabled.</strong></p>
                  <p>Errors are currently being logged to the WordPress debug log only.</p>
                  <p>To enable database logging, add this to your <code>wp-config.php</code>:</p>
                  <pre>define('LEADBOX_LOG_TO_DATABASE', true);</pre>
                  <p><strong>Note:</strong> Database logging is opt-in and adds 2-5ms overhead per error. Only enable when debugging specific issues.</p>
              </div>
          <?php elseif (empty($logs)): ?>
              <div class="notice notice-success">
                  <p><strong>No errors logged.</strong></p>
                  <p>Database logging is enabled but no errors have been recorded yet.</p>
              </div>
          <?php else: ?>
              <table id="logsTable" class="widefat fixed display" cellspacing="0" width="100%">
                  <thead>
                      <tr>
                          <th width="15%">Timestamp</th>
                          <th width="10%">Level</th>
                          <th width="35%">Message</th>
                          <th width="15%">Request ID</th>
                          <th width="10%">User ID</th>
                          <th width="15%">Context</th>
                      </tr>
                  </thead>
                  <tbody>
                      <?php foreach ($logs as $index => $log): ?>
                          <tr class="<?php echo ($index % 2 == 0) ? 'alternate' : ''; ?>">
                              <td><?php echo esc_html($log['timestamp']); ?></td>
                              <td>
                                  <span class="log-level log-level-<?php echo esc_attr(strtolower($log['level'])); ?>">
                                      <?php echo esc_html($log['level']); ?>
                                  </span>
                              </td>
                              <td><?php echo esc_html($log['message']); ?></td>
                              <td><code><?php echo esc_html($log['request_id']); ?></code></td>
                              <td><?php echo esc_html($log['user_id'] ?: 'N/A'); ?></td>
                              <td>
                                  <?php if (!empty($log['context'])): ?>
                                      <button class="view-context-btn" data-context="<?php echo esc_attr($log['context']); ?>">
                                          View Context
                                      </button>
                                  <?php else: ?>
                                      <em>None</em>
                                  <?php endif; ?>
                              </td>
                          </tr>
                      <?php endforeach; ?>
                  </tbody>
              </table>
          <?php endif; ?>

          <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
          <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
      </div>

      <!-- Modal for context -->
      <div id="context-modal" class="modal">
          <div class="modal-content">
              <span class="close">&times;</span>
              <h2>Log Context</h2>
              <pre id="context-content"></pre>
          </div>
      </div>

      <style>
          .wrap {
              max-width: 100%;
              overflow-x: auto;
          }
          .widefat th {
              background: rgb(135, 217, 255);
              color: white;
              text-align: left;
              padding: 10px;
              border: 1px solid #f1f1f1;
              font-weight: bold;
          }
          .widefat td {
              padding: 10px;
              border: 1px solid #f1f1f1;
          }
          .alternate {
              background: #f9f9f9;
          }
          .log-level {
              padding: 4px 8px;
              border-radius: 3px;
              font-weight: bold;
              font-size: 12px;
              display: inline-block;
          }
          .log-level-error {
              background: #dc3232;
              color: white;
          }
          .log-level-critical, .log-level-emergency {
              background: #8b0000;
              color: white;
          }
          .log-level-warning {
              background: #ffb900;
              color: black;
          }
          .log-level-info, .log-level-notice {
              background: #00a0d2;
              color: white;
          }
          .log-level-debug {
              background: #888;
              color: white;
          }
          button.view-context-btn {
              background: #0073aa;
              border: none;
              color: white;
              padding: 5px 10px;
              border-radius: 3px;
              cursor: pointer;
              font-size: 12px;
          }
          button.view-context-btn:hover {
              background: #005177;
          }
          .modal {
              display: none;
              position: fixed;
              z-index: 1000;
              left: 0;
              top: 0;
              width: 100%;
              height: 100%;
              background-color: rgba(0, 0, 0, 0.5);
          }
          .modal-content {
              background-color: white;
              margin: 5% auto;
              padding: 20px;
              border: 1px solid #888;
              width: 80%;
              max-width: 800px;
              border-radius: 5px;
              max-height: 80vh;
              overflow-y: auto;
          }
          .close {
              color: #aaa;
              float: right;
              font-size: 28px;
              font-weight: bold;
              cursor: pointer;
          }
          .close:hover {
              color: black;
          }
          #context-content {
              background: #f5f5f5;
              padding: 15px;
              border-radius: 3px;
              overflow-x: auto;
          }
      </style>

      <script>
          document.addEventListener("DOMContentLoaded", function () {
              const modal = document.getElementById("context-modal");
              const modalContent = document.getElementById("context-content");
              const closeModal = document.querySelector(".close");

              document.querySelectorAll(".view-context-btn").forEach(button => {
                  button.addEventListener("click", function () {
                      const contextData = this.getAttribute("data-context");
                      try {
                          const formattedContext = JSON.stringify(JSON.parse(contextData), null, 4);
                          modalContent.textContent = formattedContext;
                      } catch (error) {
                          modalContent.textContent = contextData;
                      }
                      modal.style.display = "block";
                  });
              });

              if (closeModal) {
                  closeModal.addEventListener("click", function () {
                      modal.style.display = "none";
                  });
              }

              window.addEventListener("click", function (event) {
                  if (event.target === modal) {
                      modal.style.display = "none";
                  }
              });
          });

          jQuery(document).ready(function($) {
              if ($('#logsTable').length) {
                  $('#logsTable').DataTable({
                      "paging": true,
                      "pageLength": 25,
                      "ordering": true,
                      "order": [[0, "desc"]],
                      "lengthMenu": [25, 50, 100],
                      language: {
                          emptyTable: "No logs found."
                      }
                  });
              }
          });
      </script>

      <?php
  }


  public function enqueue_scripts($hook)
  {
    if ($hook != 'leadbox-settings_page_leadbox-settings-genius') {
      return;
    }

    $genius_json = '';
    if(hasChild())
      $genius_json = get_stylesheet_directory_uri() . '/config/genius.json';
    else
      $genius_json = get_template_directory_uri() . '/resources/config/genius.json';

    // Modern JSON editor (Monaco, the VS Code engine) loaded from CDN.
    $monaco_vs = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs';

    $js_path = plugin_dir_path(__FILE__) . 'edit-json-plugin.js';
    $js_version = file_exists($js_path) ? filemtime($js_path) : null;

    wp_enqueue_script('monaco-loader', $monaco_vs . '/loader.js', array(), '0.52.2', true);
    // Monaco's AMD loader sets a global define.amd, which makes WordPress UMD
    // libraries (underscore "_", backbone) register as AMD modules instead of
    // creating their globals — breaking the WP media/backbone stack on this page.
    // Stash Monaco's require/define immediately and remove the globals so WP's
    // scripts load normally; edit-json-plugin.js restores them only while it
    // actually loads Monaco.
    wp_add_inline_script(
      'monaco-loader',
      'window.__leadboxMonacoAMD={require:window.require,define:window.define};window.require=undefined;window.define=undefined;',
      'after'
    );
    wp_enqueue_script('edit-json-plugin-script', plugin_dir_url(__FILE__) . 'edit-json-plugin.js', array('jquery', 'monaco-loader'), $js_version, true);
    wp_localize_script('edit-json-plugin-script', 'editJsonPlugin', array(
      'ajax_url'          => admin_url('admin-ajax.php'),
      'json_file_url'     => $genius_json,
      'monaco_vs'         => $monaco_vs,
      'components_action' => 'get_genius_components',
      'nonce'             => wp_create_nonce('leadbox_genius'),
    ));
  }

  public function save_json_file()
  {
    if (!current_user_can('manage_options')) {
      wp_die('You are not allowed to be here.');
    }
    check_ajax_referer('leadbox_genius', 'nonce');

    // Verificar que la acción viene de nuestra página específica
    if (isset($_POST['page']) && $_POST['page'] === 'leadbox-settings-genius') {
      $genius_json = '';
      if(hasChild())
        $genius_json = get_stylesheet_directory() . '/config/genius.json';
      else
        $genius_json = get_template_directory() . '/resources/config/genius.json';

      $json_content = stripslashes($_POST['json_content']);
      $file_path = $genius_json;

      if (file_put_contents($file_path, $json_content)) {
        wp_send_json_success('JSON file saved successfully.');
      } else {
        wp_send_json_error('Error to save JSON file.');
      }
    } else {
      wp_send_json_error('Action not allowed.');
    }
  }

  public function save_json_option()
  {
    if (!current_user_can('manage_options')) {
      wp_die('You are not allowed to be here.');
    }
    check_ajax_referer('leadbox_genius', 'nonce');

    // Verificar que la acción viene de nuestra página específica
    if (isset($_POST['page']) && $_POST['page'] === 'leadbox-settings-genius') {
      if (isset($_POST['json_content'])) {
        $json_content = sanitize_text_field($_POST['json_content']);

        // Obtener la opción actual
        $leadbox_settings = get_option('leadbox-settings', []);

        // Asegurarse de que es un array
        if (!is_array($leadbox_settings)) {
            $leadbox_settings = [];
        }

        // Agregar o actualizar la clave 'genius'
        $leadbox_settings['genius'] = $json_content;

        // Guardar la opción actualizada
        update_option('leadbox-settings', $leadbox_settings);

        // Responder con éxito
        wp_send_json_success();
      } else {
          // Responder con error
          wp_send_json_error();
      }
    } else {
      wp_send_json_error('Action not allowed.');
    }
  }

  /**
   * Resolve the active genius.json path (child theme overrides the parent).
   */
  private function get_genius_config_path()
  {
    if (hasChild()) {
      return get_stylesheet_directory() . '/config/genius.json';
    }
    return get_template_directory() . '/resources/config/genius.json';
  }

  /**
   * Read and decode a genius.json file. Always returns an array.
   */
  private function read_genius_json($path)
  {
    if (!$path || !file_exists($path)) {
      return array();
    }
    $decoded = json_decode(file_get_contents($path), true);
    return is_array($decoded) ? $decoded : array();
  }

  /**
   * Turn a component key into a readable label (kebab-case -> Title Case,
   * keeping known acronyms uppercase).
   */
  private function genius_component_label($key)
  {
    $acronyms = array(
      'vdp' => 'VDP', 'srp' => 'SRP', 'vin' => 'VIN',
      'cta' => 'CTA', 'rv'  => 'RV',  'cl'  => 'CL',
    );
    $parts = explode('-', $key);
    foreach ($parts as &$part) {
      $part = isset($acronyms[$part]) ? $acronyms[$part] : ucfirst($part);
    }
    unset($part);
    return implode(' ', $parts);
  }

  /**
   * Infer a JSON-schema primitive type from a PHP value.
   */
  private function genius_json_type($value)
  {
    if (is_bool($value)) {
      return 'boolean';
    }
    if (is_int($value) || is_float($value)) {
      return 'number';
    }
    if (is_array($value)) {
      if (empty($value)) {
        return 'array';
      }
      return array_keys($value) === range(0, count($value) - 1) ? 'array' : 'object';
    }
    return 'string';
  }

  /**
   * Scan the active theme for versioned Genius components and return both a
   * manifest (used to render the sidebar) and an auto-generated JSON schema
   * (used by the editor for validation + autocomplete).
   *
   * Versions are detected as numbered blade files: resources/views/{base}/{component}/{N}.blade.php
   * where {base} is "cl" (components) or "layouts" (page layouts).
   */
  public function get_genius_components()
  {
    if (!current_user_can('manage_options')) {
      wp_send_json_error('You are not allowed to be here.');
    }
    check_ajax_referer('leadbox_genius', 'nonce');

    $parent_views = get_template_directory() . '/resources/views';
    $child_views  = hasChild() ? get_stylesheet_directory() . '/views' : '';

    $bases = array('cl', 'layouts');

    $active_config = $this->read_genius_json($this->get_genius_config_path());
    $parent_config = $this->read_genius_json(get_template_directory() . '/resources/config/genius.json');

    $components = array();
    $seen = array();

    foreach ($bases as $base) {
      $base_dir = $parent_views . '/' . $base;
      if (!is_dir($base_dir)) {
        continue;
      }
      $dirs = glob($base_dir . '/*', GLOB_ONLYDIR);
      if (!is_array($dirs)) {
        continue;
      }
      foreach ($dirs as $dir) {
        $key = basename($dir);
        if (isset($seen[$key])) {
          continue; // first base wins (cl before layouts)
        }

        // Collect numeric blade versions inside this component folder.
        $versions = array();
        $blades = glob($dir . '/*.blade.php');
        if (is_array($blades)) {
          foreach ($blades as $file) {
            $name = basename($file, '.blade.php');
            if (ctype_digit($name)) {
              $versions[] = (int) $name;
            }
          }
        }
        if (empty($versions)) {
          continue; // not a versioned component (e.g. atomic, build-and-price)
        }
        sort($versions);
        $seen[$key] = true;

        // Current version configured for this dealer.
        $in_json = array_key_exists($key, $active_config);
        $current = null;
        if ($in_json) {
          $current = isset($active_config[$key]['version'])
            ? (int) $active_config[$key]['version']
            : 1;
        }

        // Custom = the child theme overrides this component with its own blades.
        $custom = false;
        if ($child_views) {
          $child_comp = $child_views . '/' . $base . '/' . $key;
          if (is_dir($child_comp)) {
            $child_blades = glob($child_comp . '/*.blade.php');
            $custom = is_array($child_blades) && !empty($child_blades);
          }
        }

        $components[] = array(
          'key'           => $key,
          'label'         => $this->genius_component_label($key),
          'group'         => $base,
          'current'       => $current,
          'available'     => array_values($versions),
          'custom'        => $custom,
          'missingInJson' => !$in_json,
        );
      }
    }

    usort($components, function ($a, $b) {
      return strcmp($a['label'], $b['label']);
    });

    $schema = $this->build_genius_schema($components, array($active_config, $parent_config));

    wp_send_json_success(array(
      'components' => $components,
      'schema'     => $schema,
    ));
  }

  /**
   * Build a JSON schema from the detected components.
   *
   * - version: enum of versions that physically exist on disk (exact).
   * - data:    known keys collected from existing configs (best-effort autocomplete).
   *
   * Unknown top-level keys are allowed on purpose: real configs contain
   * non-versioned keys (e.g. "comparison", "srp-title"), so flagging them
   * would produce false positives.
   */
  private function build_genius_schema($components, $configs)
  {
    $properties = array();

    foreach ($components as $comp) {
      $key = $comp['key'];

      // Collect known data keys across the provided configs (best-effort hints).
      $data_props = array();
      foreach ($configs as $config) {
        if (isset($config[$key]['data']) && is_array($config[$key]['data'])) {
          foreach ($config[$key]['data'] as $dk => $dv) {
            if (!isset($data_props[$dk])) {
              $data_props[$dk] = array('type' => $this->genius_json_type($dv));
            }
          }
        }
      }

      // Build the allowed version list from on-disk versions PLUS any version
      // already referenced in the configs (e.g. legitimately deployed "version": 0),
      // so the schema never flags a value that is actually live.
      $enum_values = $comp['available'];
      foreach ($configs as $config) {
        if (isset($config[$key]['version']) && is_scalar($config[$key]['version'])) {
          $enum_values[] = (int) $config[$key]['version'];
        }
      }
      $enum_values = array_values(array_unique($enum_values));
      sort($enum_values);

      // Accept both numeric and string version values to avoid false errors.
      $enum = array();
      foreach ($enum_values as $v) {
        $enum[] = $v;
        $enum[] = (string) $v;
      }

      $version_schema = array(
        'description' => 'Available versions: ' . implode(', ', $comp['available']),
        'enum'        => $enum,
      );

      $data_schema = array(
        'type'                 => 'object',
        'additionalProperties' => true,
      );
      if (!empty($data_props)) {
        $data_schema['properties'] = $data_props;
      }

      $properties[$key] = array(
        'type'       => 'object',
        'properties' => array(
          'version' => $version_schema,
          'data'    => $data_schema,
        ),
      );
    }

    return array(
      'type'                 => 'object',
      'properties'           => empty($properties) ? new stdClass() : $properties,
      'additionalProperties' => true,
    );
  }

  /**
   * Register and add settings
   */

  public function register_custom_css()
  {
    register_setting(
      'custom-css-options-group',
      'custom-css',
      array($this, 'sanitize')
    );

    add_settings_section(
      'css',
      '',
      array($this, 'print_section_info'),
      'custom-css'
    );

    add_settings_field(
      'custom_css',
      'Custom CSS',
      array($this, 'custom_css_callback'),
      'custom-css',
      'css'
    );
  }

  public function custom_css_callback()
  {
    printf(
      '<textarea id="custom_css" name="custom-css[custom_css]" rows="10" cols="70">%s</textarea>',
      isset($this->custom_css['custom_css']) ? esc_attr($this->custom_css['custom_css']) : ''
    );
  }


  public function register_leadbox_settings()
  {
    register_setting(
      'leadbox-settings-options-group',
      'leadbox-settings',
      array($this, 'sanitize')
    );

    add_settings_section(
      'dealer',
      'Dealer information',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'manufacturer',
      'Manufacturer',
      array($this, 'manufacturer_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'other-brands',
      'Other Brands (For SEO)',
      array($this, 'other_brands_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'all-brands',
      'Other Brands (For Offers, Showroom, Lineup)',
      array($this, 'all_brands_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'oem_models',
      'OEM Models (For Static Pages)',
      array($this, 'oem_models_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'custom_lineup',
      'Line Up',
      array($this, 'lineup_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'megamenu_lineup',
      'Megamenu Line Up',
      array($this, 'megamenu_lineup_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'custom_trimselector',
      'Trim Selector',
      array($this, 'trimselector_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'oem_program',
      'OEM Program',
      array($this, 'oem_program_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'dealer_information',
      'Website Type',
      array($this, 'dealer_information_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_field(
      'model_e_setting',
      'Model E',
      array($this, 'model_e_callback'),
      'leadbox-settings',
      'dealer'
    );

    add_settings_section(
      'api',
      'Backend Connection',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'leads_api_url',
      'Leads API URL',
      array($this, 'leads_api_url_callback'),
      'leadbox-settings',
      'api'
    );

    add_settings_field(
      'leads_api_token',
      'Leads API Token',
      array($this, 'leads_api_token_callback'),
      'leadbox-settings',
      'api'
    );

    add_settings_field(
      'inventory_api_url',
      'Inventory API URL',
      array($this, 'inventory_api_url_callback'),
      'leadbox-settings',
      'api'
    );

    add_settings_field(
      'inventory_api_token',
      'Inventory API Token',
      array($this, 'inventory_api_token_callback'),
      'leadbox-settings',
      'api'
    );

    // LBT-1468 — Leadbox Platform lead-intake routing.
    add_settings_field(
      'lead_intake_target',
      'Lead Intake Target',
      array($this, 'lead_intake_target_callback'),
      'leadbox-settings',
      'api'
    );

    // These two only apply when routing to the Platform; the 'lb-intake-endpoint-row'
    // class lets the target dropdown's inline JS hide them in 'legacy' mode.
    add_settings_field(
      'leadbox_os_lead_intake_url',
      'Leadbox Platform Lead Intake URL',
      array($this, 'leadbox_os_lead_intake_url_callback'),
      'leadbox-settings',
      'api',
      array('class' => 'lb-intake-endpoint-row')
    );

    add_settings_field(
      'leadbox_os_lead_intake_token',
      'Leadbox Platform Lead Intake Token',
      array($this, 'leadbox_os_lead_intake_token_callback'),
      'leadbox-settings',
      'api',
      array('class' => 'lb-intake-endpoint-row')
    );

    add_settings_section(
      'links',
      'Leadbox Links',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'report_url',
      'Report URL',
      array($this, 'report_url_callback'),
      'leadbox-settings',
      'links'
    );

    add_settings_field(
      'credit_url',
      'Credit URL',
      array($this, 'credit_url_callback'),
      'leadbox-settings',
      'links'
    );

    add_settings_field(
      'backend_url',
      'Backend URL',
      array($this, 'backend_url'),
      'leadbox-settings',
      'links'
    );

    add_settings_field(
      'graphql_url',
      'GraphQL URL',
      array($this, 'graphql_url'),
      'leadbox-settings',
      'links'
    );

    add_settings_section(
      'google',
      'Google',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'google_tag_manager_token',
      'Google Tag Manager Token',
      array($this, 'google_tag_manager_token_callback'),
      'leadbox-settings',
      'google'
    );

    add_settings_field(
      'google_analytics_id',
      'Google Analytics ID',
      array($this, 'google_analytics_id_callback'),
      'leadbox-settings',
      'google'
    );

    add_settings_section(
      'adobe',
      'Ford Adobe Tagging',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'ford_adobe_option',
      'Status',
      array($this, 'ford_adobe_tagging_callback'),
      'leadbox-settings',
      'adobe'
    );

    add_settings_field(
      'ford_adobe_version',
      'Environment',
      array($this, 'ford_adobe_version_callback'),
      'leadbox-settings',
      'adobe'
    );

    add_settings_field(
      'ford_dealer_code',
      'Ford Dealer Code',
      array($this, 'ford_dealer_code_callback'),
      'leadbox-settings',
      'adobe'
    );

    add_settings_section(
      'jlr',
      'Shift Digital Tagging',
      array($this, 'print_section_info'),
      'leadbox-settings'
    );

    add_settings_field(
      'jlr_option',
      'Status',
      array($this, 'jlr_option_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_version',
      'Environment',
      array($this, 'jlr_version_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_dealer_code',
      'Client ID',
      array($this, 'jlr_dealer_code_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_retailer_code',
      'Retailer Code',
      array($this, 'jlr_retailer_code_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_provider_code',
      'Provider Code',
      array($this, 'jlr_provider_code_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_dealer_bac',
      'Dealer BAC',
      array($this, 'jlr_dealer_bac_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_field(
      'jlr_pagebrand',
      'Page Brand',
      array($this, 'jlr_pagebrand_callback'),
      'leadbox-settings',
      'jlr'
    );

    add_settings_section(
      'addons',
      'Add Ons',
      array($this, 'print_section_empty'),
      'leadbox-settings'
    );

    add_settings_section(
      'cartender',
      'Cartender',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );

    add_settings_field(
      'cartender_option',
      'Status',
      array($this, 'cartender_option_callback'),
      'leadbox-settings',
      'cartender'
    );
    add_settings_field(
      'cartender_url',
      'Dealer ID',
      array($this, 'cartender_url_callback'),
      'leadbox-settings',
      'cartender'
    );


    add_settings_section(
      'live_agent',
      'Live Person',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );
    add_settings_field(
      'live_agent_option',
      'Status',
      array($this, 'live_agent_option_callback'),
      'leadbox-settings',
      'live_agent'
    );
    add_settings_field(
      'live_agent_code',
      'Code Script',
      array($this, 'live_agent_code_callback'),
      'leadbox-settings',
      'live_agent'
    );

    add_settings_section(
      'moto_insight',
      'Moto Insight',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );
    add_settings_field(
      'moto_insight_option',
      'Status',
      array($this, 'moto_insight_option_callback'),
      'leadbox-settings',
      'moto_insight'
    );
    add_settings_field(
      'moto_insight_url',
      'Script URL',
      array($this, 'moto_insight_url_callback'),
      'leadbox-settings',
      'moto_insight'
    );
    add_settings_field(
      'moto_insight_label',
      'Label',
      array($this, 'moto_insight_label_callback'),
      'leadbox-settings',
      'moto_insight'
    );
    add_settings_field(
      'moto_insight_label_fr',
      'Label Fr',
      array($this, 'moto_insight_label_fr_callback'),
      'leadbox-settings',
      'moto_insight'
    );

    add_settings_section(
      'carfax',
      'Carfax',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );

    add_settings_field(
      'carfax_option',
      'Status',
      array($this, 'carfax_option_callback'),
      'leadbox-settings',
      'carfax'
    );

    add_settings_field(
      'carfax_thirdpartykey',
      'CarFax Third Party Key',
      array($this, 'carfax_thirdpartykey_callback'),
      'leadbox-settings',
      'carfax'
    );

    add_settings_field(
      'carfax_account_number',
      'Account Number',
      array($this, 'carfax_account_number_callback'),
      'leadbox-settings',
      'carfax'
    );

    add_settings_field(
      'carfax_webservicetoken',
      'Webservice Token',
      array($this, 'carfax_webservicetoken_callback'),
      'leadbox-settings',
      'carfax'
    );

    add_settings_section(
      'iboost360',
      'iBoost360',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );

    add_settings_field(
      'iboost_option',
      'Status',
      array($this, 'iboost_option_callback'),
      'leadbox-settings',
      'iboost360'
    );

    add_settings_field(
      'iboost_token',
      'Token',
      array($this, 'iboost_token_callback'),
      'leadbox-settings',
      'iboost360'
    );

    add_settings_section(
      'additional_info',
      'Additional Info',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );

    add_settings_field(
      'additional_info_purpose',
      'Purpose',
      array($this, 'additional_info_option_callback'),
      'leadbox-settings',
      'additional_info'
    );

    add_settings_field(
      'additional_info_live_date',
      'Live Date',
      array($this, 'live_data_option_callback'),
      'leadbox-settings',
      'additional_info'
    );

    add_settings_field(
      'additional_info_billing',
      'Billing ID',
      array($this, 'billing_id_option_callback'),
      'leadbox-settings',
      'additional_info'
    );
    add_settings_field(
      'additional_info_group_name',
      'Group Name',
      array($this, 'group_name_option_callback'),
      'leadbox-settings',
      'additional_info'
    );

    add_settings_section(
      'lbx_datalayer',
      'Leadbox DataLayer',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );
    add_settings_field(
      'enable_lbx_datalayer',
      'Status',
      array($this, 'enable_lbx_datalayer_callback'),
      'leadbox-settings',
      'lbx_datalayer'
    );
    add_settings_field(
      'leadbox_id',
      'Leadbox Account ID',
      array($this, 'leadbox_id_callback'),
      'leadbox-settings',
      'lbx_datalayer'
    );

    add_settings_section(
      'new_finance_lease',
      'New Finance/Lease JSON',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );
    add_settings_field(
      'new_finance_lease_option',
      'Use New Finance/Lease JSON file',
      array($this, 'new_finance_lease_option_callback'),
      'leadbox-settings',
      'new_finance_lease'
    );
    add_settings_section(
      'custom_finance_lease',
      'Custom Used Finance',
      array($this, 'print_section_info'),
      'leadbox-settings',
      'addons'
    );
    add_settings_field(
      'custom_finance_lease_option',
      'Use Custom Finance Setting',
      array($this, 'custom_finance_lease_option_callback'),
      'leadbox-settings',
      'custom_finance_lease'
    );
  }

  public function backend_url()
  {
    printf(
      '<input type="text" id="backend_url" name="leadbox-settings[backend_url]" value="%s" />',
      isset($this->leadbox_settings['backend_url']) ? esc_attr($this->leadbox_settings['backend_url']) : ''

    );
  }

  public function graphql_url()
  {
    printf(
      '<input type="text" id="graphql_url" name="leadbox-settings[graphql_url]" value="%s" />',
      isset($this->leadbox_settings['graphql_url']) ? esc_attr($this->leadbox_settings['graphql_url']) : ''

    );
  }

  public function leads_api_url_callback()
  {
    printf(
      '<input type="text" id="leads_api_url" name="leadbox-settings[leads_api_url]" value="%s" />',
      isset($this->leadbox_settings['leads_api_url']) ? esc_attr($this->leadbox_settings['leads_api_url']) : ''
    );
  }

  public function leads_api_token_callback()
  {
    printf(
      '<input type="text" id="leads_api_token" name="leadbox-settings[leads_api_token]" value="%s" />',
      isset($this->leadbox_settings['leads_api_token']) ? esc_attr($this->leadbox_settings['leads_api_token']) : ''
    );
  }

  public function inventory_api_url_callback()
  {
    printf(
      '<input type="text" id="inventory_api_url" name="leadbox-settings[inventory_api_url]" value="%s" />',
      isset($this->leadbox_settings['inventory_api_url']) ? esc_attr($this->leadbox_settings['inventory_api_url']) : ''
    );
  }

  public function inventory_api_token_callback()
  {
    printf(
      '<input type="text" id="inventory_api_token" name="leadbox-settings[inventory_api_token]" value="%s" />',
      isset($this->leadbox_settings['inventory_api_token']) ? esc_attr($this->leadbox_settings['inventory_api_token']) : ''
    );
  }

  /**
   * LBT-1468 — Where Ninja Forms leads are routed:
   *   legacy     => leadbox-be POST /api/v1/lead (current behavior, default)
   *   leadbox_os => Leadbox Platform POST /api/v1/leads
   *   both       => dual-write; legacy stays authoritative, Leadbox Platform fires non-blocking
   */
  public function lead_intake_target_callback()
  {
    $options = array(
      'legacy'     => 'Legacy backend only (leadbox-be)',
      'leadbox_os' => 'Leadbox Platform only',
      'both'       => 'Both (dual-write — legacy authoritative)',
    );

    $current = isset($this->leadbox_settings['lead_intake_target'])
      ? $this->leadbox_settings['lead_intake_target']
      : 'legacy';
    if (!array_key_exists($current, $options)) {
      $current = 'legacy';
    }

    $forced = class_exists('LB_API_Settings')
      && LB_API_Settings::getInstance()->isLeadIntakeTargetForcedByConstant();

    echo '<select id="lead_intake_target" name="leadbox-settings[lead_intake_target]"' . ($forced ? ' disabled' : '') . '>';
    foreach ($options as $value => $label) {
      printf(
        '<option value="%s"%s>%s</option>',
        esc_attr($value),
        selected($current, $value, false),
        esc_html($label)
      );
    }
    echo '</select>';

    if ($forced) {
      printf(
        '<p class="description" style="color:#b32d2e;">Overridden by the <code>LEADBOX_LEAD_INTAKE_TARGET</code> constant in wp-config.php (currently <code>%s</code>). This setting is ignored while the constant is defined.</p>',
        esc_html(strtolower((string) LEADBOX_LEAD_INTAKE_TARGET))
      );
    } else {
      echo '<p class="description">Routes Ninja Forms lead submissions. Default <code>legacy</code> is byte-for-byte identical to current behavior.</p>';
    }

    // The URL/token fields are only relevant when routing to the Platform.
    // Hide them while 'legacy' is selected, and react as the target changes.
    ?>
    <script>
    (function () {
      var select = document.getElementById('lead_intake_target');
      if (!select) { return; }
      function toggleEndpointRows() {
        var hide = select.value === 'legacy';
        var rows = document.querySelectorAll('tr.lb-intake-endpoint-row');
        for (var i = 0; i < rows.length; i++) {
          rows[i].style.display = hide ? 'none' : '';
        }
      }
      select.addEventListener('change', toggleEndpointRows);
      toggleEndpointRows();
    })();
    </script>
    <?php
  }

  /**
   * LBT-1468 — Base URL of the Leadbox Platform lead-intake endpoint. Optional:
   * blank falls back to the LEADBOX_OS_LEAD_INTAKE_URL default. An invalid value
   * is ignored at resolution (the default is used) and flagged here.
   */
  public function leadbox_os_lead_intake_url_callback()
  {
    $default = class_exists('LB_API_Settings')
      ? LB_API_Settings::LEADBOX_OS_LEAD_INTAKE_URL
      : 'https://os.leadboxhq.com';

    $stored = isset($this->leadbox_settings['leadbox_os_lead_intake_url'])
      ? trim($this->leadbox_settings['leadbox_os_lead_intake_url'])
      : '';

    printf(
      '<input type="text" id="leadbox_os_lead_intake_url" name="leadbox-settings[leadbox_os_lead_intake_url]" value="%s" placeholder="%s" class="regular-text" autocomplete="off" />',
      esc_attr($stored),
      esc_attr($default)
    );

    // An invalid override resolves to '' here, signalling the default is in use.
    $invalid = $stored !== '' && class_exists('LB_API_Settings')
      && LB_API_Settings::sanitizeLeadIntakeUrl($stored, '') === '';

    if ($invalid) {
      printf(
        '<p class="description" style="color:#b32d2e;">Not a valid URL — ignored. Using the default <code>%s</code>. The client appends <code>/api/v1/leads</code>.</p>',
        esc_html($default)
      );
    } else {
      printf(
        '<p class="description">Leave blank to use the default <code>%s</code>. The client appends <code>/api/v1/leads</code>.</p>',
        esc_html($default)
      );
    }
  }

  public function leadbox_os_lead_intake_token_callback()
  {
    printf(
      '<input type="text" id="leadbox_os_lead_intake_token" name="leadbox-settings[leadbox_os_lead_intake_token]" value="%s" placeholder="wl_key_..." autocomplete="off" />',
      isset($this->leadbox_settings['leadbox_os_lead_intake_token']) ? esc_attr($this->leadbox_settings['leadbox_os_lead_intake_token']) : ''
    );
    echo '<p class="description">Website lead-intake Bearer token (<code>wl_key_…</code>) issued by Leadbox Platform for this location.</p>';
  }

  public function report_url_callback()
  {
    printf(
      '<input type="text" id="report_url" name="leadbox-settings[report_url]" value="%s" />',
      isset($this->leadbox_settings['report_url']) ? esc_attr($this->leadbox_settings['report_url']) : ''
    );
  }

  public function credit_url_callback()
  {
    printf(
      '<input type="text" id="credit_url" name="leadbox-settings[credit_url]" value="%s" />',
      isset($this->leadbox_settings['credit_url']) ? esc_attr($this->leadbox_settings['credit_url']) : ''
    );
  }


  public function google_analytics_id_callback()
  {
    printf(
      '<input type="text" id="google_analytics_id" name="leadbox-settings[google_analytics_id]" value="%s" />',
      isset($this->leadbox_settings['google_analytics_id']) ? esc_attr($this->leadbox_settings['google_analytics_id']) : ''
    );
  }

  public function google_tag_manager_token_callback()
  {
    printf(
      '<input type="text" id="google_tag_manager_token" name="leadbox-settings[google_tag_manager_token]" value="%s" />',
      isset($this->leadbox_settings['google_tag_manager_token']) ? esc_attr($this->leadbox_settings['google_tag_manager_token']) : ''
    );
  }

  public function ford_adobe_tagging_callback()
  {
    if (!isset($this->leadbox_settings['ford_adobe_option'])) {
      $this->leadbox_settings['ford_adobe_option'] = "Disabled";
    }

    echo '<select id="ford_adobe_option" name="leadbox-settings[ford_adobe_option]">';
    if (strtolower($this->leadbox_settings['ford_adobe_option']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['ford_adobe_option']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function jlr_option_callback()
  {
    if (!isset($this->leadbox_settings['jlr_option'])) {
      $this->leadbox_settings['jlr_option'] = "Disabled";
    }

    echo '<select id="jlr_option" name="leadbox-settings[jlr_option]">';
    if (strtolower($this->leadbox_settings['jlr_option']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['jlr_option']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function ford_vehicle_count_callback()
  {
    if (!isset($this->branding_options['vehicle_count_option'])) {
      $this->branding_options['vehicle_count_option'] = "Disabled";
    }

    echo '<select id="vehicle_count_option" name="dealer-settings-branding-options[vehicle_count_option]">';
    if (strtolower($this->branding_options['vehicle_count_option']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->branding_options['vehicle_count_option']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function newsletter_enabled_callback()
  {
    if (!isset($this->branding_options['newsletter_enabled_option'])) {
      $this->branding_options['newsletter_enabled_option'] = "Enabled";
    }
    echo '<select id="newsletter_setting_enabled_option" name="dealer-settings-branding-options[newsletter_enabled_option]">';
    if (strtolower($this->branding_options['newsletter_enabled_option']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->branding_options['newsletter_enabled_option']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }




  public function ford_adobe_version_callback()
  {
    if (!isset($this->leadbox_settings['ford_adobe_version'])) {
      $this->leadbox_settings['ford_adobe_version'] = "Staging";
    }

    echo '<select id="ford_adobe_version" name="leadbox-settings[ford_adobe_version]">';
    if (strtolower($this->leadbox_settings['ford_adobe_version']) == 'staging') {
      echo '<option selected value="Staging">Staging</option>';
      echo '<option value="Production">Production</option>';
    } else if (strtolower($this->leadbox_settings['ford_adobe_version']) == 'production') {
      echo '<option value="Staging">Staging</option>';
      echo '<option selected value="Production">Production</option>';
    } else {
      echo '<option value="Staging">Staging</option>';
      echo '<option value="Production">Production</option>';
    }

    echo '</select>';
  }

  public function jlr_version_callback()
  {
    if (!isset($this->leadbox_settings['jlr_version'])) {
      $this->leadbox_settings['jlr_version'] = "Staging";
    }

    echo '<select id="jlr_version" name="leadbox-settings[jlr_version]">';
    if (strtolower($this->leadbox_settings['jlr_version']) == 'staging') {
      echo '<option selected value="Staging">Staging</option>';
      echo '<option value="Production">Production</option>';
    } else if (strtolower($this->leadbox_settings['jlr_version']) == 'production') {
      echo '<option value="Staging">Staging</option>';
      echo '<option selected value="Production">Production</option>';
    } else {
      echo '<option value="Staging">Staging</option>';
      echo '<option value="Production">Production</option>';
    }

    echo '</select>';
  }

  public function ford_dealer_code_callback()
  {
    printf(
      '<input type="text" id="ford_dealer_code" name="leadbox-settings[ford_dealer_code]" value="%s" />',
      isset($this->leadbox_settings['ford_dealer_code']) ? esc_attr($this->leadbox_settings['ford_dealer_code']) : ''
    );
  }

  public function jlr_dealer_code_callback()
  {
    printf(
      '<input type="text" id="jlr_dealer_code" name="leadbox-settings[jlr_dealer_code]" value="%s" />',
      isset($this->leadbox_settings['jlr_dealer_code']) ? esc_attr($this->leadbox_settings['jlr_dealer_code']) : ''
    );
  }

  public function jlr_retailer_code_callback()
  {
    printf(
      '<input type="text" id="jlr_retailer_code" name="leadbox-settings[jlr_retailer_code]" value="%s" />',
      isset($this->leadbox_settings['jlr_retailer_code']) ? esc_attr($this->leadbox_settings['jlr_retailer_code']) : ''
    );
  }

  public function jlr_provider_code_callback()
  {
    printf(
      '<input type="text" id="jlr_provider_code" name="leadbox-settings[jlr_provider_code]" value="%s" />',
      isset($this->leadbox_settings['jlr_provider_code']) && !empty($this->leadbox_settings['jlr_provider_code']) ? esc_attr($this->leadbox_settings['jlr_provider_code']) : 'LEADBOX'
    );
  }

  public function jlr_pagebrand_callback()
  {
    printf(
      '<input type="text" id="jlr_pagebrand" name="leadbox-settings[jlr_pagebrand]" value="%s" />',
      isset($this->leadbox_settings['jlr_pagebrand']) ? esc_attr($this->leadbox_settings['jlr_pagebrand']) : ''
    );
  }

  public function jlr_dealer_bac_callback()
  {
    printf(
      '<input type="text" id="jlr_dealer_bac" name="leadbox-settings[jlr_dealer_bac]" value="%s" />',
      isset($this->leadbox_settings['jlr_dealer_bac']) ? esc_attr($this->leadbox_settings['jlr_dealer_bac']) : ''
    );
  }

  public function carfax_option_callback()
  {
    if (!isset($this->leadbox_settings['carfax'])) {
      $this->leadbox_settings['carfax'] = "Disabled";
    }

    echo '<select id="carfax" name="leadbox-settings[carfax]">';
    if (strtolower($this->leadbox_settings['carfax']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['carfax']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function carfax_thirdpartykey_callback()
  {
    printf(
      '<input type="text" id="carfax_thirdpartykey" name="leadbox-settings[carfax_thirdpartykey]" value="%s" />',
      isset($this->leadbox_settings['carfax_thirdpartykey']) ? esc_attr($this->leadbox_settings['carfax_thirdpartykey']) : ''
    );
  }

  public function carfax_account_number_callback()
  {
    printf(
      '<input type="text" id="carfax_account_number" name="leadbox-settings[carfax_account_number]" value="%s" />',
      isset($this->leadbox_settings['carfax_account_number']) ? esc_attr($this->leadbox_settings['carfax_account_number']) : ''
    );
  }

  public function carfax_webservicetoken_callback()
  {
    printf(
      '<input type="text" id="carfax_webservicetoken" name="leadbox-settings[carfax_webservicetoken]" value="%s" />',
      isset($this->leadbox_settings['carfax_webservicetoken']) ? esc_attr($this->leadbox_settings['carfax_webservicetoken']) : ''
    );
  }

  public function finance_rate_callback()
  {
    printf(
      '<input type="text" id="finance_rate" name="dealer-settings-branding-options[finance_rate]" value="%s" />',
      isset($this->branding_options['finance_rate']) ? esc_attr($this->branding_options['finance_rate']) : ''
    );
  }

  public function finance_term_callback()
  {
    printf(
      '<input type="number" id="finance_term" name="dealer-settings-branding-options[finance_term]" value="%s"/>',
      isset($this->branding_options['finance_term']) ? esc_attr($this->branding_options['finance_term']) : ''
    );
  }

  public function finance_downpayment_callback()
  {
    printf(
      '<input type="number" step="0.01" id="finance_downpayment" name="dealer-settings-branding-options[finance_downpayment]" value="%s"/>',
      isset($this->branding_options['finance_downpayment']) ? esc_attr($this->branding_options['finance_downpayment']) : ''
    );
  }


  public function lease_term_callback()
  {
    printf(
      '<input type="number" id="lease_term" name="dealer-settings-branding-options[lease_term]" value="%s" />',
      isset($this->branding_options['lease_term']) ? esc_attr($this->branding_options['lease_term']) : ''
    );
  }

  public function lease_rate_callback()
  {
    printf(
      '<input type="text" id="lease_rate" name="dealer-settings-branding-options[lease_rate]" value="%s" />',
      isset($this->branding_options['lease_rate']) ? esc_attr($this->branding_options['lease_rate']) : ''
    );
  }
  public function lease_downpayment_callback()
  {
    printf(
      '<input type="number" step="0.01" id="lease_downpayment" name="dealer-settings-branding-options[lease_downpayment]" value="%s" />',
      isset($this->branding_options['lease_downpayment']) ? esc_attr($this->branding_options['lease_downpayment']) : ''
    );
  }

  public function lease_residual_callback()
  {
    printf(
      '<input type="number" step="0.01" id="lease_residual" name="dealer-settings-branding-options[lease_residual]" value="%s" />',
      isset($this->branding_options['lease_residual']) ? esc_attr($this->branding_options['lease_residual']) : ''
    );
  }

  public function manufacturer_callback()
  {
    printf(
      '<input type="text" id="manufacturer" name="leadbox-settings[manufacturer]" value="%s"/>',
      isset($this->leadbox_settings['manufacturer']) ? esc_attr($this->leadbox_settings['manufacturer']) : ''
    );
  }

  public function other_brands_callback()
  {
    printf(
      '<input type="text" id="other_brands" name="leadbox-settings[other_brands]" value="%s"/>',
      isset($this->leadbox_settings['other_brands']) ? esc_attr($this->leadbox_settings['other_brands']) : ''
    );
  }

  public function oem_models_callback()
  {
    printf(
      '<input type="text" id="oem_models" name="leadbox-settings[oem_models]" value="%s"/>',
      isset($this->leadbox_settings['oem_models']) ? esc_attr($this->leadbox_settings['oem_models']) : ''
    );
  }

  public function all_brands_callback()
  {
    printf(
      '<input type="text" id="all_brands" name="leadbox-settings[all_brands]" value="%s"/>',
      isset($this->leadbox_settings['all_brands']) ? esc_attr($this->leadbox_settings['all_brands']) : ''
    );
  }

  public function lineup_callback()
  {
    if (!isset($this->leadbox_settings['lineup'])) {
      $this->leadbox_settings['lineup'] = "Default";
    }

    echo '<select id="lineup" name="leadbox-settings[lineup]">';
    if (strtolower($this->leadbox_settings['lineup']) == 'default') {
      echo '<option selected value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    } else if (strtolower($this->leadbox_settings['lineup']) == 'custom') {
      echo '<option value="Default">Default</option>';
      echo '<option selected value="Custom">Custom</option>';
    } else {
      echo '<option value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    }

    echo '</select>';
  }

  public function megamenu_lineup_callback()
  {
    if (!isset($this->leadbox_settings['megamenu_lineup'])) {
      $this->leadbox_settings['megamenu_lineup'] = "disabled";
    }

    echo '<select id="megamenu_lineup" name="leadbox-settings[megamenu_lineup]">';
    if (strtolower($this->leadbox_settings['megamenu_lineup']) == 'disabled') {
      echo '<option selected value="disabled">Disabled</option>';
      echo '<option value="enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['megamenu_lineup']) == 'enabled') {
      echo '<option value="disabled">Disabled</option>';
      echo '<option selected value="enabled">Enabled</option>';
    } else {
      echo '<option value="disabled">Disabled</option>';
      echo '<option value="enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function trimselector_callback()
  {
    if (!isset($this->leadbox_settings['trimselector'])) {
      $this->leadbox_settings['trimselector'] = "Default";
    }

    echo '<select id="trimselector" name="leadbox-settings[trimselector]">';
    if (strtolower($this->leadbox_settings['trimselector']) == 'default') {
      echo '<option selected value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    } else if (strtolower($this->leadbox_settings['trimselector']) == 'custom') {
      echo '<option value="Default">Default</option>';
      echo '<option selected value="Custom">Custom</option>';
    } else {
      echo '<option value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    }

    echo '</select>';
  }

   public function model_e_callback()
  {
    if (!isset($this->leadbox_settings['model_e_setting'])) {
      $this->leadbox_settings['model_e_setting'] = "Disabled";
    }

    echo '<select id="model_e_setting" name="leadbox-settings[model_e_setting]">';
    if (strtolower($this->leadbox_settings['model_e_setting']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['model_e_setting']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function dealer_information_callback()
  {
    if (!isset($this->leadbox_settings['dealer_information'])) {
      $this->leadbox_settings['dealer_information'] = "Auto";
    }

    echo '<select id="dealer_information" name="leadbox-settings[dealer_information]">';
    if (strtolower($this->leadbox_settings['dealer_information']) == 'auto') {
      echo '<option selected value="Auto">Auto</option>';
      echo '<option value="RV">RV</option>';
      echo '<option value="Mixed">Mixed</option>';
    } else if (strtolower($this->leadbox_settings['dealer_information']) == 'rv') {
      echo '<option value="Auto">Auto</option>';
      echo '<option selected value="RV">RV</option>';
      echo '<option value="Mixed">Mixed</option>';
    } else if (strtolower($this->leadbox_settings['dealer_information']) == 'mixed') {
      echo '<option value="Auto">Auto</option>';
      echo '<option value="RV">RV</option>';
      echo '<option selected value="Mixed">Mixed</option>';
    } else {
      echo '<option value="Auto">Auto</option>';
      echo '<option value="RV">RV</option>';
      echo '<option value="Mixed">Mixed</option>';
    }

    echo '</select>';
  }
  public function oem_program_callback()
  {
    $oem_options = '';
    foreach ($this->oem_program_options as $oem_program) {
      $oem_options .= '<option '. (isset($this->leadbox_settings['oem_program']) && strtolower(str_replace(' ', '', $this->leadbox_settings['oem_program'])) == strtolower(str_replace(' ', '', $oem_program)) ? ' selected '  : '').' value="' . $oem_program . '">' . $oem_program . '</option>';
    }

    printf(
      '<select id="oem_program" name="leadbox-settings[oem_program]">
        %s
        </select>',
      $oem_options
    );
  }

  public function finance_frequency_callback()
  {
    if (!isset($this->branding_options['finance_frequency'])) {
      $this->branding_options['finance_frequency'] = "Weekly";
    }

    echo '<select id="finance_frequency" name="dealer-settings-branding-options[finance_frequency] ">';
    if (strtolower($this->branding_options['finance_frequency']) == 'bi-weekly') {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option selected value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['finance_frequency']) == 'weekly') {
      echo '<option selected value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['finance_frequency']) == 'monthly') {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option selected value="Monthly">Monthly</option>';
    } else {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    }

    echo '</select>';
  }

  public function lease_frequency_callback()
  {
    if (!isset($this->branding_options['lease_frequency'])) {
      $this->branding_options['lease_frequency'] = "Bi-Weekly";
    }

    echo '<select id="lease_frequency" name="dealer-settings-branding-options[lease_frequency] ">';
    if (strtolower($this->branding_options['lease_frequency']) == 'bi-weekly') {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option selected value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['lease_frequency']) == 'weekly') {
      echo '<option selected value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['lease_frequency']) == 'monthly') {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option selected value="Monthly">Monthly</option>';
    } else {
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    }

    echo '</select>';
  }

  /**
   * Add options page
   */
  public function add_dealer_menu()
  {
    global $_wp_last_object_menu;

    $_wp_last_object_menu++;

    add_menu_page(
      __('Dealer Settings', 'dealer-settings'),
      __('Dealer Settings', 'dealer-settings'),
      'manage_options',
      'dealer-settings',
      array($this, 'create_dealer_settings_page'),
      'dashicons-performance',
      $_wp_last_object_menu
    );

    add_submenu_page(
      'dealer-settings',
      __('Hours', 'dealer-settings'),
      __('Hours', 'dealer-settings'),
      'manage_options',
      'dealer-settings-hours',
      array($this, 'create_hours_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('Labels', 'dealer-settings'),
      __('Labels', 'dealer-settings'),
      'manage_options',
      'dealer-settings-labels',
      array($this, 'create_labels_page'),
    );

    add_settings_section(
      'languages',
      '',
      array($this, 'print_section_languages'),
      'dealer-settings-languages'
    );

    add_settings_section(
      'labels',
      '',
      array($this, 'print_section_info'),
      'dealer-settings-labels'
    );

    add_settings_section(
      'my_garage',
      'My Garage',
      array($this, 'print_section_info'),
      'dealer-settings-my-garage'
    );

    add_settings_field(
      'img_vehicle_pricing_one',
      '',
      array($this, 'img_vehicle_pricing_one'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'calculated_msrp_callback',
      'Calculated MSRP',
      array($this, 'calculated_msrp_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'calculated_msrp_callback_fr',
      '',
      array($this, 'calculated_msrp_callback_fr'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'new_vehicle_price_label_callback',
      'New Vehicle Price',
      array($this, 'new_vehicle_price_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'new_vehicle_price_label_callback_fr',
      '',
      array($this, 'new_vehicle_price_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_vehicle_price_label_callback',
      'Used Vehicle Price',
      array($this, 'used_vehicle_price_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_vehicle_price_label_fr_callback',
      '',
      array($this, 'used_vehicle_price_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'after_discount_price_callback',
      'New After Discount Price',
      array($this, 'after_discount_price_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'after_discount_price_fr_callback',
      '',
      array($this, 'after_discount_price_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_after_discount_price_callback',
      'Used After Discount Price',
      array($this, 'used_after_discount_price_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_after_discount_price_fr_callback',
      '',
      array($this, 'used_after_discount_price_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'special_discount_price_callback',
      'Special Discount',
      array($this, 'special_discount_price_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'special_discount_price_fr_callback',
      '',
      array($this, 'special_discount_price_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'special_price_callback',
      'Special Price',
      array($this, 'special_price_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'special_price_fr_callback',
      '',
      array($this, 'special_price_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'rebates_label_callback',
      'Rebates',
      array($this, 'rebates_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'rebates_label_fr_callback',
      '',
      array($this, 'rebates_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'additional_rebates_label_callback',
      'Additional Rebates',
      array($this, 'additional_rebates_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'additional_rebates_label_fr_callback',
      '',
      array($this, 'additional_rebates_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'tax_and_lic_label_callback',
      'New Tax & Lic',
      array($this, 'tax_and_lic_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'tax_and_lic_label_fr_callback',
      '',
      array($this, 'tax_and_lic_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_tax_and_lic_label_callback',
      'Used Tax & Lic',
      array($this, 'used_tax_and_lic_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_tax_and_lic_label_fr_callback',
      '',
      array($this, 'used_tax_and_lic_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    //aqui toy
    add_settings_field(
      'new_tax_label_callback',
      'New Tax',
      array($this, 'new_tax_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'new_tax_label_fr_callback',
      '',
      array($this, 'new_tax_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_tax_label_callback',
      'Used Tax',
      array($this, 'used_tax_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_tax_label_fr_callback',
      '',
      array($this, 'used_tax_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    /* lic */

    add_settings_field(
      'new_lic_label_callback',
      'New Lic.',
      array($this, 'new_lic_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'new_lic_label_fr_callback',
      '',
      array($this, 'new_lic_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_lic_label_callback',
      'Used Lic.',
      array($this, 'used_lic_label_callback'),
      'dealer-settings-labels',
      'labels'
    );

    add_settings_field(
      'used_lic_label_fr_callback',
      '',
      array($this, 'used_lic_label_fr_callback'),
      'dealer-settings-labels',
      'labels'
    );


    /* TAG LABELS */

    add_settings_section(
      'tag-labels',
      'Tag Labels',
      array($this, 'print_section_info'),
      'dealer-settings-tag-labels'
    );

    add_settings_field(
      'img_vehicle_pricing_three',
      '',
      array($this, 'img_vehicle_pricing_three'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* Demo Tag

    add_settings_field(
      'demo_tag_label_callback',
      'Demo',
      array($this, 'demo_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'demo_tag_label_fr_callback',
      '',
      array($this, 'demo_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'demo_tag_label_color_callback',
      'Custom Demo Tag',
      array($this, 'demo_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'demo_tag_label_limit_callback',
      '',
      array($this, 'demo_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* salepending Tag

    add_settings_field(
      'salepending_tag_label_callback',
      'Sale Pending',
      array($this, 'salepending_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'salepending_tag_label_fr_callback',
      '',
      array($this, 'salepending_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		add_settings_field(
      'salepending_tag_label_color_callback',
      'Custom salepending Tag',
      array($this, 'salepending_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'salepending_tag_label_limit_callback',
      '',
      array($this, 'salepending_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* certified Tag

    add_settings_field(
      'certified_tag_label_callback',
      'Certified',
      array($this, 'certified_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'certified_tag_label_fr_callback',
      '',
      array($this, 'certified_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		add_settings_field(
      'certified_tag_label_color_callback',
      'Custom certified Tag',
      array($this, 'certified_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'certified_tag_label_limit_callback',
      '',
      array($this, 'certified_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* Special Tag

    add_settings_field(
      'special_tag_label_callback',
      'Special',
      array($this, 'special_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'special_tag_label_fr_callback',
      '',
      array($this, 'special_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		add_settings_field(
      'special_tag_label_color_callback',
      'Custom special Tag',
      array($this, 'special_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'special_tag_label_limit_callback',
      '',
      array($this, 'special_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* Incoming Tag

    add_settings_field(
      'incoming_tag_label_callback',
      'Incoming',
      array($this, 'incoming_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'incoming_tag_label_fr_callback',
      '',
      array($this, 'incoming_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
		add_settings_field(
      'incoming_tag_label_color_callback',
      'Custom incoming Tag',
      array($this, 'incoming_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'incoming_tag_label_limit_callback',
      '',
      array($this, 'incoming_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		//* As is Tag

    add_settings_field(
      'asis_tag_label_callback',
      'As is',
      array($this, 'asis_tag_label_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    add_settings_field(
      'asis_tag_label_fr_callback',
      '',
      array($this, 'asis_tag_label_fr_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

		add_settings_field(
      'asis_tag_label_color_callback',
      'Custom As is Tag',
      array($this, 'asis_tag_label_color_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );
    add_settings_field(
      'asis_tag_label_limit_callback',
      '',
      array($this, 'asis_tag_label_limit_callback'),
      'dealer-settings-tag-labels',
      'tag-labels'
    );

    /* ------------------------------------- */

    add_settings_section(
      'phones',
      'Phones',
      array($this, 'print_section_info'),
      'dealer-settings-phones'
    );

    add_settings_field(
      'img_vehicle_pricing_two',
      '',
      array($this, 'img_vehicle_pricing_two'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_sales_label_callback',
      'Phone Sales',
      array($this, 'phone_sales_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_sales_label_fr_callback',
      '',
      array($this, 'phone_sales_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_parts_label_callback',
      'Phone Parts',
      array($this, 'phone_parts_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_parts_label_fr_callback',
      '',
      array($this, 'phone_parts_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_service_label_callback',
      'Phone Service',
      array($this, 'phone_service_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_service_label_fr_callback',
      '',
      array($this, 'phone_service_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_fax_label_callback',
      'Phone Fax',
      array($this, 'phone_fax_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_fax_label_fr_callback',
      '',
      array($this, 'phone_fax_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_body_shop_label_callback',
      'Phone Body Shop',
      array($this, 'phone_body_shop_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_body_shop_label_fr_callback',
      '',
      array($this, 'phone_body_shop_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_collision_label_callback',
      'Phone Collision',
      array($this, 'phone_collision_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_collision_label_fr_callback',
      '',
      array($this, 'phone_collision_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_accessories_label_callback',
      'Phone Accessories',
      array($this, 'phone_accessories_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_accessories_label_fr_callback',
      '',
      array($this, 'phone_accessories_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_sms_label_callback',
      'Phone SMS',
      array($this, 'phone_sms_label_callback'),
      'dealer-settings-phones',
      'phones'
    );

    add_settings_field(
      'phone_sms_label_fr_callback',
      '',
      array($this, 'phone_sms_label_fr_callback'),
      'dealer-settings-phones',
      'phones'
    );


    add_settings_field(
      'my_garage_option_callback',
      'Status',
      array($this, 'my_garage_option_callback'),
      'dealer-settings-my-garage',
      'my_garage'
    );

    add_submenu_page(
      'dealer-settings',
      __('Contact', 'dealer-settings'),
      __('Contact', 'dealer-settings'),
      'manage_options',
      'dealer-settings-contact',
      array($this, 'create_contact_page'),
    );
    add_submenu_page(
      'dealer-settings',
      __('Used Finance', 'dealer-settings'),
      __('Used Finance', 'dealer-settings'),
      'manage_options',
      'dealer-settings-used_finance_custom',
      array($this, 'create_used_finance_custom_page'),
    );

    // LBT-1462: "LBX Listing Images" was moved out of the Dealer Settings submenu
    // into its own top-level menu — see add_listing_images_menu() (hooked at
    // admin_menu priority 11 so it lands after Dealer Settings and Leadbox Settings).

    add_submenu_page(
      'dealer-settings',
      __('Social Media', 'dealer-settings'),
      __('Social Media', 'dealer-settings'),
      'manage_options',
      'dealer-settings-socialmedia',
      array($this, 'create_socialmedia_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('Disclaimer', 'dealer-settings'),
      __('Disclaimer', 'dealer-settings'),
      'manage_options',
      'dealer-settings-disclaimer',
      array($this, 'create_disclaimer_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('Filter', 'dealer-settings'),
      __('Filter', 'dealer-settings'),
      'manage_options',
      'dealer-settings-filter',
      array($this, 'create_filter_page'),
    );


    add_submenu_page(
      'dealer-settings',
      __('Policies', 'dealer-settings'),
      __('Policies', 'dealer-settings'),
      'manage_options',
      'dealer-settings-policies',
      array($this, 'create_policies_page'),
    );

    add_submenu_page(
      'dealer-settings',
      'Backend login',
      'Backend login',
      'manage_options',
      'Backend login',
      array($this, 'goTobackend'),
    );

    add_submenu_page(
      'dealer-settings',
      __('Website Info', 'dealer-settings'),
      __('Website Info', 'dealer-settings'),
      'manage_options',
      'dealer-settings-web-info',
      array($this, 'create_web_info_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('Showroom', 'dealer-settings'),
      __('Showroom', 'dealer-settings'),
      'manage_options',
      'dealer-settings-showroom',
      array($this, 'create_showroom_config_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('My Garage', 'dealer-settings'),
      __('My Garage', 'dealer-settings'),
      'manage_options',
      'dealer-settings-my-garage',
      array($this, 'create_my_garage_page'),
    );

    add_submenu_page(
      'dealer-settings',
      __('VDP Payment Settings', 'dealer-settings'),
      __('VDP Payment Settings', 'dealer-settings'),
      'manage_options',
      'dealer-settings-vdp-payment',
      array($this, 'create_vdp_payment_page'),
    );




  }

  public function goTobackend()
  {
    $options = get_option('leadbox-settings');
    $url = isset($options['backend_url']) ? esc_attr($options['backend_url']) : '';
    if (filter_var($url, FILTER_VALIDATE_URL)) {
      // wp_redirect($url);
      echo '<script> window.open("' . $url . '","_blank") </script>';
    }
  }

  /**
   * Sanitize each setting field as needed
   *
   * @param array $input Contains all settings fields as array keys
   */
  public function sanitize($input)
  {

    // $new_input = array();
    // if( isset( $input['id_number'] ) )
    //   $new_input['id_number'] = absint($input['id_number']);

    // if( isset( $input['title'] ) )
    //   $new_input['title'] = sanitize_text_field($input['title']);

    return $input;
  }





  public function additional_info_option_callback()
  {
    if (!isset($this->leadbox_settings['additional_info_purpose'])) {
      $this->leadbox_settings['additional_info_purpose'] = "customer";
    }

    echo '<select id="additional_info_purpose" name="leadbox-settings[additional_info_purpose]">';
    if (strtolower($this->leadbox_settings['additional_info_purpose']) == 'internal') {
      echo '<option value="Customer">Customer</option>';
      echo '<option selected value="Internal">Internal</option>';
    } else if (strtolower($this->leadbox_settings['additional_info_purpose']) == 'customer') {
      echo '<option value="Customer">Customer</option>';
      echo '<option value="Internal">Internal</option>';
    } else {
      echo '<option value="Customer">Customer</option>';
      echo '<option value="Internal">Internal</option>';
    }

    echo '</select>';
  }

  public function new_finance_lease_option_callback()
  {
    if (!isset($this->leadbox_settings['new_finance_lease_option'])) {
      $this->leadbox_settings['new_finance_lease_option'] = "disabled";
    }
    echo '<select id="new_finance_lease_option" name="leadbox-settings[new_finance_lease_option]">';
    if (strtolower($this->leadbox_settings['new_finance_lease_option']) == 'disabled') {
      echo '<option value="enabled">Enabled</option>';
      echo '<option selected value="disabled">Disabled</option>';
    } else if (strtolower($this->leadbox_settings['new_finance_lease_option']) == 'enabled') {
      echo '<option selected value="enabled">Enabled</option>';
      echo '<option value="disabled">Disabled</option>';
    } else {
      echo '<option value="enabled">Enabled</option>';
      echo '<option selected value="disabled">Disabled</option>';
    }
    echo '</select>';
  }
  public function custom_finance_lease_option_callback()
  {
    if (!isset($this->leadbox_settings['custom_finance_lease_option'])) {
      $this->leadbox_settings['custom_finance_lease_option'] = "disabled";
    }
    echo '<select id="custom_finance_lease_option" name="leadbox-settings[custom_finance_lease_option]">';
    if (strtolower($this->leadbox_settings['custom_finance_lease_option']) == 'disabled') {
      echo '<option value="enabled">Enabled</option>';
      echo '<option selected value="disabled">Disabled</option>';
    } else if (strtolower($this->leadbox_settings['custom_finance_lease_option']) == 'enabled') {
      echo '<option selected value="enabled">Enabled</option>';
      echo '<option value="disabled">Disabled</option>';
    } else {
      echo '<option value="enabled">Enabled</option>';
      echo '<option selected value="disabled">Disabled</option>';
    }
    echo '</select>';
  }

  public function cartender_option_callback()
  {
    if (!isset($this->leadbox_settings['cartender'])) {
      $this->leadbox_settings['cartender'] = "Disabled";
    }

    echo '<select id="cartender" name="leadbox-settings[cartender]">';
    if (strtolower($this->leadbox_settings['cartender']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['cartender']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function cartender_url_callback()
  {
    printf(
      '<input type="text" id="cartender_url" name="leadbox-settings[cartender_url]" value="%s" />',
      isset($this->leadbox_settings['cartender_url']) ? esc_attr($this->leadbox_settings['cartender_url']) : ''
    );
  }
  public function cartender_label_callback()
  {
    printf(
      '<input type="text" id="cartender_label" name="leadbox-settings[cartender_label]" value="%s" />',
      isset($this->leadbox_settings['cartender_label']) ? esc_attr($this->leadbox_settings['cartender_label']) : ''
    );
  }
  public function cartender_label_fr_callback()
  {
    printf(
      '<input type="text" id="cartender_label_fr" name="leadbox-settings[cartender_label_fr]" value="%s" />',
      isset($this->leadbox_settings['cartender_label_fr']) ? esc_attr($this->leadbox_settings['cartender_label_fr']) : ''
    );
  }

  public function live_agent_option_callback()
  {
    if (!isset($this->leadbox_settings['live_agent'])) {
      $this->leadbox_settings['live_agent'] = "Disabled";
    }

    echo '<select id="live_agent" name="leadbox-settings[live_agent]">';
    if (strtolower($this->leadbox_settings['live_agent']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['live_agent']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }



  public function live_agent_code_callback()
  {
    printf(
      '<input type="text" id="live_agent_code" name="leadbox-settings[live_agent_code]" value="%s" />',
      isset($this->leadbox_settings['live_agent_code']) ? esc_attr($this->leadbox_settings['live_agent_code']) : ''
    );
  }

  public function moto_insight_option_callback()
  {
    if (!isset($this->leadbox_settings['moto_insight'])) {
      $this->leadbox_settings['moto_insight'] = "Disabled";
    }

    echo '<select id="moto_insight" name="leadbox-settings[moto_insight]">';
    if (strtolower($this->leadbox_settings['moto_insight']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['moto_insight']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function moto_insight_url_callback()
  {
    printf(
      '<input type="text" id="moto_insight_url" name="leadbox-settings[moto_insight_url]" value="%s" />',
      isset($this->leadbox_settings['moto_insight_url']) ? esc_attr($this->leadbox_settings['moto_insight_url']) : ''
    );
  }
  public function moto_insight_label_callback()
  {
    printf(
      '<input type="text" id="moto_insight_label" name="leadbox-settings[moto_insight_label]" value="%s" />',
      isset($this->leadbox_settings['moto_insight_label']) ? esc_attr($this->leadbox_settings['moto_insight_label']) : ''
    );
  }
  public function moto_insight_label_fr_callback()
  {
    printf(
      '<input type="text" id="moto_insight_label_fr" name="leadbox-settings[moto_insight_label_fr]" value="%s" />',
      isset($this->leadbox_settings['moto_insight_label_fr']) ? esc_attr($this->leadbox_settings['moto_insight_label_fr']) : ''
    );
  }


  /**
   * Print the Section text
   */
  public function print_section_info()
  {
    print 'Enter your settings below:';
  }

  public function print_excluded_section_info()
  {
    print 'Select the trims you want to exclude from the list below:';
  }

  public function print_excluded_models_section_info()
  {
    print 'Select the models you want to exclude from the list below:';
  }

  public function print_excluded_categories_section_info()
  {
    print 'Select the categories you want to exclude from the list below:';
  }

  public function print_section_languages()
  {
    printf('
    <table class="form-table">
    <tr>
    <td style="width: 200px;">
    </td>
    <td>
    <h2 style="width: 200px; text-align: center;"> EN </h2>
    </td>
    <td>
    <h2 style="width: 200px; text-align: center;"> FR </h2>
    </td>
    </tr>
    </table>
    ');
  }

  public function print_section_empty()
  {
    print '';
  }

  public function echo_nothing()
  {
    ?>
    <?php
  }

  /**
   * Options page callback
   */
  public function create_dealer_settings_page()
  {
    // Set class property
    $this->branding_options = get_option('dealer-settings-branding-options');
    ?>
      <div class="wrap">
        <h1>Dealer Settings</h1>
        <form method="post" action="options.php">
          <?php

          settings_fields('dealer-settings-branding-options-group');
          do_settings_sections('dealer-settings-branding');
          do_settings_sections('dealer-settings-finance');
          do_settings_sections('dealer-settings-finance-rv');
          do_settings_sections('dealer-settings-lease');
          do_settings_sections('dealer-settings-vehicle-count');
          do_settings_sections('dealer-settings-newsletter-settings');
          submit_button();

          ?>
        </form>
      </div>
    <?php
  }

  /**
   * Register and add settings
   */
  public function register_branding_settings()
  {
    $option = get_option('leadbox-settings');

    register_setting(
      'dealer-settings-branding-options-group',
      'dealer-settings-branding-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'branding',
      'Branding',
      array($this, 'print_section_info'),
      'dealer-settings-branding'
    );

    add_settings_section(
      'vehicle_count',
      'VDP Vehicle Count',
      array($this, 'print_section_info'),
      'dealer-settings-vehicle-count'
    );

    add_settings_field(
      'vehicle_count_option',
      'Status',
      array($this, 'ford_vehicle_count_callback'),
      'dealer-settings-vehicle-count',
      'vehicle_count'
    );

    add_settings_section(
      'newsletter_settings',
      'Newsletter Settings',
      array($this, 'print_section_info'),
      'dealer-settings-newsletter-settings'
    );

    add_settings_field(
      'newsletter_enabled_option',
      'Status',
      array($this, 'newsletter_enabled_callback'),
      'dealer-settings-newsletter-settings',
      'newsletter_settings'
    );

    add_settings_section(
      'finance_settings',
      'Finance',
      array($this, 'print_section_info'),
      'dealer-settings-finance'
    );

    add_settings_section(
      'lease_settings',
      'Lease',
      array($this, 'print_section_info'),
      'dealer-settings-lease'
    );

    add_settings_field(
      'logo_image',
      'Logo Image',
      array($this, 'logo_image_callback'),
      'dealer-settings-branding',
      'branding'
    );

    add_settings_field(
      'logo_footer_image',
      'Logo Footer Image',
      array($this, 'logo_footer_image_callback'),
      'dealer-settings-branding',
      'branding'
    );

    add_settings_field(
      'socialmedia_image',
      'Social Media Image',
      array($this, 'socialmedia_image_callback'),
      'dealer-settings-branding',
      'branding'
    );

    add_settings_field(
      'social_review_image',
      'Social review Image',
      array($this, 'social_review_image_callback'),
      'dealer-settings-branding',
      'branding'
    );
    if (isset($option['dealer_information']) && strtolower($option['dealer_information']) == 'rv') {
      add_settings_section(
        'finance_settings_rv',
        'Finance Settings RV',
        array($this, 'print_section_info'),
        'dealer-settings-finance-rv'
      );

      add_settings_field(
        'finance_fees',
        'Finance Fees',
        array($this, 'finance_fees_callback_rv'),
        'dealer-settings-finance-rv',
        'finance_settings_rv'
      );

      add_settings_field(
        'finance_tax',
        'Tax',
        array($this, 'tax_callback'),
        'dealer-settings-finance-rv',
        'finance_settings_rv'
      );

      add_settings_field(
        'finance_frequency',
        'Finance Frequency',
        array($this, 'finance_frequency_callback_rv'),
        'dealer-settings-finance-rv',
        'finance_settings_rv'
      );
    } else {

      add_settings_field(
        'finance_frequency',
        'Finance Frequency',
        array($this, 'finance_frequency_callback'),
        'dealer-settings-finance',
        'finance_settings'
      );

      add_settings_field(
        'lease_frequency',
        'Lease Frequency',
        array($this, 'lease_frequency_callback'),
        'dealer-settings-lease',
        'lease_settings'
      );
    }
  }

  /**
   * Get the settings option array and print one of its values
   */


  public function logo_image_callback()
  {
    printf(
      '<input type="text" id="background_image" name="dealer-settings-branding-options[logo_image]" value="%s" />
        <input id="upload_image_button" type="button" class="add-logo-image-button button button-secondary" value="Select image" />',
      isset($this->branding_options['logo_image']) ? esc_attr($this->branding_options['logo_image']) : ''
    );

    ?>

          <?php

  }
  public function logo_footer_image_callback()
  {
    printf(
      '<input type="text" id="logo_footer_image" name="dealer-settings-branding-options[logo_footer_image]" value="%s" />
        <input id="upload_image_button_footer" type="button" class="add-logo-footer-image-button button button-secondary" value="Select image" />',
      isset($this->branding_options['logo_footer_image']) ? esc_attr($this->branding_options['logo_footer_image']) : ''
    );

    ?>

          <?php

  }

  public function socialmedia_image_callback()
  {
    printf(
      '<input type="text" id="socialmedia_image" name="dealer-settings-branding-options[socialmedia_image]" value="%s" />
        <input id="upload_image_button_social" type="button" class="add-socialmedia-image-button button button-secondary" value="Select image" />',
      isset($this->branding_options['socialmedia_image']) ? esc_attr($this->branding_options['socialmedia_image']) : ''
    );

    ?>

          <?php

  }
  public function social_review_image_callback()
  {
    printf(
      '<input type="text" id="social_review_image" name="dealer-settings-branding-options[social_review_image]" value="%s" />
        <input id="upload_image_button_review" type="button" class="add-socialmedia-image-button-review button button-secondary" value="Select image" />',
      isset($this->branding_options['social_review_image']) ? esc_attr($this->branding_options['social_review_image']) : ''
    );

    ?>

          <?php

  }

  public function tax_callback()
  {
    printf(
      '<input type="number" step="0.01" min="0" max="100" id="finance_tax" name="dealer-settings-branding-options[finance_tax]" value="%s"/>',
      isset($this->branding_options['finance_tax']) ? esc_attr($this->branding_options['finance_tax']) : ''
    );
  }

  public function finance_rate_callback_rv()
  {
    printf(
      '<input type="number" step="0.01" min="0" max="100" id="finance_rate" name="dealer-settings-branding-options[finance_rate]" value="%s"/>',
      isset($this->branding_options['finance_rate']) ? esc_attr($this->branding_options['finance_rate']) : ''
    );
  }

  public function finance_frequency_callback_rv()
  {
    if (!isset($this->branding_options['finance_frequency'])) {
      $this->branding_options['finance_frequency'] = "Bi-Weekly";
    }

    echo '<select id="finance_frequency" name="dealer-settings-branding-options[finance_frequency]">';
    if (strtolower($this->branding_options['finance_frequency']) == 'bi-weekly') {
      echo '<option selected value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['finance_frequency']) == 'weekly') {
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option selected value="Weekly">Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    } else if (strtolower($this->branding_options['finance_frequency']) == 'monthly') {
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Weekly">Weekly</option>';
      echo '<option selected value="Monthly">Monthly</option>';
    } else {
      echo '<option value="Bi-Weekly">Bi-Weekly</option>';
      echo '<option value="Weekly">Weekly</option>';
      echo '<option value="Monthly">Monthly</option>';
    }

    echo '</select>';
  }

  public function finance_fees_callback_rv()
  {
    if (!isset($this->branding_options['finance_fees'])) {
      $this->branding_options['finance_fees'] = "Default";
    }

    echo '<select id="finance_fees" name="dealer-settings-branding-options[finance_fees]">';
    if (strtolower($this->branding_options['finance_fees']) == 'default') {
      echo '<option selected value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    } else if (strtolower($this->branding_options['finance_fees']) == 'custom') {
      echo '<option value="Default">Default</option>';
      echo '<option selected value="Custom">Custom</option>';
    } else {
      echo '<option value="Default">Default</option>';
      echo '<option value="Custom">Custom</option>';
    }

    echo '</select>';
  }
	public function set_data_google_sheet() {
		// Verificar el nonce para la seguridad
    check_ajax_referer('save_custom_finance_options_nonce', 'nonce');

    // Verificar permisos del usuario
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    // Llama a la función
    setDataGoogleSheet();

}

  public function create_web_info_page(){
    // Set class property
    $this->used_finance_options = get_option('dealer-settings-web-info-options');

    ?>
      <div class="wrap">
        <h1>Website Info</h1>
        <form method="post" action="options.php">
          <?php
          settings_fields('dealer-settings-web-info-group');
          do_settings_sections('dealer-settings-web-info');
          ?>
        </form>
      </div>
			<button type="button" class="button" id="updateGoogleSheet">Update Google Sheet</button>
      <div class="card-msg" id="google-sheet-update-result"></div>
			<style>
				.card-msg {
					text-align: center;
          text-transform: capitalize;
          align-self: center;
    		}
				.msg, .msg-er {
            width: 25%;
            border: 1px solid #ccd0d4;
            border-radius: 6px;
            box-shadow: 0 1px 1px rgba(0,0,0,0.04);
            margin: 20px auto;
            color: #ffffff;
            padding: 10px;
            animation: fadeIn 1s;
            opacity: 1;
        }
        .msg {
            background-color: #508D4E;
        }
        .msg-er {
            background-color: #c60000;
        }
				@keyframes fadeIn {
					0% { opacity: 0; }
					100% { opacity: 1; }
				}
			</style>

    <?php
  }

  //* zona de informacion de los componentes

  public function register_web_info_settings()
  {
    register_setting(
      'dealer-settings-web-info-group',
      'dealer-settings-web-info-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'plugin_info',
      'Plugin Info',
      array($this, 'print_section_empty'),
      'dealer-settings-web-info'
    );

    add_settings_field(
      'plugin_version',
      'Leadbox plugin version',
      array($this, 'print_plugin_version'),
      'dealer-settings-web-info',
      'plugin_info'
    );

    add_settings_section(
      'theme_info',
      'Theme Info',
      array($this, 'print_section_empty'),
      'dealer-settings-web-info'
    );

    add_settings_field(
      'theme_name',
      'Leadbox theme name',
      array($this, 'print_theme_name'),
      'dealer-settings-web-info',
      'theme_info'
    );

    add_settings_field(
      'theme_version',
      'Leadbox theme version',
      array($this, 'print_theme_version'),
      'dealer-settings-web-info',
      'theme_info'
    );

    add_settings_section(
      'components_info',
      'Components Info',
      array($this, 'print_section_empty'),
      'dealer-settings-web-info'
    );

    add_settings_field(
      'header_version',
      'Header version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'header'
    );
    add_settings_field(
      'navigation_version',
      'Navigation version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'navigation'
    );
    add_settings_field(
      'omnisearch_version',
      'Omnisearch version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'omnisearch'
    );
    add_settings_field(
      'social-bar_version',
      'Social bar version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'social-bar'
    );

    add_settings_field(
      'footer_version',
      'Footer version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'footer'
    );
    add_settings_field(
      'hours_footer_version',
      'Hours footer version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'hours-footer'
    );
    add_settings_field(
      'lineup_version',
      'Lineup version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'lineup'
    );
    add_settings_field(
      'srp_layout_version',
      'Srp layout version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-layout'
    );
    add_settings_field(
      'srp_title_version',
      'Srp title version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-title'
    );
    add_settings_field(
      'srp_colorizer_version',
      'Srp colorizer version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-colorizer'
    );
    add_settings_field(
      'srp_searchables_version',
      'Srp searchables version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-searchables'
    );

    add_settings_field(
      'filter_version',
      'Filter version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'filter'
    );
    add_settings_field(
      'srp_finance_version',
      'Srp finance version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-finance'
    );
    add_settings_field(
      'srp_lease_version',
      'Srp lease version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-lease'
    );


    add_settings_field(
      'vehicle_card_version',
      'Vehicle card version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vehicle-card'
    );
    add_settings_field(
      'vdp_layout_version',
      'Vdp layout version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-layout'
    );
    add_settings_field(
      'print_vdp_layout_version',
      'Print vdp layout version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'print-vdp-layout'
    );
    add_settings_field(
      'vdp_title_version',
      'Vdp title version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-title'
    );

    add_settings_field(
      'vdp_gallery_version',
      'VDP gallery version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-gallery'
    );

    add_settings_field(
      'vdp_pricing_version',
      'VDP pricing version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-pricing'
    );
    add_settings_field(
      'vdp_finance_version',
      'Vdp finance version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-finance'
    );
    add_settings_field(
      'vdp_lease_version',
      'Vdp lease version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-lease'
    );
    add_settings_field(
      'vdp_similars_version',
      'Vdp similars version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-similars'
    );

    add_settings_field(
      'vdp_cta_version',
      'VDP CTA version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-cta'
    );
    add_settings_field(
      'vdp_disclaimer_version',
      'Vdp disclaimer version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-disclaimer'
    );
    add_settings_field(
      'vdp_vehicle_features_version',
      'Vdp vehicle-features version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-vehicle-features'
    );
    add_settings_field(
      'vdp_model_banner_version',
      'Vdp model banner version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-model-banner'
    );
    add_settings_field(
      'vdp_key_features_version',
      'Vdp key features version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-key-features'
    );
    add_settings_field(
      'vdp_installed_options_version',
      'Vdp installed options version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-installed-options'
    );
    add_settings_field(
      'vdp_sticky_header_version',
      'Vdp sticky header version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-sticky-header'
    );
    add_settings_field(
      'vdp_vehicle_description_version',
      'Vdp vehicle description version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-vehicle-description'
    );
    add_settings_field(
      'vdp_fuel_economy_version',
      'Vdp fuel economy version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-fuel-economy'
    );
    add_settings_field(
      'srp_payment_calculator_version',
      'Srp payment calculator version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'srp-payment-calculator'
    );
    add_settings_field(
      'vdp_payment_calculator_version',
      'Vdp payment calculator version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-payment-calculator'
    );
    add_settings_field(
      'vdp_upgrades_version',
      'Vdp upgrades version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'vdp-upgrades'
    );
    add_settings_field(
      'blog_list_version',
      'Blog list version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'blog-list'
    );
    add_settings_field(
      'blog_entry_meta_version',
      'Blog entry meta version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'blog-entry-meta'
    );
    add_settings_field(
      'comparison_version',
      'Comparison version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison'
    );
    add_settings_field(
      'comparison_card_version',
      'Comparison card version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison-card'
    );
    add_settings_field(
      'comparison_card_thumb_version',
      'Comparison card thumb version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison-card-thumb'
    );
    add_settings_field(
      'comparison_card_phantom_version',
      'Comparison card phantom version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison-card-phantom'
    );
    add_settings_field(
      'comparison_key_features_version',
      'Comparison key features version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison-key-features'
    );
    add_settings_field(
      'comparison_key_features_title_version',
      'Comparison key features title version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'comparison-key-features-title'
    );
    add_settings_field(
      'model_trims_version',
      'Model trims version',
      array($this, 'print_component_version'),
      'dealer-settings-web-info',
      'components_info',
      'model-trims'
    );
  }
//* <------------------°°°°Fin de Seccion°°°°--------------------------->

  public function create_showroom_config_page()
  {
    // Set class property
    $this->showroom_options = get_option('dealer-settings-showroom-options');
    ?>
            <div class="wrap">
              <h1>Showroom Config</h1>
              <form method="post" action="options.php">
                <?php
                settings_fields('dealer-settings-showroom-group');
                do_settings_sections('dealer-settings-showroom');
                submit_button();
                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Register and add settings
   */
  public function register_showroom_settings()
  {
    register_setting(
      'dealer-settings-showroom-group',
      'dealer-settings-showroom-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'ex_models',
      'Exclude Models',
      array($this, 'print_excluded_models_section_info'),
      'dealer-settings-showroom'
    );


    add_settings_section(
      'ex_trims',
      'Exclude Trims',
      array($this, 'print_excluded_section_info'),
      'dealer-settings-showroom'
    );

    add_settings_field(
      'excluded_models',
      'Models',
      array($this, 'excluded_models_callback'),
      'dealer-settings-showroom',
      'ex_models',
      [
        'class' => 'excluded-models-table'
      ]
    );

    add_settings_field(
      'excluded_trims',
      'Trims',
      array($this, 'excluded_trims_callback'),
      'dealer-settings-showroom',
      'ex_trims',
      [
        'class' => 'excluded-trims-table'
      ]
    );

    add_settings_section(
      'ex_categories',
      'Exclude Categories',
      array($this, 'print_excluded_categories_section_info'),
      'dealer-settings-showroom'
    );

    add_settings_field(
      'excluded_categories',
      'Categories',
      array($this, 'excluded_categories_callback'),
      'dealer-settings-showroom',
      'ex_categories',
      [
        'class' => 'excluded-categories-table'
      ]
    );

    add_settings_section(
      'exclude_sitemap',
      'Exclude Showroom Pages From Sitemap',
      array($this, 'exclude_sitemap_callback'),
      'dealer-settings-showroom'
    );
  }

  /**
   * Make a GraphQL request to Stellate API with proper error handling
   *
   * @param string $query GraphQL query string
   * @param array $variables Optional query variables
   * @return array Response array with 'success', 'data', and 'error' keys
   */
  private function makeRequest($query, $variables = array())
  {
      $cache_key = 'stellate_' . md5($query . serialize($variables));

      // Check cache first
      $cached = get_transient($cache_key);
      if ($cached !== false) {
          return $cached;
      }

      $request = wp_remote_post('https://stellate.leadboxhq.com', [
          'headers' => [
              'Content-Type' => 'application/json'
          ],
          'body' => wp_json_encode([
              'query' => $query,
              'variables' => $variables
          ]),
          'timeout' => 10  // Add timeout to prevent indefinite hangs
      ]);

      // Check for WP_Error (network failures, timeouts, etc.)
      if (is_wp_error($request)) {
          leadbox_logger()->error('GraphQL request failed', array(
              'error_message' => $request->get_error_message(),
              'error_code' => $request->get_error_code(),
              'query' => $query,
          ));

          return array(
              'success' => false,
              'error' => 'Failed to connect to OEM data service',
              'data' => null
          );
      }

      // Check HTTP status code
      $status_code = wp_remote_retrieve_response_code($request);
      if ($status_code !== 200) {
          leadbox_logger()->error('GraphQL returned non-200 status', array(
              'status_code' => $status_code,
              'query' => $query,
          ));

          return array(
              'success' => false,
              'error' => "OEM data service returned status {$status_code}",
              'data' => null
          );
      }

      // Parse JSON response
      $body = wp_remote_retrieve_body($request);
      $decoded_response = json_decode($body, true);

      if ($decoded_response === null) {
          leadbox_logger()->error('GraphQL returned invalid JSON', array(
              'json_error' => json_last_error_msg(),
              'query' => $query,
          ));

          return array(
              'success' => false,
              'error' => 'Invalid response from OEM data service',
              'data' => null
          );
      }

      // Wrap successful response in standard format
      $response = array(
          'success' => true,
          'error' => null,
          'data' => $decoded_response
      );

      // Cache successful response for 1 hour
      set_transient($cache_key, $response, HOUR_IN_SECONDS);

      return $response;
  }

  /**
   * Get model and trim data from Stellate API
   *
   * @return array|WP_Error Array of models on success, WP_Error on failure
   */
  public function getModelTrim()
  {
      $lbsettings = get_leadbox_settings();
      if ($lbsettings['all_brands'] != '') {
          $otherBrands = explode(',', $lbsettings['all_brands']);
          $otherBrands = array_map('trim', $otherBrands);
      } else {
          $otherBrands = [];
      }

      array_unshift($otherBrands, get_leadbox_manufacturer());

      $allModels = [];

      foreach ($otherBrands as $brand) {
          $query = '{
              modelLists(first: 100, where: { search: "' . esc_attr($brand) . '" }) {
                  nodes {
                      modelData {
                          model
                          year
                          trims {
                              ... on ModelTrim {
                                  title
                                  trimData {
                                      name
                                  }
                              }
                          }
                      }
                  }
              }
          }';

          $response = $this->makeRequest($query);

          // Check if the request failed
          if (isset($response['success']) && $response['success'] === false) {
              leadbox_logger()->error('Failed to fetch models for brand', array(
                  'brand' => $brand,
                  'error' => $response['error'],
              ));
              return new WP_Error(
                  'stellate_api_error',
                  $response['error'],
                  array('brand' => $brand)
              );
          }

          // Extract models from successful response
          if (isset($response['data']['data']['modelLists']['nodes'])) {
              $allModels = array_merge($allModels, $response['data']['data']['modelLists']['nodes']);
          }
      }

      return $allModels;
  }

  /**
   * Get categories from Stellate API
   *
   * @return array|WP_Error Array of categories on success, WP_Error on failure
   */
  public function getCategories()
  {
    $query = '{
      modelLists(first: 100, where: { search: "' . esc_attr(get_leadbox_manufacturer()) . '" }) {
        nodes {
          modelData {
            category
          }
        }
      }
    }';

    $response = $this->makeRequest($query);

    // Check if the request failed
    if (isset($response['success']) && $response['success'] === false) {
        leadbox_logger()->error('Failed to fetch categories for manufacturer', array(
            'manufacturer' => get_leadbox_manufacturer(),
            'error' => $response['error'],
        ));
        return new WP_Error(
            'stellate_api_error',
            $response['error']
        );
    }

    // Extract categories from successful response
    if (!isset($response['data']['data']['modelLists']['nodes'])) {
        return array();
    }

    $categories = $response['data']['data']['modelLists']['nodes'];

    $categories = collect($categories)
    ->pluck('modelData.category')
    ->flatten()
    ->unique()
    ->values()
    ->all();

    return $categories;
  }
  public function excluded_models_callback()
  {
    ?>
            <style type="text/css">
              .excluded-models-table th {
                display: none;
              }
            </style>
            <script>
              jQuery(document).ready(function() {
                  const excludedModels = jQuery('#excluded_models').val().split(',').filter(Boolean);
                  const $modelsSelector = jQuery('#models-selector');
                  const $modelsVisual = jQuery('#model-selector-visual');

                  // Cargar modelos excluidos iniciales
                  excludedModels.forEach(model => {
                      $modelsVisual.append(`<option value="${model}">${model}</option>`);
                      $modelsSelector.find(`option[value="${model}"]`).css('color', 'red');
                  });

                  // Evento para agregar/eliminar modelos
                  $modelsSelector.on('click', function(e) {
                      const value = e.target.value;
                      const isExcluded = excludedModels.includes(value);

                      if (isExcluded) {
                          $modelsVisual.find(`option[value="${value}"]`).remove();
                          $modelsSelector.find(`option[value="${value}"]`).css('color', '');
                          excludedModels.splice(excludedModels.indexOf(value), 1);
                      } else {
                          $modelsVisual.append(`<option value="${value}">${value}</option>`);
                          $modelsSelector.find(`option[value="${value}"]`).css('color', 'red');
                          excludedModels.push(value);
                      }

                      jQuery('#excluded_models').val(excludedModels.join(','));
                  });

                  // Evento para eliminar modelos desde el selector visual
                  $modelsVisual.on('click', function(e) {
                      const value = e.target.value;
                      if (excludedModels.includes(value)) {
                          $modelsVisual.find(`option[value="${value}"]`).remove();
                          $modelsSelector.find(`option[value="${value}"]`).css('color', '');
                          excludedModels.splice(excludedModels.indexOf(value), 1);
                          jQuery('#excluded_models').val(excludedModels.join(','));
                      }
                  });
              });
            </script>
            <?php
            $model = $this->getModelTrim();

            // Check if API request failed
            if (is_wp_error($model)) {
                echo '<div class="notice notice-error" style="margin: 20px 0; padding: 10px;">';
                echo '<p><strong>Unable to load OEM data:</strong> ' . esc_html($model->get_error_message()) . '</p>';
                echo '<p>The model selector is temporarily unavailable. Please try again later or contact support if the issue persists.</p>';
                echo '</div>';
                return;
            }

            $excluded_models = explode(',', $this->showroom_options['excluded_models']);
            sort($model);

            // SELECT FOR MODELS
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Included Models</strong></label>";
            printf('<select name="models-selector" id="models-selector" multiple="multiple" style="height:200px;width:320px;">');
            foreach ($model as $models) {
                $model_text = $models["modelData"]["year"] . ' ' . $models["modelData"]["model"];

                // Verifica si el modelo está en la lista de excluidos
                if (in_array($model_text, $excluded_models)) {
                    // Si está excluido, aplica el estilo rojo
                    printf('<option value="' . esc_attr($model_text) . '" style="color: red;">' . esc_html($model_text) . '</option>');
                } else {
                    // Si no está excluido, muestra el option normal
                    printf('<option value="' . esc_attr($model_text) . '">' . esc_html($model_text) . '</option>');
                }
            }
            printf('</select>');
            echo "</div>";

            printf('<svg style="height:25px;width: 70px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M406.6 374.6l96-96c12.5-12.5 12.5-32.8 0-45.3l-96-96c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224l-293.5 0 41.4-41.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288l293.5 0-41.4 41.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z"/></svg>');

            // MODELS SELECTED
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Excluded Models</strong></label>";
            printf('<select name="model-selector-visual" id="model-selector-visual" multiple="multiple" style="height:200px;width:300px;">');
            printf('</select>');
            echo "</div>";

            // HIDDEN INPUT FOR MODELS
            printf(
              '<input type="hidden" id="excluded_models" name="dealer-settings-showroom-options[excluded_models]" value="%s" />',
              isset($this->showroom_options['excluded_models']) ? esc_attr($this->showroom_options['excluded_models']) : ''
            );
  }

  public function excluded_trims_callback()
  {
    ?>
            <style type="text/css">
              .excluded-trims-table th {
                display: none;
              }
            </style>
            <script>
            jQuery(document).ready(function() {
                const excludedTrims = jQuery('#excluded_trims').val().split(',').filter(Boolean);
                const $trimsSelector = jQuery('#trims-selector');
                const $trimsVisual = jQuery('#trims-selector-visual');

                // Cargar trims excluidos iniciales
                excludedTrims.forEach(trim => {
                    $trimsVisual.append(`<option value="${trim}">${trim}</option>`);
                    $trimsSelector.find(`option[value="${trim}"]`).css('color', 'red');
                });

                // Evento para agregar/eliminar trims
                $trimsSelector.on('click', function(e) {
                    const value = e.target.value;
                    const isExcluded = excludedTrims.includes(value);

                    if (isExcluded) {
                        $trimsVisual.find(`option[value="${value}"]`).remove();
                        $trimsSelector.find(`option[value="${value}"]`).css('color', '');
                        excludedTrims.splice(excludedTrims.indexOf(value), 1);
                    } else {
                        $trimsVisual.append(`<option value="${value}">${value}</option>`);
                        $trimsSelector.find(`option[value="${value}"]`).css('color', 'red');
                        excludedTrims.push(value);
                    }

                    jQuery('#excluded_trims').val(excludedTrims.join(','));
                });

                // Evento para eliminar trims desde el selector visual
                $trimsVisual.on('click', function(e) {
                    const value = e.target.value;
                    if (excludedTrims.includes(value)) {
                        $trimsVisual.find(`option[value="${value}"]`).remove();
                        $trimsSelector.find(`option[value="${value}"]`).css('color', '');
                        excludedTrims.splice(excludedTrims.indexOf(value), 1);
                        jQuery('#excluded_trims').val(excludedTrims.join(','));
                    }
                });
            });
            </script>
            <?php
            $models = $this->getModelTrim();

            // Check if API request failed
            if (is_wp_error($models)) {
                echo '<div class="notice notice-error" style="margin: 20px 0; padding: 10px;">';
                echo '<p><strong>Unable to load trim data:</strong> ' . esc_html($models->get_error_message()) . '</p>';
                echo '<p>The trim selector is temporarily unavailable. Please try again later or contact support if the issue persists.</p>';
                echo '</div>';
                return;
            }

            $excluded_models = explode(',', $this->showroom_options['excluded_models']);

            // SELECT FOR TRIMS
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Included Trims</strong></label>";
            printf('<select name="trims-selector" id="trims-selector" multiple="multiple" style="height:200px;width:320px;">');
            foreach ($models as $model) {
              foreach ($model['modelData'] as $modelData) {
                if (is_array($modelData)) {

                  foreach ($modelData as $trim) {
                    $trim_text = $model["modelData"]["year"]." ".$model["modelData"]["model"] . '|' . $trim["trimData"]["name"] . '">' . $trim["title"];
                    $trim_value = $model["modelData"]["year"]." ".$model["modelData"]["model"] . '|' . $trim["trimData"]["name"];
                    $trim_label = $trim["title"];

                    if (in_array($trim_text, $excluded_models)) {
                      printf('<option value="' . esc_attr($trim_value) . '" style="color: red;">' . esc_html($trim_label) . '</option>');
                    } else {
                      printf('<option value="' . esc_attr($trim_value) . '">' . esc_html($trim_label) . '</option>');
                    }
                  }
                }
              }
            }
            printf('</select>');
            echo "</div>";

            printf('<svg style="height:25px;width: 70px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M406.6 374.6l96-96c12.5-12.5 12.5-32.8 0-45.3l-96-96c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224l-293.5 0 41.4-41.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288l293.5 0-41.4 41.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z"/></svg>');

            // TRIMS SELECTED
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Excluded Trims</strong></label>";
            printf('<select name="trims-selector-visual" id="trims-selector-visual" multiple="multiple" style="height:200px;width:300px;">');
            printf('</select>');
            echo "</div>";

            // HIDDEN INPUT FOR TRIMS
            printf(
              '<input type="hidden" id="excluded_trims" name="dealer-settings-showroom-options[excluded_trims]" value="%s" />',
              isset($this->showroom_options['excluded_trims']) ? esc_attr($this->showroom_options['excluded_trims']) : ''
            );
  }

  public function excluded_categories_callback()
  {
    ?>
            <style type="text/css">
              .excluded-categories-table th {
                display: none;
              }
            </style>
            <script>
            jQuery(document).ready(function() {
                const excludedCategories = jQuery('#excluded_categories').val().split(',').filter(Boolean);
                const $categoriesSelector = jQuery('#categories-selector');
                const $categoriesVisual = jQuery('#categories-selector-visual');

                // Cargar categorías excluidas iniciales
                excludedCategories.forEach(category => {
                    $categoriesVisual.append(`<option value="${category}">${category}</option>`);
                    $categoriesSelector.find(`option[value="${category}"]`).css('color', 'red');
                });

                // Evento para agregar/eliminar categorías
                $categoriesSelector.on('click', function(e) {
                    const value = e.target.value;
                    const isExcluded = excludedCategories.includes(value);

                    if (isExcluded) {
                        $categoriesVisual.find(`option[value="${value}"]`).remove();
                        $categoriesSelector.find(`option[value="${value}"]`).css('color', '');
                        excludedCategories.splice(excludedCategories.indexOf(value), 1);
                    } else {
                        $categoriesVisual.append(`<option value="${value}">${value}</option>`);
                        $categoriesSelector.find(`option[value="${value}"]`).css('color', 'red');
                        excludedCategories.push(value);
                    }

                    jQuery('#excluded_categories').val(excludedCategories.join(','));
                });

                // Evento para eliminar categorías desde el selector visual
                $categoriesVisual.on('click', function(e) {
                    const value = e.target.value;
                    if (excludedCategories.includes(value)) {
                        $categoriesVisual.find(`option[value="${value}"]`).remove();
                        $categoriesSelector.find(`option[value="${value}"]`).css('color', '');
                        excludedCategories.splice(excludedCategories.indexOf(value), 1);
                        jQuery('#excluded_categories').val(excludedCategories.join(','));
                    }
                });
            });
            </script>
            <?php
            $categories = $this->getCategories();

            // Check if API request failed
            if (is_wp_error($categories)) {
                echo '<div class="notice notice-error" style="margin: 20px 0; padding: 10px;">';
                echo '<p><strong>Unable to load category data:</strong> ' . esc_html($categories->get_error_message()) . '</p>';
                echo '<p>The category selector is temporarily unavailable. Please try again later or contact support if the issue persists.</p>';
                echo '</div>';
                return;
            }

            // SELECT FOR CATEGORIES
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Categories</strong></label>";
            printf('<select name="categories-selector" id="categories-selector" multiple="multiple" style="height:200px;width:320px;">');
            foreach ($categories as $category) {
              printf('<option value="' . esc_attr($category) . '">' . esc_html($category) . '</option>');
            }
            printf('</select>');
            echo "</div>";

            printf('<svg style="height:25px;width: 70px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M406.6 374.6l96-96c12.5-12.5 12.5-32.8 0-45.3l-96-96c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224l-293.5 0 41.4-41.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288l293.5 0-41.4 41.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z"/></svg>');

            // TRIMS SELECTED
            echo "<div style='width: 320px;display:inline-block;'><label for='models-selector' style='display: block;text-align:center;'><strong>Excluded Categories</strong></label>";
            printf('<select name="categories-selector-visual" id="categories-selector-visual" multiple="multiple" style="height:200px;width:300px;">');
            printf('</select>');
            echo "</div>";

            // HIDDEN INPUT FOR TRIMS
            printf(
              '<input type="hidden" id="excluded_categories" name="dealer-settings-showroom-options[excluded_categories]" value="%s" />',
              isset($this->showroom_options['excluded_categories']) ? esc_attr($this->showroom_options['excluded_categories']) : ''
            );
  }

  public function exclude_sitemap_callback()
  {
    if (!isset($this->showroom_options['excluded_from_sitemap'])) {
      $this->showroom_options['excluded_from_sitemap'] = "Disabled";
    }

    echo '<select id="excluded_from_sitemap" name="dealer-settings-showroom-options[excluded_from_sitemap]">';
    if (strtolower($this->showroom_options['excluded_from_sitemap']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->showroom_options['excluded_from_sitemap']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  /**
   * Register and add VDP Payment settings
   */
  public function register_vdp_payment_settings()
  {
    register_setting(
      'dealer-settings-vdp-payment-group',
      'dealer-settings-vdp-payment-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'vdp_payment_settings',
      '',
      array($this, 'print_vdp_payment_section_info'),
      'dealer-settings-vdp-payment'
    );

    add_settings_field(
      'default_downpayment',
      'Default Downpayment',
      array($this, 'default_downpayment_callback'),
      'dealer-settings-vdp-payment',
      'vdp_payment_settings'
    );

    add_settings_field(
      'payment_type',
      'Payment Type',
      array($this, 'payment_type_callback'),
      'dealer-settings-vdp-payment',
      'vdp_payment_settings'
    );
  }

  /**
   * Create VDP Payment Settings page
   */
  public function create_vdp_payment_page()
  {
    // Set class property
    $this->vdp_payment_options = get_option('dealer-settings-vdp-payment-options');
    ?>
            <div class="wrap">
              <h1>VDP Payment Settings</h1>
              <form method="post" action="options.php">
                <?php
                settings_fields('dealer-settings-vdp-payment-group');
                do_settings_sections('dealer-settings-vdp-payment');
                submit_button();
                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Print VDP Payment section info
   */
  public function print_vdp_payment_section_info()
  {
    print '';
  }

  /**
   * Default Downpayment callback
   */
  public function default_downpayment_callback()
  {
    printf(
      '<input type="number" id="default_downpayment" name="dealer-settings-vdp-payment-options[vdp_default_downpayment]" value="%s" step="0.01" min="0" />',
      isset($this->vdp_payment_options['vdp_default_downpayment']) ? esc_attr($this->vdp_payment_options['vdp_default_downpayment']) : '0'
    );
    echo '<p class="description">Enter the default downpayment amount (e.g., 5000.00)</p>';
  }

  /**
   * Payment Type callback
   */
  public function payment_type_callback()
  {
    $selected = isset($this->vdp_payment_options['vdp_default_payment_type']) ? $this->vdp_payment_options['vdp_default_payment_type'] : 'lease';
    ?>
    <select id="payment_type" name="dealer-settings-vdp-payment-options[vdp_default_payment_type]">
      <option value="lease" <?php selected($selected, 'lease'); ?>>Lease</option>
      <option value="finance" <?php selected($selected, 'finance'); ?>>Finance</option>
    </select>
    <p class="description">Select the default payment type for VDP pages</p>
    <?php
  }

  public function print_plugin_version()
  {
    $path = plugin_dir_path(__DIR__) . 'Leadbox.php';
    $plugin_data = get_plugin_data($path);
    echo $plugin_data['Version'];
  }

  public function print_theme_name()
  {
    $my_theme = wp_get_theme();
    echo $my_theme['Name'];
  }

  public function print_theme_version()
  {
    $my_theme = wp_get_theme();
    echo $my_theme['Version'];
  }

  public function print_component_version($component)
  {
    $childPartial = get_stylesheet_directory() . '/views/partials/' . $component . '.blade.php';
    $childCl = get_stylesheet_directory() . '/views/cl/' . $component;

    if (hasChild()) {
      if (file_exists($childPartial)) {
        echo GENIUS[$component]['version'] . ' (Custom)';
      } else if (file_exists($childCl)) {
        echo GENIUS[$component]['version'] . ' (Custom)';
      } else {
        echo GENIUS[$component]['version'];
      }
    } else {
      if (file_exists($childPartial)) {
        echo GENIUS[$component]['version'];
      } else if (file_exists($childCl)) {
        echo GENIUS[$component]['version'];
      } else {
        echo GENIUS[$component]['version'];
      }
    }
  }

  public function create_used_finance_page()
  {
    // Set class property
    $this->used_finance_options = get_option('dealer-settings-used-finance-options');
    ?>
            <div class="wrap">
              <h1>Used Finance</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-used-finance-group');
                do_settings_sections('dealer-settings-used-finance');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  public function enable_first_section_callback()
  {
    if (!isset($this->used_finance_options['section_one_status'])) {
      $this->used_finance_options['section_one_status'] = "Disabled";
    }

    echo '<select id="section_one_status" name="dealer-settings-used-finance-options[section_one_status]">';
    if (strtolower($this->used_finance_options['section_one_status']) == 'disabled') {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else if (strtolower($this->used_finance_options['section_one_status']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }


  public function register_used_finance_settings()
  {
    register_setting(
      'dealer-settings-used-finance-group',
      'dealer-settings-used-finance-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'used_finance',
      'Used Finance',
      array($this, 'print_section_info'),
      'dealer-settings-used-finance'
    );

    add_settings_field(
      'section_one_status',
      'Status',
      array($this, 'enable_first_section_callback'),
      'dealer-settings-used-finance',
      'used_finance'
    );

    add_settings_section(
      'finance',
      '1 year old to 4 years old',
      array($this, 'print_section_info'),
      'dealer-settings-used-finance'
    );

    add_settings_field(
      'section_one_term',
      'Default Finance Term',
      array($this, 'finance_term_section_one_callback'),
      'dealer-settings-used-finance',
      'finance'
    );

    add_settings_field(
      'section_one_downpayment',
      'Default Finance Downpayment',
      array($this, 'finance_downpayment_section_one_callback'),
      'dealer-settings-used-finance',
      'finance'
    );

    add_settings_section(
      'finance-oldest',
      '5 years old to 15 years old',
      array($this, 'print_section_info'),
      'dealer-settings-used-finance'
    );

    add_settings_field(
      'section_one_term',
      'Default Finance Term',
      array($this, 'finance_term_section_two_callback'),
      'dealer-settings-used-finance',
      'finance-oldest'
    );

    add_settings_field(
      'section_one_downpayment',
      'Default Finance Downpayment',
      array($this, 'finance_downpayment_section_two_callback'),
      'dealer-settings-used-finance',
      'finance-oldest'
    );
  }

  public function finance_rate_section_one_callback()
  {
    printf(
      '<input type="number" id="section_one_rate" name="dealer-settings-used-finance-options[section_one_rate]" value="%s" />(Percent)',
      isset($this->used_finance_options['section_one_rate']) ? esc_attr($this->used_finance_options['section_one_rate']) : ''
    );
  }

  public function finance_term_section_one_callback()
  {
    printf(
      '<input type="number" id="section_one_term" name="dealer-settings-used-finance-options[section_one_term]" value="%s" />(Months)',
      isset($this->used_finance_options['section_one_term']) ? esc_attr($this->used_finance_options['section_one_term']) : ''
    );
  }

  public function finance_downpayment_section_one_callback()
  {
    printf(
      '<input type="number" id="section_one_downpayment" name="dealer-settings-used-finance-options[section_one_downpayment]" value="%s" />($)',
      isset($this->used_finance_options['section_one_downpayment']) ? esc_attr($this->used_finance_options['section_one_downpayment']) : ''
    );
  }


  public function finance_rate_section_two_callback()
  {
    printf(
      '<input type="number" id="section_two_rate" name="dealer-settings-used-finance-options[section_two_rate]" value="%s" />(Percent)',
      isset($this->used_finance_options['section_two_rate']) ? esc_attr($this->used_finance_options['section_two_rate']) : ''
    );
  }

  public function finance_term_section_two_callback()
  {
    printf(
      '<input type="number" id="section_two_term" name="dealer-settings-used-finance-options[section_two_term]" value="%s" />(Months)',
      isset($this->used_finance_options['section_two_term']) ? esc_attr($this->used_finance_options['section_two_term']) : ''
    );
  }

  public function finance_downpayment_section_two_callback()
  {
    printf(
      '<input type="number" id="section_two_downpayment" name="dealer-settings-used-finance-options[section_two_downpayment]" value="%s" />($)',
      isset($this->used_finance_options['section_two_downpayment']) ? esc_attr($this->used_finance_options['section_two_downpayment']) : ''
    );
  }

  /**
   * Options page callback
   */
  public function create_hours_page()
  {
    // Set class property
    $this->hours_options = get_option('dealer-settings-hours-options');
    ?>
            <div class="wrap">
              <h1>Hours</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-hours-options-group');
                do_settings_sections('dealer-settings-hours');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Register and add settings
   */
  public function register_hours_settings()
  {
    register_setting(
      'dealer-settings-hours-options-group',
      'dealer-settings-hours-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'hours',
      'Hours',
      array($this, 'print_section_info'),
      'dealer-settings-hours'
    );

    add_settings_field(
      'sale_hours_monday',
      'Sales Hours',
      array($this, 'sale_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );

    add_settings_field(
      'sale_hours_tuesday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );


    add_settings_field(
      'sale_hours_wednesday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'sale_hours_thursday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'sale_hours_friday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'sale_hours_saturday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'sale_hours_sunday',
      'Sales Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_monday',
      'Service Hours',
      array($this, 'service_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );

    add_settings_field(
      'service_hours_tuesday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_wednesday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_thursday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_friday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_saturday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'service_hours_sunday',
      'Service Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_monday',
      'Parts Hours',
      array($this, 'parts_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );

    add_settings_field(
      'parts_hours_tuesday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_wednesday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_thursday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_friday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_saturday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'parts_hours_sunday',
      'Parts Hours',
      array($this, 'echo_nothing'),
      'dealer-settings-hours',
      'hours',
      array('class' => 'hidden')
    );

    add_settings_field(
      'additionalone_hours_monday',
      'Additional Hours 1',
      array($this, 'additionalone_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );
    add_settings_field(
      'additionaltwo_hours_monday',
      'Additional Hours 2',
      array($this, 'additionaltwo_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );
    add_settings_field(
      'additionalthree_hours_monday',
      'Additional Hours 3',
      array($this, 'additionalthree_hours_callback'),
      'dealer-settings-hours',
      'hours'
    );
    add_settings_field(
      'hours_disclaimer',
      'Hours Disclaimer',
      array($this, 'hours_disclaimer_callback'),
      'dealer-settings-hours',
      'hours'
    );
  }

  public function get_hours_options($selected = NULL){
    $hours_options = '';
    foreach ($this->hour_range_options as $hour_range_option) {
      $hours_options .= '<option '. (isset($selected) && strtolower(str_replace(' ', '', $selected)) == strtolower(str_replace(' ', '', $hour_range_option)) ? ' selected '  : '').' value="' . $hour_range_option . '">' . $hour_range_option . '</option>';
    }

    return $hours_options;
  }

  public function sale_hours_callback()
  {
    ?>
            <style type="text/css">
              .tg {
                border-collapse: collapse;
                border-spacing: 0;
                width: 100%
              }

              .tg td {
                padding: 10px 5px;
                border-color: #ccc;
                border-style: solid;
                border-width: 1px;
                overflow: hidden;
                word-break: normal;
              }

              .tg th {
                font-weight: normal;
                padding: 10px 5px;
                border-color: #ccc;
                border-style: solid;
                border-width: 1px;
                overflow: hidden;
                word-break: normal;
              }

              .tg .tg-baqh {
                text-align: center;
                vertical-align: top;
                color: #999
              }

              .tg .tg-0lax {
                text-align: center;
                vertical-align: top
              }

              .tg .tg-0lax input[^type=checkbox] {
                width: 110px;
              }
            </style>
            <script>
              jQuery(document).ready(function() {
                jQuery('#sale_hours_monday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_monday_start').prop('disabled');
                  jQuery('#sale_hours_monday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_monday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_thursday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_thursday_start').prop('disabled');
                  jQuery('#sale_hours_thursday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_thursday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_wednesday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_wednesday_start').prop('disabled');
                  jQuery('#sale_hours_wednesday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_wednesday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_tuesday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_tuesday_start').prop('disabled');
                  jQuery('#sale_hours_tuesday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_tuesday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_friday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_friday_start').prop('disabled');
                  jQuery('#sale_hours_friday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_friday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_saturday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_saturday_start').prop('disabled');
                  jQuery('#sale_hours_saturday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_saturday_end').prop('disabled', !disabled);
                });
                jQuery('#sale_hours_sunday_closed').click(function() {
                  var disabled = jQuery('#sale_hours_sunday_start').prop('disabled');
                  jQuery('#sale_hours_sunday_start').prop('disabled', !disabled);
                  jQuery('#sale_hours_sunday_end').prop('disabled', !disabled);
                });
              });
              jQuery(document).ready(function() {
                jQuery('#service_hours_monday_closed').click(function() {
                  var disabled = jQuery('#service_hours_monday_start').prop('disabled');
                  jQuery('#service_hours_monday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_monday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_thursday_closed').click(function() {
                  var disabled = jQuery('#service_hours_thursday_start').prop('disabled');
                  jQuery('#service_hours_thursday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_thursday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_wednesday_closed').click(function() {
                  var disabled = jQuery('#service_hours_wednesday_start').prop('disabled');
                  jQuery('#service_hours_wednesday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_wednesday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_tuesday_closed').click(function() {
                  var disabled = jQuery('#service_hours_tuesday_start').prop('disabled');
                  jQuery('#service_hours_tuesday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_tuesday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_friday_closed').click(function() {
                  var disabled = jQuery('#service_hours_friday_start').prop('disabled');
                  jQuery('#service_hours_friday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_friday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_saturday_closed').click(function() {
                  var disabled = jQuery('#service_hours_saturday_start').prop('disabled');
                  jQuery('#service_hours_saturday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_saturday_end').prop('disabled', !disabled);
                });
                jQuery('#service_hours_sunday_closed').click(function() {
                  var disabled = jQuery('#service_hours_sunday_start').prop('disabled');
                  jQuery('#service_hours_sunday_start').prop('disabled', !disabled);
                  jQuery('#service_hours_sunday_end').prop('disabled', !disabled);
                });
              });
              jQuery(document).ready(function() {
                jQuery('#parts_hours_monday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_monday_start').prop('disabled');
                  jQuery('#parts_hours_monday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_monday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_thursday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_thursday_start').prop('disabled');
                  jQuery('#parts_hours_thursday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_thursday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_wednesday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_wednesday_start').prop('disabled');
                  jQuery('#parts_hours_wednesday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_wednesday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_tuesday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_tuesday_start').prop('disabled');
                  jQuery('#parts_hours_tuesday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_tuesday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_friday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_friday_start').prop('disabled');
                  jQuery('#parts_hours_friday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_friday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_saturday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_saturday_start').prop('disabled');
                  jQuery('#parts_hours_saturday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_saturday_end').prop('disabled', !disabled);
                });
                jQuery('#parts_hours_sunday_closed').click(function() {
                  var disabled = jQuery('#parts_hours_sunday_start').prop('disabled');
                  jQuery('#parts_hours_sunday_start').prop('disabled', !disabled);
                  jQuery('#parts_hours_sunday_end').prop('disabled', !disabled);
                });
              });
            </script>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="sale_hours_monday_start">Start:</label>
                  <?php
                    $sale_hours_monday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_monday_start']) ? $this->hours_options['sale_hours_monday_start'] : NULL);
                    printf(
                        '<select id="sale_hours_monday_start" name="dealer-settings-hours-options[sale_hours_monday_start]" %s>%s</select>',
                        $this->hours_options['sale_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                        $sale_hours_monday_start
                      );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_monday_end">End:</label>
                  <?php
                    $sale_hours_monday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_monday_end']) ? $this->hours_options['sale_hours_monday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_monday_end" name="dealer-settings-hours-options[sale_hours_monday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_monday_closed]" type="checkbox" id="sale_hours_monday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_tuesday_start">Start:</label>
                  <?php
                    $sale_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_tuesday_start']) ? $this->hours_options['sale_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_tuesday_start" name="dealer-settings-hours-options[sale_hours_tuesday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_tuesday_end">End:</label>
                  <?php
                    $sale_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_tuesday_end']) ? $this->hours_options['sale_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_tuesday_end" name="dealer-settings-hours-options[sale_hours_tuesday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_tuesday_closed]" type="checkbox" id="sale_hours_tuesday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_wednesday_start">Start:</label>
                  <?php
                    $sale_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_wednesday_start']) ? $this->hours_options['sale_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_wednesday_start" name="dealer-settings-hours-options[sale_hours_wednesday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_wednesday_end">End:</label>
                  <?php
                    $sale_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_wednesday_end']) ? $this->hours_options['sale_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_wednesday_end" name="dealer-settings-hours-options[sale_hours_wednesday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_wednesday_closed]" type="checkbox" id="sale_hours_wednesday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_thursday_start">Start:</label>
                  <?php
                    $sale_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_thursday_start']) ? $this->hours_options['sale_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_thursday_start" name="dealer-settings-hours-options[sale_hours_thursday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_thursday_end">End:</label>
                  <?php
                    $sale_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_thursday_end']) ? $this->hours_options['sale_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_thursday_end" name="dealer-settings-hours-options[sale_hours_thursday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_thursday_closed]" type="checkbox" id="sale_hours_thursday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_friday_start">Start:</label>
                  <?php
                    $sale_hours_friday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_friday_start']) ? $this->hours_options['sale_hours_friday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_friday_start" name="dealer-settings-hours-options[sale_hours_friday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_friday_end">End:</label>
                  <?php
                    $sale_hours_friday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_friday_end']) ? $this->hours_options['sale_hours_friday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_friday_end" name="dealer-settings-hours-options[sale_hours_friday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_friday_closed]" type="checkbox" id="sale_hours_friday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_saturday_start">Start:</label>
                  <?php
                    $sale_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_saturday_start']) ? $this->hours_options['sale_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_saturday_start" name="dealer-settings-hours-options[sale_hours_saturday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_saturday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_saturday_end">End:</label>
                  <?php
                    $sale_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_saturday_end']) ? $this->hours_options['sale_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_saturday_end" name="dealer-settings-hours-options[sale_hours_saturday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_saturday_closed]" type="checkbox" id="sale_hours_saturday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="sale_hours_sunday_start">Start:</label>
                  <?php
                    $sale_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['sale_hours_sunday_start']) ? $this->hours_options['sale_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="sale_hours_sunday_start" name="dealer-settings-hours-options[sale_hours_sunday_start]" %s>%s</select>',
                      $this->hours_options['sale_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_sunday_end">End:</label>
                  <?php
                    $sale_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['sale_hours_sunday_end']) ? $this->hours_options['sale_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="sale_hours_sunday_end" name="dealer-settings-hours-options[sale_hours_sunday_end]" %s>%s</select>',
                      $this->hours_options['sale_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $sale_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="sale_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[sale_hours_sunday_closed]" type="checkbox" id="sale_hours_sunday_closed" value="checked" %s>',
                      $this->hours_options['sale_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
          <?php
  }
  public function service_hours_callback()
  {

    if (!isset($this->hours_options['servicehourstatus'])) {
      $this->hours_options['servicehourstatus'] = "Disabled";
    }

    echo 'Status: <select id="servicehourstatus" name="dealer-settings-hours-options[servicehourstatus]">';
    if (strtolower($this->hours_options['servicehourstatus']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['servicehourstatus']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';
    ?>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="service_hours_monday_start">Start:</label>
                  <?php
                    $service_hours_monday_start = $this->get_hours_options( isset($this->hours_options['service_hours_monday_start']) ? $this->hours_options['service_hours_monday_start'] : NULL);
                    printf(
                      '<select id="service_hours_monday_start" name="dealer-settings-hours-options[service_hours_monday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_monday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_monday_end">End:</label>
                  <?php
                    $service_hours_monday_end = $this->get_hours_options( isset($this->hours_options['service_hours_monday_end']) ? $this->hours_options['service_hours_monday_end'] : NULL);
                    printf(
                      '<select id="service_hours_monday_end" name="dealer-settings-hours-options[service_hours_monday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_monday_closed]" type="checkbox" id="service_hours_monday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_tuesday_start">Start:</label>
                  <?php
                    $service_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['service_hours_tuesday_start']) ? $this->hours_options['service_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="service_hours_tuesday_start" name="dealer-settings-hours-options[service_hours_tuesday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_tuesday_end">End:</label>
                  <?php
                    $service_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['service_hours_tuesday_end']) ? $this->hours_options['service_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="service_hours_tuesday_end" name="dealer-settings-hours-options[service_hours_tuesday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_tuesday_closed]" type="checkbox" id="service_hours_tuesday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_wednesday_start">Start:</label>
                  <?php
                    $service_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['service_hours_wednesday_start']) ? $this->hours_options['service_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="service_hours_wednesday_start" name="dealer-settings-hours-options[service_hours_wednesday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_wednesday_end">End:</label>
                  <?php
                    $service_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['service_hours_wednesday_end']) ? $this->hours_options['service_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="service_hours_wednesday_end" name="dealer-settings-hours-options[service_hours_wednesday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_wednesday_closed]" type="checkbox" id="service_hours_wednesday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_thursday_start">Start:</label>
                  <?php
                    $service_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['service_hours_thursday_start']) ? $this->hours_options['service_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="service_hours_thursday_start" name="dealer-settings-hours-options[service_hours_thursday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_thursday_end">End:</label>
                  <?php
                    $service_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['service_hours_thursday_end']) ? $this->hours_options['service_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="service_hours_thursday_end" name="dealer-settings-hours-options[service_hours_thursday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_thursday_closed]" type="checkbox" id="service_hours_thursday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_friday_start">Start:</label>
                  <?php
                    $service_hours_friday_start = $this->get_hours_options( isset($this->hours_options['service_hours_friday_start']) ? $this->hours_options['service_hours_friday_start'] : NULL);
                    printf(
                      '<select id="service_hours_friday_start" name="dealer-settings-hours-options[service_hours_friday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_friday_end">End:</label>
                  <?php
                    $service_hours_friday_end = $this->get_hours_options( isset($this->hours_options['service_hours_friday_end']) ? $this->hours_options['service_hours_friday_end'] : NULL);
                    printf(
                      '<select id="service_hours_friday_end" name="dealer-settings-hours-options[service_hours_friday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_friday_closed]" type="checkbox" id="service_hours_friday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_saturday_start">Start:</label>
                  <?php
                    $service_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['service_hours_saturday_start']) ? $this->hours_options['service_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="service_hours_saturday_start" name="dealer-settings-hours-options[service_hours_saturday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_saturday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_saturday_end">End:</label>
                  <?php
                    $service_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['service_hours_saturday_end']) ? $this->hours_options['service_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="service_hours_saturday_end" name="dealer-settings-hours-options[service_hours_saturday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_saturday_closed]" type="checkbox" id="service_hours_saturday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="service_hours_sunday_start">Start:</label>
                  <?php
                    $service_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['service_hours_sunday_start']) ? $this->hours_options['service_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="service_hours_sunday_start" name="dealer-settings-hours-options[service_hours_sunday_start]" %s>%s</select>',
                      $this->hours_options['service_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_sunday_end">End:</label>
                  <?php
                    $service_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['service_hours_sunday_end']) ? $this->hours_options['service_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="service_hours_sunday_end" name="dealer-settings-hours-options[service_hours_sunday_end]" %s>%s</select>',
                      $this->hours_options['service_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $service_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="service_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[service_hours_sunday_closed]" type="checkbox" id="service_hours_sunday_closed" value="checked" %s>',
                      $this->hours_options['service_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
          <?php
  }
  public function parts_hours_callback()
  {
    if (!isset($this->hours_options['parthourstatus'])) {
      $this->hours_options['parthourstatus'] = "Disabled";
    }

    echo 'Status: <select id="parthourstatus" name="dealer-settings-hours-options[parthourstatus]">';
    if (strtolower($this->hours_options['parthourstatus']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['parthourstatus']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';

    ?>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="parts_hours_monday_start">Start:</label>
                  <?php
                    $parts_hours_monday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_monday_start']) ? $this->hours_options['parts_hours_monday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_monday_start" name="dealer-settings-hours-options[parts_hours_monday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_monday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_monday_end">End:</label>
                  <?php
                    $parts_hours_monday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_monday_end']) ? $this->hours_options['parts_hours_monday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_monday_end" name="dealer-settings-hours-options[parts_hours_monday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_monday_closed]" type="checkbox" id="parts_hours_monday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_tuesday_start">Start:</label>
                  <?php
                    $parts_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_tuesday_start']) ? $this->hours_options['parts_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_tuesday_start" name="dealer-settings-hours-options[parts_hours_tuesday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_tuesday_end">End:</label>
                  <?php
                    $parts_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_tuesday_end']) ? $this->hours_options['parts_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_tuesday_end" name="dealer-settings-hours-options[parts_hours_tuesday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_tuesday_closed]" type="checkbox" id="parts_hours_tuesday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_wednesday_start">Start:</label>
                  <?php
                    $parts_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_wednesday_start']) ? $this->hours_options['parts_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_wednesday_start" name="dealer-settings-hours-options[parts_hours_wednesday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_wednesday_end">End:</label>
                  <?php
                    $parts_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_wednesday_end']) ? $this->hours_options['parts_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_wednesday_end" name="dealer-settings-hours-options[parts_hours_wednesday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_wednesday_closed]" type="checkbox" id="parts_hours_wednesday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_thursday_start">Start:</label>
                  <?php
                    $parts_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_thursday_start']) ? $this->hours_options['parts_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_thursday_start" name="dealer-settings-hours-options[parts_hours_thursday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_thursday_end">End:</label>
                  <?php
                    $parts_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_thursday_end']) ? $this->hours_options['parts_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_thursday_end" name="dealer-settings-hours-options[parts_hours_thursday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_thursday_closed]" type="checkbox" id="parts_hours_thursday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_friday_start">Start:</label>
                  <?php
                    $parts_hours_friday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_friday_start']) ? $this->hours_options['parts_hours_friday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_friday_start" name="dealer-settings-hours-options[parts_hours_friday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_friday_end">End:</label>
                  <?php
                    $parts_hours_friday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_friday_end']) ? $this->hours_options['parts_hours_friday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_friday_end" name="dealer-settings-hours-options[parts_hours_friday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_friday_closed]" type="checkbox" id="parts_hours_friday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_saturday_start">Start:</label>
                  <?php
                    $parts_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_saturday_start']) ? $this->hours_options['parts_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_saturday_start" name="dealer-settings-hours-options[parts_hours_saturday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_saturday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_saturday_end">End:</label>
                  <?php
                    $parts_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_saturday_end']) ? $this->hours_options['parts_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_saturday_end" name="dealer-settings-hours-options[parts_hours_saturday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_saturday_closed]" type="checkbox" id="parts_hours_saturday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="parts_hours_sunday_start">Start:</label>
                  <?php
                    $parts_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['parts_hours_sunday_start']) ? $this->hours_options['parts_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="parts_hours_sunday_start" name="dealer-settings-hours-options[parts_hours_sunday_start]" %s>%s</select>',
                      $this->hours_options['parts_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_sunday_end">End:</label>
                  <?php
                    $parts_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['parts_hours_sunday_end']) ? $this->hours_options['parts_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="parts_hours_sunday_end" name="dealer-settings-hours-options[parts_hours_sunday_end]" %s>%s</select>',
                      $this->hours_options['parts_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $parts_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="parts_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[parts_hours_sunday_closed]" type="checkbox" id="parts_hours_sunday_closed" value="checked" %s>',
                      $this->hours_options['parts_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
          <?php
  }

  public function additionalone_hours_callback()
  {
    if (!isset($this->hours_options['additionalone'])) {
      $this->hours_options['additionalone'] = "Disabled";
    }

    echo 'Status: <select id="additionalone" name="dealer-settings-hours-options[additionalone]">';
    if (strtolower($this->hours_options['additionalone']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['additionalone']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';

    printf(
      'Label name: <input type="text" id="additionalonelabel" name="dealer-settings-hours-options[additionalonelabel]" value="%s" />',
      isset($this->hours_options['additionalonelabel']) ? esc_attr($this->hours_options['additionalonelabel']) : ''
    );

    echo '<br/><br/>';

    printf(
      'Label name FR: <input type="text" id="additionalonelabelfr" name="dealer-settings-hours-options[additionalonelabelfr]" value="%s" />',
      isset($this->hours_options['additionalonelabelfr']) ? esc_attr($this->hours_options['additionalonelabelfr']) : ''
    );

    echo '<br/><br/>';

    ?>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="additionalone_hours_monday_start">Start:</label>
                  <?php
                    $additionalone_hours_monday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_monday_start']) ? $this->hours_options['additionalone_hours_monday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_monday_start" name="dealer-settings-hours-options[additionalone_hours_monday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_monday_closed'])) && $this->hours_options['additionalone_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_monday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_monday_end">End:</label>
                  <?php
                    $additionalone_hours_monday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_monday_end']) ? $this->hours_options['additionalone_hours_monday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_monday_end" name="dealer-settings-hours-options[additionalone_hours_monday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_monday_closed'])) && $this->hours_options['additionalone_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_monday_closed]" type="checkbox" id="additionalone_hours_monday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_monday_closed'])) && $this->hours_options['additionalone_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_tuesday_start">Start:</label>
                  <?php
                    $additionalone_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_tuesday_start']) ? $this->hours_options['additionalone_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_tuesday_start" name="dealer-settings-hours-options[additionalone_hours_tuesday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_tuesday_closed'])) && $this->hours_options['additionalone_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_tuesday_end">End:</label>
                  <?php
                    $additionalone_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_tuesday_end']) ? $this->hours_options['additionalone_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_tuesday_end" name="dealer-settings-hours-options[additionalone_hours_tuesday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_tuesday_closed'])) && $this->hours_options['additionalone_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_tuesday_closed]" type="checkbox" id="additionalone_hours_tuesday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_tuesday_closed'])) && $this->hours_options['additionalone_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_wednesday_start">Start:</label>
                  <?php
                    $additionalone_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_wednesday_start']) ? $this->hours_options['additionalone_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_wednesday_start" name="dealer-settings-hours-options[additionalone_hours_wednesday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_wednesday_closed'])) && $this->hours_options['additionalone_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_wednesday_end">End:</label>
                  <?php
                    $additionalone_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_wednesday_end']) ? $this->hours_options['additionalone_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_wednesday_end" name="dealer-settings-hours-options[additionalone_hours_wednesday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_wednesday_closed'])) && $this->hours_options['additionalone_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_wednesday_closed]" type="checkbox" id="additionalone_hours_wednesday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_wednesday_closed'])) && $this->hours_options['additionalone_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_thursday_start">Start:</label>
                  <?php
                    $additionalone_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_thursday_start']) ? $this->hours_options['additionalone_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_thursday_start" name="dealer-settings-hours-options[additionalone_hours_thursday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_thursday_closed'])) && $this->hours_options['additionalone_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_thursday_end">End:</label>
                  <?php
                    $additionalone_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_thursday_end']) ? $this->hours_options['additionalone_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_thursday_end" name="dealer-settings-hours-options[additionalone_hours_thursday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_thursday_closed'])) && $this->hours_options['additionalone_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_thursday_closed]" type="checkbox" id="additionalone_hours_thursday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_thursday_closed'])) && $this->hours_options['additionalone_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_friday_start">Start:</label>
                  <?php
                    $additionalone_hours_friday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_friday_start']) ? $this->hours_options['additionalone_hours_friday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_friday_start" name="dealer-settings-hours-options[additionalone_hours_friday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_friday_closed'])) && $this->hours_options['additionalone_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_friday_end">End:</label>
                  <?php
                    $additionalone_hours_friday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_friday_end']) ? $this->hours_options['additionalone_hours_friday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_friday_end" name="dealer-settings-hours-options[additionalone_hours_friday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_friday_closed'])) && $this->hours_options['additionalone_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_friday_closed]" type="checkbox" id="additionalone_hours_friday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_friday_closed'])) && $this->hours_options['additionalone_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_saturday_start">Start:</label>
                  <?php
                    $additionalone_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_saturday_start']) ? $this->hours_options['additionalone_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_saturday_start" name="dealer-settings-hours-options[additionalone_hours_saturday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_saturday_closed'])) && $this->hours_options['additionalone_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_saturday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_saturday_end">End:</label>
                  <?php
                    $additionalone_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_saturday_end']) ? $this->hours_options['additionalone_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_saturday_end" name="dealer-settings-hours-options[additionalone_hours_saturday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_saturday_closed'])) && $this->hours_options['additionalone_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_saturday_closed]" type="checkbox" id="additionalone_hours_saturday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_saturday_closed'])) && $this->hours_options['additionalone_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalone_hours_sunday_start">Start:</label>
                  <?php
                    $additionalone_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['additionalone_hours_sunday_start']) ? $this->hours_options['additionalone_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="additionalone_hours_sunday_start" name="dealer-settings-hours-options[additionalone_hours_sunday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionalone_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_sunday_end">End:</label>
                  <?php
                    $additionalone_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['additionalone_hours_sunday_end']) ? $this->hours_options['additionalone_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="additionalone_hours_sunday_end" name="dealer-settings-hours-options[additionalone_hours_sunday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionalone_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalone_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalone_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalone_hours_sunday_closed]" type="checkbox" id="additionalone_hours_sunday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionalone_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
          <?php
  }

  public function additionaltwo_hours_callback()
  {

    //var_dump($this->hours_options);
    if (!isset($this->hours_options['additionaltwo'])) {
      $this->hours_options['additionaltwo'] = "Disabled";
    }

    echo 'Status: <select id="additionaltwo" name="dealer-settings-hours-options[additionaltwo]">';
    if (strtolower($this->hours_options['additionaltwo']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['additionaltwo']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';

    printf(
      'Label name: <input type="text" id="additionaltwolabel" name="dealer-settings-hours-options[additionaltwolabel]" value="%s" />',
      isset($this->hours_options['additionaltwolabel']) ? esc_attr($this->hours_options['additionaltwolabel']) : ''
    );

    echo '<br/><br/>';

    printf(
      'Label name FR: <input type="text" id="additionaltwolabelfr" name="dealer-settings-hours-options[additionaltwolabelfr]" value="%s" />',
      isset($this->hours_options['additionaltwolabelfr']) ? esc_attr($this->hours_options['additionaltwolabelfr']) : ''
    );

    echo '<br/><br/>';
    ?>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_monday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_monday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_monday_start']) ? $this->hours_options['additionaltwo_hours_monday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_monday_start" name="dealer-settings-hours-options[additionaltwo_hours_monday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_monday_closed'])) && $this->hours_options['additionaltwo_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_monday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_monday_end">End:</label>
                  <?php
                    $additionaltwo_hours_monday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_monday_end']) ? $this->hours_options['additionaltwo_hours_monday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_monday_end" name="dealer-settings-hours-options[additionaltwo_hours_monday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_monday_closed'])) && $this->hours_options['additionaltwo_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_monday_closed]" type="checkbox" id="additionaltwo_hours_monday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_monday_closed'])) && $this->hours_options['additionaltwo_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_tuesday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_tuesday_start']) ? $this->hours_options['additionaltwo_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_tuesday_start" name="dealer-settings-hours-options[additionaltwo_hours_tuesday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_tuesday_closed'])) && $this->hours_options['additionaltwo_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_tuesday_end">End:</label>
                  <?php
                    $additionaltwo_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_tuesday_end']) ? $this->hours_options['additionaltwo_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_tuesday_end" name="dealer-settings-hours-options[additionaltwo_hours_tuesday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_tuesday_closed'])) && $this->hours_options['additionaltwo_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_tuesday_closed]" type="checkbox" id="additionaltwo_hours_tuesday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_tuesday_closed'])) && $this->hours_options['additionaltwo_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_wednesday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_wednesday_start']) ? $this->hours_options['additionaltwo_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_wednesday_start" name="dealer-settings-hours-options[additionaltwo_hours_wednesday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_wednesday_closed'])) && $this->hours_options['additionaltwo_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_wednesday_end">End:</label>
                  <?php
                    $additionaltwo_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_wednesday_end']) ? $this->hours_options['additionaltwo_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_wednesday_end" name="dealer-settings-hours-options[additionaltwo_hours_wednesday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_wednesday_closed'])) && $this->hours_options['additionaltwo_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_wednesday_closed]" type="checkbox" id="additionaltwo_hours_wednesday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_wednesday_closed'])) && $this->hours_options['additionaltwo_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_thursday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_thursday_start']) ? $this->hours_options['additionaltwo_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_thursday_start" name="dealer-settings-hours-options[additionaltwo_hours_thursday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_thursday_closed'])) && $this->hours_options['additionaltwo_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_thursday_end">End:</label>
                  <?php
                    $additionaltwo_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_thursday_end']) ? $this->hours_options['additionaltwo_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_thursday_end" name="dealer-settings-hours-options[additionaltwo_hours_thursday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_thursday_closed'])) && $this->hours_options['additionaltwo_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_thursday_closed]" type="checkbox" id="additionaltwo_hours_thursday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_thursday_closed'])) && $this->hours_options['additionaltwo_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_friday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_friday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_friday_start']) ? $this->hours_options['additionaltwo_hours_friday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_friday_start" name="dealer-settings-hours-options[additionaltwo_hours_friday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_friday_closed'])) && $this->hours_options['additionaltwo_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_friday_end">End:</label>
                  <?php
                    $additionaltwo_hours_friday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_friday_end']) ? $this->hours_options['additionaltwo_hours_friday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_friday_end" name="dealer-settings-hours-options[additionaltwo_hours_friday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_friday_closed'])) && $this->hours_options['additionaltwo_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_friday_closed]" type="checkbox" id="additionaltwo_hours_friday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_friday_closed'])) && $this->hours_options['additionaltwo_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_saturday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_saturday_start']) ? $this->hours_options['additionaltwo_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_saturday_start" name="dealer-settings-hours-options[additionaltwo_hours_saturday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_saturday_closed'])) && $this->hours_options['additionaltwo_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_saturday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_saturday_end">End:</label>
                  <?php
                    $additionaltwo_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_saturday_end']) ? $this->hours_options['additionaltwo_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_saturday_end" name="dealer-settings-hours-options[additionaltwo_hours_saturday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionaltwo_hours_saturday_closed'])) && $this->hours_options['additionaltwo_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_saturday_closed]" type="checkbox" id="additionaltwo_hours_saturday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionaltwo_hours_saturday_closed'])) && $this->hours_options['additionaltwo_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionaltwo_hours_sunday_start">Start:</label>
                  <?php
                    $additionaltwo_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_sunday_start']) ? $this->hours_options['additionaltwo_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_sunday_start" name="dealer-settings-hours-options[additionaltwo_hours_sunday_start]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionaltwo_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_sunday_end">End:</label>
                  <?php
                    $additionaltwo_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['additionaltwo_hours_sunday_end']) ? $this->hours_options['additionaltwo_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="additionaltwo_hours_sunday_end" name="dealer-settings-hours-options[additionaltwo_hours_sunday_end]" %s>%s</select>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionaltwo_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionaltwo_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionaltwo_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionaltwo_hours_sunday_closed]" type="checkbox" id="additionaltwo_hours_sunday_closed" value="checked" %s>',
                      (isset($this->hours_options['additionalone_hours_sunday_closed'])) && $this->hours_options['additionaltwo_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
          <?php
  }

  //Additional3 Hours
  public function additionalthree_hours_callback()
  {
    if (!isset($this->hours_options['additionalthree'])) {
      $this->hours_options['additionalthree'] = "Disabled";
    }

    echo 'Status: <select id="additionalthree" name="dealer-settings-hours-options[additionalthree]">';
    if (strtolower($this->hours_options['additionalthree']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['additionalthree']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';

    printf(
      'Label name: <input type="text" id="additionalthreelabel" name="dealer-settings-hours-options[additionalthreelabel]" value="%s" />',
      isset($this->hours_options['additionalthreelabel']) ? esc_attr($this->hours_options['additionalthreelabel']) : ''
    );

    echo '<br/><br/>';

    printf(
      'Label name FR: <input type="text" id="additionalthreelabelfr" name="dealer-settings-hours-options[additionalthreelabelfr]" value="%s" />',
      isset($this->hours_options['additionalthreelabelfr']) ? esc_attr($this->hours_options['additionalthreelabelfr']) : ''
    );

    echo '<br/><br/>';
    ?>
            <table class="tg">
              <tr>
                <th class="tg-baqh">Monday<br></th>
                <th class="tg-baqh">Tuesday</th>
                <th class="tg-baqh">Wednesday</th>
                <th class="tg-baqh">Thursday</th>
                <th class="tg-baqh">Friday</th>
                <th class="tg-baqh">Saturday</th>
                <th class="tg-baqh">Sunday</th>
              </tr>
              <tr>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_monday_start">Start:</label>
                  <?php
                    $additionalthree_hours_monday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_monday_start']) ? $this->hours_options['additionalthree_hours_monday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_monday_start" name="dealer-settings-hours-options[additionalthree_hours_monday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_monday_closed']) && $this->hours_options['additionalthree_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_monday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_monday_end">End:</label>
                  <?php
                    $additionalthree_hours_monday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_monday_end']) ? $this->hours_options['additionalthree_hours_monday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_monday_end" name="dealer-settings-hours-options[additionalthree_hours_monday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_monday_closed']) && $this->hours_options['additionalthree_hours_monday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_monday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_monday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_monday_closed]" type="checkbox" id="additionalthree_hours_monday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_monday_closed']) && $this->hours_options['additionalthree_hours_monday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_tuesday_start">Start:</label>
                  <?php
                    $additionalthree_hours_tuesday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_tuesday_start']) ? $this->hours_options['additionalthree_hours_tuesday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_tuesday_start" name="dealer-settings-hours-options[additionalthree_hours_tuesday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_tuesday_closed']) && $this->hours_options['additionalthree_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_tuesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_tuesday_end">End:</label>
                  <?php
                    $additionalthree_hours_tuesday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_tuesday_end']) ? $this->hours_options['additionalthree_hours_tuesday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_tuesday_end" name="dealer-settings-hours-options[additionalthree_hours_tuesday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_tuesday_closed']) && $this->hours_options['additionalthree_hours_tuesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_tuesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_tuesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_tuesday_closed]" type="checkbox" id="additionalthree_hours_tuesday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_tuesday_closed']) && $this->hours_options['additionalthree_hours_tuesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_wednesday_start">Start:</label>
                  <?php
                    $additionalthree_hours_wednesday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_wednesday_start']) ? $this->hours_options['additionalthree_hours_wednesday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_wednesday_start" name="dealer-settings-hours-options[additionalthree_hours_wednesday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_wednesday_closed']) && $this->hours_options['additionalthree_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_wednesday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_wednesday_end">End:</label>
                  <?php
                    $additionalthree_hours_wednesday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_wednesday_end']) ? $this->hours_options['additionalthree_hours_wednesday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_wednesday_end" name="dealer-settings-hours-options[additionalthree_hours_wednesday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_wednesday_closed']) && $this->hours_options['additionalthree_hours_wednesday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_wednesday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_wednesday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_wednesday_closed]" type="checkbox" id="additionalthree_hours_wednesday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_wednesday_closed']) && $this->hours_options['additionalthree_hours_wednesday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_thursday_start">Start:</label>
                  <?php
                    $additionalthree_hours_thursday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_thursday_start']) ? $this->hours_options['additionalthree_hours_thursday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_thursday_start" name="dealer-settings-hours-options[additionalthree_hours_thursday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_thursday_closed']) && $this->hours_options['additionalthree_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_thursday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_thursday_end">End:</label>
                  <?php
                    $additionalthree_hours_thursday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_thursday_end']) ? $this->hours_options['additionalthree_hours_thursday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_thursday_end" name="dealer-settings-hours-options[additionalthree_hours_thursday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_thursday_closed']) && $this->hours_options['additionalthree_hours_thursday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_thursday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_thursday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_thursday_closed]" type="checkbox" id="additionalthree_hours_thursday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_thursday_closed']) && $this->hours_options['additionalthree_hours_thursday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_friday_start">Start:</label>
                  <?php
                    $additionalthree_hours_friday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_friday_start']) ? $this->hours_options['additionalthree_hours_friday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_friday_start" name="dealer-settings-hours-options[additionalthree_hours_friday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_friday_closed']) && $this->hours_options['additionalthree_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_friday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_friday_end">End:</label>
                  <?php
                    $additionalthree_hours_friday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_friday_end']) ? $this->hours_options['additionalthree_hours_friday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_friday_end" name="dealer-settings-hours-options[additionalthree_hours_friday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_friday_closed']) && $this->hours_options['additionalthree_hours_friday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_friday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_friday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_friday_closed]" type="checkbox" id="additionalthree_hours_friday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_friday_closed']) && $this->hours_options['additionalthree_hours_friday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_saturday_start">Start:</label>
                  <?php
                    $additionalthree_hours_saturday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_saturday_start']) ? $this->hours_options['additionalthree_hours_saturday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_saturday_start" name="dealer-settings-hours-options[additionalthree_hours_saturday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_saturday_closed']) && $this->hours_options['additionalthree_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_saturday_start
                    );
                   ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_saturday_end">End:</label>
                  <?php
                    $additionalthree_hours_saturday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_saturday_end']) ? $this->hours_options['additionalthree_hours_saturday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_saturday_end" name="dealer-settings-hours-options[additionalthree_hours_saturday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_saturday_closed']) && $this->hours_options['additionalthree_hours_saturday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_saturday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_saturday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_saturday_closed]" type="checkbox" id="additionalthree_hours_saturday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_saturday_closed']) && $this->hours_options['additionalthree_hours_saturday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
                <td class="tg-0lax">
                  <label for="additionalthree_hours_sunday_start">Start:</label>
                  <?php
                    $additionalthree_hours_sunday_start = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_sunday_start']) ? $this->hours_options['additionalthree_hours_sunday_start'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_sunday_start" name="dealer-settings-hours-options[additionalthree_hours_sunday_start]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_sunday_closed']) && $this->hours_options['additionalthree_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_sunday_start
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_sunday_end">End:</label>
                  <?php
                    $additionalthree_hours_sunday_end = $this->get_hours_options( isset($this->hours_options['additionalthree_hours_sunday_end']) ? $this->hours_options['additionalthree_hours_sunday_end'] : NULL);
                    printf(
                      '<select id="additionalthree_hours_sunday_end" name="dealer-settings-hours-options[additionalthree_hours_sunday_end]" %s>%s</select>',
                      isset($this->hours_options['additionalthree_hours_sunday_closed']) && $this->hours_options['additionalthree_hours_sunday_closed'] == 'checked' ? 'disabled' : '',
                      $additionalthree_hours_sunday_end
                    );
                  ?>
                  <br>
                  <hr>
                  <label for="additionalthree_hours_sunday_closed">
                    <?php printf(
                      '<input name="dealer-settings-hours-options[additionalthree_hours_sunday_closed]" type="checkbox" id="additionalthree_hours_sunday_closed" value="checked" %s>',
                      isset($this->hours_options['additionalthree_hours_sunday_closed']) && $this->hours_options['additionalthree_hours_sunday_closed'] == 'checked' ? 'checked' : ''
                    ); ?> Closed
                  </label>
                </td>
              </tr>
            </table>
            <br><br>
            <h3>✨ Special Hours</h3>
            <div id="special-hours-form" style="background: #f9f9f9; padding: 20px; border-radius: 5px; margin-bottom: 20px;">
              <h4 id="form-title">Add New Special Hours</h4>
              <input type="hidden" id="editing_index" value="">
              <table class="tg" style="width: 100%;">
                <tr>
                  <th class="tg-baqh">Label</th>
                  <th class="tg-baqh">Date</th>
                  <th class="tg-baqh">Sales</th>
                  <th class="tg-baqh">Service</th>
                  <th class="tg-baqh">Parts</th>
                  <th class="tg-baqh">Action</th>
                </tr>
                <tr>
                  <td class="tg-0lax">
                    <input type="text" id="special_hours_label" placeholder="e.g., Holiday Hours" style="width: 100%; padding: 5px;">
                  </td>
                  <td class="tg-0lax">
                    <input type="date" id="special_hours_date" style="width: 100%; padding: 5px;">
                  </td>
                  <td class="tg-0lax">
                    <label>
                      <input type="checkbox" id="special_hours_sales_closed" style="margin-right: 5px;">
                      Closed
                    </label>
                    <hr>
                    <div id="special_hours_sales_container">
                      <label for="special_hours_sales_start">Start:</label>
                      <?php
                        $sales_start_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_sales_start" style="width: 100%%;">%s</select>', $sales_start_options);
                      ?>
                      <br><hr>
                      <label for="special_hours_sales_end">End:</label>
                      <?php
                        $sales_end_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_sales_end" style="width: 100%%;">%s</select>', $sales_end_options);
                      ?>
                    </div>
                  </td>
                  <td class="tg-0lax">
                    <label>
                      <input type="checkbox" id="special_hours_service_closed" style="margin-right: 5px;">
                      Closed
                    </label>
                    <hr>
                    <div id="special_hours_service_container">
                      <label for="special_hours_service_start">Start:</label>
                      <?php
                        $service_start_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_service_start" style="width: 100%%;">%s</select>', $service_start_options);
                      ?>
                      <br><hr>
                      <label for="special_hours_service_end">End:</label>
                      <?php
                        $service_end_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_service_end" style="width: 100%%;">%s</select>', $service_end_options);
                      ?>
                    </div>
                  </td>
                  <td class="tg-0lax">
                    <label>
                      <input type="checkbox" id="special_hours_parts_closed" style="margin-right: 5px;">
                      Closed
                    </label>
                    <hr>
                    <div id="special_hours_parts_container">
                      <label for="special_hours_parts_start">Start:</label>
                      <?php
                        $parts_start_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_parts_start" style="width: 100%%;">%s</select>', $parts_start_options);
                      ?>
                      <br><hr>
                      <label for="special_hours_parts_end">End:</label>
                      <?php
                        $parts_end_options = $this->get_hours_options(NULL);
                        printf('<select id="special_hours_parts_end" style="width: 100%%;">%s</select>', $parts_end_options);
                      ?>
                    </div>
                  </td>
                  <td class="tg-0lax" style="vertical-align: middle; text-align: center;">
                    <button type="button" id="save-special-hours" class="button button-primary" style="padding: 10px 20px; margin-bottom: 5px;">Save</button>
                    <button type="button" id="cancel-edit-special-hours" class="button" style="padding: 10px 20px; display: none;">Cancel</button>
                  </td>
                </tr>
              </table>
            </div>

            <input type="hidden" id="special_hours_data" name="dealer-settings-hours-options[special_hours]" value='<?php echo esc_attr(isset($this->hours_options['special_hours']) ? $this->hours_options['special_hours'] : '[]'); ?>'>

            <div id="special-hours-list">
              <h4>Saved Special Hours</h4>
              <div id="special-hours-items"></div>
            </div>

            <script>
            jQuery(document).ready(function($) {
              let specialHours = [];

              try {
                const savedData = $('#special_hours_data').val();
                if (savedData && savedData !== '[]') {
                  specialHours = JSON.parse(savedData);
                }
              } catch(e) {
                console.error('Error parsing special hours:', e);
                specialHours = [];
              }

              // Handle closed checkboxes
              function updateClosedState(dept) {
                const isChecked = $(`#special_hours_${dept}_closed`).is(':checked');
                $(`#special_hours_${dept}_container`).toggle(!isChecked);
                if (isChecked) {
                  $(`#special_hours_${dept}_start`).prop('disabled', true);
                  $(`#special_hours_${dept}_end`).prop('disabled', true);
                } else {
                  $(`#special_hours_${dept}_start`).prop('disabled', false);
                  $(`#special_hours_${dept}_end`).prop('disabled', false);
                }
              }

              $('#special_hours_sales_closed').on('change', function() { updateClosedState('sales'); });
              $('#special_hours_service_closed').on('change', function() { updateClosedState('service'); });
              $('#special_hours_parts_closed').on('change', function() { updateClosedState('parts'); });

              function clearForm() {
                $('#special_hours_label').val('');
                $('#special_hours_date').val('');
                $('#special_hours_sales_start').prop('selectedIndex', 0);
                $('#special_hours_sales_end').prop('selectedIndex', 0);
                $('#special_hours_service_start').prop('selectedIndex', 0);
                $('#special_hours_service_end').prop('selectedIndex', 0);
                $('#special_hours_parts_start').prop('selectedIndex', 0);
                $('#special_hours_parts_end').prop('selectedIndex', 0);
                $('#special_hours_sales_closed').prop('checked', false);
                $('#special_hours_service_closed').prop('checked', false);
                $('#special_hours_parts_closed').prop('checked', false);
                updateClosedState('sales');
                updateClosedState('service');
                updateClosedState('parts');
                $('#editing_index').val('');
                $('#form-title').text('Add New Special Hours');
                $('#cancel-edit-special-hours').hide();
              }

              function renderSpecialHours() {
                const container = $('#special-hours-items');
                container.empty();

                if (specialHours.length === 0) {
                  container.html('<p style="color: #666; font-style: italic;">No special hours added yet.</p>');
                  return;
                }

                specialHours.forEach((item, index) => {
                  const card = $('<div>', {
                    class: 'special-hours-card',
                    style: 'background: white; border: 1px solid #ddd; border-radius: 5px; padding: 15px; margin-bottom: 10px;'
                  });

                  const salesHours = item.sales_closed ? '<span style="color: #999;">Closed</span>' : `${item.sales_start || 'N/A'} - ${item.sales_end || 'N/A'}`;
                  const serviceHours = item.service_closed ? '<span style="color: #999;">Closed</span>' : `${item.service_start || 'N/A'} - ${item.service_end || 'N/A'}`;
                  const partsHours = item.parts_closed ? '<span style="color: #999;">Closed</span>' : `${item.parts_start || 'N/A'} - ${item.parts_end || 'N/A'}`;

                  card.html(`
                    <div style="display: flex; justify-content: space-between; align-items: start;">
                      <div style="flex: 1;">
                        <h4 style="margin: 0 0 10px 0; color: #2271b1;">${item.label}</h4>
                        <p style="margin: 5px 0;"><strong>Date:</strong> ${item.date || 'N/A'}</p>
                        <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-top: 10px;">
                          <div>
                            <strong>Sales:</strong><br>
                            ${salesHours}
                          </div>
                          <div>
                            <strong>Service:</strong><br>
                            ${serviceHours}
                          </div>
                          <div>
                            <strong>Parts:</strong><br>
                            ${partsHours}
                          </div>
                        </div>
                      </div>
                      <div style="display: flex; flex-direction: column; gap: 5px; margin-left: 15px;">
                        <button type="button" class="button edit-special-hours" data-index="${index}" style="background: #2271b1; color: white; border: none;">Edit</button>
                        <button type="button" class="button delete-special-hours" data-index="${index}" style="background: #dc3232; color: white; border: none;">Delete</button>
                      </div>
                    </div>
                  `);

                  container.append(card);
                });
              }

              $('#save-special-hours').on('click', function() {
                const label = $('#special_hours_label').val().trim();
                const date = $('#special_hours_date').val();
                const editingIndex = $('#editing_index').val();

                const salesClosed = $('#special_hours_sales_closed').is(':checked');
                const serviceClosed = $('#special_hours_service_closed').is(':checked');
                const partsClosed = $('#special_hours_parts_closed').is(':checked');

                if (!label) {
                  alert('Please enter a label for the special hours.');
                  return;
                }

                const specialHoursEntry = {
                  label: label,
                  date: date,
                  sales_closed: salesClosed,
                  sales_start: salesClosed ? '' : $('#special_hours_sales_start').val(),
                  sales_end: salesClosed ? '' : $('#special_hours_sales_end').val(),
                  service_closed: serviceClosed,
                  service_start: serviceClosed ? '' : $('#special_hours_service_start').val(),
                  service_end: serviceClosed ? '' : $('#special_hours_service_end').val(),
                  parts_closed: partsClosed,
                  parts_start: partsClosed ? '' : $('#special_hours_parts_start').val(),
                  parts_end: partsClosed ? '' : $('#special_hours_parts_end').val()
                };

                if (editingIndex !== '') {
                  // Update existing entry
                  specialHours[parseInt(editingIndex)] = specialHoursEntry;
                } else {
                  // Add new entry
                  specialHours.push(specialHoursEntry);
                }

                $('#special_hours_data').val(JSON.stringify(specialHours));
                clearForm();
                renderSpecialHours();
              });

              $(document).on('click', '.edit-special-hours', function() {
                const index = $(this).data('index');
                const item = specialHours[index];

                $('#special_hours_label').val(item.label);
                $('#special_hours_date').val(item.date || '');

                $('#special_hours_sales_closed').prop('checked', item.sales_closed || false);
                $('#special_hours_service_closed').prop('checked', item.service_closed || false);
                $('#special_hours_parts_closed').prop('checked', item.parts_closed || false);

                if (!item.sales_closed) {
                  $('#special_hours_sales_start').val(item.sales_start || '');
                  $('#special_hours_sales_end').val(item.sales_end || '');
                }
                if (!item.service_closed) {
                  $('#special_hours_service_start').val(item.service_start || '');
                  $('#special_hours_service_end').val(item.service_end || '');
                }
                if (!item.parts_closed) {
                  $('#special_hours_parts_start').val(item.parts_start || '');
                  $('#special_hours_parts_end').val(item.parts_end || '');
                }

                updateClosedState('sales');
                updateClosedState('service');
                updateClosedState('parts');

                $('#editing_index').val(index);
                $('#form-title').text('Edit Special Hours');
                $('#cancel-edit-special-hours').show();

                $('html, body').animate({
                  scrollTop: $('#special-hours-form').offset().top - 100
                }, 500);
              });

              $('#cancel-edit-special-hours').on('click', function() {
                clearForm();
              });

              $(document).on('click', '.delete-special-hours', function() {
                const index = $(this).data('index');
                if (confirm('Are you sure you want to delete this special hours entry?')) {
                  specialHours.splice(index, 1);
                  $('#special_hours_data').val(JSON.stringify(specialHours));
                  renderSpecialHours();
                }
              });

              // Initialize
              updateClosedState('sales');
              updateClosedState('service');
              updateClosedState('parts');
              renderSpecialHours();
            });
            </script>

            <style>
            .special-hours-card {
              transition: box-shadow 0.2s;
            }
            .special-hours-card:hover {
              box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            }
            .edit-special-hours:hover {
              background: #135e96 !important;
            }
            .delete-special-hours:hover {
              background: #a00 !important;
            }
            </style>
          <?php
  }
  //Additional3 Hours----END

  public function hours_disclaimer_callback()
  {
    echo 'Status: <select id="hour_disclaimer_status" name="dealer-settings-hours-options[hour_disclaimer_status]">';
    if (strtolower($this->hours_options['hour_disclaimer_status']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->hours_options['hour_disclaimer_status']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select><br/><br/>';

    echo 'Disclaimer:';
    wp_editor(
      isset($this->hours_options['disclaimer']) ? ($this->hours_options['disclaimer']) : '',
      'disclaimer',
      ['textarea_name' => "dealer-settings-hours-options[disclaimer]"]
    );
  }

  public function create_labels_page()
  {
    // Set class property
    $this->labels_options = get_option('dealer-settings-labels-options');
    ?>
            <div class="wrap">
            <style>
							table {
								width: 54% !important;
								max-width: 732px; /* Máximo ancho de 732px */
							}
							/* Ocultar los th vacíos */
							th:empty {
								display: none;
							}

							tr:first-of-type td {
								padding: 0 !important;
							}
							tr:nth-child(n+2) {
								display: inline;
								max-width:50%;
							}

							td {
								flex: 1 1 33%;
								box-sizing: border-box;
								padding: 5px;
							}
							/* Ajustes para diseño en pantalla pequeña */

              @media (max-width: 1340px) {
                tr td div img  {
								display: none;
								}
                table {
                  width: 100% !important;
                }

              }

							@media (max-width: 900px) {
								td {
									flex: 1 1 100%; /* Colocar en una sola columna en pantallas pequeñas */
								}
                tr:first-of-type  {
								display: none;
								}

								table {
									width: 100% !important;
								}
							}
							.language-div {
								display: flex;
								width: 52%;
								justify-content: flex-end;
							}
							.language-title {
								display: inline;
								width: 33%;
								text-align: center;
							}
            </style>

              <h1>Labels</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-labels-options-group');
                do_settings_sections('dealer-settings-languages');
                do_settings_sections('dealer-settings-labels');
                do_settings_sections('dealer-settings-tag-labels');
                do_settings_sections('dealer-settings-phones');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  public function create_my_garage_page()
  {
    // Set class property
    $this->my_garage_options = get_option('dealer-settings-my-garage-options');
    ?>
            <div class="wrap">
              <h1>My Garage</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-my-garage-options-group');
                do_settings_sections('dealer-settings-my-garage');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Register and add settings
   */
  public function register_labels_settings()
  {
    register_setting(
      'dealer-settings-labels-options-group',
      'dealer-settings-labels-options',
      array($this, 'sanitize')
    );
  }

  public function register_my_garage_settings()
  {
    register_setting(
      'dealer-settings-my-garage-options-group',
      'dealer-settings-my-garage-options',
      array($this, 'sanitize')
    );
  }

  public function calculated_msrp_callback()
  {
    printf(
      '<input type="text" id="calculated_msrp" name="dealer-settings-labels-options[calculated_msrp]" value="%s" />',
      isset($this->labels_options['calculated_msrp']) ? esc_attr($this->labels_options['calculated_msrp']) : ''
    );
  }

  public function calculated_msrp_callback_fr()
  {
    printf(
      '<input type="text" id="calculated_msrp_fr" name="dealer-settings-labels-options[calculated_msrp_fr]" value="%s" />',
      isset($this->labels_options['calculated_msrp_fr']) ? esc_attr($this->labels_options['calculated_msrp_fr']) : ''
    );
  }

  public function additional_rebates_label_callback()
  {
    printf(
      '<input type="text" id="additional_rebates_label" name="dealer-settings-labels-options[additional_rebates_label]" value="%s" />',
      isset($this->labels_options['additional_rebates_label']) ? esc_attr($this->labels_options['additional_rebates_label']) : ''
    );
  }

  public function additional_rebates_label_fr_callback()
  {
    printf(
      '<input type="text" id="additional_rebates_label_fr" name="dealer-settings-labels-options[additional_rebates_label_fr]" value="%s" />',
      isset($this->labels_options['additional_rebates_label_fr']) ? esc_attr($this->labels_options['additional_rebates_label_fr']) : ''
    );
  }

  public function rebates_label_callback()
  {
    printf(
      '<input type="text" id="rebates_label" name="dealer-settings-labels-options[rebates_label]" value="%s" />',
      isset($this->labels_options['rebates_label']) ? esc_attr($this->labels_options['rebates_label']) : ''
    );
  }

  public function rebates_label_fr_callback()
  {
    printf(
      '<input type="text" id="rebates_label_fr" name="dealer-settings-labels-options[rebates_label_fr]" value="%s" />',
      isset($this->labels_options['rebates_label_fr']) ? esc_attr($this->labels_options['rebates_label_fr']) : ''
    );
  }

  public function tax_and_lic_label_callback()
  {
    printf(
      '<input type="text" id="tax_and_lic_label" name="dealer-settings-labels-options[tax_and_lic_label]" value="%s" />',
      isset($this->labels_options['tax_and_lic_label']) ? esc_attr($this->labels_options['tax_and_lic_label']) : ''
    );
  }

  public function tax_and_lic_label_fr_callback()
  {
    printf(
      '<input type="text" id="tax_and_lic_label_fr" name="dealer-settings-labels-options[tax_and_lic_label_fr]" value="%s" />',
      isset($this->labels_options['tax_and_lic_label_fr']) ? esc_attr($this->labels_options['tax_and_lic_label_fr']) : ''
    );
  }

  public function used_tax_and_lic_label_callback()
  {
    printf(
      '<input type="text" id="used_tax_and_lic_label" name="dealer-settings-labels-options[used_tax_and_lic_label]" value="%s" />',
      isset($this->labels_options['used_tax_and_lic_label']) ? esc_attr($this->labels_options['used_tax_and_lic_label']) : ''
    );
  }

  public function used_tax_and_lic_label_fr_callback()
  {
    printf(
      '<input type="text" id="used_tax_and_lic_label_fr" name="dealer-settings-labels-options[used_tax_and_lic_label_fr]" value="%s" />',
      isset($this->labels_options['used_tax_and_lic_label_fr']) ? esc_attr($this->labels_options['used_tax_and_lic_label_fr']) : ''
    );
  }

  //aqui toy
  public function new_tax_label_callback()
  {
    printf(
      '<input type="text" id="new_tax_label" name="dealer-settings-labels-options[new_tax_label]" value="%s" />',
      isset($this->labels_options['new_tax_label']) ? esc_attr($this->labels_options['new_tax_label']) : ''
    );
  }

  public function new_tax_label_fr_callback()
  {
    printf(
      '<input type="text" id="new_tax_label_fr" name="dealer-settings-labels-options[new_tax_label_fr]" value="%s" />',
      isset($this->labels_options['new_tax_label_fr']) ? esc_attr($this->labels_options['new_tax_label_fr']) : ''
    );
  }

  public function used_tax_label_callback()
  {
    printf(
      '<input type="text" id="used_tax_label" name="dealer-settings-labels-options[used_tax_label]" value="%s" />',
      isset($this->labels_options['used_tax_label']) ? esc_attr($this->labels_options['used_tax_label']) : ''
    );
  }

  public function used_tax_label_fr_callback()
  {
    printf(
      '<input type="text" id="used_tax_label_fr" name="dealer-settings-labels-options[used_tax_label_fr]" value="%s" />',
      isset($this->labels_options['used_tax_label_fr']) ? esc_attr($this->labels_options['used_tax_label_fr']) : ''
    );
  }

  //lic

  public function new_lic_label_callback()
  {
    printf(
      '<input type="text" id="new_lic_label" name="dealer-settings-labels-options[new_lic_label]" value="%s" />',
      isset($this->labels_options['new_lic_label']) ? esc_attr($this->labels_options['new_lic_label']) : ''
    );
  }

  public function new_lic_label_fr_callback()
  {
    printf(
      '<input type="text" id="new_lic_label_fr" name="dealer-settings-labels-options[new_lic_label_fr]" value="%s" />',
      isset($this->labels_options['new_lic_label_fr']) ? esc_attr($this->labels_options['new_lic_label_fr']) : ''
    );
  }

  public function used_lic_label_callback()
  {
    printf(
      '<input type="text" id="used_lic_label" name="dealer-settings-labels-options[used_lic_label]" value="%s" />',
      isset($this->labels_options['used_lic_label']) ? esc_attr($this->labels_options['used_lic_label']) : ''
    );
  }

  public function used_lic_label_fr_callback()
  {
    printf(
      '<input type="text" id="used_lic_label_fr" name="dealer-settings-labels-options[used_lic_label_fr]" value="%s" />',
      isset($this->labels_options['used_lic_label_fr']) ? esc_attr($this->labels_options['used_lic_label_fr']) : ''
    );
  }


	//! demo tag

  public function demo_tag_label_callback()
  {
    printf(
      '<input type="text" id="demo_tag_label" name="dealer-settings-labels-options[demo_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['demo_tag_label']) ? esc_attr($this->labels_options['demo_tag_label']) : ''
    );
  }

  public function demo_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="demo_tag_label_fr" name="dealer-settings-labels-options[demo_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['demo_tag_label_fr']) ? esc_attr($this->labels_options['demo_tag_label_fr']) : ''
    );
  }

	//* added color and character limit input(demo tag)

	public function demo_tag_label_color_callback()
  {
    printf(
      '<input type="color" id="demo_tag_label_color" name="dealer-settings-labels-options[demo_tag_label_color]" value="%s" />',
      isset($this->labels_options['demo_tag_label_color']) ? esc_attr($this->labels_options['demo_tag_label_color']) : ''
    );
  }
	public function demo_tag_label_limit_callback()
  {
    printf(
      '<input type="number" min="5" max="12" style="width: 170px;" placeholder="limit characters" id="demo_tag_label_limit" name="dealer-settings-labels-options[demo_tag_label_limit]" value="%s" />',
      isset($this->labels_options['demo_tag_label_limit']) ? esc_attr($this->labels_options['demo_tag_label_limit']) : ''
    );
  }

	//! salepending tag

  public function salepending_tag_label_callback()
  {
    printf(
      '<input type="text" id="salepending_tag_label" name="dealer-settings-labels-options[salepending_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['salepending_tag_label']) ? esc_attr($this->labels_options['salepending_tag_label']) : ''
    );
  }

  public function salepending_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="salepending_tag_label_fr" name="dealer-settings-labels-options[salepending_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['salepending_tag_label_fr']) ? esc_attr($this->labels_options['salepending_tag_label_fr']) : ''
    );
  }
	//* added color and character limit input(salepending tag)

	public function salepending_tag_label_color_callback()
  {
    printf(
      '<input type="color" id="salepending_tag_label_color" name="dealer-settings-labels-options[salepending_tag_label_color]" value="%s" />',
      isset($this->labels_options['salepending_tag_label_color']) ? esc_attr($this->labels_options['salepending_tag_label_color']) : ''
    );
  }
	public function salepending_tag_label_limit_callback()
  {
    printf(
      '<input type="number" min="5" max="12" style="width: 170px;" placeholder="limit characters" id="salepending_tag_label_limit" name="dealer-settings-labels-options[salepending_tag_label_limit]" value="%s" />',
      isset($this->labels_options['salepending_tag_label_limit']) ? esc_attr($this->labels_options['salepending_tag_label_limit']) : ''
    );
  }

	//! certified tag

  public function certified_tag_label_callback()
  {
    printf(
      '<input type="text" id="certified_tag_label" name="dealer-settings-labels-options[certified_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['certified_tag_label']) ? esc_attr($this->labels_options['certified_tag_label']) : ''
    );
  }

  public function certified_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="certified_tag_label_fr" name="dealer-settings-labels-options[certified_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['certified_tag_label_fr']) ? esc_attr($this->labels_options['certified_tag_label_fr']) : ''
    );
  }

	//* added color and character limit input(certified tag)

	public function certified_tag_label_color_callback()
  {
    printf(
      '<input type="color" id="certified_tag_label_color" name="dealer-settings-labels-options[certified_tag_label_color]" value="%s" />',
      isset($this->labels_options['certified_tag_label_color']) ? esc_attr($this->labels_options['certified_tag_label_color']) : ''
    );
  }
	public function certified_tag_label_limit_callback()
  {
    printf(
      '<input type="number" min="5" max="12" style="width: 170px;" placeholder="limit characters" id="certified_tag_label_limit" name="dealer-settings-labels-options[certified_tag_label_limit]" value="%s" />',
      isset($this->labels_options['certified_tag_label_limit']) ? esc_attr($this->labels_options['certified_tag_label_limit']) : ''
    );
  }

	//! special tag

  public function special_tag_label_callback()
  {
    printf(
      '<input type="text" id="special_tag_label" name="dealer-settings-labels-options[special_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['special_tag_label']) ? esc_attr($this->labels_options['special_tag_label']) : ''
    );
  }

  public function special_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="special_tag_label_fr" name="dealer-settings-labels-options[special_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['special_tag_label_fr']) ? esc_attr($this->labels_options['special_tag_label_fr']) : ''
    );
  }

	//* added color and character limit input(special tag)

	public function special_tag_label_color_callback()
  {
    printf(
      '<input type="color" id="special_tag_label_color" name="dealer-settings-labels-options[special_tag_label_color]" value="%s" />',
      isset($this->labels_options['special_tag_label_color']) ? esc_attr($this->labels_options['special_tag_label_color']) : ''
    );
  }
	public function special_tag_label_limit_callback()
  {
    printf(
      '<input type="number" min="5" max="12" placeholder="limit characters" id="special_tag_label_limit" name="dealer-settings-labels-options[special_tag_label_limit]" value="%s" style="width: 170px;" />',
      isset($this->labels_options['special_tag_label_limit']) ? esc_attr($this->labels_options['special_tag_label_limit']) : ''
    );
  }

	//! asis tag

  public function asis_tag_label_callback()
  {
    printf(
      '<input type="text" id="asis_tag_label" name="dealer-settings-labels-options[asis_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['asis_tag_label']) ? esc_attr($this->labels_options['asis_tag_label']) : ''
    );
  }

  public function asis_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="asis_tag_label_fr" name="dealer-settings-labels-options[asis_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['asis_tag_label_fr']) ? esc_attr($this->labels_options['asis_tag_label_fr']) : ''
    );
  }

		//* added color and character limit input(asis tag)

		public function asis_tag_label_color_callback()
		{
			printf(
				'<input type="color" id="asis_tag_label_color" name="dealer-settings-labels-options[asis_tag_label_color]" value="%s" />',
				isset($this->labels_options['asis_tag_label_color']) ? esc_attr($this->labels_options['asis_tag_label_color']) : ''
			);
		}
		public function asis_tag_label_limit_callback()
		{
			printf(
				'<input type="number" min="5" max="12" style="width: 170px;" placeholder="limit characters" id="asis_tag_label_limit" name="dealer-settings-labels-options[asis_tag_label_limit]" value="%s" />',
				isset($this->labels_options['asis_tag_label_limit']) ? esc_attr($this->labels_options['asis_tag_label_limit']) : ''
			);
		}

	//! incoming tag

  public function incoming_tag_label_callback()
  {
    printf(
      '<input type="text" id="incoming_tag_label" name="dealer-settings-labels-options[incoming_tag_label]" value="%s" maxlength="13" />',
      isset($this->labels_options['incoming_tag_label']) ? esc_attr($this->labels_options['incoming_tag_label']) : ''
    );
  }

  public function incoming_tag_label_fr_callback()
  {
    printf(
      '<input type="text" id="incoming_tag_label_fr" name="dealer-settings-labels-options[incoming_tag_label_fr]" value="%s" maxlength="13" />',
      isset($this->labels_options['incoming_tag_label_fr']) ? esc_attr($this->labels_options['incoming_tag_label_fr']) : ''
    );
  }

	//* added color and character limit input(incoming tag)

	public function incoming_tag_label_color_callback()
	{
		printf(
			'<input type="color" id="incoming_tag_label_color" name="dealer-settings-labels-options[incoming_tag_label_color]" value="%s" />',
			isset($this->labels_options['incoming_tag_label_color']) ? esc_attr($this->labels_options['incoming_tag_label_color']) : ''
		);
	}
	public function incoming_tag_label_limit_callback()
	{
		printf(
			'<input type="number" min="5" max="12" style="width: 170px;" placeholder="limit characters" id="incoming_tag_label_limit" name="dealer-settings-labels-options[incoming_tag_label_limit]" value="%s" />',
			isset($this->labels_options['incoming_tag_label_limit']) ? esc_attr($this->labels_options['incoming_tag_label_limit']) : ''
		);
	}


	/*<<<< PHONE SECCION >>>>*/

  public function phone_sales_label_callback()
  {
    printf(
      '<input type="text" id="phone_sales_label" name="dealer-settings-labels-options[phone_sales_label]" value="%s" />',
      isset($this->labels_options['phone_sales_label']) ? esc_attr($this->labels_options['phone_sales_label']) : ''
    );
  }

  public function phone_sales_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_sales_label_fr" name="dealer-settings-labels-options[phone_sales_label_fr]" value="%s" />',
      isset($this->labels_options['phone_sales_label_fr']) ? esc_attr($this->labels_options['phone_sales_label_fr']) : ''
    );
  }

  public function phone_parts_label_callback()
  {
    printf(
      '<input type="text" id="phone_parts_label" name="dealer-settings-labels-options[phone_parts_label]" value="%s" />',
      isset($this->labels_options['phone_parts_label']) ? esc_attr($this->labels_options['phone_parts_label']) : ''
    );
  }

  public function phone_parts_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_parts_label_fr" name="dealer-settings-labels-options[phone_parts_label_fr]" value="%s" />',
      isset($this->labels_options['phone_parts_label_fr']) ? esc_attr($this->labels_options['phone_parts_label_fr']) : ''
    );
  }

  public function phone_service_label_callback()
  {
    printf(
      '<input type="text" id="phone_service_label" name="dealer-settings-labels-options[phone_service_label]" value="%s" />',
      isset($this->labels_options['phone_service_label']) ? esc_attr($this->labels_options['phone_service_label']) : ''
    );
  }

  public function phone_service_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_service_label_fr" name="dealer-settings-labels-options[phone_service_label_fr]" value="%s" />',
      isset($this->labels_options['phone_service_label_fr']) ? esc_attr($this->labels_options['phone_service_label_fr']) : ''
    );
  }

  public function phone_fax_label_callback()
  {
    printf(
      '<input type="text" id="phone_fax_label" name="dealer-settings-labels-options[phone_fax_label]" value="%s" />',
      isset($this->labels_options['phone_fax_label']) ? esc_attr($this->labels_options['phone_fax_label']) : ''
    );
  }

  public function phone_fax_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_fax_label_fr" name="dealer-settings-labels-options[phone_fax_label_fr]" value="%s" />',
      isset($this->labels_options['phone_fax_label_fr']) ? esc_attr($this->labels_options['phone_fax_label_fr']) : ''
    );
  }

  public function phone_body_shop_label_callback()
  {
    printf(
      '<input type="text" id="phone_body_shop_label" name="dealer-settings-labels-options[phone_body_shop_label]" value="%s" />',
      isset($this->labels_options['phone_body_shop_label']) ? esc_attr($this->labels_options['phone_body_shop_label']) : ''
    );
  }

  public function phone_body_shop_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_body_shop_label_fr" name="dealer-settings-labels-options[phone_body_shop_label_fr]" value="%s" />',
      isset($this->labels_options['phone_body_shop_label_fr']) ? esc_attr($this->labels_options['phone_body_shop_label_fr']) : ''
    );
  }

  public function phone_collision_label_callback()
  {
    printf(
      '<input type="text" id="phone_collision_label" name="dealer-settings-labels-options[phone_collision_label]" value="%s" />',
      isset($this->labels_options['phone_collision_label']) ? esc_attr($this->labels_options['phone_collision_label']) : ''
    );
  }

  public function phone_collision_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_collision_label_fr" name="dealer-settings-labels-options[phone_collision_label_fr]" value="%s" />',
      isset($this->labels_options['phone_collision_label_fr']) ? esc_attr($this->labels_options['phone_collision_label_fr']) : ''
    );
  }

  public function phone_accessories_label_callback()
  {
    printf(
      '<input type="text" id="phone_accessories_label" name="dealer-settings-labels-options[phone_accessories_label]" value="%s" />',
      isset($this->labels_options['phone_accessories_label']) ? esc_attr($this->labels_options['phone_accessories_label']) : ''
    );
  }

  public function phone_accessories_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_accessories_label_fr" name="dealer-settings-labels-options[phone_accessories_label_fr]" value="%s" />',
      isset($this->labels_options['phone_accessories_label_fr']) ? esc_attr($this->labels_options['phone_accessories_label_fr']) : ''
    );
  }

  public function phone_sms_label_callback()
  {
    printf(
      '<input type="text" id="phone_sms_label" name="dealer-settings-labels-options[phone_sms_label]" value="%s" />',
      isset($this->labels_options['phone_sms_label']) ? esc_attr($this->labels_options['phone_sms_label']) : ''
    );
  }

  public function phone_sms_label_fr_callback()
  {
    printf(
      '<input type="text" id="phone_sms_label_fr" name="dealer-settings-labels-options[phone_sms_label_fr]" value="%s" />',
      isset($this->labels_options['phone_sms_label_fr']) ? esc_attr($this->labels_options['phone_sms_label_fr']) : ''
    );
  }

  public function special_price_callback()
  {
    printf(
      '<input type="text" id="special_price" name="dealer-settings-labels-options[special_price]" value="%s" />',
      isset($this->labels_options['special_price']) ? esc_attr($this->labels_options['special_price']) : ''
    );
  }

  public function special_price_fr_callback()
  {
    printf(
      '<input type="text" id="special_price_fr" name="dealer-settings-labels-options[special_price_fr]" value="%s" />',
      isset($this->labels_options['special_price_fr']) ? esc_attr($this->labels_options['special_price_fr']) : ''
    );
  }

  public function special_discount_price_callback()
  {
    printf(
      '<input type="text" id="special_discount_price" name="dealer-settings-labels-options[special_discount_price]" value="%s" />',
      isset($this->labels_options['special_discount_price']) ? esc_attr($this->labels_options['special_discount_price']) : ''
    );
  }

  public function special_discount_price_fr_callback()
  {
    printf(
      '<input type="text" id="special_discount_price_fr" name="dealer-settings-labels-options[special_discount_price_fr]" value="%s" />',
      isset($this->labels_options['special_discount_price_fr']) ? esc_attr($this->labels_options['special_discount_price_fr']) : ''
    );
  }

  public function after_discount_price_callback()
  {
    printf(
      '<input type="text" id="after_discount_price" name="dealer-settings-labels-options[after_discount_price]" value="%s" />',
      isset($this->labels_options['after_discount_price']) ? esc_attr($this->labels_options['after_discount_price']) : ''
    );
  }

   public function used_after_discount_price_callback()
  {
    printf(
      '<input type="text" id="used_after_discount_price" name="dealer-settings-labels-options[used_after_discount_price]" value="%s" />',
      isset($this->labels_options['used_after_discount_price']) ? esc_attr($this->labels_options['used_after_discount_price']) : ''
    );
  }

  public function after_discount_price_fr_callback()
  {
    printf(
      '<input type="text" id="after_discount_price_fr" name="dealer-settings-labels-options[after_discount_price_fr]" value="%s" />',
      isset($this->labels_options['after_discount_price_fr']) ? esc_attr($this->labels_options['after_discount_price_fr']) : ''
    );
  }

  public function used_after_discount_price_fr_callback()
  {
    printf(
      '<input type="text" id="used_after_discount_price_fr" name="dealer-settings-labels-options[used_after_discount_price_fr]" value="%s" />',
      isset($this->labels_options['used_after_discount_price_fr']) ? esc_attr($this->labels_options['used_after_discount_price_fr']) : ''
    );
  }

  public function used_vehicle_price_label_callback()
  {
    printf(
      '<input type="text" id="used_vehicle_price" name="dealer-settings-labels-options[used_vehicle_price]" value="%s" />',
      isset($this->labels_options['used_vehicle_price']) ? esc_attr($this->labels_options['used_vehicle_price']) : ''
    );
  }

  public function used_vehicle_price_label_fr_callback()
  {
    printf(
      '<input type="text" id="used_vehicle_price_fr" name="dealer-settings-labels-options[used_vehicle_price_fr]" value="%s" />',
      isset($this->labels_options['used_vehicle_price_fr']) ? esc_attr($this->labels_options['used_vehicle_price_fr']) : ''
    );
  }

  public function new_vehicle_price_label_callback()
  {
    printf(
      '<input type="text" id="new_vehicle_price" name="dealer-settings-labels-options[new_vehicle_price]" value="%s" />',
      isset($this->labels_options['new_vehicle_price']) ? esc_attr($this->labels_options['new_vehicle_price']) : ''
    );
  }

  public function new_vehicle_price_label_fr_callback()
  {
    printf(
      '<input type="text" id="new_vehicle_price_fr" name="dealer-settings-labels-options[new_vehicle_price_fr]" value="%s" />',
      isset($this->labels_options['new_vehicle_price_fr']) ? esc_attr($this->labels_options['new_vehicle_price_fr']) : ''
    );
  }

  public function my_garage_option_callback()
  {
    if (!isset($this->my_garage_options['my_garage_status'])) {
      $this->my_garage_options['my_garage_status'] = "Disabled";
    }

    echo '<select id="my_garage" name="dealer-settings-my-garage-options[my_garage_status]">';
    if (strtolower($this->my_garage_options['my_garage_status']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->my_garage_options['my_garage_status']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }
	/**
   * Options page callback
   */
  public function create_listing_image_page()
  {
    // LBT-1462: repeatable list of inventory-insert images. UI styled to match
    // the LBX Slider admin (design tokens + .lbx-* components).
    ?>
    <div class="wrap lbx-admin lbx-listing-admin">
      <div class="lbx-header">
        <div class="lbx-header-left">
          <div class="lbx-header-icon"><span class="dashicons dashicons-images-alt2"></span></div>
          <div>
            <h1>LBX Listing Images</h1>
            <p>Insert promotional images between the SRP vehicle cards, each with its own link and position.</p>
          </div>
        </div>
      </div>

      <div id="lbx-listing-notices"></div>
      <div id="response-message"></div>

      <?php
      // LBT-1462 Round 3: this page is now the Image Groups manager ONLY. The legacy
      // "Global" config UI (Round 2) has been retired — its markup below is wrapped in
      // `if (false)` so it never runs or renders, while the shared .lbx-* <style> after
      // it still styles the groups manager. (Round 2 methods stay defined but unused.)
      if (class_exists('LBX_Listing_Image_Groups')) {
        LBX_Listing_Image_Groups::instance()->render_manager();
      } else {
        echo '<div class="lbx-empty"><p>Image Groups module unavailable.</p></div>';
      }
      ?>
    </div>

    <?php if (false) : // legacy global config UI (retired) ?>
      <?php $cfg = $this->get_listing_images_config_admin(); ?>
      <div class="lbx-card">
        <div class="lbx-card-header"><h2><span class="dashicons dashicons-randomize"></span> Placement Mode</h2></div>
        <div class="lbx-card-body">
          <div class="lbx-field">
            <label class="lbx-label">Mode</label>
            <label class="lbx-radio" style="display:block;margin:4px 0;"><input type="radio" name="li_mode" value="grouped" <?php checked($cfg['mode'], 'grouped'); ?>> <strong>Grouped</strong> — all images cycle one after another (A B C A B C…) every <em>offset</em> cards</label>
            <label class="lbx-radio" style="display:block;margin:4px 0;"><input type="radio" name="li_mode" value="individual" <?php checked($cfg['mode'], 'individual'); ?>> <strong>Individual</strong> — each image uses its own Insert After / Repeat Every</label>
          </div>
          <div class="lbx-panel-grid li-group-fields"<?php if ($cfg['mode'] !== 'grouped') echo ' style="display:none;"'; ?>>
            <div class="lbx-field"><label class="lbx-label">Offset <span class="lbx-label-hint">cards between images</span></label><input type="number" min="1" id="li_group_offset" class="lbx-input" value="<?php echo esc_attr($cfg['offset']); ?>"></div>
            <div class="lbx-field"><label class="lbx-label">Repeat <span class="lbx-label-hint">full cycles, 0 = until end</span></label><input type="number" min="0" id="li_group_repeat" class="lbx-input" value="<?php echo esc_attr($cfg['repeat']); ?>"></div>
          </div>
        </div>
        <div class="lbx-card-footer">
          <button id="save-listing-config" type="button" class="lbx-btn lbx-btn-primary"><span class="dashicons dashicons-saved"></span> Save Placement</button>
        </div>
      </div>

      <div class="lbx-card">
        <div class="lbx-card-header"><h2><span class="dashicons dashicons-plus-alt2"></span> Add New Image</h2></div>
        <div class="lbx-card-body">
          <div class="lbx-field">
            <label class="lbx-label">Image <span class="lbx-req-star">*</span></label>
            <div class="lbx-slide-image lbx-pick-image" id="li_image_preview">
              <div class="lbx-slide-image-ph"><span class="dashicons dashicons-cloud-upload"></span><span>Click to upload</span></div>
            </div>
            <input type="hidden" id="li_image" value="">
          </div>

          <div class="lbx-panel-grid">
            <div class="lbx-field"><label class="lbx-label">Link</label><input type="text" id="li_link" class="lbx-input" placeholder="https://... or /specials"></div>
            <div class="lbx-field"><label class="lbx-label">Open in</label><?php echo $this->listing_image_select_html('li_target', 'target', '_self'); ?></div>
            <div class="lbx-field li-position-field"><label class="lbx-label">Insert After <span class="lbx-label-hint">card #</span></label><input type="number" min="0" id="li_insert_after" class="lbx-input" value="0"></div>
            <div class="lbx-field li-position-field"><label class="lbx-label">Repeat Every <span class="lbx-label-hint">0 = once</span></label><input type="number" min="0" id="li_repeat_every" class="lbx-input" value="0"></div>
            <div class="lbx-field"><label class="lbx-label">Condition</label><?php echo $this->listing_image_select_html('li_condition', 'condition', 'both'); ?></div>
            <div class="lbx-field"><label class="lbx-label">Language</label><?php echo $this->listing_image_select_html('li_language', 'language', 'both'); ?></div>
            <div class="lbx-field"><label class="lbx-label">Image Fit</label><?php echo $this->listing_image_select_html('li_fit', 'fit', 'contain'); ?></div>
            <div class="lbx-field"><label class="lbx-label">Limit Date</label><input type="date" id="li_limit_date" class="lbx-input"></div>
            <div class="lbx-field"><label class="lbx-label">Alt Text <span class="lbx-label-hint">accessibility</span></label><input type="text" id="li_alt" class="lbx-input"></div>
          </div>

          <label class="lbx-toggle"><input type="checkbox" id="li_activate" value="1"><span class="lbx-toggle-track"></span><span class="lbx-toggle-label">Expire on limit date</span></label>
        </div>
        <div class="lbx-card-footer">
          <button id="save-listing-image" name="save-listing-image" type="button" class="lbx-btn lbx-btn-primary"><span class="dashicons dashicons-plus-alt2"></span> Add Image</button>
        </div>
      </div>

      <div class="lbx-card">
        <div class="lbx-card-header"><h2><span class="dashicons dashicons-list-view"></span> Configured Images</h2></div>
        <div class="lbx-card-body">
          <?php $this->display_listing_images_saved_data(); ?>
        </div>
      </div>
    <?php endif; // LBT-1462 R3: end retired legacy global config UI ?>

    <style>
      :root {
        --lbx-primary:#2563eb; --lbx-primary-hover:#1d4ed8; --lbx-primary-light:#eff6ff; --lbx-primary-lighter:#f8faff;
        --lbx-danger:#dc2626; --lbx-danger-bg:#fef2f2;
        --lbx-gray-50:#f9fafb; --lbx-gray-100:#f3f4f6; --lbx-gray-200:#e5e7eb; --lbx-gray-300:#d1d5db;
        --lbx-gray-400:#9ca3af; --lbx-gray-500:#6b7280; --lbx-gray-600:#4b5563; --lbx-gray-700:#374151;
        --lbx-gray-800:#1f2937; --lbx-gray-900:#111827;
        --lbx-radius:10px; --lbx-radius-sm:6px;
        --lbx-shadow:0 1px 3px rgba(0,0,0,0.08),0 1px 2px rgba(0,0,0,0.04);
        --lbx-shadow-md:0 4px 6px -1px rgba(0,0,0,0.07),0 2px 4px -2px rgba(0,0,0,0.05);
      }
      .lbx-admin { max-width:960px; font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; margin-right:16px; }
      .lbx-admin * { box-sizing:border-box; }
      .lbx-header { display:flex; align-items:center; justify-content:space-between; margin:16px 0; }
      .lbx-header-left { display:flex; align-items:center; gap:12px; }
      .lbx-header-icon { width:34px; height:34px; background:linear-gradient(135deg,var(--lbx-primary),#7c3aed); border-radius:10px; display:flex; align-items:center; justify-content:center; color:#fff; box-shadow:0 2px 8px rgba(37,99,235,0.22); }
      .lbx-header-icon .dashicons { color:#fff; }
      .lbx-header h1 { margin:0; font-size:18px; font-weight:700; color:var(--lbx-gray-900); letter-spacing:-0.01em; }
      .lbx-header p { margin:2px 0 0; font-size:12px; color:var(--lbx-gray-500); }

      .lbx-card { background:#fff; border:1px solid var(--lbx-gray-200); border-radius:var(--lbx-radius); box-shadow:var(--lbx-shadow); margin-bottom:24px; overflow:hidden; transition:box-shadow .2s; }
      .lbx-card:hover { box-shadow:var(--lbx-shadow-md); }
      .lbx-card-header { display:flex; align-items:center; justify-content:space-between; padding:16px 24px; border-bottom:1px solid var(--lbx-gray-100); background:var(--lbx-gray-50); }
      .lbx-card-header h2 { margin:0; font-size:16px; font-weight:700; color:var(--lbx-gray-900); display:flex; align-items:center; gap:8px; }
      .lbx-card-header h2 .dashicons { color:var(--lbx-primary); }
      .lbx-card-body { padding:24px; }
      .lbx-card-footer { padding:16px 24px; border-top:1px solid var(--lbx-gray-200); background:var(--lbx-gray-50); display:flex; align-items:center; gap:12px; }

      .lbx-panel-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; margin-bottom:14px; }
      .lbx-field { margin-bottom:16px; }
      .lbx-field:last-child { margin-bottom:0; }
      .lbx-label { display:block; font-size:13px; font-weight:600; color:var(--lbx-gray-700); margin-bottom:6px; }
      .lbx-mini-label { display:block; font-size:11px; font-weight:600; color:var(--lbx-gray-600); margin-bottom:4px; text-transform:uppercase; letter-spacing:.03em; }
      .lbx-label-hint { font-weight:400; color:var(--lbx-gray-400); font-size:12px; margin-left:4px; text-transform:none; letter-spacing:0; }
      .lbx-req-star { color:var(--lbx-danger); font-weight:700; margin-left:2px; }
      /* High-specificity + explicit type coverage so WP core's input[type=...]
         rules can't override height/padding — keeps every field the same size. */
      .lbx-admin input.lbx-input,
      .lbx-admin select.lbx-input,
      .lbx-admin textarea.lbx-input {
        display:block; width:100%; max-width:100%; margin:0; height:40px; min-height:40px; padding:0 12px;
        border:1px solid var(--lbx-gray-300); border-radius:8px; background-color:#fff;
        font-size:13px; line-height:1.4; color:var(--lbx-gray-800); vertical-align:middle;
        box-shadow:none; outline:none; transition:border-color .15s, box-shadow .15s;
      }
      .lbx-admin textarea.lbx-input { height:auto; min-height:80px; padding:10px 12px; line-height:1.5; resize:vertical; }
      .lbx-admin input.lbx-input:hover,
      .lbx-admin select.lbx-input:hover,
      .lbx-admin textarea.lbx-input:hover { border-color:var(--lbx-gray-400); }
      .lbx-admin input.lbx-input:focus,
      .lbx-admin select.lbx-input:focus,
      .lbx-admin textarea.lbx-input:focus { border-color:var(--lbx-primary); box-shadow:0 0 0 3px rgba(37,99,235,0.14); outline:none; }
      .lbx-admin input.lbx-input::placeholder { color:var(--lbx-gray-400); }
      .lbx-admin input.lbx-input[type="number"] { -moz-appearance:textfield; }
      /* Custom chevron so selects match the text inputs exactly */
      .lbx-admin select.lbx-input {
        -webkit-appearance:none; -moz-appearance:none; appearance:none; padding-right:34px; cursor:pointer;
        background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
        background-repeat:no-repeat; background-position:right 12px center; background-size:14px;
      }
      .lbx-admin select.lbx-input:hover,
      .lbx-admin select.lbx-input:focus {
        background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
      }

      .lbx-toggle { display:inline-flex; align-items:center; gap:10px; cursor:pointer; margin-top:4px; font-size:13px; color:var(--lbx-gray-700); }
      .lbx-toggle input { display:none; }
      .lbx-toggle-track { width:44px; height:24px; background:var(--lbx-gray-300); border-radius:12px; position:relative; transition:background .2s; flex:0 0 auto; }
      .lbx-toggle input:checked + .lbx-toggle-track { background:var(--lbx-primary); }
      .lbx-toggle-track::after { content:''; position:absolute; top:2px; left:2px; width:20px; height:20px; background:#fff; border-radius:50%; transition:transform .2s; box-shadow:0 1px 3px rgba(0,0,0,0.15); }
      .lbx-toggle input:checked + .lbx-toggle-track::after { transform:translateX(20px); }

      .lbx-btn { display:inline-flex; align-items:center; gap:6px; padding:10px 20px; border-radius:var(--lbx-radius-sm); font-size:13px; font-weight:600; cursor:pointer; transition:all .15s; border:none; outline:none; text-decoration:none; line-height:1; }
      .lbx-btn .dashicons { font-size:16px; width:16px; height:16px; }
      .lbx-btn-primary { background:linear-gradient(135deg,var(--lbx-primary),#1d4ed8); color:#fff; box-shadow:0 1px 3px rgba(37,99,235,0.3); }
      .lbx-btn-primary:hover { background:linear-gradient(135deg,var(--lbx-primary-hover),#1e40af); box-shadow:0 4px 12px rgba(37,99,235,0.35); color:#fff; }
      .lbx-btn-primary:active { transform:translateY(1px); }
      .lbx-btn-danger { background:transparent; color:var(--lbx-danger); border:1px solid var(--lbx-gray-200); }
      .lbx-btn-danger:hover { background:var(--lbx-danger-bg); border-color:#fecaca; }

      .lbx-slide-image { width:220px; height:120px; background:var(--lbx-gray-50); border:2px dashed var(--lbx-gray-300); border-radius:var(--lbx-radius-sm); display:flex; align-items:center; justify-content:center; cursor:pointer; overflow:hidden; position:relative; transition:all .15s; }
      .lbx-slide-image:hover { border-color:var(--lbx-primary); background:var(--lbx-primary-lighter); }
      .lbx-slide-image img { width:100%; height:100%; object-fit:cover; display:block; }
      .lbx-slide-image-ph { text-align:center; color:var(--lbx-gray-400); font-size:12px; }
      .lbx-slide-image-ph .dashicons { font-size:26px; width:26px; height:26px; display:block; margin:0 auto 4px; color:var(--lbx-gray-300); }

      .lbx-slide { background:#fff; border:1px solid var(--lbx-gray-200); border-radius:var(--lbx-radius); margin-bottom:12px; overflow:hidden; transition:box-shadow .2s, border-color .2s; }
      .lbx-slide:hover { box-shadow:var(--lbx-shadow-md); }
      .lbx-slide-header { display:flex; align-items:center; gap:12px; padding:12px 16px; background:var(--lbx-gray-50); border-bottom:1px solid var(--lbx-gray-100); cursor:pointer; user-select:none; }
      .lbx-slide--collapsed .lbx-slide-header { border-bottom-color:transparent; }
      .lbx-slide-select { display:inline-flex; margin:0; }
      .lbx-slide-num { width:26px; height:26px; background:var(--lbx-primary); color:#fff; border-radius:7px; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; flex:0 0 auto; }
      .lbx-slide-title { font-size:13px; font-weight:600; color:var(--lbx-gray-700); flex:1; }
      .lbx-slide-actions { display:flex; align-items:center; gap:6px; }
      .lbx-slide-actions button { background:#fff; border:1px solid var(--lbx-gray-300); border-radius:var(--lbx-radius-sm); width:30px; height:30px; display:inline-flex; align-items:center; justify-content:center; cursor:pointer; color:var(--lbx-gray-600); transition:all .15s; }
      .lbx-slide-actions button:hover { border-color:var(--lbx-gray-400); background:var(--lbx-gray-50); }
      .lbx-slide-actions .li-remove:hover { border-color:#fecaca; background:var(--lbx-danger-bg); color:var(--lbx-danger); }
      .lbx-slide-actions .dashicons { font-size:16px; width:16px; height:16px; }
      .lbx-slide-chevron { color:var(--lbx-gray-400); transition:transform .2s; margin-left:2px; }
      .lbx-slide--collapsed .lbx-slide-chevron { transform:rotate(180deg); }
      .lbx-slide--collapsed .lbx-slide-body { display:none; }
      .lbx-slide-body { padding:18px 16px; }
      .lbx-slide-top-row { display:flex; gap:20px; align-items:flex-start; }
      .lbx-slide-image-col { flex:0 0 auto; }
      .lbx-slide-fields { flex:1; min-width:0; }

      .lbx-seed-note { display:flex; align-items:center; gap:8px; padding:10px 14px; margin-bottom:16px; background:var(--lbx-primary-light); border:1px solid #bfdbfe; border-radius:var(--lbx-radius-sm); color:#1e3a8a; font-size:13px; }
      .lbx-empty { text-align:center; padding:32px; color:var(--lbx-gray-400); }
      .lbx-empty .dashicons { font-size:36px; width:36px; height:36px; display:block; margin:0 auto 8px; }
      .lbx-listing-actions { display:flex; gap:12px; margin-top:18px; }
      #response-message:empty { display:none; }
      #response-message .msg, #response-message .msg-er { padding:10px 14px; border-radius:var(--lbx-radius-sm); margin:0 0 14px; font-size:13px; }
      #response-message .msg { background:#ecfdf5; color:#065f46; border:1px solid #a7f3d0; }
      #response-message .msg-er { background:var(--lbx-danger-bg); color:#991b1b; border:1px solid #fecaca; }

      @media screen and (max-width: 782px) {
        .lbx-panel-grid { grid-template-columns:1fr; }
        .lbx-slide-top-row { flex-direction:column; }
        .lbx-slide-image, .lbx-slide-image-col { width:100%; }
        .lbx-slide-image { height:160px; }
      }
    </style>
    <?php
  }

  /**
   * LBT-1462 helpers: option name, select markup, sanitize, admin seed.
   */
  private function listing_images_option_name()
  {
    return 'dealer-settings-listing-images-options';
  }

  // Companion option holding the global placement config (mode/offset/repeat).
  private function listing_images_config_name()
  {
    return 'dealer-settings-listing-images-config';
  }

  // Current placement config with defaults. 'grouped' is the default mode.
  private function get_listing_images_config_admin()
  {
    $cfg = get_option($this->listing_images_config_name(), array());
    $cfg = is_array($cfg) ? $cfg : array();

    $mode = isset($cfg['mode']) ? strtolower(trim($cfg['mode'])) : 'grouped';
    if (!in_array($mode, array('grouped', 'individual'), true)) {
      $mode = 'grouped';
    }

    return array(
      'mode'   => $mode,
      'offset' => isset($cfg['offset']) ? absint($cfg['offset']) : 0,
      'repeat' => isset($cfg['repeat']) ? absint($cfg['repeat']) : 0,
    );
  }

  // AJAX: persist the placement config (mode/offset/repeat).
  public function save_listing_images_config()
  {
    check_ajax_referer('save_listing_image_nonce', 'nonce');

    $mode = isset($_POST['mode']) ? strtolower(trim(sanitize_text_field(wp_unslash($_POST['mode'])))) : 'grouped';
    if (!in_array($mode, array('grouped', 'individual'), true)) {
      $mode = 'grouped';
    }

    $config = array(
      'mode'   => $mode,
      'offset' => isset($_POST['offset']) ? absint($_POST['offset']) : 0,
      'repeat' => isset($_POST['repeat']) ? absint($_POST['repeat']) : 0,
    );

    update_option($this->listing_images_config_name(), $config);
    wp_send_json_success(array('message' => 'Placement settings saved.', 'config' => $config));
  }

  // Render a <select> for target/condition/language with the given selected value.
  public function listing_image_select_html($id, $type, $selected, $name = null)
  {
    $choices = array(
      'target'    => array('_self' => 'Same tab', '_blank' => 'New tab'),
      'condition' => array('both' => 'Both', 'new' => 'New', 'used' => 'Used'),
      'language'  => array('both' => 'Both', 'en' => 'English', 'fr' => 'French'),
      'fit'       => array('contain' => 'Contain (no crop)', 'cover' => 'Cover (fill & crop)'),
    );
    $opts = isset($choices[$type]) ? $choices[$type] : array();
    $name_attr = $name ? ' name="' . esc_attr($name) . '"' : '';
    $id_attr = $id ? ' id="' . esc_attr($id) . '"' : '';
    $html = '<select' . $id_attr . $name_attr . ' class="lbx-input">';
    foreach ($opts as $val => $label) {
      $html .= '<option value="' . esc_attr($val) . '" ' . selected($selected, $val, false) . '>' . esc_html($label) . '</option>';
    }
    $html .= '</select>';
    return $html;
  }

  // Normalize + sanitize a single posted/stored entry to a stable shape.
  public function sanitize_listing_image_entry($entry)
  {
    $entry = is_array($entry) ? $entry : array();

    $condition = isset($entry['condition']) ? strtolower(sanitize_text_field($entry['condition'])) : 'both';
    if (!in_array($condition, array('new', 'used', 'both'), true)) {
      $condition = 'both';
    }
    $language = isset($entry['language']) ? strtolower(sanitize_text_field($entry['language'])) : 'both';
    if (!in_array($language, array('en', 'fr', 'both'), true)) {
      $language = 'both';
    }
    $target = isset($entry['target']) ? sanitize_text_field($entry['target']) : '_self';
    if (!in_array($target, array('_self', '_blank'), true)) {
      $target = '_self';
    }
    $fit = isset($entry['fit']) ? strtolower(sanitize_text_field($entry['fit'])) : 'contain';
    if (!in_array($fit, array('cover', 'contain'), true)) {
      $fit = 'contain';
    }

    $activate_raw = isset($entry['activate_limit_date']) ? $entry['activate_limit_date'] : 'Disabled';
    $activate = ($activate_raw === 'Enabled' || $activate_raw === '1' || $activate_raw === 1 || $activate_raw === true) ? 'Enabled' : 'Disabled';

    $limit_date = isset($entry['limit_date']) ? sanitize_text_field($entry['limit_date']) : '';
    // keep only a valid Y-m-d, otherwise drop it
    if ($limit_date !== '') {
      $d = DateTime::createFromFormat('Y-m-d', $limit_date);
      if (!$d || $d->format('Y-m-d') !== $limit_date) {
        $limit_date = '';
      }
    }

    return array(
      'image'               => isset($entry['image']) ? esc_url_raw(trim($entry['image'])) : '',
      'link'                => isset($entry['link']) ? esc_url_raw(trim($entry['link'])) : '',
      'target'              => $target,
      'insert_after'        => isset($entry['insert_after']) ? absint($entry['insert_after']) : 0,
      'repeat_every'        => isset($entry['repeat_every']) ? absint($entry['repeat_every']) : 0,
      'condition'           => $condition,
      'language'            => $language,
      'fit'                 => $fit,
      'limit_date'          => $limit_date,
      'activate_limit_date' => $activate,
      'alt'                 => isset($entry['alt']) ? sanitize_text_field($entry['alt']) : '',
    );
  }

  // Entries to show in the admin table: the repeater option, or (when empty) a
  // seed migrated from the legacy single-image keys so nothing is lost. Returns
  // array('entries' => [...], 'seeded' => bool).
  private function get_listing_images_admin()
  {
    $entries = get_option($this->listing_images_option_name(), array());
    if (is_string($entries) && $entries === '[]') {
      $entries = array();
    }
    if (is_array($entries) && !empty($entries)) {
      return array('entries' => array_map(array($this, 'sanitize_listing_image_entry'), $entries), 'seeded' => false);
    }

    // seed from legacy flat option
    $legacy = get_option('dealer-settings-listing-options', array());
    $legacy = is_array($legacy) ? $legacy : array();
    $interval = isset($legacy['insert_after_new']) ? absint($legacy['insert_after_new']) : 0;

    $map = array(
      array('image_new',     'link_new',     'new',  'en', 'limit_date_new',  'activate_limit_date'),
      array('image_new_fr',  'link_new_fr',  'new',  'fr', 'limit_date_new',  'activate_limit_date'),
      array('image_used',    'link_used',    'used', 'en', 'limit_date_used', 'activate_limit_date_used'),
      array('image_used_fr', 'link_used_fr', 'used', 'fr', 'limit_date_used', 'activate_limit_date_used'),
    );
    $seed = array();
    foreach ($map as $row) {
      list($imgK, $linkK, $cond, $lang, $ldK, $actK) = $row;
      if (empty($legacy[$imgK])) {
        continue;
      }
      $seed[] = $this->sanitize_listing_image_entry(array(
        'image'               => $legacy[$imgK],
        'link'                => isset($legacy[$linkK]) ? $legacy[$linkK] : '',
        'target'              => '_self',
        'insert_after'        => 0,
        'repeat_every'        => $interval, // preserve legacy "repeat every N" behaviour
        'condition'           => $cond,
        'language'            => $lang,
        'fit'                 => 'contain', // preserve the legacy natural (no-crop) look
        'limit_date'          => isset($legacy[$ldK]) ? $legacy[$ldK] : '',
        'activate_limit_date' => isset($legacy[$actK]) ? $legacy[$actK] : 'Disabled',
        'alt'                 => '',
      ));
    }
    return array('entries' => $seed, 'seeded' => !empty($seed));
  }

  // Render one editable table row for an entry at $index.
  private function render_listing_image_row($index, $entry)
  {
    $entry = $this->sanitize_listing_image_entry($entry);
    $n = 'entries[' . $index . ']';

    $condLabels = array('new' => 'New', 'used' => 'Used', 'both' => 'Both');
    $pos = $entry['repeat_every'] > 0
      ? ('every ' . $entry['repeat_every'])
      : ($entry['insert_after'] > 0 ? ('after ' . $entry['insert_after']) : '—');
    $summary = (isset($condLabels[$entry['condition']]) ? $condLabels[$entry['condition']] : 'Both')
      . ' &middot; ' . strtoupper($entry['language']) . ' &middot; pos ' . $pos;
    $thumb = $entry['image']
      ? '<img src="' . esc_url($entry['image']) . '" alt="">'
      : '<div class="lbx-slide-image-ph"><span class="dashicons dashicons-cloud-upload"></span><span>Click to upload</span></div>';

    echo '<div class="lbx-slide lbx-slide--collapsed" data-index="' . esc_attr($index) . '">';
      echo '<div class="lbx-slide-header">';
        echo '<label class="lbx-slide-select"><input type="checkbox" class="select-entry" value="1"></label>';
        echo '<span class="lbx-slide-num">' . ($index + 1) . '</span>';
        echo '<span class="lbx-slide-title">' . $summary . '</span>';
        echo '<div class="lbx-slide-actions">';
          echo '<button type="button" class="li-move-up" title="Move up"><span class="dashicons dashicons-arrow-up-alt2"></span></button>';
          echo '<button type="button" class="li-move-down" title="Move down"><span class="dashicons dashicons-arrow-down-alt2"></span></button>';
          echo '<button type="button" class="li-remove delete-listing-image" data-index="' . esc_attr($index) . '" title="Delete"><span class="dashicons dashicons-trash"></span></button>';
          echo '<span class="lbx-slide-chevron dashicons dashicons-arrow-up-alt2"></span>';
        echo '</div>';
      echo '</div>';

      echo '<div class="lbx-slide-body">';
        echo '<div class="lbx-slide-top-row">';
          echo '<div class="lbx-slide-image-col">';
            echo '<div class="lbx-slide-image lbx-pick-image li-row-preview">' . $thumb . '</div>';
            echo '<input type="hidden" name="' . $n . '[image]" value="' . esc_attr($entry['image']) . '" class="li-image-input">';
          echo '</div>';
          echo '<div class="lbx-slide-fields">';
            echo '<div class="lbx-panel-grid">';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Link</label><input type="text" name="' . $n . '[link]" value="' . esc_attr($entry['link']) . '" class="lbx-input"></div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Open in</label>' . $this->listing_image_select_html('', 'target', $entry['target'], $n . '[target]') . '</div>';
              echo '<div class="lbx-field li-position-field"><label class="lbx-mini-label">Insert After</label><input type="number" min="0" name="' . $n . '[insert_after]" value="' . esc_attr($entry['insert_after']) . '" class="lbx-input"></div>';
              echo '<div class="lbx-field li-position-field"><label class="lbx-mini-label">Repeat Every</label><input type="number" min="0" name="' . $n . '[repeat_every]" value="' . esc_attr($entry['repeat_every']) . '" class="lbx-input"></div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Condition</label>' . $this->listing_image_select_html('', 'condition', $entry['condition'], $n . '[condition]') . '</div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Language</label>' . $this->listing_image_select_html('', 'language', $entry['language'], $n . '[language]') . '</div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Image Fit</label>' . $this->listing_image_select_html('', 'fit', $entry['fit'], $n . '[fit]') . '</div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Limit Date</label><input type="date" name="' . $n . '[limit_date]" value="' . esc_attr($entry['limit_date']) . '" class="lbx-input"></div>';
              echo '<div class="lbx-field"><label class="lbx-mini-label">Alt Text</label><input type="text" name="' . $n . '[alt]" value="' . esc_attr($entry['alt']) . '" class="lbx-input"></div>';
            echo '</div>';
            echo '<label class="lbx-toggle"><input type="checkbox" name="' . $n . '[activate_limit_date]" value="Enabled" ' . checked($entry['activate_limit_date'], 'Enabled', false) . '><span class="lbx-toggle-track"></span><span class="lbx-toggle-label">Expire on limit date</span></label>';
          echo '</div>';
        echo '</div>';
      echo '</div>';
    echo '</div>';
  }

  // Render the saved-entries table (with seed note when migrated from legacy).
  public function display_listing_images_saved_data()
  {
    $data = $this->get_listing_images_admin();
    $entries = $data['entries'];

    if (empty($entries)) {
      echo '<div class="lbx-empty"><span class="dashicons dashicons-format-image"></span><p>No images configured yet. Add one above.</p></div>';
      return;
    }

    if (!empty($data['seeded'])) {
      echo '<div class="lbx-seed-note"><span class="dashicons dashicons-info-outline"></span> These entries were imported from your previous single-image settings. Click <strong>Save Changes</strong> to store them as the new list.</div>';
    }

    echo '<form id="update-listing-images-form" method="post" action="">';
    echo '<div id="lbx-listing-rows">';
    foreach ($entries as $index => $entry) {
      $this->render_listing_image_row($index, $entry);
    }
    echo '</div>';
    echo '<div class="lbx-listing-actions">';
    echo '<button id="update-listing-images" type="submit" class="lbx-btn lbx-btn-primary"><span class="dashicons dashicons-saved"></span> Save Changes</button>';
    echo '<button id="delete-selected-listing-images" type="button" class="lbx-btn lbx-btn-danger"><span class="dashicons dashicons-trash"></span> Delete Selected</button>';
    echo '</div>';
    echo '</form>';
  }

  public function enqueue_listing_images_scripts($hook)
  {
    // Top-level menu (LBT-1462): the page now lives at its own top-level entry, so
    // the admin hook suffix is `toplevel_page_...` instead of `dealer-settings_page_...`.
    if ($hook !== 'toplevel_page_dealer-settings-listing') {
      return;
    }
    wp_enqueue_media();
    wp_enqueue_script(
      'edit-listing-images-script',
      plugin_dir_url(__FILE__) . 'edit-listing-images.js',
      array('jquery'),
      time(),
      true
    );
    wp_localize_script('edit-listing-images-script', 'editListingImages', array(
      'ajax_url' => admin_url('admin-ajax.php'),
      'nonce'    => wp_create_nonce('save_listing_image_nonce'),
    ));
  }

  // AJAX: append a single new image entry.
  public function save_listing_image()
  {
    check_ajax_referer('save_listing_image_nonce', 'nonce');
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    $entry = $this->sanitize_listing_image_entry(isset($_POST['entry']) ? (array) $_POST['entry'] : array());
    if (empty($entry['image'])) {
      wp_send_json_error('An image is required.');
    }

    $options = get_option($this->listing_images_option_name(), array());
    if (is_string($options) && $options === '[]') {
      $options = array();
    }
    if (!is_array($options)) {
      $options = array();
    }
    $options[] = $entry;
    update_option($this->listing_images_option_name(), $options);

    wp_send_json_success(array('message' => 'Image added successfully.', 'reload' => true));
  }

  // AJAX: rewrite the whole list from the edited table (order preserved).
  public function update_listing_images()
  {
    check_ajax_referer('save_listing_image_nonce', 'nonce');
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    $entries = isset($_POST['entries']) ? (array) $_POST['entries'] : array();
    $updated = array();
    foreach ($entries as $entry) {
      $clean = $this->sanitize_listing_image_entry((array) $entry);
      if (empty($clean['image'])) {
        continue; // drop rows with no image
      }
      $updated[] = $clean;
    }

    update_option($this->listing_images_option_name(), array_values($updated));
    wp_send_json_success(array('message' => 'Entries updated successfully.', 'reload' => true));
  }

  // AJAX: delete a single entry by index.
  public function delete_listing_image()
  {
    check_ajax_referer('save_listing_image_nonce', 'nonce');
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    $index = absint($_POST['index']);
    $options = get_option($this->listing_images_option_name(), array());
    if (is_array($options) && isset($options[$index])) {
      unset($options[$index]);
      update_option($this->listing_images_option_name(), array_values($options));
      wp_send_json_success(array('message' => 'Image deleted successfully.', 'reload' => true));
    }
    wp_send_json_error('Entry not found.');
  }

  // AJAX: delete multiple entries by index.
  public function delete_selected_listing_images()
  {
    check_ajax_referer('save_listing_image_nonce', 'nonce');
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    if (isset($_POST['entries']) && is_array($_POST['entries'])) {
      $to_delete = array_map('intval', $_POST['entries']);
      $options = get_option($this->listing_images_option_name(), array());
      if (is_array($options)) {
        foreach ($to_delete as $index) {
          if (isset($options[$index])) {
            unset($options[$index]);
          }
        }
        update_option($this->listing_images_option_name(), array_values($options));
      }
      wp_send_json_success(array('message' => 'Selected images deleted successfully.', 'reload' => true));
    }
    wp_send_json_error('No entries selected');
  }

	/**
   * Register and add settings
   */
  public function register_listing_settings(){
    register_setting(
      'dealer-settings-listing-options-group',
      'dealer-settings-listing-options',
      array($this, 'sanitize')
    );

		add_settings_section(
      'listing_new',
      'Inventory Listing Image New',
      array($this, 'print_section_info'),
      'dealer-settings-listing-new'
    );
		add_settings_section(
      'listing_used',
      'Inventory Listing Image used',
      array($this, 'print_section_info'),
      'dealer-settings-listing-used'
    );
		add_settings_section(
      'listing_limits',
      'Inventory Listing options',
      array($this, 'print_section_info'),
      'dealer-settings-listing-limits'
    );

    add_settings_field(
      'image_new',
      'Image New',
      array($this, 'image_new_callback'),
      'dealer-settings-listing-new',
      'listing_new'
    );
    add_settings_field(
      'link_new',
      'Link New',
      array($this, 'link_new_callback'),
      'dealer-settings-listing-new',
      'listing_new'
    );

    // setting image new fr
    add_settings_field(
      'image_new_fr',
      'Image New FR',
      array($this, 'image_new_fr_callback'),
      'dealer-settings-listing-new',
      'listing_new'
    );
    add_settings_field(
      'link_new_fr',
      'Link New FR',
      array($this, 'link_new_fr_callback'),
      'dealer-settings-listing-new',
      'listing_new'
    );

    add_settings_field(
      'insert_after_new',
      'Insert After',
      array($this, 'insert_after_new_callback'),
      'dealer-settings-listing-limits',
      'listing_limits'
    );

		//setting for limit date new
		add_settings_field(
			'limit_date_new',
			'Limit Date',
			array($this, 'limit_date_new_callback'),
			'dealer-settings-listing-new',
      'listing_new'
		);
		//seting for enable limit date
    add_settings_field(
      'activate_limit_date',
      'Use Limit Date',
      array($this, 'activate_limit_date_callback'),
      'dealer-settings-listing-new',
      'listing_new'
    );

    add_settings_field(
      'image_used',
      'Image used',
      array($this, 'image_used_callback'),
      'dealer-settings-listing-used',
      'listing_used'
    );
		//setting for link used
		add_settings_field(
			'link_used',
			'Link used',
			array($this, 'link_used_callback'),
			'dealer-settings-listing-used',
			'listing_used'
		);

    //setting image used fr
    add_settings_field(
      'image_used_fr',
      'Image used FR',
      array($this, 'image_used_fr_callback'),
      'dealer-settings-listing-used',
      'listing_used'
    );
    add_settings_field(
      'link_used_fr',
      'Link used FR',
      array($this, 'link_used_fr_callback'),
      'dealer-settings-listing-used',
      'listing_used'
    );

    //setting for limit date used
    add_settings_field(
      'used_limit_date',
      'Limit Date',
      array($this, 'limit_date_used_callback'),
      'dealer-settings-listing-used',
      'listing_used'
    );
    //seting for enable limit date used
    add_settings_field(
      'activate_limit_date_used',
      'Use Limit Date',
      array($this, 'activate_limit_date_used_callback'),
      'dealer-settings-listing-used',
      'listing_used'
    );
  }

	public function image_new_callback()
	{
		printf(
			'<input type="text" id="image_new" name="dealer-settings-listing-options[image_new]" value="%s" />
				<input id="upload_image_button_inv_new" type="button" class="add-logo-image-button button button-secondary" value="Select image" />',
			isset($this->listing_options['image_new']) ? esc_attr($this->listing_options['image_new']) : ''
		);

		?>

		<?php
	}
	public function link_new_callback()
  {
    printf(
      '<input type="text" id="link_new" name="dealer-settings-listing-options[link_new]" value="%s" />',
      isset($this->listing_options['link_new']) ? esc_attr($this->listing_options['link_new']) : ''
    );
  }

	public function image_new_fr_callback()
	{
		printf(
			'<input type="text" id="image_new_fr" name="dealer-settings-listing-options[image_new_fr]" value="%s" />
				<input id="upload_image_button_inv_new_fr" type="button" class="add-logo-image-button button button-secondary" value="Select image" />',
			isset($this->listing_options['image_new_fr']) ? esc_attr($this->listing_options['image_new_fr']) : ''
		);
	}

	public function link_new_fr_callback()
	{
		printf(
			'<input type="text" id="link_new_fr" name="dealer-settings-listing-options[link_new_fr]" value="%s" />',
			isset($this->listing_options['link_new_fr']) ? esc_attr($this->listing_options['link_new_fr']) : ''
		);
	}

	public function insert_after_new_callback()
  {
    printf(
			'<input type="number" id="insert_after_new" name="dealer-settings-listing-options[insert_after_new]" value="%s" min="0" />',
      isset($this->listing_options['insert_after_new']) ? esc_attr($this->listing_options['insert_after_new']) : ''
    );
  }

	//input for limit date new
	public function limit_date_new_callback()
	{
		$current_date = date('Y-m-d');
		printf(
      '<input type="date" id="limit_date_new" name="dealer-settings-listing-options[limit_date_new]" value="%s" min="%s" />',
			isset($this->listing_options['limit_date_new']) ? esc_attr($this->listing_options['limit_date_new']) : '',
			$current_date
		);
	}

	public function image_used_callback()
	{
		printf(
			'<input type="text" id="image_used" name="dealer-settings-listing-options[image_used]" value="%s" />
			 <input id="upload_image_button_inv_used" type="button" class="add-logo-image-button button button-secondary" value="Select image" />',
			isset($this->listing_options['image_used']) ? esc_attr($this->listing_options['image_used']) : ''
		);
	}

	//input link used callback
	public function link_used_callback()
	{
		printf(
			'<input type="text" id="link_used" name="dealer-settings-listing-options[link_used]" value="%s" />',
			isset($this->listing_options['link_used']) ? esc_attr($this->listing_options['link_used']) : ''
		);
	}

	//image used fr callback
	public function image_used_fr_callback()
	{
		printf(
			'<input type="text" id="image_used_fr" name="dealer-settings-listing-options[image_used_fr]" value="%s" />
			 <input id="upload_image_button_inv_used_fr" type="button" class="add-logo-image-button button button-secondary" value="Select image" />',
			isset($this->listing_options['image_used_fr']) ? esc_attr($this->listing_options['image_used_fr']) : ''
		);
	}

	//input link used callback
	public function link_used_fr_callback()
	{
		printf(
			'<input type="text" id="link_used_fr" name="dealer-settings-listing-options[link_used_fr]" value="%s" />',
			isset($this->listing_options['link_used_fr']) ? esc_attr($this->listing_options['link_used_fr']) : ''
		);
	}
  //input for limit date used
  public function limit_date_used_callback()
  {
    $current_date = date('Y-m-d');
    printf(
      '<input type="date" id="limit_date_used" name="dealer-settings-listing-options[limit_date_used]" value="%s" min="%s" />',
      isset($this->listing_options['limit_date_used']) ? esc_attr($this->listing_options['limit_date_used']) : '',
      $current_date
    );
  }

	//type check input for enable limit date
	public function activate_limit_date_callback()
	{
		if (!isset($this->listing_options['activate_limit_date'])) {
			$this->listing_options['activate_limit_date'] = "Disabled";
		}

		echo '<select id="activate_limit_date" name="dealer-settings-listing-options[activate_limit_date]">';
		if (strtolower($this->listing_options['activate_limit_date']) == 'enabled') {
			echo '<option value="Disabled">Disabled</option>';
			echo '<option selected value="Enabled">Enabled</option>';
		} else if (strtolower($this->listing_options['activate_limit_date']) == 'disabled') {
			echo '<option value="Disabled">Disabled</option>';
			echo '<option value="Enabled">Enabled</option>';
		} else {
			echo '<option value="Disabled">Disabled</option>';
			echo '<option value="Enabled">Enabled</option>';
		}

		echo '</select>';
    echo '<p class="description-l">Enable or disable the limit date for the new inventory listing</p>';
	}

  //type check input for enable limit date used
  public function activate_limit_date_used_callback()
  {
    if (!isset($this->listing_options['activate_limit_date_used'])) {
      $this->listing_options['activate_limit_date_used'] = "Disabled";
    }

    echo '<select id="activate_limit_date_used" name="dealer-settings-listing-options[activate_limit_date_used]">';
    if (strtolower($this->listing_options['activate_limit_date_used']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->listing_options['activate_limit_date_used']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
    echo '<p class="description-l">Enable or disable the limit date for the used inventory listing</p>';
  }


	/**
   * Options page callback
   */
	//*Used finance custom page
    /**
   * Options page callback
   */
	public function create_used_finance_custom_page(){
    // Set class property
    $this->used_finance_custom_options = get_option('dealer-settings-used-finance-custom-options', array());
    ?>
    <div class="wrap">
		<div class="card">
    	<form method="post" action="options.php">
			<?php
				settings_fields('dealer-settings-used-finance-custom-options-group');
				do_settings_sections('used-finance-custom');
				?>
    	  <div id="response-message"></div>
    	  <input id="save-options" name="save-options" class="button button-primary" type="button" value="Save Finance">
    	  <div id="options-container" class="card-msg"></div>
    	</form>
		</div>
			<div>
				<br>
				<?php $this->display_saved_data(); ?>
			</div>
    </div>

	<style>
    .card {
        border: 1px solid #ccd0d4;
        border-radius: 6px;
        background-color: #ffffff;
        box-shadow: 0 1px 1px rgba(0,0,0,0.04);
        margin: 20px 0;
        padding: 20px;
    }
    .card-msg {
				text-align: center;
				text-transform: capitalize;
				align-self: center;
    }
    .msg {
			border: 1px solid #ccd0d4;
      border-radius: 6px;
      background-color: #508D4E;
      box-shadow: 0 1px 1px rgba(0,0,0,0.04);
      margin: 20px 0;
			color: #ffffff;
      padding: 10px;
			animation: fadeIn 1s;
    }
    .msg-er {
			border: 1px solid #ccd0d4;
      border-radius: 6px;
      background-color: #c60000;
      box-shadow: 0 1px 1px rgba(0,0,0,0.04);
      margin: 20px 0;
			color: #ffffff;
      padding: 10px;
			animation: fadeIn 1s;
    }
		@keyframes fadeIn {
  		0% { opacity: 0; }
  		100% { opacity: 1; }
		}

		.delete-selected-button {
    	background-color: #d9534f !important; /* Rojo */
    	border-color: #d43f3a !important; /* Rojo oscuro */
    	color: white !important;
		}

		.delete-selected-button:hover {
			background-color: #c9302c !important; /* Rojo más oscuro */
			border-color: #ac2925 !important; /* Rojo oscuro */
		}
		.table-responsive {
			overflow-x: auto;
		}

		.form-control {
			width: 100%;
			padding: 10px;
			margin: 10px;
			box-sizing: border-box;
		}

		.btn-sm {
			padding: 5px 10px;
			font-size: 12px;
		}

		.btn-block {
			width: 100%;
			display: block;
			margin: 10px 0;
		}

		.wp-list-table td {
			padding: 10px;
		}

		.wp-list-table {
			margin: 20px 0;
		}
		.widefat td{
			vertical-align: middle;
		}
		.action-th {
			width: 70px;
			text-align: center !important;
		}
		@media screen and (max-width: 769px) {
				.action-th {
				width: auto;
			}
		}
		.centrar-checkbox {
			text-align: center;
		}
</style>
  <?php
}

public function enqueue_used_finance_scripts($hook) {
  // Verificar si estamos en la página de opciones de nuestro plugin
  if ($hook !== 'dealer-settings_page_dealer-settings-used_finance_custom' && $hook !== 'dealer-settings_page_dealer-settings-web-info') {
    return;
  }

  wp_enqueue_script(
    'edit-used-finance-script',
    plugin_dir_url(__FILE__) . 'edit-used-finance.js',
    array('jquery'),
    time(), // Utilizando el timestamp actual para evitar caché
    true
  );

  // Localizar script para pasar variables de PHP a JavaScript
  wp_localize_script(
    'edit-used-finance-script',
    'editUsedFinance',
    array(
      'ajax_url' => admin_url('admin-ajax.php'),
      'nonce'    => wp_create_nonce('save_custom_finance_options_nonce')
    )
  );
}
//* save function

public function save_custom_finance_options() {

    // Verificar el nonce para la seguridad
    check_ajax_referer('save_custom_finance_options_nonce', 'nonce');

    // Verificar permisos del usuario
    if (!current_user_can('manage_options')) {
      wp_send_json_error('Permission denied');
    }

    // Obtener los datos del POST
    $option1 = sanitize_text_field($_POST['option1']);
    $option2 = absint($_POST['option2']);
    $option3 = absint($_POST['option3']);
    $option4 = absint($_POST['option4']);
    $option5 = floatval($_POST['option5']);
    $option6 = isset($_POST['option6']) ? filter_var($_POST['option6'], FILTER_VALIDATE_BOOLEAN) : false; // Asegurar que es booleano

    // Obtener la opción existente
    $options = get_option('dealer-settings-used-finance-custom-options', array());

    // Verificar si la opción es una cadena que representa un array vacío
    if (is_string($options) && $options === '[]') {
      $options = array();
    }

    // Agregar las nuevas opciones al array
    $options[] = array('models' => $option1, 'startyear' => $option2,
                       'endyear' => $option3, 'term' => $option4,
                       'value' => $option5, 'isCPO' => $option6);

    // Actualizar la opción en la base de datos
    update_option('dealer-settings-used-finance-custom-options', $options);

    wp_send_json_success(array(
        'message' => 'Options saved successfully.',
        'reload' => true
    ));
  }
//* update function

	public function update_custom_finance_options() {
    check_ajax_referer('save_custom_finance_options_nonce', 'nonce');

    if (!current_user_can('manage_options')) {
        wp_send_json_error('Permission denied');
    }

    // Ahora entries es un array asociativo multidimensional
    $entries = isset($_POST['entries']) ? $_POST['entries'] : array();

    $updated_options = array();

    foreach ($entries as $entry) {
        $model = isset($entry['models']) ? sanitize_text_field($entry['models']) : '';
        $startYear = isset($entry['startyear']) ? absint($entry['startyear']) : 0;
        $endYear = isset($entry['endyear']) ? absint($entry['endyear']) : 0;
        $term = isset($entry['term']) ? absint($entry['term']) : 0;
        $value = isset($entry['value']) ? floatval($entry['value']) : 0;
        $cpo = isset($entry['isCPO']) ? filter_var($entry['isCPO'], FILTER_VALIDATE_BOOLEAN) : false;

        $updated_options[] = array(
            'models' => $model,
            'startyear' => $startYear,
            'endyear' => $endYear,
            'term' => $term,
            'value' => $value,
            'isCPO' => $cpo
        );
    }

    update_option('dealer-settings-used-finance-custom-options', $updated_options);

    wp_send_json_success(array(
        'message' => 'Entries updated successfully.',
				'reload' => true
    ));
}

//* delete function

	public function delete_finance_entry() {
		check_ajax_referer('save_custom_finance_options_nonce', 'nonce');

		if (!current_user_can('manage_options')) {
				wp_send_json_error('Permission denied');
		}

		$index = absint($_POST['index']);
		$options = get_option('dealer-settings-used-finance-custom-options', array());

		if (isset($options[$index])) {
			unset($options[$index]);
			$options = array_values($options); // Reindex array
			update_option('dealer-settings-used-finance-custom-options', $options);

			wp_send_json_success(array(
					'message' => 'Entry deleted successfully.',
					'reload' => true
			));
			} else {
					wp_send_json_error('Entry not found.');
			}
	}

	function delete_selected_entries() {
    check_ajax_referer('save_custom_finance_options_nonce', 'nonce');

    if (!current_user_can('manage_options')) {
        wp_send_json_error('Permission denied');
    }

    if (isset($_POST['entries']) && is_array($_POST['entries'])) {
        $entries_to_delete = array_map('intval', $_POST['entries']);
        $options = get_option('dealer-settings-used-finance-custom-options', array());

        foreach ($entries_to_delete as $index) {
            if (isset($options[$index])) {
                unset($options[$index]);
            }
        }

        // Re-index the array to remove gaps
        $options = array_values($options);
        update_option('dealer-settings-used-finance-custom-options', $options);

        wp_send_json_success(array(
            'message' => 'Selected entries deleted successfully.',
            'reload' => true
        ));
    } else {
        wp_send_json_error('No entries selected');
    }
}

  /**
   * Register and add settings
   */
  public function register_used_finance_custom_settings()
  {
    register_setting(
      'dealer-settings-used-finance-custom-options-group',
      'dealer-settings-used-finance-custom-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'custom_finance_used_setting',
      'Custom Financing',
      array($this, 'print_section_info'),
      'used-finance-custom'
    );

    add_settings_field(
      'model',
      'Models',
      array($this, 'model_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
    add_settings_field(
      'start_year',
      'Start Year',
      array($this, 'start_year_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
    add_settings_field(
      'end_year',
      'End Year',
      array($this, 'end_year_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
    add_settings_field(
      'term',
      'Term',
      array($this, 'term_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
    add_settings_field(
      'value',
      'Value',
      array($this, 'value_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
    add_settings_field(
      'iscpo',
      'Is CPO',
      array($this, 'iscpo_callback'),
      'used-finance-custom',
      'custom_finance_used_setting'
    );
  }

	public function model_callback(){
    printf('<input type="text" id="model" required name="dealer-settings-used-finance-custom-options[model]" />');
	}

	public function start_year_callback(){
    printf('<input type="number" id="start_year" min=0 required name="dealer-settings-used-finance-custom-options[start_year]" />');
	}

	public function end_year_callback(){
    printf('<input type="number" id="end_year" min=0 required name="dealer-settings-used-finance-custom-options[end_year]" />');
	}

	public function term_callback(){
    printf('<input type="number" id="term" min=0 required name="dealer-settings-used-finance-custom-options[term]" />');
	}

	public function value_callback(){
		printf('<input type="number" id="value" max=50 step=0.01 min=0 required name="dealer-settings-used-finance-custom-options[value]" />');
	}

	public function iscpo_callback(){
    printf('<input type="checkbox" id="iscpo" name="dealer-settings-used-finance-custom-options[iscpo]" />');
	}

public function display_saved_data() {
  $options = get_option('dealer-settings-used-finance-custom-options', array());

  	if (is_array($options) &&!empty($options)) {

      echo '<form id="update-entries-form" method="post" action="">';
      echo '<div class="table-responsive">';

      echo '<table class="fixed wp-list-table widefat striped">';
      echo '<thead><tr>';
			echo '<th style="width: 40px;">Select</th>'; // New checkbox column
      echo '<th>Model</th>';
      echo '<th>Start Year</th>';
      echo '<th>End Year</th>';
      echo '<th>Term</th>';
      echo '<th>Value</th>';
      echo '<th class="action-th">Is CPO</th>';
      echo '<th class="action-th">Actions</th>';
      echo '</tr></thead>';
      echo '<tbody>';

      foreach ($options as $index => $entry) {
        echo '<tr>';
				echo '<td><input type="checkbox" class="select-entry" name="entries[' . $index . '][delete]" value="1"></td>'; // New checkbox for selection
        echo '<td><input type="text" name="entries['. $index. '][models]" value="'. esc_attr($entry['models']). '" class="form-control"></td>';
        echo '<td><input type="number" min=0 name="entries['. $index. '][startyear]" value="'. esc_attr($entry['startyear']). '" class="form-control"></td>';
        echo '<td><input type="number" min=0 name="entries['. $index. '][endyear]" value="'. esc_attr($entry['endyear']). '" class="form-control"></td>';
        echo '<td><input type="number" min=0 name="entries['. $index. '][term]" value="'. esc_attr($entry['term']). '" class="form-control"></td>';
        echo '<td><input type="number" max=50 step=0.01 min=0 name="entries['. $index. '][value]" value="'. esc_attr($entry['value']). '" class="form-control"></td>';
        echo '<td class="centrar-checkbox"><input type="checkbox" name="entries['. $index. '][isCPO]" value="1" '. checked($entry['isCPO'], true, false).'></td>';
        echo '<td class="centrar-checkbox"><button type="button" class="delete-entry button btn-sm" data-index="'. $index. '">Delete</button></td>';
        echo '</tr>';

      }
      echo '</tbody></table>';
      echo '</div>'; // Close table-responsive div
      echo '</br>';
      echo '<input id="update-entries" style="margin-right: 1em;" type="submit" class="button button-primary" value="Update Entries">';
			echo '<button id="delete-selected" type="button" class="button delete-selected-button">Delete Selected</button>';
      echo '</form>';
  } else {
      echo '<h4 class="card">No data available. Please add some entries.</h4>';
  }
}


  /**
   * Options page callback
   */
  public function create_contact_page()
  {
    // Set class property
    $this->contact_options = get_option('dealer-settings-contact-options');
    ?>
            <div class="wrap">
              <h1>Contact</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-contact-options-group');
                do_settings_sections('dealer-settings-contact');
                do_settings_sections('dealer-settings-emails');
                do_settings_sections('dealer-settings-address');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Register and add settings
   */
  public function register_contact_settings(){
    register_setting(
      'dealer-settings-contact-options-group',
      'dealer-settings-contact-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'contact',
      'Contact',
      array($this, 'print_section_info'),
      'dealer-settings-contact'
    );

    add_settings_section(
      'emails',
      'Emails',
      array($this, 'print_section_info'),
      'dealer-settings-emails'
    );

    add_settings_section(
      'address',
      'Address',
      array($this, 'print_section_info'),
      'dealer-settings-address'
    );

    add_settings_field(
      'dealer_name',
      'Dealer Name',
      array($this, 'dealer_name_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'dealer_url',
      'Dealer URL',
      array($this, 'dealer_url_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'sale_phone',
      'Sales Phone',
      array($this, 'sale_phone_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'service_phone',
      'Service Phone',
      array($this, 'service_phone_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'parts_phone',
      'Parts Phone',
      array($this, 'parts_phone_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'collision_phone',
      'Collision Phone',
      array($this, 'collision_phone_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'accessories_phone',
      'Accessories Phone',
      array($this, 'accessories_phone_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'fax',
      'Fax',
      array($this, 'fax_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'body_shop',
      'Body Shop',
      array($this, 'body_shop_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'sms',
      'SMS',
      array($this, 'sms_callback'),
      'dealer-settings-contact',
      'contact'
    );

    add_settings_field(
      'primary_email',
      'Primary Email',
      array($this, 'primary_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'secondary_email',
      'Secondary Email',
      array($this, 'secondary_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'sales-email',
      'Sales Email',
      array($this, 'sales_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'service-email',
      'Service Email',
      array($this, 'service_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'parts-email',
      'Parts Email',
      array($this, 'parts_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'accessories-email',
      'Accessories Email',
      array($this, 'accessories_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'collision-email',
      'Collision Email',
      array($this, 'collision_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'bodyshop-email',
      'Body Shop Email',
      array($this, 'bodyshop_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'additional1-email',
      'Additional Email #1',
      array($this, 'additional1_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'additional2-email',
      'Additional Email #2',
      array($this, 'additional2_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'additional3-email',
      'Additional Email #3',
      array($this, 'additional3_email_callback'),
      'dealer-settings-emails',
      'emails'
    );

    add_settings_field(
      'line-1',
      'Line 1',
      array($this, 'line_1_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'line-2',
      'Line 2',
      array($this, 'line_2_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'city',
      'City',
      array($this, 'city_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'province',
      'Province',
      array($this, 'province_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'postal_code',
      'Postal Code',
      array($this, 'postal_code_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'url_map',
      'Url Map',
      array($this, 'map_callback'),
      'dealer-settings-address',
      'address'
    );
    add_settings_field(
      'url_map_iframe',
      'Iframe Map(URL only)',
      array($this, 'map_iframe_callback'),
      'dealer-settings-address',
      'address'
    );

    add_settings_field(
      'timezone',
      'Time Zone',
      array($this, 'timezone_callback'),
      'dealer-settings-address',
      'address'
    );
  }

  public function dealer_name_callback()
  {
    printf(
      '<input type="text" id="dealer_name" name="dealer-settings-contact-options[dealer_name]" value="%s" />',
      isset($this->contact_options['dealer_name']) ? esc_attr($this->contact_options['dealer_name']) : ''
    );
  }

  public function dealer_url_callback()
  {
    printf(
      '<input type="text" id="dealer_url" name="dealer-settings-contact-options[dealer_url]" value="%s" />',
      isset($this->contact_options['dealer_url']) ? esc_attr($this->contact_options['dealer_url']) : ''
    );
  }

  public function sale_phone_callback()
  {
    printf(
      '<input type="tel" id="sale_phone" name="dealer-settings-contact-options[sale_phone]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['sale_phone']) ? esc_attr($this->contact_options['sale_phone']) : ''
    );
  }

  public function fax_callback()
  {
    printf(
      '<input type="tel" id="fax" name="dealer-settings-contact-options[fax]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['fax']) ? esc_attr($this->contact_options['fax']) : ''
    );
  }

  public function sms_callback()
  {
    printf(
      '<input type="tel" id="sms" name="dealer-settings-contact-options[sms]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['sms']) ? esc_attr($this->contact_options['sms']) : ''
    );
  }

  public function body_shop_callback()
  {
    printf(
      '<input type="tel" id="body_shop" name="dealer-settings-contact-options[body_shop]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['body_shop']) ? esc_attr($this->contact_options['body_shop']) : ''
    );
  }

  public function service_phone_callback()
  {
    printf(
      '<input type="tel" id="service_phone" name="dealer-settings-contact-options[service_phone]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['service_phone']) ? esc_attr($this->contact_options['service_phone']) : ''
    );
  }
  public function parts_phone_callback()
  {
    printf(
      '<input type="tel" id="parts_phone" name="dealer-settings-contact-options[parts_phone]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['parts_phone']) ? esc_attr($this->contact_options['parts_phone']) : ''
    );
  }

  public function collision_phone_callback()
  {
    printf(
      '<input type="tel" id="collision_phone" name="dealer-settings-contact-options[collision_phone]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['collision_phone']) ? esc_attr($this->contact_options['collision_phone']) : ''
    );
  }

  public function accessories_phone_callback()
  {
    printf(
      '<input type="tel" id="accessories_phone" name="dealer-settings-contact-options[accessories_phone]" value="%s" pattern="^[+]?[0-9]{9,12}$" />',
      isset($this->contact_options['accessories_phone']) ? esc_attr($this->contact_options['accessories_phone']) : ''
    );
  }
  public function primary_email_callback()
  {
    printf(
      '<input type="email" id="primary_email" name="dealer-settings-contact-options[primary_email]" value="%s" />',
      isset($this->contact_options['primary_email']) ? esc_attr($this->contact_options['primary_email']) : ''
    );
  }
  public function secondary_email_callback()
  {
    printf(
      '<input type="email" id="secondary_email" name="dealer-settings-contact-options[secondary_email]" value="%s" />',
      isset($this->contact_options['secondary_email']) ? esc_attr($this->contact_options['secondary_email']) : ''
    );
  }

  public function sales_email_callback()
  {
    printf(
      '<input type="email" id="sales_email" name="dealer-settings-contact-options[sales_email]" value="%s" />',
      isset($this->contact_options['sales_email']) ? esc_attr($this->contact_options['sales_email']) : ''
    );
  }

  public function service_email_callback()
  {
    printf(
      '<input type="email" id="service_email" name="dealer-settings-contact-options[service_email]" value="%s" />',
      isset($this->contact_options['service_email']) ? esc_attr($this->contact_options['service_email']) : ''
    );
  }

  public function parts_email_callback()
  {
    printf(
      '<input type="email" id="parts_email" name="dealer-settings-contact-options[parts_email]" value="%s" />',
      isset($this->contact_options['parts_email']) ? esc_attr($this->contact_options['parts_email']) : ''
    );
  }

  public function accessories_email_callback()
  {
    printf(
      '<input type="email" id="accessories_email" name="dealer-settings-contact-options[accessories_email]" value="%s" />',
      isset($this->contact_options['accessories_email']) ? esc_attr($this->contact_options['accessories_email']) : ''
    );
  }

  public function collision_email_callback()
  {
    printf(
      '<input type="email" id="collision_email" name="dealer-settings-contact-options[collision_email]" value="%s" />',
      isset($this->contact_options['collision_email']) ? esc_attr($this->contact_options['collision_email']) : ''
    );
  }

  public function bodyshop_email_callback()
  {
    printf(
      '<input type="email" id="bodyshop_email" name="dealer-settings-contact-options[bodyshop_email]" value="%s" />',
      isset($this->contact_options['bodyshop_email']) ? esc_attr($this->contact_options['bodyshop_email']) : ''
    );
  }

  public function additional1_email_callback()
  {
    printf(
      '<input type="email" id="additional1_email" name="dealer-settings-contact-options[additional1_email]" value="%s" />',
      isset($this->contact_options['additional1_email']) ? esc_attr($this->contact_options['additional1_email']) : ''
    );
  }

  public function additional2_email_callback()
  {
    printf(
      '<input type="email" id="additional2_email" name="dealer-settings-contact-options[additional2_email]" value="%s" />',
      isset($this->contact_options['additional2_email']) ? esc_attr($this->contact_options['additional2_email']) : ''
    );
  }

  public function additional3_email_callback()
  {
    printf(
      '<input type="email" id="additional3_email" name="dealer-settings-contact-options[additional3_email]" value="%s" />',
      isset($this->contact_options['additional3_email']) ? esc_attr($this->contact_options['additional3_email']) : ''
    );
  }

  public function line_1_callback()
  {
    printf(
      '<input type="text" id="address_line_1" name="dealer-settings-contact-options[address_line_1]" value="%s" />',
      isset($this->contact_options['address_line_1']) ? esc_attr($this->contact_options['address_line_1']) : ''
    );
  }

  public function line_2_callback()
  {
    printf(
      '<input type="text" id="address_line_2" name="dealer-settings-contact-options[address_line_2]" value="%s" />',
      isset($this->contact_options['address_line_2']) ? esc_attr($this->contact_options['address_line_2']) : ''
    );
  }

  public function city_callback()
  {
    printf(
      '<input type="text" id="address_city" name="dealer-settings-contact-options[address_city]" value="%s" />',
      isset($this->contact_options['address_city']) ? esc_attr($this->contact_options['address_city']) : ''
    );
  }

  public function province_callback()
  {
    $provinces_options = '';

    foreach ($this->provinces_options as $province) {
      $provinces_options .= '<option '. (isset($this->contact_options['address_province']) && strtolower(str_replace(' ', '', $this->contact_options['address_province'])) == strtolower(str_replace(' ', '', $province)) ? ' selected '  : '').' value="' . $province . '">' . $province . '</option>';
    }

    printf(
      '<select id="address_province" name="dealer-settings-contact-options[address_province]">
        %s
      </select>',
      $provinces_options
    );
  }

  public function postal_code_callback()
  {
    printf(
      '<input type="text" id="address_postal_code" name="dealer-settings-contact-options[address_postal_code]" value="%s" />',
      isset($this->contact_options['address_postal_code']) ? esc_attr($this->contact_options['address_postal_code']) : ''
    );
  }

  public function map_callback()
  {
    printf(
      '<input type="text" id="address_url_map" name="dealer-settings-contact-options[address_url_map]" value="%s" />',
      isset($this->contact_options['address_url_map']) ? esc_attr($this->contact_options['address_url_map']) : ''
    );
  }
  public function map_iframe_callback()
  {
    printf(
      '<input type="text" id="address_url_map_iframe" name="dealer-settings-contact-options[address_url_map_iframe]" value="%s" />',
      isset($this->contact_options['address_url_map_iframe']) ? esc_attr($this->contact_options['address_url_map_iframe']) : ''
    );
  }

  public function timezone_callback()
  {
    printf(
      '<input type="text" id="address_timezone" name="dealer-settings-contact-options[address_timezone]" value="%s" />',
      isset($this->contact_options['address_timezone']) ? esc_attr($this->contact_options['address_timezone']) : ''
    );
  }



  /**
   * Options page callback
   */
  public function create_iboost_page()
  {
    // Set class property
    $this->iboost_options = get_option('dealer-settings-iboost-options');
    ?>
            <div class="wrap">
              <h1>iBoost 360</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-iboost-options-group');
                do_settings_sections('dealer-settings-iboost');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  /**
   * Options page callback
   */
  public function create_disclaimer_page()
  {
    // Set class property
    $this->disclaimer_options = get_option('dealer-settings-disclaimer-options');
    ?>
            <div class="wrap">
              <h1>Disclaimer</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-disclaimer-options-group');
                do_settings_sections('dealer-settings-disclaimer');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }

  public function create_filter_page()
  {
    // Set class property
    $this->filter_options = get_option('dealer-settings-filter-options');
    ?>
            <div class="wrap">
              <h1>Filter</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-filter-options-group');
                do_settings_sections('dealer-settings-filter');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }


  /**
   * Options page callback
   */
  public function create_policies_page()
  {
    // Set class property
    $this->policies_options = get_option('dealer-settings-policies-options');
    ?>
            <div class="wrap">
              <h1>Policies</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-policies-options-group');
                do_settings_sections('dealer-settings-policies');
                submit_button();

                ?>
              </form>
            </div>
          <?php
  }


  /**
   * Options page callback
   */
  public function create_socialmedia_page()
  {
    // Set class property
    $this->socialmedia_options = get_option('dealer-settings-socialmedia-options');
    ?>
            <div class="wrap">
              <h1>Social Media</h1>
              <form method="post" action="options.php">
                <?php

                settings_fields('dealer-settings-socialmedia-options-group');
                do_settings_sections('dealer-settings-socialmedia');
                submit_button();

                ?>
              </form>
            </div>
        <?php
  }

  /**
   * Register and add settings
   */
  public function register_socialmedia_settings()
  {
    register_setting(
      'dealer-settings-socialmedia-options-group',
      'dealer-settings-socialmedia-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'socialmedia',
      'Social Media',
      array($this, 'print_section_info'),
      'dealer-settings-socialmedia'
    );

    add_settings_field(
      'facebook_socialmedia',
      'Facebook',
      array($this, 'facebook_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'twitter_socialmedia',
      'X (Twitter)',
      array($this, 'twitter_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'instagram_socialmedia',
      'Instagram',
      array($this, 'instagram_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'pinterest_socialmedia',
      'Pinterest',
      array($this, 'pinterest_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'youtube_socialmedia',
      'Youtube',
      array($this, 'youtube_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'linkedin_socialmedia',
      'Linkedin',
      array($this, 'linkedin_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );

    add_settings_field(
      'tiktok_socialmedia',
      'TikTok',
      array($this, 'tiktok_socialmedia_callback'),
      'dealer-settings-socialmedia',
      'socialmedia'
    );
  }

  public function register_policies_settings()
  {
    register_setting(
      'dealer-settings-policies-options-group',
      'dealer-settings-policies-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'policies',
      'Policies',
      array($this, 'print_section_info'),
      'dealer-settings-policies'
    );

    add_settings_field(
      'terms_and_conditions_url',
      'Terms and Conditions URL',
      array($this, 'terms_and_conditions_url_callback'),
      'dealer-settings-policies',
      'policies'
    );

    add_settings_field(
      'privacy_policy_url',
      'Privacy Policy URL',
      array($this, 'privacy_policy_url_callback'),
      'dealer-settings-policies',
      'policies'
    );

    add_settings_field(
      'terms_and_conditions_url_fr',
      'Terms and Conditions (FR)',
      array($this, 'terms_and_conditions_url_fr_callback'),
      'dealer-settings-policies',
      'policies'
    );

    add_settings_field(
      'privacy_policy_url_fr',
      'Privacy Policy (FR)',
      array($this, 'privacy_policy_url_fr_callback'),
      'dealer-settings-policies',
      'policies'
    );
  }
  /**
   * Register and add settings
   */
  public function register_disclaimer_settings()
  {
    register_setting(
      'dealer-settings-disclaimer-options-group',
      'dealer-settings-disclaimer-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'disclaimer',
      'Disclaimer',
      array($this, 'print_section_info'),
      'dealer-settings-disclaimer'
    );
    add_settings_field(
      'disclaimer_new',
      'New',
      array($this, 'disclaimer_new_callback'),
      'dealer-settings-disclaimer',
      'disclaimer'
    );
    add_settings_field(
      'disclaimer_new_fr',
      'New FR',
      array($this, 'disclaimer_new_callback_fr'),
      'dealer-settings-disclaimer',
      'disclaimer'
    );
    add_settings_field(
      'disclaimer_used',
      'Used',
      array($this, 'disclaimer_used_callback'),
      'dealer-settings-disclaimer',
      'disclaimer'
    );
    add_settings_field(
      'disclaimer_used_fr',
      'Used FR',
      array($this, 'disclaimer_used_callback_fr'),
      'dealer-settings-disclaimer',
      'disclaimer'
    );
  }

  public function register_filter_settings()
  {
    register_setting(
      'dealer-settings-filter-options-group',
      'dealer-settings-filter-options',
      array($this, 'sanitize')
    );
    add_settings_section(
      'filter',
      'Filter',
      array($this, 'print_section_info'),
      'dealer-settings-filter'
    );

		add_settings_field(
      'filter_min_number',
      'Limit Result Value',
      array($this, 'filter_min_result_number'),
      'dealer-settings-filter',
      'filter'
    );

    add_settings_field(
      'filter_zero_result',
      'Zero Result Message',
      array($this, 'filter_zero_result_message'),
      'dealer-settings-filter',
      'filter'
    );
    add_settings_field(
      'filter_min_result',
      'Limited Result Message',
      array($this, 'filter_min_result_message'),
      'dealer-settings-filter',
      'filter'
    );

    add_settings_field(
      'filter_zero_result_fr',
      'Zero Result Message Fr',
      array($this, 'filter_zero_result_message_fr'),
      'dealer-settings-filter',
      'filter'
    );
    add_settings_field(
      'filter_min_result_fr',
      'Limited Result Message Fr',
      array($this, 'filter_min_result_message_fr'),
      'dealer-settings-filter',
      'filter'
    );
  }

  public function register_iboost_settings()
  {
    register_setting(
      'dealer-settings-iboost-options-group',
      'dealer-settings-iboost-options',
      array($this, 'sanitize')
    );

    add_settings_section(
      'iboost',
      'iBoost 360',
      array($this, 'print_section_info'),
      'dealer-settings-iboost'
    );
    add_settings_field(
      'iboost_token',
      'Token',
      array($this, 'iboost_token_callback'),
      'dealer-settings-iboost',
      'iboost'
    );
  }

  public function iboost_option_callback()
  {
    if (!isset($this->leadbox_settings['iboost'])) {
      $this->leadbox_settings['iboost'] = "Disabled";
    }

    echo '<select id="iboost" name="leadbox-settings[iboost]">';
    if (strtolower($this->leadbox_settings['iboost']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else if (strtolower($this->leadbox_settings['iboost']) == 'disabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    } else {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }

    echo '</select>';
  }

  public function iboost_token_callback()
  {
    printf(
      '<input type="text" id="iboost_token" name="leadbox-settings[iboost_token]" value="%s" />',
      isset($this->leadbox_settings['iboost_token']) ? esc_attr($this->leadbox_settings['iboost_token']) : ''
    );
  }

  public function live_data_option_callback()
  {
    printf(
      '<input type="text" id="additional_info_live_data" name="leadbox-settings[additional_info_live_data]" value="%s" />',
      isset($this->leadbox_settings['additional_info_live_data']) ? esc_attr($this->leadbox_settings['additional_info_live_data']) : ''
    );
  }

  public function billing_id_option_callback()
  {
    printf(
      '<input type="text" id="additional_info_billing" name="leadbox-settings[additional_info_billing]" value="%s" />',
      isset($this->leadbox_settings['additional_info_billing']) ? esc_attr($this->leadbox_settings['additional_info_billing']) : ''
    );
  }

  public function group_name_option_callback()
  {
    printf(
      '<input type="text" id="additional_info_group_name" name="leadbox-settings[additional_info_group_name]" value="%s" />',
      isset($this->leadbox_settings['additional_info_group_name']) ? esc_attr($this->leadbox_settings['additional_info_group_name']) : ''
    );
  }

  public function enable_lbx_datalayer_callback()
  {
    if (!isset($this->leadbox_settings['enable_lbx_datalayer'])) {
      $this->leadbox_settings['enable_lbx_datalayer'] = "Disabled";
    }
    echo '<select id="enable_lbx_datalayer" name="leadbox-settings[enable_lbx_datalayer]">';
    if (strtolower($this->leadbox_settings['enable_lbx_datalayer']) == 'enabled') {
      echo '<option value="Disabled">Disabled</option>';
      echo '<option selected value="Enabled">Enabled</option>';
    } else {
      echo '<option selected value="Disabled">Disabled</option>';
      echo '<option value="Enabled">Enabled</option>';
    }
    echo '</select>';
  }

  public function leadbox_id_callback()
  {
    printf(
      '<input type="text" id="leadbox_id" name="leadbox-settings[leadbox_id]" value="%s" />',
      isset($this->leadbox_settings['leadbox_id']) ? esc_attr($this->leadbox_settings['leadbox_id']) : ''
    );
  }

  public function terms_and_conditions_url_callback()
  {
    printf(
      '<input type="text" id="terms_and_conditions_url" name="dealer-settings-policies-options[terms_and_conditions_url]" value="%s" />',
      isset($this->policies_options['terms_and_conditions_url']) ? esc_attr($this->policies_options['terms_and_conditions_url']) : ''
    );
  }

  public function privacy_policy_url_callback()
  {
    printf(
      '<input type="text" id="privacy_policy_url" name="dealer-settings-policies-options[privacy_policy_url]" value="%s" />',
      isset($this->policies_options['privacy_policy_url']) ? esc_attr($this->policies_options['privacy_policy_url']) : ''
    );
  }

  public function terms_and_conditions_url_fr_callback()
  {
    printf(
      '<input type="text" id="terms_and_conditions_url_fr" name="dealer-settings-policies-options[terms_and_conditions_url_fr]" value="%s" />',
      isset($this->policies_options['terms_and_conditions_url_fr']) ? esc_attr($this->policies_options['terms_and_conditions_url_fr']) : ''
    );
  }

  public function privacy_policy_url_fr_callback()
  {
    printf(
      '<input type="text" id="privacy_policy_url_fr" name="dealer-settings-policies-options[privacy_policy_url_fr]" value="%s" />',
      isset($this->policies_options['privacy_policy_url_fr']) ? esc_attr($this->policies_options['privacy_policy_url_fr']) : ''
    );
  }

  public function disclaimer_new_callback()
  {
    include('richtext/new.php');
  }
  public function disclaimer_used_callback()
  {
    include('richtext/used.php');
  }

  public function disclaimer_new_callback_fr()
  {
    include('richtext/new-fr.php');
  }
  public function disclaimer_used_callback_fr()
  {
    include('richtext/used-fr.php');
  }

  public function filter_zero_result_message()
  {
    include('richtext/zero-result.php');
  }
  public function filter_min_result_message()
  {
    include('richtext/min-result.php');
  }

	public function filter_min_result_number()
  {
    printf(
      '<input type="number" id="filter_min_number" name="dealer-settings-filter-options[filter_min_number]" value="%s" min="0" step="1"/>',
      isset($this->filter_options['filter_min_number']) ? esc_attr($this->filter_options['filter_min_number']) : ''
    );
  }

  public function filter_zero_result_message_fr()
  {
    include('richtext/zero-result-fr.php');
  }
  public function filter_min_result_message_fr()
  {
    include('richtext/min-result-fr.php');
  }

  public function facebook_socialmedia_callback()
  {
    printf(
      '<input type="text" id="facebook_socialmedia" name="dealer-settings-socialmedia-options[facebook_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['facebook_socialmedia']) ? esc_attr($this->socialmedia_options['facebook_socialmedia']) : ''
    );
  }

  public function twitter_socialmedia_callback()
  {
    printf(
      '<input type="text" id="twitter_socialmedia" name="dealer-settings-socialmedia-options[twitter_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['twitter_socialmedia']) ? esc_attr($this->socialmedia_options['twitter_socialmedia']) : ''
    );
  }

  public function instagram_socialmedia_callback()
  {
    printf(
      '<input type="text" id="instagram_socialmedia" name="dealer-settings-socialmedia-options[instagram_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['instagram_socialmedia']) ? esc_attr($this->socialmedia_options['instagram_socialmedia']) : ''
    );
  }

  public function pinterest_socialmedia_callback()
  {
    printf(
      '<input type="text" id="pinterest_socialmedia" name="dealer-settings-socialmedia-options[pinterest_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['pinterest_socialmedia']) ? esc_attr($this->socialmedia_options['pinterest_socialmedia']) : ''
    );
  }

  public function youtube_socialmedia_callback()
  {
    printf(
      '<input type="text" id="youtube_socialmedia" name="dealer-settings-socialmedia-options[youtube_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['youtube_socialmedia']) ? esc_attr($this->socialmedia_options['youtube_socialmedia']) : ''
    );
  }

  public function linkedin_socialmedia_callback()
  {
    printf(
      '<input type="text" id="linkedin_socialmedia" name="dealer-settings-socialmedia-options[linkedin_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['linkedin_socialmedia']) ? esc_attr($this->socialmedia_options['linkedin_socialmedia']) : ''
    );
  }

  public function tiktok_socialmedia_callback()
  {
    printf(
      '<input type="text" id="tiktok_socialmedia" name="dealer-settings-socialmedia-options[tiktok_socialmedia]" value="%s" />',
      isset($this->socialmedia_options['tiktok_socialmedia']) ? esc_attr($this->socialmedia_options['tiktok_socialmedia']) : ''
    );
  }

  public function img_vehicle_pricing_one()
  {
    echo '<div class="vehicle-pricing-img" style="
    position: absolute;
    right: 100px;
    top: 90px;
    ">
    <img width="400" src="http://cardealerstg.blob.core.windows.net/leadbox/LB-fields.jpg"/>
    </div>';
  }
  public function img_vehicle_pricing_two()
  {
    echo '<div class="vehicle-pricing-img" style="
    position: absolute;
    right: 100px;
    bottom: 70px;
    ">
    <img width="350" src="http://cardealerstg.blob.core.windows.net/leadbox/phones.png"/>
    </div>';
  }

  public function img_vehicle_pricing_three()
  {
    echo '<div class="vehicle-pricing-img" style="
    position: absolute;
    right: 100px;
    bottom: 70px;
    ">
    </div>';
  }

  function prepareData()
  {
    $lbsettings = get_option('leadbox-settings');

    $domain = $_SERVER['SERVER_NAME'];
    $dealer_name = "";
    $group_name = "";
    $primary_make = $lbsettings['manufacturer'];
    $oem_program = $lbsettings['oem_program'];
    $city = "";
    $state = "";
    $country = "";
    $live_date = "";
    $purpose = "";
    $status = "";
    $leadbox_billing = "";
    $main_languague = "";
    $header = print_component_version('header');
    $footer = "";
    $srp_filter = "";
    $vehicle_card = "";
    $vdp_layout = "";
    $vdp_gallery = "";
    $vdp_cta = "";
    $vdp_pricing = "";
    $vdp_financing = "";
    $vdp_lease = "";
    $vdp_description = "";
    $vdp_features = "";
    $vdp_upgrades = "";
    $live_agent = validateServices($lbsettings['live_agent']);
    $carfax = validateServices($lbsettings['carfax']);
    $iboost = validateServices($lbsettings['iboost']);
    $moto_insights = validateServices($lbsettings['moto_insight']);
    $cartender = validateServices($lbsettings['cartender']);
    $ga_token = $lbsettings['google_analytics_id'];
    $gtm_token = $lbsettings['google_tag_manager_token'];
  }
}

if (is_admin())
  $my_settings_page = new LeadboxSettings();

Home - Capital GMC Buick Regina

No data

Welcome to Capital GMC BUICK – REGINA

Thank you for choosing Capital GMC Buick | Regina, your premier certified Buick and GMC dealership proudly serving drivers in Regina and the surrounding communities. Whether you’re searching for a brand-new Buick or GMC vehicle or a meticulously inspected pre-owned model, we have a diverse selection to match your needs and lifestyle.

Beyond our impressive inventory, we offer a seamless and stress-free financing experience through our well-connected finance centre, where our team of experts is dedicated to securing the best loan or lease options for you, quickly, transparently, and hassle-free.

But our commitment to you doesn’t stop at the sale. Our state-of-the-art service centre is staffed with skilled Buick and GMC technicians who use the latest equipment and genuine OEM parts to keep your vehicle running at its best. From routine maintenance to complex repairs, we’ve got you covered.

Experience top-tier customer service, quality vehicles, and expert care, all in one place. Visit Capital GMC Buick | Regina today or call us at 306-205-8072 with any questions. We’re here to help!

Ask a Question