import { defineStore } from "pinia";
import appService from "../../services/appService";
import axios from 'axios'

export const useFrontendItemStore = defineStore("frontendItem", {
    state: () => ({
        lists: [],
    }),
    actions: {
        fetchLists: function (payload) {
            return new Promise((resolve, reject) => {
                let url = 'frontend/item';
                if (payload) {
                    url = url + appService.requestHandler(payload);
                }
                axios.get(url).then((res) => {
                    if (typeof payload.pinia === "undefined" || payload.pinia === true) {
                        this.lists = res.data.data;
                    }
                    resolve(res);
                }).catch((err) => {
                    reject(err);
                });
            });
        },
        details: function (payload) {
            return new Promise((resolve, reject) => {
                let url = `frontend/item/details/${payload}`;
                axios.get(url, payload).then((res) => {
                    resolve(res);
                }).catch((err) => {
                    reject(err);
                });
            });
        },
    }
});
