@use '../../styles/abstract/base' as base;
@use '../../styles/abstract/variables' as v;
@use '../../styles/abstract/functions' as f;
@use '../../styles/abstract/mixins' as m;
@use '../../styles/abstract/theme' as t;

$component: '#{base.$prefix}-radios';

.#{$component} {
display: flex;
margin: 0;
padding: 0;

&--vertical {
flex-direction: column;

}

&--horizontal {
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;

.#{$component}__item {
margin-inline-end: 16px;

&:last-child {
margin-inline-end: 0;
}
}
}

&--disabled {
pointer-events: none;
}

&__item {
position: relative;
display: inline-flex;
align-items: center;

&--disabled {
cursor: not-allowed;

.#{$component}__label {
cursor: not-allowed;
}
}
}

&__input {
font: inherit;
position: absolute;
opacity: 0;
height: 0;
width: 0;
margin: 0;
padding: 0;

&:checked ~ .#{$component}__label .#{$component}__circle {
border-color: t.color('primary');

&::after {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
}
}

&:disabled ~ .#{$component}__label {
.#{$component}__circle {
border-color: t.alpha('on-surface', 0.38);

&::after {
background-color: t.alpha('on-surface', 0.38);
}
}

.#{$component}__text {
color: t.alpha('on-surface', 0.38);
}
}
}

&__label {
position: relative;
display: inline-flex;
align-items: center;
cursor: pointer;
padding: 4px 0;
min-height: 48px;
box-sizing: border-box;
color: t.color('on-surface');

@include m.typography('body-large');

&--before {
.#{$component}__text {
margin-inline: 0 8px;
}
}

&:has(> .#{$component}__text:empty) {
min-width: 48px;
justify-content: center;
}
}

&__control {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
flex-shrink: 0;
}

&__circle {
position: relative;
width: 20px;
height: 20px;
border: 2px solid t.color('on-surface-variant');
border-radius: 50%;
box-sizing: border-box;
transition: m.spring(border-color, fast-effects);

&::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
width: 10px;
height: 10px;
border-radius: 50%;
background-color: t.color('primary');
opacity: 0;
transition: m.spring(transform, fast-spatial), m.spring(opacity, fast-effects);
}
}

&__ripple {
position: absolute;
inset: 0;
border-radius: 50%;
transition: m.spring(background-color, fast-effects);
}

&__item {
$input: '.#{$component}__input:not(:disabled)';
$label: '.#{$component}__label';
$ripple: '.#{$component}__ripple';

#{$input}:not(:checked) ~ #{$label}:is(:hover, :active) .#{$component}__circle,
#{$input}:not(:checked):focus-visible ~ #{$label} .#{$component}__circle {
border-color: t.color('on-surface');
}

#{$input} ~ #{$label}:hover #{$ripple} { background-color: t.alpha('on-surface', v.state('hover-state-layer-opacity')); }
#{$input}:focus-visible ~ #{$label} #{$ripple} { background-color: t.alpha('on-surface', v.state('focus-state-layer-opacity')); }
#{$input} ~ #{$label}:active #{$ripple} { background-color: t.alpha('primary', v.state('pressed-state-layer-opacity')); }

#{$input}:checked ~ #{$label}:hover #{$ripple} { background-color: t.alpha('primary', v.state('hover-state-layer-opacity')); }
#{$input}:checked:focus-visible ~ #{$label} #{$ripple} { background-color: t.alpha('primary', v.state('focus-state-layer-opacity')); }
#{$input}:checked ~ #{$label}:active #{$ripple} { background-color: t.alpha('on-surface', v.state('pressed-state-layer-opacity')); }

#{$input}:focus-visible ~ #{$label} #{$ripple} {
outline: 3px solid t.color('secondary');
outline-offset: 2px;
}
}

&__text {
margin-inline-start: 8px;

&:empty {
display: none;
}
}
}
