///
//  Copyright (c) 2022 GrowStocks
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in all
//  copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//  SOFTWARE.
///

@use 'node_modules/@matteusan/sentro';

@use 'sass:map';
@use 'sass:list';
@use 'sass:math';
@use 'sass:color';

@use 'general-support';

@function get-color-from-list($colors) {
    /*@return (
        'fill': list.index($colors, 1),
        'ink': list.index($colors, 2)
    );*/
}

@function tint($color, $percent) {
    @return color.adjust(color.mix(#fff, $color, $percent), $saturation: 11%);
}

@function shade($color, $percent) {
    @return color.adjust(color.mix(#000, $color, $percent), $saturation: 11%);
}

@function _get-linear($color) {
    @if $color <= 0.4045 {
        @return math.div($color, 12.92);
    } @else {
        @return math.pow(math.div($color + 0.055, 1.055), 2.4);
    }
}

@function _get-luminance($color) {
    $r: _get-linear(math.div(color.red($color), 255));
    $g: _get-linear(math.div(color.green($color), 255));
    $b: _get-linear(math.div(color.blue($color), 255));

    @return (0.2126 * $r) + (0.7152 * $g) + (0.0722 * $b);
}

@function get-ink($fill) {
    $_white-lumen: _get-luminance(#fff);

    @if general-support.is-type('map', $fill, false) {
        @if math.abs(_get-luminance(map.get($fill, 'default')) - $_white-lumen) > 0.7 {
            @return #fff;
        } @else {
            @return #000;
        }
    } @else {
        @if math.abs(_get-luminance($fill) - $_white-lumen) > 0.7 {
            @return #fff;
        } @else {
            @return #000;
        }
    }
}
