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).

## 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) Set your deployed web URL

The Android wrapper opens your deployed AZCHESS site in WebView.

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

> Use `http://...` only for local/dev tunnels. `https://...` is recommended.
> If `AZCHESS_ANDROID_URL` is not set, Android falls back to
> `NEXT_PUBLIC_APP_URL`, and then to the production default
> `https://www.azchess.az`.
> `npx cap sync android` reads these values from your shell env and from
> `.env` / `.env.local`.
> Local/private hosts (for example `localhost`, `127.0.0.1`, `192.168.x.x`) are
> ignored by default for Android APK to avoid startup URL errors on phones.
> If you really need them for local testing, set:
>
> ```bash
> export AZCHESS_ANDROID_ALLOW_LOCAL_URLS=1
> ```
> To explicitly disable that fallback, set:
>
> ```bash
> export AZCHESS_ANDROID_DISABLE_NEXT_PUBLIC_URL=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`.

### 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.

### 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"
```

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