@extends('layouts.admin')

@section('title', $admin->exists ? 'Edit Manager' : 'Add Manager')
@section('heading', $admin->exists ? 'Edit Manager' : 'Add Manager')

@section('actions')
    <a class="btn-admin btn-back" href="{{ route('admin.administrators.index') }}">&lt;- Back</a>
@endsection

@section('content')
<div class="panel">
    <form class="form" method="POST" action="{{ $admin->exists ? route('admin.administrators.update', $admin) : route('admin.administrators.store') }}">
        @csrf
        @if($admin->exists) @method('PUT') @endif
        <div class="form-row">
            <div class="field">
                <label>First name</label>
                <input name="first_name" value="{{ old('first_name', $admin->first_name) }}" required>
            </div>
            <div class="field">
                <label>Last name</label>
                <input name="last_name" value="{{ old('last_name', $admin->last_name) }}" required>
            </div>
        </div>
        <div class="form-row">
            <div class="field">
                <label>Email</label>
                <input type="email" name="email" value="{{ old('email', $admin->email) }}" required>
            </div>
            <div class="field">
                <label>Phone</label>
                <input name="phone" value="{{ old('phone', $admin->phone) }}">
            </div>
        </div>
        <div class="form-row">
            <div class="field">
                <label>Type</label>
                <select name="role_type">
                    <option value="super_admin" @selected(old('role_type', $admin->role_type) === 'super_admin')>Super Admin</option>
                    <option value="admin" @selected(old('role_type', $admin->role_type) === 'admin')>Admin</option>
                    <option value="manager" @selected(old('role_type', $admin->role_type) === 'manager')>Manager</option>
                </select>
            </div>
            <div class="field">
                <label>Status</label>
                <select name="status">
                    <option value="active" @selected(old('status', $admin->status ?: 'active') === 'active')>active</option>
                    <option value="blocked" @selected(old('status', $admin->status) === 'blocked')>blocked</option>
                </select>
            </div>
        </div>
        <div class="form-row">
            <div class="field">
                <label>Password {{ $admin->exists ? '(leave blank to keep current)' : '' }}</label>
                <input type="password" name="password" {{ $admin->exists ? '' : 'required' }} autocomplete="new-password">
            </div>
            <div class="field">
                <label>Confirm password</label>
                <input type="password" name="password_confirmation" {{ $admin->exists ? '' : 'required' }} autocomplete="new-password">
            </div>
        </div>
        <button class="btn-admin btn-primary" type="submit">Save</button>
    </form>
</div>
@endsection
