/*
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_CallEvent_wrapper {
    display: flex;
    width: 100%;

    .mx_CallEvent {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: $spacing-4 0;

        position: relative;
        margin: $spacing-4 0;
        padding: $spacing-12 $spacing-24;
        box-sizing: border-box;
        background-color: $dark-panel-bg-color;
        border-radius: 8px;
        width: 65%;
        height: fit-content;

        .mx_CallEvent_iconButton {
            display: inline-flex;

            &::before {
                content: '';

                height: 16px;
                width: 16px;
                background-color: $secondary-content;
                mask-repeat: no-repeat;
                mask-size: contain;
                mask-position: center;
            }
        }

        .mx_CallEvent_silence::before {
            mask-image: url('$(res)/img/voip/silence.svg');
        }

        .mx_CallEvent_unSilence::before {
            mask-image: url('$(res)/img/voip/un-silence.svg');
        }

        &.mx_CallEvent_voice {
            .mx_CallEvent_type_icon::before,
            .mx_CallEvent_content_button_callBack span::before,
            .mx_CallEvent_content_button_answer span::before {
                mask-image: url('$(res)/img/element-icons/call/voice-call.svg');
            }

            &.mx_CallEvent_rejected,
            &.mx_CallEvent_noAnswer {
                .mx_CallEvent_type_icon::before {
                    mask-image: url('$(res)/img/voip/declined-voice.svg');
                }
            }
        }

        &.mx_CallEvent_video {
            .mx_CallEvent_type_icon::before,
            .mx_CallEvent_content_button_callBack span::before,
            .mx_CallEvent_content_button_answer span::before {
                mask-image: url('$(res)/img/element-icons/call/video-call.svg');
            }

            &.mx_CallEvent_rejected,
            &.mx_CallEvent_noAnswer {
                .mx_CallEvent_type_icon::before {
                    mask-image: url('$(res)/img/voip/declined-video.svg');
                }
            }
        }

        &.mx_CallEvent_missed {
            &.mx_CallEvent_voice {
                .mx_CallEvent_type_icon::before {
                    mask-image: url('$(res)/img/voip/missed-voice.svg');
                }
            }

            &.mx_CallEvent_video {
                .mx_CallEvent_type_icon::before {
                    mask-image: url('$(res)/img/voip/missed-video.svg');
                }
            }
        }

        .mx_CallEvent_info {
            display: flex;
            flex-direction: row;
            align-items: center;
            width: fit-content;
            max-width: 100%;

            .mx_CallEvent_info_basic {
                display: flex;
                flex-direction: column;
                gap: $spacing-4;
                margin-left: 10px; // To match mx_CallEvent
                margin-right: 10px;
                min-width: 0;

                .mx_CallEvent_sender {
                    font-weight: 600;
                    font-size: 1.5rem;
                    line-height: 1.8rem;
                    margin-bottom: $spacing-4;

                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }

                .mx_CallEvent_type {
                    display: flex;
                    align-items: center;
                    font-weight: 400;
                    color: $secondary-content;
                    font-size: 1.2rem;
                    line-height: $font-13px;

                    .mx_CallEvent_type_icon {
                        height: 13px;
                        width: 13px;
                        margin-right: 5px;

                        &::before {
                            content: '';
                            position: absolute;
                            height: 13px;
                            width: 13px;
                            background-color: $secondary-content;
                            mask-repeat: no-repeat;
                            mask-size: contain;
                        }
                    }
                }
            }
        }

        .mx_CallEvent_content {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            color: $secondary-content;
            gap: $spacing-12; // See mx_IncomingCallToast_buttons
            margin-inline-start: 42px; // avatar (32px) + mx_CallEvent_info_basic margin (10px)
            word-break: break-word;
            max-width: fit-content;

            .mx_CallEvent_content_button {
                @mixin CallButton;
                padding: 0 $spacing-12;

                span::before {
                    mask-size: 16px;
                    width: 16px;
                    height: 16px;
                    flex-shrink: 0;
                }
            }

            .mx_CallEvent_content_button_reject {
                span::before {
                    mask-image: url('$(res)/img/element-icons/call/hangup.svg');
                }
            }

            .mx_CallEvent_content_tooltip {
                margin-right: 5px;
            }
        }

        &.mx_CallEvent_narrow {
            flex-direction: column;
            align-items: unset;
            gap: $spacing-4 $spacing-16;
            height: unset;
            min-width: 290px;

            .mx_CallEvent_iconButton {
                position: absolute;
                margin-right: 0;
                top: 12px;
                right: 12px;
                height: 16px;
                width: 16px;
                display: flex;
            }

            .mx_CallEvent_info {
                align-items: unset;
            }
        }
    }
}

.mx_EventTile[data-layout="bubble"] {
    .mx_EventTile_e2eIcon + .mx_CallEvent_wrapper {
        .mx_CallEvent {
            position: relative;

            // 5px (gap) + 14px (e2e icon size * mask-size) + 9px (margin-left of e2e icon)
            right: calc(5px + 14px + 9px);
        }
    }
}

.mx_EventTile_leftAlignedBubble {
    .mx_CallEvent_wrapper {
        .mx_CallEvent {
            &.mx_CallEvent_narrow {
                gap: $spacing-8 $spacing-4;
            }
        }
    }
}

.mx_IRCLayout {
    .mx_CallEvent_wrapper {
        .mx_CallEvent {
            margin-inline-start: $spacing-4; // display green line
        }
    }
}
