<template>
	<div v-if="shouldDisplayModule" class="special-modules">
		<!-- SNW Install Module -->
		<InstallStatus
			v-if="currentCompany === 'Sprinklers Northwest'"
			:onsite-meeting-status="snwInstallData.onsiteMeetingStatus"
			:estimate-sent-status="snwInstallData.estimateSentStatus"
			:job-status="snwInstallData.jobStatus"
			:payment-status="snwInstallData.paymentStatus"
			:full-address="fullAddress"
			:bid-meeting="snwInstallData.onsiteMeeting"
			:estimate="snwInstallData.estimate"
			:job="snwInstallData.job"
			:payment="snwInstallData.payment"
		/>
	</div>
</template>

<script setup>
import { computed } from "vue";
import { useCompanyStore } from "../../stores/company";
import InstallStatus from "./InstallStatus.vue";

const props = defineProps({
	selectedAddress: {
		type: Object,
		default: null,
	},
	fullAddress: {
		type: String,
		default: "",
	},
});

const companyStore = useCompanyStore();

const currentCompany = computed(() => companyStore.currentCompany);

// Check if we should display any module
const shouldDisplayModule = computed(() => {
	return currentCompany.value === "Sprinklers Northwest";
});

// Computed data for SNW Install status
const snwInstallData = computed(() => {
	if (!props.selectedAddress) {
		return {
			onsiteMeetingStatus: "Not Started",
			estimateSentStatus: "Not Started",
			jobStatus: "Not Started",
			paymentStatus: "Not Started",
			onsiteMeeting: "",
			estimate: "",
			job: "",
			payment: "dummy-payment-string",
		};
	}

	const addr = props.selectedAddress;

	// Filter for SNW Install template
	const snwBidMeeting = addr.onsiteMeetings?.find(
		(m) => m.projectTemplate === "SNW Install" && m.status !== "Cancelled"
	);
	const snwEstimate = addr.quotations?.find(
		(q) => q.projectTemplate === "SNW Install" && q.status !== "Cancelled"
	);
	const snwJob = addr.projects?.find(
		(p) => p.projectTemplate === "SNW Install" && p.status !== "Cancelled"
	);

	return {
		onsiteMeetingStatus: addr.onsiteMeetingScheduled || "Not Started",
		estimateSentStatus: addr.estimateSentStatus || "Not Started",
		jobStatus: addr.jobStatus || "Not Started",
		paymentStatus: addr.paymentReceivedStatus || "Not Started",
		onsiteMeeting: snwBidMeeting?.onsiteMeeting || "",
		estimate: snwEstimate?.quotation || "",
		job: snwJob?.project || "",
		payment: "dummy-payment-string",
	};
});
</script>

<style scoped>
.special-modules {
	margin-bottom: 1rem;
}
</style>
