<script setup lang="ts">
import { Lock } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

import { useClipboard } from '@vueuse/core'

const modelValue = defineModel<boolean>({ default: false })

const props = defineProps<{ account: string; password: string }>()
const { copy } = useClipboard()

function handleCopy(value: string) {
  copy(value)
  ElMessage.success('复制成功')
}

function handleSubmit() {
  window.open(`${import.meta.env.VITE_SURVEYKING_URL}?account=${props.account}&password=${props.password}`)
}
</script>

<template>
  <div class="surveyKing-tips" @click="modelValue = true">
    <el-icon><Lock /></el-icon>
  </div>
  <el-dialog title="账号密码" width="500" v-model="modelValue" @closed="$emit('update:modelValue', false)">
    <el-form labelWidth="140" labelSuffix="：">
      <el-form-item label="账号"
        >{{ account }} <el-button text type="primary" @click="handleCopy(account)">复制</el-button></el-form-item
      >
      <el-form-item label="密码"
        >{{ password }} <el-button text type="primary" @click="handleCopy(password)">复制</el-button></el-form-item
      >
    </el-form>
    <template #footer>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-dialog>
</template>

<style lang="scss">
.surveyKing-tips {
  position: fixed;
  right: 40px;
  bottom: 100px;
  width: 50px;
  height: 50px;
  background-color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 10px 0px rgba(0, 0, 0, 0.2);
}
</style>
