@extends('painel.template.Layout.padrao')
@section('titulo', 'Painel Produtos')
@section('conteudo')
  <style type="text/css">
    .btnremove {
      margin-top: -180px;
      margin-left: 30px;
      width: 100px;
      height: 30px;
      padding: 0;
      border: 0 none;
      background: transparent;
      color: transparent;
    }
    .btnremove:hover {
      visibility: visible;
      filter: opacity(75%) !important;
    }
  </style>
  <div class="content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-header border-0">
              <div class="d-flex justify-content-between">

                @if(Route::is('admin.manProdutos'))
                  <h3 class="card-title">Editar Produto</h3>
                  @php
                    $prod = $produtos->first();
                  @endphp
                @else
                  <h3 class="card-title">Cadastrar Produto</h3>
                @endif
              </div>
            </div>
            <div class="card-body">
              <form id="formManProd" name="formManProd" novalidate="novalidate" action="{{ route('admin.saveprod') }}"
                    method="POST" enctype="multipart/form-data">

                <div class="card">
                  <div class="card-body">
                    {{ csrf_field() }}
                    <div class="row">
                      <input type="hidden" name="codigo" value="{{isset($prod->codigo)  ? $prod->codigo : '' }}"/>

                      <div class="col-2">
                        <label>Descrição</label>
                      </div>
                      <div class="col">
                        <input class="form-control form-control-sm" type="text" name="descricao"
                               value="{{$prod->descricao  ?? '' }}">
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-2">
                        <label>Descrição Detalhada</label>
                      </div>
                      <div class="col">

<textarea class="form-control" id="story" name="descrideta" rows="5" cols="33">
{{$prod->descrideta  ?? '' }}
</textarea>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-2">
                        <label>Estoque</label>
                      </div>
                      <div class="col">
                        <input class="form-control form-control-sm" type="text" name="estoqueeco"
                               value="{{formataValor($prod->estoqueeco ?? '0', 13,3) ?? '0,000' }}">
                      </div>
                      <label>Preço</label>
                      <div class="col">
                        <input class="form-control form-control-sm" type="text" name="precoeco"
                               value="{{formataValor($prod->precoeco ?? '0', 13,3) ?? '0,000' }}">
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-2">
                        <label>Largura (cm)</label>
                      </div>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          <input class="form-control form-control-sm" type="text" name="largura"
                                 value="
{{substr($prod->dimeneco,strpos($prod->dimeneco, 'L')+1,(strpos($prod->dimeneco, 'X')-strpos($prod->dimeneco, 'L')-1)) ?? '' }}
                                   ">
                        @else
                          <input class="form-control form-control-sm" type="text" name="largura" value="">
                        @endif
                      </div>
                      <label>Altura (cm)</label>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          <input class="form-control form-control-sm" type="text" name="altura"
                                 value="
{{substr($prod->dimeneco,strpos($prod->dimeneco, 'A')+1,(strpos($prod->dimeneco, 'P')-1-strpos($prod->dimeneco, 'A')-1))  ?? '' }}
                                   ">
                        @else
                          <input class="form-control form-control-sm" type="text" name="altura" value="">
                        @endif
                      </div>
                      <label>Comprimento (cm)</label>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          <input class="form-control form-control-sm" type="text" name="comprimento"
                                 value="
{{substr($prod->dimeneco,strpos($prod->dimeneco, 'P')+1,(strpos($prod->dimeneco, 'X')-strpos($prod->dimeneco, 'L')-1)) ?? '' }}
                                   ">
                        @else
                          <input class="form-control form-control-sm" type="text" name="comprimento" value="">
                        @endif
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-2">
                        <label>Entrega Gratis</label>
                      </div>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          @if ($prod->entfreeeco == 1)
                            <input class="form-control-sm" type="checkbox" name="entfreeeco" checked>
                          @else
                            <input class="form-control-sm" type="checkbox" name="entfreeeco">
                          @endif
                        @else
                          <input class="form-control-sm" type="checkbox" name="entfreeeco">
                        @endif
                      </div>
                      <label>Destacar Produto</label>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          @if ($prod->destproeco == 1)
                            <input class="form-control-sm" type="checkbox" name="destproeco" checked>
                          @else
                            <input class="form-control-sm" type="checkbox" name="destproeco">
                          @endif
                        @else
                          <input class="form-control-sm" type="checkbox" name="destproeco">
                        @endif
                      </div>
                      <label>Exibir Produto</label>
                      <div class="col">
                        @if(Route::is('admin.manProdutos'))
                          @if ($prod->exproeco == 1)
                            <input class="form-control-sm" type="checkbox" name="exproeco" checked>
                          @else
                            <input class="form-control-sm" type="checkbox" name="exproeco">
                          @endif
                        @else
                          <input class="form-control-sm" type="checkbox" name="exproeco">
                        @endif
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-2">
                        <label>Imagem</label>
                      </div>
                      <div class="col">
                        <div class="input-group input-group-sm ">
                          <div class="custom-file small">
                            <input type="file" id="inputGroupFile04" name="caminho">
                          </div>
                        </div>
                      </div>
                    </div>
                    <br>
                    <div class="row">
                      @foreach ($imagens as $img)
                        @if(isset($img->codigo))
                          <div class="" style="height: 150px; width: 150px; margin-left: 3px; margin-top: 3px">
                            <a class="">
                              <img src="{{asset($img->caminho ?? '' )}}"
                                   class="img-thumbnail"
                                   style="height: 150px; width: 150px; margin: 2px; border: 1px solid"
                                   alt="{{$prod->descricao ?? '' }}"
                                   data-toggle="modal" data-target="">
                              <button class="btn btn-sm btn-danger btnremove" type="button" data-toggle="modal"
                                      data-target="#modalDel{{$img->codseq??''}}">remover
                              </button>
                            </a>
                          </div>
                        @endif
                        {{--modaldel--}}
                        <div class="modal fade" id="modalDel{{$img->codseq??''}}" tabindex="-1"
                             role="dialog" aria-labelledby="modalDel{{$img->codseq??''}}"
                             aria-hidden="true">
                          <div class="modal-dialog modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="modal-header text-right">
                                <h5 class="text-center">Deseja realmente excluir está foto?</h5>
                              </div>
                              <div class="modal-body">
                                <div class="card">
                                  <p></p>
                                  <div style="text-align: center;" class="align-content-center">
                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                                    <button type="button" class="btn btn-danger"
                                            onclick="location.href = '{{ route('admin.deleteFoto',['id' => $img->codigo??''  , 'seq'=> $img->seq??'', 'caminho'=>$img->caminho??'', 'codprod'=>$prod->codigo??'', 'tipo' => $img->tipo??'']) }}'">
                                      Excluir
                                    </button>
                                  </div>
                                  <p></p>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      @endforeach
                    </div>
                  </div>
                </div>
                <div class="row justify-content-center">
                  <button type="button" align="center" class="btn btn-secondary"
                          onclick="location.href = '{{route('admin.produtos')}}'">Fechar
                  </button>
                  <button type="submit" class="btn btn-success" id="btnModal" align="center">Salvar</button>
                </div>


              </form>
            </div>

          </div>
          <!-- /.card -->
        </div>
      </div>
      <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
  </div>
@endsection


