<?php
session_start();
require 'config/db.php';
if (!isset($_SESSION['admin_id'])) {
    header("Location: login.php");
    exit;
}

if(!isset($_GET['id'], $_GET['table'])) die('Missing parameters');

$id = intval($_GET['id']);
$table = $_GET['table'];

$valid_tables = ['sales_employees','design_employees','development_employees','marketing_employees'];
if(!in_array($table, $valid_tables)) die('Invalid table');

// Delete login logs first
$pdo->prepare("DELETE FROM {$table}_login_logs WHERE employee_id=?")->execute([$id]);

// Delete employee
$pdo->prepare("DELETE FROM $table WHERE id=?")->execute([$id]);

header("Location: employees.php");
exit;
