@use 'sass:map';
@use '~@angular/material' as mat;

@mixin color($theme) {
  $config: mat.get-color-config($theme);
  $primary: map.get($config, primary);
  $accent: map.get($config, accent);

  .rds-c-selectable {
    border: 1px solid transparent;
    cursor: pointer;
    position: relative;

    &.rds-selectable-selected::before,
    &:hover::before,
    &:focus::before {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
    }

    &.mat-accent {
      @include rds-c-selectable-color($accent);
    }

    &.mat-primary {
      @include rds-c-selectable-color($primary);
    }
  }
}

@mixin typography($theme) {
}

@mixin theme($theme) {
  $config: mat.get-color-config($theme);
  @if $config != null {
    @include color($theme);
  }

  $typography-config: mat.get-typography-config($theme);
  @if $typography-config != null {
    @include typography($theme);
  }
}

@mixin rds-c-selectable-color($palette) {
  &.rds-selectable-selected {
    border-color: mat.get-color-from-palette($palette);
    &::before {
      background-color: mat.get-color-from-palette($palette, default, 0.05);
    }
    &::after {
      content: attr(data-rds-selectable-icon);
      font-family: 'Material Symbols Outlined';
      font-family: var(--rds-selectable-icon-font, 'Material Symbols Outlined');
      position: absolute;
      color: mat.get-color-from-palette($palette);
      font-size: 20px;
      height: 20px;
      width: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    @include rds-c-selectable-icon-pos();
  }

  &:hover {
    &::before {
      background-color: mat.get-color-from-palette($palette, default, 0.075);
    }
    &:not(.rds-selectable-selected) {
      border-color: mat.get-color-from-palette($palette, default, 0.075);
    }
  }

  &:focus {
    outline: none;
    &::before {
      background-color: mat.get-color-from-palette($palette, default, 0.1);
    }
    &:not(.rds-selectable-selected) {
      border-color: mat.get-color-from-palette($palette, default, 0.1);
    }
  }
}

/* var() isn't supported in IE, so we provide a default '0' to position appropriately. */
@mixin rds-c-selectable-icon-pos() {
  &.icon-top-right::after {
    top: 0;
    right: 0;
    top: var(--rds-selectable-icon-padding, 0);
    right: var(--rds-selectable-icon-padding, 0);
  }
  &.icon-top-left::after {
    top: 0;
    left: 0;
    top: var(--rds-selectable-icon-padding, 0);
    left: var(--rds-selectable-icon-padding, 0);
  }
  &.icon-bottom-right::after {
    bottom: 0;
    right: 0;
    bottom: var(--rds-selectable-icon-padding, 0);
    right: var(--rds-selectable-icon-padding, 0);
  }
  &.icon-bottom-left::after {
    bottom: 0;
    left: 0;
    bottom: var(--rds-selectable-icon-padding, 0);
    left: var(--rds-selectable-icon-padding, 0);
  }
}
