<template>
	<div id="Account">
		<!-- breadcrumb -->
        <nav class="text-sm font-semibold mb-6" aria-label="Breadcrumb">
            <ol class="list-none p-0 inline-flex">
				<li class="flex items-center text-blue-500">
					<a href="#" class="text-gray-700">Account</a>
						<svg class="fill-current w-3 h-3 mx-3" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/></svg>
                </li>
                <!-- <li class="flex items-center">
					<a href="#" class="text-gray-600"></a>
                </li> -->
            </ol>
        </nav>
        <!-- breadcrumb end -->

        <div class="lg:flex justify-between items-center mb-6">
            <p class="text-xl mb-2 lg:mb-0">Welcome, {{getInfo.didHash}}</p>
        </div>

        <div class="flex flex-wrap -mx-3 mb-20">
        </div>
	</div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'DashboardHome',
  data() {
      return {
    getInfo:{},
      }
  },
  methods:{
	
    getInfoFn: function () {
      
      console.log("loading getInfo")

      axios.get('http://localhost:1898/getInfo')
      .then((response) => {

        console.log(response);
        this.getInfo = response.data.data.payload
        console.log(this.getInfo)
      })
      .catch(function (error) {
        console.log(error);
      });
    },

    checkStatus: function () {
      
      console.log("loading DID exists")

      axios.get('http://localhost:1898/checkDidExists')
      .then((response) => {

        console.log(response);
        if(response.data.data.payload == 'Failure'){
          console.log("moving to create DID")
          this.$router.push({path: '/create-new-DID'})
          return;
        } else {
          console.log("loading DID verified")
            axios.get('http://localhost:1898/checkDidVerified')
            .then((response) => {
              this.isVerified = response.data.data.payload
              console.log(response);
              if(response.data.data.payload == 'Failure'){
                console.log("moving to create DID [check]")
                this.$router.push({path: '/verification'})
                return;
              }
            })
            .catch(function (error) {
              console.log(error);
              this.$router.push({path: '/verification'})
              return;
            });
        }
      })
      .catch(function (error) {
        console.log(error);
        this.$router.push({path: '/create-new-DID'})
        return;
      });
      axios.get('http://localhost:1898/checkRole')
      .then((response) => {

        console.log(response);
        // this.myRole = response.data.data.payload
      })
      .catch(function (error) {
        console.log(error);
        // this.$router.push({path: '/create-new-DID'})
      });
    },

    getAccountInfo: function () {
      
      console.log("loading getAccountInfo")

      axios.get('http://localhost:1898/getAccountInfo')
      .then((response) => {

        console.log(response);
        this.did = response.data.did

      })
      .catch(function (error) {
        console.log(error);
      });
    },
  },
  beforeMount() {
    this.getAccountInfo()
    this.checkStatus()
  }
}
</script>