/*
 * 录像类型切换
 * EZOpenSDK
 *
 * Created by junecheng on 2024/5/31.
 * Copyright (c) 2024年 Ezviz. All rights reserved.
 */
@Component
export default struct PlaybackRecordToolView {
  @State recordCategory: EZRecordCategory = EZRecordCategory.EZRecordCategoryCloud
  onRecordCategoryTabClick?: (category: EZRecordCategory) => void
  // tab指示器下划线宽高
  @State tabIndicateViewWidth: number = 100
  @State tabIndicateViewHeight: number = 2

  build() {
    Row() {
      // 云录像
      Column() {
        Text($r('app.string.playback_cloud_storage'))
          .fontColor(this.recordCategory == EZRecordCategory.EZRecordCategoryCloud ? $r('app.color.ez_text_blue') :
          Color.Black)
          .textAlign(TextAlign.Center)
          .layoutWeight(1)
          .onClick(() => {
            if (this.onRecordCategoryTabClick && this.recordCategory != EZRecordCategory.EZRecordCategoryCloud) {
              this.recordCategory = EZRecordCategory.EZRecordCategoryCloud
              this.onRecordCategoryTabClick(EZRecordCategory.EZRecordCategoryCloud)
            }
          })
        Text()
          .backgroundColor($r('app.color.ez_text_blue'))
          .width(this.tabIndicateViewWidth)
          .height(this.tabIndicateViewHeight)
          .visibility(this.recordCategory == EZRecordCategory.EZRecordCategoryCloud ? Visibility.Visible :
          Visibility.Hidden)
      }.width(`50%`)

      Divider().vertical(true).height(28).color(Color.Gray)
      // SD卡录像
      Column() {
        Text($r('app.string.playback_sdcard_storage'))
          .fontColor(this.recordCategory == EZRecordCategory.EZRecordCategoryDevice ? $r('app.color.ez_text_blue') :
          Color.Black)
          .textAlign(TextAlign.Center)
          .layoutWeight(1)
          .onClick(() => {
            if (this.onRecordCategoryTabClick && this.recordCategory != EZRecordCategory.EZRecordCategoryDevice) {
              this.recordCategory = EZRecordCategory.EZRecordCategoryDevice
              this.onRecordCategoryTabClick(EZRecordCategory.EZRecordCategoryDevice)
            }
          })
        Text()
          .backgroundColor($r('app.color.ez_text_blue'))
          .width(this.tabIndicateViewWidth)
          .height(this.tabIndicateViewHeight)
          .visibility(this.recordCategory == EZRecordCategory.EZRecordCategoryDevice ? Visibility.Visible :
          Visibility.Hidden)
      }.width(`50%`)
    }
    .justifyContent(FlexAlign.SpaceEvenly)
    .width('100%')
    .height(44)
    .id('toolView')
    .alignRules({
      top: { 'anchor': 'cloud_ad', align: VerticalAlign.Bottom }
    })
  }
}

/**
 * 录像类别
 */
export const enum EZRecordCategory {
  EZRecordCategoryCloud = 0, // 云存储
  EZRecordCategorySDKCloud, // SDK云录制
  EZRecordCategoryDevice, // SD卡录像
}