<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

$base = "/SEAT";
$role = $_GET['role'] ?? "student";
$title = ucfirst($role);
?>



<!DOCTYPE html>
<html>
<head>

<title><?= $title ?> Register</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?= $base ?>/assets/css/auth/register.css">
</head>
<body>

<div class="wrap">
<div id="toastBox" class="toast-container"></div>



<div class="card">

<a href="<?= $base ?>/modules/User/auth/registerType.php" class="back-btn">← Back</a>

<h2><?= $title ?> Registration</h2>

<p class="sub">
Please fill in the required information below to create your account.
</p>

<form id="regForm" method="post" enctype="multipart/form-data" autocomplete="off">

<input type="hidden" name="role" value="<?= $role ?>">



<?php if($role!="organizer"){ ?>

<label>Full Name *</label>
<input 
name="user_full_name"
id="full_name"
required
pattern="[A-Za-z.\s]+"
title="Letters only"
oninput="validateFullName()">
<small id="fullNameMsg"></small>

<?php } ?>




<?php if($role=="student"){ ?>

<div class="row">

<div class="col">
<label>Matric ID *</label>
<input name="matric"
id="matric"
placeholder="e.g. 161000"
maxlength="6"
pattern="[0-9]{6}"
title="Matric must be exactly 6 digits"
required
oninput="validateMatric()">
<small id="matricMsg"></small>
</div>



<div class="col">

<label>Faculty *</label>

<select name="faculty" required>

    <option value="" selected disabled>
        Select Faculty
    </option>

    <option disabled>
        ──────── MAIN CAMPUS ────────
    </option>

    <option>SCHOOL OF ARTS</option>
    <option>SCHOOL OF BIOLOGICAL SCIENCES</option>
    <option>SCHOOL OF CHEMICAL SCIENCES</option>
    <option>SCHOOL OF COMMUNICATION</option>
    <option>SCHOOL OF COMPUTER SCIENCES</option>
    <option>SCHOOL OF DISTANCE EDUCATION</option>
    <option>SCHOOL OF EDUCATIONAL STUDIES</option>
    <option>SCHOOL OF HOUSING, BUILDING AND PLANNING</option>
    <option>SCHOOL OF HUMANITIES</option>
    <option>SCHOOL OF INDUSTRIAL TECHNOLOGY</option>
    <option>SCHOOL OF LANGUAGES, LITERACIES & TRANSLATION</option>
    <option>SCHOOL OF MANAGEMENT</option>
    <option>SCHOOL OF MATHEMATICAL SCIENCES</option>
    <option>SCHOOL OF PHARMACEUTICAL SCIENCES</option>
    <option>SCHOOL OF PHYSICS</option>
    <option>SCHOOL OF SOCIAL SCIENCES</option>
    <option>GRADUATE SCHOOL OF BUSINESS</option>

    <option disabled>
        ──────── ENGINEERING CAMPUS ────────
    </option>

    <option>SCHOOL OF AEROSPACE ENGINEERING</option>
    <option>SCHOOL OF CHEMICAL ENGINEERING</option>
    <option>SCHOOL OF CIVIL ENGINEERING</option>
    <option>SCHOOL OF ELECTRICAL & ELECTRONIC ENGINEERING</option>
    <option>SCHOOL OF MATERIALS & MINERAL RESOURCES ENGINEERING</option>
    <option>SCHOOL OF MECHANICAL ENGINEERING</option>

    <option disabled>
        ──────── HEALTH CAMPUS ────────
    </option>

    <option>SCHOOL OF DENTAL SCIENCES</option>
    <option>SCHOOL OF HEALTH SCIENCES</option>
    <option>SCHOOL OF MEDICAL SCIENCES</option>

</select>

</div>

</div>

<?php } ?>

<?php if($role!="organizer"){ ?>

<label>Phone Number *</label>
<input 
name="user_phone"
id="phone"
placeholder="e.g. 0123456789"
maxlength="11"
pattern="01[0-9]{8,9}"
title="Must start with 01 and be 10–11 digits"
required
autocomplete="off"
oninput="validatePhone()">

<small id="phoneMsg"></small>

<?php } ?>

<?php if($role=="student"){ ?>

<label>Email *</label>
<input name="user_email"
id="email"
placeholder="example@student.usm.my"
required
autocomplete="off"
oninput="validateEmail()">
<small id="emailMsg"></small>

<?php } ?>



