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

        <view class="">
            <view class="name" v-if="isGroup && isRemote">{{ contact(message.senderUserId).name }}</view>
            <view class="location" :class="isRemote ? 'left': 'right'" @click="showLocation">
                <view class="location--name">
                    {{ content.customFields.name }}
                    {{ content.customFields.address }}
                </view>
                <image class="map" :src="content.customFields.thumbnail" />
            </view>
        </view>
    </view>
</template>

<script>
    import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
    import messageState from './messageState'
    import imBase from '../../mixins/imBase.js'

    export default {
        mixins: [
            imBase
        ],
        name: 'showImage',
        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
            }
        },
        methods: {
            showLocation() {
                uni.openLocation({
                    latitude: Number(this.content.customFields.latitude),
                    longitude: Number(this.content.customFields.longitude),
                    fail: (err) => {
                        uni.showToast({
                            icon: 'none',
                            title: '打开地图失败'
                        })
                    }
                })
            }
        }
    }
</script>

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

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

        .location {
            position: relative;
            width: 400rpx;
            background: #FFFFFF;
            padding: 10rpx;

            .location--name {
                overflow: hidden;
                word-break: break-all;
            }

            .map {
                width: 400rpx;
                height: 200rpx;
            }

            &.left {
                border-radius: 0 10rpx 10rpx 10rpx;
            }

            &.right {
                border-radius: 10rpx 0 10rpx 10rpx;
            }
        }
    }
</style>
