/*
 * 崩溃日志查看页面
 * EZOpenSDK
 *
 * Created by junecheng on 2024/5/7.
 * Copyright (c) 2024年 Ezviz. All rights reserved.
 */
import EZCrashUtil from '../../utils/EZCrashUtil'
import EZToastUtil from '../../utils/EZToastUtil'
import { NavigationView } from '../../global/view/NavigationView'

@Entry
@Component
struct EZShowCrashLogPage {
  @State crashLog: string = ""
  private scroller: Scroller = new Scroller()

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

  async aboutToAppear() {
    this.crashLog = await EZCrashUtil.readErrorText()
    if (!this.crashLog) {
      EZToastUtil.showToast('今天暂无crashLog')
      this.crashLog = `今天暂无crashLog`
    }
  }

  aboutToDisappear() {

  }

  build() {
    Column() {
      NavigationView({
        showRightBtn: true,
        title: 'CrashLog',
        rightNavTitle: '导出',
        rightNavClick: () => {
          if (!this.crashLog || this.crashLog == '今天暂无crashLog') {
            EZToastUtil.showToast('今天暂无crashLog')
            return
          }
          EZCrashUtil.onExportErrorLog()
        }
      })
      Scroll(this.scroller) {
        Text(this.crashLog)
          .copyOption(CopyOptions.LocalDevice)
        // .visibility(this.crashLog ? Visibility.Visible : Visibility.None)
      }.padding(10)
    }.width('100%').height('100%')
  }
}