<div {{ attributes }} 
     {% if isGeneratingImage or isGeneratingPrompt %}data-poll="checkStatus"{% endif %}
>
    <div class="space-y-4">
        <div>
            <label for="ai-prompt" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Bild-Prompt</label>
            <div class="mt-1 flex gap-2">
                <textarea
                    id="ai-prompt"
                    data-model="prompt"
                    rows="3"
                    class="block w-full rounded-md border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm"
                    placeholder="Beschreiben Sie das Bild..."
                >{{ prompt }}</textarea>
                <button
                    type="button"
                    data-action="live#action"
                    data-live-action-param="generatePrompt"
                    class="inline-flex items-center px-3 py-2 border border-gray-300 dark:border-gray-700 shadow-sm text-sm font-medium rounded-md text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50"
                    {% if isGeneratingPrompt %}disabled{% endif %}
                >
                    {% if isGeneratingPrompt %}
                        <svg class="animate-spin h-5 w-5 text-gray-500 dark:text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
                    {% else %}
                        Prompt vorschlagen
                    {% endif %}
                </button>
            </div>
        </div>

        <div class="flex justify-end gap-2">
            <button
                type="button"
                data-action="live#action"
                data-live-action-param="generateImage"
                class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50"
                {% if prompt is empty or isGeneratingImage %}disabled{% endif %}
            >
                {% if isGeneratingImage %}
                    <svg class="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
                    Generiere Bild...
                {% else %}
                    Bild generieren
                {% endif %}
            </button>
        </div>

        {% if generatedImageUrl %}
            <div class="mt-4">
                <div class="aspect-square w-full max-w-sm mx-auto overflow-hidden rounded-lg border dark:border-gray-700">
                    <img src="data:image/png;base64,{{ generatedImageUrl }}" alt="Generated image" class="w-full h-full object-cover">
                </div>
                <div class="mt-4 flex justify-center gap-4">
                    <button
                        type="button"
                        data-action="live#action"
                        data-live-action-param="confirmImage"
                        class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
                    >
                        Dieses Bild verwenden
                    </button>
                <p>Oder Prompt anpassen und neu generieren</p>
                </div>
            </div>
        {% endif %}
    </div>
</div>
