@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}-drawer";

$default-width: 360px;


.#{$component} {
display: flex;
flex-direction: column;
position: relative;
height: 100%;
z-index: 1200;
pointer-events: none;

&--open {
pointer-events: auto;

.#{$component}__sheet {
transform: translateX(0);
visibility: visible;
transition: m.spring(transform, default-spatial);
}

.#{$component}__scrim {
pointer-events: auto;
}

.#{$component}__scrim--visible {
opacity: 1;
transition: m.spring(opacity, default-spatial);
}
}


&--start {
.#{$component}__sheet {
left: 0;
right: auto;
border-top-right-radius: v.shape('large');
border-bottom-right-radius: v.shape('large');
border-top-left-radius: 0;
border-bottom-left-radius: 0;
transform: translateX(-100%);
}

@include m.rtl {
.#{$component}__sheet {
left: auto;
right: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: v.shape('large');
border-bottom-left-radius: v.shape('large');
transform: translateX(100%);
}
}

&.#{$component}--open {
.#{$component}__sheet {
transform: translateX(0);
}
}
}

&--end {
.#{$component}__sheet {
left: auto;
right: 0;
border-top-left-radius: v.shape('large');
border-bottom-left-radius: v.shape('large');
border-top-right-radius: 0;
border-bottom-right-radius: 0;
transform: translateX(100%);
}

@include m.rtl {
.#{$component}__sheet {
left: 0;
right: auto;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-top-right-radius: v.shape('large');
border-bottom-right-radius: v.shape('large');
transform: translateX(-100%);
}
}

&.#{$component}--open {
.#{$component}__sheet {
transform: translateX(0);
}
}
}


&--standard {
position: relative;
z-index: auto;
pointer-events: auto;
flex-shrink: 0;
overflow: hidden;
width: 0;
transition: m.spring(width, fast-effects);

.#{$component}__sheet {
position: relative;
background-color: t.color("surface");
@include m.elevation(0);
min-width: 100%;
}

&.#{$component}--start .#{$component}__sheet {
align-self: flex-end;
}

&.#{$component}--end .#{$component}__sheet {
align-self: flex-start;
}

&.#{$component} .#{$component}__sheet,
&.#{$component}--open .#{$component}__sheet {
transform: none;
}

&.#{$component}--open {
width: var(--#{base.$prefix}-drawer-width, $default-width);
transition: m.spring(width, default-spatial);
}

&.#{$component}--start {
.#{$component}__sheet {
border-right: 1px solid t.color("outline-variant");
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

@include m.rtl {
.#{$component}__sheet {
border-right: none;
border-left: 1px solid t.color("outline-variant");
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
}
}

&.#{$component}--end {
.#{$component}__sheet {
border-left: 1px solid t.color("outline-variant");
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

@include m.rtl {
.#{$component}__sheet {
border-left: none;
border-right: 1px solid t.color("outline-variant");
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}
}
}


&--modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1200;

.#{$component}__sheet {
position: absolute;
top: 0;
bottom: 0;
background-color: t.color("surface-container-low");
@include m.elevation(1);
}

&.#{$component}--start .#{$component}__sheet {
box-shadow: f.get-elevation(1), (-1 * m.$sheet-overshoot-guard) 0 0 0 t.color("surface-container-low");
}

&.#{$component}--end .#{$component}__sheet {
box-shadow: f.get-elevation(1), m.$sheet-overshoot-guard 0 0 0 t.color("surface-container-low");
}

@include m.rtl {
&.#{$component}--start .#{$component}__sheet {
box-shadow: f.get-elevation(1), m.$sheet-overshoot-guard 0 0 0 t.color("surface-container-low");
}

&.#{$component}--end .#{$component}__sheet {
box-shadow: f.get-elevation(1), (-1 * m.$sheet-overshoot-guard) 0 0 0 t.color("surface-container-low");
}
}
}


&__sheet {
display: flex;
flex-direction: column;
width: var(--#{base.$prefix}-drawer-width, $default-width);
max-width: calc(100vw - 56px);
height: 100%;
overflow-y: auto;
overflow-x: hidden;
box-sizing: border-box;
padding: 12px 0;
transition: m.spring(transform, fast-effects);

scrollbar-width: thin;
scrollbar-color: t.color("outline-variant") transparent;
}


&__scrim {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: t.alpha("scrim", 0.32);
opacity: 0;
pointer-events: none;
z-index: -1;
transition: m.spring(opacity, fast-effects);
}


&__headline {
@include m.typography("title-small");
color: t.color("on-surface-variant");
padding: 16px 28px 0;
margin-bottom: 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}


&__items {
display: flex;
flex-direction: column;
flex: 1;
padding: 0;
margin: 0;
}


&__item {
display: flex;
align-items: center;
position: relative;
width: calc(100% - 24px);
min-height: f.density(56px, 36px);
flex-shrink: 0;
height: f.density(56px, 36px);
margin: 0 12px;
padding: 0 24px 0 16px;
gap: 12px;
border: none;
border-radius: v.shape('full');
background: none;
cursor: pointer;
color: t.color("on-surface-variant");
text-decoration: none;
box-sizing: border-box;
outline: none;
overflow: visible;
isolation: isolate;
-webkit-tap-highlight-color: transparent;
@include m.typography("label-large");
transition: color v.motion("spring-default-effects-duration")
v.motion("spring-default-effects-easing");

.#{$component}__active-indicator {
position: absolute;
inset: 0;
border-radius: inherit;
overflow: hidden;
pointer-events: none;
z-index: 0;

&::before {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
background-color: t.color("secondary-container");
opacity: 0;
transform: scaleX(0.32);
transform-origin: center;
transition:
transform v.motion("spring-default-spatial-duration")
v.motion("spring-default-spatial-easing"),
opacity v.motion("spring-default-spatial-duration")
v.motion("spring-default-effects-easing");
}

&::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
background-color: currentColor;
opacity: 0;
transition: opacity v.motion("spring-default-effects-duration")
v.motion("spring-default-effects-easing");
}
}

