@extends('layouts.admin')

@section('title', 'Profit & Loss Statement')

@section('page-title', 'Profit & Loss Statement')

@section('header-actions')
    <a href="{{ route('admin.reports.profit-loss.export', request()->all()) }}" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors flex items-center gap-2">
        <span class="material-symbols-outlined text-lg">download</span>
        <span>Export CSV</span>
    </a>
@endsection

@section('content')
<div class="max-w-5xl mx-auto">
    <div class="bg-white rounded-xl shadow-sm border border-[#e5e7eb] p-6 mb-6">
        <h3 class="text-lg font-bold text-[#111418] text-gray-900 mb-4">Profit & Loss Statement</h3>
        <p class="text-sm text-[#617589]">Period: {{ \Carbon\Carbon::parse($report['date_from'])->format('M d, Y') }} to {{ \Carbon\Carbon::parse($report['date_to'])->format('M d, Y') }}</p>
    </div>

    <!-- Revenue Section -->
    <div class="bg-white rounded-xl shadow-sm border border-[#e5e7eb] p-6 mb-6">
        <h4 class="text-lg font-bold text-[#111418] text-gray-900 mb-4">Revenue</h4>
        <div class="space-y-2">
            @foreach($report['revenue']['details'] as $item)
                <div class="flex justify-between items-center py-2 border-b border-[#e5e7eb]">
                    <span class="text-sm text-[#617589]">{{ $item['account']->name }}</span>
                    <span class="text-sm font-medium text-[#111418] text-gray-900">{{ number_format($item['amount'], 2) }}</span>
                </div>
            @endforeach
            <div class="flex justify-between items-center pt-4 mt-2 border-t-2 border-[#e5e7eb]">
                <span class="text-base font-bold text-[#111418] text-gray-900">Total Revenue</span>
                <span class="text-lg font-bold text-green-600">{{ number_format($report['revenue']['total'], 2) }}</span>
            </div>
        </div>
    </div>

    <!-- Expenses Section -->
    <div class="bg-white rounded-xl shadow-sm border border-[#e5e7eb] p-6 mb-6">
        <h4 class="text-lg font-bold text-[#111418] text-gray-900 mb-4">Expenses</h4>
        <div class="space-y-2">
            @foreach($report['expenses']['details'] as $item)
                <div class="flex justify-between items-center py-2 border-b border-[#e5e7eb]">
                    <span class="text-sm text-[#617589]">{{ $item['account']->name }}</span>
                    <span class="text-sm font-medium text-[#111418] text-gray-900">{{ number_format($item['amount'], 2) }}</span>
                </div>
            @endforeach
            <div class="flex justify-between items-center pt-4 mt-2 border-t-2 border-[#e5e7eb]">
                <span class="text-base font-bold text-[#111418] text-gray-900">Total Expenses</span>
                <span class="text-lg font-bold text-red-600">{{ number_format($report['expenses']['total'], 2) }}</span>
            </div>
        </div>
    </div>

    <!-- Net Income -->
    <div class="bg-white rounded-xl shadow-sm border border-[#e5e7eb] p-6">
        <div class="flex justify-between items-center">
            <span class="text-xl font-bold text-[#111418] text-gray-900">Net Income</span>
            <span class="text-2xl font-bold {{ $report['net_income'] >= 0 ? 'text-green-600' : 'text-red-600' }}">
                {{ number_format($report['net_income'], 2) }}
            </span>
        </div>
    </div>
</div>
@endsection



