// pages/settings/about/update-log/update-log.js
const app = getApp();

Page({
  data: {
    currentVersion: 'v1.0.0',
    currentVersionDate: '2023-10-15',
    updateLogs: [],
    hasMoreLogs: true,
    page: 1,
    pageSize: 5,
    isRefreshing: false,  // 可保留但不再使用
    isLoading: false,
    menuButtonInfo: {
      height: 32,
      width: 32,
      left: 20,
      top: 20
    },
    statusBarHeight: 0
  },

  onLoad: function() {
    try {
      const systemInfo = wx.getSystemInfoSync();
      const menuButtonInfo = wx.getMenuButtonBoundingClientRect();

      this.setData({
        statusBarHeight: systemInfo.statusBarHeight,
        menuButtonInfo: menuButtonInfo || this.data.menuButtonInfo
      });
    } catch (e) {
      console.error('获取系统信息失败:', e);
    }

    this.loadUpdateLogs();
  },

  onShow: function() {
    // 页面显示
  },

  // 移除下拉刷新相关方法
  // onPullDownRefresh: function() {
  //   this.setData({
  //     isRefreshing: true,
  //     page: 1
  //   });
  //
  //   // 模拟网络请求
  //   setTimeout(() => {
  //     this.loadUpdateLogs();
  //     wx.stopPullDownRefresh();
  //     this.setData({ isRefreshing: false });
  //   }, 1000);
  // },

  onReachBottom: function() {
    if (!this.data.hasMoreLogs || this.data.isLoading) {
      return;
    }

    this.loadMoreLogs();
  },

  loadUpdateLogs: function() {
    const logs = [
      {
        version: 'v1.0.0',
        date: '2023-10-15',
        newFeatures: [
          '• 初始版本发布',
          '• 实现位置共享功能',
          '• 新增消息推送机制'
        ],
        improvements: [
          '• 优化地图加载速度',
          '• 提升用户界面响应速度'
        ],
        fixes: [
          '• 修复已知的兼容性问题',
          '• 解决部分机型的闪退问题'
        ]
      },
      {
        version: 'v0.9.0',
        date: '2023-09-20',
        newFeatures: [
          '• 测试版本发布',
          '• 核心功能开发完成'
        ],
        improvements: [
          '• 优化用户体验',
          '• 提升系统稳定性'
        ],
        fixes: []
      },
      {
        version: 'v0.8.5',
        date: '2023-08-15',
        newFeatures: [],
        improvements: [
          '• 改进定位精度',
          '• 优化电池使用效率'
        ],
        fixes: [
          '• 修复消息发送失败问题',
          '• 解决地图显示异常'
        ]
      }
    ];

    this.setData({
      updateLogs: logs,
      hasMoreLogs: logs.length >= this.data.pageSize
    });
  },

  loadMoreLogs: function() {
    if (this.data.isLoading || !this.data.hasMoreLogs) {
      return;
    }

    this.setData({ isLoading: true });

    setTimeout(() => {
      const moreLogs = [
        {
          version: 'v0.8.0',
          date: '2023-07-10',
          newFeatures: [
            '• 新增聊天功能',
            '• 添加好友系统'
          ],
          improvements: [
            '• 优化应用启动速度',
            '• 改进用户界面布局'
          ],
          fixes: []
        },
        {
          version: 'v0.7.0',
          date: '2023-06-05',
          newFeatures: [
            '• 基础地图功能上线',
            '• 用户注册登录系统'
          ],
          improvements: [],
          fixes: []
        }
      ];

      const updatedLogs = [...this.data.updateLogs, ...moreLogs];

      this.setData({
        updateLogs: updatedLogs,
        hasMoreLogs: false,
        isLoading: false,
        page: this.data.page + 1
      });
    }, 1500);
  },

  navigateBack: function() {
    wx.navigateBack();
  },

  onShareAppMessage: function() {
    return {
      title: 'FindMe 更新日志',
      path: '/subpackages/settings/about/update-log/update-log',
      imageUrl: '/images/findme-logo.png'
    };
  }
});



