<?php
 
 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Generates a dynamic Email Form List
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - EMAILS FORM LIST
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    EMAILS FORM LIST
============================================================
*/

global $wpdb;

$messages_table_name = $wpdb->prefix . 'BlueRavenMessages';
$messages = $wpdb->get_results("SELECT id, title, shortcode FROM $messages_table_name", ARRAY_A);

if (!empty($messages)) {
    foreach ($messages as $message) {
        $form_id = esc_attr($message['id']);
        $form_name = esc_html($message['title']);
        $form_shortcode = esc_html($message['shortcode']);

        echo '<div class="flex-sb mail-list-item" data-id="' . esc_attr($form_id) . '" style="padding:1rem 0.5rem;">';
        echo '    <p class="mli-name">' . esc_html($form_name) . '</p>';
        echo '    <div class="flex-sb" style="min-width: 50%;">';
        echo '      <p class="mli-code">[' . esc_html($form_shortcode) . ']</p>';
        echo '      <div class="flex-sb" style="width: 7rem">';
        echo '          <p class="mli-edit">Edit</p>';
        echo '          <p class="mli-delete">❌</p>';
        echo '      </div>';
        echo '    </div>';
        echo '</div>';
    }
} else {
    echo '<p>' . esc_html__('No forms found.', 'blue-raven') . '</p>';
}