<template>
  <b-card bg-variant="light">
    <template v-slot:header>
      <b-row>
        <b-col class="text-left">
          <h5>CEPTD</h5>
        </b-col>
        <b-col class="text-right">
          <b-card-text>Status: Running</b-card-text>
        </b-col>
      </b-row>
    </template>
    <capec-list />
  </b-card>
</template>

<script>
import axios from 'axios'
import CapecList from './CapecList'

export default {
  name: 'CeptdCard',
  components: {
    CapecList
  },
  data () {
    return {
      file: null,
      fields: [
        { key: 'process_id', label: 'Process' },
        { key: 'created_at', label: 'Running for' },
        { key: 'actions', label: 'Actions' }
      ],
      analyzePid: '',
      items: []
    }
  },
  created () {
    this.status()
  },
  methods: {
    async start () {
      try {
        await axios.get('/v1/od/start')
        this.status()
        this.$toasted.success('OD instance started!')
      } catch (e) {
        this.$toasted.error('There was an error!')
      }
    },
    async status () {
      try {
        const { data } = await axios.get('/v1/od/status')
        this.items = data
      } catch (e) {
        this.$toasted.error('There was an error while fetching running OD instances!')
      }
    },
    async showPcapModal (pid) {
      this.analyzePid = pid
      this.$refs['pcap-modal'].show()
    },
    async stop (pid) {
      try {
        await axios.get('/v1/od/stop/' + pid)
        this.status()
        this.$toasted.success('OD instance stopped!')
      } catch (e) {
        this.$toasted.error('There was an error!')
      }
    }
  }
}
</script>

<style scoped>

</style>
