import type { ContextMenuArgs, ContextMenuBuildResponse } from './context-menu-binder';
import { Prop, toNative } from 'vue-facing-decorator';
import TsxComponent, { Component } from '../../app/vuetsx';
import ContextMenuBinder from './context-menu-binder';

@Component
class ContextMenuComponent extends TsxComponent<ContextMenuArgs> implements ContextMenuArgs {
	@Prop() selector: string;
	@Prop() build: (trigger: HTMLElement, e: MouseEvent) => ContextMenuBuildResponse;

	mounted() {
		ContextMenuBinder.bindMenu({
			selector: this.selector,
			build: this.build,
		});
	}

	beforeUnmount() {
		ContextMenuBinder.destroyMenu(this.selector);
	}

	render(_h) {
		return null;
	}
}

const ContextMenu = toNative(ContextMenuComponent);
export default ContextMenu;
