import { defineStore } from 'pinia'
import { ref } from 'vue'

export interface Regulation {
  id: string
  name: string
  type: string
  typeName: string
  publisher: string
  publishTime: string
  effectiveDate: string
  confirmStatus: 'pending' | 'confirmed'
  content: string
  scope: string
  requirements: string
  notes: string
}

export const useRegulationStore = defineStore('regulation', () => {
  // 已发布的制度列表
  const publishedRegulations = ref<Regulation[]>([])

  // 添加新发布的制度
  const addPublishedRegulation = (regulation: Regulation) => {
    publishedRegulations.value.unshift(regulation)
  }

  // 更新制度确认状态
  const updateRegulationConfirmStatus = (id: string, status: 'pending' | 'confirmed') => {
    const regulation = publishedRegulations.value.find(item => item.id === id)
    if (regulation) {
      regulation.confirmStatus = status
    }
  }

  // 批量确认所有制度
  const confirmAllRegulations = () => {
    publishedRegulations.value.forEach(regulation => {
      regulation.confirmStatus = 'confirmed'
    })
  }

  return {
    publishedRegulations,
    addPublishedRegulation,
    updateRegulationConfirmStatus,
    confirmAllRegulations
  }
}) 