async function get_sp_tu_api(): Promise<ProductInfo[]> {
    return new Promise((resolve, reject) => {
        return resolve(listproduct_mau);
    })
}


async function show_info_product() {
    const lay_thongtin_sp: ProductInfo[] = await get_sp_tu_api();

    // code hien thi danh sach dang dien ra
    show_product_detail(lay_thongtin_sp);
}

function GetURLParameter(sParam: string, url: string) {
    var url_decode = decodeURIComponent(url);
    var sPageURL = url_decode;
    var sURLVariables = sPageURL.split('?');
    for (var i = 0; i < sURLVariables.length; i++) {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) {
            return sParameterName[1];
        }
    }
}


function show_product_detail(lay_thongtin_sp: ProductInfo[]) {
    const IdProduct: number = Number(GetURLParameter('id', window.location.href));


    lay_thongtin_sp
        .filter((product: ProductInfo) => product.productId == IdProduct)
        .forEach(function (product, keyIndex) {
            console.log(product)
        })

}

show_info_product()
