@use "../tokens/breakpoint";
@use "./map" as *;

/// Get css propeties from map
///
/// @param {Map} $map - Map
/// @param {Arglist} $keys - Keys to fetch
///
/// @example
/// $map: (
///   background-color: #fff,
///   color: #000
/// );
///
/// .example {
///   @include css-map($map);
///  }
///
/// Output:
/// .example {
///   background-color: #fff;
///   color: #000;
/// }
@mixin css-map($_map, $keys...) {
  $map: if($keys, map-deep-get($_map, $keys...), $_map);

  @each $prop, $value in $map {
    #{$prop}: #{$value};
  }
}

/// Get responsive css propeties from map
///
/// @param {Map} $map - Map
/// @param {Arglist} $keys - Keys to fetch
///
/// @example
/// $map: (
///   default: (
///     color: red,
///   ),
///   xl: (
///     color: blue,
///   ),
/// );
///
/// .example {
///   @include responsive-css-map($map);
///  }
///
/// Output:
/// .example {
///   color: red;
///   @media only screen and (min-width: 1240px) {
///     color: blue;
///   }
/// }
@mixin responsive-css-map($map) {
  @each $breakpoint, $props in $map {
    @include breakpoint.get($breakpoint) {
      @include css-map($props);
    }
  }
}

/// Get variants of elemnt from map
///
/// @param {Map} $map - map
/// @param {Map} $className - class name of element
/// @param {Map} $classSuffix - suffix for class name of element
@mixin variants($map, $className: "", $classSuffix: "") {
  @each $variant, $props in $map {
    #{if(&, "&", "")}#{$className + variant-name($variant) + $classSuffix} {
      @include css-map($props);
    }
  }
}

/// Get responsive variants of elemnt from map
///
/// @param {Map} $map - map
/// @param {Map} $className - class name of element
/// @param {Map} $classSuffix - suffix for class name of element
@mixin responsive-variants($map, $className: "", $classSuffix: "") {
  @each $breakpoint, $props in $map {
    @include breakpoint.get($breakpoint) {
      @include variants($props, $className, $classSuffix);
    }
  }
}

/// Get prefixed variant name
/// @param {String} $name - Variant name
/// @return {String} - Return a prefixed variant name or empty string, for default variants
/// @example scss
///   variant-name('primary')
/// // -primary
///   variant-name('default')
///
@function variant-name($name, $prefix: "--", $suffix: "") {
  @if not $name or $name == default or $name == xs {
    @return "";
  }

  @return #{$prefix + $name + $suffix};
}
