//
//  Icons
//  _____________________________________________

//
//  Icons using font
//  ---------------------------------------------

@mixin lib-icon-font(
    $_icon-font-content,
    $_icon-font                : $icon-font,
    $_icon-font-size           : $icon-font__size,
    $_icon-font-line-height    : $icon-font__line-height,
    $_icon-font-color          : $icon-font__color,
    $_icon-font-color-hover    : $icon-font__color-hover,
    $_icon-font-color-active   : $icon-font__color-active,
    $_icon-font-margin         : $icon-font__margin,
    $_icon-font-vertical-align : $icon-font__vertical-align,
    $_icon-font-position       : $icon-font__position,
    $_icon-font-text-hide      : $icon-font__text-hide,
    $_icon-font-display        : $icon-font__display
) {
    @include _lib-icon-text-hide($_icon-font-text-hide);
    @include lib-css(display, $_icon-font-display);
    text-decoration: none;

    @if $_icon-font-position == before {
        &:before {
            @include _lib-icon-font(
                $_icon-font-content,
                $_icon-font,
                $_icon-font-size,
                $_icon-font-line-height,
                $_icon-font-color,
                $_icon-font-margin,
                $_icon-font-vertical-align
            );
        }
        &:hover {
            &:before {
                @include lib-css(color, $_icon-font-color-hover);
            }
        }
        &:active {
            &:before {
                @include lib-css(color, $_icon-font-color-active);
            }
        }
    }
    @else if $_icon-font-position == after {
        &:after {
            @include _lib-icon-font(
                $_icon-font-content,
                $_icon-font,
                $_icon-font-size,
                $_icon-font-line-height,
                $_icon-font-color,
                $_icon-font-margin,
                $_icon-font-vertical-align
            );
        }
        &:hover {
            &:after {
                @include lib-css(color, $_icon-font-color-hover);
            }
        }

        &:active {
            &:after {
                @include lib-css(color, $_icon-font-color-active);
            }
        }
    }
}

@mixin lib-icon-font-size(
    $_icon-font-size        : $icon-font__size,
    $_icon-font-line-height : $icon-font__line-height,
    $_icon-font-position    : $icon-font__position
) {
    @if $_icon-font-position == before {
        &:before {
            @include _lib-icon-font-size($_icon-font-size, $_icon-font-line-height);
        }
    }
    @else if $_icon-font-position == after {
        &:after {
            @include _lib-icon-font-size($_icon-font-size, $_icon-font-line-height);
        }
    }
}

@mixin lib-icon-font-symbol(
    $_icon-font-content,
    $_icon-font-position: $icon-font__position
) {
    @if $_icon-font-position == before {
        &:before {
            @include lib-css(content, $_icon-font-content);
        }
    }
    @else if $_icon-font-position == after {
        &:after {
            @include lib-css(content, $_icon-font-content);
        }
    }
}

//
//  Icons using image or sprite
//  ---------------------------------------------

@mixin lib-icon-image(
    $_icon-image,
    $_icon-image-width          : $icon__width,
    $_icon-image-height         : $icon__height,
    $_icon-image-margin         : $icon__margin,
    $_icon-image-vertical-align : $icon__vertical-align,
    $_icon-image-position-x     : $icon-image__position-x,
    $_icon-image-position-y     : $icon-image__position-y,
    $_icon-image-position       : $icon__position,
    $_icon-image-text-hide      : $icon__text-hide
) {
    display: inline-block;
    @include _lib-icon-text-hide($_icon-image-text-hide);

    @if $_icon-image-position == before {
        &:before {
            @include _lib-icon-image(
                $_icon-image,
                $_icon-image-width,
                $_icon-image-height,
                $_icon-image-margin,
                $_icon-image-vertical-align,
                $_icon-image-position-x,
                $_icon-image-position-y
            );
            margin: $_icon-image-margin;
        }
    }
    @else if $_icon-image-position == after {
        &:after {
            @include _lib-icon-image(
                $_icon-image,
                $_icon-image-width,
                $_icon-image-height,
                $_icon-image-margin,
                $_icon-image-vertical-align,
                $_icon-image-position-x,
                $_icon-image-position-y
            );
            margin: $_icon-image-margin;
        }
    }
}

