/*
* 
* 1. media-up()   - output @media expression (min-width)
* 2. media-down() - output @media expression (max-width)
* 3. media-only() - output @media expression (min-width) and (max-width)
*
*/



// beta TESTING


/* 1.  media-up($bp_name) - output @media expression up from breakpoint (min-width) */

// 
// @param  {String} $bp_name - breakpoint name
// @return {CSS expression} - @media expression
// 
@mixin media-up($bp_name) {

    @media (min-width:  get_grid_bp($bp_name)+px) {
        @content;
    }     
}


/* 2.  media-down($bp_name) - output @media expression down from breakpoint (max-width) */

// 
// @param  {String} $bp_name - breakpoint name
// @return {CSS expression} - @media expression
// 
@mixin media-down($bp_name) {

    @media (max-width:  get_grid_bp($bp_name)-1px) {
        @content;
    }    
}



// $mylist: asdf, qwer, tyui;

// @debug $mylist;
// // @debug list.nth(asdf qwer tyui, 2); // В ДОКУМЕНТАЦИИ ОШИБКА!!! -
// @debug nth(asdf qwer tyui, 2);
// @debug nth($mylist, 2);
// @debug nth($devices, 2);

// @debug list.nth($mylist, 2);  // Error


// list.nth($devices, 5)
// @debug list.nth($devices, 2); // 
// @debug list.nth(10px 12px 16px, 2); // 12px

// @debug list.nth(10px 12px 16px, 2); // 12px
// @debug list.nth([line1, line2, line3], -1); // line3


/* 3.  media-only($bp_name) - output @media expression up from breakpoint to the next breakpoint  (min-width) and (max-width) */

// 
// @param  {String} $bp_name - breakpoint name
// @return {CSS expression} - @media expression
// 

@mixin media-only($bp_name) { // tb_

    // $bp_index: index($devices, 'ds_'); // 1
    // $bp_index: index([mv_, tb_, ds_], ds_); // + 
    $bp_index: index(map-keys($devices), $bp_name ); // + 
    @debug $bp_index;  // Index передаваемого брейкпоинта
// $next_bp: nth($devices, $bp_index+1); // Сам объект брейкпоинта
// @debug $next_bp;
// @debug type-of($next_bp); //  => ? type;

    // $next_bp_name: map-keys($next_bp); // Имя(ключ брейкпоиинта) // -
    //$next_bp_name: index($next_bp, 0); // Имя(ключ брейкпоиинта) // -
    //
    // $next_bp_name: nth($next_bp, 1); // Имя(ключ брейкпоиинта) // + 
    // @debug $next_bp_name;

    // $next_bp_name: nth($next_bp, 1); // Имя(ключ брейкпоиинта) // +
    @debug length($devices-names);
    @if ( $bp_index >= length($devices-names) ) {
        @debug 'This is largest BP';
        // $next_bp_name: 1920;

        @media 
            (min-width:  get_grid_bp($bp_name)+px) 
        {

            @content;
        }        
    } @else {

        $next_bp_name: nth($devices-names, $bp_index+1); // Имя(ключ брейкпоиинта) // + мне кажется так писать более логично

        @media 
            // (min-width:  get_grid_bp(tb_)+px) and 
            // (max-width:  get_grid_bp(ds_)-1px) 

            (min-width:  get_grid_bp($bp_name)+px) 
            and 
            (max-width:  get_grid_bp($next_bp_name)-1px) 
        {

            @content;
        }
    }

    // $next_bp_name: nth($devices-names, $bp_index+1); // Имя(ключ брейкпоиинта) // + мне кажется так писать более логично
    // @debug $next_bp;
    // @debug $next_bp_name;

    
}



// @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
//   $min: breakpoint-min($name, $breakpoints);
//   @if $min {
//     @media (min-width: $min) {
//       @content;
//     }
//   } @else {
//     @content;
//   }
// }