@extends('layouts.app')

@section('content')
<div class="container">
<section class="content-wrapper">
<div class="row pa-2">
    <div class="col-12 col-md-12 col-lg-12 pl-4"></div>
        <div class="card">
            @if (session('status'))
            <div class="row">
                <div class="col-sm-12">
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <span>{{ session('status') }}</span>
                    </div>
                </div>
            </div>
            @endif
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4 col-lg-4 d-flex align-items-center">
                        <h5>Reports</h5>
                    </div>
                    <div class="col-md-6 col-lg-6 d-flex justify-content-end">
                        <form id="import" action="{{route('import-report')}}" method="post" enctype="multipart/form-data">
                            @csrf
                            <input id="fileinput" type="file" name="file_to_import" onchange="onChange()" hidden/>
                        </form>
                        <button class="btn btn-primary bg-primary text-white" id="falseinput" onclick="openInput()">Import</button>
                    </div>
                    <div class="col-md-2 col-lg-2 d-flex justify-content-end">
                        <a href="{{route('export-report')}}" style="font-size: .9rem;" class="btn btn-primary bg-primary text-white">Excel Export</a>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-12 col-md-12 col-lg-12">
                    <div class="table-responsive p-2">
                        <table style="font-size: .9rem; margin-bottom: 0;" class="table">
                            <thead>
                                <tr>
                                    <th style="vertical-align: middle;">Time A</th>
                                    <th style="vertical-align: middle;">Position A</th>
                                    <th style="vertical-align: middle;">Time B</th>
                                    <th style="vertical-align: middle;">Position B</th>
                                    <th style="vertical-align: middle;">Duration</th>
                                    <th style="vertical-align: middle;">Length</th>
                                    <th style="vertical-align: middle;">Fuel Consumption</th>
                                    <th style="vertical-align: middle;">Avg.fuel cons. (100km)</th>
                                    <th style="vertical-align: middle;">Fuel Cost</th>
                                    <th style="vertical-align: middle;">Driver</th>
                                    <th style="vertical-align: middle;">Trailer</th>
                                    <!-- <th style="vertical-align: middle;" class="text-right">Actions</th> -->
                                </tr>
                            </thead>
                            <tbody>
                                @if(isset($report_datas))
                                @foreach($report_datas as $index => $report)
                                <tr>
                                    <td style="vertical-align: middle;">{{  $report->start_time }}</td>
                                    <td style="vertical-align: middle;">{{  $report->start_position }}</td>
                                    <td style="vertical-align: middle;">{{  $report->end_time }}</td>
                                    <td style="vertical-align: middle;">{{  $report->end_position }}</td>
                                    <td style="vertical-align: middle;">{{  $report->duration }}</td>
                                    <td style="vertical-align: middle;">{{  $report->length }}</td>
                                    <td style="vertical-align: middle;">{{  $report->fuel_consumption }}</td>
                                    <td style="vertical-align: middle;">{{  $report->avg_fuel_consumption }}</td>
                                    <td style="vertical-align: middle;">{{  $report->fuel_cost }}</td>
                                    <td style="vertical-align: middle;">{{  $report->driver }}</td>
                                    <td style="vertical-align: middle;">{{  $report->trailer }}</td>
                                    <!-- <td style="vertical-align: middle;" class="text-right">
                                        <form id="deleteForm" action="#" method="post">
                                            @csrf
                                            @method('delete')
                                            <div class="m-0 row justify-content-end">
                                                <button type="button" class="btn btn-danger bg-danger btn-sm text-white" onClick="DeleteConfirm()" data-original-title=""><ion-icon name="trash"></ion-icon></button>
                                            </div>
                                        </form>
                                    </td> -->
                                </tr>
                                @endforeach
                                @else
                                <tr>
                                    No data found
                                </tr>
                                @endif
                            </tbody>
                        </table>
                        
                    </div>
                    <div class="d-flex justify-content-center">
                    {{ $report_datas->links('user.pagination') }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</section>
<script>
function openInput() {
    console.log("Button clicked");
    document.getElementById("fileinput").click();
}
function onChange() {
    document.getElementById('import').submit();
}
</script>
</div>
@endsection
