import { defineStore } from 'pinia'

export interface UserInfo {
  id: number,
  name: string,
  opmId: number,
  satoken: string
}

export interface Weather {
  city: string,
  info: string,
  temperature: string,
  weather: string,
  icon?:string
}

// id必填，且需要唯一
const useStore = defineStore('index', {
  state: () => ({
    userInfro: {} as UserInfo,
    token: '',
    loading: false,
    weather: {} as Weather,
    weatherIcons: [
      {
        name: '雨',
        icon: 'data:image/png;base64,[encoded data, 7964 characters]'
      },
      {
        name: '阴',
        icon: 'data:image/png;base64,[encoded data, 8224 characters]'
      },
      {
        name: '晴',
        icon: 'data:image/png;base64,[encoded data, 8004 characters]'
      },
      {
        name: '雪',
        icon: 'data:image/png;base64,[encoded data, 8704 characters]'
      },
      {
        name: '云',
        icon: 'data:image/png;base64,[encoded data, 8368 characters]'
      },
      {
        name: '雾',
        icon: 'data:image/png;base64,[encoded data, 8968 characters]'
      },
      {
        name: '沙',
        icon: 'data:image/png;base64,[encoded data, 8768 characters]'
      },
      {
        name: '霾',
        icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAABdJJREFUeF7tnV1u01AQhe1ErKvtEigroeK9zTsqK2lZQsu6UGJ0K93IQBLP2Gc8M7mHJ6jC/Jzz3bFrTeu+45+mFeib7p7NdwSgcQgIAAFoXIHG2+cEIACNK9B4+5wABKBxBRpvnxOAADSuQOPtcwIQgMYVaLx9TgAC0LgCjbfPCUAAGleg8fY5AQhA4wo03r7ZBPj28/ft98+f3tfW1ytv6dMr95K8UAAeXvZPXd89jk0fuv79x/3mzhKEIsB+2D723XD7V56h2z1/2T5Z5j7X87bf7ywPAKpnCAClmMOwebsotJEZpwxYA4Jr6RkCwNfXw9t/p+8EDc/3W0i+GnrS/PpBA/iupefFhohNKGaAjXh43Q/S8b7pD3eokXxNPS8GQHoSqlGoKSAawSM6kABk6Vly4BYDoDmFxQ8UAKpT+DF8cDej2p5R8Fn0nBYA7QSQnAbp5cQLAIueFwOgGYfIU2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QDcpI+RmADE8MGtCgLgJn2MxIsBGP9s2hotLf1Zw7XrXUOTcQ6tPrMB0OymWYig2XqZ2qCxqM81puIdR7MA0K5FW4khgWBqZcyqtghxJfqoAYgkqGTRNAqsHkBI9EkNQBF1at2bAGzuLsGnBsD72v9vMwTgvL0mE0C8i7/GzBOsXkcDdg1ZjjkE+qgnQAke4T5AQnepNRSwK7ov1WcWAEcIRnv4K/bWbfv9Tvv9bn2Hz5p1euXS6DMbAK/mmBerAAHA6pkuGgFIZxm2YAKA1TNdNAKQzjJswQQAq2e6aAQgnWXYggkAVs900QhAOsuwBRMArJ7pohGAdJZhCyYAWD3TRSMA6SzDFkwAsHqmi0YA0lmGLZgAYPVMF40ApLMMWzABwOqZLhoBSGcZtmACgNUzXTQCkM4ybMEEAKtnumh/APDyiK7HT3yPAAAAAElFTkSuQmCC'
      }
    ]
  }),
  actions: {
    setUserInfo(data: UserInfo) {
      this.userInfro = data
      this.token = data.satoken || ''
    },
    setWeather(data: Weather) {
      const obj = { ...data, icon: this.weatherIcons.find((el) => data.weather.indexOf(el.name) !== -1)?.icon }
      this.weather = obj
    }
  },
  persist: {
    enabled: true // true 表示开启持久化保存
  }
})
export default useStore