<template>
  <current-household />

  <ul class="record_actions">
    <!-- <li v-if="!hasHouseholdAddress && !isHouseholdForceAddress">
      <button class="btn btn-misc" @click="markNoAddress">
        {{ $t('household_members_editor.household_address.mark_no_address') }}
      </button>
    </li> -->
    <li v-if="!hasHouseholdAddress">
      <add-address
        :context="getAddressContext"
        :key="addAddress.key"
        :options="addAddress.options"
        :address-changed-callback="addressChanged"
      />
    </li>
    <li v-if="hasHouseholdAddress">
      <button class="btn btn-remove" @click="removeHouseholdAddress">
        {{ $t("household_members_editor.household_address.remove_address") }}
      </button>
    </li>
  </ul>
</template>

<script>
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
import CurrentHousehold from "./CurrentHousehold";
import { mapGetters } from "vuex";

export default {
  name: "HouseholdAddress.vue",
  components: {
    CurrentHousehold,
    AddAddress,
  },
  data() {
    return {
      addAddress: {
        key: "household_new",
        options: {
          useDate: {
            validFrom: false,
            validTo: false,
          },
          onlyButton: true,
          button: {
            text: {
              create: "household_members_editor.household_address.set_address",
              edit: "household_members_editor.household_address.update_address",
            },
          },
          title: {
            create:
              "household_members_editor.household_address.create_new_address",
            edit: "household_members_editor.household_address.update_address_title",
          },
        },
      },
    };
  },
  computed: {
    ...mapGetters([
      "isHouseholdNew",
      "hasHouseholdAddress",
      "getAddressContext",
      "isHouseholdForceNoAddress",
    ]),
  },
  methods: {
    addressChanged(payload) {
      console.log("addressChanged", payload);
      this.$store.dispatch("setHouseholdNewAddress", payload.address);
    },
    markNoAddress() {
      this.$store.commit("markHouseholdNoAddress");
    },
    removeHouseholdAddress() {
      this.$store.commit("removeHouseholdAddress");
    },
  },
};
</script>

<style scoped></style>
