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, LitElement } from 'lit-element/lit-element.js';
import { classMap } from 'lit-html/directives/class-map';
import { EventEmitter, subscribeDOM } from '@kano/common/index.js';
import { BriefingFloatingMenu } from '../../briefing/widget/floating-menu.js';
import { circle } from '@kano/icons/ui.js';
import { _ } from '../../../../i18n/index.js';
let KCRemixSuggestions = class KCRemixSuggestions extends LitElement {
    constructor() {
        super(...arguments);
        this.suggestions = [];
        this.selectedSuggestionIndex = -1;
    }
    static get styles() {
        return [css `
            button {
                background: transparent;
                border: none;
                cursor: pointer;
                font-size: 16px;
                font-family: inherit;
                font-weight: bold;
                text-align: left;
                color: inherit;
                border-bottom: 1px solid var(--color-porcelain);
                padding: 8px;
                width: 100%;
            }
            button:focus {
                outline: none;
            }
            button:hover, 
            button.selected {
                background: var(--button-action-background);
            }
            button:first-child {
                /* margin-top: 8px; */
                border-top: 1px solid var(--color-porcelain);
            }

            .suggestion-circle {
                width: 12px;
                fill: var(--color-stone);
                margin-right: 4px;
            }

            .selected .suggestion-circle {
                fill: var(--color-candlelight);
                stroke: var(--color-pumpkin);
            }
        `];
    }
    renderSuggestions() {
        return this.suggestions.map((s, index) => {
            const instance = circle.content.cloneNode(true);
            return html `
            <button @click=${() => this._onClick(index)} class=${classMap({ selected: this.selectedSuggestionIndex === index })}>
                <svg class="suggestion-circle" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
                    ${instance}
                </svg>
                ${s}
            </button>
            `;
        });
    }
    render() {
        return html `${this.renderSuggestions()}`;
    }
    _onClick(index) {
        this.dispatchEvent(new CustomEvent('suggestion-clicked', { detail: index }));
    }
};
__decorate([
    property({ type: Array })
], KCRemixSuggestions.prototype, "suggestions", void 0);
__decorate([
    property({ type: Number })
], KCRemixSuggestions.prototype, "selectedSuggestionIndex", void 0);
KCRemixSuggestions = __decorate([
    customElement('kc-remix-suggestions')
], KCRemixSuggestions);
export { KCRemixSuggestions };
export class RemixFloatingMenu extends BriefingFloatingMenu {
    constructor(title, suggestions, nextChallenge) {
        super(title, nextChallenge);
        this._onDidSelectSuggestion = new EventEmitter();
        this._onDidDeselectSuggestion = new EventEmitter();
        this._onDidRequestExamples = new EventEmitter();
        this.suggestions = suggestions;
        const examplesBtn = this.addMenuButton(_('EXAMPLES_BUTTON', 'Examples'));
        examplesBtn.onDidClick(() => {
            this._onDidRequestExamples.fire();
        });
    }
    get onDidSelectSuggestion() { return this._onDidSelectSuggestion.event; }
    get onDidDeselectSuggestion() { return this._onDidDeselectSuggestion.event; }
    get onDidRequestExamples() { return this._onDidRequestExamples.event; }
    addEntry() {
        const domNode = this.getBannerEl();
        const suggestionsElement = document.createElement('kc-remix-suggestions');
        suggestionsElement.slot = 'content';
        suggestionsElement.suggestions = this.suggestions.map(s => s.title);
        subscribeDOM(suggestionsElement, 'suggestion-clicked', (e) => {
            const suggestion = this.suggestions[e.detail];
            if (!suggestion) {
                return;
            }
            if (suggestionsElement.selectedSuggestionIndex === e.detail) {
                this.deselectSuggestion();
            }
            else {
                this._onDidSelectSuggestion.fire(suggestion);
                suggestionsElement.selectedSuggestionIndex = e.detail;
            }
        });
        this.menuNode = suggestionsElement;
        domNode.appendChild(suggestionsElement);
    }
    deselectSuggestion() {
        if (this.menuNode) {
            this.menuNode.selectedSuggestionIndex = -1;
        }
        this._onDidDeselectSuggestion.fire();
    }
}
//# sourceMappingURL=floating-menu.js.map