@extends('layouts.default')

@section('content')
    @parent

    <section class="bg-white space-sm pb-4">
        <div class="container">
            <div class="row justify-content-between align-items-center">
                <div class="col-auto">
                    <h1 class="h2">Účet používateľa</h1>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above space-0">
        <div class="bg-white">
            <div class="container">
                <div class="row">
                    <div class="col">
                        <ul class="nav nav-tabs" id="myTab" role="tablist">
                            <li class="nav-item">
                                <a class="nav-link active" role="tab">Hlavné</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('portal.sprava.pouzivatelia.akcie.index', $pouzivatel) }}" role="tab">Akcie</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="flush-with-above height-80 d-block">
        <div class="tab-content">

            <div class="tab-pane active" role="tabpanel">
                <div class="container">
                    <div class="row mb-4">
                        <div class="col">
                            <h5>Informácie o používateľovi</h5>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12 col-md-3 order-md-2">
                            <div class="alert alert-info text-small" role="alert">
                                <i class="icon-shield"></i>
                                <span>Informácie o používateľovi nie je možné v rámci portálu upravovať. Úprava je možná výlučne v rámci informačného systému emisných kontrol AISEK.</span>
                            </div>
                        </div>

                        <div class="col-12 col-md-9 order-md-1">
                            <div class="form-row">
                                <div class="form-group col-12 col-md-6">
                                    <label for="userName">
                                        Meno
                                    </label>
                                    <input type="text" id="userName" class="form-control" value="{{ $pouzivatel->meno }}" disabled>
                                </div>
                                <div class="form-group col-12 col-md-6">
                                    <label for="userLogin">
                                        Prihlasovacie meno
                                    </label>
                                    <input type="text" id="userLogin" class="form-control" value="{{ $pouzivatel->login }}" disabled>
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group col-12 col-md-6">
                                    <label for="pekName">
                                        Názov pracoviska emisnej kontroly
                                    </label>
                                    <input type="text" id="pekName" class="form-control" value="{{ $pouzivatel->pracovisko->nazov }}" disabled>
                                </div>
                                <div class="form-group col-12 col-md-6">
                                    <label for="pekCode">
                                        Číslo pracoviska emisnej kontroly
                                    </label>
                                    <input type="text" id="pekCode" class="form-control" value="{{ $pouzivatel->pracovisko->kod }}" disabled>
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr>

                    <div class="row mb-4">
                        <div class="col">
                            <h5>Nastavenia účtu</h5>
                        </div>
                    </div>
                    <div class="row">
                        <form class="col" action="{{ route('portal.sprava.pouzivatelia.update', $pouzivatel) }}" method="post">
                            @method('PUT')
                            @csrf
                            <div class="form-row">
                                <div class="form-group col-12 col-md-6">
                                    <label>
                                        Stav
                                    </label>
                                    @php
                                        $checked = \App\Models\Pouzivatel\PouzivatelStavEnum::AKTIVNY();
                                        if (isset($pouzivatel) && $pouzivatel->stav) {
                                            $checked = $pouzivatel->stav;
                                        }
                                    @endphp
                                    @foreach(\App\Models\Pouzivatel\PouzivatelStavEnum::toArray() as $value => $label)
                                        <div class="form-check">
                                            <input type="radio" class="form-check-input" name="stav" id="public-{{ $loop->index }}" value="{{ $value }}" @if($checked->equals(\App\Models\Pouzivatel\PouzivatelStavEnum::make($value))) checked @endif>
                                            <label class="form-check-label" for="public-{{ $loop->index }}">{{ $label }}</label>
                                        </div>
                                    @endforeach
                                    @if($errors->has('stav'))
                                        @foreach($errors->get('stav') as $message)
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @endforeach
                                    @endif
                                </div>
                                <div class="form-group col-12 col-md-6">
                                    <label for="roles">
                                        Oprávnenia
                                    </label>
                                    <select id="roles" class="custom-select" name="opravnenia" size="4" multiple disabled>
                                    @forelse($pouzivatel->permissions as $opravnenie)
                                        <option selected>{{ $opravnenie->name }}</option>
                                    @empty
                                        <option>-- žiadne pridelené oprávnenie --</option>
                                    @endforelse
                                    </select>
                                    @if($errors->has('opravnenia'))
                                        @foreach($errors->get('opravnenia') as $message)
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @endforeach
                                    @endif
                                </div>
                            </div>
                            <button class="btn btn-primary" type="submit">
                                <i class="icon-save mr-1"></i>
                                Uložiť zmeny
                            </button>
                        </form>
                    </div>

                    <hr>

                    <div class="row mb-4">
                        <div class="col">
                            <h5>Dátumové pečiatky</h5>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="form-row">
                                <div class="form-group col-12 col-md-4">
                                    <label for="lastLoginAt">
                                        Dátum posledného prihlásenia
                                    </label>
                                    <input type="text" id="lastLoginAt" class="form-control" value="{{ $pouzivatel->datum_posledneho_prihlasenia ? $pouzivatel->datum_posledneho_prihlasenia->format('d.m.Y H:i:s') : '-' }}" disabled>
                                </div>
                                <div class="form-group col-12 col-md-4">
                                    <label for="createdAt">
                                        Dátum prvého prihlásenia
                                    </label>
                                    <input type="text" id="createdAt" class="form-control" value="{{ $pouzivatel->created_at ? $pouzivatel->created_at->format('d.m.Y H:i:s') : '-' }}" disabled>
                                </div>
                                <div class="form-group col-12 col-md-4">
                                    <label for="updatedAt">
                                        Dátum aktualizácie
                                    </label>
                                    <input type="text" id="updatedAt" class="form-control" value="{{ $pouzivatel->updated_at ? $pouzivatel->updated_at->format('d.m.Y H:i:s') : '-' }}" disabled>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection