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

/*
* Builds category select modal
* -----------------------------------------------------------
* self object needs to contain the following reactive keys:
*  - expiration
*  - activityDateTime
*  - audienceSelectModal
*/

export default (self, title, description, withoutActivityDateTime) => {
  let propsData = {
    selectedExpiration: self.expiration,
    activityDateTime: self.activityDateTime,
    doneButtonClicked: () => { self.expirationSelectModal.dismiss() },
  }
  if (title) {
    propsData.title = title;
  }
  if (description) {
    propsData.description = description;
  }
  if (withoutActivityDateTime) {
    propsData.withoutActivityDateTime = withoutActivityDateTime;
  }
  return self.$ionic.modalController.create({
    component: RecoSelectExpiration,
    componentProps: {
      propsData: propsData,
      methods: {
        onSelectExpiration(val) {
          self.expiration = this.expirations.find(expiration => expiration.value === val);
        },
        onActivityDateTimeChange(val) {
          console.log(val);
          self.activityDateTime = val;
          this.activityDateTime = self.activityDateTime;
        },
      },
    },
  })
  .then(m => {
    self.expirationSelectModal = m;
    self.expirationSelectModal.present();
  })
}