@import "./color";

$border-size-data: (
  0: 0,
  0.5: 0.5px,
  default: 1px,
  2: 0.125rem,
  4: .25rem
);

$border-style-data: (
  solid: solid,
  dashed: dashed
);

@mixin border-style($style: solid, $position: "") {
  $styleValue: map-get($border-style-data, $style);
  @if type-of($styleValue) != string {
    @error "Border style `#{$style}` not found.";
  }
  @if $position ==
    top or
    $position ==
    bottom or
    $position ==
    left or
    $position ==
    right
  {
    border-#{$position}-style: $styleValue;
  } @else {
    border-style: $styleValue;
  }
}

@mixin border-width($size: default, $position: "") {
  $sizeValue: map-get($border-size-data, $size);
  @if type-of($sizeValue) != number {
    @error "Border size `#{$size}` not found.";
  }
  @if $position ==
    top or
    $position ==
    bottom or
    $position ==
    left or
    $position ==
    right
  {
    border-#{$position}-width: $sizeValue;
  } @else {
    border-width: $sizeValue;
  }
}

@mixin border($color, $size: default, $style: solid) {
  @include border-color($color);
  @include border-style($style);
  @include border-width($size);
}

@mixin border-top($color, $size: default, $style: solid) {
  @include border-color($color);
  @include border-style($style, top);
  @include border-width($size, top);
}

@mixin border-bottom($color, $size: default, $style: solid) {
  @include border-color($color);
  @include border-style($style, bottom);
  @include border-width($size, bottom);
}

@mixin border-left($color, $size: default, $style: solid) {
  @include border-color($color);
  @include border-style($style, left);
  @include border-width($size, left);
}

@mixin border-right($color, $size: default, $style: solid) {
  @include border-color($color);
  @include border-style($style, right);
  @include border-width($size, right);
}

// LEGACY
@function border($color, $size: default, $style: solid) {
  $sizeValue: map-get($border-size-data, $size);
  $styleValue: map-get($border-style-data, $style);

  @if type-of($sizeValue) != number {
    @error "Border size `#{$size}` not found.";
  }
  @if type-of($styleValue) != string {
    @error "Border style `#{$size}` not found.";
  }

  @return #{$sizeValue $styleValue color($color)};
}
