<?php
/**
 * Plugin Name: Team MXT - Team Member Showcase
 * Plugin URI:  https://www.webmxt.com/product/team-mxt-plugin/
 * Description: A WordPress plugin to manage and display team member profiles.
 * Version:     1.0.0
 * Author:      WebMXT
 * Author URI:  https://webmxt.com
 * License:     GPL v2 or later
 * Text Domain: team-mxt
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 * Requires PHP: 7.0
 * Requires at least: 5.2
 */

if (!defined('ABSPATH')) {
    exit;
}
define('TEAM_MXT_VERSION', '1.0.0');

class Team_MXT
{
    public function __construct()
    {
        register_activation_hook(__FILE__, array($this, 'activate'));
        register_deactivation_hook(__FILE__, array($this, 'deactivate'));
        register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
        add_action('admin_enqueue_scripts', array($this, 'team_mxt_enqueue_scripts'));
        add_action('admin_enqueue_scripts', array($this, 'team_mxt_enqueue_admin_styles'));
        add_action('admin_menu', array($this, 'team_mxt_add_admin_pages'));
        add_action('admin_init', array($this, 'save_member'));
        add_action('wp_ajax_team_mxt_live_preview', array($this, 'handle_live_preview'));
        add_action('admin_post_team_mxt_save_member', array($this, 'save_member'));
        add_action('admin_init', array($this, 'team_mxt_handle_member_deletion'));
        add_action('admin_post_team_mxt_update_member', array($this, 'team_mxt_update_member'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_admin_scripts'));
        add_action('init', array($this, 'register_shortcodes'));
        add_shortcode('team_mxt', array($this, 'display_members_shortcode'));
        add_action('init', array($this, 'register_plugin_styles'));
        add_action('wp_ajax_team_mxt_unique_live_preview', array($this, 'team_mxt_unique_live_preview'));
        add_action('wp_enqueue_scripts', array($this, 'team_mxt_enqueue_frontend_styles'), 999);
        add_action('wp_enqueue_scripts', array($this, 'enqueue_team_mxt_custom_scripts'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_custom_scripts'));
        add_action('admin_enqueue_scripts', array($this, 'team_mxt_enqueue_admin_scripts'));
        add_action('wp_enqueue_scripts', array($this, 'team_mxt_enqueue_scripts_styles'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_admin_settings'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_admin_all_members'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_admin_nav'));
        add_action('admin_enqueue_scripts', array($this, 'enqueue_team_mxt_output_preview'));
        add_action('admin_enqueue_scripts', array($this, 'team_mxt_enqueue_dynamic_style'));
        add_action('admin_enqueue_scripts', array($this, 'tem_mxt_tutorial_styles'));
    }
    public function activate()
    {
        $this->install();
    }

    public function deactivate()
    {
        // Deactivation logic, if any
    }

    public static function uninstall()
    {
        delete_option('team_mxt_version');
        delete_option('team_mxt_all_members');
        delete_option('team_mxt_use_carousel');
    }

    private function install()
    {
        if (!get_option('team_mxt_version')) {
            update_option('team_mxt_version', 'TEAM_MXT_VERSION');
        }
    }

    public function team_mxt_enqueue_scripts($hook)
    {
        wp_enqueue_script('team-mxt-admin-script', plugin_dir_url(__FILE__) . 'js/admin-scripts.js', array('jquery'), 'TEAM_MXT_VERSION', true);
        wp_localize_script('team-mxt-admin-script', 'team_mxt_data', array('ajax_url' => admin_url('admin-ajax.php')));
        if ('toplevel_page_team_mxt' === $hook || 'team-mxt_page_team_mxt_edit_member' === $hook) {
            wp_enqueue_media();
            $translation_array = array(
                'ajax_url' => admin_url('admin-ajax.php'),
                'plugin_url' => plugin_dir_url(__FILE__),
            );
            wp_localize_script('team-mxt-admin-script', 'team_mxt_data', $translation_array);
        }
    }

    public function team_mxt_enqueue_admin_styles($hook) {
        if ('toplevel_page_team_mxt' !== $hook && 'team-mxt_page_team_mxt_add_member' !== $hook && 'team-mxt_page_team_mxt_edit_member' !== $hook && 'team-mxt_page_team_mxt_all_members' !== $hook && 'team-mxt_page_team_mxt_settings' !== $hook) {
            return;
        }
        
        wp_enqueue_style('font-awesome', plugin_dir_url(__FILE__) . 'css/all.min.css', array(), '5.15.4');
        wp_enqueue_style('team-mxt-admin-style', plugin_dir_url(__FILE__) . 'css/admin-style.css', array(), 'TEAM_MXT_VERSION', 'all');
        
        wp_enqueue_style('team-mxt-popup', plugin_dir_url(__FILE__) . 'css/popup.css', array(), 'TEAM_MXT_VERSION');

        // Existing script localization
        $translation_array = array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'plugin_url' => plugin_dir_url(__FILE__),
        );
        wp_localize_script('team-mxt-admin-script', 'team_mxt_data', $translation_array);
    }

    public function team_mxt_add_admin_pages()
    {
        add_menu_page('Team MXT', 'Team MXT', 'manage_options', 'team_mxt', array($this, 'admin_index'), 'dashicons-groups', 110);
        add_submenu_page('team_mxt', 'Add Member', 'Add Member', 'manage_options', 'team_mxt_add_member', array($this, 'admin_add_member'));
        add_submenu_page('team_mxt', 'All Members', 'All Members', 'manage_options', 'team_mxt_all_members', array($this, 'admin_all_members'));
        add_submenu_page('team_mxt', 'License Management', 'License', 'manage_options', 'team_mxt_license_management', array($this, 'admin_license_page'));
        add_submenu_page('team_mxt', 'Tutorial', 'Tutorial', 'manage_options', 'team_mxt_tutorial', array($this, 'admin_tutorial'));
        add_submenu_page('team_mxt', 'Edit Team Member', 'Edit Member', 'manage_options', 'team_mxt_edit_member', array($this, 'team_mxt_render_edit_member_page'));
        add_submenu_page('team_mxt', 'Settings', 'Settings', 'manage_options', 'team_mxt_settings', array($this, 'admin_settings_page'));
    }

    public function save_member()
    {
        include plugin_dir_path(__FILE__) . 'partials/save-member.php';
    }

    public function handle_live_preview()
    {
        include plugin_dir_path(__FILE__) . 'partials/add-member-preview.php';
    }

    public function team_mxt_handle_member_deletion()
    {
        if (isset($_GET['page'], $_GET['action'], $_GET['member_index']) && $_GET['page'] === 'team_mxt_all_members' && $_GET['action'] === 'delete' && current_user_can('manage_options')) {
            $member_index = sanitize_text_field(wp_unslash($_GET['member_index']));
            check_admin_referer('delete_member_' . $member_index);

            $all_members = get_option('team_mxt_all_members', []);
            $index_to_delete = isset($_GET['member_index']) ? intval(wp_unslash($_GET['member_index'])) : 0;
            array_splice($all_members, $index_to_delete, 1);
            update_option('team_mxt_all_members', $all_members);

            wp_redirect(admin_url('admin.php?page=team_mxt_all_members'));
            exit;
        }
    }

    public function team_mxt_update_member()
    {
        if (
            isset($_POST['action'], $_POST['member_index']) && 
            sanitize_text_field(wp_unslash($_POST['action'])) === 'team_mxt_update_member' &&
            check_admin_referer('team_mxt_edit_member_nonce') && 
            current_user_can('manage_options')
        ) {
            $member_index = intval($_POST['member_index']);
            $all_members = get_option('team_mxt_all_members', []);

            if (!isset($all_members[$member_index])) {
                wp_die('Member not found');
            }

            $member = $all_members[$member_index];

            $member['name'] = sanitize_text_field(wp_unslash($_POST['team_mxt_member_name'] ?? ''));
            $member['designation'] = sanitize_text_field(wp_unslash($_POST['team_mxt_member_designation'] ?? ''));
            $member['phone'] = sanitize_text_field(wp_unslash($_POST['team_mxt_member_phone'] ?? ''));
            $member['email'] = sanitize_email(wp_unslash($_POST['team_mxt_member_email'] ?? ''));
            $member['website'] = esc_url_raw(wp_unslash($_POST['team_mxt_member_website'] ?? ''));
            $member['photo_id'] = isset($_POST['team_mxt_member_photo']) ? intval($_POST['team_mxt_member_photo']) : '';

            $social_media_fields = [
                'facebook',
                'twitter',
                'linkedin',
            ];

            foreach ($social_media_fields as $field) {
                $member['social'][$field] = sanitize_text_field(wp_unslash($_POST['team_mxt_member_' . $field] ?? ''));
            }

            for ($i = 1; $i <= 3; $i++) {
                $expertise_area = sanitize_text_field(wp_unslash($_POST['team_mxt_member_expertise_' . $i] ?? ''));
                $expertise_percent = absint(wp_unslash($_POST['team_mxt_member_expertise_percent_' . $i] ?? 0));
                $member['expertise'][$i - 1] = ['area' => $expertise_area, 'percent' => $expertise_percent];
            }

            $member['priority'] = isset($_POST['team_mxt_member_priority']) ? absint($_POST['team_mxt_member_priority']) : 0;
            $all_members[$member_index] = $member;
            update_option('team_mxt_all_members', $all_members);
            wp_redirect(admin_url('admin.php?page=team_mxt_all_members'));
            exit;
        }
    }

    public function enqueue_team_mxt_admin_scripts($hook)
    {
        wp_enqueue_style('team-mxt-admin-style', plugin_dir_url(__FILE__) . 'css/admin-style.css', array(), 'TEAM_MXT_VERSION', 'all');
        wp_enqueue_script('team-mxt-admin-script', plugin_dir_url(__FILE__) . 'js/admin-scripts.js', array('jquery'), 'TEAM_MXT_VERSION', true);
        wp_enqueue_style('team-mxt-coloris-style', plugin_dir_url(__FILE__) . 'css/coloris.min.css', array(), 'TEAM_MXT_VERSION', 'all');
        wp_enqueue_script('team-mxt-coloris-script', plugin_dir_url(__FILE__) . 'js/coloris.min.js', array('jquery'), 'TEAM_MXT_VERSION', true);

        if ('toplevel_page_team_mxt' === $hook || 'team-mxt_page_team_mxt_add_member' === $hook || 'team-mxt_page_team_mxt_edit_member' === $hook) {
            wp_enqueue_media();
            wp_enqueue_script('image-preview', plugin_dir_url(__FILE__) . 'js/image-preview.js', array('jquery'), 'TEAM_MXT_VERSION', true);
            $translation_array = array(
                'ajax_url' => admin_url('admin-ajax.php'),
                'plugin_url' => plugin_dir_url(__FILE__),
            );
            wp_localize_script('team-mxt-admin-script', 'team_mxt_data', $translation_array);
        }
        if ('toplevel_page_team_mxt' === $hook || 'team-mxt_page_team_mxt_add_member' === $hook || 'team-mxt_page_team_mxt_edit_member' === $hook || 'team-mxt_page_team_mxt_all_members' === $hook || 'team-mxt_page_team_mxt_settings' === $hook) {
            // Fetch the option to check if the carousel is enabled

            wp_enqueue_style('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.css', array(), '2.3.4');
            wp_enqueue_style('owl-carousel-theme', plugin_dir_url(__FILE__) . 'owlcarousel/owl.theme.default.min.css', array(), '2.3.4');
            wp_enqueue_script('jquery');
            wp_enqueue_script('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.js', array('jquery'), '2.3.4', true);
            wp_enqueue_style('team-mxt-simple-style', plugin_dir_url(__FILE__) . 'css/carousel/carousel.css', array(), 'TEAM_MXT_VERSION', 'all');
            // Existing admin styles and scripts
            wp_enqueue_style('team-mxt-admin-style', plugin_dir_url(__FILE__) . 'css/admin-style.css', array(), 'TEAM_MXT_VERSION', 'all');
            wp_enqueue_script('team-mxt-admin-script', plugin_dir_url(__FILE__) . 'js/admin-scripts.js', array('jquery'), 'TEAM_MXT_VERSION', true);
            wp_localize_script('team-mxt-admin-script', 'team_mxt_data', array('ajax_url' => admin_url('admin-ajax.php'), 'plugin_url' => plugin_dir_url(__FILE__)));
        }
    }

    public function register_shortcodes()
    {
        ob_start();
        add_shortcode('team_mxt_members', array($this, 'display_members_shortcode'));
        add_shortcode('team_mxt_without_slider', array($this, 'display_members_z_shortcode'));
        ob_end_flush();
    }

    public function display_members_shortcode($atts)
    {
        wp_enqueue_style('font-awesome', plugin_dir_url(__FILE__) . 'css/all.min.css', array(), '5.15.4');
        wp_enqueue_style('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.css', array(), '2.3.4');
        wp_enqueue_style('owl-carousel-theme', plugin_dir_url(__FILE__) . 'owlcarousel/owl.theme.default.min.css', array(), '2.3.4');
        wp_enqueue_script('jquery');
        wp_enqueue_script('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.js', array('jquery'), '2.3.4', true);
        wp_enqueue_style('team-mxt-simple-style', plugin_dir_url(__FILE__) . 'css/carousel/carousel.css', array(), 'TEAM_MXT_VERSION', 'all');

        $atts = shortcode_atts(array('style' => 'style_1'), $atts, 'team_mxt');
        $selected_style = $atts['style'];
        wp_enqueue_style('team-mxt-style-' . str_replace('style_', '', $selected_style), plugin_dir_url(__FILE__) . 'css/' . esc_attr($selected_style) . '.css', array(), 'TEAM_MXT_VERSION', 'all');
        $all_members = get_option('team_mxt_all_members', []);
        foreach ($all_members as $key => $member) {
            $photo_id = $member['photo_id'];
            $all_members[$key]['photo_url'] = $photo_id ? wp_get_attachment_url($photo_id) : 'path-to-default-image';
        }
        
        // Add fallback Font Awesome styles
        
        ob_start();
        include plugin_dir_path(__FILE__) . 'partials/output.php';
        $content = ob_get_clean();
        
        return $content;
    }

    public function display_members_z_shortcode($atts)
    {
        wp_enqueue_style('team-mxt-simple-style', plugin_dir_url(__FILE__) . 'css/carousel/simple.css', array(), 'TEAM_MXT_VERSION', 'all');
        if (!function_exists('my_theme_scripts')) {
            function my_theme_scripts()
            {
                wp_enqueue_script('jquery');
            }
            add_action('wp_enqueue_scripts', 'my_theme_scripts');
        }
        $atts = shortcode_atts(array('style' => 'style_1'), $atts, 'team_mxt_without_slider');
        $selected_style = $atts['style'];
        wp_enqueue_style('team-mxt-style-' . str_replace('style_', '', $selected_style), plugin_dir_url(__FILE__) . 'css/' . esc_attr($selected_style) . '.css', array(), 'TEAM_MXT_VERSION', 'all');
        $all_members = get_option('team_mxt_all_members', []);
        foreach ($all_members as $key => $member) {
            $photo_id = $member['photo_id'];
            $all_members[$key]['photo_url'] = $photo_id ? wp_get_attachment_url($photo_id) : 'path-to-default-image'; // Replace 'path-to-default-image' with default image path
        }
        ob_start();

        include plugin_dir_path(__FILE__) . 'partials/output-without-slider.php';
     
        return ob_get_clean();
    }

    public function register_plugin_styles()
    {
        for ($i = 1; $i <= 30; $i++) {
            wp_register_style('team-mxt-style-' . $i, plugin_dir_url(__FILE__) . 'css/style-' . $i . '.css', array(), 'TEAM_MXT_VERSION', 'all');
            $style_settings_path = plugin_dir_path(__FILE__) . 'style-settings-partials/style-settings-save/style-' . $i . '-settings.php';
            if (file_exists($style_settings_path)) {
                include $style_settings_path;
            }
        }
    }

    public function team_mxt_unique_live_preview()
    {
        $use_carousel = get_option('team_mxt_use_carousel', false);
        if ('1' === $use_carousel) {
            wp_enqueue_style('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.css', array(), '2.3.4');
            wp_enqueue_style('owl-carousel-theme', plugin_dir_url(__FILE__) . 'owlcarousel/owl.theme.default.min.css', array(), '2.3.4');
            wp_enqueue_script('jquery');
            wp_enqueue_script('owl-carousel', plugin_dir_url(__FILE__) . 'owlcarousel/owl.carousel.min.js', array('jquery'), '2.3.4', true);
            wp_enqueue_style('team-mxt-simple-style', plugin_dir_url(__FILE__) . 'css/carousel/carousel.css', array(), 'TEAM_MXT_VERSION', 'all');

        } else {
            wp_enqueue_style('team-mxt-simple-style', plugin_dir_url(__FILE__) . 'css/carousel/simple.css', array(), 'TEAM_MXT_VERSION', 'all');
            if (!function_exists('my_theme_scripts')) {
                function my_theme_scripts()
                {
                    wp_enqueue_script('jquery');
                }
                add_action('wp_enqueue_scripts', 'my_theme_scripts');
            }
        }
        if (!current_user_can('manage_options')) {
            wp_die('Permission Denied');
        }
        $style = isset($_POST['style']) && (wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'] ?? '')), 'select_style_nonce') || !isset($_POST['_wpnonce'])) ? sanitize_text_field(wp_unslash($_POST['style'])) : 'style_1';
        $all_members = get_option('team_mxt_all_members', []);
        foreach ($all_members as $key => $member) {
            $photo_id = $member['photo_id'];
            $all_members[$key]['photo_url'] = $photo_id ? wp_get_attachment_url($photo_id) : 'path-to-default-image';
        }
        wp_enqueue_script('team-mxt-admin-script', plugin_dir_url(__FILE__) . 'js/scroll.js', array('jquery'), 'TEAM_MXT_VERSION', true);
        ob_start();

        include plugin_dir_path(__FILE__) . 'partials/output-preview.php';
            
        $html = ob_get_clean();
        wp_send_json_success(array('html' => $html));
    }

    public function team_mxt_enqueue_frontend_styles() {
        // Check if current page has our shortcode
        global $post;
        if (!is_object($post) || (!has_shortcode($post->post_content, 'team_mxt') && !has_shortcode($post->post_content, 'team_mxt_members') && !has_shortcode($post->post_content, 'team_mxt_without_slider'))) {
            return;
        }
    
        $plugin_url = plugin_dir_url(__FILE__);
    
        // Check if Font Awesome is needed
        $all_members = get_option('team_mxt_all_members', []);
        $needs_fontawesome = false;
        foreach ($all_members as $member) {
            if (!empty($member['social'])) {
                $needs_fontawesome = true;
                break;
            }
        }
    
        // Enqueue Font Awesome if needed
        if ($needs_fontawesome) {
            wp_enqueue_style('team-mxt-font-awesome', $plugin_url . 'css/all.min.css', array(), '5.15.4');
        }
    
        // Check and enqueue popup if needed
        $settings = get_option('team_mxt_settings', []);
        if (isset($settings['enable_popup']) && $settings['enable_popup'] === 'yes') {
            wp_enqueue_style('team-mxt-popup', $plugin_url . 'css/popup.css', array(), TEAM_MXT_VERSION);
        }
    }

    public function enqueue_team_mxt_custom_scripts() {
        // Check if current page has our shortcode
        global $post;
        if (!is_object($post) || (!has_shortcode($post->post_content, 'team_mxt') && !has_shortcode($post->post_content, 'team_mxt_members') && !has_shortcode($post->post_content, 'team_mxt_without_slider'))) {
            return;
        }
        
        // Check if custom fonts are being used
        $settings = get_option('team_mxt_settings', []);
        $custom_fonts_enabled = isset($settings['use_custom_fonts']) && $settings['use_custom_fonts'] === 'yes';
        
        // Only load webfontloader if custom fonts are enabled
        if ($custom_fonts_enabled) {
            wp_enqueue_script('team-mxt-webfont', plugin_dir_url(__FILE__) . 'js/webfontloader.js', array(), '1.6.26', true);
        }
    }

    public function admin_index()
    {
        include plugin_dir_path(__FILE__) . 'partials/admin-display.php';
    }

    public function admin_add_member()
    {
        include plugin_dir_path(__FILE__) . 'partials/admin-display.php';
    }

    public function admin_all_members()
    {
        ob_start();

        include plugin_dir_path(__FILE__) . 'partials/admin-all-members.php';
        ob_end_flush();
    }

    public function admin_license_page()
    {
        include plugin_dir_path(__FILE__) . 'partials/admin-license.php';
    }

    public function admin_tutorial()
    {
        include plugin_dir_path(__FILE__) . 'partials/tutorial.php';
    }

    public function admin_settings_page()
    {
        if (!current_user_can('manage_options')) {
            return;
        }

        $selected_style = isset($_GET['style']) && (wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'select_style_nonce') || !isset($_GET['_wpnonce'])) ? intval($_GET['style']) : 1;

        include plugin_dir_path(__FILE__) . 'partials/admin-settings.php';
    }

    public function team_mxt_render_edit_member_page()
    {
        wp_enqueue_media();
        include plugin_dir_path(__FILE__) . 'edit-member.php';
    }

    function team_mxt_enqueue_admin_scripts($hook) {
        if ('team-mxt_page_team_mxt_edit_member' !== $hook) {
            return;
        }
        wp_enqueue_script('jquery');
        wp_enqueue_script('team-mxt-edit-member', plugins_url('js/edit-member.js', __FILE__), array('jquery'), '1.0', true);
        wp_enqueue_style('team-mxt-edit-member', plugins_url('css/edit-member.css', __FILE__), array(), '1.0');
    }
    
    function team_mxt_enqueue_scripts_styles() {
        global $post;
        if (!is_object($post) || (!has_shortcode($post->post_content, 'team_mxt') && !has_shortcode($post->post_content, 'team_mxt_without_slider'))) {
            return;
        }
        
        $plugin_url = plugin_dir_url(__FILE__);
        
        wp_enqueue_style('team-mxt-style', $plugin_url . 'css/output.css', array(), TEAM_MXT_VERSION);
        wp_enqueue_style('team-mxt-styles', $plugin_url . 'css/output-without-slider.css', array(), TEAM_MXT_VERSION);
        
        wp_enqueue_script('team-mxt-script', $plugin_url . 'js/output.js', array('jquery'), TEAM_MXT_VERSION, true);
        wp_enqueue_script('team-mxt-scripts', $plugin_url . 'js/output-without-slider.js', array('jquery'), TEAM_MXT_VERSION, true);
        
        // Get all required PHP variables
        $cards_in_row_pc = get_option('team_mxt_cards_in_row_pc', 3);
        $cards_in_row_tablet = get_option('team_mxt_cards_in_row_tablet', 2);
        $all_members = get_option('team_mxt_all_members', []);
        
        // Prepare data to pass to JavaScript
        $team_mxt_data = array(
            'cardsInRowPc' => $cards_in_row_pc,
            'cardsInRowTablet' => $cards_in_row_tablet,
            'allMembers' => $all_members
        );
        
        // Localize script for both JavaScript files
        wp_localize_script('team-mxt-script', 'teamMxtData', $team_mxt_data);
        wp_localize_script('team-mxt-scripts', 'teamMxtData', $team_mxt_data);
    }
    
    public function enqueue_team_mxt_admin_settings($hook = '') {
    $plugin_url = plugin_dir_url(__FILE__);
    if ('team-mxt_page_team_mxt_settings' === $hook) {
        wp_enqueue_style('team-mxt-admin-settings-style', $plugin_url . 'css/admin-settings.css', array(), 'TEAM_MXT_VERSION');
        wp_enqueue_script('team-mxt-admin-settings-script', $plugin_url . 'js/admin-settings.js', array('jquery'), 'TEAM_MXT_VERSION', true);
    }
    wp_enqueue_style('team-mxt-styles', $plugin_url . 'css/admin-display.css', array(), TEAM_MXT_VERSION);
    wp_localize_script('team-mxt-admin-settings-script', 'team_mxt_data', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'plugin_url' => $plugin_url,
        'form_submitted' => (
    isset($_POST['team_mxt_settings_submit']) &&
    isset($_POST['team_mxt_settings_nonce']) &&
    wp_verify_nonce(
        sanitize_text_field(wp_unslash($_POST['team_mxt_settings_nonce'])),
        'team_mxt_settings_action'
    )
) ? true : false
    ));
}

    public function enqueue_team_mxt_admin_all_members($hook) {
    if ('team-mxt_page_team_mxt_all_members' !== $hook) return;
    $plugin_url = plugin_dir_url(__FILE__);
    wp_enqueue_style('team-mxt-admin-all-members', $plugin_url . 'css/admin-all-members.css', array(), 'TEAM_MXT_VERSION');
    wp_enqueue_script('team-mxt-admin-all-members', $plugin_url . 'js/admin-all-members.js', array('jquery'), 'TEAM_MXT_VERSION', true);
    wp_localize_script('team-mxt-admin-all-members', 'team_mxt_data', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'plugin_url' => $plugin_url
    ));
}

public function enqueue_team_mxt_admin_nav() {
    $plugin_url = plugin_dir_url(__FILE__);
    if (is_admin()) wp_enqueue_style('team-mxt-admin-settings', $plugin_url . 'css/admin-nav.css', array(), 'TEAM_MXT_VERSION', 'all');
}

public function enqueue_team_mxt_output_preview() {
    wp_enqueue_style('team-mxt-output-preview-style', plugin_dir_url(__FILE__) . 'css/output-preview.css', array(), TEAM_MXT_VERSION);
    wp_enqueue_script('team-mxt-output-preview-script', plugin_dir_url(__FILE__) . 'js/output-preview.js', array('jquery'), TEAM_MXT_VERSION, true);
    
    // Get the necessary data
    $cards_in_row_pc = get_option('team_mxt_cards_in_row_pc', 3);
    $cards_in_row_tablet = get_option('team_mxt_cards_in_row_tablet', 2);
    $use_carousel = get_option('team_mxt_use_carousel', '0');
    $all_members = get_option('team_mxt_all_members', []);

    // Prepare the data to be passed to JavaScript
    $team_member_data = array(
        'cardsInRowPc' => $cards_in_row_pc,
        'cardsInRowTablet' => $cards_in_row_tablet,
        'useCarousel' => $use_carousel,
        'allMembers' => $all_members
    );

    // Pass PHP variables to JavaScript
    wp_localize_script('team-mxt-output-preview-script', 'teamMxtData', $team_member_data);
}
function team_mxt_enqueue_dynamic_style() {
    wp_enqueue_style('team-mxt-dynamic-style', false, array(), TEAM_MXT_VERSION);
    wp_add_inline_style('team-mxt-dynamic-style', '');
}

function tem_mxt_tutorial_styles() {
    wp_enqueue_style('tem-mxt-tutorial', plugins_url('css/tutorial.css', __FILE__));
 }
    }

$team_mxt_plugin = new Team_MXT();