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 '@kano/styles/typography.js';
import { customElement, html, property, css } from 'lit-element/lit-element.js';
import { classMap } from 'lit-html/directives/class-map';
import { EventEmitter, subscribeDOM } from '@kano/common/index.js';
import { KCBriefingFloatingMenu, BriefingFloatingMenu } from '../../briefing/widget/floating-menu.js';
let KCRemixFloatingMenu = class KCRemixFloatingMenu extends KCBriefingFloatingMenu {
    constructor() {
        super(...arguments);
        this.suggestions = [];
        this.selectedSuggestionIndex = -1;
    }
    static get styles() {
        return [css `
            .content>button {
                background: transparent;
                border: none;
                cursor: pointer;
                font-size: 18px;
                font-family: inherit;
                font-weight: bold;
                text-align: left;
                color: inherit;
                border: 1px solid var(--color-grey);
                border-radius: 6px;
                padding: 8px;
                margin-bottom: 4px;
            }
            .content>button:focus,
            .content>button:hover,
            .content>button.selected {
                background: var(--color-stone);
                outline: none;
            }
        `].concat(KCBriefingFloatingMenu.styles);
    }
    renderActions() {
        return html `
            <button class="btn secondary" @click=${() => this._onResetClick()}>Reset</button>
            <button class="btn secondary" @click=${() => this._onDoneClick()}>I'm done</button>
            <button class="btn secondary" @click=${() => this._onExamplesClick()}>Examples</button>
        `;
    }
    _onExamplesClick() {
        this.dispatchEvent(new CustomEvent('examples-clicked'));
    }
    renderContent() {
        return this.suggestions.map((s, index) => html `
            <button @click=${() => this._onClick(index)} class=${classMap({ selected: this.selectedSuggestionIndex === index })}>${s}</button>
        `);
    }
    _onClick(index) {
        this.dispatchEvent(new CustomEvent('suggestion-clicked', { detail: index }));
    }
};
__decorate([
    property({ type: Array })
], KCRemixFloatingMenu.prototype, "suggestions", void 0);
__decorate([
    property({ type: Number })
], KCRemixFloatingMenu.prototype, "selectedSuggestionIndex", void 0);
KCRemixFloatingMenu = __decorate([
    customElement('kc-remix-floating-menu')
], KCRemixFloatingMenu);
export { KCRemixFloatingMenu };
export class RemixFloatingMenu extends BriefingFloatingMenu {
    constructor(title, suggestions) {
        super(title);
        this._onDidSelectSuggestion = new EventEmitter();
        this._onDidRequestExamples = new EventEmitter();
        this.title = 'Remix list';
        this.suggestions = suggestions;
    }
    get onDidSelectSuggestion() { return this._onDidSelectSuggestion.event; }
    get onDidRequestExamples() { return this._onDidRequestExamples.event; }
    getMenuNode() {
        if (!this.menuNode) {
            this.menuNode = new KCRemixFloatingMenu();
            this.menuNode.title = this.title;
            this.menuNode.header = this.header;
            this.menuNode.suggestions = this.suggestions.map(s => s.title);
            subscribeDOM(this.menuNode, 'suggestion-clicked', (e) => {
                if (this.menuNode) {
                    this.menuNode.selectedSuggestionIndex = e.detail;
                }
                const suggestion = this.suggestions[e.detail];
                this._onDidSelectSuggestion.fire(suggestion);
            }, this, this.subscriptions);
            subscribeDOM(this.menuNode, 'reset-clicked', () => this._onDidRequestReset.fire(), this, this.subscriptions);
            subscribeDOM(this.menuNode, 'examples-clicked', () => this._onDidRequestExamples.fire(), this, this.subscriptions);
            subscribeDOM(this.menuNode, 'done-clicked', () => this._onDidEnd.fire(), this, this.subscriptions);
        }
        return this.menuNode;
    }
    deselectSuggestion() {
        if (this.menuNode) {
            this.menuNode.selectedSuggestionIndex = -1;
        }
    }
}
//# sourceMappingURL=floating-menu.js.map