import { defineStore } from 'pinia'
import { computed, reactive, ref, toRefs } from 'vue'

export const useCommonStore = defineStore('commonStore', () => {
  const count = ref(0)

  const state = reactive({
    sum: 0,
    hero: {
      age: 19,
      name: '困困'
    }
  })

  const gettersSum = computed(() => state.sum)

  const increment = () => {
    count.value++
    state.sum++
    state.hero.age++
  }

  const subtraction = () => {
    count.value--
    state.sum--
    state.hero.age--
  }

  return {
    count: count,
    state: toRefs({ ...state }),
    gettersSum,
    increment,
    subtraction
  }
})
