import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { c as config } from './config.js';
import { L as Locale } from './locale.js';
import { d as defineCustomElement$2 } from './container.js';

const bpmImportGxpmCss = ":host{display:grid;block-size:100%}.opacity-0{opacity:0}.gxi-hidden{display:none !important}.align-center{display:flex;align-items:center}.align-end{display:flex;align-items:end}.overflow-auto{overflow:auto}:host(.gx-ide-component){height:100% !important;display:flex !important;flex-direction:column !important}.gx-ide-main-wrapper{color:var(--gx-ide-component-text-color);font-weight:var(--font-style-regular);font-size:var(--font-size-body-m);font-family:var(--font-family-body);height:100%;display:flex;flex-direction:column;flex-grow:1;box-sizing:border-box}.buttons-container{display:flex;gap:var(--spacing-gap-m)}.giu-static-pill-icon-and-text,.giu-static-pill{background-color:var(--elevation-background-color, var(--color-accent-surface-elevation-1));padding-inline:var(--spacing-padding-m);color:var(--color-text-neutral-default);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-weight:var(--font-style-regular);border-radius:4px;min-block-size:25px;display:inline-grid;align-items:center;pointer-events:none;inline-size:max-content}.giu-static-pill-icon-and-text{display:inline-grid;grid-auto-flow:column;grid-auto-columns:max-content;gap:var(--spacing-gap-m)}.tab-full-width-buttons::part(tab-list block-start),.tab-full-width-buttons::part(tab-list block-end){grid-auto-columns:1fr}.tab-full-width-buttons::part(tab block-start){justify-content:center}.tree-view::part(item__header){--icon__system_warning_warning--disabled:var(\n    --icon__system_warning_warning--enabled\n  )}.tabular-grid{--focus-outline-width:1px}.control-wrapper{display:flex;gap:var(--spacing-gap-m);align-items:center}.control-wrapper--vertical{flex-direction:column;align-items:start}.controls-wrapper{display:flex;gap:var(--spacing-gap-m)}.controls-wrapper--vertical{flex-direction:column;align-items:start}.input-text{box-sizing:border-box;background-color:transparent;border:1px solid var(--color-border-neutral-default);border-radius:4px;height:26px;color:var(--color-text-neutral-default);font-size:var(--font-size-body-xs)}.input-text--full-width{align-self:stretch}:host{display:block}.header{display:grid;align-items:center;grid-template-columns:max-content 1fr min-content;gap:var(--spacing-gap-l)}.hidden-input{display:none}";

const GxIdeTemplate = /*@__PURE__*/ proxyCustomElement(class GxIdeTemplate extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.componentDidRenderFirstTime = createEvent(this, "componentDidRenderFirstTime", 7);
        this.renderedFirstTime = false;
        // 7.LISTENERS //
        // 8.PUBLIC METHODS API //
        // 9.LOCAL METHODS //
        this.loadFileHandle = async () => {
            this.fileInput.click();
        };
        this.handleFileInputChange = (event) => {
            const fileInput = event.target;
            if (fileInput.files && fileInput.files.length > 0) {
                const newFile = fileInput.files[0];
                this.selectedFile = newFile;
                this.pathValue = this.selectedFile.name;
            }
            this.fileInput.value = null;
        };
        this.handlePathInputChange = (event) => {
            this.selectedFile = null;
            const inputElement = event.target;
            const newValue = inputElement.value;
            this.pathValue = newValue;
        };
        this.confirmCallbackHandle = async () => {
            if (this.confirmCallback) {
                const fileName = this.pathValue
                    .replace(/^.*?([^\\\/]*)$/, "$1")
                    .toLowerCase()
                    .trim();
                if (fileName === ".gxpm" || !fileName.endsWith(".gxpm")) {
                    return;
                }
                const fileData = this.selectedFile
                    ? this.selectedFile
                    : new File([this.pathValue], fileName);
                const data = {
                    automaticBackup: this.automaticBackupEl.value === "true",
                    file: fileData
                };
                await this.confirmCallback(data);
                this.fileInput.value = null;
                this.selectedFile = null;
                this.pathValue = "";
                this.automaticBackupEl.value = "false";
            }
        };
        this.selectedFile = null;
        this.pathValue = "";
        this.displayTitle = false;
        this.confirmCallback = undefined;
        this.cancelCallback = undefined;
    }
    // 6.COMPONENT LIFECYCLE METHODS //
    async componentWillLoad() {
        this._componentLocale = await Locale.getComponentStrings(this.el);
    }
    componentDidRender() {
        if (!this.renderedFirstTime) {
            this.componentDidRenderFirstTime.emit(this._componentLocale.componentName);
            this.renderedFirstTime = true;
        }
    }
    // 10.RENDER() FUNCTION //
    render() {
        return (h(Host, { class: "gx-ide-component" }, h("div", { class: "gx-ide-main-wrapper" }, h("gx-ide-container", { slimmerFooter: config.gxIdeContainer.slimmerFooter }, h("div", { class: "header" }, h("label", { htmlFor: "project-path" }, this._componentLocale.main.projectPathInputLabel), h("input", { type: "text", class: "input-text", id: "project-path", value: this.pathValue, onChange: this.handlePathInputChange }), h("input", { type: "file", id: "input_file", accept: ".gxpm", ref: el => (this.fileInput = el), onChange: this.handleFileInputChange, class: "hidden-input" }), h("button", { onClick: this.loadFileHandle }, this._componentLocale.main.addFilesButton)), h("div", { class: "control-wrapper" }, h("label", { htmlFor: "automatic-backup" }, this._componentLocale.main.automaticBackupCheckboxLabel), h("ch-checkbox", { id: "automatic-backup", accessibleName: "automatic-backup", checkedValue: "true", unCheckedValue: "false", value: "checked", ref: (el) => (this.automaticBackupEl = el) })), h("button", { slot: "footer-end", onClick: this.cancelCallback }, this._componentLocale.footer.cancelButton), h("button", { slot: "footer-end", onClick: this.confirmCallbackHandle }, this._componentLocale.footer.confirmButton)))));
    }
    static get assetsDirs() { return ["gx-ide-assets/bpm-import-gxpm"]; }
    get el() { return this; }
    static get style() { return bpmImportGxpmCss; }
}, [1, "gx-ide-bpm-import-gxpm", {
        "displayTitle": [4, "display-title"],
        "confirmCallback": [16],
        "cancelCallback": [16],
        "selectedFile": [32],
        "pathValue": [32]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-bpm-import-gxpm", "gx-ide-container"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-bpm-import-gxpm":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeTemplate);
            }
            break;
        case "gx-ide-container":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const GxIdeBpmImportGxpm = GxIdeTemplate;
const defineCustomElement = defineCustomElement$1;

export { GxIdeBpmImportGxpm, defineCustomElement };

//# sourceMappingURL=gx-ide-bpm-import-gxpm.js.map