/**
 * 版本号显示组件
 * 使用方法：
 * <version-badge />
 */

const versionInfo = require('../../utils/version.js');

Component({
  properties: {
    // 是否显示详细信息（构建编号、commit SHA）
    showDetail: {
      type: Boolean,
      value: false
    },
    // 是否显示构建时间
    showTime: {
      type: Boolean,
      value: false
    }
  },

  data: {
    version: versionInfo.version,
    buildNumber: versionInfo.buildNumber,
    buildTime: versionInfo.buildTime,
    commitSha: versionInfo.commitSha
  },

  lifetimes: {
    attached() {
      // 格式化构建时间
      if (this.data.buildTime && this.data.buildTime !== 'unknown') {
        const date = new Date(this.data.buildTime);
        const formatted = date.toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit'
        });
        this.setData({ formattedTime: formatted });
      }
    }
  }
});