@mixin lib-icon-image-position(
    $_icon-image-position-x : $icon-image__position-x,
    $_icon-image-position-y : $icon-image__position-y,
    $_icon-image-position   : $icon__position
) {
    @if $_icon-image-position == before {
        &:before {
            @include _lib-icon-image-position(
                $_icon-image-position-x,
                $_icon-image-position-y
            );
        }
    }
    @else if $_icon-image-position == after {
        &:after {
            @include _lib-icon-image-position(
                $_icon-image-position-x,
                $_icon-image-position-y
            );
        }
    }
}

@mixin lib-icon-sprite-position(
    $_icon-sprite-position-x : $icon-sprite__position-x,
    $_icon-sprite-position-y : $icon-sprite__position-y,
    $_icon-sprite-grid       : $icon-sprite__grid,
    $_icon-sprite-position   : $icon__position
) {
    @if $_icon-sprite-position == before {
        &:before {
            @include _lib-icon-sprite-position(
                $_icon-sprite-position-x,
                $_icon-sprite-position-y,
                $_icon-sprite-grid
            );
        }
    }
    @else if $_icon-sprite-position == after {
        &:after {
            @include _lib-icon-sprite-position(
                $_icon-sprite-position-x,
                $_icon-sprite-position-y,
                $_icon-sprite-grid
            );
        }
    }
}

@mixin lib-icon-image-size(
    $_icon-image-width    : $icon__width,
    $_icon-image-height   : $icon__height,
    $_icon-image-position : $icon__position
) {
    @if $_icon-image-position == before {
        &:before {
            @include _lib-icon-image-size($_icon-image-width, $_icon-image-height);
        }
    }
    @else if $_icon-image-position == after {
        &:after {
            @include _lib-icon-image-size($_icon-image-width, $_icon-image-height);
        }
    }
}

@mixin lib-icon-text-hide() {
    & > span {
        @include lib-visually-hidden();
    }
}

//
//  Internal use mixins
//  ---------------------------------------------

@mixin _lib-icon-text-hide($_icon-text-hide) {
    @if $_icon-text-hide == true {
        @include lib-icon-text-hide();
    }
}

//
//  Url existing check
//  ---------------------------------------------

@mixin _lib-icon-image-url($_path) {
    @if $_path != false {
        @include lib-css(background-image, url($_path));
    }
}

@mixin _lib-icon-image(
    $_icon-image,
    $_icon-image-width,
    $_icon-image-height,
    $_icon-image-margin,
    $_icon-image-vertical-align,
    $_icon-image-position-x,
    $_icon-image-position-y
) {
    @include _lib-icon-image-url($_icon-image);
    @include lib-css(background-position-x, $_icon-image-position-x);
    @include lib-css(background-position-y, $_icon-image-position-y);
    @include lib-css(line-height, $_icon-image-height);
    @include lib-css(margin, $_icon-image-margin);
    @include lib-css(vertical-align, $_icon-image-vertical-align);
    @include _lib-icon-image-size(
        $_icon-image-width,
        $_icon-image-height
    );
    background-repeat: no-repeat;
    content: '';
    display: inline-block;
}

@mixin _lib-icon-image-position(
    $_icon-image-position-x,
    $_icon-image-position-y
) {
    @include lib-css(background-position, $_icon-image-position-x $_icon-image-position-y);
}

@mixin _lib-icon-image-size(
    $icon__width,
    $icon__height
) {
    @include lib-css(height, $icon__height);
    @include lib-css(width, $icon__width);
}

@mixin _lib-icon-sprite-position(
    $_icon-sprite-position-x,
    $_icon-sprite-position-y,
    $_icon-sprite-grid
) {
    @include lib-css(background-position, -($_icon-sprite-position-x * $_icon-sprite-grid) -($_icon-sprite-position-y * $_icon-sprite-grid));
}

@mixin _lib-icon-font(
    $_icon-font-content,
    $_icon-font,
    $_icon-font-size,
    $_icon-font-line-height,
    $_icon-font-color,
    $_icon-font-margin,
    $_icon-font-vertical-align
) {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    @include _lib-icon-font-size($_icon-font-size, $_icon-font-line-height);
    @include lib-css(color, $_icon-font-color);
    @include lib-css(content, $_icon-font-content);
    @include lib-css(font-family, $_icon-font);
    @include lib-css(margin, $_icon-font-margin);
    @include lib-css(vertical-align, $_icon-font-vertical-align);
    display: inline-block;
    font-weight: normal;
    overflow: hidden;
    speak: none;
    text-align: center;
}

@mixin _lib-icon-font-size($_icon-font-size, $_icon-font-line-height) {
    @include lib-css(font-size, $_icon-font-size);
    @include lib-css(line-height, $_icon-font-line-height);
}
