﻿@extends('layouts.app')

@section('title', 'تعديل كشف الراتب')

@section('content')
<div class="container m-auto p-4 sm:p-6 lg:p-8 py-8">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-bold text-gray-900">تعديل كشف الراتب: {{ $payroll->payroll_number }}</h1>
        
        <div class="flex space-y-2 space-y-reverse">
            <a href="{{ route('payrolls.show', $payroll) }}" class="bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 p-4 rounded">
                <i class="fas fa-arrow-right ml-1"></i> العودة إلى التفاصيل
            </a>
        </div>
    </div>

    @if($errors->any())
    <div class="bg-red-100 border border-red-400 text-red-700 p-4 py-3 rounded relative mb-4" role="alert">
        <ul class="list-disc list-inside">
            @foreach($errors->all() as $error)
            <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
    @endif

    <div class="bg-white shadow-md rounded-lg overflow-hidden p-6">
        <form action="{{ route('payrolls.update', $payroll) }}" method="POST">
            @csrf
            @method('PUT')
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">الشهر/السنة</label>
                    <p class="py-2 p-3 bg-gray-100 rounded-md text-gray-700">{{ $payroll->month }}/{{ $payroll->year }}</p>
                    <p class="mt-1 text-s text-gray-500">لا يمكن تغيير الشهر والسنة</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">تاريخ البداية</label>
                    <p class="py-2 p-3 bg-gray-100 rounded-md text-gray-700">{{ $payroll->start_date->format('Y-m-d') }}</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">تاريخ النهاية</label>
                    <p class="py-2 p-3 bg-gray-100 rounded-md text-gray-700">{{ $payroll->end_date->format('Y-m-d') }}</p>
                </div>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                <div>
                    <label for="payment_date" class="block text-sm font-medium text-gray-700 mb-1">تاريخ الدفع</label>
                    <input type="date" id="payment_date" name="payment_date" value="{{ old('payment_date', $payroll->payment_date->format('Y-m-d')) }}" class="mt-1 block w-full py-2 p-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                </div>
                
                <div>
                    <label for="status" class="block text-sm font-medium text-gray-700 mb-1">الحالة</label>
                    <p class="py-2 p-3 bg-gray-100 rounded-md text-gray-700">
                        @if($payroll->status == 'draft')
                            مسودة
                        @elseif($payroll->status == 'approved')
                            معتمد
                        @elseif($payroll->status == 'paid')
                            مدفوع
                        @elseif($payroll->status == 'cancelled')
                            ملغي
                        @endif
                    </p>
                </div>
            </div>
            
            <div class="mb-6">
                <label for="notes" class="block text-sm font-medium text-gray-700 mb-1">ملاحظات</label>
                <textarea id="notes" name="notes" rows="3" class="mt-1 block w-full py-2 p-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">{{ old('notes', $payroll->notes) }}</textarea>
            </div>
            
            <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-eclamation-triangle text-yellow-400"></i>
                    </div>
                    <div class="mr-3">
                        <p class="text-sm text-yellow-700">
                            لتعديل بنود كشف الرواتب الفردية، يرجى الانتقال إلى صفحة تفاصيل كشف الراتب.
                        </p>
                    </div>
                </div>
            </div>
            
            <div class="flex justify-end">
                <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 p-4 rounded">
                    <i class="fas fa-save ml-1"></i> حفظ التغييرات
                </button>
            </div>
        </form>
    </div>
</div>
@endsection