@extends('layouts.web')

@section('page-title', 'Edición de Documento'))

@section('content')
<h1 class="headerSection">Registro de Autoridades <br><small> nuevo</small></h1>
<hr> 
<div class="container bootstrap-iso" style="left: 40; padding:2em;">
    {!! Form::open(['method'=>'PUT','route' => array('documentos.update',$documento->id), 'files' => true, 'id' => 'documento-form']) !!} 
 
        <?php $nameInput='publish_up'; $nameObj='Fecha de Publicación'; ?>
        <div class="form-group col-xs-12 list-group-item @if($errors->first($nameInput)) has-error @endif  ">
            {{Form::label($nameInput, $nameObj,['class'=>'control-label datepicker','data-provide'=>'datepicker'])}}
            {{Form::text($nameInput, $documento->publish_up, ['id'=>$nameInput,'placeholder'=>$nameObj,'class'=>'form-control datepicker', 'required' => 'required'])}}
            @if($errors->first($nameInput))<div class="new badge red">{{ $errors->first($nameInput) }} </div>@endif
        </div>

        <?php $nameInput='title'; $nameObj='Título'; ?>
        <div class="form-group col-xs-12 list-group-item @if($errors->first($nameInput)) has-error @endif  ">
            {{Form::label($nameInput, $nameObj,['class'=>'control-label'])}}
            {{Form::text($nameInput, $documento->title, ['id'=>$nameInput,'placeholder'=>$nameObj,'class'=>'form-control' ])}}
            @if($errors->first($nameInput))<div class="new badge red">{{ $errors->first($nameInput) }} </div>@endif
        </div> 

       <?php $nameInput='description'; $nameObj='Descripción del recurso'; ?>
        <div class="form-group col-xs-12 list-group-item @if($errors->first($nameInput)) has-error @endif  ">
            {{Form::label($nameInput, $nameObj,['class'=>'control-label'])}}
            {{Form::text($nameInput, $documento->description, ['id'=>$nameInput,'placeholder'=>$nameObj,'class'=>'form-control' ])}}
            @if($errors->first($nameInput))<div class="new badge red">{{ $errors->first($nameInput) }} </div>@endif
        </div>   

        <div class="form-group col-xs-12 list-group-item file-field input-field despublicado"> 
          <div class="center-align">
            <h4>Archivo actual</h4>
          </div>
          <?php 
            switch ($documento->type) {
              case 'jpg':
              case 'jpeg':
              case 'bmp':
              case 'png':
                echo HTML::image('assets/documents/'.$documento->file, $documento->title, array('class'=>'center-align','width'=>"100%"));
                break;
              
              default:
                echo '<div class="file-field input-field center-align">
                              <a target="_new" href="'.url('assets/documents/'.$documento->file).'" class="pull-right btn-floating waves-effect waves-light btn-small green pulse tooltipped" data-position="bottom" data-delay="50" data-tooltip="Descargar: '.$documento->title.'">
                          <i class="fa fa-download" aria-hidden="true"></i>  
                              </a>
                        </div>';
                break;
            }
          ?>
                        
          </div>       


        <?php $nameInput='file'; $nameObj='Adjuntar un nuevo Archivo'; ?>
                    <div class="form-group col-xs-12 list-group-item file-field input-field @if($errors->first($nameInput)) has-error @endif  ">
                        <div class="file-field input-field">
                              <div class="btn">
                                <span>{{$nameObj}}</span>
                                {{Form::file($nameInput , ['id'=>$nameInput,'placeholder'=>$nameObj,'class'=>'form-control'])}}
                              </div>
                              <div class="file-path-wrapper">
                                <input class="file-path validate" type="text" placeholder="Seleccionar archivo">
                              </div>
                        </div>
                        @if($errors->first($nameInput))
                          @php
                            alert()->error('Compruebe los datos', $errors->first($nameInput) )->persistent('OK');
                          @endphp
                          <div class="new badge red">{{ $errors->first($nameInput) }} </div>
                        @endif
                    </div>       
 

      <hr>
      <div class="row">
            <div class="col-md-12">
                    <button type="submit" id="send" onClick="capture()" class="btn btn-primary btn-lg btn-block waves-effect waves-light">
                            <i class="fa fa-save"></i> Guardar Datos
                    </button>
            </div>
      </div>
      <div class="row">
            <div class="col-md-12">
                    <a class="btn btn-danger btn-lg btn-block waves-effect waves-light" href="{{route('documentos.index')}}">
                            <i class="fa fa-close"></i> Cancelar
                    </a>
            </div>
      </div>
      <hr>
    {!! Form::close() !!}
</div>


@include('partials.modal')

@stop

@section('scripts')

    @include('partials.tinymce')
    @include('partials.scripts')
     
@stop