<script setup lang="ts">
    import { DocumentsType, IApiResponse, ModuleDocuments } from '@/modules/documents';
    import UIModalContainer from '@/UI-kit/components/UI/modal/UIModalContainer.vue';
    import { ref } from 'vue';
    import ModuleDocumentsList from '@/modules/documents/ModuleDocumentsList.vue';
    import { ELanguageLocale, valueof } from '@/UI-kit/types';
    import { useUiKitConfigStore } from '@/configs/store';
    import UISteps from '@/UI-kit/components/UI/steps/UISteps.vue';
    import UIBlockCheckCode from '@/UI-blocks/components/UIBlockCheckCode.vue';
    import UIEmpty from '@/UI-kit/components/UI/empty/UIEmpty.vue';

    const initialValue = ref({});
    const currentDoc = ref();
    const currentDocType = ref();

    const whiteDocTypeList = [
        DocumentsType.NONRESIDENT_PASSPORT,
        DocumentsType.INN,
        DocumentsType.PATENT,
        DocumentsType.LICENCE_PLATE,
    ];

    const configStore = useUiKitConfigStore();

    configStore.appVersion = '2.0.7';

    configStore.setGlobalModulesProperty(
        ELanguageLocale.RU,
        '4505|sK72iyjL0ZgSAiPfrmiFrjR2G1jXvelDHbyKPcZyfa16d52d',
    );

    const submit = (value: any) => {
        initialValue.value = value;
        currentDocType.value = null;
    };

    const back = () => {
        currentDocType.value = null;
    };

    const setDoc = ({ type, doc }: { type: valueof<typeof DocumentsType>; doc: IApiResponse }) => {
        currentDocType.value = null;
        initialValue.value = doc.value;
        currentDoc.value = doc;
        currentDocType.value = type;
    };

    const getCameraPhoto = () => {
        console.log('идем в апе в сервис получения фото/камеру');
    };

    const checkCode = ref();
</script>

<template>
    <div style="min-height: calc(100vh - 100px)">
        <UIEmpty text="dfdfd" title="title" />
        <UIBlockCheckCode ref="checkCode" />
        <button @click="checkCode.send">click</button>
        <br />
        <button @click="checkCode.resetForm">click</button>
        <ModuleDocumentsList
            v-if="!currentDocType"
            :current-lang="ELanguageLocale.RU"
            :white-doc-type-list="whiteDocTypeList"
            @update:document="submit"
            @click="setDoc"
        />
        <ModuleDocuments
            v-else
            :current-lang="ELanguageLocale.RU"
            :document-type="currentDocType"
            :doc="currentDoc"
            is-show-example-image
            :is-show-delete-doc-btn="!!currentDoc?.id"
            is-show-not-save-doc-btn
            is-show-save-image-block
            :initial-value="initialValue"
            @update:document="submit"
            @back="back"
            @get:camera-photo="getCameraPhoto"
        />
        <UISteps :count="7" :active-step="4" @click="(index) => console.log(index)" />
    </div>
    <UIModalContainer />
</template>
