61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
|
|
import { useCartStore } from "~/stores/cart";
|
|||
|
|
import { storeToRefs } from "pinia";
|
|||
|
|
import type { EquipmentItem } from "~/composables/useEquipment";
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Cart composable – wraps the Pinia cart store for convenient use in components.
|
|||
|
|
* Provides reactive refs and action methods.
|
|||
|
|
*/export function useCart() {
|
|||
|
|
const store = useCartStore();
|
|||
|
|
|
|||
|
|
const { items, totalCount, isEmpty, hasItems, apiItems } = storeToRefs(store);
|
|||
|
|
|
|||
|
|
function addItem(equipment: EquipmentItem): void {
|
|||
|
|
store.addItem(equipment);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function addItemByFields(item: {
|
|||
|
|
equipment_id: number;
|
|||
|
|
name: string;
|
|||
|
|
rental_price: number | null;
|
|||
|
|
image_url: string | null;
|
|||
|
|
}): void {
|
|||
|
|
store.addItemByFields(item);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function removeItem(equipmentId: number): void {
|
|||
|
|
store.removeItem(equipmentId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function updateQuantity(equipmentId: number, quantity: number): void {
|
|||
|
|
store.updateQuantity(equipmentId, quantity);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function incrementQuantity(equipmentId: number): void {
|
|||
|
|
store.incrementQuantity(equipmentId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function decrementQuantity(equipmentId: number): void {
|
|||
|
|
store.decrementQuantity(equipmentId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function clearCart(): void {
|
|||
|
|
store.clearCart();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
items,
|
|||
|
|
totalCount,
|
|||
|
|
isEmpty,
|
|||
|
|
hasItems,
|
|||
|
|
apiItems,
|
|||
|
|
addItem,
|
|||
|
|
addItemByFields,
|
|||
|
|
removeItem,
|
|||
|
|
updateQuantity,
|
|||
|
|
incrementQuantity,
|
|||
|
|
decrementQuantity,
|
|||
|
|
clearCart,
|
|||
|
|
};
|
|||
|
|
}
|