{% extends "base.html" %}

{% block title %}{{ t('recipes.title') }}{% endblock %}
{% block page_id %}recipes{% endblock %}

{% block page_css %}
<link rel="stylesheet" href="/loras_static/css/components/card.css?v={{ version }}">
<link rel="stylesheet" href="/loras_static/css/components/recipe-modal.css?v={{ version }}">
<link rel="stylesheet" href="/loras_static/css/components/import-modal.css?v={{ version }}">
<link rel="stylesheet" href="/loras_static/css/components/batch-import-modal.css?v={{ version }}">
{% endblock %}

{% block additional_components %}
{% include 'components/import_modal.html' %}
{% include 'components/batch_import_modal.html' %}
{% include 'components/recipe_modal.html' %}

<div id="recipeContextMenu" class="context-menu" style="display: none;">
    <!-- <div class="context-menu-item" data-action="details"><i class="fas fa-info-circle"></i> View Details</div> -->
    <!-- Metadata -->
    <div class="context-menu-item" data-action="repair">
        <i class="fas fa-tools"></i> {{ t('loras.contextMenu.repairMetadata') }} (Deprecated)
    </div>
    <div class="context-menu-item" data-action="rematch">
        <i class="fas fa-link"></i> {{ t('loras.contextMenu.rematchMetadata') }}
    </div>
    <div class="context-menu-item" data-action="reimport">
        <i class="fas fa-undo-alt"></i> {{ t('loras.contextMenu.reimportMetadata') }}
    </div>
    <div class="context-menu-separator menu-section-break"></div>
    <!-- Workflow / Share -->
    <div class="context-menu-item" data-action="share"><i class="fas fa-share-alt"></i> {{
        t('loras.contextMenu.shareRecipe') }}</div>
    <div class="context-menu-item" data-action="copy"><i class="fas fa-copy"></i> {{
        t('loras.contextMenu.copyRecipeSyntax') }}</div>
    <div class="context-menu-item" data-action="sendappend"><i class="fas fa-paper-plane"></i> {{
        t('loras.contextMenu.sendToWorkflowAppend') }}</div>
    <div class="context-menu-item" data-action="sendreplace"><i class="fas fa-exchange-alt"></i> {{
        t('loras.contextMenu.sendToWorkflowReplace') }}</div>
    <div class="context-menu-separator menu-section-break"></div>
    <!-- Recipe-specific -->
    <div class="context-menu-item" data-action="viewloras"><i class="fas fa-layer-group"></i> {{
        t('loras.contextMenu.viewAllLoras') }}</div>
    <div class="context-menu-item download-missing-item" data-action="download-missing"><i class="fas fa-download"></i>
        {{ t('loras.contextMenu.downloadMissingLoras') }}</div>
    <div class="context-menu-separator menu-section-break"></div>
    <!-- Attributes -->
    <div class="context-menu-item" data-action="set-nsfw">
        <i class="fas fa-exclamation-triangle"></i> {{ t('loras.contextMenu.setContentRating') }}
    </div>
    <div class="context-menu-separator menu-section-break"></div>
    <!-- Organization -->
    <div class="context-menu-item" data-action="move"><i class="fas fa-folder-open"></i> {{
        t('loras.contextMenu.moveToFolder') }}</div>
    <div class="context-menu-separator"></div>
    <!-- Destructive -->
    <div class="context-menu-item delete-item" data-action="delete"><i class="fas fa-trash"></i> {{
        t('loras.contextMenu.deleteRecipe') }}</div>
</div>
{% endblock %}

{% block init_title %}{{ t('initialization.recipes.title') }}{% endblock %}
{% block init_message %}{{ t('initialization.recipes.message') }}{% endblock %}
{% block init_check_url %}/api/recipes?page=1&page_size=1{% endblock %}

{% block content %}
<!-- Recipe controls -->
{% include 'components/controls.html' %}
<!-- Breadcrumb Navigation -->
{% include 'components/breadcrumb.html' %}

<!-- Duplicates banner (hidden by default) -->
<div id="duplicatesBanner" class="duplicates-banner" style="display: none;">
    <div class="banner-content">
        <i class="fas fa-exclamation-triangle"></i>
        <span id="duplicatesCount">{{ t('recipes.duplicates.found', count=0) }}</span>
        <span id="duplicatesBasis" class="duplicates-basis"></span>
        <i class="fas fa-question-circle help-icon" id="duplicatesHelp" aria-label="{{ t('common.actions.help') }}"></i>
        <div class="banner-actions">
            <div class="setting-contro" id="promptMatchControl">
                <span>{{ t('recipes.duplicates.includePromptLabel') }}:</span>
                <label class="toggle-switch">
                    <input type="checkbox" id="promptMatchInput">
                    <span class="toggle-slider"></span>
                </label>
            </div>
            <button class="btn-select-latest" onclick="recipeManager.selectLatestDuplicates()">
                {{ t('recipes.duplicates.keepLatest') }}
            </button>
            <button class="btn-delete-selected disabled" onclick="recipeManager.deleteSelectedDuplicates()">
                {{ t('recipes.duplicates.deleteSelected') }} (<span id="duplicatesSelectedCount">0</span>)
            </button>
            <button class="btn-exit" onclick="recipeManager.exitDuplicateMode()">
                <i class="fas fa-times"></i>
            </button>
        </div>
    </div>
    <div class="help-tooltip" id="duplicatesHelpTooltip">
        <p id="duplicatesHelpText"></p>
    </div>
</div>

{% include 'components/folder_sidebar.html' %}

<!-- Recipe grid -->
<div class="card-grid" id="recipeGrid">
    <!-- Remove the server-side conditional rendering and placeholder -->
    <!-- Virtual scrolling will handle the display logic on the client side -->
</div>
{% endblock %}

{% block overlay %}
<div class="bulk-mode-overlay"></div>
{% endblock %}

{% block main_script %}
<script type="module" src="/loras_static/js/recipes.js?v={{ version }}"></script>
{% endblock %}