{% extends "layout.html" %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-warning text-dark">
                    <i class="bi bi-arrow-left-right"></i> Transfer {{ category.rstrip('s').title() }}
                </div>
                <div class="card-body">
                    <div class="alert alert-info mb-4">
                        <i class="bi bi-info-circle"></i> 
                        <strong>Transferring:</strong> {{ resource.name }} ({{ resource.slug }})
                        <br>
                        <small>This will create a new entity in the target category. The original {{ category.rstrip('s') }} will remain unchanged.</small>
                    </div>
                    
                    <form action="{{ url_for('transfer_resource', category=category, slug=resource.slug) }}" method="post">
                        <div class="mb-3">
                            <label for="target_category" class="form-label">Target Category</label>
                            <select class="form-select" id="target_category" name="target_category" required>
                                <option value="">Select target category...</option>
                                {% for cat_id, cat_name in available_targets %}
                                <option value="{{ cat_id }}">{{ cat_name }}</option>
                                {% endfor %}
                            </select>
                            <div class="form-text">Select where you want to transfer this {{ category.rstrip('s') }} to.</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="new_name" class="form-label">New Name</label>
                            <input type="text" class="form-control" id="new_name" name="new_name" 
                                   value="{{ resource.name }}" required>
                            <div class="form-text">Name for the new entity in the target category.</div>
                        </div>
                        
                        <div class="mb-3">
                            <label for="new_id" class="form-label">New ID/Slug (optional)</label>
                            <input type="text" class="form-control" id="new_id" name="new_id" 
                                   value="{{ resource.slug }}">
                            <div class="form-text">Leave blank to auto-generate from the name.</div>
                        </div>
                        
                        <div class="mb-3 form-check form-switch">
                            <input class="form-check-input" type="checkbox" id="use_llm" name="use_llm" value="on" checked>
                            <label class="form-check-label" for="use_llm">
                                <strong>Use AI to regenerate JSON</strong>
                            </label>
                            <div class="form-text">
                                <div class="alert alert-light border mt-2">
                                    <i class="bi bi-lightbulb"></i> 
                                    <strong>AI Regeneration:</strong> The AI will analyze the {{ category.rstrip('s') }} profile and create a new JSON structure appropriate for the target category.
                                    <br>
                                    <strong>Without AI:</strong> A blank template will be created with basic information transferred.
                                </div>
                            </div>
                        </div>
                        
                        <div class="mb-3 form-check form-switch">
                            <input class="form-check-input" type="checkbox" id="transfer_lora" name="transfer_lora" value="on" checked>
                            <label class="form-check-label" for="transfer_lora">
                                <strong>Transfer LoRA file</strong>
                            </label>
                            <div class="form-text">
                                Copy the associated LoRA file to the default directory for the target category.
                            </div>
                        </div>
                        
                        <div class="mb-3 form-check form-switch">
                            <input class="form-check-input" type="checkbox" id="remove_original" name="remove_original" value="on" checked>
                            <label class="form-check-label" for="remove_original">
                                <strong>Remove original entry</strong>
                            </label>
                            <div class="form-text">
                                Delete the original {{ category.rstrip('s') }} entry after successful transfer.
                            </div>
                        </div>
                        
                        <div class="alert alert-warning">
                            <i class="bi bi-exclamation-triangle"></i>
                            <strong>Important:</strong> The original JSON structure cannot be reused directly. 
                            Each category has different required fields and structure. 
                            AI regeneration ensures the new entity is properly formatted for its category.
                        </div>
                        
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-warning btn-lg">
                                <i class="bi bi-arrow-left-right"></i> Transfer {{ category.rstrip('s').title() }}
                            </button>
                            <a href="{{ url_for(cancel_route, slug=resource.slug) }}" class="btn btn-outline-secondary">
                                Cancel
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
