@import "../../themes/mixins";

// Radio
// --------------------------------------------------

:host {
  /**
   * @prop --color: Color of the radio
   * @prop --color-checked: Color of the checked radio
   * @prop --border-radius: Border radius of the radio
   * @prop --inner-border-radius: Border radius of the inner checked radio
   */
  --inner-border-radius: 50%;

  display: inline-block;
  position: relative;

  max-width: 100%;

  min-height: inherit;

  cursor: pointer;

  user-select: none;

  box-sizing: border-box;
}

input {
  @include visually-hidden();
}

:host(.radio-disabled) {
  pointer-events: none;
}

.radio-icon {
  display: flex;

  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;

  contain: layout size style;
}

.radio-icon,
.radio-inner {
  box-sizing: border-box;
}

:host(:focus) {
  outline: none;
}

:host(.in-item) {
  flex: 1 1 0;

  width: 100%;
  height: 100%;
}

/**
 * Radio can be slotted
 * in components such as item and
 * toolbar which is why we do not
 * limit the below behavior to just ion-item.
 */
:host([slot="start"]),
:host([slot="end"]) {
  // Reset the flex property when the radio
  // is slotted to avoid growing the element larger
  // than its content.
  flex: initial;

  width: auto;
}

// Radio Wrapper
// --------------------------------------------------
.radio-wrapper {
  display: flex;

  position: relative;

  flex-grow: 1;

  align-items: center;
  justify-content: space-between;

  height: inherit;

  min-height: inherit;

  cursor: inherit;
}

/**
 * If no label text is placed into the slot
 * then the element should be hidden otherwise
 * there will be additional margins added.
 */
.label-text-wrapper-hidden {
  display: none;
}

// Radio Native Wrapper
// ----------------------------------------------------------------

.native-wrapper {
  display: flex;

  align-items: center;
}

// Radio Justify
// --------------------------------------------------

:host(.radio-justify-space-between) .radio-wrapper {
  justify-content: space-between;
}

:host(.radio-justify-start) .radio-wrapper {
  justify-content: start;
}

:host(.radio-justify-end) .radio-wrapper {
  justify-content: end;
}

// Radio Align
// --------------------------------------------------

:host(.radio-alignment-start) .radio-wrapper {
  align-items: start;
}

:host(.radio-alignment-center) .radio-wrapper {
  align-items: center;
}

// Justify Content & Align Items
// ---------------------------------------------

// The radio should be displayed as block when either justify
// or alignment is set; otherwise, these properties will have no
// visible effect.
:host(.radio-justify-space-between),
:host(.radio-justify-start),
:host(.radio-justify-end),
:host(.radio-alignment-start),
:host(.radio-alignment-center) {
  display: block;
}

// Radio Label
// ----------------------------------------------------------------

.label-text-wrapper {
  text-overflow: ellipsis;

  white-space: nowrap;

  overflow: hidden;
}

// Radio Label Placement - Start
// ----------------------------------------------------------------

/**
 * Label is on the left of the radio in LTR and
 * on the right in RTL.
 */
:host(.radio-label-placement-start) .radio-wrapper {
  flex-direction: row;
}

// Radio Label Placement - End
// ----------------------------------------------------------------

/**
 * Label is on the right of the radio in LTR and
 * on the left in RTL.
 */
:host(.radio-label-placement-end) .radio-wrapper {
  flex-direction: row-reverse;
}

// Radio Label Placement - Fixed
// ----------------------------------------------------------------

/**
 * Label is on the left of the radio in LTR and
 * on the right in RTL. Label also has a fixed width.
 */
:host(.radio-label-placement-fixed) .label-text-wrapper {
  flex: 0 0 100px;

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

// Radio Label Placement - Stacked
// ----------------------------------------------------------------

/**
 * Label is on top of the radio.
 */
:host(.radio-label-placement-stacked) .radio-wrapper {
  flex-direction: column;
}

:host(.radio-label-placement-stacked.radio-alignment-start) .label-text-wrapper {
  @include transform-origin(start, top);
}

:host(.radio-label-placement-stacked.radio-alignment-center) .label-text-wrapper {
  @include transform-origin(center, top);
}
