@extends('Vzdelavanie::layout.default')

@section('content')
    @parent
    <div class="main-container">
        <section class="bg-white space-sm pb-4">
            <div class="container">
                <div class="row justify-content-between align-items-center">
                    <div class="col">
                        <h1 class="h2">Upraviť učebný materiál</h1>
                        @if(session('error'))
                            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                                <i class="icon-warning"></i>
                                {{ session('error') }}
                            </div>
                        @endif
                        @if(session('created'))
                            <div class="alert alert-success alert-dismissible fade show" role="alert">
                                <i class="icon-check"></i>
                                {{ session('created') }}
                            </div>
                        @endif
                    </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">
                                    <p class="nav-link active">Učebný materiál</p>
                                </li>
                                <li class="nav-item">
                                    <a href="{{ route('ucebnica.sekcia.index', ['id' => $ucebnica->getKey()]) }}" class="nav-link">Sekcie</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 fade active show" id="general" role="tabpanel" aria-labelledby="general-tab">
                    <div class="container">
                        <div class="row mb-4">
                            <div class="col">
                                <h5>Detaily učebného materiálu</h5>
                            </div>
                        </div>
                        <div class="row">
                            @if($errors->any())
                            <div class="col-12 col-md-4 order-md-2">
                                <div class="alert alert-danger text-small" role="alert">
                                    <i class="icon-shield"></i>
                                    <span>Skontrolujte si prosím zadané údaje, niečo nie je v poriadku.</span>
                                </div>
                            </div>
                            @endif
                            <div class="col-12 col-md-8 order-md-1">
                                <form class="row" action="{{ route('ucebnica.update', ['id' => $ucebnica->getKey()]) }}" method="post">
                                    @method('PUT')
                                    @csrf
                                    <div class="col-12">
                                        <div class="form-group">
                                            <label>
                                                Názov
                                                <span class="text-red">*</span>
                                            </label>
                                            <input class="form-control @if($errors->has('nazov')) is-invalid @endif" type="text" name="nazov" placeholder="názov učebného materiálu" value="{{ old('nazov') ?: $ucebnica->nazov }}" required autofocus>
                                            @if($errors->has('nazov'))
                                                @foreach($errors->get('nazov') as $message)
                                                <div class="invalid-feedback">{{ $message }}</div>
                                                @endforeach
                                            @endif
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label>Kategória</label>
                                            <select class="form-control" name="kategoria" @empty($kategorie) readonly @endempty>
                                                @forelse($kategorie as $_kategoria)
                                                <option value="{{ $_kategoria->getKey() }}" @if(isset($ucebnica->kategoria_id) && ($ucebnica->kategoria_id == $_kategoria->getKey())) selected @endif>{{ $_kategoria->nazov }}</option>
                                                @empty
                                                <option value="null">žiadna kategória</option>
                                                @endforelse
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label>Autor</label>
                                            <input class="form-control" type="text" name="autor" placeholder="celé meno autora učebného materiálu" value="{{ old('autor') ?: $ucebnica->autor }}">
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="form-group">
                                            <label>Popis</label>
                                            <textarea class="form-control" name="popis" placeholder="popis učebného materiálu" rows="3">{{ old('popis') ?: $ucebnica->popis }}</textarea>
                                            <small>* nepovinné pole</small>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="form-group">
                                            <div class="custom-control custom-checkbox custom-checkbox-switch">
                                                <input type="checkbox" class="custom-control-input" name="verejne" id="public" value="1" @if(old('verejne') ?: $ucebnica->verejne) checked @endif>
                                                <label class="custom-control-label" for="public">zverejniť pre študentov</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12">
                                        <div class="form-group">
                                            <button class="btn btn-primary" type="submit">
                                                <i class="fa fa-save"></i>
                                                Uložiť
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
@endsection
