import RecoSelectLocation from '@/components/complex/RecoSelectLocation.vue';

/*
* Builds category select modal
* -----------------------------------------------------------
* self object needs to contain the following reactive keys:
*  - distance
*  - locationSelectModal
*/

export default (self, title, description, withoutDevLocation) => {
  let propsData = {
    selectedDistance: self.distance,
    selectedDevLocation: self.devLocation,
    doneButtonClicked: () => { self.locationSelectModal.dismiss() },
  }
  if (title) {
    propsData.title = title;
  }
  if (description) {
    propsData.description = description;
  }
  if (withoutDevLocation) {
    propsData.withoutDevLocation = withoutDevLocation;
  }
  return self.$ionic.modalController.create({
    component: RecoSelectLocation,
    componentProps: {
      propsData: propsData,
      methods: {
        onSelectDistance(val) {
          self.distance = this.distances.find(distance => distance.value === val);
          console.log(self.distance);
        },
        onSelectDevLocation(val) {
          self.devLocation = this.devLocations.find(devLocation => devLocation.value === val);
          console.log(self.devLocation);
        },
      },
    },
  })
  .then(m => {
    self.locationSelectModal = m;
    self.locationSelectModal.present();
  });
}