/**
 * 养殖标准相关页：上架/知识库状态文案 + stdT（按组件 data.stdNs 取模块文案）
 */
export default {
  methods: {
    stdT(key) {
      const ns = this.stdNs
      if (!ns) {
        return key
      }
      return this.$t(`breedingStd.${ns}.${key}`)
    },
    publishStatusText(v) {
      if (v === 0) {
        return this.$t("breedingStd.status.unpublished")
      }
      if (v === 1) {
        return this.$t("breedingStd.status.published")
      }
      if (v === 2) {
        return this.$t("breedingStd.status.unpublished")
      }
      return this.$t("breedingStd.status.dash")
    },
    kbSyncStatusText(v) {
      if (v === 0) {
        return this.$t("breedingStd.status.kbUnsynced")
      }
      if (v === 1) {
        return this.$t("breedingStd.status.kbSynced")
      }
      return this.$t("breedingStd.status.dash")
    },
    /** 确认后执行同步知识库，带全局 loading */
    runSyncKbAfterConfirm(confirmMessage, syncFn) {
      let syncLoading = false
      return this.$modal
        .confirm(confirmMessage)
        .then(() => {
          syncLoading = true
          this.$modal.loading(this.$t("breedingStd.common.syncKbLoading"))
          return syncFn()
        })
        .finally(() => {
          if (syncLoading) {
            this.$modal.closeLoading()
          }
        })
    },
    /** 确认后执行移出知识库，带全局 loading */
    runRemoveKbAfterConfirm(confirmMessage, removeFn) {
      let removeLoading = false
      return this.$modal
        .confirm(confirmMessage)
        .then(() => {
          removeLoading = true
          this.$modal.loading(this.$t("breedingStd.common.removeKbLoading"))
          return removeFn()
        })
        .finally(() => {
          if (removeLoading) {
            this.$modal.closeLoading()
          }
        })
    }
  }
}
