{{-- PRC-66: ticket merge modal — autocomplete picker --}}
<div class="modal fade" id="ticketMergeModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <form method="POST" action="{{ route('admin.tickets.merge', $ticket) }}" class="modal-content">
            @csrf
            <div class="modal-header">
                <h5 class="modal-title">{{ __('admin/tickets.merge_modal_title', ['source' => $ticket->id]) }}</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="mb-3">
                    <label class="form-label">{{ __('admin/tickets.merge_target_picker') }}</label>
                    <input type="search" id="ticketMergeSearch" class="form-control" placeholder="#123 or subject keywords" autocomplete="off">
                    <div id="ticketMergeResults" class="list-group mt-2" style="max-height: 240px; overflow-y: auto;"></div>
                    <input type="hidden" name="target_ticket_id" id="ticketMergeTargetId" required>
                </div>
                <div id="ticketMergeSelected" class="alert alert-info d-none">
                    <strong>{{ __('admin/tickets.merge_into') }}:</strong> <span id="ticketMergeSelectedLabel"></span>
                </div>

                {{-- PRC-298 — opt-in client notification. Default state from
                     ticket_merge_notify_client_default setting. --}}
                @php $notifyDefault = (bool) \App\Models\Setting::getValue('ticket_merge_notify_client_default', false); @endphp
                <div class="form-check form-switch mb-2">
                    <input class="form-check-input" type="checkbox" id="ticketMergeNotifyClient" name="notify_client" value="1" @checked($notifyDefault)>
                    <label class="form-check-label" for="ticketMergeNotifyClient">
                        {{ __('admin/tickets.merge_notify_client') }}
                    </label>
                    <div class="form-text small">{{ __('admin/tickets.merge_notify_client_help') }}</div>
                </div>

                <div class="alert alert-warning small mb-0">
                    <i class="fas fa-exclamation-triangle me-1"></i>{{ __('admin/tickets.merge_confirm') }}
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ __('admin/common.cancel') }}</button>
                <button type="submit" class="btn btn-info" id="ticketMergeSubmit" disabled>
                    <i class="fas fa-compress-arrows-alt me-1"></i>{{ __('admin/tickets.merge') }}
                </button>
            </div>
        </form>
    </div>
</div>

@push('scripts')
<script>
window.ticketMergeConfig = {
    searchUrl: "{{ route('admin.tickets.merge.search') }}",
    sourceId: {{ $ticket->id }},
    csrfToken: "{{ csrf_token() }}",
};
</script>
@vite('resources/js/admin/tickets/merge.js')
@endpush
