<template>
    <view class="msg--call">
        <view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
        <view class="im--text" :class="isRemote ? 'left': 'right'">
            <u-icon name="camera" size="22" v-if="msg.mediaType == 1" :label="label" />
            <u-icon name="phone" size="22" v-else :label="label" />
        </view>
    </view>
</template>

<script>
    import utils from '@/utils/index.js'
    import moment from 'moment'
    import imBase from '../../mixins/imBase.js'

    export default {
        mixins: [
            imBase
        ],
        name: 'showText',
        props: {
            message: {
                type: Object,
                default: () => {
                    return {}
                }
            },
            isGroup: {
                type: Boolean,
                default: false
            }
        },
        mounted() {
        },
        computed: {
            msg() {
                return JSON.parse(this.message.content.message)
            },
            label() {
                return this.msg.connected ? '通话时长：' + duration : '未接通'
            },
            isRemote() {
                return this.message.messageDirection == 2
            },
            duration() {
                if (this.message.duration > 3600) {
                    return moment.utc(this.message.duration * 1000).format('HH:mm:ss')
                } else {
                    return moment.utc(this.message.duration * 1000).format('mm:ss')
                }
            }
        }
    }
</script>

<style scoped lang="scss">
    .msg--call {
        .name {
            font-size: 26rpx;
            color: $text-gray-m;
            display: inline-block;
        }

        .im--text {
            max-width: 508rpx;
            padding: 20rpx;
            line-height: 46rpx;
            font-size: 32rpx;
            color: $text-color;
            display: flex;
            flex-direction: row;

            &.left {
                border-radius: 0 20rpx 20rpx 20rpx;
                background: white;
            }

            &.right {
                border-radius: 20rpx 0 20rpx 20rpx;
                background: $main-color;
                color: white;

                .u-icon {
                    color: white;
                }
            }
        }
    }
</style>
