{{ csrf_field() }}
<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title"></h3>
    </div>

    <div class="box-body">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="title">Titolo:</label> <span id="chars">{{isset($event) ? 90 - strlen($event->title) : 90}} caratteri rimanenti</span>
                    <input type="text" name="title" class="form-control title" maxlength="90" value="{{ old('title', isset($event) ? $event->title : '') }}">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="text_short">Testo breve:</label>
                    <input type="text" name="text_short" id="text_short" class="form-control"
                           value="{{ old('text_short', isset($event) ? $event->text_short : '') }}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label for="text">Testo:</label>
                    <textarea name="text" id="text" rows="10" cols="100" class="js-editor">{{ old('text', isset($event) ? $event->text : '') }}</textarea>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="slug">Slug:</label>
                    <input type="text" name="slug" id="slug" class="form-control slug"
                           value="{{ old('slug', isset($event) ? $event->slug : '') }}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="image">Immagine:</label><br>
                    <div class="custom-file-upload"><input type="file" name="image" class="form-control"></div>
                    @if (isset($event) && $event->image != '')
                        <br><img src="/files/events/{{$event->image}}" style="max-width:250px" />
                    @endif
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="online">Online:</label><br>
                    <input type="checkbox" name="online" value="on" {{ old('online') ? 'checked' : '' }}>
                </div>
            </div>
        </div>
    </div>

    <div class="box-footer">
        <button type="submit" class="btn btn-success" name="save">{{ $submit_text }}</button>
        <a href="{{ route('events.index') }}" class="btn btn-info">Annulla</a>
    </div>
</div>

@section('extra_js')

    <script src="/backend/plugins/input-mask/jquery.inputmask.js"></script>
    <script src="/backend/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="/backend/plugins/input-mask/jquery.inputmask.extensions.js"></script>

    <script>

        $(function () {



            $('.js-editor').summernote(
                {
                    lang: 'it-IT'
                }

            );

            // $('.js-editor').wysihtml5()

            $(".title").keyup(function(){
                var Text = $(this).val();
                Text = Text.toLowerCase();
                Text = Text.replace(/[^a-zA-Z0-9]+/g,'-');
                $(".slug").val(Text);
            });

            $('.title').on("keyup change", function () {

                const max = 90;
                const len = $(this).val().length;

                if (len >= max)
                {
                $('#chars').text("0 caratteri rimanenti");
                }
                else
                {

                  const char = max - len;
                  $('#chars').text(char + '  caratteri rimanenti');
                }
              });

        });

    </script>
@stop
