@use 'sass:meta';
@use 'iro-sass/src/bem';
@use 'iro-sass/src/props';
@use '../props' as *;
@use '../objects/table.vars' as table;

@forward 'tables.vars';
@use 'tables.vars' as vars;

@mixin styles {
    @include materialize-at-root(meta.module-variables('vars'));

    @include bem.scope('tables') {
        table {
            margin-block-start: props.get(vars.$margin-bs);
            border-spacing:     0;
            border-collapse:    separate;
        }

        th {
            padding-block:  props.get(table.$pad-b);
            padding-inline: props.get(table.$pad-i);
            font-family:    props.get(table.$heading--font-family);
            font-size:      props.get(table.$heading--font-size);
            font-weight:    props.get(table.$heading--font-weight);
            color:          props.get(table.$heading-color);
            text-align:     start;
            text-transform: props.get(table.$heading--text-transform);
            letter-spacing: props.get(table.$heading--letter-spacing);
        }

        td {
            padding-block:            props.get(table.$pad-b);
            padding-inline:           props.get(table.$pad-i);
            border-color:             props.get(table.$border-color);
            border-style:             solid;
            border-width:             0;
            border-block-start-width: props.get(table.$border-width);
        }

        tr {
            &:last-child {
                td {
                    border-block-end-width: props.get(table.$border-width);
                }
            }
        }

        @include bem.modifier('flush') {
            th,
            td {
                &:first-child {
                    padding-inline-start: 0;
                }

                &:last-child {
                    padding-inline-end: 0;
                }
            }
        }

        @include bem.modifier('box') {
            td {
                background-color: props.get(table.$box--bg-color);
            
                &:first-child {
                    border-inline-start-width: props.get(table.$border-width);
                }
            
                &:last-child {
                    border-inline-end-width: props.get(table.$border-width);
                }
            }
    
            tr {
                &:first-child {
                    td {
                        &:first-child {
                            border-start-start-radius: props.get(table.$rounding);
                        }
            
                        &:last-child {
                            border-start-end-radius: props.get(table.$rounding);
                        }
                    }
                }
    
                &:last-child {
                    td {
                        &:first-child {
                            border-end-start-radius: props.get(table.$rounding);
                        }
            
                        &:last-child {
                            border-end-end-radius: props.get(table.$rounding);
                        }
                    }
                }
            }
        }
    }
}