<div>
    @isset($jsPath)
        <script>{!! file_get_contents($jsPath) !!}</script>
    @endisset
    @isset($cssPath)
        <style>{!! file_get_contents($cssPath) !!}</style>
    @endisset

    <div
            x-data="LivewireUIModal()"
            x-on:close.stop="setShowPropertyTo(false)"
            x-on:keydown.escape.window="show && closeModalOnEscape()"
            x-show="show"
            class="fixed inset-0 z-[70] overflow-y-auto"
            style="display: none;"
    >
        {{-- Backdrop --}}
        <div
                x-show="show"
                x-on:click="closeModalOnClickAway()"
                x-transition:enter="ease-out duration-300"
                x-transition:enter-start="opacity-0"
                x-transition:enter-end="opacity-100"
                x-transition:leave="ease-in duration-200"
                x-transition:leave-start="opacity-100"
                x-transition:leave-end="opacity-0"
                class="fixed inset-0 bg-black/60 transition-opacity"
        ></div>

        {{-- Centered panel with a fixed, contextual max width (max-w-lg is
             compiled statically; the package's dynamic modalWidth class would be
             purged by Tailwind and collapse the modal to full width). --}}
        <div class="flex min-h-full items-center justify-center p-4 sm:p-6">
            <div
                    x-show="show && showActiveComponent"
                    x-transition:enter="ease-out duration-300"
                    x-transition:enter-start="opacity-0 translate-y-4 sm:scale-95"
                    x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100"
                    x-transition:leave="ease-in duration-200"
                    x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
                    x-transition:leave-end="opacity-0 translate-y-4 sm:scale-95"
                    {{-- R24: never taller than the screen.

                         The panel used to grow with its content, so a form modal
                         ran off the bottom of the window and its own save button
                         with it — reachable only by scrolling the page behind the
                         backdrop. Capped here, once, for every modal: the panel
                         is a column, and whatever inside it is marked as the body
                         does the scrolling (see x-ui.modal).

                         100dvh, not 100vh: on a phone the browser's own chrome is
                         part of vh, which is exactly the case where the last
                         centimetre matters. --}}
                    class="relative flex max-h-[calc(100dvh-2rem)] w-full max-w-lg transform flex-col overflow-hidden rounded-xl bg-surface text-left shadow-xl transition-all sm:max-h-[calc(100dvh-3rem)]"
                    id="modal-container"
                    x-trap.noscroll.inert="show && showActiveComponent"
                    aria-modal="true"
            >
                @forelse($components as $id => $component)
                    {{-- min-h-0 and the column: without them the flex child
                         refuses to shrink below its content, and capping the
                         panel achieves nothing. --}}
                    <div x-show.immediate="activeComponent == '{{ $id }}'" x-ref="{{ $id }}" wire:key="{{ $id }}"
                         class="flex min-h-0 flex-1 flex-col">
                        @livewire($component['name'], $component['arguments'], key($id))
                    </div>
                @empty
                @endforelse
            </div>
        </div>
    </div>
</div>
