
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { localize } from '../../../../nls.js';
import { Emitter } from '../../../../base/common/event.js';
import { BinaryEditorModel } from '../../../common/editor/binaryEditorModel.js';
import { IStorageService } from '../../../../platform/storage/common/storage.service.js';
import { ByteSize } from '../../../../platform/files/common/files.js';
import { EditorPlaceholder } from './editorPlaceholder.js';

let BaseBinaryResourceEditor = class BaseBinaryResourceEditor extends EditorPlaceholder {
    constructor(id, group, callbacks, telemetryService, themeService, storageService) {
        super(id, group, telemetryService, themeService, storageService);
        this.callbacks = callbacks;
        this._onDidChangeMetadata = this._register(( new Emitter()));
        this.onDidChangeMetadata = this._onDidChangeMetadata.event;
        this._onDidOpenInPlace = this._register(( new Emitter()));
        this.onDidOpenInPlace = this._onDidOpenInPlace.event;
    }
    getTitle() {
        return this.input ? this.input.getName() : ( localize(3113, "Binary Viewer"));
    }
    async getContents(input, options) {
        const model = await input.resolve();
        if (!(model instanceof BinaryEditorModel)) {
            throw ( new Error("Unable to open file as binary"));
        }
        const size = model.getSize();
        this.handleMetadataChanged(typeof size === "number" ? ByteSize.formatSize(size) : "");
        return {
            icon: "$(warning)",
            label: ( localize(
                3114,
                "The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding."
            )),
            actions: [{
                label: ( localize(3115, "Open Anyway")),
                run: async () => {
                    await this.callbacks.openInternal(input, options);
                    this._onDidOpenInPlace.fire();
                }
            }]
        };
    }
    handleMetadataChanged(meta) {
        this.metadata = meta;
        this._onDidChangeMetadata.fire();
    }
    getMetadata() {
        return this.metadata;
    }
};
BaseBinaryResourceEditor = ( __decorate([( __param(5, IStorageService))], BaseBinaryResourceEditor));

export { BaseBinaryResourceEditor };
