---
import * as fs from "node:fs";
import * as path from "node:path";

import { footerConfig, profileConfig } from "@/config";
import { url } from "@utils/url";


const currentYear = new Date().getFullYear();

// HTML 内容获取逻辑
let customFooterHtml = "";
if (footerConfig.enable) {
    // 优先使用 customHtml，如果为空则使用 FooterConfig.html 文件内容
    if (footerConfig.customHtml && footerConfig.customHtml.trim() !== "") {
        customFooterHtml = footerConfig.customHtml.trim();
    } else {
        // customHtml 为空时，读取 FooterConfig.html 文件内容
        try {
            const footerConfigPath = path.join(
                process.cwd(),
                "public",
                "FooterConfig.html",
            );
            customFooterHtml = fs.readFileSync(footerConfigPath, "utf-8");
            // 移除HTML注释
            customFooterHtml = customFooterHtml.replace(/<!--[\s\S]*?-->/g, "").trim();
        } catch (error) {
            console.warn("FooterConfig.html文件读取失败:", error.message);
        }
    }
}
---

<div class="transition border-t border-black/10 dark:border-white/15 my-10 border-dashed mx-32"></div>
<div class="transition border-dashed border-[oklch(85%_0.01_var(--hue))] dark:border-white/15 rounded-2xl mb-12 flex flex-col items-center justify-center px-6">
    <div class="transition text-50 text-sm text-center">
        {customFooterHtml && (
            <div class="mb-2" set:html={customFooterHtml}></div>
        )}
        &copy; <span id="copyright-year">{currentYear}</span> {profileConfig.name}. All Rights Reserved. /
        <a class="transition link text-(--primary) font-medium" href={url('rss/')} onclick={`event.preventDefault(); navigateToPage('${url('rss/')}')`}>RSS</a> /
        <a class="transition link text-(--primary) font-medium" href={url('atom/')} onclick={`event.preventDefault(); navigateToPage('${url('atom/')}')`}>Atom</a> /
        <a class="transition link text-(--primary) font-medium" target="_blank" href={url('sitemap-index.xml')}>Sitemap</a><br>
        Powered by
        <a class="transition link text-(--primary) font-medium" target="_blank" href="https://astro.build">Astro</a> &
        <a class="transition link text-(--primary) font-medium" target="_blank" href="https://github.com/Spr-Aachen/Twilight">Twilight</a>&nbsp; Version <a class="transition link text-(--primary) font-medium" target="_blank" href="https://github.com/Spr-Aachen/Twilight/releases">1.0</a><br>

    </div>
</div>