package com.example.components;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Shared ApexCharts styling for the Dialect design system
 * (https://www.figma.com/design/6DRThj0vmRgfjMIdsmkaIy).
 */
public final class DialectTheme {

    /** Categorical palette, primary orange first. */
    public static final List<String> COLORS = List.of(
            "#E86C00", // primary orange
            "#4C9BE8", // blue
            "#2FB7A6", // teal
            "#F6B93B", // gold
            "#8E7CD6", // purple
            "#E5544B", // red
            "#3F51B5"  // indigo
    );

    private static final String FONT_FAMILY =
            "'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";

    private DialectTheme() {
    }

    /** Common option fragments merged into every chart before series/labels are added. */
    public static Map<String, Object> baseOptions(String chartType) {
        Map<String, Object> options = new LinkedHashMap<>();

        Map<String, Object> chart = new LinkedHashMap<>();
        chart.put("type", chartType);
        chart.put("height", "100%");
        chart.put("fontFamily", FONT_FAMILY);
        chart.put("toolbar", Map.of("show", false));
        options.put("chart", chart);

        options.put("colors", COLORS);

        // grid.borderColor, legend.labels.colors and tooltip.theme are theme-varying
        // (light vs. dark) and get overlaid client-side from the --dialect-* CSS
        // tokens — see applyThemeOverlay() in apex-chart.ts.
        options.put("grid", Map.of("strokeDashArray", 4));
        options.put("legend", Map.of("position", "bottom"));
        options.put("dataLabels", Map.of("enabled", false));

        if ("line".equals(chartType)) {
            options.put("stroke", Map.of("curve", "smooth", "width", 3));
        } else if ("bar".equals(chartType)) {
            options.put("stroke", Map.of("width", 0));
            options.put("plotOptions", Map.of(
                    "bar", Map.of(
                            "borderRadius", 6,
                            "borderRadiusApplication", "end",
                            "columnWidth", "55%"
                    )
            ));
        }

        return options;
    }
}
