@extends('layouts.app')

@section('content')
<div class="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 py-8 px-4 md:px-8">
    <div class="max-w-7xl mx-auto">
        <!-- الرأس -->
        <div class="mb-8">
            <div class="flex items-center justify-between mb-6">
                <div>
                    <h1 class="text-3xl font-bold text-gray-900 mb-2">@transDb('Zakat Calculations')</h1>
                    <p class="text-gray-600">@transDb('Calculate zakat obligations and amounts')</p>
                </div>
                <div class="flex space-x-4 space-x-reverse">
                    <a href="{{ route('zakat-taxes.manage') }}" class="inline-flex items-center px-6 py-3 bg-white text-gray-700 font-semibold rounded-lg border border-gray-200 hover:bg-gray-50 transition-all duration-200 shadow-sm">
                        <i class="fas fa-arrow-right ml-2"></i>
                        <span>@transDb('Back')</span>
                    </a>
                    <button onclick="document.getElementById('new-calc-modal').classList.remove('hidden')" class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-semibold rounded-lg hover:from-blue-700 hover:to-blue-800 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105">
                        <i class="fas fa-plus ml-2"></i>
                        <span>@transDb('New Calculation')</span>
                    </button>
                </div>
            </div>
        </div>

        @if(session('success'))
        <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-6 rounded shadow-sm" role="alert">
            <p class="font-bold">@transDb('Success')</p>
            <p>{{ session('success') }}</p>
        </div>
        @endif

        <!-- قائمة الحسابات السابقة -->
        <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
            <div class="p-6 border-b border-gray-200 bg-gray-50">
                <h2 class="text-xl font-bold text-gray-900">@transDb('Previous Calculations')</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="w-full text-right">
                    <thead>
                        <tr class="bg-gray-100 text-gray-700 uppercase text-sm leading-normal">
                            <th class="py-3 px-6 text-right">@transDb('Date')</th>
                            <th class="py-3 px-6 text-right">@transDb('Fiscal Year')</th>
                            <th class="py-3 px-6 text-right">@transDb('Zakat Base')</th>
                            <th class="py-3 px-6 text-right">@transDb('Rate')</th>
                            <th class="py-3 px-6 text-right">@transDb('Zakat Amount')</th>
                            <th class="py-3 px-6 text-right">@transDb('Status')</th>
                        </tr>
                    </thead>
                    <tbody class="text-gray-600 text-sm font-light">
                        @forelse($calculations as $calc)
                        <tr class="border-b border-gray-200 hover:bg-gray-50">
                            <td class="py-3 px-6">{{ $calc->calculation_date->format('Y-m-d') }}</td>
                            <td class="py-3 px-6">{{ $calc->fiscalYear->name ?? 'N/A' }}</td>
                            <td class="py-3 px-6 font-semibold">{{ number_format($calc->zakat_base, 2) }} SAR</td>
                            <td class="py-3 px-6">{{ $calc->zakat_rate }}%</td>
                            <td class="py-3 px-6 font-bold text-blue-600">{{ number_format($calc->zakat_amount, 2) }} SAR</td>
                            <td class="py-3 px-6">
                                <span class="px-2 py-1 {{ $calc->status == 'paid' ? 'bg-green-100 text-green-700' : 'bg-amber-100 text-amber-700' }} rounded-full text-xs font-bold">
                                    {{ TranslationHelper::trans($calc->status) }}
                                </span>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="py-12 text-center text-gray-500 italic">
                                @transDb('No previous zakat calculations found.')
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="p-4">
                {{ $calculations->links() }}
            </div>
        </div>
    </div>
</div>

<!-- Modal للعملية الجديدة -->
<div id="new-calc-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
    <div class="bg-white rounded-xl shadow-2xl w-full max-w-lg p-8 transform transition-all">
        <div class="flex items-center justify-between mb-6">
            <h2 class="text-2xl font-bold text-gray-900">@transDb('New Zakat Calculation')</h2>
            <button onclick="document.getElementById('new-calc-modal').classList.add('hidden')" class="text-gray-500 hover:text-gray-700">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>
        
        <form action="{{ route('zakat-taxes.calculations.store') }}" method="POST">
            @csrf
            <div class="space-y-6">
                <div>
                    <label class="block text-sm font-semibold text-gray-700 mb-2">@transDb('Fiscal Year')</label>
                    <select name="fiscal_year_id" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:outline-none" required>
                        @if($activeFiscalYear)
                            <option value="{{ $activeFiscalYear->id }}">{{ $activeFiscalYear->name }}</option>
                        @else
                            <option value="">@transDb('No active fiscal year found')</option>
                        @endif
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-semibold text-gray-700 mb-2">@transDb('Calculation Date')</label>
                    <input type="date" name="calculation_date" value="{{ date('Y-m-d') }}" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:outline-none" required>
                </div>
                <div>
                    <label class="block text-sm font-semibold text-gray-700 mb-2">@transDb('Notes')</label>
                    <textarea name="notes" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:outline-none" placeholder="@transDb('Optional notes...')"></textarea>
                </div>
                
                <div class="bg-blue-50 p-4 rounded-lg">
                    <p class="text-sm text-blue-800">
                        <i class="fas fa-info-circle ml-2"></i>
                        @transDb('Zakat will be automatically calculated based on the active fiscal year balances.')
                    </p>
                </div>

                <div class="flex space-x-4 space-x-reverse pt-4">
                    <button type="submit" class="flex-1 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-bold py-3 rounded-lg hover:shadow-lg transition-all">
                        @transDb('Calculate Now')
                    </button>
                    <button type="button" onclick="document.getElementById('new-calc-modal').classList.add('hidden')" class="flex-1 bg-gray-100 text-gray-700 font-bold py-3 rounded-lg hover:bg-gray-200 transition-all">
                        @transDb('Cancel')
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
