@use "../../wc";
@use "../../form-control";

:host {
  display: block;
}

.input__control {
  /**
   * Visually hide the input type=file without display:none
   * This is necessary for accessibility reasons and so the native html input validation popup
   * is shown.
   */
  border: 0;
  clip-path: inset(50%);
  height: 1px;
  margin: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.form-control--droparea .input__control {
  /* move the input into the center, so the native validation popup is centered to the droparea */
  left: 50%;
}

.form-control-input {
  /* needed, so the native validation popup is centered correctly */
  position: relative;
}

/* Regular Input with button only */
.button__wrapper {
  align-items: center;
  display: flex;
  gap: var(--zn-input-spacing-medium);
}

.form-control--small .button__wrapper {
  gap: var(--zn-input-spacing-small);
}

:host([size="large"]) .button__wrapper {
  gap: var(--zn-input-spacing-large);
}

/**
 * The value of the chosen file(s) or the placeholder text
 */
.input__value {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: var(--zn-spacing-small);
  color: var(--zn-input-color);
  font-size: var(--zn-input-label-font-size-medium);
}

.input__value.input__value--hidden {
  display: none;
}

.input__delete {
  cursor: pointer;
  color: var(--zn-input-color);
  font-size: var(--zn-input-label-font-size-medium);

  &:hover {
    color: var(--zn-color-primary-600);
  }
}

.input__value--placeholder {
  color: var(--zn-input-help-text-color);
}

.form-control--small .input__value {
  font-size: var(--zn-input-label-font-size-small);
}

.form-control--large .input__value {
  font-size: var(--zn-input-label-font-size-large);
}

/**
 * Special case for regular inputs:
 * When the user uses drag and drop, highlight the button with the primary color
 */
.form-control--user-dragging:not([disabled]) .button::part(base) {
  background: none;
  border-color: var(--zn-color-primary-900);
  color: var(--zn-color-primary-900);
}

/* Drop Area */
.droparea {
  --highlight-color: var(--zn-color-primary-600);

  border: 2px dashed var(--zn-input-border-color);
  font: var(--zn-font-size-medium);
  padding: var(--zn-spacing-x-large) var(--zn-spacing-large);
  transition: var(--zn-transition-medium) background,
  var(--zn-transition-medium) border-color;
}

.droparea:focus-visible {
  border: 2px dashed var(--zn-color-primary-600);
  outline: var(--zn-focus-ring);
  outline-offset: var(--zn-focus-ring-offset);
}

/* Adjust the highlight to match an inactive item */
:host([disabled]) .droparea {
  --highlight-color: var(--zn-color-neutral-600);
}

:host([disabled]) .input__value {
  display: none;
}

.droparea__background {
  align-items: center;
  display: flex;
  gap: var(--zn-spacing-x-small);
  padding: var(--zn-spacing-x-small) var(--zn-spacing-medium);
}

.droparea__icon {
  align-items: center;
  color: var(--highlight-color);
  display: flex;
  font-size: var(--zn-spacing-3x-large);
}

.file-wrapper {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.droparea__text {
  display: flex;
  flex-direction: column;
  gap: var(--zn-spacing-3x-small);
  margin: 0;
}

.droparea__text strong {
  color: var(--highlight-color);
  font-weight: var(--zn-font-weight-bold);
}

/* Sizes */
/* stylelint-disable-next-line no-descending-specificity */
.form-control--small .droparea {
  font: var(--zn-font-size-small);
}

.form-control--small .droparea__icon {
  font-size: var(--zn-spacing-2x-large)
}

/* stylelint-disable-next-line no-descending-specificity */
.form-control--large .droparea {
  font: var(--zn-font-size-large);
}

.form-control--large .droparea__icon {
  font-size: var(--zn-spacing-4x-large)
}

/* Disabled Styles */
:host([disabled]) .droparea,
:host([disabled]) .input__value {
  cursor: not-allowed;
  opacity: 0.5;
}

:host(:not([disabled])) .form-control--user-dragging .droparea {
  background: var(--zn-color-primary-50);
  border: 2px solid var(--zn-color-primary-600);
  cursor: pointer;
}

:host(:not([disabled])) .droparea:not(:focus-visible):hover {
  --highlight-color: var(--zn-color-primary-800);

  border: 2px dashed var(--zn-color-primary-700);
  background-color: var(--zn-color-primary-50);
  cursor: pointer;
}

/* Validation */
/* stylelint-disable-next-line no-descending-specificity */
:host([data-user-invalid]:not([disabled])) .droparea {
  border: 2px dashed var(--zn-color-error);
}