<?php if($role=="staff"){ ?>

<div class="col">
<label>Staff ID *</label>

<input 
name="matric"
id="staff_matric"
placeholder="e.g. ST1234"
maxlength="6"
pattern="[A-Z]{2}[0-9]{4}"
title="Format: 2 letters + 4 digits (e.g. ST1234)"
required
oninput="validateStaffMatric()">

<small id="matricMsg"></small>
</div>

<label>Email *</label>
<input name="user_email"
id="email"
placeholder="example@usm.my"
required
autocomplete="off"
oninput="validateEmail()">
<small id="emailMsg"></small>

<?php } ?>


<?php if($role=="organizer"){ ?>

<!-- You SHOULD set this from session in real backend -->
<input type="hidden" name="user_id" value="<?= $_SESSION['user_id'] ?? '' ?>">

<!-- optional audit field -->
<input type="hidden" name="updated_by" value="<?= $_SESSION['user_full_name'] ?? '' ?>">

<label>Association / Club Name *</label>
<input 
name="club_name"
id="club_name"
required
pattern="[A-Za-z\s]+"
title="Letters only"
oninput="validateClubName()">
<small id="clubMsg"></small>

<label>Type *</label>
<select name="club_type" required>
<option value="">Select type</option>
<option>Club</option>
<option>Association</option>
</select>

<label>Advisor Name *</label>
<input 
name="advisor_name"
id="advisor_name"
required
pattern="[A-Za-z.\s]+"
title="Letters, dot and spaces only"
oninput="validateAdvisorName()">
<small id="advisorNameMsg"></small>

<label>Advisor Phone *</label>
<input 
name="advisor_phone_unique"
id="advisor_phone"
placeholder="0123456789"
maxlength="11"
pattern="01[0-9]{8,9}"
required
autocomplete="off"
oninput="validateAdvisorPhone()">

<small id="advisorMsg"></small>

<label>Club Email *</label>
<input name="user_email"
id="email"
placeholder="example@gmail.com"
required
autocomplete="off"
oninput="validateEmail()">
<small id="emailMsg"></small>

<label>Description</label>
<textarea name="description"></textarea>

<hr class="section-divider">

<h3 class="section-title">Bank Details</h3>
<p class="section-sub">Required for payment & fund transfers</p>

<label>Account Holder Name *</label>
<input 
name="account_holder_name"
id="bank_holder"
required
maxlength="50"
pattern="[A-Za-z.\s]{3,150}"
title="Only letters, dot, spaces"
oninput="validateBankHolder()">
<small id="bankHolderMsg"></small>

<label>Bank Name *</label>
<select name="bank_name" id="bank_name" required>
<option value="">Select Bank</option>
<option>Maybank</option>
<option>CIMB Bank</option>
<option>Public Bank</option>
<option>RHB Bank</option>
<option>Hong Leong Bank</option>
<option>AmBank</option>
<option>Bank Islam</option>
<option>Bank Rakyat</option>
<option>HSBC</option>
<option>OCBC</option>
</select>

<label>Bank Account Number *</label>
<input 
name="account_number"
id="bank_account"
placeholder="e.g. 158156789012"
required
maxlength="50"
pattern="[0-9]+"
title="Numbers only"
oninput="validateBankAccount()">
<small id="bankAccMsg"></small>

<label>Supporting Document (PDF)</label>
<input 
type="file" 
name="file" 
id="supportFile"
accept="application/pdf"
required
onchange="validatePDF()">

<small id="fileMsg"></small>

<div class="note-box">
    <span class="note-title">Note</span>
    <p>Upload ONE PDF (max 5MB): Organizer's bank details.</p>
</div>

<?php } ?>



<?php if($role!="organizer"){ ?>

<div class="row">

<div class="col">
<label>Password *</label>
<input type="password"
name="user_password"
id="password"
placeholder="e.g. Abc123!"
required
oninput="validatePassword()">
<small id="passMsg"></small>
</div>

<div class="col">
<label>Confirm *</label>
<input type="password"
name="user_confirm_password"
id="confirm"
required
oninput="validateConfirm()">
<small id="confirmMsg"></small>
</div>

</div>

<?php } ?>

<button class="btn">Create Account</button>

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

<script>
const BASE = "<?= $base ?>";
</script>

<script src="<?= $base ?>/modules/User/auth/register.js"></script>

</body>
</html>