<script>
export default {
  props: {
    value: {
      default: null,
      demoValue: () => new Date()
    },
    schema: {
      type: Object,
      required: true
    },
    required: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      popupVisible: false,
      focus: this.value ? this.value : ''
    };
  },
  computed: {
    valueCopy: {
      get() {
        return this.value ? this.value.toString().match(/\d\d:\d\d/)[0] : '';
      },
      set(value) {
        this.$emit('input', value);
      }
    },
    title() {
      return this.getTime();
    }
  }
};
</script>

<template>
  <div class="time-picker" :class="{ readonly: readonly }">
    <input
      type="time"
      class="form-control"
      :readonly="readonly"
      :value="valueCopy"
      @change="valueCopy = $event.target.value"
      placeholder="(geen)"
    />
    <span class="icon-cross" @click.stop="valueCopy = null" v-if="value && !required && !readonly"></span>
  </div>
</template>

<style scoped lang="scss">
.time-picker {
  position: relative;

  .icon-cross {
    position: absolute;
    right: 2.5em;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: 0.3s opacity ease;
  }

  &:hover .icon-cross {
    opacity: 0.5;

    &:hover {
      opacity: 1;
    }
  }

  &:not(.readonly) {
    .form-control {
      background: white;
      margin-bottom: 0;
    }
  }
}
</style>
