
import { CreateVoteDto, MemberItem, ListItem } from '@/types/Dto'

const _form = () => {
  return {
    name: '',
    description: '',
    url: '',
    type: 1,
    startHeight: undefined,
    endHeight: undefined,
    options: [] as ListItem[],
    members: [] as MemberItem[],
    isOpen: true,
    numType: 2
  }
}

const stateData = {
    overlay:{
        show:false,
        data:{
            title:'默认'
        }
    },
    address: '',   // 用户地址
    form: _form() as CreateVoteDto       // 发起表单
}
interface overlayData {
    title:string
}
interface memberItem {
    name: string;
    addr: string
}
export type AppType = typeof stateData
export const appStore = {
    namespaced: true,
        state: () => ({
            ...stateData
        }),
    getter: {
      getAddress(state: {address: string}) {
        return state.address
      }
    },
    mutations: {
        TOGGLE_STATUS(state:AppType){
            state.overlay.show = !state.overlay.show
        },
        SET_OVERLAY(state:AppType,payload:overlayData){
            Object.assign(state.overlay.data,payload)
        },
        SET_ADDRESS(state: AppType, s: string) {
            state.address = s
        },
        CLEAR_ADDRESS(state: AppType) {
            state.address = ''
        },
        SET_FORM(state: AppType, form: CreateVoteDto) {
            state.form = form
        },
        CLEAR_FORM(state: AppType) {
            state.form = _form()
        },
    },
    actions: {

    },
  };
  
