<template>
  <Modal :is-modal-open="true" @modal:close="() => zoneEditorStore.toggleSettingsModal()" :modal-width="300" :modal-height="350" :is-resizable="false">
    <template #modalHeader>
      <h3 class="m-0 font-medium shrink-0">Zone settings</h3>
    </template>

    <template #modalBody>
      <div class="m-4">
        <form method="post" @submit.prevent="" class="inline">
          <div class="gap-2.5 flex flex-wrap">
            <div class="form-field-full">
              <label for="name">Name</label>
              <input class="input-cyan" v-model="name" name="name" id="name" />
            </div>
            <div class="form-field-half">
              <label for="name">Width</label>
              <input class="input-cyan" v-model="width" name="name" id="name" type="number" />
            </div>
            <div class="form-field-half">
              <label for="name">Height</label>
              <input class="input-cyan" v-model="height" name="name" id="name" type="number" />
            </div>
            <div class="form-field-full">
              <label for="pvp">PVP enabled</label>
              <select v-model="pvp" class="input-cyan" name="pvp" id="pvp">
                <option :value="false">No</option>
                <option :value="true">Yes</option>
              </select>
            </div>
          </div>
        </form>
      </div>
    </template>
  </Modal>
</template>

<script setup>
import { ref, watch } from 'vue'
import Modal from '@/components/utilities/Modal.vue'
import { useZoneEditorStore } from '@/stores/zoneEditor'

const zoneEditorStore = useZoneEditorStore()

const name = ref(zoneEditorStore.zone?.name)
const width = ref(zoneEditorStore.zone?.width)
const height = ref(zoneEditorStore.zone?.height)
const pvp = ref(zoneEditorStore.zone?.pvp)

watch(name, (value) => {
  zoneEditorStore.setZoneName(value)
})

watch(width, (value) => {
  zoneEditorStore.setZoneWidth(value)
})

watch(height, (value) => {
  zoneEditorStore.setZoneHeight(value)
})

watch(pvp, (value) => {
  zoneEditorStore.setZonePvp(value)
})
</script>
