import { defineStore } from 'pinia'
import type { OperationResultDto } from '../api/contracts'
import { useAuthStore } from './auth'

export const useMissionControlUiStore = defineStore('mission-control-ui', {
  state: () => ({
    commandOpen: false,
    irisOpen: false,
    operationResult: null as OperationResultDto | null,
    operationTitle: 'Operation',
  }),
  actions: {
    openCommand() {
      this.irisOpen = false
      this.commandOpen = true
    },
    closeCommand() {
      this.commandOpen = false
    },
    openIris() {
      if (!useAuthStore().isOwner) {
        this.irisOpen = false
        return
      }
      this.commandOpen = false
      this.irisOpen = true
    },
    closeIris() {
      this.irisOpen = false
    },
    showOperation(result: OperationResultDto, title = 'Operation') {
      this.operationResult = result
      this.operationTitle = title
    },
    dismissOperation() {
      this.operationResult = null
      this.operationTitle = 'Operation'
    },
  },
})
