import { p as proxyCustomElement, H, c as createEvent, h, F as Fragment, d as Host } from './p-D16h8pzh.js';
import { r as requireFormat } from './p-BvYQ0L1f.js';
import { getRGBA } from '@verdocs/js-sdk';
import { F as FORMAT_TIMESTAMP } from './p-Dl7Xw8F0.js';
import { S as SettingsIcon } from './p-7LXbcjVz.js';
import { S as Store } from './p-DmsV595e.js';
import { d as defineCustomElement$9 } from './p-BNrp2UP2.js';
import { d as defineCustomElement$8 } from './p-wYGYhfrp.js';
import { d as defineCustomElement$7 } from './p-DsCKNQPC.js';
import { d as defineCustomElement$6 } from './p-BGZ_owBm.js';
import { d as defineCustomElement$5 } from './p-Bv-L0hsU.js';
import { d as defineCustomElement$4 } from './p-Boia1Nbz.js';
import { d as defineCustomElement$3 } from './p-Cy-AXBKH.js';
import { d as defineCustomElement$2 } from './p-vCuIwe1D.js';
import { d as defineCustomElement$1 } from './p-C_SISdpZ.js';

var formatExports = /*@__PURE__*/ requireFormat();

const verdocsFieldTimestampCss = "@-webkit-keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}@keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}verdocs-field-timestamp{width:160px;height:15px;display:block;font-size:9px;position:relative;scroll-margin:20px 0;background-color:transparent;-webkit-transform-origin:bottom left;transform-origin:bottom left;font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-field-timestamp.done{opacity:1}verdocs-field-timestamp input{position:absolute;cursor:inherit;opacity:0.5;width:100%;height:100%;font-size:9px;background:none;font-weight:500;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-box-sizing:border-box;box-sizing:border-box;color:rgba(0, 0, 0, 0.87);border:1px solid rgba(0, 0, 0, 0.2)}verdocs-field-timestamp input.hide{display:none}verdocs-field-timestamp label{top:-14px;left:-1px;height:14px;color:white;padding:0 4px;font-size:9px;line-height:13px;position:absolute;background:#4a4a99;border-top-left-radius:2px;border-top-right-radius:2px}verdocs-field-timestamp.required{border:1px solid rgb(204, 0, 0)}verdocs-field-timestamp.focused{-webkit-animation:verdocs-field-pulse 0.4s 1;animation:verdocs-field-pulse 0.4s 1}verdocs-field-timestamp verdocs-button-panel{top:-3px;left:-2px;opacity:0.5;z-index:1000;cursor:pointer;position:absolute;-webkit-transform:scale(0.6);transform:scale(0.6)}verdocs-field-timestamp verdocs-button-panel[data-active],verdocs-field-timestamp verdocs-button-panel:hover{opacity:1}verdocs-field-timestamp verdocs-button-panel .icon svg{fill:#333333}verdocs-field-timestamp verdocs-button-panel .icon:hover svg{fill:#000000}verdocs-field-timestamp .settings-icon{position:absolute;top:-3px;left:-20px;display:inline-block;cursor:pointer;opacity:0.3}verdocs-field-timestamp .settings-icon svg{fill:#707ae5}verdocs-field-timestamp .settings-icon:hover{opacity:1}";

