import { defineStore } from 'pinia'

interface VisitedRowState {
  trackingTableData: Array<String>
  bookingTableData: Array<String>
}

export const useVisitedRowState = defineStore('visitedRowState', {
  state: (): VisitedRowState => ({
    trackingTableData: JSON.parse(localStorage.getItem('trackingTableData')) || [],
    bookingTableData: JSON.parse(localStorage.getItem('bookingTableData')) || []
  }),
  getters: {},
  actions: {
    setTrackingTableData(item: String) {
      this.trackingTableData.push(item)
      localStorage.setItem('trackingTableData', JSON.stringify(this.trackingTableData))
    },
    setBookingTableData(item: String) {
      this.bookingTableData.push(item)
      localStorage.setItem('bookingTableData', JSON.stringify(this.bookingTableData))
    },
    clearVisitedRow() {
      this.trackingTableData = []
      this.bookingTableData = []
      localStorage.removeItem('trackingTableData')
      localStorage.removeItem('bookingTableData')
    }
  }
})
