<?php
/**
 * The core plugin class.
 */
class FixReport {

	/**
	 * The loader that's responsible for maintaining and registering all hooks that power
	 * the plugin. Although we are adding hooks directly in this example, a loader class
	 * is a common practice in more complex plugins.
	 *
	 * @since    1.0.1
	 * @access   protected
	 * @var      object    $loader    Maintains and registers all hooks for the plugin.
	 */
	// protected $loader; // Example for a hook loader class

	/**
	 * The unique identifier (slug) of this plugin.
	 *
	 * @since    1.0.1
	 * @access   protected
	 * @var      string    $plugin_name_slug    The string used to uniquely identify this plugin.
	 */
	protected $plugin_name_slug;

	/**
	 * The current version of the plugin.
	 *
	 * @since    1.0.1
	 * @access   protected
	 * @var      string    $version    The current version of the plugin.
	 */
	protected $version;

    /**
     * The admin-specific functionality handler.
     *
     * @since    1.0.1
     * @access   protected
     * @var      FixReport_Admin    $admin    Instance of the admin class.
     */
    protected $admin;

	/**
	 * Define the core functionality of the plugin.
	 *
	 * @since    1.0.1
	 */
	public function __construct() {
		if ( defined( 'FIXREPORT_VERSION' ) ) {
			$this->version = FIXREPORT_VERSION;
		} else {
			$this->version = '1.0.1';
		}
		$this->plugin_name_slug = 'fixreport-maintenance-logger';

		$this->load_dependencies();
		$this->set_locale();
        // Hooks are defined in the run() method now
	}

	/**
	 * Load the required dependencies for this plugin.
	 *
	 * @since    1.0.1
	 * @access   private
	 */
	private function load_dependencies() {
        if ( ! class_exists( 'FixReport_DB' ) ) {
            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-fixreport-db.php';
        }
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-fixreport-admin.php';
        if ( ! class_exists( 'FixReport_Exporter' ) ) {
            $includes_path = defined('FIXREPORT_PATH') ? FIXREPORT_PATH . 'includes/' : plugin_dir_path( dirname( __FILE__ ) ) . 'includes/';
            $exporter_file = $includes_path . 'class-fixreport-exporter.php';
            if ( file_exists( $exporter_file ) ) {
                require_once $exporter_file;
            }
        }
	}

	/**
	 * Define the locale for this plugin for internationalization.
	 *
	 * @since    1.0.1
	 * @access   private
	 */
	private function set_locale() {
		add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
	}

	/**
	 * Load the plugin text domain for translation.
	 *
	 * @since    1.0.1
	 */
	public function load_plugin_textdomain() {
		load_plugin_textdomain(
			'fixreport-maintenance-logger',
			false,
			dirname( FIXREPORT_BASENAME ) . '/languages/'
		);
	}

	/**
	 * Register all of the hooks related to the admin area functionality
	 * of the plugin.
	 *
	 * @since    1.0.1
	 * @access   private
	 */
	private function define_admin_hooks() {
		$this->admin = new FixReport_Admin( $this->get_plugin_name(), $this->get_version() );

		// Hook for adding the menu page
		add_action( 'admin_menu', array( $this->admin, 'add_plugin_admin_menu' ) );
        
        // Hook for enqueuing admin styles and scripts
        add_action( 'admin_enqueue_scripts', array( $this->admin, 'enqueue_styles' ) );
        add_action( 'admin_enqueue_scripts', array( $this->admin, 'enqueue_scripts' ) );

        // Hooks for form submissions (admin-post actions)
        add_action( 'admin_post_fixreport_add_log', array( $this->admin, 'handle_add_log_submission' ) );
        add_action( 'admin_post_fixreport_update_log', array( $this->admin, 'handle_update_log_submission' ) );
        add_action( 'admin_post_fixreport_delete_log', array( $this->admin, 'handle_delete_log_submission' ) );
        add_action( 'admin_post_fixreport_export_pdf', array( $this->admin, 'handle_export_pdf_submission' ) );
	}

	/**
	 * Run the plugin by defining all the hooks.
	 *
	 * @since    1.0.1
	 */
	public function run() {
		$this->define_admin_hooks();
        // If you had public-facing hooks, you would call define_public_hooks() here too.
	}


	/**
	 * Retrieve the name (slug) of the plugin.
	 * @since     1.0.1
	 * @return    string    The slug of the plugin.
	 */
	public function get_plugin_name() {
		return $this->plugin_name_slug;
	}

	/**
	 * Retrieve the version number of the plugin.
	 * @since     1.0.1
	 * @return    string    The version number of the plugin.
	 */
	public function get_version() {
		return $this->version;
	}

}