@import '../abstracts/mixins';
// -----------------------------------------------------
//  Pepperi - Checkbox
// -----------------------------------------------------
@mixin pepperi-checkbox-size($size) {
    $checkbox-width: 1.5rem; 
    $checkbox-height: 1.5rem; 

    @if $size == 'xs' {
        $checkbox-width: 0.75rem; 
        $checkbox-height: 0.75rem; 
    }
    @else if $size == 'sm' {
        $checkbox-width: 1rem; 
        $checkbox-height: 1rem; 
    }
    @else if $size == 'md' {
        $checkbox-width: 1.25rem; 
        $checkbox-height: 1.25rem; 
    }
    @else if $size == 'lg' {
        $checkbox-width: 1.5rem; 
        $checkbox-height: 1.5rem; 
    }
    
    width: $checkbox-width;
    height: $checkbox-height;
}

// -----------------------------------------------------
//  Override material style
// -----------------------------------------------------
.mat-checkbox-anim-checked-unchecked .mat-checkbox-background {
    display: none;
}

.mat-checkbox-disabled,
.mat-checkbox-indeterminate,
.mat-checkbox-checked {
    .mat-checkbox-layout {
        .mat-checkbox-background {
            border-radius: $border-radius-md;
        }
    }
}

.mat-checkbox-checked {
    .mat-checkbox-layout {
        .mat-checkbox-background {
            content: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+CiAgICA8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNy41MTExNjM5LDcuMDAwNjI5NjggQzE3LjEzNTI3Myw3LjAxMDk5Mjg1IDE2Ljc3OTE1ODIsNy4xNjgzMTkwOSAxNi41MTYzMjg4LDcuNDM3NzU0MjEgQzE0LjIyNjEzMzksOS43MzI2NTE5MiAxMi4xMzU2Nzc4LDExLjk4MjQwMjIgOS45MzY5MTEzNSwxNC4yMjgxOTczIEw3LjM1MTc4NzA4LDEyLjE1NTYxMiBDNy4wNTIyMDMwMywxMS45MTUzODI5IDYuNjY5NzI4MTIsMTEuODA0MjI0MiA2LjI4ODE2OTY2LDExLjg0NjYyMjMgQzUuOTA1Njk0NzUsMTEuODg5MDE1NSA1LjU1NzEyODY0LDEyLjA4MTIwMDggNS4zMTY4OTcwNiwxMi4zODE3MzUxIEM1LjA3NzYwODQ2LDEyLjY4MTMxOTEgNC45NjY0NDk4MSwxMy4wNjM3OTQgNS4wMDg4NDc4NywxMy40NDUzNTI1IEM1LjA1MTI0MTExLDEzLjgyNzgyNzQgNS4yNDM0MjYzOCwxNC4xNzYzOTM1IDUuNTQyOTk1OTUsMTQuNDE2NjI1MSBMOS4xNjA1NzgyLDE3LjMxMDY5MDkgQzkuNzM5MDA1NDksMTcuNzcwNDEzMiAxMC41Njk5NCwxNy43MjIzNzE3IDExLjA4OTk1NTQsMTcuMTk3NjQxNCBDMTMuNjkxOTYxNywxNC41OTAwODgxIDE2LjAyMzYxNDEsMTIuMDI4MzU3NiAxOC41NjYyOTIxLDkuNDgwMTMyNjIgQzE4Ljk5MTE2NSw5LjA2Mjc4NDIxIDE5LjExNzQxODcsOC40Mjc4MjYxOCAxOC44ODQ3MTE2LDcuODgwNDg1OTggQzE4LjY1MTA3NjEsNy4zMzIyMDUyMSAxOC4xMDY1NDU2LDYuOTgzNjE0OTkgMTcuNTExMTYzOSw3LjAwMDU5MzUxIEwxNy41MTExNjM5LDcuMDAwNjI5NjggWiIvPgogIDwvc3ZnPg==");
            width: inherit;
            height: inherit;
            
            .mat-checkbox-checkmark-path {
                display: none;
            }
        }
    }
}

