import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-b7735e0d.js';

const dvnFieldInputCellRichContentCss = "dvn-field-input-cell-rich-content{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;height:100%}dvn-field-input-cell-rich-content .form-footer{padding:calc(2 * var(--spacing-unit));background-color:var(--color-background-secondary)}";

let DvnFieldInputCellRichContent = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.cellFormCancel = createEvent(this, "cellFormCancel", 7);
    this.cellFormSubmit = createEvent(this, "cellFormSubmit", 7);
    this.isConfirmationDialogShown = false;
  }
  async focus() {
    var _a, _b;
    (_b = (_a = this.el.querySelector('dvn-input')) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
  }
  ;
  render() {
    const { field, value } = this;
    const editorValue = value || {
      version: '0.0.1',
      content: [{
          type: 'text',
          id: 'form-content',
          value: {
            placeholder: field.placeholder,
            text: '',
          },
        }]
    };
    return (h(Host, null, h("dvn-side-modal", { shown: true, onDismiss: () => {
        var _a, _b;
        if (JSON.stringify((_a = this.value) === null || _a === void 0 ? void 0 : _a.content) !== JSON.stringify((_b = this.internalValue) === null || _b === void 0 ? void 0 : _b.content)) {
          this.isConfirmationDialogShown = true;
        }
        else {
          this.cellFormCancel.emit();
        }
      } }, h("div", { class: "flex-grow-1 d-flex flex-column mt-3" }, h("div", { class: "flex-grow-1" }, h("dvn-rich-editor", { key: "editor", onChange: (e) => {
        e.stopImmediatePropagation();
        const editorValue = e.detail;
        this.internalValue = {
          version: '0.0.1',
          content: editorValue,
        };
      }, editorSettings: field.settings || defaultSettings, value: editorValue.content })), h("div", { class: "form-footer" }, h("dvn-button", { leaned: true, onClick: (e) => {
        e.stopImmediatePropagation();
        this.cellFormSubmit.emit({ value: this.internalValue });
        this.cellFormCancel.emit();
      } }, "Save")))), h("dvn-dialog", { shown: this.isConfirmationDialogShown, title: "You have unsaved changes" }, "You're going to loose the changes if you don't save.", h("div", { slot: "actions" }, h("dvn-button", { tint: "danger", view: "flat", onClick: (e) => {
        e.stopImmediatePropagation();
        this.cellFormCancel.emit();
      } }, "Discard Changes"), h("dvn-button", { view: "flat", onClick: () => this.isConfirmationDialogShown = false }, "Cancel")))));
  }
  get el() { return getElement(this); }
};
const defaultSettings = {
  enableDrag: false,
  enableBlockCreation: false,
  enableBlockDeletion: false,
  hideDragControls: true,
  blockTypes: [],
  blockSettings: {
    text: {
      textSelectionOptions: ['bold', 'link']
    }
  }
};
DvnFieldInputCellRichContent.style = dvnFieldInputCellRichContentCss;

export { DvnFieldInputCellRichContent as dvn_field_input_cell_rich_content };
