// Contains a utility function for changing font family

$fonts: (
    ".fl-font-arial": "Arial",
    ".fl-font-system-ui": "system-ui",
    ".fl-font-verdana": "Verdana",
    ".fl-font-times": "Georgia, Times, Times New Roman, serif",
    ".fl-font-comic-sans": "Comic Sans MS, sans-serif",
    ".fl-font-open-dyslexic": "OpenDyslexic, sans-serif",
    ".fl-font-atkinson-hyperlegible": "Atkinson Hyperlegible, sans-serif",
);

// Defines any @font-face definitions needed by the enactors
$fontFaces: (
    open-dyslexic: (
        font-directory: "../../../lib/opendyslexic/fonts/",
        font-family: "OpenDyslexic",
        definitions: (
            normal: (
                filename:"opendyslexic-latin-400-normal.woff2",
                font-weight: normal,
                font-style: normal
            ),
            bold: (
                filename:"opendyslexic-latin-700-normal.woff2",
                font-weight: 700,
                font-style: normal
            ),
            italic: (
                filename:"opendyslexic-latin-400-italic.woff2",
                font-weight: normal,
                font-style: italic
            ),
            bold-italic: (
                filename:"opendyslexic-latin-700-italic.woff2",
                font-weight: 700,
                font-style: italic
            )
        )
    ),
    atkinson-hyperlegible: (
        font-directory: "../../../lib/atkinson-hyperlegible/fonts/",
        font-family: "Atkinson Hyperlegible",
        definitions: (
            normal: (
                filename:"atkinson-hyperlegible-latin-400-normal.woff2",
                font-weight: normal,
                font-style: normal
            ),
            bold: (
                filename:"atkinson-hyperlegible-latin-700-normal.woff2",
                font-weight: 700,
                font-style: normal
            ),
            italic: (
                filename:"atkinson-hyperlegible-latin-400-italic.woff2",
                font-weight: normal,
                font-style: italic
            ),
            bold-italic: (
                filename:"atkinson-hyperlegible-latin-700-italic.woff2",
                font-weight: 700,
                font-style: italic
            )
        )
    )
);

@mixin build-font-face-def($fontFaces) {
    // Build any necessary @font-face definitions
    @each $key, $properties in $fontFaces {
        @each $key, $definition in map-get($properties, "definitions") {
            @font-face {
                font-family: map-get($properties, "font-family");
                font-style: map-get($definition, "font-style");
                font-weight: map-get($definition, "font-weight");
                src: url(#{map-get($properties, "font-directory")}#{map-get($definition, "filename")});
            }
        }
    }
}

@mixin build-fonts-properties($fonts) {
    @each $selector, $fontFamily in $fonts {
        #{$selector} {
            --fl-font-family: #{$fontFamily};
        }
    }
}

@mixin build-fonts-Enactors($fonts) {
    // Used by the @extend rule to reduce duplication of output CSS styles
    %fl-font-application {
        font-family: var(--fl-font-family) !important;
    }

    @each $selector, $fontFamily in $fonts {
        #{$selector},
        #{$selector} * {
            &:not([class*='icon']) {
                @extend %fl-font-application;
            }
        }
    }
}
