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

@include c.host('text-field') {
display: inline-block;
position: relative;
width: v.text-field('width');

&::before {
content: attr(value) ' ';
display: inline-block;
box-sizing: border-box;
width: 100%;
height: f.density(v.text-field('height'), 40px);
padding: f.density(24.5px, 12.5px, 3px) v.text-field('padding-horizontal') 0;
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: pre;
overflow: clip;
@include m.typography('body-large');
}

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

&[variant='outlined']::before {
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;
}


&[supporting-text]:not([supporting-text='']),
&[maxlength] {
&::before {
height: calc(#{f.density(v.text-field('height'), 40px)} + #{field.$supporting-row});
border-bottom: field.$supporting-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']::before {
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 field.$supporting-row;
border-radius: v.text-field('border-radius') / v.text-field('border-radius') v.text-field('border-radius') calc(#{v.text-field('border-radius')} + #{field.$supporting-row}) calc(#{v.text-field('border-radius')} + #{field.$supporting-row});
background-image: none;
box-shadow: inset 0 0 0 v.text-field('border-width') t.color('outline');
}
}

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

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

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

&[type='multiline'] {
&::before {
display: inline-flex;
height: f.density(v.text-field('height-multiline'), 84px);
padding-top: f.density(v.text-field('padding-top-multiline'), 8px, 2px);
}

&[label]::before {
padding-top: f.density(v.text-field('padding-top-multiline-label'), 12px, 3px);
}

&[variant='outlined']::before {
padding-top: calc(#{f.density(v.text-field('padding-top-multiline'), 8px, 2px)} - #{v.text-field('border-width')});
}

&[supporting-text]:not([supporting-text='']),
&[maxlength] {
&::before {
height: calc(#{f.density(v.text-field('height-multiline'), 84px)} + #{field.$supporting-row});
}

&[variant='outlined']::before {
padding-top: f.density(v.text-field('padding-top-multiline'), 8px, 2px);
}
}
}

&[type='password' i]::before,
&[type='hidden' i]::before {
content: ' ';
}

&[type='hidden' i] {
display: none;
}

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

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

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

&[supporting-text]:not([supporting-text='']),
&[maxlength] {
&::before {
height: calc(40px + #{field.$supporting-row});
}

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

&[label]::after {
top: 8px;
}

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

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

&[type='multiline'] {
&::before {
height: 84px;
padding-top: 8px;
}

&[label]::before {
padding-top: 12px;
}

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

&[supporting-text]:not([supporting-text='']),
&[maxlength] {
&::before {
height: calc(84px + #{field.$supporting-row});
}

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

> * { display: none; }
}
