/*
 * 功能测试页面
 * EZOpenSDK
 *
 * Created by junecheng on 2024/4/19.
 * Copyright (c) 2024年 Ezviz. All rights reserved.
 */
import RouterManager from '../../global/RouterManager/RouterManager'
import EZToastUtil from '../../utils/EZToastUtil'
import { PreferenceUtil } from '../../utils/PreferenceUtil'
import { NavigationView } from '../../global/view/NavigationView'
import PreviewList, { ListItemData } from '../../global/view/PreviewList'

@Entry
@Component
struct EZTestPage {
  // 数据源
  @State private listData: ListItemData[] = []

  // ------------------------ 生命周期 ------------------------

  aboutToAppear() {
    // 初始化数据源
    this.listData = [
      {
        mainTitle: 'P2P测试',
        subTitle: 'EZP2pTestPage',
        onItemClick: (): void => {
          RouterManager.pushUrl(RouterManager.p2pTestPage)
        }
      },
      {
        mainTitle: '取流方式设置',
        onItemClick: (): void => {
          RouterManager.pushUrl(RouterManager.streamTypeSettingPage)
        }
      },
      {
        mainTitle: '小权限tkToken设置',
        subTitle: 'EZTKTokenTestPage',
        onItemClick: (): void => {
          RouterManager.pushUrl(RouterManager.tkTokenTestPage)
        }
      },
      {
        mainTitle: '接口测试',
        subTitle: 'EZHttpInterfaceTestPage',
        onItemClick: (): void => {
          RouterManager.pushUrl(RouterManager.httpInterfaceTestPage)
        }
      },
      {
        mainTitle: '设备验证码清空',
        subTitle: '',
        onItemClick: (): void => {
          AlertDialog.show({
            title: "是否清空所有设备验证码",
            alignment: DialogAlignment.Center,
            message: '',
            primaryButton: {
              value: $r('app.string.dialog_cancel'),
              action: () => {
              }
            },
            secondaryButton: {
              value: $r('app.string.dialog_ok'),
              action: () => {
                PreferenceUtil.clear(getContext())
                EZToastUtil.showToast('所有设备验证码已清空')
              }
            }
          })
        }
      },
      {
        mainTitle: '查看今天CrashLog',
        subTitle: '',
        onItemClick: async () => {
          RouterManager.pushUrl(RouterManager.showCrashLogTesPage)
        }
      }
    ]

  }

  aboutToDisappear() {

  }

  // ------------------------ Actions ------------------------

  // ------------------------ 网络请求 ------------------------

  // ------------------------ 自定义方法 ------------------------

  // ------------------------ UI ------------------------

  build() {
    Column() {
      NavigationView({
        title: '萤石功能测试'
      })
      PreviewList({
        items: this.listData
      })
    }.width('100%').height('100%')
  }
}
