<?php

namespace Modules\Workflows\Controllers;

use Gestoreasy\Core\Http\Request;
use Gestoreasy\Core\Http\Response;

class WorkflowsViewsController {
    public function index(Request $req): Response {
        $html = <<<HTML
<!DOCTYPE html>
<html>
<head>
    <title>Workflows</title>
    <meta charset="UTF-8">
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .workflow-list { display: grid; gap: 20px; }
        .workflow-card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
        .btn { padding: 8px 16px; background: #d32f2f; color: white; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; }
    </style>
</head>
<body>
    <h1>Workflows e Automações</h1>
    <a href="/workflows/create" class="btn">Criar Workflow</a>
    <div id="workflows" class="workflow-list"></div>
    
    <script>
        async function loadWorkflows() {
            const res = await fetch('/api/workflows');
            const {data} = await res.json();
            
            const div = document.getElementById('workflows');
            div.innerHTML = data.map(w => \`
                <div class="workflow-card">
                    <h3>\${w.nome}</h3>
                    <p>\${w.descricao || ''}</p>
                    <p>Status: \${w.status} | Execuções: \${w.execucoes_total}</p>
                    <a href="/workflows/\${w.id}" class="btn">Ver Detalhes</a>
                </div>
            \`).join('');
        }
        loadWorkflows();
    </script>
</body>
</html>
HTML;
        return new Response(200, [], $html);
    }

    public function create(Request $req): Response {
        return new Response(200, [], '<h1>Criar Workflow</h1><p>Interface de criação em desenvolvimento...</p>');
    }

    public function show(Request $req): Response {
        $id = $req->get('params')[0] ?? 0;
        return new Response(200, [], "<h1>Workflow #{$id}</h1><p>Detalhes em desenvolvimento...</p>");
    }

    public function edit(Request $req): Response {
        $id = $req->get('params')[0] ?? 0;
        return new Response(200, [], "<h1>Editar Workflow #{$id}</h1><p>Editor em desenvolvimento...</p>");
    }
}

