@extends('layouts.app')

@section('title', 'ব্যয় সম্পাদনা - আমবাগান যুব কল্যাণ সমিতি')

@section('breadcrumbs')
<nav aria-label="breadcrumb">
    <ol class="breadcrumb bg-light">
        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">ড্যাশবোর্ড</a></li>
        <li class="breadcrumb-item"><a href="{{ route('expenses.index') }}">ব্যয় ব্যবস্থাপনা</a></li>
        <li class="breadcrumb-item active">ব্যয় সম্পাদনা</li>
    </ol>
</nav>
@endsection

@section('content')
<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-warning text-dark">
                    <h5 class="card-title mb-0">
                        <i class="fas fa-edit me-2"></i>ব্যয় সম্পাদনা
                    </h5>
                </div>
                <div class="card-body">
                    <form action="{{ route('expenses.update', $expense) }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        @method('PUT')
                        
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="title" class="form-label">শিরোনাম *</label>
                                <input type="text" class="form-control @error('title') is-invalid @enderror" 
                                    id="title" name="title" value="{{ old('title', $expense->title) }}" required>
                                @error('title')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="category_id" class="form-label">ক্যাটাগরি *</label>
                                <select class="form-control @error('category_id') is-invalid @enderror" 
                                    id="category_id" name="category_id" required>
                                    <option value="">ক্যাটাগরি নির্বাচন করুন</option>
                                    @foreach($categories as $category)
                                    <option value="{{ $category->id }}" {{ (old('category_id', $expense->category_id) == $category->id) ? 'selected' : '' }}>
                                        {{ $category->name_in_bangla }}
                                    </option>
                                    @endforeach
                                </select>
                                @error('category_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="amount" class="form-label">পরিমাণ (টাকা) *</label>
                                <input type="number" step="0.01" class="form-control @error('amount') is-invalid @enderror" 
                                    id="amount" name="amount" value="{{ old('amount', $expense->amount) }}" required min="0">
                                @error('amount')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="date" class="form-label">তারিখ *</label>
                                <input type="date" class="form-control @error('date') is-invalid @enderror" 
                                    id="date" name="date" value="{{ old('date', $expense->date) }}" required>
                                @error('date')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="payment_method" class="form-label">পেমেন্ট পদ্ধতি *</label>
                                <select class="form-control @error('payment_method') is-invalid @enderror" 
                                    id="payment_method" name="payment_method" required>
                                    <option value="">পদ্ধতি নির্বাচন করুন</option>
                                    <option value="cash" {{ (old('payment_method', $expense->payment_method) == 'cash') ? 'selected' : '' }}>নগদ</option>
                                    <option value="bank" {{ (old('payment_method', $expense->payment_method) == 'bank') ? 'selected' : '' }}>ব্যাংক</option>
                                    <option value="check" {{ (old('payment_method', $expense->payment_method) == 'check') ? 'selected' : '' }}>চেক</option>
                                    <option value="mobile_banking" {{ (old('payment_method', $expense->payment_method) == 'mobile_banking') ? 'selected' : '' }}>মোবাইল ব্যাংকিং</option>
                                </select>
                                @error('payment_method')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="reference_no" class="form-label">রেফারেন্স নম্বর</label>
                                <input type="text" class="form-control @error('reference_no') is-invalid @enderror" 
                                    id="reference_no" name="reference_no" value="{{ old('reference_no', $expense->reference_no) }}">
                                @error('reference_no')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-6 mb-3">
                                <label for="status" class="form-label">স্ট্যাটাস *</label>
                                <select class="form-control @error('status') is-invalid @enderror" 
                                    id="status" name="status" required>
                                    <option value="pending" {{ (old('status', $expense->status) == 'pending') ? 'selected' : '' }}>মুলতুবি</option>
                                    <option value="approved" {{ (old('status', $expense->status) == 'approved') ? 'selected' : '' }}>অনুমোদিত</option>
                                    <option value="rejected" {{ (old('status', $expense->status) == 'rejected') ? 'selected' : '' }}>প্রত্যাখ্যাত</option>
                                </select>
                                @error('status')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-12 mb-3">
                                <label for="description" class="form-label">বর্ণনা</label>
                                <textarea class="form-control @error('description') is-invalid @enderror" 
                                    id="description" name="description" rows="3">{{ old('description', $expense->description) }}</textarea>
                                @error('description')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-12 mb-3">
                                <label for="notes" class="form-label">নোট</label>
                                <textarea class="form-control @error('notes') is-invalid @enderror" 
                                    id="notes" name="notes" rows="2">{{ old('notes', $expense->notes) }}</textarea>
                                @error('notes')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="col-md-12 mb-3">
                                <label for="receipt_attachment" class="form-label">রিসিট সংযুক্তি</label>
                                @if($expense->receipt_attachment)
                                <div class="mb-2">
                                    <span class="badge bg-info">বর্তমান ফাইল সংযুক্ত আছে</span>
                                    <a href="{{ asset('storage/' . $expense->receipt_attachment) }}" target="_blank" class="ms-2">
                                        <i class="fas fa-eye"></i> দেখুন
                                    </a>
                                </div>
                                @endif
                                <input type="file" class="form-control @error('receipt_attachment') is-invalid @enderror" 
                                    id="receipt_attachment" name="receipt_attachment" accept=".jpg,.jpeg,.png,.pdf">
                                <small class="text-muted">সর্বোচ্চ ফাইল সাইজ: 2MB, অনুমোদিত ফরম্যাট: JPG, PNG, PDF</small>
                                @error('receipt_attachment')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>
                        
                        <div class="d-flex justify-content-between mt-4">
                            <a href="{{ route('expenses.index') }}" class="btn btn-secondary">
                                <i class="fas fa-arrow-left me-2"></i>ফিরে যান
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save me-2"></i>আপডেট করুন
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection