@extends('layout.app')

@section('center-area')
@parent

    <head>
    <title>Edycja jednostki straży pożarnej</title>
    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
  </head>


    <h2>Edytuj jednostkę</h2>
    <form method="POST" action="/jednostka/edit">
        {{ csrf_field() }}
        <input type="hidden" class="form-control" name="fireStationID" value="{{ $fireStation->id }}">
        <div class="form-group">
            <label for="name">Nazwa Jednostki:</label>
            <input type="text" class="form-control" id="fireStationName" name="fireStationName" value="{{ $fireStation->name  }} ">
        </div>

        <div class="form-group">
            <label for="name">Numer Jednostki:</label>
            <input type="text" class="form-control" id="number" name="number" value="{{ $fireStation->number }}">
        </div>

        <div class="form-group">
            <label for="voivodeship">Województwo:</label>
            <select name="voivodeship" class="form-control" style="width:250px">
                 <option value="">--- Wybierz województwo ---</option>
                @foreach ($voivodeships as $key => $value)
                <option value="{{ $key }}">{{ $value }}</option>
                @endforeach
            </select>
        </div>
        <div class="form-group">
            <label for="county">Powiat:</label>
            <select name="county" class="form-control"style="width:250px">
            <option>--Wybierz powiat--</option>
            </select>
        </div>
        <div class="form-group">
            <label for="community">Gmina:</label>
            <select name="community" class="form-control"style="width:250px">
            <option>--Wybierz gminę--</option>
            </select>
        </div>

        <div class="form-group">
            <label for="name">Urząd Pocztowy:</label>
            <input type="text" class="form-control" id="postOffice" name="postOffice" value="{{ $fireStation->postOffice }}">
        </div>

        <div class="form-group">
            <label for="name">Kod Pocztowy:</label>
            <input type="text" class="form-control" id="zipCode" name="zipCode" value="{{ $fireStation->zipCode }}">
        </div>

        <div class="form-group">
            <label for="name">Ulica:</label>
            <input type="text" class="form-control" id="address" name="address" value="{{ $fireStation->address }}">
        </div>

        <div class="form-group">
            <label for="name">Szerokość Geograficzna:</label>
            <input type="text" class="form-control" id="latitude" name="latitude" value="{{ $fireStation->latitude }}">
        </div>

        <div class="form-group">
            <label for="name">Długość Geograficzna:</label>
            <input type="text" class="form-control" id="longitude" name="longitude" value="{{ $fireStation->longitude }}">
        </div>

        <div class="form-group">
            <label for="name">KRS:</label>
            <input type="text" class="form-control" id="KRS" name="KRS" value="{{ $fireStation->KRS }}">
        </div>

        <div class="form-group">
            <label for="name">NIP:</label>
            <input type="text" class="form-control" id="NIP" name="NIP" value="{{ $fireStation->NIP }}">
        </div>

        <div class="form-group">
            <label for="name">Numer telefonu:</label>
            <input type="text" class="form-control" id="phoneNumber" name="phoneNumber" value="{{ $fireStation->phoneNumber }}">
        </div>

        <div class="form-group">
            <label for="name">Email:</label>
            <input type="email" class="form-control" id="email" name="email" value="{{ $fireStation->email }}">
        </div>



        <div class="form-group">
            <button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
        </div>
        @include('inc.formerrors')
    </form>

<script type="text/javascript">
    jQuery(document).ready(function ()
    {
            jQuery('select[name="voivodeship"]').on('change',function(){
               var voivodeshipID = jQuery(this).val();
               if(voivodeshipID)
               {
                  jQuery.ajax({
                     url : '/./jednostka/getcounties/' +voivodeshipID,
                     type : "GET",
                     dataType : "json",
                     success:function(data)
                     {
                        //console.log(data);
                        jQuery('select[name="county"]').empty();
                        jQuery('select[name="county"]').append(new Option('--Wybierz powiat--', ''));
                        jQuery('select[name="community"]').empty();
                        jQuery.each(data, function(key,value){
                           $('select[name="county"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });

                     }
                  });
               }
               else
                {
                  $('select[name="county"]').empty();
                  $('select[name="community"]').empty();

                }
            });

            jQuery('select[name="county"]').on('change',function(){
              var countyID = jQuery(this).val();
              if(countyID)
               {
                  jQuery.ajax({
                     url : '/./jednostka/getcommunities/' +countyID,
                     type : "GET",
                     dataType : "json",
                     success:function(data)
                     {
                        //console.log(data);
                        jQuery('select[name="community"]').empty();
                        jQuery.each(data, function(key,value){
                           $('select[name="community"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });
                     }
                  });
               }
               else
               {
                  $('select[name="community"]').empty();
               }
            });




    });

    </script>
@stop
