# EchoAI Installer

This directory contains the installer component for the EchoAI WordPress plugin.

## Overview

The installer is responsible for setting up the EchoAI plugin on a WordPress site. It handles the initial configuration, API key setup, and content indexing process.

## Files

- `installer.html`: The test HTML template for the installer interface.
- `mini.html`: The test HTML template for the mini installer interface.
- `dist/installer.html`: The production-ready version of the installer interface.
- `dist/installer.js`: The compiled JavaScript for the full installer.
- `dist/mini.js`: A lightweight version of the installer for specific functionalities.
- `dist/style.css`: The compiled CSS for the installer.
- `src/installer.tsx`: The main TypeScript React component for the installer.
- `src/mini.tsx`: The source for the lightweight mini installer.

## Usage

The installer is automatically invoked when a user activates the EchoAI plugin for the first time or when they need to reconfigure the plugin.

### Full Installer

The full installer (`installer.js`) is used for the complete setup process, including partner registration and initial content indexing.

### Mini Installer

The mini installer (`mini.js`) is a lightweight version used for specific functionalities:

- Displaying the current indexing progress
- Showing error messages related to the indexing process

It's typically used on the plugin's dashboard or settings pages to provide quick access to indexing controls without loading the full installer.

## Development

To work on the installer:

1. Ensure you have Node.js and npm installed.
2. Navigate to the `/installer` directory.
3. Run `npm install` to install dependencies.
4. Use `npm run dev` for development with hot-reloading.
5. Use `npm run build` to create a production build of both the full installer and mini installer.

## API Configuration

Both the full installer and mini installer use the `apiConfig` object to communicate with the WordPress REST API. This object is injected into the page by the WordPress plugin and includes:

- `setup`: The endpoint for the setup process.
- `processJob`: The endpoint for processing indexing jobs.
- `dashboard`: The URL for the EchoAI dashboard in the WordPress admin.
- `apiKey`: The API key for authenticating requests.

## Localization

The installer and mini installer support multiple languages. Ensure all user-facing strings are wrapped in translation functions for proper localization.

## Integration

### Full Installer

To integrate the full installer into a WordPress admin page:

1. Enqueue the `installer.js` script on the desired admin page.
2. Create a container element with the ID `echoai_setup`.
3. Ensure the `apiConfig` object is properly defined before the script loads.

Example:

```php
function enqueue_echoai_installer() {
wp_enqueue_script('echoaisetupjs', ECHOAI_PLUGIN_URL . 'installer/dist/installer.js', array(), ECHOAI_VERSION, true);
wp_localize_script('echoaisetupjs', 'apiConfig', array(
'setup' => rest_url('echo-ai/v1/setup'),
'processJob' => rest_url('echo-ai/v1/process-job'),
'dashboard' => admin_url('admin.php?page=echoai'),
'apiKey' => get_option('echoai_wp_api_key'),
));
}
add_action('admin_enqueue_scripts', 'enqueue_echoai_installer');
?>
```

### Mini Installer

To integrate the mini installer into a WordPress admin page:

1. Enqueue the `mini.js` script on the desired admin page.
2. Create a container element with the ID `echoai_setup`.
3. Ensure the `apiConfig` object is properly defined before the script loads.

Example:
```php
function enqueue_echoai_mini_installer() {
wp_enqueue_script('echoaisetupjs-mini', ECHOAI_PLUGIN_URL . 'installer/dist/mini.js', array(), ECHOAI_VERSION, true);
wp_localize_script('echoaisetupjs-mini', 'apiConfig', array(
'setup' => rest_url('echo-ai/v1/setup'),
'processJob' => rest_url('echo-ai/v1/process-job'),
'dashboard' => admin_url('admin.php?page=echoai'),
'apiKey' => get_option('echoai_wp_api_key'),
));
}
add_action('admin_enqueue_scripts', x'enqueue_echoai_mini_installer');
?>
```