/*
 * Copyright (c) 2016-2025 Broadcom. All Rights Reserved.
 * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
 * This software is released under MIT license.
 * The full license information can be found in LICENSE in the root directory of this project.
 */
@use '../../utils/mixins';
@use 'mixins.forms' as forms-mixins;
@use 'variables.forms' as forms-variables;
@use '../../utils/variables/variables.density' as density;

@use '@cds/core/tokens/tokens.scss';

@include mixins.exports('forms.radio') {
  //Remove the default radio appearance
  %custom-radio {
    @include mixins.clr-appearance-normal();
  }

  // @TODO un-nest the radio inputs when old forms are removed
  .clr-radio-wrapper {
    @include forms-mixins.form-flatten-validate-text();
    position: relative;
    display: flex;
    align-items: flex-start;

    @include forms-mixins.checkbox-radio-toggle-control-group-gap();

    //Hide the default radio
    input[type='radio'] {
      @include forms-mixins.checkbox-radio-input-styles(forms-variables.$clr-forms-radio-size);
      @extend %custom-radio;
      padding: density.$clr-base-vertical-offset-xs 0;

      &:not(:disabled) {
        cursor: pointer;
      }

      //Radio button base
      &::before {
        @include forms-mixins.checkbox-radio-shared-inactive(
          forms-variables.$clr-forms-radio-height,
          forms-variables.$clr-forms-border-color
        );
        border-radius: 50%;
      }

      //Checked Radio Styles
      &:checked {
        &::before {
          border: none;
          box-shadow: forms-variables.$clr-forms-radio-selected-shadow;
        }
        &:disabled::before {
          //background-color around the dot
          box-shadow: forms-variables.$clr-forms-radio-checked-disabled-shadow;
        }
      }

      &:focus {
        outline: none;
        &::before {
          @include mixins.include-outline-style-form-fields(mixins.baselinePx(3));
        }
      }

      &:disabled {
        + label {
          cursor: not-allowed;
          color: forms-variables.$clr-forms-radio-label-disabled-color;
        }
        &::before {
          background-color: forms-variables.$clr-forms-radio-disabled-background-color;
          border-color: tokens.$cds-alias-object-interaction-color-disabled;
        }
      }
    }

    .clr-control-label {
      @include forms-mixins.checkbox-radio-label-styles(
        forms-variables.$clr-forms-radio-label-height,
        forms-variables.$clr-forms-radio-label-color,
        'SECONDARY-13-RG-CPT'
      );
      &:empty {
        padding-left: 0;
      }
    }
  }

  .clr-form-control-disabled .clr-radio-wrapper {
    .clr-control-label {
      cursor: not-allowed;
      color: forms-variables.$clr-forms-radio-label-disabled-color;
    }
  }

  .clr-error .clr-radio-wrapper input[type='radio']::before {
    border-color: forms-variables.$clr-forms-invalid-color;
  }

  .clr-form-compact .clr-radio-wrapper {
    padding-top: 0;

    @include forms-mixins.form-flatten-compact-adjustments();
    @include forms-mixins.form-inline-input();

    .clr-control-label {
      margin-top: 0;
    }
  }
}
