<?php

namespace App\Controllers;

class Visit extends BaseController
{
    protected $db;

    public function __construct()
    {
        $this->db = \Config\Database::connect();
 
        date_default_timezone_set('Asia/Jakarta');
    }

    public function index()
    {
        $id_pegawai = session()->get('id_pegawai');

        if (!$id_pegawai || !session()->get('logged_in')) {
            session()->destroy();
            return redirect()->to('/authpegawai');
        }
        session_write_close();

        // 1. Ambil data pegawai (Cukup 1x Query)
        $pegawai = $this->db->table('pegawai')
            ->select('pegawai.*, opd.id_jam_kerja as id_jam_opd, opd.nama_opd')
            ->join('opd', 'pegawai.id_opd = opd.id_opd', 'left')
            ->where('id_pegawai', $id_pegawai)
            ->get()->getRowArray();
        
        $tanggal_hari_ini = date('Y-m-d');
        //$nama_hari_indo = $this->get_nama_hari(date('D'));

        return view('visit/index', [
            'pegawai'         => $pegawai]);
        
        
    }

 
}
