///
//  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 '../kardia';
@use 'sass:map';

@mixin text($fills, $inks, $borders) {
  $fill: map.get($fills, 'default');
  $fill-disabled: map.get($fills, 'disabled');
  $ink-disabled: map.get($fills, 'disabled');
  $border: map.get($borders, 'default');

  &:not(:disabled) {
    @include kardia.color-bind('button', (
      fill: transparent,
      ink: $fill,
      border: transparent
    ));
    @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-fill-default-opacity));

    &:hover {
      @include kardia.color-bind('button', (
        fill: rgba(raw($fill), kardia.$color-fill-hover-opacity),
        ink: $fill,
        border: rgba(raw($border), kardia.$color-border-hover-opacity)
      ));
    }

    &:focus {
      @include kardia.color-bind('button', (
        fill: rgba(raw($fill), kardia.$color-fill-focus-opacity),
        ink: $fill,
        border: rgba(raw($border), kardia.$color-border-focus-opacity)
      ));
      @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-outline-focus-opacity));
    }

    &:active {
      @include kardia.color-bind('button', (
        fill: rgba(raw($fill), kardia.$color-fill-active-opacity),
        ink: $fill,
        border: rgba(raw($border), kardia.$color-border-active-opacity)
      ));
    }
  }

  &:disabled {
    @include kardia.color-bind('button', (
      fill: transparent,
      ink: $ink-disabled,
      border: transparent
    ));
  }
}

@mixin outlined($fills, $inks, $borders) {
  $fill: map.get($fills, 'default');
  $fill-hover: map.get($fills, 'hover');
  $fill-focus: map.get($fills, 'focus');
  $fill-active: map.get($fills, 'active');
  $fill-disabled: map.get($fills, 'disabled');
  $ink: map.get($inks, 'default');
  $ink-disabled: map.get($fills, 'disabled');
  $border: map.get($borders, 'default');
  $border-hover: map.get($borders, 'hover');
  $border-focus: map.get($borders, 'focus');
  $border-active: map.get($borders, 'active');
  $border-disabled: map.get($borders, 'disabled');

  &:not(:disabled) {
    @include kardia.color-bind('button', (
      fill: transparent,
      ink: $fill,
      border: $border
    ));
    @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-fill-default-opacity));

    &:focus {
      @include kardia.color-bind('button', (
        fill: rgba(raw($fill), kardia.$color-fill-focus-opacity),
        ink: $fill,
        border: $border
      ));
      @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-outline-focus-opacity));
    }

    &:hover {
      @include kardia.color-bind('button', (
        fill: $fill-hover,
        ink: $ink,
        border: $border-hover
      ));
    }

    &:active {
      @include kardia.color-bind('button', (
        fill: $fill-active,
        ink: $ink,
        border: $border-active
      ));
    }
  }

  &:disabled {
    @include kardia.color-bind('button', (
      fill: transparent,
      ink: $ink-disabled,
      border: $border-disabled
    ));
  }
}

@mixin filled($fills, $inks, $borders) {
  $fill: map.get($fills, 'default');
  $fill-hover: map.get($fills, 'hover');
  $fill-focus: map.get($fills, 'focus');
  $fill-active: map.get($fills, 'active');
  $fill-disabled: map.get($fills, 'disabled');
  $ink: map.get($inks, 'default');
  $ink-disabled: map.get($inks, 'disabled');
  $border: map.get($borders, 'default');
  $border-hover: map.get($borders, 'hover');
  $border-focus: map.get($borders, 'focus');
  $border-active: map.get($borders, 'active');
  $border-disabled: map.get($borders, 'disabled');

  &:not(:disabled) {
    @include kardia.color-bind('button', (
      fill: $fill,
      ink: $ink,
      border: $border
    ));
    @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-fill-default-opacity));

    &:hover {
      @include kardia.color-bind('button', (
        fill: $fill-hover,
        ink: $ink,
        border: $border-hover
      ));
    }

    &:focus {
      @include kardia.color-bind('button', (
        fill: $fill-focus,
        ink: $ink,
        border: $border-focus
      ));
      @include kardia.key-bind('button-outline', 2px solid rgba(raw($fill), kardia.$color-outline-focus-opacity));
    }

    &:active {
      @include kardia.color-bind('button', (
        fill: $fill-active,
        ink: $ink,
        border: $border-active
      ));
    }
  }

  &:disabled {
    @include kardia.color-bind('button', (
      fill: $fill-disabled,
      ink: $ink-disabled,
      border: $border-disabled
    ));
  }
}

@function raw($query) {
  @return kardia.token-switch-raw($query);
}