<template>
    <view class="msg--text">
        <message-state :message="message" :isGroup="isGroup" :isRemote="isRemote" />

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

<script>
    import messageState from './messageState'
    import imBase from '../../mixins/imBase.js'

    export default {
        name: 'showText',
        mixins: [
            imBase,
        ],
        props: {
            message: {
                type: Object,
                default: () => {
                    return {}
                }
            },
            isGroup: {
                type: Boolean,
                default: false
            }
        },
        components: {
            messageState
        },
        computed: {
            isRemote() {
                return this.message.messageDirection == 2
            },
            content() {
                return this.message.content.content
            }
        }
    }
</script>

<style scoped lang="scss">
    .msg--text {
        display: flex;
        align-items: flex-end;

        .name {
            font-size: 24rpx;
            color: $text-gray-m;
        }

        .text {
            box-sizing: border-box;
            max-width: 502rpx;
            padding: 20rpx 24rpx;
            line-height: 46rpx;
            font-size: 32rpx;
            color: $text-color;
            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>
