@extends('portal.auth.layout')

@section('shell_class', 'auth-wide')

@section('content')
@php
    $title = 'Create account';
    $isCampus = $plan?->code === 'campus';
@endphp
<h1>{{ $isCampus ? 'Apply for Campus Plan' : 'Create your account' }}</h1>
<p class="lead">
    @if($isCampus)
        Submit a complete sponsorship application with your letter. You cannot sign in to My MeXCo until a Super Admin approves it.
    @else
        One organisation account. Each event keeps its own plan and license.
    @endif
</p>

@if($plan)
    <div class="plan-note">
        <span>Selected plan</span>
        <strong>{{ $plan->name }}</strong>
        @if($plan->code === 'demo')
            <span>· Free limited trial</span>
        @elseif($plan->code === 'campus')
            <span>· Sponsored · RM0 · Approval required</span>
        @elseif(!$plan->is_custom_pricing && $plan->price_cents > 0)
            <span>· {{ $plan->formattedPrice() }} / event</span>
        @endif
    </div>
@endif

@if(session('error'))
    <div class="alert-flash alert-danger">{{ session('error') }}</div>
@endif

<form method="POST" action="{{ route('mexco.register.submit') }}" @if($isCampus) enctype="multipart/form-data" @endif>
    @csrf
    @if($plan)
        <input type="hidden" name="plan" value="{{ $plan->code }}">
    @endif

    <div class="field">
        <label class="form-label" for="name">Your name</label>
        <input class="form-input" type="text" name="name" id="name" value="{{ old('name') }}" required autocomplete="name" placeholder="Full name">
        @error('name')<div class="form-error">{{ $message }}</div>@enderror
    </div>

    <div class="row-2">
        <div class="field">
            <label class="form-label" for="email">Email</label>
            <input class="form-input" type="email" name="email" id="email" value="{{ old('email') }}" required autocomplete="email" placeholder="you@organisation.com">
            @error('email')<div class="form-error">{{ $message }}</div>@enderror
        </div>
        <div class="field">
            <label class="form-label" for="phone">Phone @if(!$isCampus)<span style="font-weight:500;color:var(--muted)">(optional)</span>@endif</label>
            <input class="form-input" type="text" name="phone" id="phone" value="{{ old('phone') }}" @if($isCampus) required @endif autocomplete="tel" placeholder="+60…">
            @error('phone')<div class="form-error">{{ $message }}</div>@enderror
        </div>
    </div>

    <div class="row-2">
        <div class="field">
            <label class="form-label" for="password">Password</label>
            <input class="form-input" type="password" name="password" id="password" required minlength="8" autocomplete="new-password" placeholder="Min. 8 characters">
            @error('password')<div class="form-error">{{ $message }}</div>@enderror
        </div>
        <div class="field">
            <label class="form-label" for="password_confirmation">Confirm password</label>
            <input class="form-input" type="password" name="password_confirmation" id="password_confirmation" required autocomplete="new-password" placeholder="Repeat password">
        </div>
    </div>

    <div class="row-2">
        <div class="field">
            <label class="form-label" for="organisation_name">{{ $isCampus ? 'Institution / organisation' : 'Organisation name' }}</label>
            <input class="form-input" type="text" name="organisation_name" id="organisation_name" value="{{ old('organisation_name') }}" required autocomplete="organization" placeholder="University / company">
            @error('organisation_name')<div class="form-error">{{ $message }}</div>@enderror
        </div>
        <div class="field">
            <label class="form-label" for="organisation_type">Organisation type</label>
            <select class="form-select" name="organisation_type" id="organisation_type" required>
                @foreach($orgTypes as $value => $label)
                    <option value="{{ $value }}" @selected(old('organisation_type', 'university') === $value)>{{ $label }}</option>
                @endforeach
            </select>
            @error('organisation_type')<div class="form-error">{{ $message }}</div>@enderror
        </div>
    </div>

    @if($isCampus)
        <div class="row-2">
            <div class="field">
                <label class="form-label" for="faculty">Faculty</label>
                <input class="form-input" type="text" name="faculty" id="faculty" value="{{ old('faculty') }}" required>
                @error('faculty')<div class="form-error">{{ $message }}</div>@enderror
            </div>
            <div class="field">
                <label class="form-label" for="student_organisation">Student organisation</label>
                <input class="form-input" type="text" name="student_organisation" id="student_organisation" value="{{ old('student_organisation') }}" required>
                @error('student_organisation')<div class="form-error">{{ $message }}</div>@enderror
            </div>
        </div>

        <div class="field">
            <label class="form-label" for="event_name">Event name</label>
            <input class="form-input" type="text" name="event_name" id="event_name" value="{{ old('event_name') }}" required placeholder="e.g. Student Innovation Day 2026">
            @error('event_name')<div class="form-error">{{ $message }}</div>@enderror
        </div>

        <div class="row-2">
            <div class="field">
                <label class="form-label" for="event_date">Event date</label>
                <input class="form-input" type="date" name="event_date" id="event_date" value="{{ old('event_date') }}" required>
                @error('event_date')<div class="form-error">{{ $message }}</div>@enderror
            </div>
            <div class="field">
                <label class="form-label" for="expected_participants">Expected participants</label>
                <input class="form-input" type="number" name="expected_participants" id="expected_participants" value="{{ old('expected_participants') }}" min="1" required>
                @error('expected_participants')<div class="form-error">{{ $message }}</div>@enderror
            </div>
        </div>

        <div class="row-2">
            <div class="field">
                <label class="form-label" for="sessions_count">Sessions count</label>
                <input class="form-input" type="number" name="sessions_count" id="sessions_count" value="{{ old('sessions_count') }}" min="0" required>
                @error('sessions_count')<div class="form-error">{{ $message }}</div>@enderror
            </div>
            <div class="field">
                <label class="form-label" for="booths_count">Booths count</label>
                <input class="form-input" type="number" name="booths_count" id="booths_count" value="{{ old('booths_count') }}" min="0" required>
                @error('booths_count')<div class="form-error">{{ $message }}</div>@enderror
            </div>
        </div>

        <div class="field">
            <label class="form-label" for="event_objective">Event objective</label>
            <textarea class="form-input" name="event_objective" id="event_objective" rows="3" required placeholder="Describe the programme objectives">{{ old('event_objective') }}</textarea>
            @error('event_objective')<div class="form-error">{{ $message }}</div>@enderror
        </div>

        <div class="field">
            <label class="form-label" for="promotional_exposure">Promotional exposure</label>
            <textarea class="form-input" name="promotional_exposure" id="promotional_exposure" rows="3" required placeholder="How will MeXCo be promoted at your event?">{{ old('promotional_exposure') }}</textarea>
            @error('promotional_exposure')<div class="form-error">{{ $message }}</div>@enderror
        </div>

        <div class="field">
            <label class="form-label" for="sponsorship_letter">Sponsorship letter</label>
            <input class="form-input" type="file" name="sponsorship_letter" id="sponsorship_letter" required accept=".pdf,.doc,.docx,.jpg,.jpeg,.png">
            <div style="margin-top:.35rem;font-size:.78rem;color:var(--muted)">PDF, Word, or image · max 10 MB</div>
            @error('sponsorship_letter')<div class="form-error">{{ $message }}</div>@enderror
        </div>
    @endif

    <button type="submit" class="btn-purple auth-submit">
        @if($plan?->code === 'demo')
            Create account &amp; start demo
        @elseif($isCampus)
            Submit application
        @else
            Create account
        @endif
    </button>
</form>

<p class="foot">
    Already approved? <a href="{{ route('mexco.login') }}">Sign in</a>
</p>
@endsection

@section('after_card')
    <a href="{{ route('mexco.home') }}" class="auth-home">← Back to website</a>
@endsection
