class PageBase {
  constructor(path, vue) {
    this.path = path
    this.name = path.replace(/.*[\\\/]([^\\\/]+)$/g, '$1')
    this.init(vue)
  }

  init(vue) {
    if (/appName/.test(vue)) {
      let appName = vue.replace(/[\s\S]*(appName:.+),[\s\S]*/gm, '$1')
      this.label = appName.replace(/(appName:|["'])/g, '')?.trim()
    }
    if (/customNavigation/.test(vue)) {
      this.style = {
        navigationStyle: "custom",
      }
      if (/navigationBarTextStyle/.test(vue)) {
        this.style.navigationBarTextStyle = vue.replace(/[\s\S]*navigationBarTextStyle:([^,]+),[\s\S]*/gm, '$1').replace(/["']/g, '')?.trim()
      }
      //导航栏背景颜色（同状态栏背景色）
      if (/navigationBarBackgroundColor/.test(vue)) {
        this.style.navigationBarBackgroundColor = vue.replace(/[\s\S]*navigationBarBackgroundColor:([^,]+),[\s\S]*/gm, '$1').replace(/["']/g, '')?.trim()
      }
    } else {
      this.style = {navigationBarTitleText: this.label}
      //是否开启下拉刷新
      if (/enablePullDownRefresh/.test(vue)) {
        this.style.enablePullDownRefresh = true
      }
      //导航栏标题颜色及状态栏前景颜色，仅支持 black/white
      if (/navigationBarTextStyle/.test(vue)) {
        this.style.navigationBarTextStyle = vue.replace(/[\s\S]*navigationBarTextStyle:([^,]+),[\s\S]*/gm, '$1').replace(/["']/g, '')?.trim()
      }
      //导航栏背景颜色（同状态栏背景色）
      if (/navigationBarBackgroundColor/.test(vue)) {
        this.style.navigationBarBackgroundColor = vue.replace(/[\s\S]*navigationBarBackgroundColor:([^,]+),[\s\S]*/gm, '$1').replace(/["']/g, '')?.trim()
      }
      // //下拉显示出来的窗口的背景色
      // if (/backgroundColor/.test(vue)) {
      //   this.style.backgroundColor = vue.replace(/[\s\S]*(backgroundColor:.+),[\s\S]*/gm, '$1')
      // }
    }
  }

  setLabel(name) {
    this.label = name
  }
}

module.exports = PageBase
