<?php

declare(strict_types=1);

namespace BeycanPress\Tokenico;

use BeycanPress\Tokenico\PluginHero\Helpers;

class Loader extends PluginHero\Plugin
{
    /**
     * @param string $pluginFile
     */
    public function __construct(string $pluginFile)
    {
        parent::__construct([
            'pluginFile' => $pluginFile,
            'textDomain' => 'tokenico',
            'pluginKey' => 'tokenico',
            'settingKey' => 'tokenico-settings'
        ]);

        Helpers::setProp('hidePremiumVersionReason', true);
        Helpers::feedback(true, 'tokenico-cryptocurrency-token-launchpad-presale-ico-ido-airdrop');

        new RestAPI();

        if (!is_admin()) {
            new Shortcode();
        }

        add_filter(
            'plugin_action_links_' . plugin_basename(Helpers::getProp('pluginFile')),
            [$this, 'pluginActionLinks']
        );
    }

    /**
     * @param array<string,string> $links
     * @return array<string,string>
     */
    public function pluginActionLinks(array $links): array
    {
        // @phpcs:disable
        $links[] = Helpers::view('components/link', [
            'url' => 'https://beycanpress.com/tokenico/?utm_source=free_version&utm_medium=plugins_list',
            'text' => __('Buy Premium', 'tokenico'),
        ]);

        $links[] = Helpers::view('components/link', [
            'url' => admin_url('admin.php?page=tokenico-settings'),
            'text' => __('Settings', 'tokenico'),
        ]);

        $links[] = Helpers::view('components/link', [
            'url' => 'https://beycanpress.gitbook.io/tokenico-docs/',
            'text' => __('Documentation', 'tokenico'),
        ]);
        // @phpcs:enable

        return $links;
    }

    /**
     * @return void
     */
    public function adminProcess(): void
    {
        add_action('init', function (): void {
            new Pages\Creator();

            if (file_exists(Helpers::getProp('pluginDir') . '/debug.log')) {
                new Pages\DebugLogs();
            }

            new Settings();
        }, 9);
    }

    /**
     * @return void
     */
    public static function activation(): void
    {
        // activation code here
    }

    /**
     * @return void
     */
    public static function uninstall(): void
    {
        if (Settings::get('dds')) {
            delete_option(Helpers::getProp('settingKey'));
        }
    }
}
