{{ 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">
                    {!! Form::label('title', 'Titolo:') !!} <span id="chars">{{isset($page) ? 90 - strlen($page->title) : 90}} caratteri rimanenti</span>
                    {!! Form::text('title', null, array('class' => 'form-control title', 'maxlength' => 90)) !!}
                </div>                
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('text_short', 'Testo breve:') !!}
                    {!! Form::text('text_short', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
        </div>
        <!--
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    {!! Form::label('text', 'Testo:') !!}
                    {!! Form::textarea('text', null, array('rows' => 10, 'cols' => 100, 'class' => 'form-control js-editor')) !!}
                </div>                
            </div>
        </div>
        -->
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('web', 'Sito web:') !!}
                    {!! Form::text('web', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('email', 'Indirizzo email:') !!}
                    {!! Form::text('email', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('facebook', 'Facebook:') !!}
                    {!! Form::text('facebook', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('instagram', 'Instagram:') !!}
                    {!! Form::text('instagram', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('twitter', 'Twitter:') !!}
                    {!! Form::text('twitter', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('youtube', 'Youtube:') !!}
                    {!! Form::text('youtube', null, array('class' => 'form-control')) !!}
                </div>                
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('slug', 'Slug:') !!}
                    {!! Form::text('slug', null, array('class' => 'form-control slug')) !!}
                </div>                
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">    
                <div class="form-group">
                    {!! Form::label('image', 'Immagine:') !!}<br>
                    <div class="custom-file-upload">{!! Form::file('image', null, array('class' => 'form-control')) !!}</div>
                    @if (isset($page) && $page->image != '')
                        <br><img src="/files/pages/{{$page->image}}" style="max-width:250px" />
                    @endif
                </div>            
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    {!! Form::label('online', 'Online:') !!}<br>
                    {!! Form::checkbox('online', 'on', null) !!}
                </div>                
            </div>
        </div>
    </div>

    <div class="box-footer">
        {!! Form::submit($submit_text, ['class'=>'btn btn-success', 'name' => 'save']) !!}
        {!! link_to_route('pages.index', 'Annulla', null, array('class' => 'btn btn-info')) !!}
    </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