<template>
  <view>
    <!-- see https://uniapp.dcloud.net.cn/component/uniui/uni-popup.html#type-options   -->
    <uniPopup ref="popup" type="dialog" :safeArea="false" :isMaskClick="true" @maskClick="hide" background-color="#fff" borderRadius="20px 20px 20px 20px">
      <uniPopupDialog
        type="dialog"
        :cancelText="TUITranslateService.t('取消')"
        :confirmText="TUITranslateService.t('去申请')"
        :title="TUITranslateService.t('权限申请提示')"
        :content="showContent"
        @confirm="dialogConfirm"
      >
      </uniPopupDialog>
    </uniPopup>
  </view>
</template>
<script>
import vue from '../../adapter-vue';
import uniPopup from "../common/uni-ui/uni-popup/components/uni-popup/uni-popup.vue";
import uniPopupDialog from "../common/uni-ui/uni-popup/components/uni-popup-dialog/uni-popup-dialog.vue";
import { StoreName, TUIStore, TUITranslateService } from '../../@aidesk/uikit-engine';
import { PROMPT } from "../../constant";

const { ref } = vue;

export default {
  components: {
    uniPopup,
    uniPopupDialog,
  },
  data() {
    let promptType = '';
    return {
      promptType,
      TUITranslateService,
    }
  },
  computed: {
    showContent() {
      return TUITranslateService.t(this.promptType);
    }
  },
  methods: {
    show(promptType) {
      this.promptType = promptType;
      // uni vue2 -> app，this.$refs.popup 可能为 undefined，做个防御
      if (this.$refs.popup) {
        this.$refs.popup.open('center');
      }
    },
    hide() {
      if (this.$refs.popup) {
        this.$refs.popup.close();
      }
    },
    dialogConfirm() {
      if (this.promptType === PROMPT.TAKE_PHOTO) {
        uni.setStorageSync('ai-desk-apply-camera', true);
        TUIStore.update(StoreName.CUSTOM, 'applyTakePhoto', true);
      } else if (this.promptType === PROMPT.SELECT_IMAGE) {
        uni.setStorageSync('ai-desk-apply-album', true);
        TUIStore.update(StoreName.CUSTOM, 'applySelectImage', true);
      } else if (this.promptType === PROMPT.SELECT_VIDEO) {
        uni.setStorageSync('ai-desk-apply-album', true);
        TUIStore.update(StoreName.CUSTOM, 'applySelectVideo', true);
      } else if (this.promptType === PROMPT.RECORD) {
        uni.setStorageSync('ai-desk-apply-camera', true);
        TUIStore.update(StoreName.CUSTOM, 'applyRecord', true);
      }
    }
  }
}
</script>
<style scoped lang="scss">
</style>

