/*
 * Copyright (c) 2019-present Sonatype, Inc.
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which accompanies this
 * distribution and is available at https://www.eclipse.org/legal/epl-2.0/.
 */
@use 'sass:math';
@use '../../scss-shared/nx-text-helpers';
@use '../../scss-shared/nx-container-helpers';
@use '../../scss-shared/nx-button-helpers';

.nx-file-upload {
  position: relative; // correctly position validation error when scrolling
  margin-bottom: var(--nx-spacing-8x);

  &__input {
    @include nx-text-helpers.visually-hidden;

    // focus styles must be reimplemented because it isn't the actual button that gets focus, it's the input
    &:focus + .nx-btn {
      @include nx-button-helpers.bordered-btn-focus-outline("tertiary");
    }
  }

  > .nx-btn {
    // container-horizontal doesn't work here because the input is the first child
    margin-left: 0;
    margin-right: var(--nx-spacing-4x);
  }

  &__no-file-message {
    > .nx-icon {
      display: none;
    }

    &--invalid {
      color: var(--nx-color-validation-invalid-message);

      > .nx-icon {
        color: var(--nx-color-validation-invalid-icon);
        display: inline;
      }
    }

    &.hidden {
      display: none;
    }

    @include nx-container-helpers.container-horizontal;
  }

  @include nx-container-helpers.container-horizontal;
}

.nx-selected-file {
  $height: 36px;

  align-items: center;
  background-color: var(--nx-color-file-upload-selected-background);
  border: var(--nx-border-width-alt) solid var(--nx-color-file-upload-selected-border);
  border-radius: math.div($height, 2);
  box-sizing: border-box;
  display: inline-flex;

  // Deliberately non-standard, Design says standard sizes don't look right with the rounded borders here
  padding-left: 20px;
  height: $height;
  width: 300px;

  &__info {
    align-items: center;
    display: inline-flex;
    flex: 0 1 auto;
    min-width: 0;
  }

  &__name {
    @include nx-text-helpers.truncate-ellipsis;

    color: var(--nx-color-file-upload-selected-text);
    flex: 0 1 auto;
    font-weight: bold;
    margin-right: var(--nx-spacing-3x);
  }

  &__size {
    font-size: var(--nx-font-size-xs);
    margin-right: var(--nx-spacing-4x);
    min-width: max-content;
  }

  &__dismiss-btn {
    align-items: center;
    background: transparent;
    border-color: transparent;
    border-style: inherit;
    border-width: inherit;
    border-radius: inherit;
    border: none;
    color: var(--nx-color-file-upload-selected-dismiss-text);
    cursor: pointer;
    display: inline-flex;
    font-size: var(--nx-font-size);
    height: inherit;
    margin-left: auto;

    // "outline" to overlap with parent border
    margin-right: calc(0px - var(--nx-border-width-alt));
    padding: 0 var(--nx-spacing-3x);

    &:hover {
      box-shadow: inset 0 0 0 var(--nx-border-width-alt) var(--nx-color-file-upload-selected-dismiss-border-hover);
    }

    &:hover {
      background-color: var(--nx-color-file-upload-selected-dismiss-background-hover);
    }

    &:focus,
    &:hover:focus {
      outline: none;
      box-shadow: inset 0 0 0 var(--nx-focus-outline-width) var(--nx-color-interactive-border-focus);
    }

    &:active,
    &:active:focus {
      box-shadow: inset 0 0 0 var(--nx-border-width-alt)
          var(--nx-color-file-upload-selected-border);
      background-color: var(--nx-color-file-upload-selected-dismiss-background-active);
    }

    @include nx-container-helpers.container-horizontal;
  }
}
