@use 'sass:color';
@use 'sass:map';
@use 'sass:string';

@use 'colors';
@use 'colors-dark';

@mixin themeProperty($theme, $property, $color, $additionalPropertiesPositionIsFront, $additionalProperties) {
  @if $additionalPropertiesPositionIsFront {
    #{$property}: string.unquote($additionalProperties + ' ' + map.get($theme, $color));
  } @else {
    #{$property}: string.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: (
    action--foreground: #8899a8,
    action--foreground--hover: colors.$action--foreground--hover,
    action--background--hover: colors.$action--background--hover,
    action--border--hover: (
      1px 0 colors.$action--border--hover,
      -1px 0 colors.$action--border--hover,
    ),
    torrent-view--background: #e9eef2,
    torrent-list--background: #fff,
    torrent-list--border: -1px 0 0 0 rgba(colors.$sidebar--background, 0.15),
    torrents-list--alert--foreground: rgba(#8899a8, 0.5),
    table--heading--background: rgba(#f6f8fa, 0.6),
    table--heading--color: colors.$table--heading--color,
    table--heading--color--hover: color.adjust(colors.$table--heading--color, $lightness: -10%),
    table--heading--color--active: color.adjust(colors.$table--heading--color, $lightness: -30%),
    table--heading--color--active--hover: color.adjust(colors.$table--heading--color, $lightness: -40%),
    table--heading--resize--indicator--background: rgba(color.adjust(#f6f8fa, $lightness: -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: color.adjust(color.adjust(colors.$grey, $lightness: -20%), $saturation: 10%),
    torrent--primary--foreground--error: colors.$red,
    torrent--primary--foreground--error--stopped: rgba(colors.$red, 0.6),
    torrent--primary--foreground--error--stopped--selected: rgba(colors.$white, 0.6),
    torrent--primary--foreground--stopped: rgba(colors.$grey, 0.8),
    torrent--primary--foreground--selected: colors.$white,
    torrent--primary--foreground--selected--stopped: rgba(colors.$white, 0.6),
    torrent--primary--foreground--selected--error: colors.$white,
    torrent--secondary--foreground: #8899a8,
    torrent--secondary--foreground--stopped: #c3ccd3,
    torrent--secondary--foreground--selected: colors.$white,
    torrent--secondary--foreground--selected--stopped: rgba(colors.$white, 0.6),
    torrent--tertiary--foreground: #8899a8,
    torrent--tertiary--foreground--stopped: #c3ccd3,
    torrent--tertiary--foreground--selected: rgba(colors.$white, 0.9),
    torrent--tertiary--foreground--selected--stopped: rgba(colors.$white, 0.5),
    torrent--background--hover: #f6f8fa,
    torrent--background--selected: colors.$blue,
    torrent--background--error: colors.$red,
    torrent--border: 1px solid #e9eef2,
    torrent--border--selected: color.adjust(colors.$blue, $lightness: -3%),
    torrent--border--selected--error: color.adjust(colors.$red, $lightness: -3%),
    torrent--speed--foreground--selected--has-error: colors.$white,
    torrent--speed--foreground--selected: colors.$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: colors.$white,
    torrent--tags--foreground--has-error: #fbe8ec,
    more-info--background: colors.$white,
    more-info--background--hover: colors.$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: colors.$green,
    progress-bar--fill--checking: #8899a8,
    progress-bar--fill--completed: colors.$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(colors.$green, 0.15),
    progress-bar--track--background--completed: rgba(colors.$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),
    sidebar--background: colors.$sidebar--background,
    sidebar--foreground: colors.$sidebar--foreground,
    sidebar--border: 1px 0 rgba(color.adjust(colors.$sidebar--foreground, $lightness: -40%), 0.3),
    sidebar-filter--foreground: colors.$sidebar--foreground,
    sidebar-filter--foreground--fill: rgba(colors.$sidebar--foreground, 0.5),
    sidebar-filter--foreground--header: rgba(colors.$sidebar--foreground, 0.5),
    sidebar-filter--foreground--active: colors.$blue,
    sidebar-filter--foreground--hover: color.adjust(colors.$sidebar--foreground, $lightness: 15%),
    sidebar--icon-button--fill: colors.$sidebar--foreground,
    sidebar--icon-button--fill--hover: colors.$blue,
    sidebar--icon-button--foreground: rgba(colors.$sidebar--foreground, 0.7),
    sidebar--icon-button--foreground--hover: colors.$blue,
    sidebar-filter--count--foreground: color.adjust(colors.$darkest-grey--hard, $lightness: -5%),
    sidebar-filter--count--foreground--active: color.adjust(colors.$darkest-grey--hard, $lightness: -5%),
    sidebar-filter--count--background: color.adjust(colors.$darkest-grey--hard, $lightness: 20%),
    sidebar-filter--count--background--active: colors.$blue,
  ),
  dark: (
    action--foreground: colors-dark.$md-grey-500,
    action--foreground--hover: colors.$action--foreground--hover,
    action--background--hover: color.adjust(colors-dark.$md-surface-dark-e08, $lightness: 4%),
    action--border--hover: (
      0px,
      0px,
    ),
    torrent-view--background: colors-dark.$md-surface-dark-e08,
    torrent-list--background: colors-dark.$md-surface-dark,
    torrent-list--border: -1px 0 0 0 rgba(colors.$sidebar--background, 0.15),
    torrents-list--alert--foreground: rgba(#8899a8, 0.5),
    table--heading--background: colors-dark.$md-surface-dark-e01,
    table--heading--color: colors-dark.$md-text-disabled-dark,
    table--heading--color--hover: colors-dark.$md-text-secondary-dark,
    table--heading--color--active: colors-dark.$md-text-primary-dark,
    table--heading--color--active--hover: colors.$white,
    table--heading--resize--indicator--background: colors-dark.$md-text-secondary-dark,
    table--heading--border: 0 1px 0 colors-dark.$md-text-dividers-dark,
    table--heading--border--horizontal: 1px solid colors-dark.$md-text-dividers-dark,
    torrent--primary--font-weight: 400,
    torrent--primary--foreground: colors-dark.$md-text-primary-dark,
    torrent--primary--foreground--error: colors.$red,
    torrent--primary--foreground--error--stopped: rgba(colors.$red, 0.6),
    torrent--primary--foreground--error--stopped--selected: rgba(colors.$white, 0.6),
    torrent--primary--foreground--stopped: rgba(colors.$grey, 0.8),
    torrent--primary--foreground--selected: colors.$white,
    torrent--primary--foreground--selected--stopped: rgba(colors.$white, 0.6),
    torrent--primary--foreground--selected--error: colors.$white,
    torrent--secondary--foreground: colors-dark.$md-text-secondary-dark,
    torrent--secondary--foreground--stopped: colors-dark.$md-text-disabled-dark,
    torrent--secondary--foreground--selected: colors.$white,
    torrent--secondary--foreground--selected--stopped: rgba(colors.$white, 0.6),
    torrent--tertiary--foreground: colors-dark.$md-text-secondary-dark,
    torrent--tertiary--foreground--stopped: #c3ccd3,
    torrent--tertiary--foreground--selected: rgba(colors.$white, 0.9),
    torrent--tertiary--foreground--selected--stopped: rgba(colors.$white, 0.5),
    torrent--background--hover: #f6f8fa,
    torrent--background--selected: colors.$blue,
    torrent--background--error: colors.$red,
    torrent--border: 1px solid colors-dark.$md-text-dividers-dark,
    torrent--border--selected: color.adjust(colors.$blue, $lightness: -3%),
    torrent--border--selected--error: color.adjust(colors.$red, $lightness: -3%),
    torrent--speed--foreground--selected--has-error: colors.$white,
    torrent--speed--foreground--selected: colors.$white,
    torrent--tags--background: colors-dark.$md-surface-dark-e06,
    torrent--tags--foreground: colors-dark.$md-text-secondary-dark,
    torrent--tags--background--selected: #4ea3ea,
    torrent--tags--background--selected--has-error: #ed7994,
    torrent--tags--foreground--selected: colors.$white,
    torrent--tags--foreground--has-error: #fbe8ec,
    more-info--background: colors.$white,
    more-info--background--hover: colors.$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: colors.$green,
    progress-bar--fill--checking: #8899a8,
    progress-bar--fill--completed: colors.$blue,
    progress-bar--fill--error: #e95779,
    progress-bar--fill--error--stopped: #f2acbc,
    progress-bar--fill--selected: #fff,
    progress-bar--fill--selected--stopped: colors-dark.$md-text-secondary-dark,
    progress-bar--fill--stopped: colors-dark.$md-text-disabled-dark,
    progress-bar--track--background: rgba(colors.$green, 0.15),
    progress-bar--track--background--completed: rgba(colors.$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: colors-dark.$md-text-dividers-dark,
    progress-bar--track--background--stopped: colors-dark.$md-text-dividers-dark,
    sidebar--background: colors-dark.$md-surface-dark,
    sidebar--foreground: colors-dark.$md-text-secondary-dark,
    sidebar--border: 1px 0 colors-dark.$md-text-dividers-dark,
    sidebar-filter--foreground: colors-dark.$md-text-disabled-dark,
    sidebar-filter--foreground--fill: colors-dark.$md-text-dividers-dark,
    sidebar-filter--foreground--header: colors-dark.$md-text-primary-dark,
    sidebar-filter--foreground--active: colors.$blue,
    sidebar-filter--foreground--hover: colors-dark.$md-text-secondary-dark,
    sidebar--icon-button--fill: colors-dark.$md-grey-500,
    sidebar--icon-button--fill--hover: colors.$blue,
    sidebar--icon-button--foreground: colors-dark.$md-grey-400,
    sidebar--icon-button--foreground--hover: colors.$blue,
    sidebar-filter--count--foreground: colors-dark.$md-text-secondary-dark,
    sidebar-filter--count--foreground--active: color.adjust(colors.$darkest-grey--hard, $lightness: -5%),
    sidebar-filter--count--background: colors-dark.$md-surface-dark-e06,
    sidebar-filter--count--background--active: colors.$blue,
  ),
);
