import { isWeb, isNative } from '../../../../base/common/platform.js';
import { editorConfigurationBaseNode } from '../../../../editor/common/config/editorConfigurationSchema.js';
import { localizeWithPath } from '../../../../nls.js';
import { Extensions } from '../../../../platform/configuration/common/configurationRegistry.js';
import { FILES_EXCLUDE_CONFIG, FILES_ASSOCIATIONS_CONFIG, AutoSaveConfiguration, FILES_READONLY_INCLUDE_CONFIG, FILES_READONLY_EXCLUDE_CONFIG, FILES_READONLY_FROM_PERMISSIONS_CONFIG, HotExitConfiguration } from '../../../../platform/files/common/files.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { SUPPORTED_ENCODINGS } from '../../../services/textfile/common/encoding.js';
const _moduleId = "vs/workbench/contrib/files/browser/files.configuration.contribution";
const configurationRegistry = ( (Registry.as(Extensions.Configuration)));
const hotExitConfiguration = isNative ?
    {
        'type': 'string',
        'scope': 1 ,
        'enum': [HotExitConfiguration.OFF, HotExitConfiguration.ON_EXIT, HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE],
        'default': HotExitConfiguration.ON_EXIT,
        'markdownEnumDescriptions': [
            ( localizeWithPath(
                _moduleId,
                0,
                'Disable hot exit. A prompt will show when attempting to close a window with editors that have unsaved changes.'
            )),
            ( localizeWithPath(
                _moduleId,
                1,
                'Hot exit will be triggered when the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu). All windows without folders opened will be restored upon next launch. A list of previously opened windows with unsaved files can be accessed via `File > Open Recent > More...`'
            )),
            ( localizeWithPath(
                _moduleId,
                2,
                'Hot exit will be triggered when the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu), and also for any window with a folder opened regardless of whether it\'s the last window. All windows without folders opened will be restored upon next launch. A list of previously opened windows with unsaved files can be accessed via `File > Open Recent > More...`'
            ))
        ],
        'markdownDescription': ( localizeWithPath(
            _moduleId,
            3,
            "[Hot Exit](https://aka.ms/vscode-hot-exit) controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.",
            HotExitConfiguration.ON_EXIT,
            HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE
        ))
    } : {
    'type': 'string',
    'scope': 1 ,
    'enum': [HotExitConfiguration.OFF, HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE],
    'default': HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE,
    'markdownEnumDescriptions': [
        ( localizeWithPath(
            _moduleId,
            0,
            'Disable hot exit. A prompt will show when attempting to close a window with editors that have unsaved changes.'
        )),
        ( localizeWithPath(
            _moduleId,
            4,
            'Hot exit will be triggered when the browser quits or the window or tab is closed.'
        ))
    ],
    'markdownDescription': ( localizeWithPath(
        _moduleId,
        3,
        "[Hot Exit](https://aka.ms/vscode-hot-exit) controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.",
        HotExitConfiguration.ON_EXIT,
        HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE
    ))
};
configurationRegistry.registerConfiguration({
    'id': 'files',
    'order': 9,
    'title': ( localizeWithPath(_moduleId, 5, "Files")),
    'type': 'object',
    'properties': {
        [FILES_EXCLUDE_CONFIG]: {
            'type': 'object',
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                6,
                "Configure [glob patterns](https://aka.ms/vscode-glob-patterns) for excluding files and folders. For example, the File Explorer decides which files and folders to show or hide based on this setting. Refer to the `#search.exclude#` setting to define search-specific excludes. Refer to the `#explorer.excludeGitIgnore#` setting for ignoring files based on your `.gitignore`."
            )),
            'default': {
                ...{ '**/.git': true, '**/.svn': true, '**/.hg': true, '**/CVS': true, '**/.DS_Store': true, '**/Thumbs.db': true },
                ...(isWeb ? { '**/*.crswap': true  } : undefined)
            },
            'scope': 4 ,
            'additionalProperties': {
                'anyOf': [
                    {
                        'type': 'boolean',
                        'enum': [true, false],
                        'enumDescriptions': [( localizeWithPath(_moduleId, 7, "Enable the pattern.")), ( localizeWithPath(_moduleId, 8, "Disable the pattern."))],
                        'description': ( localizeWithPath(
                            _moduleId,
                            9,
                            "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern."
                        )),
                    },
                    {
                        'type': 'object',
                        'properties': {
                            'when': {
                                'type': 'string',
                                'pattern': '\\w*\\$\\(basename\\)\\w*',
                                'default': '$(basename).ext',
                                'markdownDescription': ( localizeWithPath(
                                    _moduleId,
                                    10,
                                    "Additional check on the siblings of a matching file. Use \\$(basename) as variable for the matching file name."
                                ))
                            }
                        }
                    }
                ]
            }
        },
        [FILES_ASSOCIATIONS_CONFIG]: {
            'type': 'object',
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                11,
                "Configure [glob patterns](https://aka.ms/vscode-glob-patterns) of file associations to languages (for example `\"*.extension\": \"html\"`). Patterns will match on the absolute path of a file if they contain a path separator and will match on the name of the file otherwise. These have precedence over the default associations of the languages installed."
            )),
            'additionalProperties': {
                'type': 'string'
            }
        },
        'files.encoding': {
            'type': 'string',
            'enum': ( (Object.keys(SUPPORTED_ENCODINGS))),
            'default': 'utf8',
            'description': ( localizeWithPath(
                _moduleId,
                12,
                "The default character set encoding to use when reading and writing files. This setting can also be configured per language."
            )),
            'scope': 5 ,
            'enumDescriptions': ( (( (Object.keys(SUPPORTED_ENCODINGS))).map(key => SUPPORTED_ENCODINGS[key].labelLong))),
            'enumItemLabels': ( (( (Object.keys(SUPPORTED_ENCODINGS))).map(key => SUPPORTED_ENCODINGS[key].labelLong)))
        },
        'files.autoGuessEncoding': {
            'type': 'boolean',
            'default': false,
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                13,
                "When enabled, the editor will attempt to guess the character set encoding when opening files. This setting can also be configured per language. Note, this setting is not respected by text search. Only {0} is respected.",
                '`#files.encoding#`'
            )),
            'scope': 5
        },
        'files.eol': {
            'type': 'string',
            'enum': [
                '\n',
                '\r\n',
                'auto'
            ],
            'enumDescriptions': [
                ( localizeWithPath(_moduleId, 14, "LF")),
                ( localizeWithPath(_moduleId, 15, "CRLF")),
                ( localizeWithPath(_moduleId, 16, "Uses operating system specific end of line character."))
            ],
            'default': 'auto',
            'description': ( localizeWithPath(_moduleId, 17, "The default end of line character.")),
            'scope': 5
        },
        'files.enableTrash': {
            'type': 'boolean',
            'default': true,
            'description': ( localizeWithPath(
                _moduleId,
                18,
                "Moves files/folders to the OS trash (recycle bin on Windows) when deleting. Disabling this will delete files/folders permanently."
            ))
        },
        'files.trimTrailingWhitespace': {
            'type': 'boolean',
            'default': false,
            'description': ( localizeWithPath(
                _moduleId,
                19,
                "When enabled, will trim trailing whitespace when saving a file."
            )),
            'scope': 5
        },
        'files.trimTrailingWhitespaceInRegexAndStrings': {
            'type': 'boolean',
            'default': true,
            'description': ( localizeWithPath(
                _moduleId,
                20,
                "When enabled, trailing whitespace will be removed from multiline strings and regexes will be removed on save or when executing 'editor.action.trimTrailingWhitespace'. This can cause whitespace to not be trimmed from lines when there isn't up-to-date token information."
            )),
            'scope': 5
        },
        'files.insertFinalNewline': {
            'type': 'boolean',
            'default': false,
            'description': ( localizeWithPath(
                _moduleId,
                21,
                "When enabled, insert a final new line at the end of the file when saving it."
            )),
            'scope': 5
        },
        'files.trimFinalNewlines': {
            'type': 'boolean',
            'default': false,
            'description': ( localizeWithPath(
                _moduleId,
                22,
                "When enabled, will trim all new lines after the final new line at the end of the file when saving it."
            )),
            scope: 5 ,
        },
        'files.autoSave': {
            'type': 'string',
            'enum': [AutoSaveConfiguration.OFF, AutoSaveConfiguration.AFTER_DELAY, AutoSaveConfiguration.ON_FOCUS_CHANGE, AutoSaveConfiguration.ON_WINDOW_CHANGE],
            'markdownEnumDescriptions': [
                ( localizeWithPath(_moduleId, 23, "An editor with changes is never automatically saved.")),
                ( localizeWithPath(
                    _moduleId,
                    24,
                    "An editor with changes is automatically saved after the configured `#files.autoSaveDelay#`."
                )),
                ( localizeWithPath(
                    _moduleId,
                    25,
                    "An editor with changes is automatically saved when the editor loses focus."
                )),
                ( localizeWithPath(
                    _moduleId,
                    26,
                    "An editor with changes is automatically saved when the window loses focus."
                ))
            ],
            'default': isWeb ? AutoSaveConfiguration.AFTER_DELAY : AutoSaveConfiguration.OFF,
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                27,
                "Controls [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors that have unsaved changes.",
                AutoSaveConfiguration.OFF,
                AutoSaveConfiguration.AFTER_DELAY,
                AutoSaveConfiguration.ON_FOCUS_CHANGE,
                AutoSaveConfiguration.ON_WINDOW_CHANGE,
                AutoSaveConfiguration.AFTER_DELAY
            )),
            scope: 5
        },
        'files.autoSaveDelay': {
            'type': 'number',
            'default': 1000,
            'minimum': 0,
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                28,
                "Controls the delay in milliseconds after which an editor with unsaved changes is saved automatically. Only applies when `#files.autoSave#` is set to `{0}`.",
                AutoSaveConfiguration.AFTER_DELAY
            )),
            scope: 5
        },
        'files.autoSaveWorkspaceFilesOnly': {
            'type': 'boolean',
            'default': false,
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                29,
                "When enabled, will limit [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors to files that are inside the opened workspace. Only applies when `#files.autoSave#` is enabled."
            )),
            scope: 5
        },
        'files.autoSaveWhenNoErrors': {
            'type': 'boolean',
            'default': false,
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                30,
                "When enabled, will limit [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors to files that have no errors reported in them at the time the auto save is triggered. Only applies when `#files.autoSave#` is enabled."
            )),
            scope: 5
        },
        'files.watcherExclude': {
            'type': 'object',
            'patternProperties': {
                '.*': { 'type': 'boolean' }
            },
            'default': { '**/.git/objects/**': true, '**/.git/subtree-cache/**': true, '**/node_modules/*/**': true, '**/.hg/store/**': true },
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                31,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to exclude from file watching. Paths can either be relative to the watched folder or absolute. Glob patterns are matched relative from the watched folder. When you experience the file watcher process consuming a lot of CPU, make sure to exclude large folders that are of less interest (such as build output folders)."
            )),
            'scope': 4
        },
        'files.watcherInclude': {
            'type': 'array',
            'items': {
                'type': 'string'
            },
            'default': [],
            'description': ( localizeWithPath(
                _moduleId,
                32,
                "Configure extra paths to watch for changes inside the workspace. By default, all workspace folders will be watched recursively, except for folders that are symbolic links. You can explicitly add absolute or relative paths to support watching folders that are symbolic links. Relative paths will be resolved to an absolute path using the currently opened workspace."
            )),
            'scope': 4
        },
        'files.hotExit': hotExitConfiguration,
        'files.defaultLanguage': {
            'type': 'string',
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                33,
                "The default language identifier that is assigned to new files. If configured to `${activeEditorLanguage}`, will use the language identifier of the currently active text editor if any."
            ))
        },
        [FILES_READONLY_INCLUDE_CONFIG]: {
            'type': 'object',
            'patternProperties': {
                '.*': { 'type': 'boolean' }
            },
            'default': {},
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                34,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to mark as read-only. Glob patterns are always evaluated relative to the path of the workspace folder unless they are absolute paths. You can exclude matching paths via the `#files.readonlyExclude#` setting. Files from readonly file system providers will always be read-only independent of this setting."
            )),
            'scope': 4
        },
        [FILES_READONLY_EXCLUDE_CONFIG]: {
            'type': 'object',
            'patternProperties': {
                '.*': { 'type': 'boolean' }
            },
            'default': {},
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                35,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to exclude from being marked as read-only if they match as a result of the `#files.readonlyInclude#` setting. Glob patterns are always evaluated relative to the path of the workspace folder unless they are absolute paths. Files from readonly file system providers will always be read-only independent of this setting."
            )),
            'scope': 4
        },
        [FILES_READONLY_FROM_PERMISSIONS_CONFIG]: {
            'type': 'boolean',
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                36,
                "Marks files as read-only when their file permissions indicate as such. This can be overridden via `#files.readonlyInclude#` and `#files.readonlyExclude#` settings."
            )),
            'default': false
        },
        'files.restoreUndoStack': {
            'type': 'boolean',
            'description': ( localizeWithPath(_moduleId, 37, "Restore the undo stack when a file is reopened.")),
            'default': true
        },
        'files.saveConflictResolution': {
            'type': 'string',
            'enum': [
                'askUser',
                'overwriteFileOnDisk'
            ],
            'enumDescriptions': [
                ( localizeWithPath(
                    _moduleId,
                    38,
                    "Will refuse to save and ask for resolving the save conflict manually."
                )),
                ( localizeWithPath(
                    _moduleId,
                    39,
                    "Will resolve the save conflict by overwriting the file on disk with the changes in the editor."
                ))
            ],
            'description': ( localizeWithPath(
                _moduleId,
                40,
                "A save conflict can occur when a file is saved to disk that was changed by another program in the meantime. To prevent data loss, the user is asked to compare the changes in the editor with the version on disk. This setting should only be changed if you frequently encounter save conflict errors and may result in data loss if used without caution."
            )),
            'default': 'askUser',
            'scope': 5
        },
        'files.dialog.defaultPath': {
            'type': 'string',
            'pattern': '^((\\/|\\\\\\\\|[a-zA-Z]:\\\\).*)?$',
            'patternErrorMessage': ( localizeWithPath(
                _moduleId,
                41,
                "Default path for file dialogs must be an absolute path (e.g. C:\\\\myFolder or /myFolder)."
            )),
            'description': ( localizeWithPath(
                _moduleId,
                42,
                "Default path for file dialogs, overriding user's home path. Only used in the absence of a context-specific path, such as most recently opened file or folder."
            )),
            'scope': 2
        },
        'files.simpleDialog.enable': {
            'type': 'boolean',
            'description': ( localizeWithPath(
                _moduleId,
                43,
                "Enables the simple file dialog for opening and saving files and folders. The simple file dialog replaces the system file dialog when enabled."
            )),
            'default': false
        },
        'files.participants.timeout': {
            type: 'number',
            default: 60000,
            markdownDescription: ( localizeWithPath(
                _moduleId,
                44,
                "Timeout in milliseconds after which file participants for create, rename, and delete are cancelled. Use `0` to disable participants."
            )),
        }
    }
});
configurationRegistry.registerConfiguration({
    ...editorConfigurationBaseNode,
    properties: {
        'editor.formatOnSave': {
            'type': 'boolean',
            'description': ( localizeWithPath(
                _moduleId,
                45,
                "Format a file on save. A formatter must be available, the file must not be saved after delay, and the editor must not be shutting down."
            )),
            'scope': 5 ,
        },
        'editor.formatOnSaveMode': {
            'type': 'string',
            'default': 'file',
            'enum': [
                'file',
                'modifications',
                'modificationsIfAvailable'
            ],
            'enumDescriptions': [
                ( localizeWithPath(_moduleId, 46, "Format the whole file.")),
                ( localizeWithPath(_moduleId, 47, "Format modifications (requires source control).")),
                ( localizeWithPath(
                    _moduleId,
                    48,
                    "Will attempt to format modifications only (requires source control). If source control can't be used, then the whole file will be formatted."
                )),
            ],
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                49,
                "Controls if format on save formats the whole file or only modifications. Only applies when `#editor.formatOnSave#` is enabled."
            )),
            'scope': 5 ,
        },
    }
});
configurationRegistry.registerConfiguration({
    ...editorConfigurationBaseNode,
    properties: {
        'editor.formatOnSave': {
            'type': 'boolean',
            'description': ( localizeWithPath(
                _moduleId,
                45,
                "Format a file on save. A formatter must be available, the file must not be saved after delay, and the editor must not be shutting down."
            )),
            'scope': 5 ,
        },
        'editor.formatOnSaveMode': {
            'type': 'string',
            'default': 'file',
            'enum': [
                'file',
                'modifications',
                'modificationsIfAvailable'
            ],
            'enumDescriptions': [
                ( localizeWithPath(_moduleId, 46, "Format the whole file.")),
                ( localizeWithPath(_moduleId, 47, "Format modifications (requires source control).")),
                ( localizeWithPath(
                    _moduleId,
                    48,
                    "Will attempt to format modifications only (requires source control). If source control can't be used, then the whole file will be formatted."
                )),
            ],
            'markdownDescription': ( localizeWithPath(
                _moduleId,
                49,
                "Controls if format on save formats the whole file or only modifications. Only applies when `#editor.formatOnSave#` is enabled."
            )),
            'scope': 5 ,
        },
    }
});
