@use "sass:map";
@use "sass:list";

//
$md-config: (
    "effects": (
        "active-brightness": 0.95,
        "hover-brightness": 0.96
    ),
    "shape": (
        "border-radius": 8px,
        "box-shadow": 0 1px 3px rgba(0,0,0,0.12),
        "box-shadow-card": 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    ),
    "colors": (
        "accent": (#0969da, #2f81f7),
        "bg": (#ffffff, #0d1117),
        "bg-subtle": (#f6f8fa, #161b22),
        "bg-secondary": (#f6f8fa, #161b22),
        "border": (#d0d7de, #30363d),
        "border-subtle": (#eff1f3, #21262d),
        "link": (#0969da, #2f81f7),
        "text": (#1f2328, #e6edf3),
        "text-muted": (#656d76, #7d8590),
        "text-secondary": (#656d76, #7d8590),
        "scrollbar": (#d0d7de, #30363d),
        "scrollbar-hover": (#8c959f, #8b949e),
        "code-bg": (#eff1f3, #25292f), // Flat code background
        "code-text": (#1f2328, #e6edf3),
        "highlight": (#fff8c5, #bb800926),
        "table-border": (#d0d7de, #30363d),
        "table-stripe": (#f6f8fa, #161b22)
    ),
    "font": (
        "emoji": "\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"",
        "body": "\"Noto Serif\", \"Noto Serif Display\", \"PT Serif\", \"IBM Plex Serif\", \"Literata\", \"Merriweather\", \"Source Serif 4\", \"Georgia\", \"Cambria\", \"Palatino Linotype\", \"Times New Roman\", \"Times\", serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Noto Sans\", Helvetica, Arial, sans-serif, var(--font-family-emoji-flag-capable)",
        "mono": "\"ui-monospace\", \"SFMono-Regular\", \"SF Mono\", \"Menlo\", \"Consolas\", \"Liberation Mono\", \"monospace\"",
        "size-base": 16px
    ),
    "layout": (
        "line-height": 1.4,
        "justify-important": start,
        "justify-normal": start,
        "widths": (
            "card": 285px,
            "card-medium": 460px,
            "card-wide": 800px,
            "content": 980px
        )
    ),
    "page": (
        "margin": 2rem
    ),
    "heading": (
        "padding": 0,
        "padding-small": 0
    ),
    "blockquote": (
        "margin-inline": 0,
        "padding-inline": 1em
    ),
    "table": (
        "cell-padding": 6px 13px
    ),
    "media": (
        "img-max-width": 100%
    ),
    "scrollbar": (
        "size": 10px
    )
);

@function md-config($keys...) {
    $value: $md-config;

    @each $key in $keys {
        @if $value == null {
            @return null;
        }

        $value: map.get($value, $key);
    }

    @return $value;
}

@function md-color($name, $mode: null) {
    $palette: md-config("colors");
    $value: map.get($palette, $name);

    @if $mode == "light" {
        @return if(sass($value != null): list.nth($value, 1));
    }

    @if $mode == "dark" {
        @return if(sass($value != null): list.nth($value, 2));
    }

    @return $value;
}

@function md-light-dark($name) {
    $value: md-color($name);

    @if $value == null {
        @return null;
    }

    @return light-dark(#{list.nth($value, 1)}, #{list.nth($value, 2)});
}
