<template>
  <div class="row q-gutter-x-md">
    <x-date-input
      :value="from"
      label="от"
      hide-bottom-space
      class="font-12"
      :defaultView="fromDefaultView"
      @input="inputHandler($event, 'from')"
    />
    <x-date-input
      :value="to"
      label="до"
      hide-bottom-space
      class="font-12"
      :defaultView="toDefaultView"
      @input="inputHandler($event, 'to')"
    />
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import XDateInput from './x-date-input.vue';
import { QDate as QDateType } from 'quasar/dist/types';

@Component({
  components: { XDateInput },
})
export default class XDateRange extends Vue {
  @Prop() private from!: Date;
  @Prop() private to!: Date;

  @Prop() private fromDefaultView: QDateType["defaultView"];
  @Prop() private toDefaultView: QDateType["defaultView"];

  private inputHandler($event: any, field: string): void {
    this.$emit(`update:${field}`, $event);
    this.$emit('input', {
      from: this.from,
      to: this.to,
    });
  }
}
</script>
