<script setup>
import {NSpace, NDropdown, NButton, NIcon} from 'naive-ui'
import {TbExternalLink, TbEyePlus, TbClick} from "vue-icons-plus/tb"
import {computed, h} from "vue";
const props = defineProps({
    row: Object,
    isMis: Boolean,
    isAddObservable: Boolean
})

const renderIcon = (icon) => {
    return () => h(
        NIcon,
        {},
        {
            default: () => h(icon)
        }
    )
}

const actions = computed(() => ([
    {
        label: 'Просмотреть в МИС',
        key: 'mis',
        icon: renderIcon(TbExternalLink),
        show: props.isMis
    },
    {
        type: 'divider',
        key: 'd1',
        show: props.isMis && props.isAddObservable
    },
    {
        label: 'Добавить в наблюдение',
        key: 'add-observable',
        icon: renderIcon(TbEyePlus),
        show: props.isAddObservable
    },
]))

const onOpenMis = () => {
    const id = props.row.id
    window.open(`https://stationar.amurzdrav.ru/prod/statist/edit/card/${id}`, '_blank')
}

const onSelectOption = (key, option) => {
    switch (key) {
        case 'mis': onOpenMis()
            break
    }
}
</script>

<template>
    <NSpace size="small" justify="end">
        <NDropdown size="small" trigger="click" placement="bottom-end" :options="actions" @select="onSelectOption">
            <NButton secondary size="tiny">
                <template #icon>
                    <TbClick />
                </template>
                Действия
            </NButton>
        </NDropdown>
    </NSpace>
</template>

<style scoped>

</style>
