This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Source handoff for Lichess

This repository is prepared as a shareable frontend source handoff.

- Full frontend source is included.
- Local environment files are intentionally excluded.
- Use `.env.example` as a template for local configuration.

### Quick start

```bash
npm install
cp .env.example .env.local
npm run dev
```

## Branding

AZCHESS © - JBA Group LLC - Lichess powered platform

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

## Android APK (direct install / sideload)

This repo includes a Capacitor Android wrapper so you can build an APK and install it directly on your phone before Play Console approval.

### Prerequisites

- Node.js + npm
- JDK 17
- Android Studio (SDK + platform tools)

### 1) Android startup behavior (remote first with local fallback)

APK opens your normal deployed AZCHESS web home by default.
If network is unavailable, Android falls back to bundled local `local-home.html` (settings + offline Stockfish).

```bash
export AZCHESS_ANDROID_URL="https://your-domain.com"
```

Optional fallback source:

```bash
export AZCHESS_ANDROID_USE_NEXT_PUBLIC_URL=1
```

To force local-first boot behavior for testing, set:

```bash
export AZCHESS_ANDROID_LOCAL_MODE=1
```

### 2) Create/sync Android project

First time:

```bash
npm run android:add
```

Every time after config/dependency changes:

```bash
npm run android:sync
```

> OAuth/login note: Lichess auth should open externally and return via deep link.
> If login flow seems stale, rebuild APK after `android:sync`.
> Security note: set a strong `LICHESS_OAUTH_STATE_SECRET` in production env.

### 3) Build debug APK

```bash
npm run android:apk:debug
```

APK output:

```text
android/app/build/outputs/apk/debug/app-debug.apk
```

Install to device (USB debugging on):

```bash
adb install -r android/app/build/outputs/apk/debug/app-debug.apk
```

### Optional: release APK

```bash
npm run android:apk:release
```

You will need signing config before distributing a release build.

### Google Play release bundle (AAB)

```bash
npm run android:aab:release
```

Bundle output:

```text
android/app/build/outputs/bundle/release/app-release.aab
```

You will need signing config before uploading to Play Console.

### Play Console privacy policy URL

Use your publicly reachable policy page, for example:

```text
https://www.azchess.az/privacy
```

This route is stable and redirects to the localized policy page.

### Show APK download button on homepage

Professional setup (recommended):

1) Build your release APK.
2) `npm run build` automatically runs `npm run apk:publish`.
3) The script copies APK to:

```text
public/downloads/azchess.apk
```

If `public/downloads/azchess.apk` already exists in the repo, it is kept as-is and still published.
4) Homepage download button is shown automatically only when:

```text
/downloads/apk-manifest.json => { "available": true, ... }
```

Supported APK source paths:

- `android/app/release/app-release.apk`
- `android/app/release/apk-release.apk`
- `android/app/build/outputs/apk/release/app-release.apk`
- `android/app/build/outputs/apk/release/apk-release.apk`
- optional override: `AZCHESS_APK_SOURCE=/absolute/or/relative/path/to.apk`

Stable public URL:

```text
https://your-domain/downloads/azchess.apk
```

Optional env var (only if you host APK elsewhere):

```bash
NEXT_PUBLIC_ANDROID_APK_URL="https://your-file-host.example.com/azchess.apk"
```

Store badges (shown on homepage + settings when configured):

```bash
NEXT_PUBLIC_APP_STORE_URL="https://apps.apple.com/app/idXXXXXXXXXX"
NEXT_PUBLIC_PLAY_STORE_URL="https://play.google.com/store/apps/details?id=com.azchess.app"
```

Backward compatibility: old paths `/android/app/release/app-release.apk` and `/android/app/release/apk-release.apk` redirect to `/downloads/azchess.apk`.
