<?php
use BLR\Backline\Core\Router;

if (!defined('ABSPATH')) exit;

$user = wp_get_current_user();
$is_logged_in = is_user_logged_in();
$logout_url = wp_logout_url(Router::login_url());
?>

<div class="card">
  <div class="card-body">
    <h1 class="h3 mb-3"><?php echo esc_html__('Not allowed', 'blr-backline'); ?></h1>
    <?php if (!$is_logged_in): ?>
      <p class="text-muted mb-4"><?php echo esc_html__('You need to log in before you can access Backline.', 'blr-backline'); ?></p>
      <a class="btn btn-primary" href="<?php echo esc_url(Router::login_url()); ?>"><?php echo esc_html__('Go to login', 'blr-backline'); ?></a>
    <?php else: ?>
      <p class="mb-2"><?php echo esc_html__('You\'re logged in as', 'blr-backline'); ?> <strong><?php echo esc_html($user->user_login); ?></strong><?php echo esc_html__(', but this account isn\'t on the approved list for Backline.', 'blr-backline'); ?></p>
      <p class="text-muted mb-4"><?php echo esc_html__('If you think this is a mistake, contact the site admin and ask to be added to', 'blr-backline'); ?> <em><?php echo esc_html__('Backline → Settings → Allowed Users', 'blr-backline'); ?></em>.</p>
      <div class="d-flex gap-2">
        <a class="btn btn-outline-secondary" href="<?php echo esc_url(home_url('/')); ?>"><?php echo esc_html__('Back to site', 'blr-backline'); ?></a>
        <a class="btn btn-danger" href="<?php echo esc_url($logout_url); ?>"><?php echo esc_html__('Log out', 'blr-backline'); ?></a>
      </div>
    <?php endif; ?>
  </div>
</div>