<?php
class Sifency_Ajax {

    public function __construct() {
        // Hook for logged-in users
        add_action( 'wp_ajax_sifency_install_theme', [ $this, 'install_theme' ] );
        add_action( 'wp_ajax_sifency_install_plugin', [ $this, 'install_plugin' ] );
        add_action( 'wp_ajax_sifency_import_data', [ $this, 'import_demo_data' ] );
    }

    // STEP 1: Install the required theme (if needed)
    public function install_theme() {
        check_ajax_referer( 'sifency_demo_import_nonce', 'nonce' );
        
        wp_send_json_success( ['message' => 'Theme installed and activated.', 'next_step' => 'install_plugins'] );
    }

    public function install_plugin() {
        check_ajax_referer( 'sifency_demo_import_nonce', 'nonce' );

        $plugin_slug = sanitize_text_field( $_POST['plugin_slug'] ); 
        
        wp_send_json_success( ['message' => $plugin_slug . ' installed and activated.', 'next_step' => 'next_plugin_or_import_data'] );
    }

    public function import_demo_data() {
        check_ajax_referer( 'sifency_demo_import_nonce', 'nonce' );
        $demo_file = sanitize_text_field( $_POST['demo_file'] );
        wp_send_json_success( ['message' => 'Demo data imported successfully.', 'next_step' => 'finished'] );
    }
}