<?php

namespace SoftMultimediaPlayer;

defined( 'ABSPATH' ) || exit;
final class Main {
    /**
     * The single instance of the class.
     *
     * @var Main
     * @since 1.0.0
     */
    protected static $instance = null;

    /**
     * Constructor
     *
     * @since 1.0.0
     */
    public function __construct() {
        $this->includes();
        $this->init_hooks();
        register_activation_hook( SOFT_MULTIMEDIA_PLAYER_FILE, array($this, 'activate') );
        do_action( 'smp_loaded' );
    }

    /**
     * Include required core files.
     *
     * @since 1.0.0
     */
    public function includes() {
        /* core includes */
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/functions.php';
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Enqueue.php';
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Hooks.php';
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Shortcode.php';
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Ajax.php';
        /* block */
        include_once SOFT_MULTIMEDIA_PLAYER_PATH . '/block/Block.php';
        /* tinymce */
        include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Tinymce.php';
        /* elementor */
        include_once SOFT_MULTIMEDIA_PLAYER_PATH . '/elementor/Elementor.php';
        /* admin includes */
        if ( is_admin() ) {
            include_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Admin.php';
        }
    }

    public function init_hooks() {
        add_action( 'init', [$this, 'localization_setup'] );
        /* action_links */
        add_filter( 'plugin_action_links_' . plugin_basename( SOFT_MULTIMEDIA_PLAYER_FILE ), [$this, 'plugin_action_links'] );
    }

    public function localization_setup() {
        load_plugin_textdomain( 'soft-multimedia-player', false, dirname( plugin_basename( SOFT_MULTIMEDIA_PLAYER_FILE ) ) . '/languages/' );
    }

    /**
     * Adds a 'Settings' link to the list of action links for the plugin.
     *
     * This link redirects to the settings page of the plugin in the admin area.
     *
     * @param array $links An array of action links for the plugin.
     *
     * @return array Modified array of action links with the 'Settings' link added.
     */
    public function plugin_action_links( $links ) {
        $links[] = '<a href="' . admin_url( 'admin.php?page=multimedia-player' ) . '">' . __( 'Settings', 'soft-multimedia-player' ) . '</a>';
        return $links;
    }

    /**
     * Activates the plugin by calling the `activate` method of the `Install` class.
     *
     * @since 1.0.0
     */
    public function activate() {
        if ( !class_exists( 'SoftMultimediaPlayer\\Install' ) ) {
            require_once SOFT_MULTIMEDIA_PLAYER_INCLUDES . '/Install.php';
        }
        Install::activate();
    }

    /**
     * Returns the instance of the plugin.
     *
     * @return  Main instance of the plugin.
     * @since 1.0.0
     */
    public static function instance() {
        if ( is_null( self::$instance ) ) {
            self::$instance = new self();
        }
        return self::$instance;
    }

}

// kickoff multimedia player
if ( !function_exists( 'soft_multimedia_player' ) ) {
    function soft_multimedia_player() {
        return Main::instance();
    }

}
soft_multimedia_player();