<tr{{ attributes }} is="download-list-row" class="dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-900" id="ad_download_{{ download.id }}" data-title="{{ download.title }}"
    download-id="{{ download.id }}"
    imdb-id="{{ download.imdbId }}"
    media-title="{{ download.title }}"
    url="{{ download.url }}"
    filename="{{ download.filename }}"
    status="{{ download.status }}"
    progress="{{ download.progress }}"
    media-type="{{ download.mediaType }}"
    episode-id="{{ download.episodeId }}"
    created-at="{{ download.createdAt|date('m/d/Y g:i a') }}"
    updated-at="{{ download.updatedAt|date('m/d/Y g:i a') }}"
    data-filename="{{ download.filename }}" data-media-type="{{ download.mediaType }}" data-status="{{ download.status }}" data-progress="{{ download.progress }}"
>
    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium truncate">
        {% if download.mediaType == "movies" %}
            {% set routeParams = {imdbId: download.imdbId, mediaType: download.mediaType} %}
            {% set route = path('app_search_result', routeParams) %}
        {% else %}
            {% set episodeIdDto = extract_from_episode_id(download.episodeId) %}
            {% set routeParams = {imdbId: download.imdbId, mediaType: download.mediaType, season: episodeIdDto.season, episode: episodeIdDto.episode} %}
            {% set route = path('app_search_result', routeParams) ~ "#" ~ episode_anchor(episodeIdDto.season, episodeIdDto.episode) %}
        {% endif %}
        <a href="{{ route }}"
           class="mr-1 hover:underline rounded-md max-w-[10ch] md:max-w-[unset] truncate">
            {{ download.title }}
        </a>

        {% if download.mediaType == "tvshows" and download.episodeId != null %}
            &mdash; <span class="ml-1">({{ download.episodeId }})</span>
        {% endif %}
    </td>

    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium max-w-[60ch] {{ isWidget == true ? "hidden" : "r-tablecell" }} truncate">
       {{ download.filename }}
    </td>

    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium truncate {{ isWidget == true ? "hidden" : "r-tablecell" }}">
        {{ download.mediaType }}
    </td>

    <td class="whitespace-nowrap gap-2 text-sm align-middle text-gray-800 dark:text-gray-50">
        {% if download.progress < 100 %}
            <div class="flex flex-row items-center justify-center">
                <div id="download_progress_{{ download.id }}" class="progress border-2 border-green-600 rounded-md text-center w-16 h-6 align-middle overflow-hidden">
                    <div class="background text-black text-center rounded-sm text-bold bg-green-300 h-5 relative z-10"
                         style="width: {{ download.progress }}%">
                    </div>
                    <div class="number text-black dark:text-white font-bold text-center z-40"
                    >{{ download.progress }}%</div>
                </div>
            </div>

        {% else %}
            <twig:StatusBadge color="green" status="Complete" />
        {% endif %}
    </td>
    <td id="hidden md:table-cell action_buttons_{{ download.id }}" class="pl-2 pr-4 py-4 flex flex-row items-center justify-end">
        {% if download.status == 'In Progress' and download.progress < 100 %}
            <button id="pause_{{ download.id }}" class="text-orange-500 hover:text-orange-600 mr-1 self-start" {{ stimulus_action('download_list', 'pauseDownload', 'click', {id: download.id}) }}>
                <twig:ux:icon name="icon-park-twotone:pause-one" width="16.75px" height="16.75px" class="rounded-full" />
            </button>
        {% elseif download.status == 'Paused' %}
            <button id="resume_{{ download.id }}" class="text-orange-500 hover:text-orange-600 mr-1 self-start" {{ stimulus_action('download_list', 'resumeDownload', 'click', {id: download.id}) }}>
                <twig:ux:icon name="icon-park-twotone:play" width="16.75px" height="16.75px" class="rounded-full" />
            </button>
        {% endif %}

        {% set delete_button = component('ux:icon', {name: 'ic:twotone-cancel', height: '17.75px', width: '17.75px', class: 'rounded-full align-middle text-red-600 hover:text-red-700' }) %}
        <twig:Modal heading="But wait!" button_text="{{ delete_button }}" submit_action="{{ stimulus_action('download_list', 'deleteDownload', 'click', {id: download.id}) }}" show_cancel show_submit>
            <p class="mb-1">Are you sure you want to delete the following record?</p>
            <p class="mb-1 ml-4 italic">{{ download.filename }}</p>
            <div class="">
                <input id="delete_file_{{ download.id }}" class="accent-orange-500" type="checkbox" value="false" name="delete_file" />
                <label for="delete_file_{{ download.id }}">Delete the file as well?</label>
            </div>
        </twig:Modal>
    </td>
</tr>