@use 'sass:meta';
@use 'sass:string';
@use '../variables/misc' as *;

/// A simply asset file location builder.
///
/// @param {String} $type - Asset type, matching folder name
/// @param {String} $file - Asset file name, including extension
///
/// @return {String} A file location leading to the asset.
///
/// @access private
/// @group Utilities
/// @require {variable} $asset-base-path
@function _asset($type, $file) {
  $asset-path: if(
    meta.variable-exists('asset-base-path') or
    meta.global-variable-exists('asset-base-path'),
    $asset-base-path,
    'assets'
  );

  @if not $asset-path or $asset-path == '' {
    @return string.unquote('#{$type}/#{$file}');
  }

  @return string.unquote('#{$asset-path}/#{$type}/#{$file}');
}

/// Image asset helper. Returns the full relative file path for the image.
///
/// @param {String} $file - The image file name, including extension.
///
/// @return {String} The relative file location leading to the image.
///
/// @access public
/// @group Utilities
/// @require {function} _asset
@function image($file) {
  @return _asset('img', $file);
}

/// Font asset helper. Returns the full relative file path for the font.
///
/// @param {String} $file - The font file name, including extension.
///
/// @return {String} The relative file location leading to the font.
///
/// @access public
/// @group Utilities
/// @require {function} _asset
@function font($file) {
  @return _asset('fonts', $file);
}
