<script lang="tsx">
import { defineComponent, type PropType } from 'vue'
import { type Moment } from 'moment'
import WeekCalendar from '../../calendars/inputs/week/week-calendar-input.vue'
import { PeriodCalendarFilter } from '../Filters'

export default defineComponent({
  props: {
    filter: {
      type: Object as PropType<PeriodCalendarFilter>,
      required: true,
    },
  },
  setup(props) {
    const setValue = (val: Moment | undefined, isEndVal?: boolean) => {
      const startDate: Moment | undefined = !isEndVal ? val : props.filter.startDate
      const endDate: Moment | undefined = isEndVal ? val : props.filter.endDate

      props.filter.addValue({ startDate, endDate })
    }

    return () => (
      <div class="ark-ui-filterbar-week-calendar-filter">
        <WeekCalendar
          label={props.filter.label}
          start={props.filter.startDate}
          end={props.filter.endDate}
          onSetStart={(v) => setValue(v)}
          onSetEnd={(v) => setValue(v, true)}
        />
      </div>

    )
  },
})
</script>

<style lang="scss" scoped>
.ark-ui-filterbar-week-calendar-filter {
  &:deep {
    .ark-ui-week-calendar-input-body {
      margin-top: 2px;
    }
  }
}
</style>
