////
/// @group helpers
////

/// A map of glyph name to code (character entity reference).
/// Avoids things like content: '\201C' throughout SASS.
/// Usual usage is via the `get-glyph` function.
/// @see get-glyph
/// @link https://css-tricks.com/snippets/html/glyphs/
/// @prop {String} bullet [2022] Bullet (•)
/// @prop {String} quotation-mark [0022] Quotation mark (")
/// @prop {String} greater-than [003e] Greater than symbol (>)
/// @prop {String} greater-than [003c] Less than symbol (<)
/// @prop {String} copyright [00a9] Copyright symbol (©)
/// @prop {String} left-double-quotation-mark [201C] Left double quotation mark (“)
/// @prop {String} heavy-right-pointing-angle-quotation-mark-ornament [276F] Heavy right pointing angle quotation mark ornament (❯)
/// @prop {String} ne-double-arrow [021D7] North east double arrow (⇗)
/// @prop {String} up-tee-arrow [021A5] Up tee (bar) arrow (↥)
/// @prop {String} box-box [029C9] Double box (⧉)
/// @prop {String} punc-space [02008] Punctuation space (small, width of a comma)
/// @since 0.1.0
$nice-glyphs: (
  bullet: '2022',
  quotation-mark: '0022',
  greater-than: '003e',
  less-than: '003c',
  copyright: '00a9',
  left-double-quotation-mark: '201C',
  heavy-right-pointing-angle-quotation-mark-ornament: '276F',
  ne-double-arrow: '021D7',
  up-tee-arrow: '021A5',
  box-box: '029C9',
  punc-space: '02008'
  // Add more entity codes here as and when they're needed
) !default;

/// Gets a glyph code, or several, (character entity reference) from the
/// `$nice-glyphs` map, matching the given `$names`. Usually used with the content
/// property for psuedo elements, to avoid use of magic character reference strings.
/// @param {argList} $names The name(s) of the glyph(s) to get
/// @returns {string} The character entity reference code(s) as a string, e.g. '\201C' or '\02008\029C9'
/// @see $nice-glyphs
/// @since 0.1.0
/// @example Single glyph
///   .rule {
///     content: get-glyph(greater-than);
///   }
/// @example Multiple glyphs together
///   .rule {
///     content: get-glyph(punc-space, box-box);
///   }
@function get-glyph($names...) {
  $codes: '';

  @each $name in $names {
    @if map-has-key($nice-glyphs, $name) {
      $code: map-get($nice-glyphs, $name);
      $codes: $codes + '\\#{$code}';
    } @else {
      @error 'Glyph with name #{$name} could not be found in the $nice-glyphs map';
    }
  }

  @return unquote('\'#{$codes}\'');
}

@if $nice-output-glyph-classes {
  /// Output a BEM style glyph selector for each glyph in the map.
  /// E.g. .glyph.glyph--bullet { content: '\2022'; }
  /// @since 0.1.0
  .glyph {
    @each $key, $value in $nice-glyphs {
      &--#{$key} {
        &::before {
          content: unquote('\'\\#{$value}\'');
        }
      }
    }
  }
}