&::after {
content: "";
position: absolute;
left: 0;
right: 0;
top: 50%;
height: 48px;
transform: translateY(-50%);
}

.#{base.$prefix}-ripple {
z-index: 1;
}


&:hover:not(:is([disabled], [aria-disabled="true"])) {
color: t.color("on-surface");

.#{$component}__active-indicator::after {
opacity: v.state("hover-state-layer-opacity");
}
}

&:focus-visible {
color: t.color("on-surface");
outline: 3px solid t.color("secondary");
outline-offset: 2px;
z-index: 1;

.#{$component}__active-indicator::after {
opacity: v.state("focus-state-layer-opacity");
}
}

&:active:not(:is([disabled], [aria-disabled="true"])) {
color: t.color("on-surface");

&:not(:has(> .#{base.$prefix}-ripple))
.#{$component}__active-indicator::after {
opacity: v.state("pressed-state-layer-opacity");
}
}


&--active,
&--active:hover:not(:is([disabled], [aria-disabled="true"])),
&--active:focus-visible,
&--active:active:not(:is([disabled], [aria-disabled="true"])),
&--has-active:not(.#{$component}__item--expanded) {
color: t.color("on-secondary-container");
}

&--active,
&--has-active:not(.#{$component}__item--expanded) {
.#{$component}__active-indicator::before {
opacity: 1;
transform: scaleX(1);
transition:
transform v.motion("spring-default-spatial-duration")
v.motion("spring-default-spatial-easing"),
opacity v.motion("spring-default-effects-duration")
v.motion("spring-default-effects-easing");
}

.#{$component}__item-label {
font-weight: 700;
}
}


&:is([disabled], [aria-disabled="true"]) {
cursor: default;
opacity: 0.38;
pointer-events: none;
}
}

&__group,
&__group-items-inner {
display: flex;
flex-direction: column;
}

&__group-items {
display: grid;
grid-template-rows: 0fr;
visibility: hidden;
transition:
m.spring(grid-template-rows, default-spatial),
visibility 0s linear v.motion("spring-default-spatial-duration");
}

&__group--expanded > &__group-items {
grid-template-rows: 1fr;
visibility: visible;
transition: m.spring(grid-template-rows, default-spatial), visibility 0s;
}

&__group-items-inner {
min-height: 0;
overflow: hidden;
}

&__item--child {
padding-inline-start: calc(16px + var(--#{base.$prefix}-drawer-child-indent, 28px));
padding-inline-end: 24px;
}

&__item-chevron {
display: grid;
place-items: center;
position: relative;
z-index: 2;
flex: none;
width: 24px;
height: 24px;
margin-inline-start: auto;
transform: rotate(0deg);
transition: m.spring(transform, fast-spatial);

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

&__item--expanded &__item-chevron {
transform: rotate(180deg);
}

&__item-badge + &__item-chevron {
margin-inline-start: 0;
}


&__item-icon {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 24px;
height: 24px;
color: inherit;
position: relative;
z-index: 2;

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


&__item-label {
flex: 1;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
position: relative;
z-index: 2;
color: inherit;

@include m.rtl {
text-align: right;
}
}


&__item-badge {
@include m.typography("label-large");
color: t.color("on-surface-variant");
margin-left: auto;
position: relative;
z-index: 2;
flex-shrink: 0;

@include m.rtl {
margin-left: 0;
margin-right: auto;
}
}


&__divider {
width: calc(100% - 56px);
height: 1px;
margin: 8px 28px;
border: none;
background-color: t.color("outline-variant");
}


&__section-label {
@include m.typography("title-small");
color: t.color("on-surface-variant");
padding: 18px 28px 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}


&--dense {
--#{base.$prefix}-density: -5;
}


@include m.rtl-selector('.#{$component}__item') {
padding: 0 16px 0 24px;
}

@include m.rtl-selector('.#{$component}__item--child') {
padding: 0 calc(16px + var(--#{base.$prefix}-drawer-child-indent, 28px)) 0 24px;
}


@include m.reduced-motion {
&--standard,
&--standard.#{$component}--open {
transition: none;
}

&__sheet,
&--open .#{$component}__sheet {
transition: none;
}

&__scrim,
&--open .#{$component}__scrim--visible {
transition: none;
}

&__item,
&__item-chevron,
&__group-items,
&__group--expanded > &__group-items,
&__item::before,
&__active-indicator,
&__item &__active-indicator::before,
&__item &__active-indicator::after {
transition: none;
}
}


@include m.high-contrast {
&__sheet {
border: 1px solid currentColor;
}

&__item {
&--active,
&--has-active:not(.#{$component}__item--expanded) {
.#{$component}__active-indicator {
outline: 2px solid Highlight;
outline-offset: -2px;
}
}

&:focus-visible {
outline: 3px solid CanvasText;
outline-offset: 2px;
}
}

&__divider {
background-color: currentColor;
}
}
}


dialog.#{$component} {
width: auto;
height: auto;
max-width: none;
max-height: none;
margin: 0;
padding: 0;
border: 0;
overflow: visible;
background: transparent;
color: inherit;
transition: overlay m.spring-duration(fast-effects) allow-discrete;

&::backdrop {
background-color: t.alpha("scrim", 0.32);
opacity: 0;
transition: m.spring(opacity, fast-effects);
}

&.#{$component}--open::backdrop {
opacity: 1;
transition: m.spring(opacity, default-spatial);
}

@include m.reduced-motion {
&,
&::backdrop {
transition: none;
}
}
}
