@extends('admin.admin_master')

@section('admin')
<div class="page-content">
    <div class="container-fluid">
        <div class="row mb-4">
            <div class="col-12">
                <div class="page-header-card">
                    <div class="page-header-content">
                        <div class="d-flex align-items-center">
                            <div class="page-icon me-3">
                                <div class="avatar-md">
                                    <div class="avatar-title bg-primary-subtle text-primary rounded-circle">
                                        <i class="ri-bar-chart-2-line font-size-24"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="flex-grow-1">
                                <h4 class="page-title mb-1">Reports Dashboard</h4>
                                <p class="page-subtitle text-muted mb-0">Overview and analytics for workflows, tasks, users, and more</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row g-4">
            <div class="col-md-6">
                <div class="card shadow">
                    <div class="card-body">
                        <h5 class="card-title">Workflow Summary</h5>
                        <p class="card-text">View statistics on workflows created, completed, and in progress.</p>
                        <a href="{{ route('reports.workflow-report') }}" target="_blank" class="btn btn-primary btn-sm text-white">View Workflow Report</a>
                        <div id="workflow-report-table" class="mt-4 d-none">
                            <h6>All Workflows</h6>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>Name</th>
                                            <th>Status</th>
                                            <th>Created By</th>
                                            <th>Created At</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse($workflows as $workflow)
                                            <tr>
                                                <td>{{ $workflow->name }}</td>
                                                <td>{{ ucfirst($workflow->status) }}</td>
                                                <td>{{ $workflow->createdBy->first_name ?? '-' }} {{ $workflow->createdBy->last_name ?? '' }}</td>
                                                <td>{{ $workflow->created_at->format('Y-m-d H:i') }}</td>
                                            </tr>
                                        @empty
                                            <tr><td colspan="4" class="text-center">No workflows found</td></tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card shadow">
                    <div class="card-body">
                        <h5 class="card-title">Task Status</h5>
                        <p class="card-text">See pending, completed, and overdue tasks by user or workflow.</p>
                        <a href="{{ route('reports.task-report') }}" target="_blank" class="btn btn-info btn-sm text-white">View Task Report</a>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card shadow">
                    <div class="card-body">
                        <h5 class="card-title">User Activity</h5>
                        <p class="card-text">Track user logins, actions, and activity logs.</p>
 <a href="{{ route('reports.user-report') }}" target="_blank" class="btn btn-success btn-sm text-white" >View User Report</a>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card shadow">
                    <div class="card-body">
                        <h5 class="card-title">Folder & File Stats</h5>
                        <p class="card-text">Analyze folder/file creation, modification, and access.</p>

                        <a href="{{ route('reports.folder-file-stats') }}" target="_blank" class="btn btn-warning btn-sm text-dark" >View Folder Report</a>
                        <div id="folder-report-table" class="mt-4 d-none">
                            <h6>All Folders</h6>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>Folder ID</th>
                                            <th>Name</th>
                                            <th>Path</th>
                                            <th>Parent ID</th>
                                            <th>Created By</th>
                                            <th>Created At</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse($folders as $folder)
                                            <tr>
                                                <td>{{ $folder->id }}</td>
                                                <td>{{ $folder->name }}</td>
                                                <td>{{ $folder->path }}</td>
                                                <td>{{ $folder->parent_id ?? '-' }}</td>
                                                <td>{{ $folder->created_by ?? '-' }}</td>
                                                <td>{{ $folder->created_at->format('Y-m-d H:i') }}</td>
                                            </tr>
                                        @empty
                                            <tr><td colspan="6" class="text-center">No folders found</td></tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                       
                    </div>
                </div>
            </div>
            
          
        </div>
    </div>
</div>
@endsection
