<?php
require_once 'db/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $nombre = trim($_POST['nombre']);

    if (!empty($nombre)) {
        $pdo = db();
        
        // Find the current max order value
        $stmt_max_order = $pdo->query('SELECT MAX(orden) AS max_orden FROM kanban_columns');
        $max_orden = $stmt_max_order->fetchColumn();
        $new_orden = $max_orden + 1;

        $stmt = $pdo->prepare('INSERT INTO kanban_columns (nombre, orden) VALUES (?, ?)');
        $stmt->execute([$nombre, $new_orden]);
    }
}

header('Location: kanban.php');
exit;
