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, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import { VegaInternalIconManager } from '../../../../../../../helpers/icon/internal-icon-manager';
import AlignRight from '../../../../../assets/align-right';
import AlignCenter from '../../../../../assets/align-center';
import AlignJustify from '../../../../../assets/align-justify';
import AlignLeft from '../../../../../assets/align-left';
import AlignTop from '../../assets/align-top';
import AlignBottom from '../../assets/align-bottom';
import AlignMiddle from '../../assets/align-middle';
import ObjectsAlignCenterHorizontal from '../../assets/objects-align-center-horizontal';
import ObjectsAlignLeft from '../../assets/objects-align-left';
import ObjectsAlignRight from '../../assets/objects-align-right';
export class VegaRichTextTablePropertiesRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.formTouched = false;
    /**
     * Mark the form as touched.
     */
    this.markFormTouched = () => {
      this.formTouched = true;
    };
    /**
     * Reset the touch state.
     */
    this.resetTouchedState = () => {
      this.formTouched = false;
    };
  }
  initialFormState(newValue) {
    this.resetTouchedState();
    this.resetColorRelatedFields(newValue);
    this.setFormFieldValues(newValue);
  }
  getFormRef() {
    return this.formRef;
  }
  /**
   * Indicates whether the form has been interacted with.
   *
   * @returns {boolean} True if the form has been touched; otherwise, false.
   */
  isFormTouched() {
    return this.formTouched;
  }
  render() {
    return (h("vega-form", { class: "table-properties-form", ref: (el) => (this.formRef = el), onMouseDown: this.markFormTouched }, this.type === 'TABLE'
      ? this.tableFormRenderer.renderPropertiesFields()
      : this.cellFormRenderer.renderPropertiesFields()));
  }
  /**
   * Set form field values if the form is not touched.
   *
   * @param formValues
   */
  setFormFieldValues(formValues) {
    if (this.formRef) {
      void this.formRef.reset(formValues);
    }
  }
  /**
   * Handle color related fields before setting form value to ensure change event is triggered.
   *
   * @param {RTETablePropertiesType} formValue - The form value to be set.
   */
  resetColorRelatedFields(formValue) {
    if (this.formRef) {
      if (formValue.borderColor) {
        const borderColorInput = this.formRef.querySelector('[data-vega-form="borderColor"]');
        borderColorInput && (borderColorInput.value = '');
      }
      if (formValue.backgroundColor) {
        const backgroundColorInput = this.formRef.querySelector('[data-vega-form="backgroundColor"]');
        backgroundColorInput && (backgroundColorInput.value = '');
      }
    }
  }
}
(() => {
  VegaInternalIconManager.register({
    'align-center': AlignCenter,
    'align-justify': AlignJustify,
    'align-left': AlignLeft,
    'align-right': AlignRight,
    'align-top': AlignTop,
    'align-bottom': AlignBottom,
    'align-middle': AlignMiddle,
    'objects-align-left': ObjectsAlignLeft,
    'objects-align-center': ObjectsAlignCenterHorizontal,
    'objects-align-right': ObjectsAlignRight,
  });
})();
__decorate([
  MapToComponentField()
], VegaRichTextTablePropertiesRenderer.prototype, "type", void 0);
__decorate([
  MapToComponentField()
], VegaRichTextTablePropertiesRenderer.prototype, "tableFormRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaRichTextTablePropertiesRenderer.prototype, "cellFormRenderer", void 0);
__decorate([
  MapToComponentMethod('watchDefaultValueChange')
], VegaRichTextTablePropertiesRenderer.prototype, "initialFormState", null);