.mat-checkbox-indeterminate {
    .mat-checkbox-layout {
        .mat-checkbox-background {
            content: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+Cgk8cmVjdCB3aWR0aD0iMTYiIGhlaWdodD0iNCIgeD0iNCIgeT0iMTAiIGZpbGwtcnVsZT0iZXZlbm9kZCIgcng9IjIiLz4KICAgPCEtLSA8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNy41MTExNjM5LDcuMDAwNjI5NjggQzE3LjEzNTI3Myw3LjAxMDk5Mjg1IDE2Ljc3OTE1ODIsNy4xNjgzMTkwOSAxNi41MTYzMjg4LDcuNDM3NzU0MjEgQzE0LjIyNjEzMzksOS43MzI2NTE5MiAxMi4xMzU2Nzc4LDExLjk4MjQwMjIgOS45MzY5MTEzNSwxNC4yMjgxOTczIEw3LjM1MTc4NzA4LDEyLjE1NTYxMiBDNy4wNTIyMDMwMywxMS45MTUzODI5IDYuNjY5NzI4MTIsMTEuODA0MjI0MiA2LjI4ODE2OTY2LDExLjg0NjYyMjMgQzUuOTA1Njk0NzUsMTEuODg5MDE1NSA1LjU1NzEyODY0LDEyLjA4MTIwMDggNS4zMTY4OTcwNiwxMi4zODE3MzUxIEM1LjA3NzYwODQ2LDEyLjY4MTMxOTEgNC45NjY0NDk4MSwxMy4wNjM3OTQgNS4wMDg4NDc4NywxMy40NDUzNTI1IEM1LjA1MTI0MTExLDEzLjgyNzgyNzQgNS4yNDM0MjYzOCwxNC4xNzYzOTM1IDUuNTQyOTk1OTUsMTQuNDE2NjI1MSBMOS4xNjA1NzgyLDE3LjMxMDY5MDkgQzkuNzM5MDA1NDksMTcuNzcwNDEzMiAxMC41Njk5NCwxNy43MjIzNzE3IDExLjA4OTk1NTQsMTcuMTk3NjQxNCBDMTMuNjkxOTYxNywxNC41OTAwODgxIDE2LjAyMzYxNDEsMTIuMDI4MzU3NiAxOC41NjYyOTIxLDkuNDgwMTMyNjIgQzE4Ljk5MTE2NSw5LjA2Mjc4NDIxIDE5LjExNzQxODcsOC40Mjc4MjYxOCAxOC44ODQ3MTE2LDcuODgwNDg1OTggQzE4LjY1MTA3NjEsNy4zMzIyMDUyMSAxOC4xMDY1NDU2LDYuOTgzNjE0OTkgMTcuNTExMTYzOSw3LjAwMDU5MzUxIEwxNy41MTExNjM5LDcuMDAwNjI5NjggWiIgLz4gLS0+CiAgPC9zdmc+");
            width: inherit;
            height: inherit;
            
            .mat-checkbox-checkmark-path {
                display: none;
            }
        }
    }
}

