import "../atomic-insight-user-actions-modal/atomic-insight-user-actions-modal.js";
import { Schema, StringValue } from "@coveo/bueno";
import { buildUserActions } from "@coveo/headless/insight";
import { LitElement, html } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { renderIconButton } from "../../common/icon-button.js";
import { ValidatePropsController } from "../../common/validate-props-controller/validate-props-controller.js";
import { bindStateToController } from "../../../decorators/bind-state.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 clock from "../../../images/clock.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 AtomicInsightUserActionsToggle extends LitElement {
    initialize() {
        this.userActions = buildUserActions(this.bindings.engine, {
            options: {
                ticketCreationDate: this.ticketCreationDateTime,
                excludedCustomActions: this.excludedCustomActions
            }
        });
    }
    enableModal() {
        if (this.modalRef) this.modalRef.isOpen = true;
        this.userActions.logOpenUserActions();
    }
    loadModal() {
        if (this.modalRef) return;
        this.modalRef = document.createElement('atomic-insight-user-actions-modal');
        this.insertAdjacentElement('beforebegin', this.modalRef);
        this.modalRef.openButton = this.buttonRef;
        this.modalRef.userId = this.userId;
        this.modalRef.ticketCreationDateTime = this.ticketCreationDateTime;
        this.modalRef.excludedCustomActions = this.excludedCustomActions;
    }
    render() {
        return html`${renderIconButton({
            props: {
                partPrefix: 'insight-user-actions-toggle',
                style: 'outline-neutral',
                icon: clock,
                ariaLabel: this.bindings.i18n.t('user-actions'),
                onClick: ()=>this.enableModal(),
                title: this.bindings.i18n.t('user-actions'),
                buttonRef: (button)=>{
                    if (!button) return;
                    this.buttonRef = button;
                    this.loadModal();
                }
            }
        })}`;
    }
    constructor(){
        super(), this.excludedCustomActions = [];
        new ValidatePropsController(this, ()=>({
                userId: this.userId,
                ticketCreationDateTime: this.ticketCreationDateTime
            }), new Schema({
            userId: new StringValue({
                required: true,
                emptyAllowed: false
            }),
            ticketCreationDateTime: new StringValue({
                required: true,
                emptyAllowed: false
            })
        }), false);
    }
}
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightUserActionsToggle.prototype, "bindings", void 0);
_ts_decorate([
    state(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightUserActionsToggle.prototype, "error", void 0);
_ts_decorate([
    bindStateToController('userActions'),
    state(),
    _ts_metadata("design:type", "u" < typeof InsightUserActionsState ? Object : InsightUserActionsState)
], AtomicInsightUserActionsToggle.prototype, "userActionsState", void 0);
_ts_decorate([
    property({
        type: String,
        attribute: 'user-id'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsToggle.prototype, "userId", void 0);
_ts_decorate([
    property({
        type: String,
        attribute: 'ticket-creation-date-time'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightUserActionsToggle.prototype, "ticketCreationDateTime", void 0);
_ts_decorate([
    property({
        type: Array,
        attribute: 'excluded-custom-actions'
    }),
    _ts_metadata("design:type", Array)
], AtomicInsightUserActionsToggle.prototype, "excludedCustomActions", void 0);
_ts_decorate([
    errorGuard(),
    bindingGuard(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicInsightUserActionsToggle.prototype, "render", null);
AtomicInsightUserActionsToggle = _ts_decorate([
    customElement('atomic-insight-user-actions-toggle'),
    bindings(),
    withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightUserActionsToggle);
export { AtomicInsightUserActionsToggle };
