@use 'spacing' as *;
@use 'semanticColors' as *;
@use '../icon/Icon.module.scss' as *;
@use 'surfaces' as *;

$icon-overall-size: 1.5em;
$input-icon-margin: 0.25em;

.iconInput {
  position: relative;
  display: flex;
  align-items: center;

  // No actual border drawn. This provides the mask for the rounded corners to clip child elements
  border-radius: $button-radius;
  overflow: hidden;

  z-index: 0;

  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;

    border: 1px solid $control-border-color;
    border-radius: $button-radius;

    pointer-events: none;
  }

  .wrapper {
    display: flex;
    flex-grow: 1;

    &:first-child {
      // If first child, apply border padding
      padding-left: spacing(s);
    }

    &:last-child {
      // If last child, apply border padding
      padding-right: spacing(s);
    }
  }

  .input {
    flex-grow: 1;
    // Required to allow input to shrink in certain size scenarios
    width: 0;
    padding: 0;

    background-color: transparent;
    border: 0;
    border-radius: 0;

    &:focus {
      outline: none;
    }
  }

  .icon {
    flex-grow: 0;
    flex-shrink: 0;

    // Icon 
    margin: 0 $input-icon-margin;
    bottom: 0;

    color: $control-text-color-black;
  }

  .iconButton {
    // See global expression below
    // Make sure button fills entire height, to enable the button focus ring to cover the IconInput border
    align-self: stretch;

    padding: 0 $input-icon-margin;
    line-height: 1;

    border-radius: 0;

    &::after {
      z-index: 1;
    }
  }
}

:global {
  :local(.iconButton) {
    &.focused {
      // Set overflow and border radius to clip corners when focused
      overflow: hidden;
  
      border-radius: $button-radius;
    }  
  }
}
