<?php
require_once __DIR__ . '/../core/session.php';

// Validate input
$first = trim($_POST['first_name'] ?? '');
$last  = trim($_POST['last_name'] ?? '');
$nick  = trim($_POST['nickname'] ?? '');

if ($first === '' || $last === '') {
  die("First and last name are required.");
}

// Initialize onboarding session if not exists
if (!isset($_SESSION['onboarding'])) {
  $_SESSION['onboarding'] = [];
}

// Save data
$_SESSION['onboarding']['first_name'] = $first;
$_SESSION['onboarding']['last_name']  = $last;
$_SESSION['onboarding']['nickname']   = $nick ?: $first;
$_SESSION['onboarding']['step']        = 'phone';

// Redirect to next step
header("Location: /public/phone.php");
exit;
