import type { Metadata } from "next";

export function metadataBySlug(result: any): Metadata {
    console.log('metadataBySlug: ', result)
    switch (result.type) {
        case "product_category":
            return {
                title: result.data.title,
                description: stripHtml(result.data.summary),
                openGraph: {
                    type: 'website',
                    images: [
                        result.data.big_image
                    ],
                },
            };

        case "product_detail":
            return {
                title: result.data.productName,
                description: stripHtml(result.data.productSummary),
                openGraph: {
                    type: 'website',
                    images: [
                        result.data.productImage.large.replace('/250_', '/')
                    ],
                },
            };

        case "article_home":
            return {
                title: "Tin tức",
                description: "Tin tức mới nhất",
                openGraph: {
                    type: 'article',
                    images: [
                        result.data.productImage.large.replace('/250_', '/')
                    ]
                }
            };

        case "article_category":
            return {
                title: result.data.title,
                description: stripHtml(result.data.summary),
                openGraph: {
                    type: 'article',
                    images: [
                        result.data.thumbnail
                    ]
                }
            };

        case "article_detail":
            return {
                title: result.data.title,
                description: result.data.excerpt,
                openGraph: {
                    type: 'article',
                }
            };

        default:
            return {
                title: "Local PC",
                openGraph: {
                    type: 'website',
                    images: [
                        '/images/logo.png'
                    ],
                }
            };
    }
}


function stripHtml(html: string) {
    return html.replace(/<[^>]*>/g, '');
}
