import { defineStore } from "pinia";
import axios from "axios";
export const useSlipStore = defineStore({
	id: "slips",
	state: () => ({
		slip: {},
    details : {},
	}),
	getters: {
    showSlip(state) {
      return state.slip;
    },
    getClientName(state) {
      return state.details.clientname;
    },
    getSlipDate(state) {
      return state.details.slipdate;
    },
    getDetails(state) {
      return state.details.slipmeta;
    },
    getSlipCount(state) {
      return state.details.availability;
    },
    getInstructions(state) {
      return state.details.description;
    }
  },
	actions: {
		async getSlipDetails(id: string, endpoint: string) {
			try {    
        const myResult = await axios.get(`${endpoint}/api/slip/id/${id}`);
				if(myResult){          
          this.slip = myResult.data.data;
          this.details = myResult.data.data.attributes;
        }
			} catch (err) {
				console.log(err);
			}
		},
	},
});
