<?php

/**
 * Plugin Name:       PingVid
 * Description:       Embed a floating video anywhere. Perfect for introductions, announcements, or calls-to-action.
 * Version:           1.1.1
 * Requires at least: 6.4
 * Requires PHP:      7.4
 * Author:            Devnet
 * Author URI:        https://devnet.hr
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       pingvid
 * Domain Path:       /languages
 *
 */
use Devnet\PingVid\Includes\Activator;
use Devnet\PingVid\Includes\Deactivator;
use Devnet\PingVid\Includes\Plugin;
use Devnet\PingVid\Includes\Uninstaller;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( function_exists( 'devnet_pingvid_fs' ) ) {
    devnet_pingvid_fs()->set_basename( false, __FILE__ );
} else {
    if ( !function_exists( 'devnet_pingvid_fs' ) ) {
        // Create a helper function for easy SDK access.
        function devnet_pingvid_fs() {
            global $devnet_pingvid_fs;
            if ( !isset( $devnet_pingvid_fs ) ) {
                // Include Freemius SDK.
                require_once __DIR__ . '/vendor/freemius/wordpress-sdk/start.php';
                $devnet_pingvid_fs = fs_dynamic_init( [
                    'id'               => '19744',
                    'slug'             => 'pingvid',
                    'premium_slug'     => 'pingvid-pro',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_d080e2feadb3160902baf5e14f47a',
                    'is_org_compliant' => true,
                    'is_premium'       => false,
                    'premium_suffix'   => 'Pro',
                    'has_addons'       => false,
                    'has_paid_plans'   => true,
                    'trial'            => [
                        'days'               => 7,
                        'is_require_payment' => true,
                    ],
                    'menu'             => [
                        'slug'    => 'pingvid',
                        'contact' => false,
                    ],
                    'is_live'          => true,
                ] );
            }
            return $devnet_pingvid_fs;
        }

        // Init Freemius.
        devnet_pingvid_fs();
        // Signal that SDK was initiated.
        do_action( 'devnet_pingvid_fs_loaded' );
    }
    if ( !function_exists( 'devnet_esub_is_submenu_visible' ) ) {
        function devnet_esub_is_submenu_visible(  $is_visible, $menu_id  ) {
            if ( 'contact' != $menu_id ) {
                return $is_visible;
            }
            return devnet_pingvid_fs()->can_use_premium_code();
        }

    }
    /*
     * TODO: do uninstall logic.
     */
    if ( !function_exists( 'devnet_pingvid_fs_uninstall_cleanup' ) ) {
        function devnet_pingvid_fs_uninstall_cleanup() {
            require_once plugin_dir_path( __FILE__ ) . 'includes/uninstaller.php';
            Uninstaller::cleanup();
        }

    }
    /*
     * Run Freemius actions and filters.
     */
    if ( function_exists( 'devnet_pingvid_fs' ) ) {
        devnet_pingvid_fs()->add_filter(
            'is_submenu_visible',
            'devnet_esub_is_submenu_visible',
            10,
            2
        );
        devnet_pingvid_fs()->add_action( 'after_uninstall', 'devnet_pingvid_fs_uninstall_cleanup' );
    }
    define( 'DEVNET_PINGVID_VERSION', '1.1.1' );
    define( 'DEVNET_PINGVID_NAME', 'pingvid' );
    define( 'DEVNET_PINGVID_PATH_DIR', plugin_dir_path( __FILE__ ) );
    define( 'DEVNET_PINGVID_PATH_FILE', plugin_basename( __FILE__ ) );
    define( 'DEVNET_PINGVID_OPTIONS', [
        'general' => get_option( 'devnet_pingvid_general' ),
        'display' => get_option( 'devnet_pingvid_display' ),
    ] );
    function activate_devnet_pingvid() {
        require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php';
        Activator::activate();
    }

    function deactivate_devnet_pingvid() {
        require_once plugin_dir_path( __FILE__ ) . 'includes/deactivator.php';
        Deactivator::deactivate();
    }

    register_activation_hook( __FILE__, 'activate_devnet_pingvid' );
    register_deactivation_hook( __FILE__, 'deactivate_devnet_pingvid' );
    add_action( 'plugins_loaded', function () {
        require plugin_dir_path( __FILE__ ) . 'includes/plugin.php';
        $plugin = new Plugin();
        $plugin->run();
    } );
}