@import '../shared-styles/index';

// General style
:host {
  display: inline-block;
  cursor: pointer;
  position: relative;
  text-decoration: underline;
  transition-property: color, box-shadow, transform;
  transition-duration: v(link-transition-duration);
  transition-timing-function: v(link-transition-timing-function);
  hyphens: none;

  &::ng-deep a {
    display: flex; // get icons aligned with text
    align-items: flex-start; // align with the top
  }

  &:hover {
    text-decoration: none;
  }

  &:active {
    text-decoration: none;

    ::ng-deep a:not([disabled]):not([aria-disabled]) {
      transform: v(link-active-transform);
    }
  }

  &:has(a[disabled]),
  &:has(a[aria-disabled]) {
    text-decoration: underline;
    text-decoration-color: v(link-disabled-color);
  }
}

:host.nx-link--xsmall {
  @include type-style(link-xsmall);
}

:host.nx-link--small {
  @include type-style(link-small);
}

:host.nx-link--large {
  @include type-style(link-large);
}

:host.nx-link--primary {
  color: v(link-color);

  &:hover {
    color: v(link-hover-color);
  }

  &:active {
    color: v(link-active-color);
  }

  &::ng-deep a[disabled],
  &::ng-deep a[aria-disabled] {
    color: v(link-disabled-color);
  }
}

:host.nx-link--secondary {
  color: v(link-secondary-color);

  &:hover {
    color: v(link-secondary-hover-color);
  }

  &:active {
    color: v(link-secondary-active-color);
  }

  &::ng-deep a[disabled],
  &::ng-deep a[aria-disabled] {
    color: v(link-secondary-disabled-color);
  }
}

:host.nx-link--subtle {
  text-decoration: none;
  font-weight: v(link-subtle-font-weight);

  &:hover {
    text-decoration: underline;
  }

  &:active {
    text-decoration: underline;
  }
}

// focus styling
:host.cdk-keyboard-focused ::ng-deep a {
  border-radius: nx-border-radius(s);
  outline: 0;
  @include focus-style;
}

// negative
:host(.nx-link--negative) {
  color: v(negative);

  &:hover {
    color: v(negative-01);
  }

  &::ng-deep a:active {
    color: v(negative-02);
  }

  &::ng-deep a[disabled],
  &::ng-deep a[aria-disabled] {
    color: v(negative-dimmed);
  }
}

// black
:host(.nx-link--black) {
  color: v(link-black-color);

  &:hover {
    color: v(link-black-hover-color);
  }

  &::ng-deep a:active {
    color: v(link-black-active-color);
  }

  &::ng-deep a[disabled],
  &::ng-deep a[aria-disabled] {
    color: v(link-black-disabled-color);
  }
}

// link within text
:host.nx-link--text {
  font-weight: nx-font-weight(bold);
  text-transform: none;
  letter-spacing: normal;
  border-radius: nx-border-radius(s);
  font-size: inherit;
  line-height: inherit;
  display: inline;

  // fix text - link alignment in IE11
  ::ng-deep a {
    display: inline;
  }

  ::ng-deep nx-icon.nx-link__icon {
    vertical-align: bottom;
  }
}

// link with icons
:host::ng-deep {
  .c-icon::before,
  nx-icon.nx-link__icon::before {
    line-height: inherit;
    font-size: inherit;
    display: inline-block;
  }

  nx-icon {
    margin-inline-end: v(link-icon-gap);
    display: inline-block;
  }
}

:host.nx-link--icon-right ::ng-deep nx-icon {
  order: 2;
  margin-inline-end: 0;
  margin-inline-start: v(link-icon-gap);
}

:host.nx-link--icon-only ::ng-deep {
  .c-icon,
  nx-icon {
    margin-inline-end: 0;
    margin-inline-start: 0;
  }
}

:host.nx-link--xsmall ::ng-deep {
  .c-icon,
  nx-icon.nx-link__icon {
    font-size: v(link-xsmall-icon-size);
  }
}

:host.nx-link--small ::ng-deep {
  .c-icon,
  nx-icon.nx-link__icon {
    font-size: v(link-small-icon-size);
  }
}

:host.nx-link--large ::ng-deep {
  .c-icon,
  nx-icon.nx-link__icon {
    font-size: v(link-large-icon-size);
  }
}

// disabled
:host::ng-deep a[disabled],
:host::ng-deep a[aria-disabled] {
  cursor: not-allowed;

  &:focus {
    outline: none;
    box-shadow: none;
  }
}

@media screen and (forced-colors: active) {
  :host {
    color: LinkText !important;
  }
}

@media screen and (forced-colors: active) {
  :host::ng-deep a[disabled],
  :host::ng-deep a[aria-disabled] {
    color: GrayText !important;
  }
}
