@extends('layouts.company')
@section('content')


<!-- start page title -->
<div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
            <h4 class="mb-sm-0">Challenge Report</h4>

            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li>
                    <li class="breadcrumb-item active">Challenge challenge</li>
                </ol>
            </div>
        </div>
    </div>
</div>
<!-- end page title -->

<div class="row">
    <div class="col-lg-12">
        <div class="card" id="orderList">
            <div class="card-header border-0">
                <div class="row align-items-center gy-3">
                    <div class="col-sm">
                        <h5 class="card-title mb-0">Challenge Report</h5>
                    </div>
                    <div class="col-sm-auto">
                        <div class="d-flex gap-1 flex-wrap">
                            <a href="{{ route('company.challenge_report.export') }}" type="button" class="btn btn-info"><i class="ri-file-download-line align-bottom me-1"></i> Export</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body border border-dashed border-end-0 border-start-0">
                <form method="GET" action="{{ route('company.challenge_report') }}">
                    <div class="row g-3 align-items-end">
                        
                        
                        <div class="col-lg-4 mb-3">
                            <label class="form-label">Challenge</label>
                            <select class="form-select js-example-basic-single" data-placeholder="Select Challenge" name="challenge">
                                <option value=""></option>
                                @foreach($allChallenges as $challenge)
                                    <option value="{{ $challenge->id }}" {{ request('challenge') == $challenge->id ? 'selected' : '' }}>{{ $challenge->name }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-lg-4 mb-3">
                            <button type="submit" class="btn btn-primary">Filter</button>
                            <a  href="{{ route('company.challenge_report') }}" type="submit" class="btn btn-soft-dark">Clear</a>
                        </div>
                    </div>
                    <!--end row-->
                </form>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table id="example" class="table table-bordered nowrap align-middle" style="width: 100%;">
                        <thead class="">
                            <tr class="text-uppercase">
                                <th>Sl No</th>
                                
                                <th>Challenge Name</th>
                                <th>Challenge For</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Total Challenge User</th>
                                <th>Active Challenge User</th>
                                <th>Progress</th>
                            </tr>
                        </thead>
                        <tbody class="list form-check-all">
                        @foreach($challenges as $index => $challenge)
                            <tr>
                                <td class="id">{{ $index + 1 }}</td>

                                <td>{{ $challenge->name }}</td>
                                <td>{{ $challenge->challengeFor }}</td>
                                <td>{{ $challenge->start_date->format('M d, Y') }}</td>
                                <td>{{ $challenge->end_date->format('M d, Y') }}</td>
                                <td>{{ $challenge->total_users }}</td>
                                <td>{{ $challenge->active_users }}</td>
                                <td>
                                    <div class="progress animated-progress custom-progress progress-label">
                                        <!-- <div class="progress-bar bg-dark" role="progressbar" style="width: 20%;" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100">
                                            <div class="label">20%</div>
                                        </div> -->
                                        <div class="progress-bar bg-dark" role="progressbar" style="width: {{ $challenge->progress }}%;" aria-valuenow="{{ $challenge->progress }}" aria-valuemin="0" aria-valuemax="100">
                                            <div class="label">{{ $challenge->progress }}%</div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--end col-->
</div>
<!--end row-->
@endsection
@section('script')
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/additional-methods.min.js"></script>
  
<script>
    $(document).ready(function() {
        $('#CompanyReport').DataTable({
            responsive: true, 
            paging: true,     
            searching: true,  
            ordering: true,   
            lengthChange: true, 
            
        });
    });

   </script>
   <script>
    $(document).ready(function() {
        // Event listener for the "Clear" button
        $('#clearButton').on('click', function(e) {
            e.preventDefault(); // Prevent form submission
            $('#filterForm')[0].reset(); // Reset the form fields

            // Reload the page without query parameters
            window.location.href = window.location.pathname; // Remove the query string from the URL
        });
    });
</script>

@endsection
