import type { key_val } from '$lib/stores/ae_stores';
import { api } from '$lib/api/api';

import { db_core } from '$lib/ae_core/db_core';

const ae_promises: key_val = {};

// Updated 2026-02-20
export async function load_ae_obj_li__time_zone({
    api_cfg,
    // account_id,
    enabled = 'enabled',
    hidden = 'not_hidden',
    limit = 1800, // There are roughly 1780 as of 2026-02
    offset = 0,
    // order_by_li = {'priority': 'DESC', 'group': 'ASC', 'sort': 'DESC', 'name': 'ASC'},
    order_by_li = { priority: 'DESC', sort: 'DESC', name: 'ASC' } as const,
    params = {},
    only_priority = false,
    try_cache = true,
    log_lvl = 0
}: {
    api_cfg: any;
    // account_id: string,
    enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
    hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
    limit?: number;
    offset?: number;
    order_by_li?: key_val;
    params?: key_val;
    only_priority?: boolean;
    try_cache?: boolean;
    log_lvl?: number;
}) {
    if (log_lvl) {
        console.log(`*** load_ae_obj_li__time_zone() *** only_priority=${only_priority}`);
    }

    const params_json: key_val = {};

    // console.log('params_json:', params_json);

    ae_promises.load__time_zone_li = await api
        .get_ae_obj_li_for_lu({
            api_cfg: api_cfg,
            for_lu_type: 'time_zone',
            enabled: enabled,
            hidden: hidden,
            limit: limit,
            offset: offset,
            params: params,
            only_priority: only_priority,
            log_lvl: log_lvl
        })
        .then(function (time_zone_li_get_result) {
            if (time_zone_li_get_result) {
                // handle_db_save_ae_obj_li__time_zone({obj_type: 'time_zone', obj_li: time_zone_li_get_result});
                return time_zone_li_get_result;
            } else {
                return [];
            }
        })
        .catch(function (error: any) {
            console.log('No results returned or failed.', error);
        });

    console.log('ae_promises.load__time_zone_li:', ae_promises.load__time_zone_li);
    return ae_promises.load__time_zone_li;
}
