<template>
  <Modal :isModalOpen="true" @modal:close="() => zoneEditorStore.toggleCreateZoneModal()" :modal-width="300" :modal-height="400" :is-resizable="false">
    <template #modalHeader>
      <h3 class="m-0 font-medium shrink-0">Create new zone</h3>
    </template>

    <template #modalBody>
      <div class="m-[15px]">
        <form method="post" @submit.prevent="submit" class="inline">
          <div class="gap-2.5 flex flex-wrap">
            <div class="w-full flex flex-col mb-5">
              <label class="mb-1.5 font-titles" for="name">Name</label>
              <input class="input-cyan max-w-[250px]" v-model="name" name="name" id="name" />
            </div>
            <div class="w-[48%] flex flex-col mb-5">
              <label class="mb-1.5 font-titles" for="name">Width</label>
              <input class="input-cyan max-w-[250px]" v-model="width" name="name" id="name" type="number" />
            </div>
            <div class="w-[48%] flex flex-col mb-5">
              <label class="mb-1.5 font-titles" for="name">Height</label>
              <input class="input-cyan max-w-[250px]" v-model="height" name="name" id="name" type="number" />
            </div>
            <div class="w-full flex flex-col mb-5">
              <label class="mb-1.5 font-titles" for="name">PVP enabled</label>
              <input class="input-cyan max-w-[250px]" name="name" id="name" />
            </div>
          </div>
          <button class="btn-cyan px-[15px] py-1.5 min-w-[100px]" type="submit">Save</button>
        </form>
      </div>
    </template>
  </Modal>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import Modal from '@/components/utilities/Modal.vue'
import { useGameStore } from '@/stores/game'
import { useZoneEditorStore } from '@/stores/zoneEditor'
import type { Zone } from '@/types'

const gameStore = useGameStore()
const zoneEditorStore = useZoneEditorStore()

const name = ref('')
const width = ref(0)
const height = ref(0)

function submit() {
  gameStore.connection.emit('gm:zone_editor:zone:create', { name: name.value, width: width.value, height: height.value }, (response: Zone[]) => {
    zoneEditorStore.setZoneList(response)
  })
  zoneEditorStore.toggleCreateZoneModal()
}
</script>
