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 { html, customElement, property, css, state, repeat } from '../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
import { UmbTextStyles } from '../../../../core/style/index.js';
import { UmbChangeEvent } from '../../../../core/event/index.js';
let UmbPropertyEditorUIBlockGridColumnSpanElement = class UmbPropertyEditorUIBlockGridColumnSpanElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this.value = [];
        this._columnsArray = Array.from(Array(12).keys());
    }
    set config(config) {
        const maxColumns = config?.getValueByAlias('maxColumns');
        if (typeof maxColumns === 'number') {
            this._columnsArray = Array.from(Array(maxColumns).keys());
        }
    }
    #pickColumn(index) {
        const value = this.value ?? [];
        const exists = value.find((column) => column.columnSpan === index);
        if (exists) {
            this.value = value.filter((column) => column.columnSpan !== index);
        }
        else {
            this.value = [...value, { columnSpan: index }];
        }
        this.dispatchEvent(new UmbChangeEvent());
    }
    render() {
        const template = repeat(this._columnsArray, (index) => index, (index) => {
            const colNumber = index + 1;
            let classes = 'default';
            if (this.value && this.value.length > 0) {
                const applied = this.value.find((column) => column.columnSpan >= colNumber);
                const picked = this.value.find((column) => column.columnSpan === colNumber);
                classes = picked ? 'picked applied' : applied ? 'applied' : 'default';
            }
            return html `<div class="${classes}" data-index=${index}>
					<span>${colNumber}</span>
					<button type="button" aria-label=${colNumber} @click=${() => this.#pickColumn(colNumber)}></button>
				</div>`;
        });
        return html `<div id="wrapper">${template}</div>`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			#wrapper {
				box-sizing: border-box;
				display: flex;
				flex-wrap: nowrap;
				border: 1px solid var(--uui-color-divider-emphasis);
			}

			#wrapper div {
				color: var(--uui-color-divider-emphasis);
				position: relative;
				flex-grow: 1;
				min-height: 35px;
				box-sizing: border-box;
				display: flex;
				justify-content: flex-end;
				padding-left: 5px;
				border-right: 1px solid transparent;
			}

			#wrapper div:not(.picked) {
				border-right: 1px solid var(--uui-color-divider-standalone);
			}

			#wrapper div.picked,
			#wrapper div:has(button:hover) {
				color: var(--uui-color-interactive);
			}

			#wrapper div:last-child {
				border-right: 1px solid transparent;
			}

			#wrapper:has(button:hover) div:not(:has(button:hover) ~ div) {
				background-color: var(--uui-color-interactive-emphasis);
			}

			#wrapper div span {
				user-select: none;
				position: absolute;
				padding: var(--uui-size-6);
				transform: translate(50%, -75%);
			}

			#wrapper div button {
				border: none;
				position: absolute;
				z-index: 1;
				transform: translateX(50%);
				inset: -1px;
				opacity: 0;
			}

			#wrapper .picked::after {
				content: '';
				position: absolute;
				transform: translateX(50%);
				width: 4px;
				border-right: 1px solid var(--uui-color-interactive);
				background-color: var(--uui-color-surface);
				top: 0;
				right: 0;
				bottom: 0;
			}

			#wrapper .applied {
				background-color: var(--uui-color-interactive);
			}
		`,
    ]; }
};
__decorate([
    property({ type: Array })
], UmbPropertyEditorUIBlockGridColumnSpanElement.prototype, "value", void 0);
__decorate([
    state()
], UmbPropertyEditorUIBlockGridColumnSpanElement.prototype, "_columnsArray", void 0);
UmbPropertyEditorUIBlockGridColumnSpanElement = __decorate([
    customElement('umb-property-editor-ui-block-grid-column-span')
], UmbPropertyEditorUIBlockGridColumnSpanElement);
export { UmbPropertyEditorUIBlockGridColumnSpanElement };
export default UmbPropertyEditorUIBlockGridColumnSpanElement;
