/*
Stylus variables are information about icon's compiled state, stored under its original file name

.icon-home {
  width: $icon_home_width;
}

The large array-like variables contain all information about a single icon
$icon_home = x y offset_x offset_y width height total_width total_height image_path;

At the bottom of this section, we provide information about the spritesheet itself
$spritesheet = width height image $spritesheet_sprites;
*/
$sprite_dash_case_name = 'sprite-dash-case';
$sprite_dash_case_x = 0px;
$sprite_dash_case_y = 0px;
$sprite_dash_case_offset_x = 0px;
$sprite_dash_case_offset_y = 0px;
$sprite_dash_case_width = 10px;
$sprite_dash_case_height = 20px;
$sprite_dash_case_total_width = 80px;
$sprite_dash_case_total_height = 100px;
$sprite_dash_case_image = 'nested/dir/spritesheet.png';
$sprite_dash_case = 0px 0px 0px 0px 10px 20px 80px 100px 'nested/dir/spritesheet.png' 'sprite-dash-case';
$sprite_snake_case_name = 'sprite_snake_case';
$sprite_snake_case_x = 10px;
$sprite_snake_case_y = 20px;
$sprite_snake_case_offset_x = -10px;
$sprite_snake_case_offset_y = -20px;
$sprite_snake_case_width = 20px;
$sprite_snake_case_height = 30px;
$sprite_snake_case_total_width = 80px;
$sprite_snake_case_total_height = 100px;
$sprite_snake_case_image = 'nested/dir/spritesheet.png';
$sprite_snake_case = 10px 20px -10px -20px 20px 30px 80px 100px 'nested/dir/spritesheet.png' 'sprite_snake_case';
$sprite_camel_case_name = 'spriteCamelCase';
$sprite_camel_case_x = 30px;
$sprite_camel_case_y = 50px;
$sprite_camel_case_offset_x = -30px;
$sprite_camel_case_offset_y = -50px;
$sprite_camel_case_width = 50px;
$sprite_camel_case_height = 50px;
$sprite_camel_case_total_width = 80px;
$sprite_camel_case_total_height = 100px;
$sprite_camel_case_image = 'nested/dir/spritesheet.png';
$sprite_camel_case = 30px 50px -30px -50px 50px 50px 80px 100px 'nested/dir/spritesheet.png' 'spriteCamelCase';
$sprite_dash_case_2x_name = 'sprite-dash-case@2x';
$sprite_dash_case_2x_x = 0px;
$sprite_dash_case_2x_y = 0px;
$sprite_dash_case_2x_offset_x = 0px;
$sprite_dash_case_2x_offset_y = 0px;
$sprite_dash_case_2x_width = 20px;
$sprite_dash_case_2x_height = 40px;
$sprite_dash_case_2x_total_width = 160px;
$sprite_dash_case_2x_total_height = 200px;
$sprite_dash_case_2x_image = 'nested/dir/spritesheet@2x.png';
$sprite_dash_case_2x = 0px 0px 0px 0px 20px 40px 160px 200px 'nested/dir/spritesheet@2x.png' 'sprite-dash-case@2x';
$sprite_snake_case_2x_name = 'sprite_snake_case@2x';
$sprite_snake_case_2x_x = 20px;
$sprite_snake_case_2x_y = 40px;
$sprite_snake_case_2x_offset_x = -20px;
$sprite_snake_case_2x_offset_y = -40px;
$sprite_snake_case_2x_width = 40px;
$sprite_snake_case_2x_height = 60px;
$sprite_snake_case_2x_total_width = 160px;
$sprite_snake_case_2x_total_height = 200px;
$sprite_snake_case_2x_image = 'nested/dir/spritesheet@2x.png';
$sprite_snake_case_2x = 20px 40px -20px -40px 40px 60px 160px 200px 'nested/dir/spritesheet@2x.png' 'sprite_snake_case@2x';
$sprite_camel_case_2x_name = 'spriteCamelCase@2x';
$sprite_camel_case_2x_x = 60px;
$sprite_camel_case_2x_y = 100px;
$sprite_camel_case_2x_offset_x = -60px;
$sprite_camel_case_2x_offset_y = -100px;
$sprite_camel_case_2x_width = 100px;
$sprite_camel_case_2x_height = 100px;
$sprite_camel_case_2x_total_width = 160px;
$sprite_camel_case_2x_total_height = 200px;
$sprite_camel_case_2x_image = 'nested/dir/spritesheet@2x.png';
$sprite_camel_case_2x = 60px 100px -60px -100px 100px 100px 160px 200px 'nested/dir/spritesheet@2x.png' 'spriteCamelCase@2x';
$spritesheet_width = 80px;
$spritesheet_height = 100px;
$spritesheet_image = 'nested/dir/spritesheet.png';
$spritesheet_sprites = $sprite_dash_case $sprite_snake_case $sprite_camel_case;
$spritesheet = 80px 100px 'nested/dir/spritesheet.png' $spritesheet_sprites;
$retina_spritesheet_width = 160px;
$retina_spritesheet_height = 200px;
$retina_spritesheet_image = 'nested/dir/spritesheet@2x.png';
$retina_spritesheet_sprites = $sprite_dash_case_2x $sprite_snake_case_2x $sprite_camel_case_2x;
$retina_spritesheet = 160px 200px 'nested/dir/spritesheet@2x.png' $retina_spritesheet_sprites;

