<?php
if (!defined('ABSPATH')) {
	exit;
}

class Wtols_Login_Designer {

	private $options;

	public function __construct($options) {
		$this->options = $options;
		add_action('login_head', array($this, 'apply_advanced_login_styles'), 999);
	}

	public function apply_advanced_login_styles() {
		if (empty($this->options['enable_login_designer'])) {
			return;
		}

		$layout = isset($this->options['login_designer_layout']) ? $this->options['login_designer_layout'] : 'default';
		$bg_image = isset($this->options['login_bg_image']) ? $this->options['login_bg_image'] : '';
		
		$css = '<style type="text/css">';

		if ($layout === 'split-left' || $layout === 'split-right') {
			$css .= '
				body.login {
					display: flex !important;
					flex-direction: row !important;
					align-items: center !important;
					justify-content: ' . ($layout === 'split-left' ? 'flex-start' : 'flex-end') . ' !important;
					min-height: 100vh !important;
					width: 100% !important;
					background: #f1f5f9 !important;
					background-image: url("' . esc_url($bg_image) . '") !important;
					background-size: cover !important;
					background-position: center !important;
					padding: 0 !important;
					margin: 0 !important;
					box-sizing: border-box !important;
					overflow-x: hidden !important;
				}
				body.login::before {
					content: "";
					position: absolute;
					top: 0; left: 0; right: 0; bottom: 0;
					background: rgba(0,0,0,0.4);
					z-index: 0;
				}
				body.login #login {
					position: relative !important;
					z-index: 1 !important;
					width: 450px !important;
					max-width: 100% !important;
					padding: 40px !important;
					margin: 0 !important;
					background: #ffffff !important;
					height: 100vh !important;
					display: flex !important;
					flex-direction: column !important;
					justify-content: center !important;
					box-shadow: 0 0 40px rgba(0,0,0,0.2) !important;
					border-radius: 0 !important;
					box-sizing: border-box !important;
					overflow-y: auto !important;
				}
				.login form {
					border: none !important;
					box-shadow: none !important;
					padding: 0 !important;
					background: transparent !important;
				}
			';
		} elseif ($layout === 'glassmorphism') {
			$css .= '
				body.login {
					display: flex !important;
					flex-direction: column !important;
					align-items: center !important;
					justify-content: center !important;
					min-height: 100vh !important;
					width: 100% !important;
					background: #0f172a !important;
					background-image: url("' . esc_url($bg_image) . '") !important;
					background-size: cover !important;
					background-position: center !important;
					padding: 20px !important;
					margin: 0 !important;
					box-sizing: border-box !important;
					overflow-x: hidden !important;
				}
				body.login #login {
					position: relative !important;
					z-index: 1 !important;
					width: 400px !important;
					max-width: 100% !important;
					padding: 40px !important;
					margin: 0 !important;
					background: rgba(255, 255, 255, 0.1) !important;
					backdrop-filter: blur(20px) !important;
					-webkit-backdrop-filter: blur(20px) !important;
					border: 1px solid rgba(255, 255, 255, 0.2) !important;
					border-radius: 20px !important;
					box-shadow: 0 20px 40px rgba(0,0,0,0.2) !important;
					box-sizing: border-box !important;
				}
				.login form {
					border: none !important;
					box-shadow: none !important;
					padding: 0 !important;
					background: transparent !important;
				}
				.login form label {
					color: #ffffff !important;
				}
				.login #backtoblog a, .login #nav a {
					color: #e2e8f0 !important;
				}
				.login form input[type="text"], .login form input[type="password"] {
					background: rgba(255, 255, 255, 0.2) !important;
					border: 1px solid rgba(255, 255, 255, 0.3) !important;
					color: #fff !important;
					border-radius: 8px !important;
				}
			';
		}

		$css .= '</style>';
		// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		echo $css;
	}
}
