<?php
function pr_h($v) {
    return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}

$user = $user ?? [];
$error = $_SESSION['error'] ?? '';
unset($_SESSION['error']);
?>

<div class="container py-4">
    <div class="card border-0 shadow-sm" style="border-radius:24px;">
        <div class="card-body p-4">

            <div class="mb-4 p-4 rounded-4" style="background:linear-gradient(135deg,#0f172a,#1d4ed8);color:#fff;">
                <h3 class="fw-bold mb-1">Complete Author Profile</h3>
                <div class="opacity-75">Phone number is compulsory before submitting papers.</div>
            </div>

            <?php if ($error): ?>
                <div class="alert alert-danger"><?= pr_h($error) ?></div>
            <?php endif; ?>

            <form method="post" action="/easychair/author/profile/save" class="row g-3">
                <div class="col-md-6">
                    <label class="form-label fw-bold">First Name</label>
                    <input name="first_name" class="form-control" value="<?= pr_h($user['first_name'] ?? '') ?>">
                </div>

                <div class="col-md-6">
                    <label class="form-label fw-bold">Last Name</label>
                    <input name="last_name" class="form-control" value="<?= pr_h($user['last_name'] ?? '') ?>">
                </div>

                <div class="col-md-6">
                    <label class="form-label fw-bold">Email</label>
                    <input class="form-control" value="<?= pr_h($user['email'] ?? '') ?>" disabled>
                </div>

                <div class="col-md-6">
                    <label class="form-label fw-bold">Phone / Mobile <span class="text-danger">*</span></label>
                    <input name="phone" class="form-control" required value="<?= pr_h(($user['phone'] ?? '') ?: ($user['mobile'] ?? '')) ?>">
                </div>

                <div class="col-12">
                    <button class="btn btn-success btn-lg rounded-pill px-5">
                        Save and Continue
                    </button>
                </div>
            </form>

        </div>
    </div>
</div>
