<?php
session_start();
require 'db.php'; // or wherever your DB connection is

$user_id = $_SESSION['user_id'];

$sql = "SELECT * FROM shifts WHERE user_id = ? AND status = 'open' ORDER BY start_time DESC LIMIT 1";
$stmt = $pdo->prepare($sql);
$stmt->execute([$user_id]);
$shift = $stmt->fetch(PDO::FETCH_ASSOC);

if ($shift) {
    echo json_encode(['status' => 'open', 'shift_id' => $shift['id']]);
} else {
    echo json_encode(['status' => 'none']);
}
