@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="card card-sm shadow">
                        <div class="card-body">
                            <h6 class="title-decorative">Informácie o používateľovi</h6>
                            <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->cele_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 class="form-row">
                                        <div class="form-group col-12 col-md-6">
                                            <label for="email">
                                                Emailová adresa
                                            </label>
                                            <input type="email" id="email" class="form-control" value="{{ $pouzivatel->email }}" disabled>
                                        </div>
                                        <div class="form-group col-12 col-md-6">
                                            <label for="phone">
                                                Telefónne číslo
                                            </label>
                                            <input type="text" id="phone" class="form-control" value="{{ $pouzivatel->telefon }}" disabled>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-row">
                                        <div class="form-group col-12">
                                            <label for="deviceToken">
                                                Token mobilného zariadenia
                                            </label>
                                            <input type="text" id="deviceToken" class="form-control" value="{{ $pouzivatel->notification_token }}" disabled>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <hr>

                            <h6 class="title-decorative">Nastavenia účtu</h6>
                            <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>

                            <h6 class="title-decorative">Napísať používateľovi notifikáciu</h6>
                            <div class="row">
                                <div class="col-12">
                                    <div class="alert alert-info text-small" role="alert">
                                        <i class="icon-shield"></i>
                                        <span>Slúži na testovacie odoslatie notifikácie na mobilné zariadenie používateľa, pokiaľ má používateľ definovaný token zariadenia.</span>
                                    </div>
                                </div>

                                <form class="col" action="{{ route('portal.sprava.pouzivatelia.notifications.send', $pouzivatel) }}" method="post">
                                    @csrf
                                    <div class="form-row">
                                        <div class="form-group col-12">
                                            <label for="notificationMessage">
                                                Správa
                                            </label>
                                            <textarea class="form-control" name="message" id="notificationMessage" rows="2"></textarea>
                                        </div>
                                    </div>
                                    <button class="btn btn-success" type="submit" @if(!$pouzivatel->notification_token) disabled @endif>
                                        <i class="icon-send mr-1"></i>
                                        Odoslať
                                    </button>
                                </form>
                            </div>

                            <hr>

                            <h6 class="title-decorative">Dátumové pečiatky</h6>
                            <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>
            </div>
        </div>
    </section>
@endsection