.pepperi-checkbox-container {
    // width: inherit !important;
    display: grid;
    align-items: center;

    .mat-checkbox {
        height: inherit;
        display: flex;
        align-items: center;
        cursor: default;
    }

    .mat-checkbox-layout {
        cursor: pointer;
    }

    .mat-checkbox-inner-container {
        // margin: auto 0rem auto 0.5rem !important; // override default auto margin.
        // margin: auto 0.5rem auto 0.5rem !important; // override default auto margin.
        margin: auto 0 !important; // override default auto margin.
        margin-left: 0.25rem !important
    }

    .emoji-icon {
        line-height: 1rem;
        border-radius: $border-radius-md;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

        @include pepperi-checkbox-size('lg');
    }

    .emoji-title {
        margin: 0 0.25rem;
    }

    &.right-alignment {
        .mat-checkbox-inner-container {
            // margin: auto 0.5rem auto 0rem !important;
            // margin: auto 0.5rem auto 0.5rem !important;
            margin-left: 0 !important;
            margin-right: 0.25rem !important;
        }
        
        .emoji-icon {
            margin-left: 0 !important;
            margin-right: 0.25rem;
        }
    }

    &.center-alignment {
        .mat-checkbox-inner-container {
            // margin: auto 0 auto 0 !important;
        }

        .mat-checkbox-layout {
            width: 100% !important;
            justify-content: center !important;

            .mat-checkbox-label {
                // margin-left: 0.25rem;
            }
        }

        // .emoji-icon {
        //     margin-left: 0 !important;
        // }
    }

    &.pepperi-input {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
}

.pepperi-report-checkbox {
    background: transparent !important;
}

.pepperi-card-checkbox {
    display: flex;
    padding-top: 0 !important;
    padding-bottom: 0 !important;

    &.right-alignment {
        justify-self: flex-end;
    }

    &.center-alignment {
        justify-self: center;
    }
    
    &.no-title {
        width: 2.5rem !important;
    }

    .mat-checkbox-layout {
        width: 100% !important;
        height: auto;
        align-items: center !important;
        vertical-align: unset; // override default auto margin.
    }

    .mat-checkbox-inner-container {
        margin: auto 0.25rem;
    }

    &.pepperi-input {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    &.one-row {
        // padding: 0 0.25rem;
        // padding: 0;
        padding-top: 0;
        height: $card-field-height; // 1.5rem;
        line-height: 1rem;

        &.no-title {
            width: $card-field-height !important; // 1.5rem !important;

            .mat-checkbox-inner-container {
                // margin: auto 0.5rem auto 0rem !important;
                // margin: auto 0.5rem auto 0.5rem !important;
                margin-left: 0 !important;
                margin-right: 0 !important;
            }
            
            .emoji-icon {
                margin-left: 0 !important;
                margin-right: 0 !important;
            }
        }

        .emoji-icon {
            // margin-top: 0.25rem;
            // margin-left: 0.25rem;
            height: 1rem;
            width: 1rem;
            @include font-size($fs-xs);
        }

        .mat-checkbox-layout {
            height: 1.5rem;
        }

        .mat-checkbox-inner-container {
            border-radius: $border-radius-md;

            @include pepperi-checkbox-size('sm');
        }
    }

    &.disable {
        background: transparent !important;
        padding: 0 !important;

        .mat-checkbox-inner-container {
            //margin-left: 0;
        }
    }
}

.mat-checkbox-layout {
    // height: inherit;
    margin-bottom: unset; // Cancel bootstrap defaults for Label.
    width: fit-content;
    font-weight: inherit;
    display: flex;
    align-items: unset !important;
    vertical-align: unset !important;

    .mat-checkbox-inner-container {
        border-radius: $border-radius-md;

        @include pepperi-checkbox-size('lg');
    }

    .mat-checkbox-label {
        display: block;
        @include ellipsis();
        span {
            margin: 0 0.25rem;
        }
    }

    .mat-checkbox-frame {
        height: inherit;
        width: inherit;
        border-radius: $border-radius-md;
    }
}

// disabled
.mat-checkbox-disabled {
    cursor: auto;

    .mat-checkbox-layout {
        cursor: auto;
    }
}

// Sizes
.mat-checkbox {

    &.lg {
        .mat-checkbox-inner-container {
            @include pepperi-checkbox-size('lg');
        }
    }
    &.md {
        .mat-checkbox-inner-container {
            @include pepperi-checkbox-size('md');
        }
    }
    &.sm {
        .mat-checkbox-inner-container {
            @include pepperi-checkbox-size('sm');
        }
    }
    &.xs {
        .mat-checkbox-inner-container {
            @include pepperi-checkbox-size('xs');
        }
    }
}

@mixin pepperi-checkbox-theme($pepperi-theme) {
    .pepperi-checkbox-container {
        
        &:not(.disable) {
            .emoji-icon {
                border: unset;
    
                &:focus {
                    @include focus($pepperi-theme);
                }
            }
        }

        &.pepperi-card-checkbox {
            background: get-pepperi-color($pepperi-theme, color-weak, color-tran-10);
        }
        
    }

    .has-active-campaign {
        width: 100%;
        justify-content: center;

        .svg-icon {
            fill: get-pepperi-color($pepperi-theme, color-system-caution, color-base);
        }
    }

    // &:hover {
    //     //cursor: default;
    //     @include state-weak-hover($pepperi-theme);
    // }
    // &:active {
    //     @include state-weak-active($pepperi-theme);
    // }

    // -----------------------------------------------------
    //  Override material style
    // -----------------------------------------------------
    .mat-checkbox-layout {
        &:hover {
            .mat-checkbox-frame {
                @include state-regular-hover($pepperi-theme, true);
            }
        }

        &:active {
            .mat-checkbox-frame {
                @include state-regular-active($pepperi-theme, true);
            }
        }

        .mat-checkbox-frame {
            // border: unset;
            @include state-regular-default($pepperi-theme, true);
        }
    }

    // checked
    .mat-checkbox-indeterminate,
    .mat-checkbox-checked {
        .mat-checkbox-layout {
            &:hover {
                .mat-checkbox-background {
                    @include state-regular-hover($pepperi-theme, true);
                    opacity: 0.7;
                }
            }

            &:active {
                .mat-checkbox-background {
                    @include state-regular-active($pepperi-theme, true);
                }
            }

            .mat-checkbox-background {
                @include state-regular-default($pepperi-theme, true);
            }
        }
    }

    .mat-checkbox-indeterminate {
        .mat-checkbox-mixedmark {
            background: get-pepperi-color($pepperi-theme, color-text, color-dimmed) !important;
        }
    }

    // focused
    .cdk-focused {
        .mat-checkbox-layout {
            &:hover {
                .mat-checkbox-frame {
                    @include state-regular-hover($pepperi-theme, true);
                    @include focus($pepperi-theme);
                }
            }

            &:active {
                .mat-checkbox-frame {
                    @include state-regular-active($pepperi-theme, true);
                    @include focus($pepperi-theme);
                }
            }

            .mat-checkbox-frame {
                @include state-regular-focus($pepperi-theme, true);
            }
        }
    }

    // disabled
    .mat-checkbox-disabled {
        .mat-checkbox-layout {
            &:hover {
                .mat-checkbox-background {
                    @include state-regular-disable($pepperi-theme, true);
                    box-shadow: unset;
                    opacity: 0.35;
                }
            }

            &:active {
                .mat-checkbox-background {
                    @include state-regular-disable($pepperi-theme, true);
                    box-shadow: unset;
                    opacity: 0.35;
                }
            }

            .mat-checkbox-frame {
                @include state-regular-disable($pepperi-theme, true);
                box-shadow: unset;
            }

            .mat-checkbox-background {
                @include state-regular-disable($pepperi-theme, true);
                box-shadow: unset;
                opacity: 0.35;
            }

            .mat-checkbox-label {
                color: get-pepperi-color($pepperi-theme, color-text, color-dimmed);
            }
        }
    }
}
