@extends('super-admin.layout')

@section('title', $organisation ? 'Edit organisation' : 'Create organisation')

@section('content')
<div class="pg-head">
    <div>
        <h1>{{ $organisation ? 'Edit organisation' : 'Create organisation' }}</h1>
    </div>
    <a href="{{ route('mexco.super.organisations') }}" class="btn-outline">← Back</a>
</div>

<form method="POST" action="{{ $organisation ? route('mexco.super.organisations.update', $organisation) : route('mexco.super.organisations.store') }}" class="form-stack">
    @csrf
    @if($organisation) @method('PUT') @endif

    <div class="card section-card">
        <div class="form-row">
            <label class="form-label" for="name">Organisation name</label>
            <input type="text" name="name" id="name" class="form-input" value="{{ old('name', $organisation->name ?? '') }}" required>
        </div>
        <div class="form-row">
            <label class="form-label" for="type">Type</label>
            <select name="type" id="type" class="form-input" required>
                @foreach($types as $key => $label)
                    <option value="{{ $key }}" @selected(old('type', $organisation->type ?? 'other') === $key)>{{ $label }}</option>
                @endforeach
            </select>
        </div>
        <div class="form-row">
            <label class="form-label" for="contact_person">Contact person</label>
            <input type="text" name="contact_person" id="contact_person" class="form-input" value="{{ old('contact_person', $organisation->contact_person ?? '') }}">
        </div>
        <div class="row g-3">
            <div class="col-md-6">
                <div class="form-row mb-0">
                    <label class="form-label" for="email">Email</label>
                    <input type="email" name="email" id="email" class="form-input" value="{{ old('email', $organisation->email ?? '') }}">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-row mb-0">
                    <label class="form-label" for="phone">Phone</label>
                    <input type="text" name="phone" id="phone" class="form-input" value="{{ old('phone', $organisation->phone ?? '') }}">
                </div>
            </div>
        </div>
        @if($organisation)
            <div class="form-row mt-3 mb-0">
                <label class="form-label" for="status">Status</label>
                <select name="status" id="status" class="form-input">
                    @foreach(['active','suspended','archived'] as $s)
                        <option value="{{ $s }}" @selected(old('status', $organisation->status) === $s)>{{ ucfirst($s) }}</option>
                    @endforeach
                </select>
            </div>
        @endif
    </div>

    <div class="d-flex justify-content-end">
        <button type="submit" class="btn-purple">{{ $organisation ? 'Save changes' : 'Create organisation' }}</button>
    </div>
</form>
@endsection
