<template>
  <v-layout v-if="xistrend === 'Y'">
    <v-flex xs12>
      <v-card class="mb-2" color="white" style="min-height:100px">
        <v-toolbar class="mb-1" color="blue lighten-3" dark height="50px">
          <v-toolbar-title>TREND ANALYS : {{xautoverificationlists.name}}</v-toolbar-title>
          <v-spacer></v-spacer>
        </v-toolbar>
        <v-layout>
          <v-flex xs12 pa-1>
            <v-text-field v-model="ta_minimumtest" label="Minimum Test"></v-text-field>
          </v-flex>
        </v-layout>
        <v-layout>
          <v-flex xs12 pa-1>
            <v-text-field v-model="ta_trendvalue" label="Trend Value"></v-text-field>
          </v-flex>
        </v-layout>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn color="blue darken-1" flat @click="saveFormTrendAnalys()">Simpan</v-btn>
        </v-card-actions>
      </v-card>
    </v-flex>
  </v-layout>
</template>

<style scoped>
</style>

<script>
  module.exports = {
    data: () => ({
      color: "success",
      validtest: false,
      search: "",
      dialogdeletealerttest: false,
      xid: 0,
      msgalerttest: ""
    }),
    computed: {
      xistrend() {
                return this.$store.state.trendanalys.istrend
            },
      vtrendanalyss() {
        return this.$store.state.trendanalys.trendanalyss
      },
      ta_minimumtest: {
        get() {
          return this.$store.state.trendanalys.minimumtest
        },
        set(val) {
          this.$store.commit("trendanalys/update_minimumtest", val)
        }
      },
      ta_trendvalue: {
        get() {
          return this.$store.state.trendanalys.trendvalue
        },
        set(val) {
          this.$store.commit("trendanalys/update_trendvalue", val)
        }
      },
      dialogtrendanalys() {
        return this.$store.state.trendanalys.dialog_form_trend_analys
      },
      xautoverificationlists() {
        return this.$store.state.autoverificationlist.selected_autoverificationlist
      },
      xtests() {
        return this.$store.state.trendanalys.tests
      },
      is_loading() {
        return this.$store.state.trendanalys.search_status == 1
      }
    },
    methods: {
      updateDialogFormTrendAnalys() {
        this.$store.commit("trendanalys/update_dialog_form_trend_analys", false)
      },
      openFormTrendAnalys() {
        this.$store.commit("trendanalys/update_selected_test", {})
        this.$refs.formtrendanalys.reset()
        this.$refs.formtrendanalys.resetValidation()
        this.$store.commit("trendanalys/update_dialog_form_trend_analys", true)
      },
      saveFormTrendAnalys() {
        this.$store.dispatch("trendanalys/save", {
          Nat_TrendAnalysisT_TestID: this.$store.state.autoverificationlist.selected_autoverificationlist.id,
          T_TestName: this.$store.state.autoverificationlist.selected_autoverificationlist.name,
          Nat_TrendAnalysisMinimunTest: this.ta_minimumtest,
          Nat_TrendAnalysisValue: this.ta_trendvalue
        })
      },
      updateAlert_success(val) {
        this.$store.commit("autoverificationlist/update_alert_success", val)
      },
      thr_search: _.debounce(function () {
        this.$store.dispatch("trendanalys/search", {
          id: this.$store.state.autoverificationlist.selected_autoverificationlist.id
        })
      }, 2000),
      deleteTest(data) {
        this.xid = data.id
        console.log(this.xid)
        this.$store.commit("trendanalys/update_selected_test", data)
        this.msgalerttest = "Yakin, mau hapus pemeriksaan " + this.xselected_test.name + "dari autoverificationlist " +
          this.xautoverificationlists.name + "  ?"
        this.dialogdeletealerttest = true
      },
      closeDeleteAlertTest() {
        this.$store.dispatch("trendanalys/delete", {
          xid: this.xid,
          autoverificationlistid: this.$store.state.autoverificationlist.selected_autoverificationlist.id,
          autoverificationlistname: this.$store.state.autoverificationlist.selected_autoverificationlist.name,
          testname: this.xselected_test.name
        })
        this.dialogdeletealerttest = false
      }
    },
    watch: {
      search(val, old) {
        console.log(val)
        if (val !== "" && val !== old && val && val.length > 2) {
          this.$store.commit("trendanalys/update_search", val)
          this.thr_search()
        }
      }
    }
  }
</script>