@extends('backend.layouts.master')
@section('title')
    Module Listing Page
@endsection
@section('css')

@endsection
<!-- page content -->
@section('content')
    <div class="right_col" role="main">
        <div class="">
            <div class="clearfix"></div>
            @if(Session::has('success'))
                <div class="alert alert-success">
                    {{ Session::get('success') }}
                </div>
            @endif
            @if(Session::has('error'))
                <div class="alert alert-danger">
                    {{ Session::get('error') }}
                </div>
            @endif
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>Manage Module
                                <a href="{{route('backup.index')}}" class="btn btn-xs btn-primary">New Backup</a>
                            </h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div class="row search-section">
								<form action="{{route('backup.index')}}" id="searchForm" method="Get">
                                    <div class="col-sm-2">
                                        <div class="form-group">
                                            <button type="button" class="btn btn-danger btn-xs" onclick="event.preventDefault();document.getElementById('cleanBackup').submit()" >
                                                <i class="ace-icon fa fa-trash fa-2x icon-only"></i>
                                            </button>
                                            <form id="cleanBackup" action="{{route('backup.clean')}}" method="POST" style="display: none;">
                                                {{ csrf_field()}}
                                                {{ method_field('DELETE') }}
                                            </form>
                                            <button class="btn btn-info btn-xs" onclick="event.preventDefault();document.getElementById('newBackup').submit()" type="button">
                                                <i class="ace-icon fa fa-cloud fa-2x icon-only"></i>
                                            </button>
                                            <form id="newBackup" action="{{route('backup.store')}}" method="Post" style="display:none;">
                                                {{ csrf_field()}}
                                            </form>
                                        </div>
                                    </div>
                                    <div class="col-sm-5"></div>
                                    <div class="col-sm-5">
                                        <div class="input-group">
                                            <input type="text" id="myInput" class="form-control" placeholder="Search">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-purple btn-sm">
                                                    <span class="ace-icon fa fa-search icon-on-right bigger-110"></span></button>
                                            </span>
                                        </div>
                                    </div>
                                </form> 
							</div>
                            <div class="table-content">
                                <table id="" class="table table-bordered" role="grid" aria-describedby="dynamic-table_info">
                                    <thead>
                                        <tr>
                                            <th>SL</th>
                                            <th>File Name</th>
                                            <th>Size</th>
                                            <th>DateTime</th>
                                            <th>Times</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($backups as $i=>$backup)
                                        <tr>
                                            <td>{{ $i + 1}}</td>
                                            <td>{{ $backup['file_name'] }}</td>
                                            <td>{{ $backup['file_size'] }}</td>
                                            <td>{{ $backup['last_modified'] }}</td>
                                            <td>{{ \Carbon\Carbon::parse($backup['last_modified'])->diffForHumans() }}</td>
                                            <td>
                                                
                                                <a href="{{route('backup.download',$backup['file_name'])}}"><i class="ace-icon fa fa-download bigger-160 fa-2x"></i></a>
                                                
                                                <a class="red" href="#" data-toggle="tooltip" title="Delete Information!" onclick="deleteData({{ $i+1 }})"><i class="fa fa-trash-o bigger-160 fa-2x"></i></a>
                                                <form id="delete-form-{{ $i+1 }}" action="{{ route('backup.destroy',$backup['file_name']) }}" method="POST" style="display: none;">
                                                    {{ csrf_field()}}
                                                    {{ method_field('DELETE') }}
                                                </form>
                                                
                                            </td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection

@push('js')
<script>
    function deleteData(id) {
		var conf = confirm('Do you want to really Delete?');
		  if(conf == true)
		  {
			document.getElementById('delete-form-'+id).submit();
		  }
        }
</script>
@endpush