@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}-card';

.#{$component} {
position: relative;
display: flex;
flex-direction: column;
box-sizing: border-box;
border-radius: f.get-shape('medium');
background-color: t.color('surface');
color: t.color('on-surface');
overflow: hidden;
@include m.typography('body-medium');

@include m.motion-transition(
box-shadow,
background-color,
border-color
);

&:focus-visible {
@include m.focus-ring(t.color('secondary'));
}

&--focused {
@include m.focus-ring(t.color('secondary'));
}

.ripple {
position: absolute;
border-radius: 50%;
transform: scale(0);
pointer-events: none;
background-color: currentColor;
opacity: f.get-state-opacity('hover');
}

> :not(:last-child) {
margin-bottom: 0;
}


&--elevated {
background-color: t.color('surface-container-low');
@include m.elevation(1);

&:hover.#{$component}--interactive {
@include m.elevation(2);
}

&:active.#{$component}--interactive {
@include m.elevation(1);
@include m.state-layer(t.color('on-surface'), 'pressed');
}

&.#{$component}--dragging {
@include m.elevation(4);
}

&.#{$component}--state-disabled {
background-color: t.color('surface');
@include m.elevation(1);
}
}

&--filled {
background-color: t.color('surface-container-highest');
@include m.elevation(0);

&:hover.#{$component}--interactive {
@include m.elevation(1);
@include m.state-layer(t.color('on-surface'), 'hover');
}

&:active.#{$component}--interactive {
@include m.elevation(0);
@include m.state-layer(t.color('on-surface'), 'pressed');
}

&.#{$component}--dragging {
@include m.elevation(3);
}

&.#{$component}--state-disabled {
background-color: t.color('surface-variant');
}
}

&--outlined {
border: 1px solid t.color('outline-variant');
background-color: t.color('surface');
@include m.elevation(0);

&:hover.#{$component}--interactive {
@include m.elevation(1);
@include m.state-layer(t.color('on-surface'), 'hover');
border-color: t.color('outline-variant');
}

&:focus-visible,
&.#{$component}--focused {
border-color: t.color('on-surface');
}

&:active.#{$component}--interactive {
@include m.elevation(0);
@include m.state-layer(t.color('on-surface'), 'pressed');
border-color: t.color('outline-variant');
}

&.#{$component}--dragging {
@include m.elevation(3);
}

&.#{$component}--state-disabled {
border-color: t.alpha('outline', 0.12);
}
}


&--interactive {
cursor: pointer;
user-select: none;
}

&--full-width {
width: 100%;
}

&--small {
width: v.card('width-small');
}

&--medium {
width: v.card('width-medium');
}

&--large {
width: v.card('width-large');
}


&__header {
display: flex;
align-items: center;
padding: v.card('padding');
padding-bottom: 0;

&:last-child {
padding-bottom: v.card('padding');
}

&-avatar {
margin-right: v.card('padding');
@include m.rtl {
margin-right: 0;
margin-left: v.card('padding');
}
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;

img {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
}
}

&-text {
flex: 1;
overflow: hidden;
}

&-title {
margin: 0;
@include m.typography('title-large');
@include m.truncate;
color: t.color('on-surface');
}

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

&-action {
margin-left: 8px;
@include m.rtl {
margin-left: 0;
margin-right: 8px;
}
flex-shrink: 0;
}
}

&__media {
position: relative;
overflow: hidden;
border-radius: f.get-shape('medium');
&-img {
display: block;
width: 100%;
object-fit: cover;
}

&--16-9 {
aspect-ratio: 16 / 9;

img {
height: 100%;
}
}

&--4-3 {
aspect-ratio: 4 / 3;

img {
height: 100%;
}
}

&--1-1 {
aspect-ratio: 1 / 1;

img {
height: 100%;
}
}

&--contain {
img {
object-fit: contain;
}
}
}

&__content {
padding: v.card('padding');
flex: 1 1 auto;

> *:first-child {
margin-top: 0;
}

> *:last-child {
margin-bottom: 0;
}

.#{$component}__media + &:not(.#{$component}__content--no-padding) {
padding-top: v.card('padding');
}

&--no-padding {
padding: 0;
}
}

&__actions {
display: flex;
flex-wrap: wrap;
padding: 8px;
align-items: center;

> * {
margin: 0 4px;

&:first-child {
margin-left: 8px;
}

&:last-child {
margin-right: 8px;
}

@include m.rtl {
&:first-child {
margin-left: 4px;
margin-right: 8px;
}

&:last-child {
margin-right: 4px;
margin-left: 8px;
}
}
}

&--full-bleed {
padding: 0;

> * {
margin: 0;
border-radius: 0;
flex: 1 1 auto;

&:first-child {
margin-left: 0;
}

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

&--vertical {
flex-direction: column;

> * {
width: 100%;
margin: 4px 0;

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

&:last-child {
margin-bottom: 8px;
}
}
}

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

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

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

&--state-disabled {
opacity: 0.38;
pointer-events: none;
}

&--dragging {
cursor: grabbing;
}
}

@include m.breakpoint-down('sm') {
.#{$component} {
width: 100%;
}
}