@extends('admin.layouts.master')
@section('title', __('edit_new_tv_show'))
@section('content')

    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="section-title">{{ __('edit_tv_show') }}</h3>
                <form action="{{ route('admin.tv.show.update', ['id' => $tv_show->id]) }}" method="post"
                    enctype="multipart/form-data" class="crud-form">
                    @csrf
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="default-tab-list default-tab-list-v2  bg-white redious-border p-20 p-sm-30">
                                <h3 class="section-title"> {{ __('tv_show_information') }} </h3>
                                <div class="mb-4">
                                    <label for="title" class="form-label"> {{ __('tv_show_title') }} <span
                                            class="text-danger">*</span> </label>
                                    <input type="text" class="form-control rounded-2" id="title" name="title"
                                        value="{{ $tv_show->title }}" placeholder="{{ __('tv_show_title') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('title') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="slug" class="form-label"> {{ __('tv_show_slug') }} <span
                                            class="text-danger">*</span> </label>
                                    <input type="text" class="form-control rounded-2" id="slug" name="slug"
                                        value="{{ $tv_show->slug }}" placeholder="{{ __('tv_show_slug') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('slug') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="tv_show_description" class="form-label d-flex justify-content-between">
                                        <span>{{ __('tv_show_description') }}</span>
                                            <small class="generate-button">
                                                <button data-url="{{ route('ai-helper') }}"
                                                    data-type="tv_series_description" data-title="" data-id="tv_show_description"
                                                    class="generate-content text-decoration-none text-danger">
                                                    <span><i class="las la-robot"></i></span>
                                                </button>
                                            </small>
                                        </label>
                                    <textarea name="description" id="tv_show_description" cols="30" rows="4" class="form-control rounded-2"
                                        placeholder="{{ __('tv_show_description') }}">{{ $tv_show->description }}</textarea>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('description') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="actor" class="form-label">{{ __('actors') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="actor[]"
                                        id="actor" multiple>
                                        @foreach ($stars as $actor)
                                            @php
                                                if ($actor->star_type != 'actor') {
                                                    continue;
                                                }
                                            @endphp
                                            <option value="{{ $actor->id }}"
                                                {{ isset($tv_show->stars) && in_array($actor->id, json_decode($tv_show->stars)) ? 'selected' : '' }}>
                                                {{ $actor->star_name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('actor') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="director" class="form-label">{{ __('director') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="director[]"
                                        id="director" multiple>
                                        @foreach ($stars as $director)
                                            @php
                                                if ($director->star_type != 'director') {
                                                    continue;
                                                }
                                            @endphp
                                            <option value="{{ $director->id }}"
                                                {{ isset($tv_show->director) && in_array($director->id, json_decode($tv_show->director)) ? 'selected' : '' }}>
                                                {{ $director->star_name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('director') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="writer" class="form-label">{{ __('writer') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="writer[]"
                                        id="writer" multiple>
                                        @foreach ($stars as $writer)
                                            @php
                                                if ($writer->star_type != 'writer') {
                                                    continue;
                                                }
                                            @endphp
                                            <option value="{{ $writer->id }}"
                                                {{ isset($tv_show->writer) && in_array($writer->id, json_decode($tv_show->writer)) ? 'selected' : '' }}>
                                                {{ $writer->star_name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('writer') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="imdb_rating" class="form-label"> {{ __('imdb_rating') }} </label>
                                    <input type="number" class="form-control rounded-2" id="imdb_rating" name="imdb_rating"
                                        value="{{ $tv_show->imdb_rating }}" placeholder="{{ __('00') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('imdb_rating') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="date" class="form-label"> {{ __('release_date') }} <span
                                            class="text-danger">*</span> </label>
                                    <input type="date" class="form-control rounded-2 datetimePicker" id="date"
                                        name="release_date" value="{{ $tv_show->release }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('release_date') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="country" class="form-label">{{ __('country') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="country[]"
                                        id="country" multiple>
                                        <option value=""> {{ __('select_tv_show_country') }} </option>
                                        @foreach ($countries as $country)
                                            <option value="{{ $country->id }}"
                                                {{ isset($tv_show->country) && in_array($country->id, json_decode($tv_show->country)) ? 'selected' : '' }}>
                                                {{ $country->name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('country') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="genre" class="form-label">{{ __('genre') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="genre[]"
                                        id="genre" multiple>
                                        <option value=""> {{ __('select_genre') }} </option>
                                        @foreach ($genres as $genre)
                                            <option value="{{ $genre->id }}"
                                                {{ isset($tv_show->genre) && in_array($genre->id, json_decode($tv_show->genre)) ? 'selected' : '' }}>
                                                {{ $genre->name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('genre') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="language" class="form-label">{{ __('language') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="language[]"
                                        id="language" multiple>
                                        <option value=""> {{ __('select_tv_show_language') }} </option>
                                        @foreach ($languages as $language)
                                            <option value="{{ $language->id }}"
                                                {{ isset($tv_show->language) && in_array($language->id, json_decode($tv_show->language)) ? 'selected' : '' }}>
                                                {{ $language->name }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('language') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="video_type" class="form-label">{{ __('video_type') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="video_type"
                                        id="video_type">
                                        <option value=""> {{ __('select_video_category') }} </option>
                                        @foreach ($categories as $category)
                                            <option value="{{ $category->id }}"
                                                {{ $category->id == $tv_show->video_type ? 'selected' : '' }}>
                                                {{ $category->video_type }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('video_type') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="runtime" class="form-label"> {{ __('runtime(in_minutes)') }} <span
                                            class="text-danger">*</span> </label>
                                    <input type="text" class="form-control rounded-2 timepicker" id="runtime"
                                        name="runtime" value="{{ $tv_show->runtime }}"
                                        placeholder="{{ __('minute_duration') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('runtime') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="video_quality" class="form-label">{{ __('video_quality') }} <span
                                            class="text-danger">*</span></label>
                                    <select class="form-select form-select-lg mb-3 with_search" name="video_quality"
                                        id="video_quality">
                                        <option value=""> {{ __('select_video_quality') }}</option>
                                        @foreach ($video_qualities as $quality)
                                            <option value="{{ $quality->id }}"
                                                {{ $quality->id == $tv_show->video_quality ? 'selected' : '' }}>
                                                {{ $quality->quality }} </option>
                                        @endforeach
                                    </select>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('video_quality') }}</p>
                                    </div>
                                </div>

                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="status" value="{{ $tv_show->status }}">
                                    <label class="form-label" for="status"> {{ __('status') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->status == 1 ? 'checked' : '' }} id="status"
                                            class="sandbox_mode">
                                        <label for="status"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="enable_download"
                                        value="{{ $tv_show->enable_download }}">
                                    <label class="form-label" for="enable_download"> {{ __('enable_download') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" {{ $tv_show->enable_download == 1 ? 'checked' : '' }}
                                            value="1" id="enable_download" class="sandbox_mode">
                                        <label for="enable_download"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_original" value="{{ $tv_show->is_original }}">
                                    <label class="form-label" for="is_original"> {{ __('original') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->is_original == 1 ? 'checked' : '' }} id="is_original"
                                            class="sandbox_mode">
                                        <label for="is_original"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_featured" value="{{ $tv_show->is_featured }}">
                                    <label class="form-label" for="is_featured"> {{ __('featured') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->is_featured == 1 ? 'checked' : '' }} id="is_featured"
                                            class="sandbox_mode">
                                        <label for="is_featured"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_blockbuster" value="{{ $tv_show->is_blockbuster }}">
                                    <label class="form-label" for="is_blockbuster"> {{ __('blockbuster') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->is_blockbuster == 1 ? 'checked' : '' }} id="is_blockbuster"
                                            class="sandbox_mode">
                                        <label for="is_blockbuster"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_recommended" value="{{ $tv_show->is_recommended }}">
                                    <label class="form-label" for="is_recommended"> {{ __('recommended') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->is_recommended == 1 ? 'checked' : '' }} id="is_recommended"
                                            class="sandbox_mode">
                                        <label for="is_recommended"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_real_life_story"
                                        value="{{ $tv_show->is_real_life_story }}">
                                    <label class="form-label" for="is_real_life_story"> {{ __('real_life_story') }}
                                    </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->is_real_life_story == 1 ? 'checked' : '' }}
                                            id="is_real_life_story" class="sandbox_mode">
                                        <label for="is_real_life_story"></label>
                                    </div>
                                </div>
                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="is_popular" value="{{ $tv_show->is_popular }}">
                                    <label class="form-label" for="is_popular"> {{ __('is_popular') }}
                                    </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1" id="is_popular"
                                            {{ $tv_show->is_popular == 1 ? 'checked' : '' }} class="sandbox_mode">
                                        <label for="is_popular"></label>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="trailer_youtube_source" class="form-label">
                                        {{ __('trailer_url(mp4_url_only)') }} </label>
                                    <input type="text" class="form-control rounded-2 timepicker"
                                        id="trailer_youtube_source" name="trailer_youtube_source"
                                        value="{{ $tv_show->trailler_youtube_source }}"
                                        placeholder="{{ __('mp4_url_only') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('trailer_youtube_source') }}</p>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="default-tab-list default-tab-list-v2  bg-white redious-border p-20 p-sm-30">
                                <h3 class="section-title"> {{ __('poster_and_thumbnail') }} </h3>
                                <div class="input_file_div d-flex align-items-center gap-3">
                                    <div class="mb-3 w-75">
                                        <label for="thumbUpload"
                                            class="form-label mb-1">{{ __('tv_show_thumbnail_(500x750)') }}</label>
                                        <label for="thumbUpload"
                                            class="file-upload-text">{{ __('select_file_from_device') }}</label>
                                        <input class="d-none file_picker" type="file" name="thumbnail"
                                            id="thumbUpload" accept=".jpg,.png">
                                        <div class="nk-block-des text-danger">
                                            <p class="error"></p>
                                        </div>
                                    </div>
                                    <div class="selected-files d-flex flex-wrap gap-20">
                                        <div class="selected-files-item">
                                            <img class="selected-img"
                                                src="{{ getFileLink('thumbnail', $tv_show->thumbnail, 'tv_shows', '500x750') }}"
                                                alt="thumbnail">
                                        </div>
                                    </div>
                                </div>
                                <div class="input_file_div d-flex align-items-center gap-3">
                                    <div class="mb-3 w-75">
                                        <label for="posterUpload"
                                            class="form-label mb-1">{{ __('tv_show_poster_(1920x1080)') }}</label>
                                        <label for="posterUpload"
                                            class="file-upload-text">{{ __('select_file_from_device') }}</label>
                                        <input class="d-none file_picker" type="file" name="poster"
                                            id="posterUpload" accept=".jpg,.png">
                                        <div class="nk-block-des text-danger">
                                            <p class="error"></p>
                                        </div>
                                    </div>
                                    <div class="selected-files d-flex flex-wrap gap-20">
                                        <div class="selected-files-item">
                                            <img class="selected-img"
                                                src="{{ getFileLink('poster', $tv_show->poster, 'tv_shows', '1920x1080') }}"
                                                alt="poster">
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="default-tab-list default-tab-list-v2 mt-3 bg-white redious-border p-20 p-sm-30">
                                <h3 class="section-title mb-3">{{ __('monetization_and_revenue') }}</h3>

                                {{-- Free Access --}}
                                <div class="d-flex gap-12 align-items-center justify-content-between mb-4">
                                    <input type="hidden" name="is_free" value="{{ $tv_show->is_free }}"
                                        id="is_free_status">
                                    <label class="form-label mb-0"
                                        for="is_free">{{ __('make_this_series_free_for_all_users') }}</label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1" name="is_free" id="is_free"
                                            {{ old('is_free', $tv_show->is_free) ? 'checked' : '' }}
                                            class="access-control">
                                        <label for="is_free"></label>
                                    </div>
                                </div>

                                {{-- Rental Access --}}
                                <div class="d-flex gap-12 align-items-center justify-content-between mb-4">
                                    <input type="hidden" name="is_rental" value="{{ $tv_show->is_rental }}"
                                        id="is_rental_status">
                                    <label class="form-label mb-0"
                                        for="is_rental">{{ __('allow_users_to_rent_this_series') }}</label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1" name="is_rental" id="is_rental"
                                            {{ old('is_rental', $tv_show->is_rental) ? 'checked' : '' }}
                                            class="access-control">
                                        <label for="is_rental"></label>
                                    </div>
                                </div>

                                {{-- Rental Fields --}}
                                <div id="rental-fields"
                                    class="{{ old('is_rental', $tv_show->is_rental) ? '' : 'd-none' }} d-flex align-items-center gap-3 flex-wrap">
                                    <div class="mb-3">
                                        <label for="rental_price" class="form-label">{{ __('Rental Price') }}</label>
                                        <input type="number" step="0.01" class="form-control" name="rental_price"
                                            id="rental_price" placeholder="{{ __('rental_price') }}"
                                            value="{{ old('rental_price', $tv_show->rental_price) }}">
                                    </div>
                                    <div class="mb-3">
                                        <label for="rental_duration"
                                            class="form-label">{{ __('Rental Duration (in hours)') }}</label>
                                        <input type="number" class="form-control" name="rental_duration"
                                            id="rental_duration" placeholder="{{ __('rental_duration') }}"
                                            value="{{ old('rental_duration', $tv_show->rental_duration) }}">
                                    </div>
                                    <div class="mb-3">
                                        <label for="rental_price" class="form-label">{{ __('Rental type') }}</label>
                                        <select class="form-select form-select-lg mb-3 with_search" name="rental_type"
                                            id="rental_type">
                                            <option value=""> {{ __('select_rental_type') }}</option>
                                            <option value="hours"
                                                {{ $tv_show->rental_type == 'hours' ? 'selected' : '' }}>
                                                {{ __('hours') }}</option>
                                            <option value="day"
                                                {{ $tv_show->rental_type == 'day' ? 'selected' : '' }}>
                                                {{ __('day') }}</option>
                                            <option value="month"
                                                {{ $tv_show->rental_type == 'month' ? 'selected' : '' }}>
                                                {{ __('month') }}</option>
                                            <option value="year"
                                                {{ $tv_show->rental_type == 'year' ? 'selected' : '' }}>
                                                {{ __('year') }}</option>
                                        </select>

                                        <div class="nk-block-des text-danger">
                                            <p class="error">{{ $errors->first('rental_type') }}</p>
                                        </div>
                                    </div>
                                </div>

                            </div>

                            <div class="default-tab-list default-tab-list-v2  bg-white redious-border p-20 p-sm-30 mt-3">
                                <h3 class="section-title"> {{ __('seo_and_marketing') }} </h3>
                                <div class="mb-4">
                                    <label for="seo_title" class="form-label"> {{ __('seo_title') }} </label>
                                    <input type="text" class="form-control rounded-2" id="seo_title" name="seo_title"
                                        value="{{ $tv_show->seo_title }}" placeholder="{{ __('seo_title') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('seo_title') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="meta_description" class="form-label d-flex justify-content-between">
                                        <span>{{ __('meta_description') }}</span>
                                        <small class="generate-button">
                                            <button data-url="{{ route('ai-helper') }}"
                                                data-type="tv_series_meta_description" data-title="" data-id="meta_description"
                                                class="generate-content text-decoration-none text-danger">
                                                <span><i class="las la-robot"></i></span>
                                            </button>
                                        </small>
                                    </label>
                                    <textarea name="meta_description" id="meta_description" cols="30" rows="3"
                                        class="form-control rounded-2" placeholder="{{ __('meta_description') }}">{{ $tv_show->meta_description }}</textarea>
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('meta_description') }}</p>
                                    </div>
                                </div>
                                <div class="mb-4">
                                    <label for="focus_keyword" class="form-label"> {{ __('focus_keyword') }} </label>
                                    <input type="text" class="form-control rounded-2" id="focus_keyword"
                                        name="focus_keyword" value="{{ $tv_show->focus_keyword }}"
                                        placeholder="{{ __('focus_focus_keyword') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('focus_keyword') }}</p>
                                    </div>
                                    <p class="text-muted">({{ __('use_comma_to_separate_focus_keyword') }})</p>
                                </div>
                                <div class="mb-4">
                                    <label for="tags" class="form-label"> {{ __('tags') }} </label>
                                    <input type="text" class="form-control rounded-2" id="tags" name="tags"
                                        value="{{ $tv_show->tags }}" placeholder="{{ __('tags') }}">
                                    <div class="nk-block-des text-danger">
                                        <p class="error">{{ $errors->first('tags') }}</p>
                                    </div>
                                    <p class="text-muted">({{ __('use_comma_to_separate_tags') }})</p>
                                </div>

                                <div
                                    class="d-flex gap-12 align-items-center justify-content-between sandbox_mode_div mb-4">
                                    <input type="hidden" name="email_notify" value="{{ $tv_show->email_notify }}">
                                    <label class="form-label" for="email_notify">
                                        {{ __('send_email_newslatter_to_subscriber') }} </label>
                                    <div class="setting-check">
                                        <input type="checkbox" value="1"
                                            {{ $tv_show->email_notify == 1 ? 'checked' : '' }} id="email_notify"
                                            class="sandbox_mode">
                                        <label for="email_notify"></label>
                                    </div>
                                </div>

                                <button type="submit" class="btn sg-btn-primary">{{ __('submit') }}</button>
                            </div>
                        </div>
                </form>
            </div>
        </div>
    </div>

@endsection
@push('js')
    <script>
        "use strict";
        flatpickr(".datetimePicker", {
            defaultDate: new Date(),
            enableTime: true,
            enableSeconds: true,
            dateFormat: "Y-m-d",
            time_24hr: true,
        });

        $('#description').summernote({
            height: 210,
        });
        $("#title").keyup(function() {
            var Text = $(this).val();
            Text = Text.toLowerCase();
            Text = Text.replace(/[^\w ]+/g, '');
            Text = Text.replace(/ +/g, '-');
            $("#slug").val(Text);
        });

        function toggleAccessFields() {
            const isFree = document.getElementById('is_free').checked;
            const isRental = document.getElementById('is_rental').checked;

            // Only one can be selected
            if (isFree) {
                document.getElementById('is_rental').checked = false;
                document.getElementById('is_rental_status').value = 0;
            } else {
                document.getElementById('is_free_status').value = 0;
            }
            if (isRental) {
                document.getElementById('is_free').checked = false;
                document.getElementById('is_free_status').value = 0;
            } else {
                document.getElementById('is_rental_status').value = 0;
            }

            // Show rental fields if rental is selected
            if (!isFree) {
                document.getElementById('rental-fields').classList.toggle('d-none', !isRental);
            }
        }

        document.querySelectorAll('.access-control').forEach(cb => {
            cb.addEventListener('change', toggleAccessFields);
        });

        // Initialize on page load
        document.addEventListener('DOMContentLoaded', toggleAccessFields);
    </script>
@endpush
