<script setup lang="ts">
const props = defineProps<{
  x: number;
  y: number;
}>();

const { onRender } = useScreen();

const settingsStore = useSettingsStore();
const menusContext = inject<{
  isSubmenuSelected: ComputedRef<boolean>;
  selectedSubmenuParent: ComputedRef<string | null>;
}>("menusContext")!;

const { assets } = useAssets();

// TODO: i don't like this
const isAnyOtherMenuOpen = computed(() => {
  if (settingsStore.currentSubMenu) {
    return !settingsStore.currentSubMenu.startsWith("touchScreen");
  }
  if (menusContext.isSubmenuSelected.value) {
    return menusContext.selectedSubmenuParent.value !== "touchScreen";
  }
  return false;
});

onRender((ctx) => {
  if (isAnyOtherMenuOpen.value) {
    ctx.drawImage(
      assets.settings.topScreen.touchScreen.touchScreenDisabled,
      props.x,
      props.y,
    );
  } else {
    ctx.drawImage(
      assets.settings.topScreen.touchScreen.touchScreen,
      props.x,
      props.y,
    );
  }
});

defineOptions({
  render: () => null,
});
</script>
