@php
    $b = $banner ?? null;
    $val = fn($k, $d = '') => old($k, $b[$k] ?? $d);
    $dtVal = function ($k) use ($b) {
        $raw = old($k, $b[$k] ?? null);
        if (! $raw) return '';
        try { return \Illuminate\Support\Carbon::parse($raw)->format('Y-m-d\TH:i'); }
        catch (\Throwable $e) { return $raw; }
    };
@endphp

<div class="row">
    <div class="col-md-8">
        <div class="mb-3">
            <label class="form-label">{{ __('admin/support-banners.field_title') }} <span class="text-danger">*</span></label>
            <input type="text" class="form-control @error('title') is-invalid @enderror" name="title" value="{{ $val('title') }}" maxlength="150" required>
            @error('title') <div class="invalid-feedback">{{ $message }}</div> @enderror
        </div>
    </div>
    <div class="col-md-4">
        <div class="mb-3">
            <label class="form-label">{{ __('admin/support-banners.field_style') }} <span class="text-danger">*</span></label>
            <select class="form-select @error('style') is-invalid @enderror" name="style" required>
                @foreach(['info','warning','danger'] as $s)
                    <option value="{{ $s }}" @selected($val('style','info') === $s)>{{ __('admin/support-banners.style_' . $s) }}</option>
                @endforeach
            </select>
            @error('style') <div class="invalid-feedback">{{ $message }}</div> @enderror
        </div>
    </div>
</div>

<div class="mb-3">
    <label class="form-label">{{ __('admin/support-banners.field_message') }} <span class="text-danger">*</span></label>
    <textarea class="form-control @error('message') is-invalid @enderror" name="message" rows="3" maxlength="1000" required>{{ $val('message') }}</textarea>
    @error('message') <div class="invalid-feedback">{{ $message }}</div> @enderror
</div>

<div class="row">
    <div class="col-md-4">
        <div class="mb-3">
            <label class="form-label">{{ __('admin/support-banners.field_scope') }}</label>
            <select class="form-select @error('department_id') is-invalid @enderror" name="department_id">
                <option value="">{{ __('admin/support-banners.scope_general') }}</option>
                @foreach($departments as $dept)
                    <option value="{{ $dept->id }}" @selected((string) $val('department_id') === (string) $dept->id)>{{ $dept->name }}</option>
                @endforeach
            </select>
            @error('department_id') <div class="invalid-feedback">{{ $message }}</div> @enderror
            <div class="form-text small">{{ __('admin/support-banners.field_scope_help') }}</div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="mb-3">
            <label class="form-label">{{ __('admin/support-banners.field_start') }} <span class="text-danger">*</span></label>
            <input type="datetime-local" class="form-control @error('start_time') is-invalid @enderror" name="start_time" value="{{ $dtVal('start_time') }}" required>
            @error('start_time') <div class="invalid-feedback">{{ $message }}</div> @enderror
        </div>
    </div>
    <div class="col-md-4">
        <div class="mb-3">
            <label class="form-label">{{ __('admin/support-banners.field_end') }} <span class="text-danger">*</span></label>
            <input type="datetime-local" class="form-control @error('end_time') is-invalid @enderror" name="end_time" value="{{ $dtVal('end_time') }}" required>
            @error('end_time') <div class="invalid-feedback">{{ $message }}</div> @enderror
        </div>
    </div>
</div>
