Response
Write access was denied, so here's the file content directly instead:
```ts
// stores/cart.ts
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
export interface CartItem {
id: string
name: string
price: number
quantity: number
}
export const useCartStore = defineStore('cart', () => {
const items = ref<CartItem[]>([])
function add(item: Omit<CartItem, 'quantity'>, quantity = 1) {
const existing = items.value.find((i) => i.id === item.id)
if (existing) {
existing.quantity += quantity
} else {
items.value.push({ ...item, quantity })
}
}
function remove(id: string) {
items.value = items.value.filter((i) => i.id !== id)
}
const total = computed(() =>
items.value.reduce((sum, item) => sum + item.price * item.quantity, 0)
)
return { items, add, remove, total }
})
```
If you'd like this saved to a file, let me know and I can retry with permission.