@use "../abstract/base" as base;
@use "../abstract/functions" as f;
@use "../abstract/variables" as v;
@use "../abstract/mixins" as m;
@use "../abstract/theme" as t;
@use "../abstract/direction" as d;

$component: "#{base.$prefix}-side-sheet";

.#{$component} {
--#{base.$prefix}-density: 0;
position: fixed;
inset: 0;
z-index: v.z-index("modal");
display: flex;
pointer-events: none;

--#{$component}-direction: 1;

@include m.rtl {
--#{$component}-direction: -1;
}

&--open {
pointer-events: auto;
}

&__scrim {
position: absolute;
inset: 0;
background-color: t.alpha("scrim", 0.32);
opacity: 0;
visibility: hidden;
transition:
m.spring(opacity, fast-effects),
visibility 0s linear m.spring-duration(fast-effects);
}

&__container {
position: relative;
height: 100%;
max-width: 400px;
display: flex;
flex-direction: column;
box-sizing: border-box;
pointer-events: auto;
color: t.color("on-surface");
transition: m.spring(transform, fast-effects);

&:focus {
outline: none;
}

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

&__header {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 12px;
padding: 16px 24px;
min-height: 72px;
box-sizing: border-box;
}

&__title {
margin: 0;
flex: 1 1 auto;
min-width: 0;
color: t.color("on-surface");
@include m.typography("title-large");
}

&__close {
font: inherit;
position: relative;
flex: 0 0 auto;
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
margin-inline-end: -8px;
padding: 0;
border: 0;
border-radius: 50%;
background: transparent;
color: t.color("on-surface-variant");
cursor: pointer;

@include m.state-layer(t.color("on-surface-variant"), "hover");

&:active::before {
opacity: v.state("pressed-state-layer-opacity");
}

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

&::after {
content: "";
position: absolute;
width: 48px;
height: 48px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}

&__content {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
padding: 0 24px 24px;
@include m.typography("body-medium");
color: t.color("on-surface-variant");
}

&--standard {
pointer-events: none;

.#{$component}__container {
background-color: t.color("surface");
pointer-events: auto;
}

&.#{$component}--end .#{$component}__container {
box-shadow: calc(m.$sheet-overshoot-guard * var(--#{$component}-direction)) 0 0 0 t.color("surface");
border-inline-start: 1px solid t.color("outline-variant");
}

&.#{$component}--start .#{$component}__container {
box-shadow: calc(-1 * m.$sheet-overshoot-guard * var(--#{$component}-direction)) 0 0 0 t.color("surface");
border-inline-end: 1px solid t.color("outline-variant");
}
}

&--modal {
.#{$component}__container {
background-color: t.color("surface-container-low");
@include m.elevation(1);
}

&.#{$component}--end .#{$component}__container {
box-shadow: f.get-elevation(1), calc(m.$sheet-overshoot-guard * var(--#{$component}-direction)) 0 0 0 t.color("surface-container-low");
@include d.corners($start-start: v.shape("large"), $end-start: v.shape("large"), $arm: false);
}

&.#{$component}--start .#{$component}__container {
box-shadow: f.get-elevation(1), calc(-1 * m.$sheet-overshoot-guard * var(--#{$component}-direction)) 0 0 0 t.color("surface-container-low");
@include d.corners($start-end: v.shape("large"), $end-end: v.shape("large"), $arm: false);
}

&.#{$component}--end {
@include d.arms($self: true) {
.#{$component}__container {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-top-right-radius: v.shape("large");
border-bottom-right-radius: v.shape("large");
}
}
}

&.#{$component}--start {
@include d.arms($self: true) {
.#{$component}__container {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: v.shape("large");
border-bottom-left-radius: v.shape("large");
}
}
}
}

&--end {
justify-content: flex-end;

.#{$component}__container {
transform: translateX(calc(100% * var(--#{$component}-direction)));
}
}

&--start {
justify-content: flex-start;

.#{$component}__container {
transform: translateX(calc(-100% * var(--#{$component}-direction)));
}
}

&--open {
.#{$component}__container {
transform: translateX(0);
transition: m.spring(transform, default-spatial);
}

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

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

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;
}
}
}
