<template>
	<div class="overview-content">
		<!-- New Client Forms -->
		<div v-if="isNew" class="new-client-forms">
			<ClientInformationForm
				:form-data="client"
				:is-submitting="false"
				:is-edit-mode="false"
				@update:formData="handleFormDataUpdate"
				@newClientToggle="handleNewClientToggle"
				@customerSelected="handleCustomerSelected"
			/>
			<ContactInformationForm
				:form-data="client"
				:is-submitting="false"
				:is-edit-mode="false"
				@update:formData="handleFormDataUpdate"
			/>
			<AddressInformationForm
				:form-data="client"
				:is-submitting="false"
				:is-edit-mode="false"
				@update:formData="handleFormDataUpdate"
			/>
		</div>

		<!-- Quick Actions (only in non-edit mode) -->
		<QuickActions
			v-if="!editMode && !isNew"
			:full-address="fullAddress"
			@edit-mode-enabled="handleEditModeEnabled"
		/>

		<!-- Special Modules Section -->
		<SpecialModules
			v-if="!isNew && !editMode"
			:selected-address="selectedAddress"
			:full-address="fullAddress"
		/>

		<!-- Property Details -->
		<PropertyDetails
			v-if="!isNew && selectedAddress"
			:address-data="selectedAddress"
			:all-contacts="allContacts"
			:edit-mode="editMode"
			@update:address-contacts="handleAddressContactsUpdate"
			@update:primary-contact="handlePrimaryContactUpdate"
		/>
	</div>
</template>

<script setup>
import QuickActions from "./QuickActions.vue";
import SpecialModules from "./SpecialModules.vue";
import PropertyDetails from "./PropertyDetails.vue";
import ClientInformationForm from "../clientSubPages/ClientInformationForm.vue";
import ContactInformationForm from "../clientSubPages/ContactInformationForm.vue";
import AddressInformationForm from "../clientSubPages/AddressInformationForm.vue";

const props = defineProps({
	selectedAddress: {
		type: Object,
		default: null,
	},
	allContacts: {
		type: Array,
		default: () => [],
	},
	editMode: {
		type: Boolean,
		default: false,
	},
	isNew: {
		type: Boolean,
		default: false,
	},
	fullAddress: {
		type: String,
		default: "",
	},
	client: {
		type: Object,
		default: () => ({}),
	},
});

const emit = defineEmits([
	"edit-mode-enabled",
	"update:address-contacts",
	"update:primary-contact",
	"update:client",
]);

const handleEditModeEnabled = () => {
	emit("edit-mode-enabled");
};

const handleAddressContactsUpdate = (contactNames) => {
	emit("update:address-contacts", contactNames);
};

const handlePrimaryContactUpdate = (contactName) => {
	emit("update:primary-contact", contactName);
};

const handleFormDataUpdate = (newFormData) => {
	emit("update:client", newFormData);
};

const handleNewClientToggle = (isNewClient) => {
	// Handle if needed
};

const handleCustomerSelected = (customer) => {
	// Handle if needed
};
</script>

<style scoped>
.overview-content {
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

.new-client-forms {
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}
</style>