<template>
  <div class="location">
    <i class="icon icon-location" @click="toggleShow"></i>
    <main class="location-main" v-if="show">
      <ul class="location-list">
        <li class="location-list-item">
          <label>{{ $t('TUIChat.描述') }}</label>
          <input type="text" v-model="location.description" />
        </li>
        <li class="location-list-item">
          <label>{{ $t('TUIChat.经度') }}</label>
          <input type="number" v-model="location.longitude" />
        </li>
        <li class="location-list-item">
          <label>{{ $t('TUIChat.纬度') }}</label>
          <input type="number" v-model="location.latitude" />
        </li>
      </ul>
      <ul class="location-footer">
        <button class="btn btn-cancel" @click="cancel">{{ $t('取消') }}</button>
        <button
          class="btn btn-default"
          :disabled="
            !location.data && !location.description && location.extension
          "
          @click="submit"
        >
          {{ $t('发送') }}
        </button>
      </ul>
    </main>
    <div v-if="show" class="mask" @click.self="toggleShow"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, watchEffect, toRefs } from 'vue';

const Location = defineComponent({
  props: {
    show: {
      type: Boolean,
      default: () => false
    }
  },
  setup(props: any, ctx: any) {
    const data = reactive({
      show: false,
      location: {
        description: '深圳市深南大道10000号腾讯大厦',
        longitude: 113.941079,
        latitude: 22.546103
      }
    });

    watchEffect(() => {
      data.show = props.show;
    });

    const toggleShow = () => {
      data.show = !data.show;
    };

    const cancel = () => {
      toggleShow();
    };

    const submit = () => {
      Location.TUIServer.sendLocationMessage(data.location);
      cancel();
    };

    return {
      ...toRefs(data),
      toggleShow,
      cancel,
      submit
    };
  }
});
export default Location;
</script>

<style lang="scss" scoped>
@import url('../../../../styles/common.scss');
@import url('../../../../styles/icon.scss');
.location {
  display: inline-block;
  position: relative;
  &-main {
    position: absolute;
    z-index: 5;
    width: 315Px;
    background: #ffffff;
    top: -180Px;
    box-shadow: 0 2Px 12Px 0 rgba(0, 0, 0, 0.1);
    padding: 10Px;
    display: flex;
    flex-direction: column;
  }
  &-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    &-item {
      padding-bottom: 15Px;
      label {
        width: 88Px;
        font-size: 18Px;
        padding: 0 20Px;
        display: inline-block;
      }
      input {
        flex: 1;
        height: 24Px;
        padding: 0 10Px;
        border: 1Px solid #dddddd;
        border-radius: 5Px;
        &::-webkit-inner-spin-button {
          display: none;
        }
      }
    }
  }
  &-footer {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }
}
.btn {
  padding: 8Px 20Px;
  border-radius: 4Px;
  border: none;
  font-weight: 400;
  font-size: 14Px;
  color: #ffffff;
  letter-spacing: 0;
  text-align: center;
  line-height: 20Px;
  &-cancel {
    border: 1Px solid #dddddd;
    color: #666666;
  }
  &-default {
    background: #006eff;
    border: 1Px solid #006eff;
  }
  &:disabled {
    opacity: 0.3;
  }
}
.mask {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  opacity: 0;
  z-index: 1;
}
</style>
