<template>
  <h2 class="tool-title">Explain crontab</h2>
  <hr class="mt-5 mb-5">

  <div class="input-group">
    <label for="data">Data</label>
    <input id="data" class="input" v-model="toolData.data" v-on:keyup="result" placeholder="* * * * *" type="text">
  </div>

  <hr class="mt-5 mb-5">

  <div class="input-group">
    <label for="result">Result</label>
    <MonacoEditor name="result" language="json" :value="toolResult"></MonacoEditor>
  </div>
</template>

<script>
import cronstrue from 'cronstrue';
import MonacoEditor from "@/components/MonacoEditor.vue";

export default {
  components: {
    MonacoEditor
  },
  data() {
    return {
      toolData: {
        data: '* * * * *',
      },
      toolResult: '',
    };
  },
  mounted() {
    this.toolResult = cronstrue.toString(this.toolData.data, {
      use24HourTimeFormat: true,
      verbose: true,
    });
  },
  methods: {
    result() {
      try {
        this.toolResult = cronstrue.toString(this.toolData.data, {
          use24HourTimeFormat: true,
          verbose: true,
        });
      } catch (e) {
        this.toolResult = 'invalid syntax';
      }
    },
  },
}
</script>

<style lang="scss">

</style>