"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _semiJsonViewerCore = require("@douyinfe/semi-json-viewer-core");
var _foundation = _interopRequireDefault(require("../base/foundation"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class JsonViewerFoundation extends _foundation.default {
  constructor(adapter) {
    super(Object.assign(Object.assign({}, JsonViewerFoundation), adapter));
    this.jsonViewer = null;
  }
  init() {
    const props = this.getProps();
    const editorRef = this._adapter.getEditorRef();
    this.jsonViewer = new _semiJsonViewerCore.JsonViewer(editorRef, props.value, props.options);
    this.jsonViewer.emitter.on('customRender', e => {
      this._adapter.notifyCustomRender(e.customRenderMap);
    });
    this.jsonViewer.layout();
    this.jsonViewer.emitter.on('contentChanged', e => {
      var _a;
      this._adapter.notifyChange((_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getModel().getValue());
      if (this.getState('showSearchBar')) {
        this.search(this._adapter.getSearchRef().value);
      }
    });
  }
  search(searchText) {
    var _a;
    const state = this.getState('searchOptions');
    const {
      caseSensitive,
      wholeWord,
      regex
    } = state;
    (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().search(searchText, caseSensitive, wholeWord, regex);
  }
  prevSearch() {
    var _a;
    (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(-1);
  }
  nextSearch() {
    var _a;
    (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(1);
  }
  replace(replaceText) {
    var _a;
    if (this.getProps().options.readOnly) {
      return;
    }
    (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().replace(replaceText);
  }
  replaceAll(replaceText) {
    var _a;
    if (this.getProps().options.readOnly) {
      return;
    }
    (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().replaceAll(replaceText);
  }
  setSearchOptions(key) {
    this._adapter.setSearchOptions(key);
  }
  showSearchBar() {
    this._adapter.showSearchBar();
  }
}
var _default = exports.default = JsonViewerFoundation;