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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { LitElement, html, css, property, } from 'lit-element';
// This decorator defines the element.
export class Quote extends LitElement {
    constructor() {
        super(...arguments);
        // This decorator creates a property accessor that triggers rendering and
        // an observed attribute.
        this.mood = 'great';
    }
    // Render element DOM by returning a `lit-html` template.
    render() {
        return html `
      <div class="incut-plugin incut no-ad">
        <div class="line">
          <div class="author">
            <slot name="quote_author"></slot>
            <slot name="quote_role"></slot>
          </div>
          <div class="quote_image">
            <slot></slot>
          </div>
        </div>


        <div class="quote_author_role">
        </div>
        <div class="quote_text">
          <slot name="quote_body"></slot>
        </div>
      </div>
    `;
    }
}
Quote.styles = css `
    :host {
    }
    .line {
      display: flex;
      align-items: center;
      margin: 0.3rem 0.3rem 0.5rem ;
    }
    .quote_image {
      width: 2.6rem;
      height: 2.6rem;
    }
    .author {
      flex: 1;
      margin-right: 1rem;
    }
  `;
__decorate([
    property(),
    __metadata("design:type", Object)
], Quote.prototype, "mood", void 0);
const defaultOptions = {
    name: 'quote',
    // icon: '<b>Q</b>',
    title: 'Цитата',
    tag: 'ARENA-QUOTE',
    attributes: ['class=textarena-quote'],
    shortcut: 'Alt + KeyQ',
    hint: 'q',
    command: 'add-quote',
    component: 'arena-quote',
};
const quotePlugin = (opts) => ({
    register(textarena) {
        const { name, icon, title, tag, attributes, shortcut, hint, command, component, } = Object.assign(Object.assign({}, defaultOptions), (opts || {}));
        if (!customElements.get(component)) {
            customElements.define(component, Quote);
        }
        const paragraph = textarena.getDefaultTextArena();
        const image = textarena.getArena('image');
        if (!paragraph) {
            throw new Error('Default Arena for text not found');
        }
        // const allowedArenas = textarena.getSimpleArenas();
        const bodyContainer = textarena.registerArena({
            name: 'quote-body-container',
            tag: 'QUOTE',
            attributes: ['slot=quote_body', 'class=body'],
            hasText: true,
            nextArena: paragraph,
            getPlain: (text) => `«${text}»`,
        }, [
            {
                tag: 'QUOTE',
                attributes: ['slot=quote_body'],
            },
        ], []);
        const roleContainer = textarena.registerArena({
            name: 'quote-role-container',
            tag: 'CITE',
            attributes: ['slot=quote_role', 'class=textarena-quote__role'],
            hasText: true,
            nextArena: bodyContainer,
        }, [
            {
                tag: 'CITE',
                attributes: ['slot=quote_role'],
            },
        ], []);
        const titleParagraph = textarena.registerArena({
            name: 'quote-author-container',
            tag: 'CITE',
            attributes: ['slot=quote_author', 'class=textarena-quote__author'],
            hasText: true,
            nextArena: roleContainer,
        }, [
            {
                tag: 'CITE',
                attributes: ['slot=quote_author'],
            },
        ], []);
        const arena = textarena.registerArena({
            name,
            tag,
            attributes,
            protectedChildren: [
                [image, { width: 100, height: 100 }],
                [titleParagraph, {}, 'Автор цитаты'],
                [roleContainer, {}, 'Роль'],
                [bodyContainer, {}, 'Цитата…'],
            ],
            arenaForText: bodyContainer,
        }, [
            {
                tag,
                attributes: [],
            },
        ], [textarena.getRootArenaName()]);
        textarena.registerCommand(command, (ta, selection) => {
            const sel = ta.insertBeforeSelected(selection, arena);
            return sel;
        });
        // textarena.registerShortcut(shortcut, command);
        textarena.registerCreator({
            name,
            icon,
            title,
            shortcut,
            hint,
            command,
            canShow: (node) => node.parent.isAllowedNode(arena),
        });
    },
});
export default quotePlugin;
//# sourceMappingURL=quotePlugin.js.map