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

.#{$component}__overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: transparent;
visibility: hidden;
z-index: v.z-index("modal");
display: flex;
align-items: center;
justify-content: center;
overflow: auto;
padding: 24px;
box-sizing: border-box;

&--contained {
position: absolute;
}

transition:
background-color v.motion("duration-short3") linear,
visibility 0s linear v.motion("duration-short3");

&--visible {
background-color: t.alpha("scrim", 0.32);
visibility: visible;
transition: background-color v.motion("duration-long2") linear, visibility 0s;
}
}


.#{$component} {
--#{base.$prefix}-density: 0;
position: relative;
background-color: t.color("surface-container-high");
color: t.color("on-surface");
border-radius: v.shape("extra-large");
max-width: 560px;
min-width: 280px;
width: 100%;
margin: auto;
@include m.elevation(3);

transform-origin: top center;
transform: translateY(-50px) scaleY(0.35);
opacity: 0;
pointer-events: none;
transition:
transform v.motion("duration-short3") v.motion("easing-emphasized-accelerate"),
opacity v.motion("duration-short1") linear v.motion("duration-short2");

.#{$component}__header,
.#{$component}__content,
.#{$component}__footer {
opacity: 0;
transition: opacity v.motion("duration-short2") linear;
}

&--visible {
transform: translateY(0) scaleY(1);
opacity: 1;
pointer-events: auto;
transition:
transform v.motion("duration-long2") v.motion("easing-emphasized"),
opacity v.motion("duration-short1") linear;

.#{$component}__header,
.#{$component}__content {
opacity: 1;
transition: opacity v.motion("duration-medium1") linear v.motion("duration-short1");
}

.#{$component}__footer {
opacity: 1;
transition: opacity v.motion("duration-medium2") linear v.motion("duration-short3");
}
}

&--small {
width: 80%;
max-width: 360px;
}

&--medium {
width: 90%;
max-width: 560px;
}

&--large {
width: 95%;
max-width: 560px;
}

&--fullwidth {
width: 100%;
max-width: none;
margin: 24px;
}

&--fullscreen {
width: 100%;
height: 100%;
max-width: none;
max-height: none;
margin: 0;
border-radius: 0;
transform-origin: center center;
transform: translateY(24px);

&.#{$component}--visible {
transform: translateY(0);
}
}

&--slide-up {
transform: translateY(24px) scaleY(0.35);

&.#{$component}--visible {
transform: translateY(0) scaleY(1);
}
}

&--slide-down {
transform: translateY(-24px) scaleY(0.35);

&.#{$component}--visible {
transform: translateY(0) scaleY(1);
}
}

&--fade {
transform: none;

&.#{$component}--visible {
transform: none;
}
}

&--scale {
transform-origin: center center;
transform: scale(0.8);

&.#{$component}--visible {
transform: scale(1);
}
}
}

dialog.#{$component} {
position: fixed;
inset: 0;
height: fit-content;
max-height: calc(100% - 48px);
padding: 0;
border: 0;
overflow: visible;
transition:
transform v.motion("duration-short3") v.motion("easing-emphasized-accelerate"),
opacity v.motion("duration-short1") linear v.motion("duration-short2"),
display v.motion("duration-short3") allow-discrete,
overlay v.motion("duration-short3") allow-discrete;

&.#{$component}--visible {
transform: none;
transition:
transform v.motion("duration-long2") v.motion("easing-emphasized"),
opacity v.motion("duration-short1") linear;
}

&.#{$component}--fullwidth {
width: auto;
}

&.#{$component}--fullscreen {
height: 100%;
max-height: none;
}

&::backdrop {
background-color: transparent;
transition:
background-color v.motion("duration-short3") linear,
display v.motion("duration-short3") allow-discrete,
overlay v.motion("duration-short3") allow-discrete;
}

&.#{$component}--visible::backdrop {
background-color: t.alpha("scrim", 0.32);
transition: background-color v.motion("duration-long2") linear;
}
}

.#{$component}__header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding: 24px 24px 16px 24px;

&-content {
flex: 1;
}

&-title {
margin: 0;
color: t.color("on-surface");
@include m.typography("headline-small");
}

