@import 'colors';
@import 'colors-dark';

@mixin themeProperty($theme, $property, $color, $additionalPropertiesPositionIsFront, $additionalProperties) {
  @if $additionalPropertiesPositionIsFront {
    #{$property}: unquote($additionalProperties + ' ' + map-get($theme, $color));
  } @else {
    #{$property}: unquote(map-get($theme, $color) + ' ' + $additionalProperties);
  }
}

@mixin theme($property, $color, $additionalPropertiesPositionIsFront: false, $additionalProperties: '') {
  $light: map-get($themes, 'light');
  $dark: map-get($themes, 'dark');

  @include themeProperty($light, $property, $color, $additionalPropertiesPositionIsFront, $additionalProperties);

  .dark & {
    @include themeProperty($dark, $property, $color, $additionalPropertiesPositionIsFront, $additionalProperties);
  }
}

$themes: (
  light: (
    torrent-view--background: #e9eef2,
    torrent-list--background: #fff,
    torrent-list--border: -1px 0 0 0 rgba($sidebar--background, 0.15),
    torrents-list--alert--foreground: rgba(#8899a8, 0.5),
    action--foreground: #8899a8,
    table--heading--background: rgba(#f6f8fa, 0.6),
    table--heading--color: $table--heading--color,
    table--heading--color--hover: darken($table--heading--color, 10%),
    table--heading--color--active: darken($table--heading--color, 30%),
    table--heading--color--active--hover: darken($table--heading--color, 40%),
    table--heading--resize--indicator--background: rgba(darken(#f6f8fa, 10%), 0.75),
    table--heading--border: 0 1px 0 rgba(#1d2938, 0.1),
    table--heading--border--horizontal: 1px solid rgba(#1d2938, 0.08),
    torrent--primary--font-weight: 500,
    torrent--primary--foreground: saturate(darken($grey, 20%), 10%),
    torrent--primary--foreground--error: $red,
    torrent--primary--foreground--error--stopped: rgba($red, 0.6),
    torrent--primary--foreground--error--stopped--selected: rgba($white, 0.6),
    torrent--primary--foreground--stopped: rgba($grey, 0.8),
    torrent--primary--foreground--selected: $white,
    torrent--primary--foreground--selected--stopped: rgba($white, 0.6),
    torrent--primary--foreground--selected--error: $white,
    torrent--secondary--foreground: #8899a8,
    torrent--secondary--foreground--stopped: #c3ccd3,
    torrent--secondary--foreground--selected: $white,
    torrent--secondary--foreground--selected--stopped: rgba($white, 0.6),
    torrent--tertiary--foreground: #8899a8,
    torrent--tertiary--foreground--stopped: #c3ccd3,
    torrent--tertiary--foreground--selected: rgba($white, 0.9),
    torrent--tertiary--foreground--selected--stopped: rgba($white, 0.5),
    torrent--background--hover: #f6f8fa,
    torrent--background--selected: $blue,
    torrent--background--error: $red,
    torrent--border: 1px solid #e9eef2,
    torrent--border--selected: darken($blue, 3%),
    torrent--border--selected--error: darken($red, 3%),
    torrent--speed--foreground--selected--has-error: $white,
    torrent--speed--foreground--selected: $white,
    torrent--tags--background: #dce2e6,
    torrent--tags--foreground: #6f7d87,
    torrent--tags--background--selected: #4ea3ea,
    torrent--tags--background--selected--has-error: #ed7994,
    torrent--tags--foreground--selected: $white,
    torrent--tags--foreground--has-error: #fbe8ec,
    more-info--background: $white,
    more-info--background--hover: $white,
    more-info--box-shadow: (
      0 0 30px rgba(#1a2f3d, 0.11),
      0 0 0 1px rgba(#1a2f3d, 0.07),
    ),
    more-info--box-shadow--hover: (
      0 0 30px rgba(#1a2f3d, 0.2),
      0 0 0 1px rgba(#1a2f3d, 0.1),
    ),
    progress-bar--fill: $green,
    progress-bar--fill--checking: #8899a8,
    progress-bar--fill--completed: $blue,
    progress-bar--fill--error: #e95779,
    progress-bar--fill--error--stopped: #f2acbc,
    progress-bar--fill--selected: #fff,
    progress-bar--fill--selected--stopped: #5daaeb,
    progress-bar--fill--stopped: #e7ebee,
    progress-bar--track--background: rgba($green, 0.15),
    progress-bar--track--background--completed: rgba($blue, 0.15),
    progress-bar--track--background--error: rgba(#e95779, 0.15),
    progress-bar--track--background--error--stopped: rgba(#f2acbc, 0.15),
    progress-bar--track--background--selected: rgba(#fff, 0.15),
    progress-bar--track--background--selected--stopped: rgba(#fff, 0.15),
    progress-bar--track--background--stopped: rgba(#e7ebee, 0.35),
    progress-bar--track--background--checking:
      linear-gradient(
        -45deg,
        rgba(rgba(#8899a8, 0.15), 0) 0,
        rgba(rgba(#8899a8, 0.15), 0) 25%,
        rgba(rgba(#8899a8, 0.15), 0.5) 25%,
        rgba(rgba(#8899a8, 0.15), 0.5) 50%,
        rgba(rgba(#8899a8, 0.15), 0) 50%,
        rgba(rgba(#8899a8, 0.15), 0) 75%,
        rgba(rgba(#8899a8, 0.15), 0.5) 75%,
        rgba(rgba(#8899a8, 0.15), 0.5) 100%
      ),
    sidebar--background: $sidebar--background,
    sidebar--foreground: $sidebar--foreground,
    sidebar--border: 1px 0 rgba(darken($sidebar--foreground, 40%), 0.3),
    sidebar-filter--foreground: $sidebar--foreground,
    sidebar-filter--foreground--fill: rgba($sidebar--foreground, 0.5),
    sidebar-filter--foreground--header: rgba($sidebar--foreground, 0.5),
    sidebar-filter--foreground--active: $blue,
    sidebar-filter--foreground--hover: lighten($sidebar--foreground, 15%),
    sidebar--icon-button--fill: $sidebar--foreground,
    sidebar--icon-button--fill--hover: $blue,
    sidebar--icon-button--foreground: rgba($sidebar--foreground, 0.7),
    sidebar--icon-button--foreground--hover: $blue,
    sidebar-filter--count--foreground: darken($darkest-grey--hard, 5%),
    sidebar-filter--count--foreground--active: darken($darkest-grey--hard, 5%),
    sidebar-filter--count--background: lighten($darkest-grey--hard, 20%),
    sidebar-filter--count--background--active: $blue,
  ),
  dark: (
    torrent-view--background: $md-surface-dark-e08,
    torrent-list--background: $md-surface-dark,
    torrent-list--border: -1px 0 0 0 rgba($sidebar--background, 0.15),
    torrents-list--alert--foreground: rgba(#8899a8, 0.5),
    action--foreground: $md-grey-500,
    table--heading--background: $md-surface-dark-e01,
    table--heading--color: $md-text-disabled-dark,
    table--heading--color--hover: $md-text-secondary-dark,
    table--heading--color--active: $md-text-primary-dark,
    table--heading--color--active--hover: $white,
    table--heading--resize--indicator--background: $md-text-secondary-dark,
    table--heading--border: 0 1px 0 $md-text-dividers-dark,
    table--heading--border--horizontal: 1px solid $md-text-dividers-dark,
    torrent--primary--font-weight: 400,
    torrent--primary--foreground: $md-text-primary-dark,
    torrent--primary--foreground--error: $red,
    torrent--primary--foreground--error--stopped: rgba($red, 0.6),
    torrent--primary--foreground--error--stopped--selected: rgba($white, 0.6),
    torrent--primary--foreground--stopped: rgba($grey, 0.8),
    torrent--primary--foreground--selected: $white,
    torrent--primary--foreground--selected--stopped: rgba($white, 0.6),
    torrent--primary--foreground--selected--error: $white,
    torrent--secondary--foreground: $md-text-secondary-dark,
    torrent--secondary--foreground--stopped: $md-text-disabled-dark,
    torrent--secondary--foreground--selected: $white,
    torrent--secondary--foreground--selected--stopped: rgba($white, 0.6),
    torrent--tertiary--foreground: $md-text-secondary-dark,
    torrent--tertiary--foreground--stopped: #c3ccd3,
    torrent--tertiary--foreground--selected: rgba($white, 0.9),
    torrent--tertiary--foreground--selected--stopped: rgba($white, 0.5),
    torrent--background--hover: #f6f8fa,
    torrent--background--selected: $blue,
    torrent--background--error: $red,
    torrent--border: 1px solid $md-text-dividers-dark,
    torrent--border--selected: darken($blue, 3%),
    torrent--border--selected--error: darken($red, 3%),
    torrent--speed--foreground--selected--has-error: $white,
    torrent--speed--foreground--selected: $white,
    torrent--tags--background: $md-surface-dark-e06,
    torrent--tags--foreground: $md-text-secondary-dark,
    torrent--tags--background--selected: #4ea3ea,
    torrent--tags--background--selected--has-error: #ed7994,
    torrent--tags--foreground--selected: $white,
    torrent--tags--foreground--has-error: #fbe8ec,
    more-info--background: $white,
    more-info--background--hover: $white,
    more-info--box-shadow: (
      0 0 30px rgba(#1a2f3d, 0.11),
      0 0 0 1px rgba(#1a2f3d, 0.07),
    ),
    more-info--box-shadow--hover: (
      0 0 30px rgba(#1a2f3d, 0.2),
      0 0 0 1px rgba(#1a2f3d, 0.1),
    ),
    progress-bar--fill: $green,
    progress-bar--fill--checking: #8899a8,
    progress-bar--fill--completed: $blue,
    progress-bar--fill--error: #e95779,
    progress-bar--fill--error--stopped: #f2acbc,
    progress-bar--fill--selected: #fff,
    progress-bar--fill--selected--stopped: $md-text-secondary-dark,
    progress-bar--fill--stopped: $md-text-disabled-dark,
    progress-bar--track--background: rgba($green, 0.15),
    progress-bar--track--background--completed: rgba($blue, 0.15),
    progress-bar--track--background--error: rgba(#e95779, 0.15),
    progress-bar--track--background--error--stopped: rgba(#f2acbc, 0.15),
    progress-bar--track--background--selected: rgba(#fff, 0.15),
    progress-bar--track--background--selected--stopped: $md-text-dividers-dark,
    progress-bar--track--background--stopped: $md-text-dividers-dark,
    progress-bar--track--background--checking:
      linear-gradient(
        -45deg,
        rgba(rgba(#8899a8, 0.15), 0) 0,
        rgba(rgba(#8899a8, 0.15), 0) 25%,
        rgba(rgba(#8899a8, 0.15), 0.5) 25%,
        rgba(rgba(#8899a8, 0.15), 0.5) 50%,
        rgba(rgba(#8899a8, 0.15), 0) 50%,
        rgba(rgba(#8899a8, 0.15), 0) 75%,
        rgba(rgba(#8899a8, 0.15), 0.5) 75%,
        rgba(rgba(#8899a8, 0.15), 0.5) 100%
      ),
    sidebar--background: $md-surface-dark,
    sidebar--foreground: $md-text-secondary-dark,
    sidebar--border: 1px 0 $md-text-dividers-dark,
    sidebar-filter--foreground: $md-text-disabled-dark,
    sidebar-filter--foreground--fill: $md-text-dividers-dark,
    sidebar-filter--foreground--header: $md-text-primary-dark,
    sidebar-filter--foreground--active: $blue,
    sidebar-filter--foreground--hover: $md-text-secondary-dark,
    sidebar--icon-button--fill: $md-grey-500,
    sidebar--icon-button--fill--hover: $blue,
    sidebar--icon-button--foreground: $md-grey-400,
    sidebar--icon-button--foreground--hover: $blue,
    sidebar-filter--count--foreground: $md-text-secondary-dark,
    sidebar-filter--count--foreground--active: darken($darkest-grey--hard, 5%),
    sidebar-filter--count--background: $md-surface-dark-e06,
    sidebar-filter--count--background--active: $blue,
  ),
);
