<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SDG Flow Builder</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
</head>
<body>
    <div class="container-fluid mt-4">
        <h1 class="mb-4">SDG Flow Builder</h1>
        
        <div class="row">
            <div class="col-md-3">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title mb-0">Available Blocks</h5>
                    </div>
                    <div class="card-body block-list">
                        {% for block_id, block_info in block_types.items() %}
                        <div class="block" draggable="true" data-block-type="{{ block_id }}">
                            <div class="d-flex justify-content-between align-items-center">
                                <span>{{ block_info.name }}</span>
                                <i class="fas fa-grip-vertical"></i>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
            
            <div class="col-md-9">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="card-title mb-0">Flow Canvas</h5>
                        <div>
                            <button class="btn btn-outline-primary me-2" onclick="saveFlow()">
                                <i class="fas fa-save"></i> Save Flow
                            </button>
                            <button class="btn btn-outline-info me-2" onclick="loadYAML()">
                                <i class="fas fa-file-code"></i> Load YAML
                            </button>
                            <button class="btn btn-primary" onclick="generateYAML()">
                                <i class="fas fa-code"></i> Generate YAML
                            </button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div id="flow-canvas" class="block-container">
                            <!-- Blocks will be dropped here -->
                        </div>
                    </div>
                </div>
                
                <div class="card mt-4">
                    <div class="card-header">
                        <h5 class="card-title mb-0">Generated YAML</h5>
                    </div>
                    <div class="card-body">
                        <pre id="yaml-output" class="bg-light p-3" style="display: none;"></pre>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Block Configuration Modal -->
    <div class="modal fade" id="blockConfigModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Configure Block</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="blockConfigForm">
                        <!-- Dynamic form fields will be inserted here -->
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="saveBlockConfig()">Save</button>
                </div>
            </div>
        </div>
    </div>

    <!-- YAML Input Modal -->
    <div class="modal fade" id="yamlInputModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Load YAML Flow</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="yamlInput" class="form-label">Paste your YAML flow here:</label>
                        <textarea id="yamlInput" class="form-control" rows="10"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary" onclick="parseYAML()">Load</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Pass block types to JavaScript
        window.blockTypes = {{ block_types|tojson|safe }};
    </script>
    <script src="{{ url_for('static', filename='js/app.js') }}"></script>
</body>
</html> 