import {LOCATABLE_ITEMS_HOLDER_TYPE} from '../location/location.const';
import {
  ObjectSubTypeDefinition,
  ObjectTypeDefinition,
} from './../../integration/extension.provider';
export const CONTENT_IMAGE_PROVIDER = 'ContentImageProvider';
export const CONTENT_IMAGE_SERVICE = 'ContentImageService';

export const IMAGE_GALLERIES_TYPE: ObjectTypeDefinition = {
  name: 'ImageGalleries',
  title: 'Image galleries',
  definition: {
    properties: {},
  },
  contentType: '',
  iconView: 'fas fa-photo-video',
};

export const IMAGE_GALLERY_TYPE: ObjectTypeDefinition = {
  name: 'ImageGallery',
  inheritedTypesIds: [LOCATABLE_ITEMS_HOLDER_TYPE.name],
  title: 'Image gallery',
  definition: {
    properties: {},
  },
  contentType: '',
  iconView: 'far fa-images',
};

export const DISPLAYED_IMAGE_GALLERY_TYPE: ObjectTypeDefinition = {
  name: 'DisplayedImageGallery',
  inheritedTypesIds: [IMAGE_GALLERY_TYPE.name],
  definition: {
    properties: {},
  },
  contentType: '',
};

export const IMAGE_ALBUM_TYPE: ObjectTypeDefinition = {
  name: 'ImageAlbum',
  inheritedTypesIds: [DISPLAYED_IMAGE_GALLERY_TYPE.name],
  title: 'Image album',
  definition: {
    properties: {},
  },
  contentType: '',
  iconView: 'far fa-images',
};

export const IMAGE_GALLERY_REFERRER_TYPE: ObjectTypeDefinition = {
  name: 'ImageGalleryReferrer',
  title: 'Images referrer',
  inheritedTypesIds: [LOCATABLE_ITEMS_HOLDER_TYPE.name],
  definition: {
    properties: {
      imageGalleryObjectTreeId: {
        title: 'Image album',
        type: 'string',
        oneOfTree: [
          {
            treeType: IMAGE_GALLERY_TYPE.name,
          },
        ],
      },
    },
  },
  contentType: '',
};

export const IMAGE_GALLERY_SELECTOR_TYPE: ObjectTypeDefinition = {
  name: 'ImageGallerySelector',
  inheritedTypesIds: [IMAGE_GALLERY_REFERRER_TYPE.name],
  definition: {
    properties: {
      selectedImages: {
        title: 'Selected images',
        type: 'array',
        items: {
          type: 'string',
        },
        'x-schema-form': {
          condition: 'undefined !== embeddedCondition',
        },
      },
    },
  },
  contentType: '',
};

export const IMAGE_GALLERY_CONCATENATION_TYPE: ObjectTypeDefinition = {
  name: 'ImageGalleryConcatenation',
  title: 'Concatenation of albums',
  inheritedTypesIds: [DISPLAYED_IMAGE_GALLERY_TYPE.name],
  definition: {
    properties: {
      selectedGalleriesObjectTreeIds: {
        title: 'Selected albums',
        type: 'array',
        items: {
          type: 'string',
          enumOfTree: [
            {
              treeType: IMAGE_GALLERY_TYPE.name,
            },
          ],
        },
      },
    },
  },
  contentType: '',
};

export const IMAGE_GALLERY_CONCATENATION_ALL_DEFAULT_TYPE: ObjectTypeDefinition = {
  name: 'ImageGalleryConcatenationAllDefault',
  fieldsOrder: ['selectAlbums', 'selectedGalleriesObjectTreeIds'],
  inheritedTypesIds: [IMAGE_GALLERY_CONCATENATION_TYPE.name],
  definition: {
    properties: {
      selectAlbums: {
        type: 'boolean',
        title: 'Select a subset of albums to be displayed',
        default: false,
      },
      selectedGalleriesObjectTreeIds: {
        'x-schema-form': {
          condition: {functionBody: 'return !!model.selectAlbums'},
        },
      },
    },
  },
};

export const IMAGE_TYPE: ObjectTypeDefinition = {
  name: 'Image',
  definition: {
    properties: {
      imagePosition: {
        title: 'Image position',
        type: 'string',
        'x-schema-form': {
          type: 'position',
          conditionalValue: {
            title: 'Set the image position',
          },
        },
      },
      imageDate: {
        title: 'Shooting date',
        type: 'string',
        'x-schema-form': {
          type: 'date-time',
          conditionalValue: {
            title: 'Set a shooting date',
          },
        },
      },
    },
  },
  contentType: 'ContentImage',
  iconView: 'far fa-image',
  templateView:
    '<span class="child-tree-preview"><span class="child-image-name">{{dataNode.title}}</span><img style="padding-left: 10px;height: 50px;" src="{{dataNode.contentImageUri}}"/></span>',
};

export const IMAGE_GALLERY_CONCATENATION_IMAGE_SUBTYPE: ObjectSubTypeDefinition = {
  typeName: IMAGE_GALLERY_CONCATENATION_TYPE.name,
  subTypeName: IMAGE_TYPE.name,
  max: 0,
};

export const IMAGE_GALLERIES_IMAGE_ALBUM_SUBTYPE: ObjectSubTypeDefinition = {
  typeName: IMAGE_GALLERIES_TYPE.name,
  subTypeName: IMAGE_ALBUM_TYPE.name,
  name: IMAGE_ALBUM_TYPE.name,
  acl: false,
  namespace: false,
  owner: false,
  tree: true,
};

export const IMAGE_GALLERIES_IMAGE_GALLERY_CONCATENATION_SUBTYPE: ObjectSubTypeDefinition = {
  typeName: IMAGE_GALLERIES_TYPE.name,
  subTypeName: IMAGE_GALLERY_CONCATENATION_TYPE.name,
  name: IMAGE_GALLERY_CONCATENATION_TYPE.name,
  acl: false,
  namespace: false,
  owner: false,
  tree: true,
};

export const IMAGE_ALBUM_IMAGE_SUBTYPE: ObjectSubTypeDefinition = {
  typeName: IMAGE_ALBUM_TYPE.name,
  subTypeName: IMAGE_TYPE.name,
  name: IMAGE_TYPE.name,
  acl: false,
  namespace: false,
  owner: false,
  tree: false,
};
