<template>
  <view>
    <view class="mx-4 pt-5 text-base">
      <view class="text-sm">
        <view v-if="type === 'remoteUnlock'">
          功能开启后，你将可以通过网关远程开锁。此功能的开启和关闭只能在锁附近通过手机蓝牙进行。
        </view>
        <view v-if="type === 'resetSwitch'">
          开启后，可通过长按锁上的设置键重新上电，用APP重新添加
        </view>
        <view v-if="type === 'resetSwitch'" class="mt-3">
          关闭后，重置键无效，锁要通过app删除后才能重新添加
        </view>
        <view v-if="type === 'antiPrySwitch'"> 开启后，锁被撬动时，会发出报警声 </view>
        <view class="mt-5 font-bold"
          >当前模式：{{
            $bluetooth.currentLockSetting.lockSettingInfo[type] === 1 ? '已开启' : '已关闭'
          }}</view
        >
      </view>
      <view
        @click="update"
        class="w-full bg-#4777ee text-white line-height-80rpx h-80 rounded-40rpx text-center mt-4 text-lg font-bold"
        >{{ $bluetooth.currentLockSetting.lockSettingInfo[type] === 1 ? '关闭' : '开启' }}</view
      >
    </view></view
  >
</template>

<script setup>
  import { onLoad } from '@dcloudio/uni-app'
  import { getCurrentInstance, ref } from 'vue'
  import { useBluetoothStore } from '@/stores/bluetooth'

  const instance = getCurrentInstance().proxy
  const eventChannel = instance.getOpenerEventChannel()

  const $bluetooth = useBluetoothStore()

  const type = ref('')

  const update = async () => {
    eventChannel.emit('changeSetting', {})
  }

  onLoad(options => {
    type.value = options.key
    let title = ''
    if (type.value === 'resetSwitch') {
      title = '重置键'
    } else if (type.value === 'remoteUnlock') {
      title = '远程开锁'
    } else if (type.value === 'antiPrySwitch') {
      title = '防撬报警'
    }
    uni.setNavigationBarTitle({
      title
    })
  })
</script>

<style lang="scss">
  page {
    background-color: $uni-bg-color-grey;
  }
</style>
