FROM ghcr.io/gleam-lang/gleam:v1.13.0-erlang-alpine

WORKDIR /workspace

# Install dependencies
RUN apk add --no-cache curl gettext

# Download gleam dependencies
COPY gleam.toml manifest.toml* ./
RUN gleam deps download

# Copy source code
COPY . .

# Download and setup tailwindcss, then build CSS
RUN mkdir -p build/bin && \
    curl -sLo build/bin/tailwindcss https://github.com/tailwindlabs/tailwindcss/releases/download/v4.1.17/tailwindcss-linux-x64-musl && \
    chmod +x build/bin/tailwindcss && \
    build/bin/tailwindcss -i ./tailwind.css -o ./priv/static/app.css

# Compile i18n message catalogs
RUN sh -c 'mkdir -p priv/locales && cd locales && for d in */; do mkdir -p ../priv/locales/$d/LC_MESSAGES && msgfmt -o ../priv/locales/$d/LC_MESSAGES/messages.mo $d/messages.po; done'

CMD ["gleam", "run"]
