import { manifest as propertyEditorSchema } from './Umbraco.BlockGrid.js';
import { UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS, UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS } from './constants.js';
import { UmbStandardBlockValueResolver } from '@umbraco-cms/backoffice/block';

const propertyEditorUi: UmbExtensionManifest = {
	type: 'propertyEditorUi',
	alias: UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS,
	name: 'Block Grid Property Editor UI',
	element: () => import('./property-editor-ui-block-grid.element.js'),
	meta: {
		label: 'Block Grid',
		propertyEditorSchemaAlias: UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS,
		icon: 'icon-layout',
		group: 'richContent',
		supportsReadOnly: true,
		settings: {
			properties: [
				{
					alias: 'blockGroups',
					label: '',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.BlockTypeGroupConfiguration',
					weight: 1,
				},
				{
					alias: 'useLiveEditing',
					label: 'Live editing mode',
					description: 'Live update content when editing in overlay',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.Toggle',
				},
				{
					alias: 'maxPropertyWidth',
					label: 'Editor width',
					description: 'Optional css overwrite. (example: 1200px or 100%)',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
				},
				{
					alias: 'createLabel',
					label: 'Create Button Label',
					description: 'Override the label text for adding a new block, Example Add Widget',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
				},
				{
					alias: 'gridColumns',
					label: 'Grid Columns',
					description: 'Set the number of columns for the layout.',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.Integer',
					config: [
						{ alias: 'min', value: 0 },
						{ alias: 'placeholder', value: '12' },
					],
				},
				{
					alias: 'layoutStylesheet',
					label: 'Layout Stylesheet',
					description: 'Override default stylesheet for backoffice layout.',
					propertyEditorUiAlias: 'Umb.PropertyEditorUi.BlockGridLayoutStylesheet',
					config: [
						{
							alias: 'singleItemMode',
							value: true,
						},
					],
				},
			],
		},
	},
};

const propertyValueResolver: UmbExtensionManifest = {
	type: 'propertyValueResolver',
	alias: 'Umb.PropertyValueResolver.BlockGrid',
	name: 'Block Grid Value Resolver',
	api: UmbStandardBlockValueResolver,
	forEditorAlias: UMB_BLOCK_GRID_PROPERTY_EDITOR_SCHEMA_ALIAS,
};

const sortModePropertyContext: UmbExtensionManifest = {
	type: 'propertyContext',
	kind: 'sortMode',
	alias: 'Umb.PropertyContext.BlockGrid.SortMode',
	name: 'Block Grid Sort Mode Property Context',
	forPropertyEditorUis: [UMB_BLOCK_GRID_PROPERTY_EDITOR_UI_ALIAS],
};

export const manifests: Array<UmbExtensionManifest> = [
	propertyEditorSchema,
	propertyEditorUi,
	propertyValueResolver,
	sortModePropertyContext,
];
