@extends('admin/layouts/default')
{{-- Page title --}}
@section('title')
Journal Banner List
@parent
@stop
{{-- page level styles --}}
@section('header_styles')
<!--page level css -->
<link href="{{ asset('assets/css/pages/tables.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('assets/vendors/select2/css/select2.min.css') }}" type="text/css" rel="stylesheet">
<link href="{{ asset('assets/vendors/select2/css/select2-bootstrap.css') }}" rel="stylesheet">
<!--end of page level css-->
@stop
{{-- Page content --}}
@section('content')
<section class="content-header">
    <!--section starts-->
    <h1>Manage Shareable Link</h1>
    <ol class="breadcrumb">
        <li>
            <a href="{{ route('admin.dashboard') }}">
            <i class="livicon" data-name="home" data-size="18" data-loop="true"></i>
            Dashboard
            </a>
        </li>
        <li class="active">Shareable Link List</li>
    </ol>
</section>
<!--section ends-->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- BEGIN SAMPLE TABLE PORTLET-->
            <div class="portlet box primary">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="livicon" data-name="responsive" data-size="16" data-loop="true" data-c="#fff" data-hc="white"></i>
                        Shareable Link 
                    </div>
                    @if($createPermission)
                        <a class="btn btn-sm btn-default button-alignment pull-right mb-1" title="Add New Journal" href="{{ route('shareable.create') }}"><span class="glyphicon glyphicon-plus"></span> New</a>
                    @endif    
                </div>
                <div class="portlet-body table-responsive">
                    @if ($message = Session::get('success'))
                        <div class="alert alert-success alert-dismissable">
                            <p>{{ $message }}</p>
                        </div>
                    @endif

                   <form action="" method="Get"  id="shareable_frm" enctype="multipart/form-data">
                   
                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">User Name</label>
                            <input type="text" id="user_name" name="user_name" value="{{$param['user_name']}}" class="form-control" placeholder="Search by User Name...">
                        </div>
                   
                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">User Email</label>
                            <input type="text" id="user_email" name="user_email" value="{{$param['user_email']}}" class="form-control" placeholder="Search by User Email...">
                        </div>
                   
                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">D.O.I</label>
                            <input type="text" id="doi" name="doi" value="{{$param['doi']}}" class="form-control" placeholder="Search by D.O.I...">
                        </div>

						<div class="form-group col-md-3" style="margin-top: 25px;">

							<button type="submit" class="btn btn-primary w-50" name="frm_search" value ="true">
								<span class="glyphicon glyphicon-search"></span>  Search
							</button>
							<a href="{{ URL::to('admin/shareable') }}"  id="btn_reset" class="btn btn-default">Reset</a>
						</div>
                        
						
                    </form>
                    <br>
                    <table class="table table-striped table-bordered small" id="article_table">
                        <thead>
                            <tr>
                                <th class="text-center" style="vertical-align: middle;">S.#.</th>
                                <th class="text-center" style="vertical-align: middle;"><span class="fa fa-fw fa-users fa-lg" title="User Name"></span></th>
                                <th class="text-center" style="vertical-align: middle;"><span class="fa fa-fw fa-envelope fa-lg" title="User Email"></span></th>
                                <th class="text-center" style="vertical-align: middle;">D.O.I</th>
                                <th class="text-center" style="vertical-align: middle;">Download Allow</th>
                                <th class="text-center" style="vertical-align: middle;">From Date</th>
                                <th class="text-center" style="vertical-align: middle;">To Date</th>
                                <th class="text-center" style="vertical-align: middle;"><span class="fa fa-fw fa-link fa-lg" title="Shareable Link"></span></th>
                                <th class="text-center" style="vertical-align: middle;"><span class="fa fa-fw fa-download fa-lg" title="Downloaded"></span></th>
                                <th class="text-center" style="vertical-align: middle;">Status</th>
                                <th class="text-center" style="vertical-align: middle;">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (count($shareable_list) > 0)
                             @php $a=1;  @endphp
                            @foreach($shareable_list as $key => $value)
                            <tr>
                                <td>{{ $a }}</td>
                                <td>{{ $value->name }}</td>
                                <td class="whitespace-normal">{{ $value->email }}</td>
                                <td class="whitespace-normal">{!! $value->doi !!}</td>
                                <td class="text-center">{!! $value->nod_allow !!}</td>
                                <td class="text-center">{{ strftime('%Y-%m-%d',$value->from_date) }}</td>
                                <td class="text-center">{{ strftime('%Y-%m-%d',$value->to_date) }}</td>
                                <td><span id="{{$value->shareable_link_id}}" style="display:none">{{ $value->link }}</span> 

                                <button type="button" class="btn btn-info btn-sm" title="Click to copy link" onclick="copyToClipboard('#{{$value->shareable_link_id}}')"><i class="livicon mt-2" data-name="link" data-loop="true" data-color="#fff" data-hc="#fff" data-hovercolor="white" data-size="18"></i></button>

                            </td>
                                <td class="text-center">{{ $value->downloaded }}</td>
                                <td>
                                    @if($value->status == "Active") 
                                        <span class="label label-success">{{$value->status}}</span>
                                    @elseif($value->status == "Expire") 
                                        <span class="label label-warning">{{$value->status}}</span>
                                    @elseif($value->status == "Awaiting") 
                                        <span class="label label-info">{{$value->status}}</span>
                                    @elseif($value->status == "Deleted") 
                                        <span class="label label-danger">{{$value->status}}</span>
                                    @endif
                                </td>
                                <td class="text-nowrap">

                                @if($editPermission)
                                <a href="{{ route('shareable.edit',$value->shareable_link_id) }}" class="btn btn-primary btn-sm pull-left mb-1" title="Edit Banner">
                                        <i class="livicon mt-2" data-name="pen" data-loop="true" data-color="#fff" data-hovercolor="white" data-size="18"></i>
                                    </a> 
                                 @endif       
                                @if($deletePermission && $value->status != "Deleted")
                                    <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#Del{{ $value->shareable_link_id }}" title="Delete Banner"><i class="livicon mt-2" data-name="trash" data-loop="true" data-color="#fff" data-hovercolor="white" data-size="18"></i></button>
                                        <!-- Modal -->
                                      <div class="modal fade" id="Del{{ $value->shareable_link_id }}" role="dialog">
                                        <div class="modal-dialog">
                                        
                                          <!-- Modal content-->
                                          <div class="modal-content">
                                            <div class="modal-header">
                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
                                              <h3 class="modal-title text-danger">Confirmation</h3>
                                            </div>
                                            <div class="modal-body">
                                              <p><strong>Are you sure you want to delete this record?</strong></p>
                                            </div>
                                            <div class="modal-footer">                                                    
													<form method="POST" action="{{ route('shareable.destroy', $value->shareable_link_id) }}">
                                                        @csrf
                                                        <input name="_method" type="hidden" value="DELETE">
                                                        <input class="btn btn-danger" type="submit" value="Yes">
                                                        <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                                                    </form> 
                                           
                                            </div>
                                          </div>
                                        </div>
                                      </div>
                                    @endif                                  
                                </td>
                                 @php $a++;  @endphp
                            </tr>
                            @endforeach
                            @else
                            <tr>
                                <td colspan="11">
                                    <center>Empty</center>
                                </td>
                            </tr>
                            @endif
                        </tbody>
                    </table>
                    @if (count($shareable_list) > 0)
                    <center>{{ $shareable_list->appends(request()->input())->links() }}</center>
                    @endif
                </div>
            </div>
            <!-- END SAMPLE TABLE PORTLET-->
        </div>
    </div>
</section>
@stop
<script type="text/javascript">
    function copyToClipboard(element) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(element).text()).select();
    document.execCommand("copy");
    $temp.remove();
    }
</script>

