@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Create New Check', __('Create New Check')))

@section('content')
<div class="container-fluid p-4">
    <h1 class="mt-4">{{ \App\Helpers\TranslationHelper::transFromDatabase('Create New Check', __('Create New Check')) }}</h1>
    <ol class="breadcrumb mb-4">
        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ \App\Helpers\TranslationHelper::transFromDatabase('Dashboard', __('Dashboard')) }}</a></li>
        <li class="breadcrumb-item"><a href="{{ route('banking.checks.index') }}">{{ \App\Helpers\TranslationHelper::transFromDatabase('Checks', __('Checks')) }}</a></li>
        <li class="breadcrumb-item active">{{ \App\Helpers\TranslationHelper::transFromDatabase('Create New Check', __('Create New Check')) }}</li>
    </ol>

    <div class="card mb-4">
        <div class="card-header">
            <i class="fas fa-money-check me-1"></i>
            {{ \App\Helpers\TranslationHelper::transFromDatabase('Check Information', __('Check Information')) }}
        </div>
        <div class="card-body">
            <form action="{{ route('banking.checks.store') }}" method="POST" enctype="multipart/form-data">
                @csrf
                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="check_type" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Check Type', __('Check Type')) }} <span class="text-danger">*</span></label>
                            <select name="check_type" id="check_type" class="select2 form-select @error('check_type') is-invalid @enderror" required>
                                <option value="">{{ \App\Helpers\TranslationHelper::transFromDatabase('Select Check Type', __('Select Check Type')) }}</option>
                                <option value="incoming" {{ old('check_type') == 'incoming' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Incoming Check', __('Incoming Check')) }}</option>
                                <option value="outgoing" {{ old('check_type') == 'outgoing' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Outgoing Check', __('Outgoing Check')) }}</option>
                            </select>
                            @error('check_type')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="status" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Check Status', __('Check Status')) }} <span class="text-danger">*</span></label>
                            <select name="status" id="status" class="select2 form-select @error('status') is-invalid @enderror" required>
                                <option value="">{{ \App\Helpers\TranslationHelper::transFromDatabase('Select Status', __('Select Status')) }}</option>
                                <option value="pending" {{ old('status') == 'pending' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Pending', __('Pending')) }}</option>
                                <option value="deposited" {{ old('status') == 'deposited' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Deposited', __('Deposited')) }}</option>
                                <option value="cashed" {{ old('status') == 'cashed' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Cashed', __('Cashed')) }}</option>
                                <option value="returned" {{ old('status') == 'returned' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Returned', __('Returned')) }}</option>
                                <option value="cancelled" {{ old('status') == 'cancelled' ? 'selected' : '' }}>{{ \App\Helpers\TranslationHelper::transFromDatabase('Cancelled', __('Cancelled')) }}</option>
                            </select>
                            @error('status')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="bank_account_id" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Bank Account', __('Bank Account')) }} <span class="text-danger">*</span></label>
                            <select name="bank_account_id" id="bank_account_id" class="select2 form-select @error('bank_account_id') is-invalid @enderror" required>
                                <option value="">{{ \App\Helpers\TranslationHelper::transFromDatabase('Select Bank Account', __('Select Bank Account')) }}</option>
                                @foreach($bankAccounts as $account)
                                    <option value="{{ $account->id }}" {{ old('bank_account_id') == $account->id ? 'selected' : '' }}>
                                        {{ $account->bank->name }} - {{ $account->account_name }} - {{ $account->account_number }} ({{ $account->currency }})
                                    </option>
                                @endforeach
                            </select>
                            @error('bank_account_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="chart_of_account_id" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Counterpart Account', __('Counterpart Account')) }} <span class="text-danger">*</span></label>
                            <select name="chart_of_account_id" id="chart_of_account_id" class="select2 form-select @error('chart_of_account_id') is-invalid @enderror" required>
                                <option value="">{{ \App\Helpers\TranslationHelper::transFromDatabase('Select Counterpart Account', __('Select Counterpart Account')) }}</option>
                                @foreach($accounts as $account)
                                    <option value="{{ $account->id }}" {{ old('chart_of_account_id') == $account->id ? 'selected' : '' }}>
                                        {{ $account->account_number }} - {{ $account->name }} ({{ $account->account_type }})
                                    </option>
                                @endforeach
                            </select>
                            @error('chart_of_account_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="check_number" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Check Number', __('Check Number')) }} <span class="text-danger">*</span></label>
                            <input type="text" name="check_number" id="check_number" class="form-control @error('check_number') is-invalid @enderror" value="{{ old('check_number') }}" required>
                            @error('check_number')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="amount" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Amount', __('Amount')) }} <span class="text-danger">*</span></label>
                            <input type="number" step="0.01" name="amount" id="amount" class="form-control @error('amount') is-invalid @enderror" value="{{ old('amount') }}" required>
                            @error('amount')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="check_date" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Check Date', __('Check Date')) }} <span class="text-danger">*</span></label>
                            <input type="date" name="check_date" id="check_date" class="form-control @error('check_date') is-invalid @enderror" value="{{ old('check_date') }}" required>
                            @error('check_date')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="due_date" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Maturity Date', __('Maturity Date')) }} <span class="text-danger">*</span></label>
                            <input type="date" name="due_date" id="due_date" class="form-control @error('due_date') is-invalid @enderror" value="{{ old('due_date') }}" required>
                            @error('due_date')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="beneficiary_name" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Beneficiary Name', __('Beneficiary Name')) }} <span class="text-danger">*</span></label>
                            <input type="text" name="beneficiary_name" id="beneficiary_name" class="form-control @error('beneficiary_name') is-invalid @enderror" value="{{ old('beneficiary_name') }}" required>
                            @error('beneficiary_name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="issuer_name" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Issuer Name', __('Issuer Name')) }} <span class="text-danger">*</span></label>
                            <input type="text" name="issuer_name" id="issuer_name" class="form-control @error('issuer_name') is-invalid @enderror" value="{{ old('issuer_name') }}" required>
                            @error('issuer_name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="issuer_bank_name" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Issuer Bank Name', __('Issuer Bank Name')) }} <span class="text-danger">*</span></label>
                            <input type="text" name="issuer_bank_name" id="issuer_bank_name" class="form-control @error('issuer_bank_name') is-invalid @enderror" value="{{ old('issuer_bank_name') }}" required>
                            @error('issuer_bank_name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-12">
                        <div class="form-group mb-3">
                            <label for="description" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Description', __('Description')) }}</label>
                            <textarea name="description" id="description" class="form-control @error('description') is-invalid @enderror" rows="3">{{ old('description') }}</textarea>
                            @error('description')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row mb-3">
                    <div class="col-md-12">
                        <div class="form-group mb-3">
                            <label for="attachment" class="form-label">{{ \App\Helpers\TranslationHelper::transFromDatabase('Attachment', __('Attachment')) }}</label>
                            <input type="file" name="attachment" id="attachment" class="form-control @error('attachment') is-invalid @enderror">
                            <small class="form-text text-muted">{{ \App\Helpers\TranslationHelper::transFromDatabase('Allowed file types: PDF, JPG, JPEG, PNG. Maximum size: 2MB', __('Allowed file types: PDF, JPG, JPEG, PNG. Maximum size: 2MB')) }}</small>
                            @error('attachment')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12">
                        <button type="submit" class="btn btn-primary">{{ \App\Helpers\TranslationHelper::transFromDatabase('Save', __('Save')) }}</button>
                        <a href="{{ route('banking.checks.index') }}" class="btn btn-secondary">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cancel', __('Cancel')) }}</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection

@push('scripts')
<script>
    $(document).ready(function() {
        // تم إلغاء الإخفاء التلقائي بناءً على طلب المستخدم لتسهيل عملية الإدخال
    });
</script>
@endpush
