@import "../../themes/native/native.globals";
@import "./select.common";
@import "./select.vars";

// Select: Native
// --------------------------------------------------

:host {
  --placeholder-opacity: #{$placeholder-opacity};

  min-height: 44px;

  font-family: $font-family-base;

  z-index: $z-index-item-input;
}

// Select Used in ion-item
// --------------------------------------------------

:host(.has-focus) button {
  border: 2px solid #5e9ed6;
}

// Select Icon
// --------------------------------------------------

.select-icon {
  @include margin(0, 0, 0, $select-icon-margin-start);

  position: relative;
}

/**
 * The select icon should be centered with
 * the entire container not just the control
 * with floating/stacked labels.
 */
:host(.select-label-placement-stacked) .select-icon,
:host(.select-label-placement-floating) .select-icon {
  position: absolute;

  height: 100%;
}

// Select Wrapper
// --------------------------------------------------

.select-wrapper {
  @include padding(var(--padding-top), var(--padding-end), var(--padding-bottom), var(--padding-start));
  @include border-radius(var(--border-radius));
}

.select-wrapper .select-placeholder {
  /**
   * When the floating label appears on top of the
   * select, we need to fade the text out so that the
   * label does not overlap with the placeholder.
   */
  transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

// Select Bottom Content
// ----------------------------------------------------------------

.select-bottom {
  /**
   * The bottom content should take on the start and end
   * padding so it is always aligned with either the label
   * or the start of the text select.
   */
  @include padding(5px, var(--padding-end), 0, var(--padding-start));

  font-size: dynamic-font(12px);
}

// Select Hint Text
// ----------------------------------------------------------------

.select-bottom .helper-text {
  color: $text-color-step-300;
}

// Select Text
// --------------------------------------------------

.select-text {
  min-width: 16px;
}

// Select Label
// ----------------------------------------------------------------

.label-text-wrapper {
  /**
   * Label text should not extend
   * beyond the bounds of the select.
   * However, we do not set the max
   * width to 100% because then
   * only the label would show and users
   * would not be able to see what they are typing.
   */
  max-width: 200px;

  transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1), transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

// Select Label Placement - Start
// ----------------------------------------------------------------

:host(.select-label-placement-start) .label-text-wrapper {
  /**
   * The margin between the label and
   * the select should be on the end
   * when the label sits at the start.
   */
  @include margin(0, $form-control-label-margin, 0, 0);
}

// Select Label Placement - End
// ----------------------------------------------------------------
/**
 * The margin between the label and
 * the select should be on the start
 * when the label sits at the end.
 */
:host(.select-label-placement-end) .label-text-wrapper {
  @include margin(0, 0, 0, $form-control-label-margin);
}

// Select Label Placement - Fixed
// ----------------------------------------------------------------

:host(.select-label-placement-fixed) .label-text-wrapper {
  /**
   * The margin between the label and
   * the select should be on the end
   * when the label sits at the start.
   */
  @include margin(0, $form-control-label-margin, 0, 0);
  /**
  * Label is on the left of the select in LTR and
  * on the right in RTL. Label also has a fixed width.
  */
  flex: 0 0 100px;

  width: 100px;
  min-width: 100px;
  max-width: 200px;
}

// Select Label Placement - Stacked and Floating
// ----------------------------------------------------------------

/**
 * Ensures the select does not
 * overlap the label.
 * Also ensure that the native wrapper
 * takes up the remaining available height and width.
 */
:host(.select-label-placement-stacked) .native-wrapper,
:host(.select-label-placement-floating) .native-wrapper {
  @include margin(1px, 0, 0, 0);
}

/**
 * This makes the label sit over the select
 * when the select is blurred and has no value.
 * The label should not sit over the select if the
 * select has a placeholder.
 * Note: This is different from what ion-input does
 * because the activating the select causes an overlay
 * to appear. This makes it hard to read the placeholder.
 * With ion-input, the input just focuses and the placeholder
 * is still easy to read.
 */
:host(.select-label-placement-floating) .label-text-wrapper {
  @include transform(translateY(100%), scale(1));
}

/**
 * This makes the label sit above the input.
 */
:host(.label-floating) .label-text-wrapper {
  @include transform(translateY(50%), scale(#{$form-control-label-stacked-scale}));

  /**
   * Label text should not extend
   * beyond the bounds of the input.
   */
  max-width: calc(100% / #{$form-control-label-stacked-scale});
}

/**
 * Since the label sits on top of the element,
 * the component needs to be taller otherwise the
 * label will appear too close to the select text.
 */
:host(.select-label-placement-floating),
:host(.select-label-placement-stacked) {
  min-height: 56px;
}

/**
 * When using a stacked/floating label, the inner wrapper is
 * stacked vertically under the label container. This line
 * ensures that the inner wrapper fills all the remaining height
 * of the component.
 */
:host(.select-label-placement-stacked) .select-wrapper-inner,
:host(.select-label-placement-floating) .select-wrapper-inner {
  flex-grow: 1;
}

// Start/End Slots
// ----------------------------------------------------------------

::slotted([slot="start"]:last-of-type) {
  margin-inline-end: $form-control-label-margin;
}

::slotted([slot="end"]:first-of-type) {
  margin-inline-start: $form-control-label-margin;
}

// Select Native Wrapper
// ----------------------------------------------------------------

.native-wrapper {
  /**
   * When the floating label appears on top of the
   * input, we need to fade the input out so that the
   * label does not overlap with the placeholder.
   */
  transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
