import type { ProjectType } from '@/types/global'
import { defineStore } from 'pinia'

export const useGlobalStore = defineStore(
  'global',
  () => {
    const projectList = ref<ProjectType[]>([
      {
        name: '工程1',
        id: Date.now() + '',
        time: new Date().toLocaleString(),
        commandList: [
          {
            name: '任务1',
            id: '11',
            time: '2025-01-09 16:00:00',
            parentId: '1',
            x: 100,
            y: 100,
            stepList: [
              {
                x: 300,
                y: 100,
                type: 'condition',
                list: [
                  {
                    x: 300,
                    y: 100,
                    id: '111',
                    type: 'input',
                    label: 'DI1',
                    value: '闭合'
                  },
                  {
                    x: 300,
                    y: 400,
                    id: '112',
                    type: 'input',
                    label: 'AI1',
                    operation: '=',
                    value: '0'
                  },
                  {
                    x: 300,
                    y: 700,
                    id: '113',
                    type: 'time',
                    label: '每天',
                    value: '08:00'
                  }
                ]
              },
              {
                x: 3300,
                y: 100,
                id: '12',
                type: 'delay',
                value: '1000',
                unit: 's'
              },
              {
                x: 3700,
                y: 100,
                type: 'exec',
                list: [
                  {
                    x: 3700,
                    y: 20,
                    id: '131',
                    type: 'output',
                    label: 'DO1',
                    value: '打开'
                  },
                  {
                    x: 3700,
                    y: 40,
                    id: '132',
                    type: 'output',
                    label: 'AO1',
                    value: '0'
                  }
                ]
              }
            ]
          }
        ],
        isCompiled: false,
        CompileTime: ''
      }
    ])

    return { projectList }
  },
  {
    persist: true
  }
)
