@php
    $current = (is_array($data ?? null) && count($data) > 0) ? $data[0] : null;
    $currentDestination = $current['destination'] ?? '';
    $currentType = $current['type'] ?? 'redirect_301';
@endphp

<h5 class="mb-1"><i class="fas fa-directions me-2"></i>{{ __('store.clientarea_domains_url_forwarding_title') }}</h5>
<p class="text-muted mb-3">{{ __('store.clientarea_domains_url_forwarding_description') }}</p>

{{-- DNS ≠ URL forwarding ayrımı net --}}
<div class="alert alert-info border-0 shadow-sm py-2 px-3">
    <i class="fas fa-info-circle me-2"></i>{{ __('store.clientarea_domains_url_forwarding_dns_note') }}
</div>

{{-- Aktif yönlendirme --}}
@if($currentDestination)
    <div class="card mb-4 border-success">
        <div class="card-body d-flex justify-content-between align-items-center flex-wrap gap-2">
            <div>
                <div class="small text-muted mb-1">{{ __('store.clientarea_domains_url_forwarding_current') }}</div>
                <code>{{ $domain->domain }}</code>
                <i class="fas fa-arrow-right text-muted mx-2"></i>
                <a href="{{ $currentDestination }}" target="_blank" rel="noopener">{{ $currentDestination }}</a>
                <span class="badge bg-secondary ms-2">{{ __('store.clientarea_domains_url_forwarding_type_' . $currentType) }}</span>
            </div>
            <form action="{{ route('store.auth.domains.manage.url-forwarding.delete', $domain->id) }}" method="POST" class="d-inline">
                @csrf
                @method('DELETE')
                <button type="submit" class="btn btn-outline-danger btn-sm">
                    <i class="fas fa-trash me-1"></i>{{ __('store.clientarea_domains_url_forwarding_remove') }}
                </button>
            </form>
        </div>
    </div>
@endif

{{-- Yönlendirmeyi ayarla/güncelle --}}
<div class="card">
    <div class="card-header">
        <h6 class="mb-0"><i class="fas fa-edit me-2"></i>{{ $currentDestination ? __('store.clientarea_domains_url_forwarding_update') : __('store.clientarea_domains_url_forwarding_set') }}</h6>
    </div>
    <div class="card-body">
        <form action="{{ route('store.auth.domains.manage.url-forwarding.save', $domain->id) }}" method="POST">
            @csrf
            <div class="mb-3">
                <label class="form-label">{{ __('store.clientarea_domains_url_forwarding_destination') }} <span class="text-danger">*</span></label>
                <input type="url" name="destination" class="form-control @error('destination') is-invalid @enderror"
                       placeholder="https://www.example.com" value="{{ old('destination', $currentDestination) }}" required>
                @error('destination') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>
            <div class="mb-3">
                <label class="form-label">{{ __('store.clientarea_domains_url_forwarding_type') }} <span class="text-danger">*</span></label>
                <select name="type" class="form-select @error('type') is-invalid @enderror">
                    @foreach(['redirect_301','redirect_302','frame'] as $t)
                        <option value="{{ $t }}" {{ old('type', $currentType) === $t ? 'selected' : '' }}>{{ __('store.clientarea_domains_url_forwarding_type_' . $t) }}</option>
                    @endforeach
                </select>
                @error('type') <div class="invalid-feedback">{{ $message }}</div> @enderror
                <div class="form-text small">{{ __('store.clientarea_domains_url_forwarding_type_help') }}</div>
            </div>
            <button type="submit" class="btn btn-primary">
                <i class="fas fa-save me-1"></i>{{ __('store.common_save') }}
            </button>
        </form>
    </div>
</div>
