<?php

if (!function_exists('is_period_active')) {
    /**
     * Memeriksa apakah suatu periode akademik aktif (is_active = 1)
     *
     * @param int|string $periodId ID periode akademik
     * @return bool
     */
    function is_period_active($periodId)
    {
        if (empty($periodId)) {
            return false;
        }

        $db = \Config\Database::connect();
        $period = $db->table('academic_periods')
            ->select('is_active')
            ->where('id', $periodId)
            ->get()
            ->getRowArray();

        return $period && (int)$period['is_active'] === 1;
    }
}
