import { html, TemplateResult } from 'lit';
import { UiDemoPage } from '../ui/UiDemoPage.js';
import { ContextualMenu } from '../../../src/contextual-menu/ContextualMenu.js';
import { IContextMenuCommand, IExecuteOptions } from '../../../src/contextual-menu/types.js';
import { copy, paste, flag } from './DemoIcons.js';

class ComponentPage extends UiDemoPage {
  componentName = 'Icons example';

  firstRender(): void {
    super.firstRender();
    this.initContextMenu();
  }

  initContextMenu(): void {
    const container = document.body.querySelector('#workspace') as HTMLElement;
    const instance = new ContextualMenu(container);
    const commands: IContextMenuCommand[] = ([
      {
        target: 'root',
        label: 'Paste',
        title: 'Paste the value',
        icon: paste,
        execute: (args: IExecuteOptions): void => {
          console.log(args);
        },
      },
      {
        target: 'root',
        label: 'Copy',
        title: 'Copies the object',
        icon: copy,
        execute: (args: IExecuteOptions): void => {
          console.log(args);
        }
      },
      {
        target: 'root',
        label: 'Flag',
        icon: flag,
        execute: (args: IExecuteOptions): void => {
          console.log(args);
        }
      },
    ]);
    instance.registerCommands(commands);
    instance.connect();
  }

  contentTemplate(): TemplateResult {
    return html`
      <a href="./">Back</a>
      <section class="demo-section">
        <h2 class="title-large">Contextual menu</h2>
        <div id="workspace">
          <div class="target" data-id="test-value"></div>
        </div>
      </section>
    `;
  }
}

const instance = new ComponentPage();
instance.render();
