.PHONY: help

# Default to 'help' when no target is given
DEFAULT_GOAL := help
.DEFAULT_GOAL := $(DEFAULT_GOAL)

help:  ## Display this help screen
	@echo "Usage: make [target] ..."
	@echo
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: install
install: ## Install dependencies and pre-commit hooks.
	uv pip install -e ".[dev]"
	uv run pre-commit install

.PHONY: uninstall
uninstall: ## Uninstall the package from the local virtual environment.
	uv pip uninstall svglib -y

.PHONY: test
test: ## Run the test suite with coverage.
	uv run pytest -s -v -rs --cov=src/svglib --cov-report=term-missing --cov-report=html tests
	uv run coverage html

.PHONY: lint
lint: ## Run the formatter and linter.
	uv run ruff format .
	uv run ruff check --fix .

.PHONY: typecheck
typecheck: ## Run the type checker.
	uv run mypy --ignore-missing-imports src tests

.PHONY: hooks
hooks:  ## Run all pre-commit hooks.
	uv run pre-commit run --all-files

.PHONY: all
all: lint typecheck hooks test ## Run all checks (lint, typecheck, hookstest).

.PHONY: dist
dist: ## Build the package for distribution.
	uv build

.PHONY: test-dist
test-dist: ## Build and test the distribution wheel.
	@./scripts/test-dist.sh

.PHONY: clean
clean: ## Remove temporary build files.
	@find . -type f -name "*~" -delete
	@find . -type f -name "*.py[co]" -delete
	@find . -type f -name ".coverage" -delete
	@find . -type f -name "coverage.xml" -delete
	@find . -type d -name "__pycache__" -delete
	@find . -type d -name ".mypy_cache" -delete
	@find . -type d -name ".pytest_cache" -delete
	@find . -type d -name ".rust_cache" -delete
	@find . -type d -name "*.egg-info" -exec rm -rf {} +
	@rm -rf .pytest_cache .ruff_cache .mypy_cache .tox

.PHONY: testclean
testclean: ## Delete PDF files generated by the test suite.
	@find tests/samples -type f -name "*-svglib.pdf" -delete

.PHONY: distclean
distclean: clean ## Delete all temporary files and the virtual environment.
	@rm -rf .venv
