import "../../common/atomic-modal/atomic-modal.js";
import "../atomic-insight-user-actions-timeline/atomic-insight-user-actions-timeline.js";
import { LitElement, css, html } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { when } from "lit/directives/when.js";
import { ATOMIC_MODAL_EXPORT_PARTS } from "../../common/atomic-modal/export-parts.js";
import { renderButton } from "../../common/button.js";
import { booleanConverter } from "../../../converters/boolean-converter.js";
import { bindingGuard } from "../../../decorators/binding-guard.js";
import { bindings } from "../../../decorators/bindings.js";
import { errorGuard } from "../../../decorators/error-guard.js";
import { withTailwindStyles } from "../../../decorators/with-tailwind-styles.js";
import { rectEquals } from "../../../utils/dom-utils.js";
import images_close from "../../../images/close.js";
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) 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;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
class AtomicInsightUserActionsModal extends LitElement {
    disconnectedCallback() {
        super.disconnectedCallback();
        if (void 0 !== this.animationFrameId) window.cancelAnimationFrame(this.animationFrameId);
    }
    initialize() {}
    updated(changedProperties) {
        if (changedProperties.has('isOpen') && this.isOpen) this.onAnimationFrame();
    }
    render() {
        return html`
      ${when(this.interfaceDimensions, ()=>html`
          <style>
            atomic-modal::part(backdrop) {
              top: ${this.interfaceDimensions.top}px;
              left: ${this.interfaceDimensions.left}px;
              width: ${this.interfaceDimensions.width}px;
              height: ${this.interfaceDimensions.height}px;
            }
          </style>
        `)}
      <atomic-modal
        .fullscreen=${true}
        .isOpen=${this.isOpen}
        .source=${this.openButton}
        .container=${this}
        .close=${()=>{
            this.isOpen = false;
        }}
        exportparts=${ATOMIC_MODAL_EXPORT_PARTS}
        .scope=${this.bindings.interfaceElement}
      >
        ${this.renderHeader()} ${this.renderBody()}
      </atomic-modal>
    `;
    }
    renderHeader() {
        return html`
      <div slot="header" class="contents">
        <div part="title" class="font-light truncate">
          ${this.bindings.i18n.t('user-actions')}
        </div>
        ${renderButton({
            props: {
                style: 'text-transparent',
                class: 'grid place-items-center',
                part: 'close-button',
                onClick: ()=>{
                    this.isOpen = false;
                },
                ariaLabel: this.bindings.i18n.t('close')
            }
        })(html`
          <atomic-icon
            part="close-icon"
            class="w-5 h-5"
            .icon=${images_close}
          ></atomic-icon>
        `)}
      </div>
    `;
    }
    renderBody() {
        return html`
      <aside
        style="height: 100%"
        slot="body"
        class="flex flex-col w-full px-2"
        aria-label=${this.bindings.i18n.t('user-actions-content')}
      >
        <atomic-insight-user-actions-timeline
          .userId=${this.userId}
          .ticketCreationDateTime=${this.ticketCreationDateTime}
          .excludedCustomActions=${this.excludedCustomActions}
          class="flex-1"
        ></atomic-insight-user-actions-timeline>
      </aside>
    `;
    }
    onAnimationFrame() {
        if (!this.isOpen) {
            this.animationFrameId = void 0;
            return;
        }
        if (this.dimensionChanged()) this.updateDimensions();
        this.animationFrameId = window.requestAnimationFrame(()=>this.onAnimationFrame());
    }
    dimensionChanged() {
        if (!this.interfaceDimensions) return true;
        if (!this.bindings?.interfaceElement) return false;
        return !rectEquals(this.interfaceDimensions, this.bindings.interfaceElement.getBoundingClientRect());
    }
    updateDimensions() {
        if (!this.bindings?.interfaceElement) return;
        this.interfaceDimensions = this.bindings.interfaceElement.getBoundingClientRect();
    }
    constructor(...args){
        super(...args), this.isOpen = false, this.excludedCustomActions = [];
    }
}
AtomicInsightUserActionsModal.styles = css`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */atomic-modal::part(body-wrapper),atomic-modal::part(footer-wrapper){padding:2px}`;
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightUserActionsModal.prototype, "bindings", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightUserActionsModal.prototype, "error", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof DOMRect ? Object : DOMRect)
], AtomicInsightUserActionsModal.prototype, "interfaceDimensions", void 0);
_ts_decorate([
    property({
        type: Object,
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof HTMLElement ? Object : HTMLElement)
], AtomicInsightUserActionsModal.prototype, "openButton", void 0);
_ts_decorate([
    property({
        type: Boolean,
        reflect: true,
        converter: booleanConverter,
        attribute: 'is-open'
    })
], AtomicInsightUserActionsModal.prototype, "isOpen", void 0);
_ts_decorate([
    property({
        type: String,
        attribute: 'user-id'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsModal.prototype, "userId", void 0);
_ts_decorate([
    property({
        type: String,
        attribute: 'ticket-creation-date-time'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsModal.prototype, "ticketCreationDateTime", void 0);
_ts_decorate([
    property({
        type: Array,
        attribute: 'excluded-custom-actions'
    }),
    _ts_metadata("design:type", Array)
], AtomicInsightUserActionsModal.prototype, "excludedCustomActions", void 0);
_ts_decorate([
    errorGuard(),
    bindingGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightUserActionsModal.prototype, "render", null);
AtomicInsightUserActionsModal = _ts_decorate([
    customElement('atomic-insight-user-actions-modal'),
    bindings(),
    withTailwindStyles
], AtomicInsightUserActionsModal);
export { AtomicInsightUserActionsModal };