/*
These "retina group" variables are mappings for the naming and pairing of normal and retina sprites.

The list formatted variables are intended for mixins like `retinaSprite` and `retinaSprites`.
*/
$sprite_dash_case_group_name = 'sprite-dash-case';
$sprite_dash_case_group = 'sprite-dash-case' $sprite_dash_case $sprite_dash_case_2x;
$sprite_snake_case_group_name = 'sprite_snake_case';
$sprite_snake_case_group = 'sprite_snake_case' $sprite_snake_case $sprite_snake_case_2x;
$sprite_camel_case_group_name = 'spriteCamelCase';
$sprite_camel_case_group = 'spriteCamelCase' $sprite_camel_case $sprite_camel_case_2x;
$retina_groups = $sprite_dash_case_group $sprite_snake_case_group $sprite_camel_case_group;

/*
The provided mixins are intended to be used with the array-like variables

.icon-home {
  spriteWidth($icon_home)
}

.icon-email {
  sprite($icon_email)
}

Example usage in HTML:

`display: block` sprite:
<div class="icon-home"></div>

To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:

// CSS
.icon {
  display: inline-block;
}

// HTML
<i class="icon icon-home"></i>
*/
spriteWidth($sprite) {
  width: $sprite[4];
}

spriteHeight($sprite) {
  height: $sprite[5];
}

spritePosition($sprite) {
  background-position: $sprite[2] $sprite[3];
}

spriteImage($sprite) {
  background-image: url($sprite[8]);
}

sprite($sprite) {
  spriteImage($sprite)
  spritePosition($sprite)
  spriteWidth($sprite)
  spriteHeight($sprite)
}

/*
The `retinaSprite` mixin sets up rules and a media query for a sprite/retina sprite.
  It should be used with a "retina group" variable.

The media query is from CSS Tricks: https://css-tricks.com/snippets/css/retina-display-media-query/

$icon_home_group = 'icon-home' $icon_home $icon_home_2x;

.icon-home {
  retinaSprite($icon_home_group)
}
*/
spriteBackgroundSize($sprite) {
  background-size: $sprite[6] $sprite[7];
}

retinaSprite($retina_group) {
  $normal_sprite = $retina_group[1];
  $retina_sprite = $retina_group[2];
  sprite($normal_sprite)

  @media (-webkit-min-device-pixel-ratio: 2),
         (min-resolution: 192dpi) {
    spriteImage($retina_sprite)
    spriteBackgroundSize($normal_sprite)
  }
}

/*
The `sprites` mixin generates identical output to the CSS template
  but can be overridden inside of Stylus

This must be run when you have at least 2 sprites.
  If run with a single sprite, then there will be reference errors.

sprites($spritesheet_sprites);
*/
sprites($sprites) {
  for $sprite in $sprites {
    $sprite_name = $sprite[9];
    .{$sprite_name} {
      sprite($sprite);
    }
  }
}

/*
The `retinaSprites` mixin generates a CSS rule and media query for retina groups
  This yields the same output as CSS retina template but can be overridden in Stylus

retinaSprites($retina_groups);
*/
retinaSprites($retina_groups) {
  for $retina_group in $retina_groups {
    $sprite_name = $retina_group[0];
    .{$sprite_name} {
      retinaSprite($retina_group);
    }
  }
}
