@use '../../variables' as *;

$b: '.wysiwyg';
$block: true !default;

@mixin wysiwyg() {
    color: $wysiwyg-color;

    @include font($wysiwyg-font);

    a:not(.link, .button) {
        color: $wysiwyg-link-color;
        text-decoration: none;
        transition-duration: var(--duration-micro-s);
        transition-property: color;
        transition-timing-function: var(--easing-standard);

        @include ul-solid($wysiwyg-link-color);

        &:hover,
        &:focus-visible {
            color: $wysiwyg-link-active-color;

            @include ul-solid($wysiwyg-link-active-color);
        }
    }

    h1,
    #{$b}__h1 {
        color: $wysiwyg-h1-color;

        @include font($wysiwyg-h1-mobile-font);

        @media (--tablet-landscape-up) {
            @include font($wysiwyg-h1-desktop-font);
        }

        &:not(:last-child) {
            margin-bottom: 4px * 8;
        }
    }

    h2,
    #{$b}__h2 {
        color: $wysiwyg-h2-color;

        @include font($wysiwyg-h2-mobile-font);

        @media (--tablet-landscape-up) {
            @include font($wysiwyg-h2-desktop-font);
        }

        &:not(:first-child) {
            margin-top: 4px * 8;

            @media (--tablet-landscape-up) {
                margin-top: 4px * 12;
            }
        }

        &:not(:last-child) {
            margin-bottom: 4px * 4;

            @media (--tablet-landscape-up) {
                margin-bottom: 4px * 8;
            }
        }
    }

    h3,
    #{$b}__h3 {
        color: $wysiwyg-h3-color;

        @include font($wysiwyg-h3-mobile-font);

        @media (--tablet-landscape-up) {
            @include font($wysiwyg-h3-desktop-font);
        }

        &:not(:first-child) {
            margin-top: 4px * 8;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 4;
        }
    }

    h4,
    #{$b}__h4 {
        color: $wysiwyg-h4-color;

        @include font($wysiwyg-h4-mobile-font);

        @media (--tablet-landscape-up) {
            @include font($wysiwyg-h4-desktop-font);
        }

        &:not(:first-child) {
            margin-top: 4px * 8;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 4;
        }
    }

    p {
        &:not(:last-child) {
            margin-bottom: 4px * 4;
        }
    }

    ul {
        list-style-type: disc;
        margin-left: 1em;

        ul,
        ol {
            padding-left: 1em;
        }

        ul {
            list-style-type: circle;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 4;
        }

        li {
        }
    }

    ol {
        counter-reset: list;

        ul,
        ol {
            padding-left: 1em;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 4;
        }

        li,
        li > ol > li {
            &::before {
                content: counters(list, '.') '. ';
                counter-increment: list;
                font-weight: bold;
            }
        }
    }

    img,
    svg {
        border-radius: $wysiwyg-image-radius;
        display: block;
        max-width: 100%;

        &:not(:first-child) {
            margin-top: 4px * 8;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 8;
        }

        &#{$b}__float {
            &_right {
                @media (--tablet-landscape-up) {
                    float: right;
                    margin-bottom: 0;
                    margin-left: 4px * 6;
                    margin-top: 0;
                }
            }

            &_left {
                @media (--tablet-landscape-up) {
                    float: left;
                    margin-bottom: 0;
                    margin-right: 4px * 6;
                    margin-top: 0;
                }
            }
        }

        &#{$b}__fluid-image {
            width: 100%;
        }
    }

    #{$b}__table {
        overflow: auto;
        -webkit-overflow-scrolling: touch;

        &:not(:first-child) {
            margin-top: 4px * 8;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 8;
        }

        table {
            width: 100%;

            @include font($wysiwyg-table-font);
        }

        th,
        td {
            padding: 4px * 4 4px * 3;

            &:first-child {
                padding-left: 4px * 6;
            }

            &:last-child {
                padding-right: 4px * 6;
                text-align: right;
            }
        }

        thead {
            th {
                background-color: $wysiwyg-table-header-bg;
                color: $wysiwyg-table-header-color;
                text-align: left;

                @include font($wysiwyg-table-header-font);

                &:first-child {
                    border-bottom-left-radius: $wysiwyg-table-radius;
                    border-top-left-radius: $wysiwyg-table-radius;
                }

                &:last-child {
                    border-bottom-right-radius: $wysiwyg-table-radius;
                    border-top-right-radius: $wysiwyg-table-radius;
                }
            }
        }

        tbody {
            td {
                border-bottom: $wysiwyg-table-separator-width solid $wysiwyg-table-separator-color;
            }
        }

        &_zebra {
            background-color: $wysiwyg-table-zebra-bg;
            border-radius: $wysiwyg-table-radius;
            box-shadow: $wysiwyg-table-zebra-shadow;

            thead {
                th {
                    &:first-child {
                        border-bottom-left-radius: 0;
                    }

                    &:last-child {
                        border-bottom-right-radius: 0;
                    }
                }
            }

            tbody {
                tr {
                    &:nth-child(even) {
                        td {
                            background-color: $wysiwyg-table-zebra-td-bg;
                        }
                    }

                    &:last-child {
                        td {
                            &:first-child {
                                border-bottom-left-radius: $wysiwyg-table-radius;
                            }

                            &:last-child {
                                border-bottom-right-radius: $wysiwyg-table-radius;
                            }
                        }
                    }
                }

                td {
                    border-bottom-style: none;
                }
            }
        }
    }

    #{$b}__alert {
        background-color: $wysiwyg-alert-bg;
        border-radius: $wysiwyg-alert-radius;
        color: $wysiwyg-alert-color;
        padding-top: 4px * 4;

        @media (--tablet-landscape-up) {
            padding: 4px * 6 4px * 8;
        }

        &:not(:first-child) {
            margin-top: 4px * 8;
        }

        &:not(:last-child) {
            margin-bottom: 4px * 8;
        }

        &_warning {
            background-color: $wysiwyg-alert-warning-bg;
        }

        > * {
            color: $wysiwyg-alert-color;
        }

        a:not(.link, .button) {
            color: $wysiwyg-alert-link-color;

            @include ul-solid($wysiwyg-alert-link-color);

            &:hover,
            &:focus-visible {
                color: $wysiwyg-alert-active-link-color;

                @include ul-solid($wysiwyg-alert-active-link-color);
            }
        }
    }
}

@if $block == true {
    #{$b} {
        @include wysiwyg;
    }
}
