@use '../abstract/variables' as v;
@use '../abstract/functions' as f;
@use '../abstract/mixins' as m;
@use '../abstract/theme' as t;

$supporting-row: 20px;

/**
 * The field: a text field, or a select (`$trailing`: the space its trailing
 * icon takes beside the text).
 */
@mixin field($trailing: 0px) {
display: inline-block;
position: relative;
box-sizing: border-box;
width: v.text-field('width');
height: f.density(v.text-field('height'), 40px);
padding: f.density(24.5px, 12.5px, 3px) (v.text-field('padding-horizontal') + $trailing) 0 v.text-field('padding-horizontal');
border-radius: v.text-field('border-radius') v.text-field('border-radius') 0 0;
border-bottom: v.text-field('border-width') solid t.color('on-surface-variant');
background-color: t.color('surface-container-highest');
color: t.color('on-surface');
white-space: nowrap;
overflow: clip;
@include m.typography('body-large');

&::before {
content: attr(value) ' ';
white-space: pre;
}

&[label]::after {
content: attr(label);
position: absolute;
top: f.density(v.text-field('padding-vertical'), 8px, 2px);
left: v.text-field('padding-horizontal');
color: t.color('on-surface-variant');
}

&[label][value]:not([value=''])::after {
top: f.density(8px, 0px, 2px);
@include m.typography('body-small');
}

&:not([label]) {
padding-top: f.density(16.5px, 8.5px, 2px);
}

&[variant='outlined'] {
padding-top: f.density(15.5px, 7.5px, 2px);
border: v.text-field('border-width') solid t.color('outline');
border-radius: v.text-field('border-radius');
background: none;

&[label][value]:not([value=''])::after {
top: -8px;
padding: 0 4px;
left: 12px;
}
}

&[density='compact'] {
height: 40px;
padding-top: 12.5px;

&::after {
top: 8px;
}

&[label][value]:not([value=''])::after {
top: 0;
}

&:not([label]) {
padding-top: 8.5px;
}

&[variant='outlined'] {
padding-top: 7.5px;
}

&[variant='outlined'][label][value]:not([value=''])::after {
top: -8px;
}
}

&[supporting-text]:not([supporting-text='']),
&[maxlength] {
$row: $supporting-row;
height: calc(#{f.density(v.text-field('height'), 40px)} + #{$row});
border-bottom: $row solid transparent;
background-clip: padding-box;
background-image: linear-gradient(to top, #{t.color('on-surface-variant')} v.text-field('border-width'), transparent v.text-field('border-width'));

&[variant='outlined'] {
padding-top: calc(#{f.density(15.5px, 7.5px, 2px)} + #{v.text-field('border-width')});
padding-left: calc(#{v.text-field('padding-horizontal')} + #{v.text-field('border-width')});
border-width: 0 0 $row;
border-radius: v.text-field('border-radius') / v.text-field('border-radius') v.text-field('border-radius') calc(#{v.text-field('border-radius')} + #{$row}) calc(#{v.text-field('border-radius')} + #{$row});
background-image: none;
box-shadow: inset 0 0 0 v.text-field('border-width') t.color('outline');
}

&[density='compact'] {
height: calc(40px + #{$row});

&[variant='outlined'] {
padding-top: calc(7.5px + #{v.text-field('border-width')});
}
}
}

> * {
display: none;
}
}
