<h5 class="mb-3"><i class="fas fa-envelope me-2"></i>{{ __('store.clientarea_domains_email_forwarding_title') }}</h5>
<p class="text-muted mb-4">{{ __('store.clientarea_domains_email_forwarding_description') }}</p>


<div class="card mb-4">
    <div class="card-header">
        <h6 class="mb-0"><i class="fas fa-plus me-2"></i>{{ __('store.clientarea_domains_email_forwarding_add') }}</h6>
    </div>
    <div class="card-body">
        <form action="{{ route('store.auth.domains.manage.email-forwarding.add', $domain->id) }}" method="POST">
            @csrf
            <div class="row g-3 align-items-end">
                <div class="col-md-4">
                    <label class="form-label">{{ __('store.clientarea_domains_email_forwarding_source') }} <span class="text-danger">*</span></label>
                    <div class="input-group">
                        <input type="text" name="source" class="form-control" placeholder="info" required>
                        @error('source') <div class="invalid-feedback">{{ $message }}</div> @enderror
                        <span class="input-group-text">@{{ $domain->domain }}</span>
                    </div>
                </div>
                <div class="col-md-1 text-center pt-4">
                    <i class="fas fa-arrow-right text-muted"></i>
                </div>
                <div class="col-md-5">
                    <label class="form-label">{{ __('store.clientarea_domains_email_forwarding_destination') }} <span class="text-danger">*</span></label>
                    <input type="email" name="destination" class="form-control" placeholder="user@example.com" required>
                    @error('destination') <div class="invalid-feedback">{{ $message }}</div> @enderror
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-plus me-1"></i>{{ __('store.common_add') }}
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="card">
    <div class="card-header">
        <h6 class="mb-0"><i class="fas fa-list me-2"></i>{{ __('store.clientarea_domains_email_forwarding_rules') }}</h6>
    </div>
    <div class="card-body p-0">
        @if(!empty($data) && is_array($data) && count($data) > 0)
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>{{ __('store.clientarea_domains_email_forwarding_source') }}</th>
                            <th></th>
                            <th>{{ __('store.clientarea_domains_email_forwarding_destination') }}</th>
                            <th class="text-end">{{ __('store.common_actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($data as $forwarder)
                            <tr>
                                <td>
                                    <code>{{ $forwarder['source'] ?? '' }}@{{ $domain->domain }}</code>
                                </td>
                                <td><i class="fas fa-arrow-right text-muted"></i></td>
                                <td>{{ $forwarder['destination'] ?? '' }}</td>
                                <td class="text-end">
                                    <form action="{{ route('store.auth.domains.manage.email-forwarding.delete', $domain->id) }}" method="POST" class="d-inline"
                                          onsubmit="return confirm('{{ __('store.common_confirm_delete') }}')">
                                        @csrf
                                        @method('DELETE')
                                        <input type="hidden" name="source" value="{{ $forwarder['source'] ?? '' }}">
                                        <button type="submit" class="btn btn-outline-danger btn-sm">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @else
            <div class="text-center py-4 text-muted">
                <i class="fas fa-inbox fa-3x mb-3 d-block"></i>
                {{ __('store.clientarea_domains_email_forwarding_empty') }}
            </div>
        @endif
    </div>
</div>
