import type { PropType} from 'vue';
import { defineComponent, ref } from 'vue'

import { Logo } from '../../components/logo/index'

import { LandingFooter } from '../../components/LandingFooter/index'

import { tools } from '../../store/Modules/tools'
import { static_data } from '@src/db/static_data'

import { CCard } from '@src/components/CCard/index'
import { CImgText } from '@src/components/CImgText/index'
import { CMyAvatar } from '@src/components/CMyAvatar/index'
import { CMyTeacher } from '@src/components/CMyTeacher/index'
import { CMyPage } from '@src/components/CMyPage/index'

import type { IEvents} from '@src/model';
import { IOperators } from '@src/model'
import MixinEvents from '@src/mixins/mixin-events'
import { useGlobalStore } from '@src/store/globalStore'

export default defineComponent({
  name: 'CMySingleEvent',
  components: { Logo, LandingFooter, CImgText, CCard, CMyPage, CMyAvatar, CMyTeacher },
  props: {
    myevent: {
      type: Object as PropType<IEvents>,
      required: true,
    },
  },

  setup(props, { emit }) {

    const selected = ref(false)
    const globalStore = useGlobalStore()

    const site = ref(globalStore.site)

    const { isShowPrice, getImgEvent, getStyleByEvent, isAlreadyBooked, getWhereIcon, getWhereName,
      editable, getContribtypeById, getPrice, isEventEnabled, findEventIndex, UpdateDbByFields,
    } = MixinEvents()

    function selectEvent(eventparam: IEvents) {
      selected.value = !selected.value
    }

    function getTextEvent(myevent: IEvents) {
      if (myevent.bodytext === '') {
        return myevent.details
      } else {
        return myevent.bodytext
      }
    }

    function duplicateEvent(event: any, numgg: number) {
      emit('duplicateEvent', event, numgg)
    }

    function askForInfoEventMenu(event: any) {
      emit('askForInfoEventMenu', event)
    }

    function deleteEvent(event: any) {
      emit('deleteEvent', event)
    }

    function editEvent(event: any) {
      emit('editEvent', event)
    }

    function addBookEventMenu(event: any) {
      emit('addBookEventMenu', event)
    }

    function EditBookEvent(event: any) {
      emit('EditBookEvent', event)
    }

    return {
      EditBookEvent,
      addBookEventMenu,
      editEvent,
      deleteEvent,
      askForInfoEventMenu,
      duplicateEvent,
      getTextEvent,
      tools,
      static_data,
      selectEvent,
      getImgEvent,
      getStyleByEvent,
      isAlreadyBooked,
      getWhereIcon,
      getWhereName,
      editable,
      getContribtypeById,
      getPrice,
      isShowPrice,
      isEventEnabled,
      findEventIndex,
      UpdateDbByFields,
      selected,
      site,
    }

  }
})
