# Base image
FROM node:24.16.0-alpine AS base

WORKDIR /app

RUN corepack enable && corepack prepare pnpm@10.24.0 --activate

COPY package*.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile

# Development Build
FROM base AS development

ARG ALLOWED_HOSTS=""
ARG STRIPE_PUBLISHABLE_KEY=""
ARG STRIPE_PRICE_ID=""
ARG API_BASE_URL=""

COPY . .

ENV HOST=0.0.0.0
ENV PORT=4321
ENV ALLOWED_HOSTS=${ALLOWED_HOSTS}
ENV STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
ENV STRIPE_PRICE_ID=${STRIPE_PRICE_ID}
ENV API_BASE_URL=${API_BASE_URL}

EXPOSE 4321

CMD ["pnpm", "dev", "--host", "0.0.0.0", "--port", "4321"]

# Build stage for production assets
FROM base AS build

ARG ALLOWED_HOSTS=""
ARG STRIPE_PUBLISHABLE_KEY=""
ARG STRIPE_PRICE_ID=""
ARG API_BASE_URL=""

COPY . .

ENV ALLOWED_HOSTS=${ALLOWED_HOSTS}
ENV STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
ENV STRIPE_PRICE_ID=${STRIPE_PRICE_ID}
ENV API_BASE_URL=${API_BASE_URL}

RUN pnpm build


# Production runtime for static assets
FROM nginx:1.27-alpine AS production

COPY --from=build /app/dist /usr/share/nginx/html

EXPOSE 80
