@extends('admin')
@section('contentData')
    @if (session()->has('message'))
        <div class="alert alert-success">
            {{ session('message') }}
        </div>
    @endif
    <div>
        <div class="row">
            <div class="col-xs-6" style="width: 650px;">
                <div class="card" style="width: 600px;">
                    <div class="card-header">{{ __('Editace čidla') }}</div>
                    <div class="card-body">
                        <form method="POST" action="{{ route('stanice-edit',$stanice->appId) }}">
                            @csrf

                            <div class="form-group row">
                                <label for="nazev" class="col-md-4 col-form-label text-md-right">{{ __('Název') }}</label>

                                <div class="col-md-6">
                                    <input id="nazev" type="text" class="form-control @error('nazev') is-invalid @enderror" name="nazev" value="{{ old('nazev') ?? $stanice->nazev }}">

                                    @error('nazev')
                                    <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="adresa" class="col-md-4 col-form-label text-md-right">{{ __('Adresa') }}</label>

                                <div class="col-md-6">
                                    <input id="adresa" type="text" class="form-control @error('adresa') is-invalid @enderror" name="adresa" value="{{ old('adresa') ?? $stanice->adresa }}">

                                    @error('adresa')
                                    <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
                                <a id='modalClick' href='javascript:void(0);' onclick='vratSouradnice($("#adresa").val())' data-toggle='modal' data-target='#showAdresy'>Najdi adresu</a>
                            </div>
                            <div class="form-group row">
                                <label for="souradnice_x" class="col-md-4 col-form-label text-md-right">{{ __('Souřadnice X (JTSK)') }}</label>

                                <div class="col-md-6">
                                    <input id="souradnice_x" type="text" class="form-control @error('souradnice_x') is-invalid @enderror" name="souradnice_x" value="{{ old('souradnice_x') ?? $stanice->souradnice_x }}">

                                    @error('souradnice_x')
                                    <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="souradnice_y" class="col-md-4 col-form-label text-md-right">{{ __('Souřadnice Y (JTSK)') }}</label>

                                <div class="col-md-6">
                                    <input id="souradnice_y" type="text" class="form-control @error('souradnice_y') is-invalid @enderror" name="souradnice_y" value="{{ old('souradnice_y') ?? $stanice->souradnice_y }}">

                                    @error('souradnice_y')
                                    <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="registrovano" class="col-md-4 col-form-label text-md-right">{{ __('Zobrazit v mapě') }}</label>

                                <div class="col-md-6">
                                    <input id="registrovano" type="checkbox" style="width: auto;" class="form-control @error('registrovano') is-invalid @enderror" name="registrovano" value="{{old('registrovano') ?? $stanice->registrovano}}" {{ old('registrovano', 1 === $stanice->registrovano ? 'checked': '') }}>

                                    @error('registrovano')
                                    <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
                            </div>
                            <div class="form-group row"><label for="parametry" class="col-md-4 col-form-label text-md-right" style="font-weight: bold;">Veličiny k zobrazení:</label></div>
                            <div class="form-group row">
                                <label for="parametry" class="col-md-4 col-form-label text-md-right">Veličina z čidla</label>
                                <label for="parametry" class="col-md-2 col-form-label text-md-right">Zobrazit</label>
                                <label for="parametry" class="col-md-5 col-form-label text-md-right">Zobrazovaná veličina a jednotka</label>

                            </div>
                                @foreach($stanice->getDataEdit() as $id => $data)
                                <div class="form-group row">
                                    <label for="parametry" class="col-md-4 col-form-label text-md-right">{{ $data->sloupec_velicina }}</label>
                                    <div class="col-md-2">
                                        <label for="{{$data->sloupec_velicina}}">
                                            <input type="hidden" name="zobrazeni[{{$data->sloupec_velicina}}]" value=0>
                                            <input id="{{$data->sloupec_velicina}}" type="checkbox" style="width: auto; position: relative; left: 36px;" class="form-control" name="zobrazeni[{{$data->sloupec_velicina}}]" {{ old($data->sloupec_velicina, 1 === $data->zobrazit ? 'checked': '') }}>
                                        </label>
                                    </div>
                                    <div class="col-md-4">
                                        <label for="typ_veliciny">
                                            <select id="typ_veliciny" name="vizitka[{{$data->idVizitky}}]" style="position: relative; left: 30px;">
                                                @foreach($vizitka as $idVel => $veliciny)
                                                    @if($data->idnazvoslovi_veliciny === $veliciny->idnazvoslovi_veliciny && $veliciny->jednotka !== '')
                                                        <option selected value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }} [ {{$veliciny->jednotka}} ]</option>
                                                    @elseif($data->idnazvoslovi_veliciny === $veliciny->idnazvoslovi_veliciny && $veliciny->jednotka === '')
                                                            <option selected value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }}</option>
                                                    {{-- hodnota veliciny 1 odpovidá DB nedefinovano --}}
                                                    @elseif($data->idnazvoslovi_veliciny === null && $veliciny->idnazvoslovi_veliciny === 1)
                                                        <option selected value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }}</option>
                                                    @elseif($veliciny->jednotka === null)
                                                        <option value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }}</option>
                                                    @elseif($veliciny->jednotka === '' || $veliciny->jednotka ==='-')
                                                        <option value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }}</option>
                                                    @else
                                                        <option value='{{ $veliciny->idnazvoslovi_veliciny }}'>{{ $veliciny->nazev }} [{{$veliciny->jednotka}}]</option>
                                                    @endif
                                                @endforeach
                                            </select>
                                        </label>
                                    </div>
                                </div>
                                @endforeach

                            <div class="form-group row mb-0">
                                <div class="col-md-6 offset-md-4">
                                    <button type="submit" class="btn btn-primary">
                                        {{ __('Uložit') }}
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="col-xs-6" style="width: 550px; height: 500px;">
                <h3>Náhled vizitky</h3>
                {!! \App\Http\Controllers\StaniceController::getMapaAStaniceVBladeVizitka($stanice->idStanice) !!}
            </div>
        </div>
    </div>
    @include('layouts.modal')
    @include('layouts.modalAdresy')
@endsection

