@auth
<div
    data-te-modal-init
    id="modalAddToPlaylist"
    tabindex="-1"
    aria-modal="true"
    role="dialog"
    class="fixed inset-0 z-[1055] hidden overflow-y-auto bg-black/60 backdrop-blur-sm"
>
    <div data-te-modal-dialog-ref class="flex min-h-screen items-center justify-center p-4">
        <div class="relative w-full max-w-2xl overflow-hidden rounded-2xl border border-neutral-200 bg-white shadow-2xl dark:border-neutral-700 dark:bg-neutral-900">
            <x-modal-header :title="__('Add to Playlist')" />

            <!--Modal body-->
            <div class="relative p-4">
                <!-- Add to existing playlist -->
                @php $playlists = Auth::user()->playlists; @endphp

                @if (count($playlists) > 0)
                <div class="p-4">
                    <label class="mb-2 leading-tight  text-gray-800 dark:text-gray-200 w-full" for="playlist">Select Playlist:</label>
                    <select name="playlist" id="playlist" class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-rose-800 focus:border-rose-900 dark:bg-neutral-900 dark:border-neutral-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-rose-800 dark:focus:border-rose-900">
                        @foreach($playlists as $playlist)
                        <option value="{{ $playlist->id }}">
                            {{ $playlist->name }} - 
                            {{ $playlist->is_private == 1 ? 'Private' : 'Public' }} - 
                            {{ $playlist->episodes->count() }} Episodes 
                            {{ $playlist->episodes->contains('episode_id', $episode->id) ? '- Episode Already Added' : '' }}
                        </option>
                        @endforeach
                    </select>
                    <x-input-error :messages="$errors->get('playlist')" class="mt-2" />
                </div>
                               
                <div class="flex flex-shrink-0 flex-wrap items-center justify-end rounded-b-md p-4 gap-3">
                    <a
                        data-te-modal-dismiss
                        id="playlist-cancel" 
                        class="cursor-pointer rounded-xl border border-neutral-300 px-5 py-2.5 text-sm font-medium text-neutral-700 transition hover:bg-neutral-100 dark:border-neutral-600 dark:text-neutral-200 dark:hover:bg-neutral-800">
                        Cancel
                    </a>
                    <a
                        id="playlist-add" 
                        class="cursor-pointer rounded-xl bg-rose-600 px-5 py-2.5 text-sm font-semibold text-white shadow-lg shadow-rose-600/20 transition hover:bg-rose-700">
                        Add
                    </a>
                </div>


                <div class="p-4">
                    <label class="mb-2 leading-tight  text-gray-800 dark:text-gray-200 w-full" for="name">Enter Playlist Name Here:</label>
                    <x-text-input id="name" class="block mt-1 w-full" type="text" name="name" required autofocus/>
                    <x-input-error :messages="$errors->get('name')" class="mt-2" />
                </div>

                <div class="p-4">
                    <label class="mb-2 leading-tight  text-gray-800 dark:text-gray-200 w-full" for="visiblity">Visiblity:</label>
                    <select name="visiblity" id="visiblity" class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-rose-800 focus:border-rose-900 dark:bg-neutral-900 dark:border-neutral-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-rose-800 dark:focus:border-rose-900">
                        <option value="public">Public</option>
                        <option value="private" selected>Private</option>
                    </select>
                    <x-input-error :messages="$errors->get('visiblity')" class="mt-2" />
                </div>
                
                <div class="flex flex-shrink-0 flex-wrap items-center justify-end rounded-b-md p-4">
                    <a 
                        id="playlist-create-and-add" 
                        class="cursor-pointer rounded-xl bg-rose-600 px-5 py-2.5 text-sm font-semibold text-white shadow-lg shadow-rose-600/20 transition hover:bg-rose-700">
                        Create and Add Episode
                    </a>
                </div>

                @else

                <!-- Create Playlist -->
                <a class="font-semibold text-gray-800 dark:text-gray-200 leading-tight">
                    No Playlists found. Please create a Playlist first!
                </a>

                <div class="p-4">
                    <label class="mb-2 leading-tight  text-gray-800 dark:text-gray-200 w-full" for="name">Enter Playlist Name Here:</label>
                    <x-text-input id="name" class="block mt-1 w-full" type="text" name="name" required autofocus/>
                    <x-input-error :messages="$errors->get('name')" class="mt-2" />
                </div>

                <div class="mt-5 p-4">
                    <label class="mb-2 leading-tight  text-gray-800 dark:text-gray-200 w-full" for="visiblity">Visiblity:</label>
                    <select name="visiblity" id="visiblity" class="block w-full text-sm text-gray-900 border border-gray-300 rounded-lg bg-gray-50 focus:ring-rose-800 focus:border-rose-900 dark:bg-neutral-900 dark:border-neutral-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-rose-800 dark:focus:border-rose-900">
                        <option value="public">Public</option>
                        <option value="private" selected>Private</option>
                    </select>
                    <x-input-error :messages="$errors->get('visiblity')" class="mt-2" />
                </div>
                
                <div class="flex flex-shrink-0 flex-wrap items-center justify-end rounded-b-md p-4">
                    <a id="playlist-cancel" class="inline-block cursor-pointer rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-100 focus:bg-primary-accent-100 focus:outline-none focus:ring-0 active:bg-primary-accent-200" data-te-modal-dismiss data-te-ripple-init data-te-ripple-color="light">
                        Cancel
                    </a>
                    <a id="playlist-create-and-add" class="ml-1 cursor-pointer inline-block rounded bg-rose-600 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white transition duration-150 ease-in-out hover:bg-rose-700 focus:bg-rose-600" data-te-ripple-init data-te-ripple-color="light">
                        Create and Add Episode
                    </a>
                </div>

                @endif

            </div>
        </div>
    </div>
</div>
@vite(['resources/js/modals-playlist.js'])
@endauth