(function () {
    'use strict';

    const ME_API = `${ADMIN_BASE_URL}api/auth/me.php`;

    async function loadEmployeeName() {
        try {
            const res = await fetch(ME_API, {
                headers: { 'Accept': 'application/json' },
                credentials: 'include'
            });

            const json = await res.json();

            if (json.status !== 'success' || !json.data?.employee) {
                console.warn('Employee data not available');
                return;
            }

            const emp = json.data.employee;
            const fullName = `${emp.first_name} ${emp.last_name}`.trim();

            const el = document.getElementById('employeeName');
            if (el) {
                el.textContent = fullName || 'Employee';
            }

        } catch (err) {
            console.error('Failed to load employee profile', err);
        }
    }

    document.addEventListener('DOMContentLoaded', loadEmployeeName);

})();
