#!/bin/bash
set -e

if ! command -v corepack >/dev/null 2>&1; then
  echo "❌ corepack is required for pre-commit checks."
  exit 1
fi

if ! git diff --cached --quiet -- '*.rs' Cargo.toml Cargo.lock; then
  cargo fmt --manifest-path src-tauri/Cargo.toml -- --emit=files
fi

if ! git diff --cached --quiet -- src/locales crates/clash-verge-i18n/locales; then
  corepack pnpm i18n:types
  git add src/types/generated
fi

if ! git diff --cached --quiet -- '*.js' '*.jsx' '*.ts' '*.tsx' '*.json' '*.css' '*.scss' '*.html'; then
  corepack pnpm exec lint-staged
fi
