import router from '@ohos.router';
import { ArrayProcessor } from '../utils/ArrayProcessor';

@Entry
@Component
struct Page1_1 {
  @State message: string = '第1层第1个页面';
  level: number = 1;
  pageNum: number = 1;

  build() {
    Scroll() {
      Column({ space: 20 }) {
        Text(this.message)
          .fontSize(28)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FF6B35')
        
        Text(`这是第${this.level}层的第${this.pageNum}个子页面`)
          .fontSize(16)
          .fontColor('#666666')
        
        this.createNextLevelButtons()
        
        Button('返回首页')
          .width('80%')
          .height(50)
          .backgroundColor('#3498DB')
          .onClick(() => {
            router.pushUrl({
              url: 'pages/Index'
            });
          })
          
        this.generateLargeContent(100)
      }
      .width('100%')
      .padding(20)
    }
    .backgroundColor('#FFF3E0')
  }
  
  @Builder
  createNextLevelButtons() {
    Column({ space: 10 }) {
      Text(`跳转到第2层页面：`)
        .fontSize(18)
        .fontWeight(FontWeight.Bold)
        .fontColor('#333333')
      
      ForEach([1,2,3,4,5,6,7,8,9,10], (num: number) => {
        Button(`前往第2层第${num}个页面`)
          .width('90%')
          .height(45)
          .backgroundColor('#FF8A65')
          .margin({bottom: 5})
          .onClick(() => {
            router.pushUrl({
              url: `pages/Page2_${num}`
            });
          })
      })
    }
  }
  
  @Builder
  generateLargeContent(count: number) {
    ForEach(this.getLargeTextArray(count), (item: string, index: number) => {
      Text(item)
        .fontSize(12)
        .fontColor('#555555')
        .textAlign(TextAlign.Start)
        .margin({top: 8})
    })
  }
  
  getLargeTextArray(count: number): string[] {
    let baseArray: string[] = [];
    for (let i = 0; i < count; i++) {
      baseArray.push(`第${this.level}层第${this.pageNum}个页面的内容片段${i + 1}：这是用于增加包体积的大量文本内容。该页面展示了第${this.level}层级的第${this.pageNum}个子页面，包含丰富的文本信息和导航选项。`);
    }
    
    // 使用复杂的数组处理器
    let processedArray = ArrayProcessor.processLargeArray(baseArray, 3);
    
    // 生成复杂嵌套数组
    let nestedData = ArrayProcessor.generateComplexNestedArrays(15);
    
    // 执行复杂操作
    let complexResult = ArrayProcessor.performComplexOperations(nestedData);
    
    // 将复杂数据转换为字符串数组
    let complexStrings = complexResult.map((item, index) => {
      return `复杂处理结果_${index}: ${JSON.stringify(item).substring(0, 80)}...`;
    });
    
    // 合并所有数组
    let finalArray = [...processedArray, ...complexStrings];
    
    // 再次处理
    let reprocessedArray = ArrayProcessor.processLargeArray(finalArray, 2);
    
    return reprocessedArray;
  }
}