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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $column_name = trim($_POST['column_name']);
    if (!empty($column_name)) {
        $pdo = db();
        // Find the current max order value
        $stmt_max = $pdo->query('SELECT MAX(orden) as max_orden FROM kanban_columns');
        $max_orden = $stmt_max->fetchColumn() ?? 0;
        
        $stmt = $pdo->prepare('INSERT INTO kanban_columns (nombre, orden) VALUES (:nombre, :orden)');
        $stmt->execute([':nombre' => $column_name, ':orden' => $max_orden + 1]);
    }
}

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