<template>
  <Modal :is-modal-open="zoneEditorStore.isSettingsModalShown" @modal:close="() => zoneEditorStore.toggleSettingsModal()" :modal-width="600" :modal-height="350">
    <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/zoneEditorStore'

const zoneEditorStore = useZoneEditorStore()

zoneEditorStore.setZoneName(zoneEditorStore.zone.name)
zoneEditorStore.setZoneWidth(zoneEditorStore.zone.width)
zoneEditorStore.setZoneHeight(zoneEditorStore.zone.height)
zoneEditorStore.setZonePvp(zoneEditorStore.zone.pvp)

const name = ref(zoneEditorStore.zoneSettings.name)
const width = ref(zoneEditorStore.zoneSettings.width)
const height = ref(zoneEditorStore.zoneSettings.height)
const pvp = ref(zoneEditorStore.zoneSettings.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>
