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

/*
* Builds category select modal
* -----------------------------------------------------------
* self object needs to contain the following reactive keys:
*  - motto
*  - description
*  - isInitialSteps
*  - postDescriptionCreateModal
*/

export default (self, animations, callbacks, triggeredBy) => {
	return self.$ionic.modalController.create({
      component: RecoCreatePostDescription,
      enterAnimation: animations.enterAnimation,
      leaveAnimation: animations.leaveAnimation,
      componentProps: {
        propsData: {
          motto: self.motto,
          description: self.description,
          type: self.type,
          category: self.category,
          visibility: {
            gender: self.gender,
            age: self.age,
            expiration: self.expiration,
            distance: self.distance,
            activityDateTime: self.activityDateTime,
            maxResponses: self.maxResponses,
            chatType: self.chatType,
            automaticResponse: self.automaticResponse,
          },
          excludedFeatures: self.excludedFeatures,
          color: self.color,
          isInitialSteps: self.isInitialSteps,
          backButtonClicked: callbacks.backButtonClicked ? callbacks.backButtonClicked : () => { return },
	        doneButtonClicked: callbacks.doneButtonClicked ? callbacks.doneButtonClicked : () => { return },
  	      withBackButton: callbacks.backButtonClicked ? true : false,
          withDoneButton: callbacks.doneButtonClicked ? true : false,
          postLanguageChanged: callbacks.postLanguageChanged ? callbacks.postLanguageChanged : () => { return },
          activeFeatures: self.activeFeatures,
          me: self.me,
          preSelectedLanguage: self.language,
        },
        mounted() {
          if (triggeredBy == 'motto') {
            setTimeout(() => { this.$refs.mottoInput.setFocus(); }, 300);
          } else {
            setTimeout(() => { this.$refs.descriptionInput.setFocus(); }, 300);
          }
        },
        methods: {
          onMottoChange(motto) {
            self.motto = motto;
          },
          onDescriptionChange(description) {
            self.description = description;
          },
          onTypeChange(type) {
            self.type = type;
            console.log(self.type);
          },
          onVisibilityChange(key, value) {
            self[key] = value;
            console.log({key, value});
          },
        }
      },
    })
    .then(m => {
      self.postDescriptionCreateModal = m;
      self.postDescriptionCreateModal.present();
    })
}