
<?php
/*
Plugin Name: Vinesh Contact Form Ultimate
Description: Drag & drop form builder, database storage, auto-responder, HTML email templates.
Version: 3.0
Author: Vinesh
*/

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

define('VACF_PATH', plugin_dir_path(__FILE__));
define('VACF_URL', plugin_dir_url(__FILE__));

register_activation_hook(__FILE__, 'vacf_install');

require_once VACF_PATH.'includes/admin-builder.php';
require_once VACF_PATH.'includes/shortcode.php';

add_action('admin_enqueue_scripts', function() {
    wp_enqueue_script('vacf-builder', VACF_URL.'assets/builder.js', ['jquery'], null, true);
    wp_enqueue_style('vacf-style', VACF_URL.'assets/style.css');
});

function vacf_install() {
    global $wpdb;
    $charset = $wpdb->get_charset_collate();

    $wpdb->query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}vacf_forms (
        id BIGINT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(200),
        layout VARCHAR(50),
        fields LONGTEXT,
        admin_template LONGTEXT,
        user_template LONGTEXT
    ) $charset;");

    $wpdb->query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}vacf_submissions (
        id BIGINT AUTO_INCREMENT PRIMARY KEY,
        form_id BIGINT,
        data LONGTEXT,
        created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    ) $charset;");
}
