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 { ShadowlessElement } from '@blockeditor/lit';
import { css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
export const renderUniLit = (uni, props, options) => {
    return html ` <uni-lit
    .uni="${uni}"
    .props="${props}"
    .ref="${options?.ref}"
    style=${options?.style ? styleMap(options?.style) : ''}
  ></uni-lit>`;
};
let UniLit = class UniLit extends ShadowlessElement {
    get expose() {
        return this.uniReturn?.expose;
    }
    mount() {
        this.uniReturn = this.uni?.(this, this.props);
        if (this.ref) {
            // @ts-expect-error
            this.ref.value = this.uniReturn?.expose;
        }
    }
    unmount() {
        this.uniReturn?.unmount();
    }
    connectedCallback() {
        super.connectedCallback();
        this.mount();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.unmount();
    }
    updated(_changedProperties) {
        super.updated(_changedProperties);
        if (_changedProperties.has('uni')) {
            this.unmount();
            this.mount();
        }
        else if (_changedProperties.has('props')) {
            this.uniReturn?.update(this.props);
        }
    }
    render() {
        return html ``;
    }
};
UniLit.styles = css `
    uni-lit {
      display: contents;
    }
  `;
__decorate([
    property({ attribute: false })
], UniLit.prototype, "uni", void 0);
__decorate([
    property({ attribute: false })
], UniLit.prototype, "props", void 0);
__decorate([
    property({ attribute: false })
], UniLit.prototype, "ref", void 0);
UniLit = __decorate([
    customElement('uni-lit')
], UniLit);
export { UniLit };
export const createUniComponentFromWebComponent = (component) => {
    return (ele, props) => {
        const ins = new component();
        Object.assign(ins, props);
        ele.appendChild(ins);
        return {
            update: props => {
                Object.assign(ins, props);
            },
            unmount: () => {
                ins.remove();
            },
            expose: ins,
        };
    };
};
let UniAnyRender = class UniAnyRender extends ShadowlessElement {
    render() {
        return this.renderTemplate(this.props, this.expose);
    }
};
__decorate([
    property({ attribute: false })
], UniAnyRender.prototype, "props", void 0);
__decorate([
    property({ attribute: false })
], UniAnyRender.prototype, "expose", void 0);
__decorate([
    property({ attribute: false })
], UniAnyRender.prototype, "renderTemplate", void 0);
UniAnyRender = __decorate([
    customElement('uni-any-render')
], UniAnyRender);
export const defineUniComponent = (renderTemplate) => {
    return (ele, props) => {
        const ins = new UniAnyRender();
        ins.props = props;
        ins.expose = {};
        ins.renderTemplate = renderTemplate;
        ele.appendChild(ins);
        return {
            update: props => {
                ins.props = props;
            },
            unmount: () => {
                ins.remove();
            },
            expose: ins.expose,
        };
    };
};
//# sourceMappingURL=uni-component.js.map