# ================================
# Base
# ================================
FROM node:22 AS base
WORKDIR /app
COPY package.json package-lock.json ./

# ================================
# DEV
# ================================
FROM base AS dev
ENV NODE_ENV=development
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev"]

# ================================
# STAGING
# ================================
FROM base AS staging
ARG VITE_API_URL
ENV NODE_ENV=staging
ENV VITE_API_URL=$VITE_API_URL
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "run", "preview"]

# ================================
# PROD
# ================================
FROM base AS builder
ARG VITE_API_URL
ENV NODE_ENV=production
ENV VITE_API_URL=$VITE_API_URL
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine AS runner
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /app/dist .
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]