@extends('layouts.web')

@section('page-title', 'Multimedia')

@section('content')
	<section class="page-header">
		<div class="page-header__bg" style="background-image: url({{asset('assets/images/header.jpg')}});"></div>
		<div class="container">
			<h2>{{$category}} </h2>
			<ul class="thm-breadcrumb list-unstyled">
				<li class="text-white"><a href="{{url('/')}}">Inicio</a></li>
			</ul>
		</div>
	</section>

@if (Auth::user())
	<div class="row">
		<div class="container py-2">
			<div class="col text-right">
				<a href="{{route('multimedia.create')}}" class="thm-btn">
				<i class="fas fa-plus"></i>  
				Registrar Multimedia
				</a>
			</div>
		</div>
	</div>
@endif


<div class="blog-page">
  <div class="container">
    <div class="row">
	@if (count($multimedia))
		@foreach ($multimedia as $resource)               
				

		<div class="col-sm-12 col-md-6 col-lg-4 {{ $resource->status ?: 'despublicado' }}">
			<div class="blog-card">
				<div class="blog-card__image">
				<div class="blog-card__date">{{ date('d M', strtotime($resource->publish_up)) }}</div><!-- /.blog-card__date -->
				<?php 
					$sep = explode(' ', $resource->embed);
					$width = explode('"',$sep[1]); 
					echo str_replace($sep[1], 'width="100%"', $resource->embed);
				?>
				</div>
				<div class="blog-card__content">
				<div class="blog-card__meta">
				</div>
				<h3>
					<a href="#">
						{{ str_limit($resource->title, $limit = 50, $end = '...') }}
					</a>
				</h3> 
				<p>
					{!! $resource->description !!}
				</p>
				</div>

				@if (Auth::user())
					<div class="card-action teal darken-1">
				
						<div class="">
							<a onclick="trash('{{$resource->id}}','{{$resource->title}}')" class="pull-right btn-floating waves-effect waves-light btn-small red">
								<i class="fa fa-trash" aria-hidden="true"></i>
							</a>
							<a href="{{route('multimedia.edit',$resource->id)}}" class="pull-right btn-floating waves-effect waves-light btn-small blue">
								<i class="fa fa-edit" aria-hidden="true"></i>
							</a>   
						@if($resource->status)
							<a onclick="statusChange('{{$resource->id}}','{{$resource->status}}','{{$resource->title}}')" class="pull-right btn-floating waves-effect waves-light btn-small green tooltipped" data-position="bottom" data-delay="50" data-tooltip="Este registro está PUBLICADO">
								<i class="fa fa-eye" aria-hidden="true"></i>
							</a>   	
						@else 
							<a onclick="statusChange('{{$resource->id}}','{{$resource->status}}','{{$resource->title}}')" class="pull-right btn-floating waves-effect waves-light btn-small green tooltipped" data-position="bottom" data-delay="50" data-tooltip="Este registro está DESPUBLICADO">
								<i class="fa fa-eye-slash" aria-hidden="true"></i>
							</a>   	
						@endif  				           
						</div>
					</div>
				@endif	

			</div>
		</div>

		@endforeach
	@else
		@include('partials.noData')
	@endif
	    
    </div>
  </div>
</div>


	@php $paginates=$multimedia; @endphp
	<div class="container list-unstyled d-flex justify-content-center py-4">
		{{ $paginates->links() }}
	</div>

@stop
@section('scripts')

<script>
function trash(id,title){ 
    var ident = id;
    swal({
     text: 'Esta seguro de realizar esta Acción?',
     title: 'Si procede <span class="btn btn-danger">'+title+'</span> será eliminado!',
     type: 'warning',
     showCancelButton: true,
     confirmButtonColor: '#DD6B55',
     confirmButtonText: 'Eliminar!',
     cancelButtonText: 'Cancelar', 
     closeOnConfirm: false,
     closeOnCancel: false,
     html: true

   },
   function(isConfirm){
       if (isConfirm) { 
       //	console.log(id+'-'+title)
           $.ajax({
               url: '{{ url('/multimedia/delete') }}' + '/' + id, 
               type: "GET",  
               dataType: "JSON", 
               headers: {
                'X-CSRF-TOKEN': $('meta[title="token"]').attr('content')
            },
            success: function (res) {
                console.log(res);
            },
            error: function(res){
                console.log("Error :" + res );
            }
               }); 
               swal(title+' eliminado!', 'Este registro fue eliminado.', 'success');
               window.location.reload(true);

       }else {
           swal('Cancelado!', 'Este registro NO fue eliminado.', 'error');
       }
   });
}
</script>
<script>
function statusChange(id,status,title){
   $.ajax({
       url: '{{ url('/multimedia/statusChange') }}' + '/' + id + '/' + status,
       type: 'GET', 
       headers: {
           'X-CSRF-TOKEN': $('meta[title="token"]').attr('content')
       },
       dataType: "JSON",
       success: function (res) {
           console.log(res);
            if(res.now){
                swal(title+', modificado!', 'este registro está publicado.', 'success');
                window.location.reload(true);
            }else{
                swal(title+', modificado!', 'este registro está despublicado.', 'warning');
                window.location.reload(true);
            }
       },
       error: function(res){
           console.log("Error :" + res );
       }
   }); 
}
</script>

@stop
