<template>
  <section class="loading">
    <!--    <div class="iconfont iconfont-iconWeChat"/>-->
    <!--    <div class="iconfont iconfont-iconjuminxinxi"/>-->
    <!--    <div class="iconfont iconfont-iconLogo"/>-->
    <ai-result v-if="result.tips" v-bind="result"/>
    <input v-if="!!$route.query.code" class="codeText" :value="$route.query.code"/>
    <input class="codeText" v-model="search" placeholder="搜索要查找的应用"/>
    <div flex class="appsPane wrap">
      <div class="item" flex v-for="app in appsList" :key="app.id" @tap="handleGotoApp(app)">
        <b v-text="app.label"/>
        <u-tag v-if="app.project" :text="app.project" mode="dark" shape="circle" size="mini"/>
        <div class="appName fill" v-text="app.name"/>
      </div>
    </div>
  </section>
</template>

<script>
import {mapActions, mapState} from 'vuex'
import AiResult from "../components/AiResult";
import AiSelect from "../components/AiSelect";

export default {
  name: 'loading',
  components: {AiSelect, AiResult},
  inject: ['root'],
  computed: {
    ...mapState(['apps']),
    appsList() {
      let {search} = this
      return this.apps.filter(e => {
        if (/\/project\//.test(e.libPath)) {
          e.project = e.libPath.replace(/.*project\/([^\/]+)\/.+/, '$1')
        }
        return e
      }).filter(e => !!search ? e.label?.indexOf(search) > -1 : true) || []
    },
    currentApp() {
      return this.apps.find(e => e.key == this.$route.query.app) || {}
    }
  },
  data() {
    return {
      result: {},
      search: ""
    }
  },
  methods: {
    ...mapActions(['agentSign']),
    handleGotoApp(app) {
      uni.navigateTo({url: `${app.libPath}`})
    },
  },
  onLoad() {
    this.agentSign(this.$route.query)
  },
  onShow() {
    this.result = {
      tips: "欢迎进入开发应用",
    }
  }
}
</script>

<style lang="scss" scoped>
.loading {
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;

  & > span {
    font-size: 36px;
  }

  .codeText {
    font-size: 24px;
    margin-top: 16px;
    padding: 4px 0;
    width: 100%;
    text-align: center;
    background: #ccc;
  }

  .codeBtn {
    width: 180px;
    text-align: center;
    cursor: pointer;
    font-size: 24px;
    background: $uni-color-warning;
    color: #fff;
    padding: 8px;
    margin-top: 16px;
    border-radius: 8px;
    font-weight: normal;
  }

  .appsPane {
    justify-content: center;
    margin-top: 16px;

    .item {
      width: 100vw;
      font-size: 28px;
      padding: 0 32px;
      height: 64px;
      border-bottom: 1px solid #ddd;
      box-sizing: border-box;

      &:nth-of-type(2n) {
        background: rgba(#26f, .02);
      }
    }

    b {
      cursor: pointer;
      margin-right: 16px;
      display: block;
    }

    .appName {
      text-align: right;
    }
  }
}
</style>
