import {ObjectTreesApplicationInterface} from '../../application.interface';
import {contentGenericTemplate} from '../../helper';
import {ExtensionProvider} from '../../integration/extension.provider';
import {WebSiteProvider} from '../web-site/web-site.provider';
import {ContentGenericTemplateProvider} from './../content-generic-template/content-generic-template.provider';
import {ContentImageProvider} from './../content-image/content-image.provider';
import {PARAGRAPH_TEMPLATE_TYPE} from './../web-site/web-site.const';
import {
  CATEGORY_IMAGE_GALLERY_TEMPLATE_SUBTYPE,
  CONTENT_IMAGE_TEMPLATE_PROVIDER,
  GALLERY_PARAGRAPH_TYPE,
  GALLERY_TEXT_PARAGRAPH_TYPE,
  IMAGE_GALLERY_TEMPLATE_TYPE,
  PAGE_WITH_GALLERY_PARAGRAPH_GALLERY_PARAGRAPH_SUBTYPE,
  PAGE_WITH_GALLERY_PARAGRAPH_TYPE,
  PAGE_WITH_GALLERY_TEXT_PARAGRAPH_GALLERY_TEXT_PARAGRAPH_SUBTYPE,
  PAGE_WITH_GALLERY_TEXT_PARAGRAPH_TYPE,
  PAGE_WITH_GALLERY_TYPE,
  PARAGRAPH_CONTAINER_GALLERY_TEXT_PARAGRAPH_SUBTYPE,
  WEB_SITE_VIEW_WITH_IMAGE_IN_POPUP,
} from './content-image-template.const';
import {ContentImageTemplateService} from './content-image-template.service';

