@extends('admin.layouts.main-layout')
@section('content')
<div class="card">
  <div class="card-header">
    <h3 class="card-title">You Played Game</h3>
  </div>

  <div align="left">
    <!--<a href="{{ url('admin/stores-newgame-schedule/create') }}" class="btn btn-info">Add New</a>-->
  </div>

  <div class="card-body">
    @if(session()->has('message'))
    <div class="alert alert-success">
      {{ session()->get('message') }}
    </div>
    @endif
    <div id="example1_wrapper" class="dt-bootstrap4">
      <div class="row">
        <div class="col-sm-12">
          <div class='tablescroll'>
            <div class="table-responsive">
              <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                <thead>
                  <tr role="row">
                    <th>Sr No.</th>
                    <th>Game Name</th>
                    <th>Day</th>
                    <th>Open Time</th>
                    <th>Close Time</th>
                    <th>View</th>
                  </tr>
                </thead>
                <tbody>
                  @php
                  $page = 1;
                  if(Request::input('page'))
                  $page = Request::input('page');
                  $sort = $lists->perPage();
                  @endphp

                  @php
                  $currentDayId = null;
                  $rowSpanCount = 0;
                  @endphp

                  @forelse($lists as $key => $list)
                  @php
                  $storesGroupedByDay = $list->storesDay->groupBy('stores_day_id')->sortBy(function ($group, $key) {
                  return $key; // Assuming the key represents the day
                  });
                  $gameNameDisplayed = false;
                  $serialNumberDisplayed = false;
                  $actionDisplayed = false;
                  @endphp

                  @foreach($storesGroupedByDay as $dayId => $stores)
                  @php
                  $rowSpanCount = $stores->count();
                  @endphp

                  @foreach($stores as $index => $store)
                  <tr>
                    @if ($index === 0)
                    @if (!$serialNumberDisplayed)
                    <td rowspan="{{ $storesGroupedByDay->flatten()->count() }}">{{ $sort * ($page - 1) + ($key + 1) }}</td>
                    @php $serialNumberDisplayed = true; @endphp
                    @endif
                    @if (!$gameNameDisplayed)
                    <td rowspan="{{ $storesGroupedByDay->flatten()->count() }}">{{ $list->name }}</td>
                    @php $gameNameDisplayed = true; @endphp
                    @endif
                    <td rowspan="{{ $rowSpanCount }}">{{ isset($store->storesDayName)? $store->storesDayName[0]->name:'' }}</td>
                    @endif
                    <td>{{ timeShow($store->opent_time) }}</td>
                    <td>{{ timeShow($store->close_time) }}</td>
                    <td>
                    
                      <a href="{{url('admin/your-store-palyed-open/'.$store->id .'?store_id='.$store->stores_id )}}" class="btn btn-primary">View Open</a>
                     @if($store->stores_id != 9)
                      <a href="{{url('admin/your-store-palyed-close/'.$store->id.'?store_id='.$store->stores_id)}}" class="btn btn-primary">View Close</a>
                      @endif
                    </td>
                    
                    @php $actionDisplayed = true; @endphp

                  </tr>
                  @endforeach
                  @endforeach
                  @empty
                  <tr>
                    <td colspan="6">Record not found</td>
                  </tr>
                  @endforelse
                </tbody>
              </table>
            </div>
          </div>
          <div class="row">
            <div class="col-md-6 text-left" style="margin: 20px 0px;">
              Showing {{$lists->firstItem()}} to {{$lists->lastItem()}} of {{$lists->total()}}
            </div>
            <div class="col-md-6 text-right">
              {!! $lists->appends(request()->input())->links() !!}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
@endsection
@section('js-content')
@endsection