<script>
import {computed, getCurrentInstance} from 'vue';
import AnalysisResult from "@/pages/ie/entry-analysis/analysis-result.vue";
import {useProvidePageScroll} from "@/hooks/usePageScrollInjection";
import {useTransfer} from "@/hooks/useTransfer";
import {useProvideUserSnapshot} from "@/pages/ie/hooks/useUserSnapshotInjection";

export default {
    extends: AnalysisResult,
    setup() {
        const scrollTop = useProvidePageScroll()
        const {prevData, transferTo} = useTransfer()
        const instance = getCurrentInstance()
        const snapshot = computed(() => instance.proxy.voluntaryRef?.userSnapshot)
        useProvideUserSnapshot(snapshot)

        return {
            prevData,
            scrollTop,
            transferTo
        }
    },
    methods: {
        getAnalysisResult() {
            const {request, details} = this.prevData
            this.voluntaryRef = this.prevData // keep this ref for report
            this.prevData = request
            this.results = details

            // try to fix this.prevData.form.universities' `num` prop
            this.prevData.universities.forEach((u, i) => {
                if (!u.hasOwnProperty('num')) this.$set(u, 'num', i)
            })
        }
    }
}
</script>

<style>

</style>
