// Mixins :: Generate Button

// Dependencies
@import "pack/seed-dash/_index";
@import "./_set-button-prop";
@import "./_set-button-text-color";
@import "./generate-button-states";
@import "./disabled-styles";

// Example $map
// $seed-button-color-primary: (
//   _generate-states: false
//   background: (
//     default: #3197D6,
//     hover: darken(#3197D6, 4),
//     active: darken(#3197D6, 8)
//   ),
//   border: (
//     default: #237AB3,
//     hover: #237AB3,
//     active: #237AB3,
//     focus: #237AB3
//   ),
//   box-shadow: (
//     focus: 0 0 0 1px rgba(white, 0.4) inset
//   ),
//   text: #fff
// ) !default;

@mixin generate-button-styles($config: false) {
  @if not $config or type-of($config) != "map" {
    @warn "generate-button-styles: Argument must be a sass map";
  }

  background-color: _get($config, background, default);
  border-color: _get($config, border, default);
  @include __set-button-prop(box-shadow, $config, default);
  @include __set-button-text-color($config, default, true);

  &:hover {
    background-color: _get($config, background, hover);
    border-color: _get($config, border, hover);
    @include __set-button-prop(box-shadow, $config, hover);
    @include __set-button-prop(text-decoration, $config, hover);
    @include __set-button-text-color($config, hover);
  }

  &:active {
    background-color: _get($config, background, active);
    border-color: _get($config, border, active);
    @include __set-button-prop(box-shadow, $config, active);
    @include __set-button-prop(text-decoration, $config, active);
    @include __set-button-text-color($config, active);
  }

  &:focus {
    border-color: _get($config, border, focus);
    @include __set-button-prop(box-shadow, $config, focus);
    @include __set-button-prop(text-decoration, $config, focus);
    @include __set-button-text-color($config, focus);

    &:active {
      @if _get($config, box-shadow, focus) and _get($config, box-shadow, active) {
        $focus: _get($config, box-shadow, focus);
        $active: _get($config, box-shadow, active);
        @if ($focus == "none") or ($active == "none") {
          box-shadow: none;
        }
        @else {
          box-shadow: $focus, $active;
        }
      }
      @else {
        @include __set-button-prop(box-shadow, $config, active);
      }
      @include __set-button-text-color($config, focus);
    }
  }

  @include disabled-styles {
    background-color: _get($config, background, default);
    border-color: _get($config, border, default);

    @if _get($config, text-decoration) {
      @if _get($config, text-decoration, default) {
        @include __set-button-prop(text-decoration, $config, default);
      }
    }
  }

  @if _get($config, _generate-states) {
    @include generate-button-states($config);
  }
}
