<?php

namespace ProudNerds\Plugin\LoginScreen;

class LoginScreen
{
    public string $relativeDir;
    public string $relativeUrl;

    public function __construct()
    {
        $this->relativeDir = str_replace(WP_CONTENT_DIR, '', __DIR__);
        $this->relativeUrl = content_url($this->relativeDir);

        add_action('login_head', [$this, 'loginHead'], 10);
        add_action('login_enqueue_scripts', [$this, 'loginScreen'], 10);
    }

    /**
     * Enqueues the login screen stylesheet
     *
     * @return void
     */
    public function loginScreen(): void
    {
        wp_enqueue_style(
            'pn-login-screen',
            content_url($this->relativeDir . '/../assets/css/login-screen.css'),
            [],
            false,
            'all'
        );

        wp_enqueue_script(
            'pn-login-screen',
            content_url($this->relativeDir . '/../assets/js/login-screen.js'),
            ['jquery'],
            false,
            true
        );
    }

    /**
     * Adds the login screen partial to the login screen
     *
     * @return void
     */
    public function loginHead(): void
    {
        require_once __DIR__ . '/../partials/login-head.php'; // NOSONAR
    }

    /**
     * Use this method to initialize the package within WordPress
     *
     * @param string $vendorDir
     */
    public static function init(): static
    {
        return new static();
    }
}
