import { router } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
import logManager, { LogCategory, LogEventType } from '../common/logtext';

@Entry
@Component
@Preview
struct Login {
  @State message: string = 'Hello World';
  @State username: string = ''; // 用户名
  @State password: string = ''; // 密码
  build() {
    Column({space:10}){//列布局
      Image('http://139.155.155.67:2342/images/tdcat.webp')
        .height(150)

      //分割线组件
      Divider()

      Text("唱跳 rap 篮球").fontColor(Color.Green).fontSize(30)

      Row(){
        Text("用户名：")
        TextInput({placeholder:'请输入账号'})//输入提示
          .width(250)
          .onChange((value: string) => {
            this.username = value; // 绑定用户名输入
          })
      }


      Row(){
        Text("密码：")
        TextInput({placeholder:'请输入密码'})
          .type(InputType.Password)//输入模式
          .width(270)
          .onChange((value: string) => {
            this.password = value; // 绑定密码输入
          })
      }

      Button("登录")
        .onClick(()=>{
          if (this.username === '1' && this.password === '1') {
            router.pushUrl({url:'pages/HomePage'})
          }else {
            AlertDialog.show({message:'输入有误'})
          }

        })

        .width('50%')


      Row(){//行布局
        Button("忘记密码？")
          .fontSize(15)
          .backgroundColor(Color.Gray)
          .onClick(()=>{
            AlertDialog.show({message:"尚未开发"})
          })

        Blank(150)//间隔
        Button("注册")
      }

    }
    .height('100%')
    .width('100%')
    .padding(20)
    .alignItems(HorizontalAlign.Center)
  }
  // 页面生命周期方法
  onPageShow(): void {// 页面显示时触发的生命周期方法
    this.Log_LoginEvent('onPageShow');
  }

  onPageHide(): void {// 页面隐藏时触发的生命周期方法
    this.Log_LoginEvent('onPageHide');
  }

  onBackPress(): void {// 页面返回按键按下时触发的生命周期方法
    this.Log_LoginEvent('onBackPress');
  }

  aboutToAppear(): void {// 页面即将显示时触发的生命周期方法
    this.Log_LoginEvent('aboutToAppear');
  }

  aboutToDisappear(): void {// 页面即将消失时触发的生命周期方法
    this.Log_LoginEvent('aboutToDisappear');
  }

  // 通用日志记录方法
  public Log_LoginEvent(eventName: string): void {
    // 根据事件名称选择合适的日志事件类型
    switch (eventName) {
      case 'aboutToAppear':
        logManager.info(LogCategory.USER, LogEventType.PAGE_APPEAR, 'LoginPage');
        break;
      case 'aboutToDisappear':
        logManager.info(LogCategory.USER, LogEventType.PAGE_DISAPPEAR, 'LoginPage');
        break;
      case 'onPageShow':
        logManager.info(LogCategory.USER, LogEventType.PAGE_SHOW, 'LoginPage');
        break;
      case 'onPageHide':
        logManager.info(LogCategory.USER, LogEventType.PAGE_HIDE, 'LoginPage');
        break;
      case 'onBackPress':
        logManager.info(LogCategory.USER, LogEventType.PAGE_BACK, 'LoginPage');
        break;
      default:
        logManager.info(LogCategory.USER, LogEventType.SYSTEM_INFO, `LoginPage: ${eventName}`);
    }
  }


}
/*
interface User{
  uname:string
  upwd:string
}
class Userinfo{
  uname:string
  upwd:string

  constructor(uname: string, upwd: string) {
    this.uname = uname;
    this.upwd = upwd;
  }
}*/
