<template>
  <datetime-picker
    v-model="valueCopy"
    :schema="schema"
    :min="todaysDate"
    :max="dateInHalfAYear"
    :required="schema.required"
  ></datetime-picker>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import { ValueSync } from '../../tools/decorators';
import datetimePicker from './datetime-picker.vue';
import { SchemaProperty } from '../../types/api';
import { getCmsSettings } from '../../tools/settings';

@Component({
  components: {
    datetimePicker
  }
})
export default class IpWhitelistDatetimePicker extends Vue {
  @ValueSync('value', {}) valueCopy!: null | Date | string;
  @Prop() readonly schema!: SchemaProperty;
  get todaysDate() {
    return new Date();
  }

  get dateInHalfAYear() {
    const setting = getCmsSettings().maxIpWhiteListDays;

    if (setting) {
      return new Date(new Date().setDate(this.todaysDate.getDate() + setting));
    } else {
      return null;
    }
  }
}
</script>
