<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) {
    assets.images.settings.topScreen.touchScreen.touchScreenDisabled.draw(
      ctx,
      props.x,
      props.y,
    );
  } else {
    assets.images.settings.topScreen.touchScreen.touchScreen.draw(
      ctx,
      props.x,
      props.y,
    );
  }
});

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