&-subtitle {
margin: 4px 0 0 0;
@include m.typography("body-medium");
color: t.color("on-surface-variant");
}

&-close {
font: inherit;
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
margin: -8px -8px 0 0;
padding: 8px;
background: transparent;
border: none;
border-radius: 50%;
cursor: pointer;
color: t.color("on-surface-variant");
transition: background-color v.motion("duration-short2")
v.motion("easing-standard");

&:hover {
background-color: t.alpha("on-surface", 0.08);
}

&:focus {
outline: none;
}

&:focus-visible {
outline: 2px solid t.color("primary");
outline-offset: 2px;
background-color: t.alpha("on-surface", v.state("focus-state-layer-opacity"));
}

&:active {
background-color: t.alpha("on-surface", v.state("pressed-state-layer-opacity"));
}

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

position: relative;

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

@include m.rtl-selector('.#{$component}__header-close') {
margin: -8px 0 0 -8px;
}
}

.#{$component}__header:empty {
display: none;
}

.#{$component}__header:not(:has(*)) + .#{$component}__content,
.#{$component} > .#{$component}__content:first-child {
padding-top: 24px;
}

.#{$component}__content {
padding: 0 24px;
color: t.color("on-surface-variant");
@include m.typography("body-medium");

overflow: visible;

p {
margin: 0 0 16px 0;

&:last-child {
margin-bottom: 0;
}
}

&:last-child {
padding-bottom: 24px;
}
}

.#{$component}__footer {
display: flex;
align-items: center;
justify-content: flex-end;
padding: 24px 24px 24px 24px;
gap: 8px;

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

&--center {
justify-content: center;
}

&--space-between {
justify-content: space-between;
}

&--stacked {
flex-direction: column-reverse;
align-items: stretch;
gap: 8px;
}
}

.#{$component}--fullscreen {
.#{$component}__header {
display: flex;
align-items: center;
min-height: 56px;
padding: 0 24px;
gap: 8px;
}

.#{$component}__header-close {
order: -1;
margin: 0 0 0 -8px;

@include m.rtl {
margin: 0 -8px 0 0;
}
}

.#{$component}__header-title {
@include m.typography("title-large");
text-align: start;
}

.#{$component}__content {
flex: 1;
overflow-y: auto;
padding: 24px;
}

.#{$component}__footer {
min-height: 56px;
padding: 0 24px;
box-sizing: border-box;
}

display: flex;
flex-direction: column;
}

.#{$component}__header-divider,
.#{$component}__footer-divider {
margin: 0;
border: none;
height: 1px;
background-color: t.color("outline-variant");
}

@include m.reduced-motion {
.#{$component},
.#{$component}--visible,
.#{$component}__overlay,
.#{$component}__overlay--visible {
transition: opacity v.motion("duration-short2") linear;
}

.#{$component},
.#{$component}--visible,
.#{$component}--scale,
.#{$component}--slide-up,
.#{$component}--slide-down,
.#{$component}--fullscreen {
transform: none;
}
}

@include m.high-contrast {
.#{$component},
dialog.#{$component} {
border: 2px solid CurrentColor;
}

.#{$component}__header-divider,
.#{$component}__footer-divider {
background-color: CurrentColor;
}

.#{$component}__header-close:focus-visible {
outline: 2px solid CurrentColor;
}
}

@media (max-width: v.breakpoint("sm")) {
.#{$component} {
min-width: 280px;
width: calc(100% - 32px);
max-width: 100%;
margin: 16px;

transform-origin: bottom center;

&--fullscreen {
width: 100%;
height: 100%;
margin: 0;
transform-origin: center center;
}
}

.#{$component}__overlay {
padding: 16px;
align-items: flex-end;
}

.#{$component}--slide-up {
transform: translateY(24px);

&.#{$component}--visible {
transform: translateY(0);
}
}

.#{$component}__footer--responsive {
flex-direction: column-reverse;
align-items: stretch;
}
}

@media print {
.#{$component}__overlay {
position: static;
background: none;
padding: 0;
}

.#{$component} {
box-shadow: none;
border: 1px solid #000;
max-width: 100%;
transform: none;
opacity: 1;
}
}
