@use "sass:list";
@use "../variables" as *;

///
/// Generates a custom `@font-face` rule based on given parameters.
///
/// @param {String} $path - The path to the font file.
/// @param {String} $family - The font family name.
/// @param {String} [$type=""] - The type or variant of the font.
/// @param {String} [$ttf=null] - Indicates if TTF format is included.
/// @param {String} [$otf=null] - Indicates if OTF format is included.
/// @param {String} [$eot=null] - Indicates if EOT format is included.
/// @param {String} [$svg=null] - The ID for the SVG font along with indication to include SVG format.
///
/// @example
/// @include icon_face("#{$icon_dir}/#{$icon_name}", $icon_name, "", "ttf");
///
@mixin icon_face(
    $path,
    $family,
    $type: "",
    // $weight: 400,
    // $style: normal,
    // $local1: null,
    // $local2: null,
    $ttf: null,
    $otf: null,
    $eot: null,
    $svg: null
) {

    // Source List
    // ------------------------------------------------------------------------

    // Initialize an empty source list
    $src: null; // initialize an empty source path


    // Local Sources
    // ------------------------------------------------------------------------
    // only load local files when both sources are present

    // @if $local1 and $local2 {
    //     $src: list.append($src, local("#{$local1}"), comma);
    //     $src: list.append($src, local("#{$local2}"), comma);
    // }

    // ------------------------------------------------------------------------

    // list.append OpenType font if specified
    @if $otf {
        $src: list.append($src, url("#{$path}#{$type}.otf") format("opentype"), comma);
    }


    // Default Formats
    // ------------------------------------------------------------------------
    // load default formats (woff and woff2)

    // list.append WOFF2 and WOFF formats by default
    $src: list.append($src, url("#{$path}#{$type}.woff2") format("woff2"), comma);
    $src: list.append($src, url("#{$path}#{$type}.woff") format("woff"), comma);



    // Other Formats
    // ------------------------------------------------------------------------
    // Formats that should only be added at the end

    // list.append TrueType font if specified
    @if $ttf {
        $src: list.append($src, url("#{$path}#{$type}.ttf") format("truetype"), comma);
    }

    // list.append SVG font if specified
    @if $svg {
        $src: list.append($src, url("#{$path}#{$type}.svg##{$svg}") format("svg"), comma);
    }



    // Font Face Declaration
    // ------------------------------------------------------------------------

    // Define the font-face with the composed source list
    @font-face {
        font-family: $family;
        // for compatibility reasons EOT comes first and is not list.appended
        // Include EOT specifically for IE compatibility
        @if $eot {
            src: url("#{$path}#{$type}.eot"); // EOT should be first for IE
        }
        // load list.appended sources path
        src: $src; // Include all other font formats
        // font-weight: $weight;
        // font-style: $style;
    }


}
