@use 'sass:string';

/// Generate font-face declaration.
/// @param {string} $font-family - The font family name.
/// @param {string} $src - The font source.
/// @param {number} $font-weight - The font weight.
/// @param {string} $font-style - The font style.
/// @param {string} $font-display - The font display.
/// @return {string} - The generated font-face declaration.
/// @throws {error} - If the font format is not .woff2.
@mixin font-face(
  $font-family: null,
  $src: null,
  $font-weight: 400,
  $font-style: normal,
  $font-display: swap
) {
  @if not string.index($src, '.woff2') {
    @error 'It seems that your font format is not .woff2, please use a that format.';
  }

  @font-face {
    font-display: $font-display;
    font-family: $font-family;
    font-style: $font-style;
    font-weight: $font-weight;
    src: url('#{$src}') format('woff2');
  }
}
