import {ObjectTypeDefinition} from '../../integration/extension.provider';
import {IMAGE_GALLERY_CONCATENATION_ALL_DEFAULT_TYPE} from '../content-image/content-image.const';
import {MAP_TYPE} from '../map/map.const';

export const IMAGES_MAP_PROVIDER = 'ImagesMapProvider';

export const IMAGES_EVENTS_MAP_TYPE: ObjectTypeDefinition = {
  name: 'ImagesAndEventsMap',
  fieldsOrder: [
    'eventsLayerName',
    'imagesLayerName',
    'selectAlbums',
    'selectedGalleriesObjectTreeIds',
  ],
  inheritedTypesIds: [
    IMAGE_GALLERY_CONCATENATION_ALL_DEFAULT_TYPE.name,
    MAP_TYPE.name,
  ],

  definition: {
    properties: {
      eventsLayerName: {
        type: 'string',
        title: 'events layer label',
        'x-schema-form': {
          type: 'conditional-text',
          conditionalValue: {
            title: 'Display events on map',
            defaultValue: `return 'Events'`,
          },
        },
      },
      imagesLayerName: {
        type: 'string',
        title: 'images layer label',
        'x-schema-form': {
          type: 'conditional-text',
          conditionalValue: {
            title: 'Display images on map',
            defaultValue: `return 'Images'`,
          },
        },
      },
      selectAlbums: {
        'x-schema-form': {
          condition: {
            functionBody: 'return !!model.imagesLayerName',
          },
        },
      },
      selectedGalleriesObjectTreeIds: {
        'x-schema-form': {
          condition: {
            functionBody:
              'return !!model.imagesLayerName && !!model.selectAlbums',
          },
        },
      },
    },
  },
};