export class ContentImageTemplateProvider extends ExtensionProvider {
  constructor(protected app: ObjectTreesApplicationInterface) {
    super(CONTENT_IMAGE_TEMPLATE_PROVIDER, app);
    this.requiredProviders.push(
      ContentImageProvider,
      ContentGenericTemplateProvider,
      WebSiteProvider,
    );

    this.services.push({cls: ContentImageTemplateService});

    this.objectTypes.push(
      IMAGE_GALLERY_TEMPLATE_TYPE,
      GALLERY_PARAGRAPH_TYPE,
      GALLERY_TEXT_PARAGRAPH_TYPE,
      PAGE_WITH_GALLERY_TYPE,
      PAGE_WITH_GALLERY_PARAGRAPH_TYPE,
      PAGE_WITH_GALLERY_TEXT_PARAGRAPH_TYPE,
      WEB_SITE_VIEW_WITH_IMAGE_IN_POPUP,
    );
    this.objectSubTypes.push(
      CATEGORY_IMAGE_GALLERY_TEMPLATE_SUBTYPE,
      PAGE_WITH_GALLERY_PARAGRAPH_GALLERY_PARAGRAPH_SUBTYPE,
      PAGE_WITH_GALLERY_TEXT_PARAGRAPH_GALLERY_TEXT_PARAGRAPH_SUBTYPE,
      PARAGRAPH_CONTAINER_GALLERY_TEXT_PARAGRAPH_SUBTYPE,
    );

    this.objectTrees.carousel = {
      reset: false,
      parentNode: () => this.appCtx.publicTemplatesNode.value,
      treeNodeName: 'carousel',
      treeNodeTypeId: IMAGE_GALLERY_TEMPLATE_TYPE.name,
      tree: {
        treeNode: {
          contentGenericTemplate: contentGenericTemplate(__dirname, 'carousel'),
        },
        children: {},
      },
    };

    this.objectTrees.thumbs = {
      reset: false,
      parentNode: () => this.appCtx.publicTemplatesNode.value,
      treeNodeName: 'thumbs',
      treeNodeTypeId: IMAGE_GALLERY_TEMPLATE_TYPE.name,
      tree: {
        treeNode: {
          contentGenericTemplate: contentGenericTemplate(__dirname, 'thumbs'),
        },
        children: {},
      },
    };

    this.objectTrees.imageFullPage = {
      reset: false,
      parentNode: () => this.appCtx.publicTemplatesNode.value,
      treeNodeName: 'imageFullPage',
      treeNodeTypeId: IMAGE_GALLERY_TEMPLATE_TYPE.name,
      tree: {
        treeNode: {
          contentGenericTemplate: contentGenericTemplate(
            __dirname,
            'imageFullPage',
          ),
        },
        children: {},
      },
    };

    this.objectTrees.pageCardTextAndImages = {
      reset: false,
      parentNode: () => this.appCtx.publicTemplatesNode.value,
      treeNodeName: 'cardTextAndImages',
      treeNodeTypeId: PARAGRAPH_TEMPLATE_TYPE.name,
      tree: {
        treeNode: {
          contentGenericTemplate: contentGenericTemplate(
            __dirname,
            'cardTextAndImages',
            ['card', 'cardImg'],
          ),
        },
        children: {
          [PARAGRAPH_TEMPLATE_TYPE.name + 'EmbeddedConfiguration']: {
            ['textAndThumbAfter']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/thumbs',
                    imageGalleryPosition: 'after',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: 'Text and thumb after',
                },
                children: {},
              },
            ],
            ['textAndImagesAfter']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/imageFullPage',
                    imageGalleryPosition: 'after',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: 'Text and images in full page after',
                },
                children: {},
              },
            ],
            ['textAndCarousselRight']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/carousel',
                    imageGalleryPosition: 'right',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: 'Text and caroussel on right',
                },
                children: {},
              },
            ],
            ['textAndImageOnMapAfter']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/imagesMap',
                    imageGalleryPosition: 'after',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: 'Text and images on a map after',
                },
                children: {},
              },
            ],
            ['text25pctWithCaroussel']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/carousel',
                    paragraphBreakLine: 'xs',
                    paragraphMaxWidth: 3,
                    paragraphMinWidth: 6,
                    paragraphKeepProportion: true,
                    galleryBreakLine: 'none',
                    galleryMaxWidth: 6,
                    galleryMinWidth: 6,
                    imageGalleryPosition: 'right',
                    displayParentPageTitle: false,
                    contentClass: 'h4',
                    titleClass: 'display-4',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: '1/4 page text and caroussel',
                },
                children: {},
              },
            ],
            ['text33pctWithCaroussel']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/carousel',
                    paragraphBreakLine: 'sm',
                    paragraphMaxWidth: 4,
                    paragraphMinWidth: 4,
                    paragraphKeepProportion: true,
                    galleryBreakLine: 'none',
                    galleryMaxWidth: 6,
                    galleryMinWidth: 6,
                    imageGalleryPosition: 'right',
                    displayParentPageTitle: false,
                    contentClass: 'h4',
                    titleClass: 'display-4',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: '1/3 page text and caroussel',
                },
                children: {},
              },
            ],
            ['text50pctWithCaroussel']: [
              {
                treeNode: {
                  templateObjectTreeId:
                    'tree/Repository/public/RepositoryCategory/templates/ParagraphTemplate/cardTextAndImages',
                  configuration: {
                    imageGalleryObjectTreeId:
                      'tree/Repository/public/RepositoryCategory/templates/ImageGalleryTemplate/carousel',
                    paragraphBreakLine: 'md',
                    paragraphMaxWidth: 6,
                    paragraphMinWidth: 6,
                    paragraphKeepProportion: true,
                    galleryBreakLine: 'none',
                    galleryMaxWidth: 6,
                    galleryMinWidth: 6,
                    imageGalleryPosition: 'right',
                    displayParentPageTitle: false,
                    contentClass: 'h4',
                    titleClass: 'display-4',
                  },
                  templateConfigurationObjectTreeId: '',
                  title: '1/2 page text and caroussel',
                },
                children: {},
              },
            ],
          },
        },
      },
    };
  }
}
