<script>
import { get } from '@/utils/object';
import demoSpecs from '@/config/demo-stacks';

import Card from '@/components/Card';
export default {
  components: { Card },
  data() {
    return {
      demos: [
        {
          title:       'Deploy service using a Dockerfile',
          demo:        'serviceFromGit',
          description: 'Clicking deploy will prefill the image section of Service with a Dockerfile.',
          createPath:  '/rio/services/create'
        },
        {
          title:       'Deploy stack using a Riofile',
          demo:        'stackFromGit',
          description: 'Deploying a stack allows multiple resources to be deployed at once and updated through a rio file you keep in GitHub. Clicking deploy will pre-fill the stack fields with a demo rio file.',
          createPath:  '/rio/stack/create'
        },
        {
          title:       'Autoscaling',
          demo:        null,
          description: 'Coming Soon.',
          createPath:  null
        },
        {
          title:       'Service Mesh',
          demo:        null,
          description: 'Coming Soon.',
          createPath:  null
        }
      ]
    };
  },
  methods: {
    createDemo(index) {
      this.$router.push({ path: this.demos[index].createPath, query: { demo: this.demos[index].demo } });
    },
    repoUrl(demo) {
      const spec = demoSpecs[demo];

      return get(spec, 'build.repo');
    }
  }
};
</script>

<template>
  <div>
    <header>
      <h1>
        Discover Rio
      </h1>
      <br>
      <span class="subtitle">Deploy preconfigured sample snacks</span>
    </header>
    <div class="row">
      <div class="col span-6">
        <div class="cards">
          <Card
            v-for="(demo, i) in demos"
            :key="demo.title"
            :content="demo.description"
          >
            <template v-slot:title>
              <span>{{ demo.title }}</span>
              <a target="_blank" class="icon icon-external-link role-multi-action" :href="repoUrl(demo.demo)" />
            </template>
            <template v-slot:actions>
              <button class="btn role-secondary btn-sm" :disabled="!demo.demo" @click="e=>createDemo(i)">
                Deploy
              </button>
            </template>
          </Card>
        </div>
      </div>
      <div class="col span-6">
        <img src="~/assets/images/setup-step-one.svg" alt="landscape" />
      </div>
    </div>
  </div>
</template>

<style lang='scss'>
    .subtitle{
        margin-top: 20px;
    }
    .cards {
         margin-right: 20px;
        // width: 50%;
        display: grid;
        grid-template-columns:  50% 50%;
        grid-row-gap: 20px;
        grid-column-gap: 20px;
        & > * {
            align-content: center;
        }
        & span.icon{
            padding: 3px;
        }
    }
</style>
