/*
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;
*/
$sprite1_name = 'sprite1';
$sprite1_x = 100px;
$sprite1_y = 0px;
$sprite1_offset_x = -100px;
$sprite1_offset_y = 0px;
$sprite1_width = 50px;
$sprite1_height = 50px;
$sprite1_total_width = 150px;
$sprite1_total_height = 200px;
$sprite1_image = 'sprite.retina.png';
$sprite1 = 100px 0px -100px 0px 50px 50px 150px 200px 'sprite.retina.png' 'sprite1';
$sprite2_name = 'sprite2';
$sprite2_x = 100px;
$sprite2_y = 50px;
$sprite2_offset_x = -100px;
$sprite2_offset_y = -50px;
$sprite2_width = 50px;
$sprite2_height = 50px;
$sprite2_total_width = 150px;
$sprite2_total_height = 200px;
$sprite2_image = 'sprite.retina.png';
$sprite2 = 100px 50px -100px -50px 50px 50px 150px 200px 'sprite.retina.png' 'sprite2';
$sprite3_name = 'sprite3';
$sprite3_x = 0px;
$sprite3_y = 0px;
$sprite3_offset_x = 0px;
$sprite3_offset_y = 0px;
$sprite3_width = 100px;
$sprite3_height = 200px;
$sprite3_total_width = 150px;
$sprite3_total_height = 200px;
$sprite3_image = 'sprite.retina.png';
$sprite3 = 0px 0px 0px 0px 100px 200px 150px 200px 'sprite.retina.png' 'sprite3';
$sprite1_2x_name = 'sprite1@2x';
$sprite1_2x_x = 200px;
$sprite1_2x_y = 0px;
$sprite1_2x_offset_x = -200px;
$sprite1_2x_offset_y = 0px;
$sprite1_2x_width = 100px;
$sprite1_2x_height = 100px;
$sprite1_2x_total_width = 300px;
$sprite1_2x_total_height = 400px;
$sprite1_2x_image = 'sprite.retina@2x.png';
$sprite1_2x = 200px 0px -200px 0px 100px 100px 300px 400px 'sprite.retina@2x.png' 'sprite1@2x';
$sprite2_2x_name = 'sprite2@2x';
$sprite2_2x_x = 200px;
$sprite2_2x_y = 100px;
$sprite2_2x_offset_x = -200px;
$sprite2_2x_offset_y = -100px;
$sprite2_2x_width = 100px;
$sprite2_2x_height = 100px;
$sprite2_2x_total_width = 300px;
$sprite2_2x_total_height = 400px;
$sprite2_2x_image = 'sprite.retina@2x.png';
$sprite2_2x = 200px 100px -200px -100px 100px 100px 300px 400px 'sprite.retina@2x.png' 'sprite2@2x';
$sprite3_2x_name = 'sprite3@2x';
$sprite3_2x_x = 0px;
$sprite3_2x_y = 0px;
$sprite3_2x_offset_x = 0px;
$sprite3_2x_offset_y = 0px;
$sprite3_2x_width = 200px;
$sprite3_2x_height = 400px;
$sprite3_2x_total_width = 300px;
$sprite3_2x_total_height = 400px;
$sprite3_2x_image = 'sprite.retina@2x.png';
$sprite3_2x = 0px 0px 0px 0px 200px 400px 300px 400px 'sprite.retina@2x.png' 'sprite3@2x';
$spritesheet_width = 150px;
$spritesheet_height = 200px;
$spritesheet_image = 'sprite.retina.png';
$spritesheet_sprites = $sprite1 $sprite2 $sprite3;
$spritesheet = 150px 200px 'sprite.retina.png' $spritesheet_sprites;
$retina_spritesheet_width = 300px;
$retina_spritesheet_height = 400px;
$retina_spritesheet_image = 'sprite.retina@2x.png';
$retina_spritesheet_sprites = $sprite1_2x $sprite2_2x $sprite3_2x;
$retina_spritesheet = 300px 400px 'sprite.retina@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`.
*/
$sprite1_group_name = 'sprite1';
$sprite1_group = 'sprite1' $sprite1 $sprite1_2x;
$sprite2_group_name = 'sprite2';
$sprite2_group = 'sprite2' $sprite2 $sprite2_2x;
$sprite3_group_name = 'sprite3';
$sprite3_group = 'sprite3' $sprite3 $sprite3_2x;
$retina_groups = $sprite1_group $sprite2_group $sprite3_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);
    }
  }
}
