#!/bin/bash
# ==============================================================================
# karch module: fonts
# Phase 2 (chroot) — Install Terminus + Japanese fonts, set console font
# ==============================================================================

run_fonts() {
    msg_info "Installing fonts..."

    # Install font packages
    if ! pacman -S --noconfirm terminus-font noto-fonts-cjk; then
        msg_error "Failed to install font packages!"
        return 1
    fi

    # --- Console font selection ----------------------------------------------
    local font_choice
    font_choice=$(dialog_menu "Console Font" \
        "Select a Terminus console font for the TTY:" \
        "ter-116b" "16px Bold" \
        "ter-116n" "16px Normal" \
        "ter-118b" "18px Bold" \
        "ter-118n" "18px Normal" \
        "ter-120b" "20px Bold" \
        "ter-120n" "20px Normal" \
        "ter-122b" "22px Bold" \
        "ter-122n" "22px Normal" \
        "ter-124b" "24px Bold" \
        "ter-124n" "24px Normal" \
        "ter-128b" "28px Bold" \
        "ter-128n" "28px Normal" \
        "ter-132b" "32px Bold" \
        "ter-132n" "32px Normal") || font_choice="ter-116b"

    # Write vconsole.conf
    echo "FONT=${font_choice}" > /etc/vconsole.conf

    msg_ok "Console font set to: $font_choice"

    dialog_msgbox "Fonts" \
        "Installed:\n  • terminus-font\n  • noto-fonts-cjk\n\nConsole font: ${font_choice}"

    return 0
}
