<?php
namespace DisableDashiconsFrontend;

use WP_PowerSuite\Core\AbstractModule;

class Module extends AbstractModule {

	private const MODULE_ID = 'disable-dashicons-frontend';
	private const MODULE_VERSION = '1.2.1';

	public function getId(): string {
		return self::MODULE_ID;
	}

	public function getName(): string {
		return __( 'Disable Dashicons Frontend', 'wp-powersuite' );
	}

	public function getVersion(): string {
		return self::MODULE_VERSION;
	}

	public function getDescription(): string {
		return __( 'Loads fewer icon styles on your public pages for guests. Not recommended if you use Elementor, Bricks, or similar builders on the front end.', 'wp-powersuite' );
	}

	public function getContext(): array {
		return [ 'frontend' ];
	}

	protected function registerHooks(): void {
		if ( is_user_logged_in() || $this->isLoginScreen() ) {
			return;
		}

		add_action( 'wp_enqueue_scripts', [ $this, 'dequeueDashicons' ], 100 );
	}

	public function dequeueDashicons(): void {
		wp_dequeue_style( 'dashicons' );
		wp_deregister_style( 'dashicons' );
	}

	private function isLoginScreen(): bool {
		global $pagenow;

		return isset( $pagenow ) && $pagenow === 'wp-login.php';
	}
}
