var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
/**
 * Control the component focus state.
 */
export class VegaCodeBlockFocusController extends VegaSlimmer {
  /**
   * Focus the code block and update the selection range offset to end.
   */
  focusAndUpdateSelection() {
    if (!this.disabled && !this.readOnly) {
      const codeContentContainerRef = this.contentRenderer.getCodeContentContainerRef();
      if (codeContentContainerRef) {
        codeContentContainerRef.focus();
        const offset = this.value && this.value.code && this.value.code !== ' ' ? this.value.code.length : 0;
        this.selectionController.setNextCodeBlockRange(offset, true);
      }
    }
  }
  /**
   * Remove the focus class when component disabled or readonly.
   */
  removeFocusAfterDisabled() {
    if (this.disabled || this.readOnly) {
      this.host.classList.remove('focus');
    }
  }
}
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "readOnly", void 0);
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "contentRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaCodeBlockFocusController.prototype, "selectionController", void 0);
__decorate([
  MapToComponentMethod('doFocus')
], VegaCodeBlockFocusController.prototype, "focusAndUpdateSelection", null);
__decorate([
  MapToComponentMethod('watchEditableChange')
], VegaCodeBlockFocusController.prototype, "removeFocusAfterDisabled", null);
