"""Export symbol count results to XLSX."""
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment


def export_to_excel(results: list[dict], filename: str, out_path: str) -> None:
    """results = [{id, description, count, confidence, notes}, ...]"""
    wb = Workbook()
    ws = wb.active
    ws.title = "Symboly"

    headers = ["Symbol", "Popis", "Počet", "Spolehlivost", "Poznámka"]
    ws.append(headers)
    for cell in ws[1]:
        cell.font = Font(bold=True, color="FFFFFF")
        cell.fill = PatternFill("solid", fgColor="2563EB")
        cell.alignment = Alignment(horizontal="center")

    for r in results:
        ws.append([
            r.get("id", ""),
            r.get("description", ""),
            r.get("count", 0),
            r.get("confidence", ""),
            r.get("notes", ""),
        ])

    # Auto-width
    widths = [16, 60, 10, 14, 40]
    for i, w in enumerate(widths, 1):
        ws.column_dimensions[chr(64 + i)].width = w

    # Total row
    total = sum(int(r.get("count", 0) or 0) for r in results)
    ws.append([])
    last = ws.max_row + 1
    ws.append(["", f"Celkem ({filename})", total, "", ""])
    ws[f"B{last+1}"].font = Font(bold=True)
    ws[f"C{last+1}"].font = Font(bold=True)

    wb.save(out_path)
