import { defineStore } from 'pinia'
import type { TextInfo, TextState } from './helper'
import { defaultSetting, getLocalState, setLocalState } from './helper'

export const useTextStore = defineStore('text-store', {
  state: (): TextState => getLocalState(),
  actions: {
    updateTextInfo(textInfo: Partial<TextInfo>) {
      this.textInfo = { ...this.textInfo, ...textInfo }
      this.recordState()
    },

    resetTextInfo() {
      this.textInfo = { ...defaultSetting().textInfo }
      this.recordState()
    },

    recordState() {
      setLocalState(this.$state)
    },
  },
})
