<script setup lang="ts">
import { computed } from "vue";
import { useEntities } from "@/services/onboarding";

const props = defineProps<{
  modelValue: {
    company_name: string;
    company_street: string;
    company_street_number: string;
    company_postal_code: string;
    company_city: string;
    company_country: string;
  };
}>();

const emit = defineEmits(["update:modelValue"]);

const { countries } = useEntities();

const orgAddress = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit("update:modelValue", value);
  },
});
</script>

<template>
  <div class="my-10 grid grid-cols-1 gap-x-6 gap-y-6 sm:grid-cols-6">
    <div class="col-span-full">
      <label
        for="company-name"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.Name") }}
      </label>
      <div class="mt-2">
        <input
          id="company-name"
          v-model="orgAddress.company_name"
          type="text"
          required
          name="company-name"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        />
      </div>
    </div>
    <div class="sm:col-span-4">
      <label
        for="company-street-address"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.Strasse") }}
      </label>
      <div class="mt-2">
        <input
          id="company-street-address"
          v-model="orgAddress.company_street"
          type="text"
          required
          name="street-address"
          autocomplete="street-address"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        />
      </div>
    </div>

    <div class="sm:col-span-2">
      <label
        for="company-street-number"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.Hausnummmer") }}
      </label>
      <div class="mt-2">
        <input
          id="company-street-number"
          v-model="orgAddress.company_street_number"
          name="street-number"
          type="text"
          autocomplete="street-number"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        />
      </div>
    </div>
    <div class="sm:col-span-1">
      <label
        for="company-postal-code"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.PLZ") }}
      </label>
      <div class="mt-2">
        <input
          id="company-postal-code"
          v-model="orgAddress.company_postal_code"
          type="text"
          required
          name="postal-code"
          autocomplete="postal-code"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        />
      </div>
    </div>

    <div class="sm:col-span-5">
      <label
        for="company-city"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.Ort") }}
      </label>
      <div class="mt-2">
        <input
          id="company-city"
          v-model="orgAddress.company_city"
          type="text"
          name="city"
          required
          autocomplete="address-level2"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        />
      </div>
    </div>

    <div class="col-span-full">
      <label
        for="company-country"
        class="block text-sm font-medium leading-6 text-gray-900"
      >
        {{ $t("a.Land") }}
      </label>
      <div class="mt-2">
        <select
          id="company-country"
          v-model="orgAddress.company_country"
          required
          name="country"
          autocomplete="country-name"
          class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
        >
          <option v-for="country in countries" :key="country.id" :value="country.id">
            {{ country.name }}
          </option>
        </select>
      </div>
    </div>
  </div>
</template>
