@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/direction' as d;
@use '../../styles/abstract/theme' as t;

$component: '#{base.$prefix}-fab-menu';
$fab: '#{base.$prefix}-fab';
$spatial: v.motion('spring-fast-spatial-duration') v.motion('spring-fast-spatial-easing');
$spatial-colour: v.motion('spring-fast-spatial-duration') v.motion('spring-fast-spatial-clamped-easing');
$effects: v.motion('spring-fast-effects-duration') v.motion('spring-fast-effects-easing');
$swap: v.spring-delay-scale('spring-fast-spatial-duration', 48ms);

.#{$component} {
position: relative;
display: inline-block;
width: 56px;
height: 56px;
vertical-align: middle;

&--medium {
width: 80px;
height: 80px;
}

&--large {
width: 96px;
height: 96px;
}

@each $role in primary, secondary, tertiary {
&--#{$role} {
--#{$component}-close: #{t.color($role)};
--#{$component}-on-close: #{t.color('on-#{$role}')};
--#{$component}-item: #{t.color('#{$role}-container')};
--#{$component}-on-item: #{t.color('on-#{$role}-container')};
}
}

&--bottom-end,
&--bottom-start {
--#{$component}-margin: 16px;
position: absolute;
bottom: var(--#{$component}-margin);
z-index: f.get-z-index('fixed');

@media (min-width: 1200px) {
--#{$component}-margin: 24px;
}
}

&--bottom-end {
@include d.end(var(--#{$component}-margin), $self: true);
}

&--bottom-start {
@include d.start(var(--#{$component}-margin), $self: true);

.#{$fab}.#{$component}__fab {
@include d.sides(0, auto);
}

.#{$component}__list {
@include d.sides(0, auto);
align-items: flex-start;
}

.#{$component}__item {
justify-content: flex-start;
}
}

@at-root .#{$fab}.#{$component}__fab {
position: absolute;
inset-block-start: 0;
@include d.end(0);
display: grid;
place-items: center;
transition:
width $spatial,
height $spatial,
border-radius $spatial,
background-color $spatial-colour,
color $spatial-colour,
box-shadow $spatial;


> *:not(.#{base.$prefix}-ripple) {
grid-area: 1 / 1;
}

.#{$fab}__icon,
.#{$component}__close {
transition: visibility 0s linear $swap;
}
}

&__close {
display: inline-flex;
width: 20px;
height: 20px;
visibility: hidden;

svg {
width: 20px;
height: 20px;
fill: currentColor;
}
}

&--list.#{$component}--open .#{$component}__fab {
width: 56px;
height: 56px;
border-radius: 28px;
background-color: var(--#{$component}-close);
color: var(--#{$component}-on-close);

.#{$fab}__icon {
visibility: hidden;
}

.#{$component}__close {
visibility: visible;
}
}

&__list {
position: absolute;
bottom: calc(100% + 8px);
@include d.end(0);
translate: var(--#{$component}-shift, 0px) 0;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
overflow-y: auto;
visibility: hidden;
transition: visibility 0s linear var(--#{$component}-exit, 0ms);

}

&--bottom-start {
@include d.arms-self-only {
.#{$fab}.#{$component}__fab {
right: 0;
left: auto;
}

.#{$component}__list {
right: 0;
left: auto;
}
}
}

&--list-down .#{$component}__list {
top: calc(100% + 8px);
bottom: auto;
}

&--list-start {
.#{$component}__list {
@include d.sides(0, auto);
align-items: flex-start;
}

.#{$component}__item {
justify-content: flex-start;
}
}

&--list-start {
@include d.arms-self-only {
.#{$component}__list {
right: 0;
left: auto;
}
}
}

&--menu .#{$component}__list {
display: none;
}

&--open .#{$component}__list {
visibility: visible;
transition-delay: 0s;
}

&__item {
position: relative;
display: inline-flex;
flex-shrink: 0;
justify-content: flex-end;
box-sizing: border-box;
width: 0;
height: 56px;
padding: 0;
border: none;
border-radius: v.shape('full');
background-color: var(--#{$component}-item);
color: var(--#{$component}-on-item);
@include m.typography('title-medium');
white-space: nowrap;
cursor: pointer;
overflow: hidden;
opacity: 0;
min-width: 0;
transition:
opacity $effects,
width $spatial;
transition-delay: var(--#{$component}-delay, 0ms);
}

button.#{$component}__item {
gap: 0;
height: 56px;
padding: 0;
border: none;
border-radius: v.shape('full');
background-color: var(--#{$component}-item);
color: var(--#{$component}-on-item);
box-shadow: none;
@include m.typography('title-medium');

&:hover,
&:focus-visible,
&:active {
background-color: var(--#{$component}-item);
box-shadow: none;
}

&:active {
border-radius: v.shape('full');
}

&:focus-visible {
outline: 3px solid t.color('secondary');
outline-offset: -3px;
}
}

&__item-content {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
gap: 8px;
box-sizing: border-box;
min-width: 56px;
height: 100%;
padding: 0 24px;
}

&--open .#{$component}__item {
opacity: 1;
width: var(--#{$component}-item-width, auto);
}

&__item-icon {
display: inline-flex;
width: 24px;
height: 24px;

svg {
width: 24px;
height: 24px;
fill: currentColor;
}
}

@include m.reduced-motion {
@at-root .#{$fab}.#{$component}__fab {
transition: background-color $effects, color $effects;
}

&__item {
transition: opacity $effects;
}
}
}
