@extends('layouts.admin.app')

@section('title', translate($title))

@section('content')
    <div class="content container-fluid">
        <div class="page-header">
            <h1 class="page-header-title">
                <span class="page-header-icon">
                    <i class="tio-chart-bar-2"></i>
                </span>
                <span>{{ translate($title) }}</span>
            </h1>
        </div>

        <div class="card mb-3">
            <div class="card-body">
                <form action="{{ route($routeName) }}" method="get">
                    <div class="row g-3">
                        <div class="col-sm-6 col-md-3">
                            <input type="search" name="search" value="{{ request('search') }}" class="form-control" placeholder="{{ translate('Search') }}">
                        </div>
                        <div class="col-sm-6 col-md-2">
                            <input type="date" name="from" value="{{ request('from') }}" class="form-control">
                        </div>
                        <div class="col-sm-6 col-md-2">
                            <input type="date" name="to" value="{{ request('to') }}" class="form-control">
                        </div>
                        <div class="col-sm-6 col-md-1">
                            <button class="btn btn--primary btn-block" type="submit">{{ translate('Go') }}</button>
                        </div>
                        <div class="col-sm-6 col-md-1">
                            <a href="{{ route($routeName) }}" class="btn btn--reset btn-block">{{ translate('Reset') }}</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        @if(! empty($summaryCards))
            <div class="row g-3 mb-3">
                @foreach($summaryCards as $card)
                    <div class="col-sm-6 col-lg-3">
                        <div class="card h-100">
                            <div class="card-body">
                                <h6>{{ translate($card['label']) }}</h6>
                                <h3>{{ $card['value'] }}</h3>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
        @endif

        <div class="card">
            <div class="card-header border-0">
                <h5 class="card-title mb-0">{{ translate($title) }}</h5>
            </div>
            <div class="table-responsive">
                <table class="table table-borderless table-thead-bordered mb-0">
                    <thead class="thead-light">
                    <tr>
                        @forelse($columns as $column)
                            <th class="{{ $column['class'] ?? '' }}">{{ translate($column['label']) }}</th>
                        @empty
                            <th>{{ translate('Status') }}</th>
                        @endforelse
                    </tr>
                    </thead>
                    <tbody>
                    @forelse($records as $row)
                        <tr>
                            @foreach($columns as $column)
                                <td class="{{ $column['class'] ?? '' }}">
                                    @if(! empty($column['raw']))
                                        {!! data_get($row, $column['key'], '-') !!}
                                    @else
                                        {{ data_get($row, $column['key'], '-') }}
                                    @endif
                                </td>
                            @endforeach
                        </tr>
                    @empty
                        <tr>
                            <td colspan="{{ max(count($columns), 1) }}" class="text-center py-4">
                                {{ translate($emptyText ?? 'No data found') }}
                            </td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
            <div class="card-footer border-0">
                {!! $records->links() !!}
            </div>
        </div>
    </div>
@endsection
