<template>
    <view class="msg--text">
        <view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
        <view>
            <text class="im--text" :class="isRemote ? 'left': 'right'">{{ content }}</text>
        </view>
    </view>
</template>

<script>
    export default {
        name: 'showText',
        props: {
            message: {
                type: Object,
                default: () => {
                    return {}
                }
            },
            isGroup: {
                type: Boolean,
                default: false
            }
        },
        computed: {
            isRemote() {
                return this.message.messageDirection == 2
            },
            content() {
                return this.message.content.content
            },
            contact() {
                return function(targetId) {
                    return this.$store.getters.contactInfo(targetId)
                }
            }
        },
    }
</script>

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

        .im--text {
            max-width: 508rpx;
            padding: 20rpx;
            line-height: 46rpx;
            font-size: 32rpx;
            color: $text-color;
            display: inline-block;
            word-break: break-all;

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

            &.right {
                border-radius: 20rpx 0 20rpx 20rpx;
                background: $main-color;
                color: white;
            }
        }
    }
</style>
