<template>
  <div>
    <div class="row">
      <div class="col-xs-1 col-md-4"></div>
      <div class="col-xs-10 col-md-4">
        <h6 style="text-align: center;margin: 1rem;">节点</h6>
        <q-input v-model="text" filled autogrow />
      </div>
    </div>
    <div v-if="isobj">
      <div class="row" v-for="(item, index) in serve" :key="index">
        <div class="col-xs-1 col-md-4"></div>
        <div class="col-xs-10 col-md-4">
          <LinkItem :serve="item" v-model:text="text"></LinkItem>
        </div>
      </div>
    </div>


  </div>
</template>

<script lang="ts">
import { server } from 'components/models';
import { computed, defineComponent, onMounted, ref } from 'vue';
import { getdata } from 'src/api/api'
import LinkItem from 'components/LinkItem.vue';
import { b64decode } from '@waiting/base64'
import { encode, decode } from 'js-base64';
export default defineComponent({
  name: 'IndexPage',
  components: { LinkItem },
  setup() {
    const serve = ref(<server[]>[])
    const api = new getdata;
    const text = ref('');
    onMounted(() => {
      api.get_server().then((res) => {
        for (let index = 0; index < res.data.length; index++) {
          serve.value.push(res.data[index]);
        }
      })
    })
    const isobj = computed(() => {
      try {
        let obj = JSON.parse(decode(text.value.replace('vmess://', '')));
        if (obj.id != '2ee57806-f6e4-482a-ef08-7360c04cd3e5' || obj.net != 'ws') {
          return false
        }
      } catch (error) {
        console.log(error);
        return false
      }

      return true
    })
    return {
      serve,
      text,
      isobj
    };
  }
});
</script>
