@use "sass:color";
@use "sass:map";
@use "settings" as *;
@use "colors" as *;
@use "helpers/functions";

$bitcoin-color: #f7931a;

// Default: Light theme
@mixin theme {
  #{$css-var-prefix}background-color: #{$white};

  // Text color
  #{$css-var-prefix}color: #{$zinc-750};

  // Text selection color
  #{$css-var-prefix}text-selection-color: #{rgba($bitcoin-color, 0.25)};

  // Muted colors
  #{$css-var-prefix}muted-color: #{$zinc-550};
  #{$css-var-prefix}muted-border-color: #{mix($slate-100, $slate-50)};

  // Primary colors
  #{$css-var-prefix}primary: #{$bitcoin-color};
  #{$css-var-prefix}primary-background: var(#{$css-var-prefix}primary);
  #{$css-var-prefix}primary-border: var(#{$css-var-prefix}primary-background);
  #{$css-var-prefix}primary-underline: #{rgba($bitcoin-color, 0.5)};
  #{$css-var-prefix}primary-hover: #{color.scale($bitcoin-color, $lightness: -21%)};
  #{$css-var-prefix}primary-hover-background: #{color.scale($bitcoin-color, $lightness: 21%)};
  #{$css-var-prefix}primary-hover-border: var(#{$css-var-prefix}primary-hover-background);
  #{$css-var-prefix}primary-hover-underline: var(#{$css-var-prefix}primary-hover);
  #{$css-var-prefix}primary-focus: #{rgba($bitcoin-color, 0.375)};
  #{$css-var-prefix}primary-inverse: #{$black};

  // Secondary colors
  #{$css-var-prefix}secondary: #{$slate-550};
  #{$css-var-prefix}secondary-background: #{$slate-600};
  #{$css-var-prefix}secondary-border: var(#{$css-var-prefix}secondary-background);
  #{$css-var-prefix}secondary-underline: #{rgba($slate-550, 0.5)};
  #{$css-var-prefix}secondary-hover: #{$slate-650};
  #{$css-var-prefix}secondary-hover-background: #{$slate-650};
  #{$css-var-prefix}secondary-hover-border: var(#{$css-var-prefix}secondary-hover-background);
  #{$css-var-prefix}secondary-hover-underline: var(#{$css-var-prefix}secondary-hover);
  #{$css-var-prefix}secondary-focus: #{rgba($slate-550, 0.25)};
  #{$css-var-prefix}secondary-inverse: #{$white};

  // Contrast colors
  #{$css-var-prefix}contrast: #{$slate-900};
  #{$css-var-prefix}contrast-background: #{$slate-900};
  #{$css-var-prefix}contrast-border: var(#{$css-var-prefix}contrast-background);
  #{$css-var-prefix}contrast-underline: #{rgba($slate-900, 0.5)};
  #{$css-var-prefix}contrast-hover: #{$black};
  #{$css-var-prefix}contrast-hover-background: #{$black};
  #{$css-var-prefix}contrast-hover-border: var(#{$css-var-prefix}contrast-hover-background);
  #{$css-var-prefix}contrast-hover-underline: var(#{$css-var-prefix}secondary-hover);
  #{$css-var-prefix}contrast-focus: #{rgba($slate-550, 0.25)};
  #{$css-var-prefix}contrast-inverse: #{$white};

  // Box shadow
  #{$css-var-prefix}box-shadow: functions.shadow($slate-400);

  // Typography
  @if map.get($modules, "content/typography") {
    // Headings colors
    #{$css-var-prefix}h1-color: #{$zinc-800};
    #{$css-var-prefix}h2-color: #{$zinc-750};
    #{$css-var-prefix}h3-color: #{$zinc-700};
    #{$css-var-prefix}h4-color: #{$zinc-650};
    #{$css-var-prefix}h5-color: #{$zinc-600};
    #{$css-var-prefix}h6-color: #{$zinc-550};

    // Highlighted text (<mark>)
    #{$css-var-prefix}mark-background-color: #{mix($amber-100, $amber-50)};
    #{$css-var-prefix}mark-color: #{$zinc-950};

    // Inserted (<ins>) & Deleted (<del>)
    #{$css-var-prefix}ins-color: #{mix($jade-450, $zinc-750)};
    #{$css-var-prefix}del-color: #{mix($red-500, $zinc-750)};

    // Blockquote
    #{$css-var-prefix}blockquote-border-color: var(#{$css-var-prefix}muted-border-color);
    #{$css-var-prefix}blockquote-footer-color: var(#{$css-var-prefix}muted-color);
  }

  // Button
  @if map.get($modules, "content/button") {
    // To disable box-shadow, remove the var or set to '0 0 0 rgba(0, 0, 0, 0)'
    // Don't use, 'none, 'false, 'null', '0', etc.
    #{$css-var-prefix}button-box-shadow: 0 0 0 rgba(0, 0, 0, 0);
    #{$css-var-prefix}button-hover-box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }

  // Table
  @if map.get($modules, "content/table") {
    #{$css-var-prefix}table-border-color: var(#{$css-var-prefix}muted-border-color);
    #{$css-var-prefix}table-row-stripped-background-color: #{rgba($zinc-500, 0.0375)};
  }

  // Form elements
  @if map.get($modules, "forms/basics") {
    #{$css-var-prefix}form-element-background-color: #{mix($slate-50, $white, 25%)};
    #{$css-var-prefix}form-element-selected-background-color: #{$slate-100};
    #{$css-var-prefix}form-element-border-color: #{$slate-150};
    #{$css-var-prefix}form-element-color: #{$zinc-850};
    #{$css-var-prefix}form-element-placeholder-color: var(#{$css-var-prefix}muted-color);
    #{$css-var-prefix}form-element-active-background-color: #{$white};
    #{$css-var-prefix}form-element-active-border-color: var(#{$css-var-prefix}primary-border);
    #{$css-var-prefix}form-element-focus-color: var(#{$css-var-prefix}primary-focus);
    #{$css-var-prefix}form-element-disabled-background-color: var(
      #{$css-var-prefix}form-element-background-color
    );
    #{$css-var-prefix}form-element-disabled-border-color: var(
      #{$css-var-prefix}form-element-border-color
    );
    #{$css-var-prefix}form-element-disabled-opacity: 0.5;
    #{$css-var-prefix}form-element-invalid-border-color: #{mix($red-500, $zinc-350)};
    #{$css-var-prefix}form-element-invalid-active-border-color: #{mix($red-500, $zinc-350, 75%)};
    #{$css-var-prefix}form-element-invalid-focus-color: var(
      #{$css-var-prefix}form-element-invalid-active-border-color
    );
    #{$css-var-prefix}form-element-valid-border-color: #{mix($jade-450, $zinc-350)};
    #{$css-var-prefix}form-element-valid-active-border-color: #{mix($jade-450, $zinc-350, 75%)};
    #{$css-var-prefix}form-element-valid-focus-color: var(
      #{$css-var-prefix}form-element-valid-active-border-color
    );

    // Focus for buttons, radio and select
    input:is(
        [type="submit"],
        [type="button"],
        [type="reset"],
        [type="checkbox"],
        [type="radio"],
        [type="file"]
      ) {
      #{$css-var-prefix}form-element-focus-color: var(#{$css-var-prefix}primary-focus);
    }
  }

  // Range (input[type="range"])
  @if map.get($modules, "forms/input-range") {
    #{$css-var-prefix}range-border-color: #{$slate-100};
    #{$css-var-prefix}range-active-border-color: #{$slate-200};
    #{$css-var-prefix}range-thumb-border-color: var(#{$css-var-prefix}background-color);
    #{$css-var-prefix}range-thumb-color: var(#{$css-var-prefix}primary-background);
    #{$css-var-prefix}range-thumb-active-color: var(#{$css-var-prefix}primary-hover-background);
  }

  // Form validation icons
  @if map.get($modules, "forms/basics") {
    #{$css-var-prefix}icon-valid: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='#{functions.display-rgb(mix($jade-450, $zinc-350))}' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    #{$css-var-prefix}icon-invalid: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='#{functions.display-rgb(mix($red-500, $zinc-350, 75%))}' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
  }

  // Document
  color-scheme: light;
}
