/**
 * Installs icons used by the SCION Workbench.
 */

@use 'sass:map';

/**
 * Current version of the icon font.
 * This version is appended to the HTTP request as query parameter when fetching the icon font to support cache busting.
 * Update this version when adding, removing or changing icons.
 */
$-version: 3;

$-default-icon-font-config: (
  // The font path must be root relative or excluded from the application build. Otherwise, the application build will fail
  // because the builder cannot resolve the font files relative to "this" SASS file.
  //
  // Webpack allows to exclude assets from the build by prefixing their path with a leading caret (^). For esbuild, the
  // application can register the excluded assets as `externalDependencies` in angular.json.
  //
  // To keep the workbench configuration minimal for Angular projects deployed in the context root, we reference font files by
  // their root relative path. Consequently, applications deployed in a subdirectory require additional configuration depending
  // on whether the application is built with esbuild or webpack.
  directory: '/fonts',
  filename: 'scion-workbench-icons',
  version: $-version,
);

/**
 * Installs icons used by the SCION Workbench as icon font named 'scion-workbench-icons'.
 *
 * Icons can be referenced by ligature in HTML elements associated with the CSS class 'scion-workbench-icons'.
 *
 * Example:
 * ```css
 * <span class="scion-workbench-icons">close</span>
 * ```
 */
@mixin install-icon-font($config) {
  $config: if(sass($config): $config; else: ());
  $config: map.merge($-default-icon-font-config, $config);
  $path: map.get($config, directory) + '/' + map.get($config, filename);
  $version: map.get($config, version);

  @font-face {
    font-family: 'scion-workbench-icons';
    src: url($path + '.ttf?' + $version) format('truetype'),
    url($path + '.woff?' + $version) format('woff'),
    url($path + '.svg?' + $version + '#scion-workbench-icons') format('svg');
    font-weight: normal;
    font-style: normal;
    font-display: block;
  }

  .scion-workbench-icons {
    /* use !important to prevent issues with browser extensions that change fonts */
    font-family: 'scion-workbench-icons' !important;
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;

    /* Enable Ligatures ================ */
    letter-spacing: 0;
    -webkit-font-feature-settings: "liga";
    -moz-font-feature-settings: "liga=1";
    -moz-font-feature-settings: "liga";
    -ms-font-feature-settings: "liga" 1;
    font-feature-settings: "liga";
    -webkit-font-variant-ligatures: discretionary-ligatures;
    font-variant-ligatures: discretionary-ligatures;

    /* Better Font Rendering =========== */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}
