@use 'sass:map';
@use '../../styles/abstract/base' as base;
@use '../../styles/abstract/variables' as v;
@use '../base/plain-slot-button';
@use '../../styles/abstract/functions' as f;
@use '../../styles/abstract/mixins' as m;
@use '../../styles/abstract/theme' as t;

$component: '#{base.$prefix}-top-app-bar';

.#{$component} {
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: f.get-z-index('fixed');
display: flex;
align-items: center;
width: 100%;
box-sizing: border-box;
background-color: t.color('surface');

height: 64px;
padding: 0 16px;

transition: 
box-shadow 0.3s ease-in-out,
background-color 0.3s ease-in-out,
height 0.3s ease-in-out;

&__headline {
flex: 1;
display: flex;
align-items: center;
@include m.typography('title-large');
color: t.color('on-surface');
margin: 0;
padding: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: 
font-size 0.3s ease-in-out,
margin 0.3s ease-in-out,
padding 0.3s ease-in-out;
}

&__leading {
display: flex;
align-items: center;
color: t.color('on-surface');
--#{base.$prefix}-icon-button-standard-color: #{t.color('on-surface')};
button { color: inherit; }
&:not(:empty):not([data-empty]) {
margin-right: 24px;
}
}

slot::slotted(button) { color: inherit; }

&__trailing {
display: flex;
align-items: center;
gap: 8px;
margin-left: auto;
color: t.color('on-surface-variant');
--#{base.$prefix}-icon-button-standard-color: #{t.color('on-surface-variant')};
button { color: inherit; }
}

&--center {
.#{$component}__headline {
position: absolute;
left: 50%;
transform: translateX(-50%);
text-align: center;
flex: 0;
}
}

&--medium {
height: 112px;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;
padding: 0;

.#{$component}__row {
display: flex;
align-items: center;
width: 100%;
box-sizing: border-box;
padding: 0 16px;

&:first-child {
margin-top: 20px;
}
}

.#{$component}__headline {
margin-bottom: 24px;
margin-left: 16px;
@include m.typography('headline-small');
}
}

&--large {
height: 152px;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;
padding: 0;

.#{$component}__row {
display: flex;
align-items: center;
width: 100%;
box-sizing: border-box;
padding: 0 16px;

&:first-child {
margin-top: 20px;
}
}

.#{$component}__headline {
margin-bottom: 28px;
margin-left: 16px;
@include m.typography('headline-medium');
}
}

&--scrolled {
background-color: t.color('surface-container');
@include m.elevation(2);

&.#{$component}--medium.#{$component}--compressible,
&.#{$component}--large.#{$component}--compressible {
height: 64px;
flex-direction: row;
align-items: center;
padding: 0 16px;

.#{$component}__row {
display: contents;
}

.#{$component}__leading { order: 0; }

.#{$component}__headline {
order: 1;
margin: 0;
@include m.typography('title-large');
}

.#{$component}__trailing { order: 2; }
}
}

@include m.rtl {
.#{$component}__leading:not(:empty):not([data-empty]) {
margin-right: 0;
margin-left: 24px;
}

.#{$component}__trailing {
margin-left: 0;
margin-right: auto;
}

}

@include m.rtl-selector('.#{$component}--medium .#{$component}__headline') {
margin-left: 0;
margin-right: 16px;
}

@include m.rtl-selector('.#{$component}--large .#{$component}__headline') {
margin-left: 0;
margin-right: 16px;
}

@include m.rtl-selector('.#{$component}--center .#{$component}__headline') {
left: auto;
right: 50%;
transform: translateX(50%);
}

@media (max-width: map.get(v.$breakpoints, 'sm')) {
padding: 0 12px;

.#{$component}__leading:not(:empty):not([data-empty]) {
margin-right: 16px;
}

@include m.rtl {
.#{$component}__leading:not(:empty):not([data-empty]) {
margin-right: 0;
margin-left: 16px;
}
}

.#{$component}__trailing {
gap: 4px;
}

.#{$component}__leading,
.#{$component}__trailing {
button {
padding: 8px;
}
}
}

@include m.reduced-motion {
transition-duration: 0.01ms;

.#{$component}__headline {
transition-duration: 0.01ms;
}
}

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