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

/*
* Builds category select modal
* -----------------------------------------------------------
* self object needs to contain the following reactive keys:
*  - images
*  - imageDimensions
*  - post
*  - postPreviewModal
*/

export default (self, animations, callbacks) => {
  return self.$ionic.modalController.create({
    component: RecoPostPreview,
    enterAnimation: animations.enterAnimation,
    leaveAnimation: animations.leaveAnimation,
    componentProps: {
      propsData: {
        post: self.getPost('preview').display,
        backButtonClicked: callbacks.backButtonClicked ? callbacks.backButtonClicked : () => { return },
        doneButtonClicked: callbacks.doneButtonClicked ? callbacks.doneButtonClicked : () => { return },
        withBackButton: callbacks.backButtonClicked ? true : false,
        withDoneButton: callbacks.doneButtonClicked ? true : false,
        previewCloseButtonClicked: callbacks.previewCloseButtonClicked,
        excludedFeatures: self.excludedFeatures,
        color: self.color,
      },
      mounted() {
        this.images = self.images;
        this.imageURLs = self.imageURLs;
        this.imageDimensions = self.imageDimensions;
        this.isEdit = self.post ? true : false;

        setTimeout(() => (this.isLoaded = true), 300);
        // setTimeout(() => this.$refs.ionSlider.slideTo(this.imageURLs.length), 600);
      },
      methods: {
        setImages(images, imageURLs, dimensions) {
          self.images = images;
          self.imageURLs = imageURLs;
          self.imageDimensions = dimensions;
        },
        setColor(color) {
          self.category.color = color;
        }
      }
    },
  })
  .then(m => {
    self.postPreviewModal = m;
    self.postPreviewModal.present();
  });
}