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 { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick } from '../../../../../helpers/event-manager/event-id/vega-event-id';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import { formatAndValidResponsiveToken } from '../../../../../utils/design-token';
import { Icons } from '../../../assets/icons';
export class WrittenModeRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-signature-capture-focus-e2e}
     */
    /* istanbul ignore next */
    this.signatureCaptureFocus = () => {
      this.signatureCaptureContainerRef.focus();
    };
  }
  getSignatureCaptureContainer() {
    return this.signatureCaptureContainerRef;
  }
  render() {
    return (h("vega-flex", { direction: "col", gap: "size-8" },
      this.renderLabel(),
      this.renderContainer(),
      this.renderFooter()));
  }
  renderLabel() {
    return (this.label && (h("vega-field-label", { onClick: this.signatureCaptureFocus, isFieldRequired: this.required, label: this.label, disabled: this.disabled })));
  }
  renderContainer() {
    return (h("div", { class: {
        'signature-capture-written-container': true,
        'disabled': this.disabled,
      }, "aria-label": "Please sign here", role: "textbox", tabIndex: this.disabled ? -1 : 0, ref: (ref) => (this.signatureCaptureContainerRef = ref) },
      this.renderPlaceholder(),
      this.renderSignaturePad()));
  }
  renderPlaceholder() {
    if (this.isDrawing || this.value)
      return;
    return (this.placeholder && (h("vega-flex", { class: "placeholder-container", gap: "size-8", justifyContent: "center", alignItems: "center", margin: {
        left: 'size-24',
        right: 'size-24',
      } },
      this.placeholderIcon && (h("vega-icon", { class: "placeholder-container-icon", size: "size-20", color: "text-secondary", icon: this.placeholderIcon })),
      h("div", { class: "placeholder-container-content" }, this.translationSlimmer.t(this.placeholder)))));
  }
  /*
   * When the clear button is displayed, since the error message and the clear button are in the same line, this element is displayed.
   */
  renderSignaturePad() {
    // TODO: Adding the SVG attribute will cause changes to the generated base64 value, leading to problems. https://gethired.atlassian.net/browse/VD-7854
    return (h("svg", { width: "100%", height: formatAndValidResponsiveToken(this.height, 'widthAndHeight'), "touch-action": "none", ref: (ref) => this.writtenModeSvgController.setSignatureContainerRef(ref) }));
  }
  renderFooter() {
    return (this.showClearBtn && (h("vega-flex", { class: "signature-capture-written-footer", justifyContent: "space-between" },
      h("div", { class: "vega-error vega-hidden vega-error-content" }),
      this.renderClearBtn())));
  }
  renderClearBtn() {
    return (h("div", { class: "clear-button" },
      h("vega-button-link", { size: "small", disabled: this.disabled, ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, () => {
            this.writtenModeSvgController.clear();
          });
        }, label: this.translationSlimmer.t('Clear Signature') })));
  }
}
(() => {
  VegaInternalIconManager.register(Icons);
})();
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "label", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "required", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "showClearBtn", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "placeholder", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "placeholderIcon", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "isDrawing", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "height", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "writtenModeSvgController", void 0);
__decorate([
  MapToComponentField()
], WrittenModeRenderer.prototype, "translationSlimmer", void 0);
