@extends('adm.index')
@section('novedades','active')
@section('novedades_true','true')
@section('novedades_show','show')
@section('novedades_collapsed','collapsed')
@section('form')

<style>
    form{
        margin-bottom: 40px !important;
        height: 100%;
    }
    main{
        max-height: none;
    }
</style>

<div class="container">
    <div class="row">
        <div class="col-12">
            <h2>Editar novedad</h2>
        </div>
        <div class="col-12">
            <form method="POST" action="<?= route('editNovedad') ?>" enctype="multipart/form-data">
                @csrf
                <div class="container px-md-0">
                    <div class="row">
                        <div class="col-12 mb-3">
                            <label for="inputOrden" class="form-label">Orden</label>
                            <input type="text" class="form-control" id="inputOrden" name="orden" value="<?= $novedad->orden ?>" required>
                        </div>
                        <div class="col-12 mb-3">
                            <input type="hidden" name="id" value="<?= $novedad->id ?>">
                            <label for="inputTitulo" class="form-label">Titulo</label>
                            <input type="text" class="form-control" value="<?= $novedad->titulo ?>" id="inputTitulo" name="titulo" required>
                        </div>
                        <div class="col-12 mb-3">
                            <label for="descripcion_corta" class="form-label">Descripci&oacute;n corta</label>
                            <textarea class="form-control" name="descripcion_corta" id="descripcion_corta" required cols="30" rows="10" value="<?= $novedad->descripcion_corta ?>">{!!$novedad->descripcion_corta!!}</textarea>
                        </div>
                        <div class="col-12 mb-3">
                            <label for="descripcion_larga" class="form-label">Descripci&oacute;n larga</label>
                            <textarea class="form-control" name="descripcion_larga" id="descripcion_larga" cols="30" rows="10" required value="<?= $novedad->descripcion_larga ?>">{!!$novedad->descripcion_larga!!}</textarea>
                        </div>
                        <div class="col-12">
                            <div class="form-check">
                                <?php if($novedad->destacado == 1){ ?>
                                    <input class="form-check-input" name="destacado" type="checkbox" id="flexCheckDefault" checked="checked">
                                <?php } else { ?>
                                    <input class="form-check-input" name="destacado" type="checkbox" id="flexCheckDefault">
                                <?php } ?>
                                <label class="form-check-label" for="flexCheckDefault">
                                    Destacar novedad
                                </label>
                            </div>
                        </div>
                        <div class="col-12">
                            <div class="mb-3">
                                <label for="categoria" class="form-label">Selecciona la categor&iacute;a</label>
                                <select class="form-select" name="categoria_id" aria-label="Default select example" id="categoria">
                                    <?php foreach($categorias as $categoria){ ?>
                                        <?php if($categoria->id == $novedad->categoria_id){ ?>
                                            <option value="<?= $categoria->id ?>" selected><?= $categoria->nombre ?></option>
                                        <?php } else { ?>
                                            <option value="<?= $categoria->id ?>"><?= $categoria->nombre ?></option>
                                        <?php } ?>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label for="formFile" class="form-label">Imagen(Tama&ntilde;o recomendado: 1080 x 1080 px)</label>
                            <input class="form-control" type="file" id="formFile" name="foto">
                            <img src="{{asset(Storage::url($novedad->foto))}}" class="img-thumbnail mt-4 h-25 w-25">
                        </div>
                    </div>
                    <div class="col-12">
                        <button type="submit" class="btn btn-primary">Actualizar novedad</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
  $(document).ready(function() {
       $('textarea').summernote({
           height: 200,
  toolbar: [
    // [groupName, [list of button]]
    ['style', ['bold', 'italic', 'underline', 'clear']],
    ['font', ['strikethrough', 'superscript', 'subscript']],
    ['fontsize', ['fontsize']],
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']],
    ['view', ['fullscreen', 'codeview', 'help']],
],
});
   });

</script>

@endsection
