{% extends "base.html" %}
{% from "components/client_select.html" import client_select %}

{% block title %}{{ _('Create Project from Template') }} - {{ app_name }}{% endblock %}

{% block content %}
<div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-6">
    <div>
        <h1 class="text-2xl font-bold">{{ _('Create Project from Template') }}</h1>
        <p class="text-text-muted-light dark:text-text-muted-dark">{{ _('Using template:') }} <strong>{{ template.name }}</strong></p>
    </div>
    <a href="{{ url_for('project_templates.view_template', template_id=template.id) }}" class="bg-gray-200 dark:bg-gray-700 px-4 py-2 rounded-lg mt-4 md:mt-0">{{ _('Back to Template') }}</a>
</div>

<div class="bg-card-light dark:bg-card-dark p-6 rounded-xl border border-border-light dark:border-border-dark shadow-sm">
    <form method="POST" action="{{ url_for('project_templates.create_project_from_template', template_id=template.id) }}" novalidate>
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
            <div>
                <label for="client_id" class="form-label">{{ _('Client') }} *</label>
                {{ client_select('client_id', clients, required=True, only_one_client=only_one_client|default(false), single_client=single_client) }}
            </div>
            
            <div>
                <label for="name" class="form-label">{{ _('Project Name') }}</label>
                <input type="text" id="name" name="name" class="form-input" placeholder="{{ template.name }}">
                <p class="text-xs text-text-muted-light dark:text-text-muted-dark mt-1">{{ _('Leave empty to use template name') }}</p>
            </div>
        </div>
        
        <div class="border-t border-border-light dark:border-border-dark pt-4 mb-6">
            <h3 class="text-lg font-semibold mb-4">{{ _('Override Settings (Optional)') }}</h3>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <label for="hourly_rate" class="form-label">{{ _('Hourly Rate') }}</label>
                    <input type="number" step="0.01" id="hourly_rate" name="hourly_rate" class="form-input" placeholder="{{ template.config.get('hourly_rate', '') }}">
                </div>
                <div>
                    <label for="code" class="form-label">{{ _('Project Code') }}</label>
                    <input type="text" id="code" name="code" class="form-input" maxlength="20" placeholder="{{ template.config.get('code', '') }}">
                </div>
            </div>
        </div>
        
        {% if template.tasks %}
        <div class="border-t border-border-light dark:border-border-dark pt-4 mb-6">
            <h3 class="text-lg font-semibold mb-4">{{ _('Template Tasks') }}</h3>
            <p class="text-sm text-text-muted-light dark:text-text-muted-dark mb-4">{{ _('The following tasks will be created:') }}</p>
            <div class="space-y-2">
                {% for task in template.tasks %}
                <div class="border border-border-light dark:border-border-dark rounded-lg p-3 bg-gray-50 dark:bg-gray-800">
                    <div class="flex justify-between items-center">
                        <span>{{ task.get('name', 'Untitled Task') }}</span>
                        {% if task.get('estimated_hours') %}
                        <span class="text-xs text-text-muted-light dark:text-text-muted-dark">{{ task.get('estimated_hours') }}h</span>
                        {% endif %}
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
        {% endif %}
        
        <div class="flex flex-col-reverse sm:flex-row justify-end gap-4">
            <a href="{{ url_for('project_templates.view_template', template_id=template.id) }}" class="px-4 py-2 border border-border-light dark:border-border-dark rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 text-center">{{ _('Cancel') }}</a>
            <button type="submit" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary/90 transition-colors">{{ _('Create Project') }}</button>
        </div>
    </form>
</div>
{% endblock %}

