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 { formatSize, copy, paste, title } from './DemoIcons.js';

class ComponentPage extends UiDemoPage {
  componentName = 'Nested menus';

  constructor() {
    super();
    this.componentName = 'Nested menus';
  }

  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: 'Font size',
        icon: formatSize,
        execute: (args: IExecuteOptions): void => {
          console.log('Selected font size:', args.item.id);
        },
        children: [
          {
            label: '0.75 rem',
            id: '0.75rem',
          },
          {
            label: '1 rem',
            id: '1rem',
          },
          {
            label: '1.25 rem',
            id: '1.25rem',
          },
          {
            label: '1.5 rem',
            id: '1.5rem',
          },
          {
            label: '2 rem',
            id: '2rem',
          },
        ],
      },
      {
        target: 'root',
        label: 'Font family',
        icon: title,
        execute: (args: IExecuteOptions): void => {
          console.log('Selected font family:', args.item.id);
        },
        children: [
          {
            label: 'Arial',
            id: 'Arial',
          },
          {
            label: 'Calibri',
            id: 'Calibri',
          },
          {
            label: 'Consolas',
            id: 'Consolas',
          },
          {
            label: 'Courier New',
            id: 'Courier New',
          },
          {
            label: 'Open Sans',
            id: 'Open Sans',
          },
          {
            label: 'Roboto',
            id: 'Roboto',
          },
          {
            label: 'Times New Roman',
            id: 'Times New Roman',
          },
        ],
      },
      {
        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: 'Add',
        children: [
          {
            label: 'Event',
            children: [
              {
                label: 'Publish event',
                id: 'event-publish'
              },
              {
                label: 'Subscribe event',
                id: 'event-subscribe'
              }
            ],
          }
        ],
        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">Nested menu</h2>
        <div id="workspace">
          <div class="target" data-id="test-value"></div>
        </div>
        </section>
      </section>
    `;
  }
}

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