import { html, TemplateResult } from 'lit'
import { DemoPage } from '../../../src/demo/DemoPage.js'
import { ContextualMenu } from '../../../src/elements/contextual-menu/internals/ContextualMenu.js'
import { ContextMenuCommand, CommandExecuteOptions } from '../../../src/elements/contextual-menu/internals/types.js'
import { copy, paste, flag } from './DemoIcons.js'

class ComponentPage extends DemoPage {
  override accessor componentName = 'Icons example'

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

  initContextMenu(): void {
    const container = document.body.querySelector('#workspace') as HTMLElement
    const instance = new ContextualMenu(container)
    const commands: ContextMenuCommand[] = [
      {
        target: 'root',
        label: 'Paste',
        title: 'Paste the value',
        icon: paste,
        execute: (args: CommandExecuteOptions): void => {
          console.log(args)
        },
      },
      {
        target: 'root',
        label: 'Copy',
        title: 'Copies the object',
        icon: copy,
        execute: (args: CommandExecuteOptions): void => {
          console.log(args)
        },
      },
      {
        target: 'root',
        label: 'Flag',
        icon: flag,
        execute: (args: CommandExecuteOptions): 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()
