
import { localize } from '../../../../nls.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { Extensions } from '../../../../platform/jsonschemas/common/jsonContributionRegistry.js';
import { iconsSchemaId } from '../../../../platform/theme/common/iconRegistry.js';

const fontIdRegex = '^([\\w_-]+)$';
const fontStyleRegex = '^(normal|italic|(oblique[ \\w\\s-]+))$';
const fontWeightRegex = '^(normal|bold|lighter|bolder|(\\d{0-1000}))$';
const fontSizeRegex = '^([\\w_.%+-]+)$';
const fontFormatRegex = '^woff|woff2|truetype|opentype|embedded-opentype|svg$';
const fontCharacterRegex = '^([^\\\\]|\\\\[a-fA-F0-9]+)$';
const fontColorRegex = '^#[0-9a-fA-F]{0,6}$';
const schemaId = 'vscode://schemas/product-icon-theme';
const schema = {
    type: 'object',
    allowComments: true,
    allowTrailingCommas: true,
    properties: {
        fonts: {
            type: 'array',
            items: {
                type: 'object',
                properties: {
                    id: {
                        type: 'string',
                        description: ( localize(11906, 'The ID of the font.')),
                        pattern: fontIdRegex,
                        patternErrorMessage: ( localize(11907, 'The ID must only contain letters, numbers, underscore and minus.'))
                    },
                    src: {
                        type: 'array',
                        description: ( localize(11908, 'The location of the font.')),
                        items: {
                            type: 'object',
                            properties: {
                                path: {
                                    type: 'string',
                                    description: ( localize(11909, 'The font path, relative to the current product icon theme file.')),
                                },
                                format: {
                                    type: 'string',
                                    description: ( localize(11910, 'The format of the font.')),
                                    enum: ['woff', 'woff2', 'truetype', 'opentype', 'embedded-opentype', 'svg']
                                }
                            },
                            required: [
                                'path',
                                'format'
                            ]
                        }
                    },
                    weight: {
                        type: 'string',
                        description: ( localize(
                            11911,
                            'The weight of the font. See https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight for valid values.'
                        )),
                        anyOf: [
                            { enum: ['normal', 'bold', 'lighter', 'bolder'] },
                            { type: 'string', pattern: fontWeightRegex }
                        ]
                    },
                    style: {
                        type: 'string',
                        description: ( localize(
                            11912,
                            'The style of the font. See https://developer.mozilla.org/en-US/docs/Web/CSS/font-style for valid values.'
                        )),
                        anyOf: [
                            { enum: ['normal', 'italic', 'oblique'] },
                            { type: 'string', pattern: fontStyleRegex }
                        ]
                    }
                },
                required: [
                    'id',
                    'src'
                ]
            }
        },
        iconDefinitions: {
            description: ( localize(11913, 'Association of icon name to a font character.')),
            $ref: iconsSchemaId
        }
    }
};
function registerProductIconThemeSchemas() {
    const schemaRegistry = ( Registry.as(Extensions.JSONContribution));
    schemaRegistry.registerSchema(schemaId, schema);
}

export { fontCharacterRegex, fontColorRegex, fontFormatRegex, fontIdRegex, fontSizeRegex, fontStyleRegex, fontWeightRegex, registerProductIconThemeSchemas };
