<template>
  <ui-select
    v-on="$listeners"
    v-bind="$attrs"
    label="Отправитель"
    name="carrier"
    :loading="isLoading"
    :options="carriers"
    option-value="uid"
    option-label="name"
    emit-value
    map-options
  />
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { Carrier } from '../../dto/Carrier'
import UiSelect from '../../../../form/UiSelect.vue'
import DeliveryTrackingService from '../../services/DeliveryTrackingService'

@Component({
  inheritAttrs: false,
  components: { UiSelect },
})
export default class TrackCarrierSelect extends Vue {
  carriers: Carrier[] = []
  isLoading = false

  created() {
    this.isLoading = true

    DeliveryTrackingService.getCarriers()
      .then(carriers => (this.carriers = carriers))
      .finally(() => (this.isLoading = false))
  }
}
</script>
