/*
 * Copyright (C) 2022 Robert Bosch GmbH Copyright (C) 2022 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { Directive, HostBinding, Input } from '@angular/core';

@Directive({
  selector: '[bciCardColorState]',
})
export class BciCardBorderDirective {

  @Input({required: false}) bciCardColorState = '';
  @Input({required: false}) bciCardDisabled = false;
  @Input({required: false}) bciCardDisabledWithBorder = false;
  @Input({required: false}) bciCardHoverPressed = false;
  @Input({required: false}) bciCardHorizontal = false;

  // horizontal card

  @HostBinding('class.mat-card-border') get bciCardBorder() {
    return this.bciCardColorState === '' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-border-blue') get bciCardBorderBlue() {
    return this.bciCardColorState === 'blue' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-border-green') get bciCardBorderGreen() {
    return this.bciCardColorState === 'green' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-border-yellow') get bciCardBorderYellow() {
    return this.bciCardColorState === 'yellow' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-border-red') get bciCardBorderRed() {
    return this.bciCardColorState === 'red' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-border-neutral') get bciCardBorderNeutral() {
    return this.bciCardColorState === 'neutral' && !this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  // horizontal card

  @HostBinding('class.mat-card-horizontal-border') get bciCardHorizontalBorder() {
    return this.bciCardColorState === '' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-border-blue') get bciCardHorizontalBorderBlue() {
    return this.bciCardColorState === 'blue' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal  ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-border-green') get bciCardHorizontalBorderGreen() {
    return this.bciCardColorState === 'green' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal  ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-border-yellow') get bciCardHorizontalBorderYellow() {
    return this.bciCardColorState === 'yellow' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal  ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-border-red') get bciCardHorizontalBorderRed() {
    return this.bciCardColorState === 'red' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal  ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-border-neutral') get bciCarHorizontaldBorderNeutral() {
    return this.bciCardColorState === 'neutral' && !this.bciCardDisabledWithBorder && this.bciCardHorizontal  ? true : false;
  }

  // disabled

  @HostBinding('class.mat-card-disabled') get bciCardDisabledStyle() {
    return (this.bciCardDisabled && !this.cardHasColorBorder() && !this.bciCardHorizontal) || (this.bciCardDisabledWithBorder && !this.bciCardHorizontal) ? true : false;
  }

  @HostBinding('class.mat-card-disabled-with-color-border') get bciCardDisabledStyleWitholorBorder() {
    return this.bciCardDisabled && this.cardHasColorBorder() && !this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-disabled-with-border') get bciCardDisabledWithBorderStyle() {
    return this.bciCardDisabledWithBorder && !this.bciCardHorizontal ? true : false;
  }

  // disabled horizontal

  @HostBinding('class.mat-card-horizontal-disabled') get bciCardHorizontalDisabledStyle() {
    return (this.bciCardDisabled && !this.cardHasColorBorder() && this.bciCardHorizontal) || (this.bciCardDisabledWithBorder && this.bciCardHorizontal) ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-disabled-with-color-border') get bciCardHorizontalDisabledStyleWitholorBorder() {
    return this.bciCardDisabled && this.cardHasColorBorder() && this.bciCardHorizontal ? true : false;
  }

  @HostBinding('class.mat-card-horizontal-disabled-with-border') get bciCardHorizontalDisabledWithBorderStyle() {
    return this.bciCardDisabledWithBorder && this.bciCardHorizontal ? true : false;
  }

  // add hover and pressed styling if needed

  @HostBinding('class.mat-card-hover-pressed') get bciCardHoverPressedStyling() {
    return this.bciCardHoverPressed ? true : false;
  }

  cardHasColorBorder(): boolean {
    return this.bciCardColorState === 'blue' ||
      this.bciCardColorState === 'green' ||
      this.bciCardColorState === 'yellow' ||
      this.bciCardColorState === 'red' ||
      this.bciCardColorState === 'neutral';
  }
}
