function newFunction() {
  return {
    ctrl: undefined,
    async init(ctrl) {
      this.ctrl = ctrl;

      // eslint-disable-next-line no-void
      void this.backGroundInit();
    },
    async backGroundInit() { },
    async initMustache() {

      let positions = [];
      let hasEvents = !!this.ctrl.dataNode.eventsLayerName;
      let hasImages = !!this.ctrl.dataNode.imagesLayerName;

      if (!hasEvents && !hasImages) {
        hasEvents = true;
        this.ctrl.dataNode.eventsLayerName = 'default';
      }

      if (
        hasEvents &&
        this.ctrl.dataNode.map &&
        this.ctrl.dataNode.map.positions
      ) {
        this.ctrl.hasMap = true;

        for (const position of this.ctrl.dataNode.map.positions) {
          position.popupHref = this.ctrl.getPopupHref(position);
          position.layer = this.ctrl.dataNode.eventsLayerName;
        }

        positions = this.ctrl.dataNode.map.positions;
      }

      if (hasImages) {
        if (!this.ctrl.dataNode.images && this.ctrl.dataTree.images) {
          this.ctrl.dataNode.images = this.ctrl.dataTree.images;
        }

        if (this.ctrl.dataNode.images) {
          this.ctrl.dataNode.images = this.ctrl.dataNode.images.filter(
            (image) => image.treeNode.imagePosition,
          );
          if (0 < this.ctrl.dataNode.images.length) {
            this.ctrl.hasMap = true;

            this.ctrl.singleImage = 1 === this.ctrl.dataNode.images.length;
            for (const imageIndex in this.ctrl.dataNode.images) {
              if (
                this.ctrl.dataNode.images[imageIndex].treeNode.imagePosition
              ) {
                const imageSrc = this.ctrl.dataNode.images[imageIndex].thumb
                  ? this.ctrl.getImgSrc({
                    uri: this.ctrl.dataNode.images[imageIndex].thumb
                      .contentImageUri,
                  })
                  : this.ctrl.getImgSrc({
                    uri: this.ctrl.dataNode.images[imageIndex].treeNode
                      .contentImageUri,
                  });
                positions.push({
                  layer: this.ctrl.dataNode.imagesLayerName,
                  position: this.ctrl.dataNode.images[
                    imageIndex
                  ].treeNode.imagePosition.split(','),
                  index: imageIndex,
                  src: imageSrc,
                  title: this.ctrl.dataNode.images[imageIndex].treeNode.title,
                });
              }
              this.ctrl.dataNode.images[imageIndex].index = imageIndex;
              this.ctrl.dataNode.images[imageIndex].imageClass =
                0 === imageIndex ? ' active' : '';
              this.ctrl.dataNode.images[
                imageIndex
              ].imgSrc = this.ctrl.getImgSrc({
                uri: this.ctrl.dataNode.images[imageIndex].treeNode
                  .contentImageUri,
              });
              this.ctrl.dataNode.images[imageIndex].thumbSrc = this.ctrl
                .dataNode.images[imageIndex].thumb
                ? this.ctrl.getImgSrc({
                  uri: this.ctrl.dataNode.images[imageIndex].thumb
                    .contentImageUri,
                })
                : this.ctrl.getImgSrc({
                  uri: this.ctrl.dataNode.images[imageIndex].treeNode
                    .contentImageUri,
                });

              // eslint-disable-next-line no-constant-condition
              if (false && this.ctrl.dataNode.images[imageIndex].original) {
                this.ctrl.dataNode.images[
                  imageIndex
                ].imgBackground = this.ctrl.getImgBackground({
                  uri: this.ctrl.dataNode.images[imageIndex].original
                    .contentImageUri,
                });
              } else {
                this.ctrl.dataNode.images[
                  imageIndex
                ].imgBackground = this.ctrl.getImgBackground({
                  uri: this.ctrl.dataNode.images[imageIndex].treeNode
                    .contentImageUri,
                });
              }
              this.ctrl.dataNode.images[imageIndex].modalTitle =
                this.ctrl.dataNode.images[imageIndex].treeNode.imageTitle ||
                this.ctrl.dataNode.images[imageIndex].treeNode.title ||
                this.ctrl.dataNode.paragraphTitle ||
                this.ctrl.dataNode.pageTitle ||
                this.ctrl.dataNode.menuTitle ||
                this.ctrl.dataNode.parentPageTitle ||
                '';
            }
          } else {
            hasImages = false;
          }
        } else {
          hasImages = false;
        }
      }
      this.ctrl.hasEvents = hasEvents;
      this.ctrl.hasImages = hasImages;
      this.ctrl.jsonPositions = JSON.stringify(
        positions,
      ); /*.replace(
        /"/g,
        '&quot;',
      );*/
    },
  };
}
newFunction();