const VerdocsFieldTimestamp = /*@__PURE__*/ proxyCustomElement(class VerdocsFieldTimestamp extends H {
    constructor() {
        super();
        this.__registerHost();
        this.settingsChanged = createEvent(this, "settingsChanged");
        this.deleted = createEvent(this, "deleted");
        /**
         * Fields may be attached to templates or envelopes, but only template fields may be edited.
         */
        this.source = 'template';
        /**
         * The source template or envelope ID the field is found in.
         */
        this.sourceid = '';
        /**
         * The name of the field to display.
         */
        this.fieldname = '';
        /**
         * Override the field's settings. This is intended to be used during signing when fields are being
         * mutated.
         */
        this.field = null;
        /**
         * If set, overrides the field's settings object. Primarily used to support "preview" modes where all fields are disabled.
         */
        this.disabled = false;
        /**
         * If set, a settings icon will be displayed on hover. The settings shown allow the field's recipient and other settings to be
         * changed, so it should typically only be enabled in the Builder.
         */
        this.editable = false;
        /**
         * If set, the field may be dragged to a new location. This should only be enabled in the Builder, or for self-placed fields.
         */
        this.moveable = false;
        /**
         * If set, the field is considered "done" and is drawn in a display-final-value state.
         */
        this.done = false;
        /**
         * If set, the field will be be scaled horizontally by this factor.
         */
        this.xscale = 1;
        /**
         * If set, the field will be be scaled vertically by this factor.
         */
        this.yscale = 1;
        /**
         * The page the field is on
         */
        this.pagenumber = 1;
        this.showingProperties = false;
    }
    async focusField() {
        this.el.focus();
    }
    async showSettingsPanel() {
        const settingsPanel = document.getElementById(`verdocs-settings-panel-${this.fieldname}`);
        if (settingsPanel && settingsPanel.showPanel) {
            settingsPanel.showPanel();
        }
    }
    async hideSettingsPanel() {
        const settingsPanel = document.getElementById(`verdocs-settings-panel-${this.fieldname}`);
        if (settingsPanel && settingsPanel.hidePanel) {
            settingsPanel.hidePanel();
        }
        this.showingProperties = false;
    }
    render() {
        const { source, sourceid, fieldname, editable = false, done = false, disabled = false, xscale = 1, yscale = 1 } = this;
        const { index, field } = Store.getField(source, sourceid, fieldname, this.field);
        const { required = false, placeholder = '', value = '', label = '' } = field || {};
        const backgroundColor = getRGBA(index);
        const formatted = formatExports.format(new Date(value || new Date().toISOString()), FORMAT_TIMESTAMP);
        if (done) {
            return h(Host, { class: { done } }, formatted);
        }
        return (h(Host, { class: { required, disabled, done }, style: { backgroundColor } }, label && h("label", null, label), h("input", { type: "text", placeholder: placeholder, value: formatted, disabled: true, ref: el => (this.el = el) }), editable && (h(Fragment, null, h("div", { id: `verdocs-settings-panel-trigger-${fieldname}`, style: { transform: `scale(${Math.floor((1 / xscale) * 1000) / 1000}, ${Math.floor((1 / yscale) * 1000) / 1000})` }, class: "settings-icon", innerHTML: SettingsIcon, onClick: (e) => {
                e.stopPropagation();
                this.showingProperties = !this.showingProperties;
            } }), this.showingProperties && (h("verdocs-portal", { anchor: `verdocs-settings-panel-trigger-${fieldname}`, onClickAway: () => (this.showingProperties = false) }, h("verdocs-template-field-properties", { templateId: sourceid, fieldName: fieldname, onClose: () => this.hideSettingsPanel(), onDelete: () => {
                var _a;
                (_a = this.deleted) === null || _a === void 0 ? void 0 : _a.emit({ fieldName: fieldname });
                return this.hideSettingsPanel();
            }, onSettingsChanged: e => {
                var _a;
                (_a = this.settingsChanged) === null || _a === void 0 ? void 0 : _a.emit(e.detail);
                return this.hideSettingsPanel();
            }, helpText: 'Time stamps are automatically set when the recipient signs the document.' })))))));
    }
    static get style() { return verdocsFieldTimestampCss; }
}, [256, "verdocs-field-timestamp", {
        "source": [513],
        "sourceid": [513],
        "fieldname": [513],
        "field": [16],
        "disabled": [516],
        "editable": [516],
        "moveable": [516],
        "done": [516],
        "xscale": [514],
        "yscale": [514],
        "pagenumber": [2],
        "showingProperties": [32],
        "focusField": [64],
        "showSettingsPanel": [64],
        "hideSettingsPanel": [64]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["verdocs-field-timestamp", "verdocs-button", "verdocs-checkbox", "verdocs-component-error", "verdocs-help-icon", "verdocs-loader", "verdocs-portal", "verdocs-select-input", "verdocs-template-field-properties", "verdocs-text-input"];
    components.forEach(tagName => { switch (tagName) {
        case "verdocs-field-timestamp":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, VerdocsFieldTimestamp);
            }
            break;
        case "verdocs-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "verdocs-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "verdocs-component-error":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "verdocs-help-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "verdocs-loader":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "verdocs-portal":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "verdocs-select-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "verdocs-template-field-properties":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "verdocs-text-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { VerdocsFieldTimestamp as V, defineCustomElement as d };
//# sourceMappingURL=p-DF8La-N2.js.map

//# sourceMappingURL=p-DF8La-N2.js.map