/*
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;
*/
$icon1_name = 'icon1';
$icon1_x = 0px;
$icon1_y = 0px;
$icon1_offset_x = 0px;
$icon1_offset_y = 0px;
$icon1_width = 50px;
$icon1_height = 50px;
$icon1_total_width = 100px;
$icon1_total_height = 300px;
$icon1_image = 'sprite.retinaMapped.png';
$icon1 = 0px 0px 0px 0px 50px 50px 100px 300px 'sprite.retinaMapped.png' 'icon1';
$icon2_name = 'icon2';
$icon2_x = 0px;
$icon2_y = 50px;
$icon2_offset_x = 0px;
$icon2_offset_y = -50px;
$icon2_width = 50px;
$icon2_height = 50px;
$icon2_total_width = 100px;
$icon2_total_height = 300px;
$icon2_image = 'sprite.retinaMapped.png';
$icon2 = 0px 50px 0px -50px 50px 50px 100px 300px 'sprite.retinaMapped.png' 'icon2';
$icon3_name = 'icon3';
$icon3_x = 0px;
$icon3_y = 100px;
$icon3_offset_x = 0px;
$icon3_offset_y = -100px;
$icon3_width = 100px;
$icon3_height = 200px;
$icon3_total_width = 100px;
$icon3_total_height = 300px;
$icon3_image = 'sprite.retinaMapped.png';
$icon3 = 0px 100px 0px -100px 100px 200px 100px 300px 'sprite.retinaMapped.png' 'icon3';
$icon1_2x_name = 'icon1@2x';
$icon1_2x_x = 0px;
$icon1_2x_y = 0px;
$icon1_2x_offset_x = 0px;
$icon1_2x_offset_y = 0px;
$icon1_2x_width = 100px;
$icon1_2x_height = 100px;
$icon1_2x_total_width = 200px;
$icon1_2x_total_height = 600px;
$icon1_2x_image = 'sprite.retinaMapped@2x.png';
$icon1_2x = 0px 0px 0px 0px 100px 100px 200px 600px 'sprite.retinaMapped@2x.png' 'icon1@2x';
$icon2_2x_name = 'icon2@2x';
$icon2_2x_x = 0px;
$icon2_2x_y = 100px;
$icon2_2x_offset_x = 0px;
$icon2_2x_offset_y = -100px;
$icon2_2x_width = 100px;
$icon2_2x_height = 100px;
$icon2_2x_total_width = 200px;
$icon2_2x_total_height = 600px;
$icon2_2x_image = 'sprite.retinaMapped@2x.png';
$icon2_2x = 0px 100px 0px -100px 100px 100px 200px 600px 'sprite.retinaMapped@2x.png' 'icon2@2x';
$icon3_2x_name = 'icon3@2x';
$icon3_2x_x = 0px;
$icon3_2x_y = 200px;
$icon3_2x_offset_x = 0px;
$icon3_2x_offset_y = -200px;
$icon3_2x_width = 200px;
$icon3_2x_height = 400px;
$icon3_2x_total_width = 200px;
$icon3_2x_total_height = 600px;
$icon3_2x_image = 'sprite.retinaMapped@2x.png';
$icon3_2x = 0px 200px 0px -200px 200px 400px 200px 600px 'sprite.retinaMapped@2x.png' 'icon3@2x';
$icons_width = 100px;
$icons_height = 300px;
$icons_image = 'sprite.retinaMapped.png';
$icons_sprites = $icon1 $icon2 $icon3;
$icons = 100px 300px 'sprite.retinaMapped.png' $icons_sprites;
$icons_retina_width = 200px;
$icons_retina_height = 600px;
$icons_retina_image = 'sprite.retinaMapped@2x.png';
$icons_retina_sprites = $icon1_2x $icon2_2x $icon3_2x;
$icons_retina = 200px 600px 'sprite.retinaMapped@2x.png' $icons_retina_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`.
*/
$icon1_group_name = 'icon1';
$icon1_group = 'icon1' $icon1 $icon1_2x;
$icon2_group_name = 'icon2';
$icon2_group = 'icon2' $icon2 $icon2_2x;
$icon3_group_name = 'icon3';
$icon3_group = 'icon3' $icon3 $icon3_2x;
$icon_groups = $icon1_group $icon2_group $icon3_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);
    }
  }
}
