<?php

use Dolphy\Plugin\Helpers\Page;
use Dolphy\Plugin\Helpers\User;
use Dolphy\Plugin\Options\Settings\AccessOptions;

// Redirect to Admin URL user is logged in
if ($user = User::current()) {
  $redirect = esc_url_raw($_GET['redirect']);
  $adminUrl = ($redirect) ? $redirect : admin_url();

  wp_redirect($adminUrl);
  exit;
}

// Redirect to HTTPS login if forced to use SSL.
if (force_ssl_admin() && !is_ssl()) {
	if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) {
    wp_safe_redirect(set_url_scheme($_SERVER['REQUEST_URI'], 'https'));
	} else {
		wp_safe_redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  }
  exit;
}

$title = Page::currentPageTitle();

$customLogo = get_theme_mod('custom_logo');

if ($customLogo === false) {
  $logo = DOLPHY_LOGO_URL;
} else {
  $image = wp_get_attachment_image_src($customLogo , 'full');
  list ($logo) = $image;
}

$options = AccessOptions::instance();

?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?php echo $title; ?></title>

  <?php
  do_action('dolphy_access_enqueue_scripts');
  do_action('dolphy_header_scripts');
  ?>

  <style>
  .dol-access {
    background-image: url(<?php echo esc_url_raw($options->backgroundImage); ?>) !important;
  }

  .dol-access-overlay {
    background-color: <?php echo $options->backgroundOverlay; ?> !important;
  }
  </style>
</head>
<body class="dolphy">
  <div class="dol-access">
    <div class="dol-access-overlay"></div>

    <div class="dol-access-body">
      <div class="dol-access-container">
        <div class="logo">
          <img src="<?php echo esc_url($logo); ?>" alt="Logo">
        </div>
