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 './filter-group.js';
import './filter-root.js';
import { ShadowlessElement, WithDisposable } from '@blockeditor/lit';
import { css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { createPopup } from '../../../_common/components/menu/index.js';
let AdvancedFilterModal = class AdvancedFilterModal extends WithDisposable(ShadowlessElement) {
    constructor() {
        super(...arguments);
        this.isRoot = false;
    }
    connectedCallback() {
        super.connectedCallback();
        this.disposables.addFromEvent(this, 'mouseover', e => {
            let current = e.target;
            while (current && current !== this) {
                if (current.classList.contains('filter-exactly-hover-container')) {
                    current.classList.add('filter-exactly-hover-background');
                    break;
                }
                current = current.parentElement;
            }
        });
        this.disposables.addFromEvent(this, 'mouseout', e => {
            let current = e.target;
            while (current && current !== this) {
                if (current.classList.contains('filter-exactly-hover-container')) {
                    current.classList.remove('filter-exactly-hover-background');
                    break;
                }
                current = current.parentElement;
            }
        });
    }
    render() {
        return html `
      <div class="filter-modal-container">
        ${this.isRoot
            ? html ` <filter-root-view
              .onBack=${this.onBack}
              .vars="${this.vars}"
              .data="${this.data}"
              .setData="${this.setData}"
            ></filter-root-view>`
            : html ` <filter-group-view
              .vars="${this.vars}"
              .data="${this.data}"
              .setData="${this.setData}"
            ></filter-group-view>`}
      </div>
      <div class="filter-modal-bottom">
        <div
          @click=${this.onDelete}
          class="filter-modal-button filter-delete-button"
        >
          Delete
        </div>
      </div>
    `;
    }
};
AdvancedFilterModal.styles = css `
    advanced-filter-modal {
      background-color: var(--affine-background-overlay-panel-color);
      position: absolute;
      border-radius: 8px;
      box-shadow: var(--affine-shadow-2);
      min-width: 500px;
    }

    .filter-modal-bottom {
      border-top: 1px solid var(--affine-border-color);
      padding: 8px;
    }

    .filter-modal-button {
      padding: 8px 12px;
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 14px;
      line-height: 22px;
      border-radius: 4px;
      cursor: pointer;
      color: var(--affine-text-secondary-color);
    }

    .filter-modal-button svg {
      fill: var(--affine-text-secondary-color);
      color: var(--affine-text-secondary-color);
      width: 20px;
      height: 20px;
    }

    .filter-modal-button:hover {
      background-color: var(--affine-hover-color);
      color: var(--affine-text-primary-color);
    }
    .filter-modal-button:hover svg {
      fill: var(--affine-text-primary-color);
      color: var(--affine-text-primary-color);
    }

    .filter-delete-button:hover {
      background-color: var(--affine-background-error-color);
      color: var(--affine-error-color);
    }

    .filter-exactly-hover-container {
      transition: background-color 0.2s ease-in-out;
    }

    .filter-exactly-hover-background {
      background-color: var(--affine-hover-color);
    }
  `;
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "isRoot", void 0);
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "data", void 0);
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "vars", void 0);
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "setData", void 0);
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "onDelete", void 0);
__decorate([
    property({ attribute: false })
], AdvancedFilterModal.prototype, "onBack", void 0);
AdvancedFilterModal = __decorate([
    customElement('advanced-filter-modal')
], AdvancedFilterModal);
export { AdvancedFilterModal };
export const popFilterModal = (target, props) => {
    const filter = new AdvancedFilterModal();
    filter.vars = props.vars;
    filter.data = props.value;
    filter.isRoot = props.isRoot;
    filter.onDelete = () => {
        props.onDelete();
        close();
    };
    filter.onBack = () => {
        props.onBack();
        close();
    };
    filter.setData = group => {
        props.onChange(group);
        filter.data = group;
    };
    const close = createPopup(target, filter);
};
//# sourceMappingURL=filter-modal.js.map