import { create } from "zustand";

interface Amenity {
  name: string;
  name_ru: string;
  icon_name: string;
}

interface TicketStore {
  amenities: Amenity[];
  id: number | null;
  setId: (id: number) => void;
  setAmenities: (amenities: Amenity[]) => void;
  addAmenity: (amenity: Amenity) => void;
  removeAmenity: (index: number) => void;
  updateAmenity: (index: number, updated: Partial<Amenity>) => void;
}

export const useTicketStore = create<TicketStore>((set) => ({
  amenities: [],
  id: null,
  setId: (id) => set({ id }),
  setAmenities: (amenities) => set({ amenities }),
  addAmenity: (amenity) =>
    set((state) => ({ amenities: [...state.amenities, amenity] })),
  removeAmenity: (index) =>
    set((state) => ({
      amenities: state.amenities.filter((_, i) => i !== index),
    })),
  updateAmenity: (index, updated) =>
    set((state) => ({
      amenities: state.amenities.map((a, i) =>
        i === index ? { ...a, ...updated } : a,
      ),
    })),
}));
