@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">{{ \App\Helpers\TranslationHelper::transFromDatabase('Tax Declarations', __('Tax Declarations')) }}</h1>
                    <p class="text-gray-600">{{ \App\Helpers\TranslationHelper::transFromDatabase('Manage tax declarations and filings', __('Manage tax declarations and filings')) }}</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>{{ \App\Helpers\TranslationHelper::transFromDatabase('Back', __('Back')) }}</span>
                    </a>
                    <button onclick="document.getElementById('new-decl-modal').classList.remove('hidden')" class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-green-600 to-green-700 text-white font-semibold rounded-lg hover:from-green-700 hover:to-green-800 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105">
                        <i class="fas fa-plus ml-2"></i>
                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('New Declaration', __('New Declaration')) }}</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">{{ \App\Helpers\TranslationHelper::transFromDatabase('Success', __('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">{{ \App\Helpers\TranslationHelper::transFromDatabase('Previous Declarations', __('Previous Declarations')) }}</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">{{ \App\Helpers\TranslationHelper::transFromDatabase('Period', __('Period')) }}</th>
                            <th class="py-3 px-6 text-right">{{ \App\Helpers\TranslationHelper::transFromDatabase('Sales VAT', __('Sales VAT')) }}</th>
                            <th class="py-3 px-6 text-right">{{ \App\Helpers\TranslationHelper::transFromDatabase('Purchase VAT', __('Purchase VAT')) }}</th>
                            <th class="py-3 px-6 text-right">{{ \App\Helpers\TranslationHelper::transFromDatabase('Net VAT Due', __('Net VAT Due')) }}</th>
                            <th class="py-3 px-6 text-right">{{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}</th>
                            <th class="py-3 px-6 text-right">{{ \App\Helpers\TranslationHelper::transFromDatabase('Submission Date', __('Submission Date')) }}</th>
                        </tr>
                    </thead>
                    <tbody class="text-gray-600 text-sm font-light">
                        @forelse($declarations as $decl)
                        <tr class="border-b border-gray-200 hover:bg-gray-50">
                            <td class="py-3 px-6">
                                <span class="font-medium text-gray-900">{{ $decl->year }} - {{ $decl->period_type == 'monthly' ? \App\Helpers\TranslationHelper::transFromDatabase('Month', __('Month')) : \App\Helpers\TranslationHelper::transFromDatabase('Quarter', __('Quarter')) }} {{ $decl->period_number }}</span>
                            </td>
                            <td class="py-3 px-6 text-green-600 font-semibold">{{ number_format($decl->vat_on_sales, 2) }} SAR</td>
                            <td class="py-3 px-6 text-red-600 font-semibold">{{ number_format($decl->vat_on_purchases, 2) }} SAR</td>
                            <td class="py-3 px-6 font-bold text-blue-600">{{ number_format($decl->net_vat_due, 2) }} SAR</td>
                            <td class="py-3 px-6">
                                <span class="px-2 py-1 {{ $decl->status == 'submitted' ? 'bg-blue-100 text-blue-700' : 'bg-gray-100 text-gray-700' }} rounded-full text-xs font-bold">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase($decl->status, __($decl->status)) }}
                                </span>
                            </td>
                            <td class="py-3 px-6">{{ $decl->submission_date ? $decl->submission_date->format('Y-m-d') : '-' }}</td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="py-12 text-center text-gray-500 italic">
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('No tax declarations found.', __('No tax declarations found.')) }}
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            <div class="p-4">
                {{ $declarations->links() }}
            </div>
        </div>
    </div>
</div>

<!-- Modal للعملية الجديدة -->
<div id="new-decl-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">{{ \App\Helpers\TranslationHelper::transFromDatabase('Generate Tax Declaration', __('Generate Tax Declaration')) }}</h2>
            <button onclick="document.getElementById('new-decl-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.declarations.store') }}" method="POST">
            @csrf
            <div class="space-y-6">
                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Period Type', __('Period Type')) }}</label>
                        <select name="period_type" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:outline-none" required>
                            <option value="monthly">{{ \App\Helpers\TranslationHelper::transFromDatabase('Monthly', __('Monthly')) }}</option>
                            <option value="quarterly">{{ \App\Helpers\TranslationHelper::transFromDatabase('Quarterly', __('Quarterly')) }}</option>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Year', __('Year')) }}</label>
                        <input type="number" name="year" value="{{ date('Y') }}" 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>
                
                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Period Number', __('Period Number')) }}</label>
                        <input type="number" name="period_number" min="1" max="12" 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>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold text-gray-700 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Start Date', __('Start Date')) }}</label>
                        <input type="date" name="start_date" 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">{{ \App\Helpers\TranslationHelper::transFromDatabase('End Date', __('End Date')) }}</label>
                        <input type="date" name="end_date" 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>

                <div class="bg-green-50 p-4 rounded-lg">
                    <p class="text-sm text-green-800">
                        <i class="fas fa-info-circle ml-2"></i>
                        {{ \App\Helpers\TranslationHelper::transFromDatabase('VAT summary will be automatically generated for the selected date range.', __('VAT summary will be automatically generated for the selected date range.')) }}
                    </p>
                </div>

                <div class="flex space-x-4 space-x-reverse pt-4">
                    <button type="submit" class="flex-1 bg-gradient-to-r from-green-600 to-green-700 text-white font-bold py-3 rounded-lg hover:shadow-lg transition-all">
                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Generate Now', __('Generate Now')) }}
                    </button>
                    <button type="button" onclick="document.getElementById('new-decl-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">
                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Cancel', __('Cancel')) }}
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
