# Login Customization

Each layout is one folder with a small set of files:

- **`config.php`** — label, capabilities, defaults, **declared `fields`** (no markup).
- **`template.php`** — registers WordPress login hooks; compose markup from `_partials/`.
- **`thumb.svg`** — optional thumbnail for the admin picker (PNG/JPG/WEBP also accepted).

## Module layout

```
LoginCustomization/
├── Template.php             # Template::partial() / capture()
├── TemplateLoader.php
├── Context.php
├── Frontend.php
├── Policy.php
├── Admin/
│   ├── AdminAssets.php
│   ├── BuilderSections.php  # Groups a template's `fields` by section
│   ├── FieldRenderers.php   # Schema + renderers for every known builder field
│   ├── LayoutAdmin.php      # Free picker fallback when Pro is not present
│   ├── SplitLayoutControls.php
│   └── TemplatePicker.php
├── Support/
│   ├── Assets.php
│   ├── CssGenerator.php
│   └── StyleSanitizer.php
└── templates/
    ├── manifest.php
    ├── _partials/           # Reusable markup (intro, footer, …)
    │   ├── hooks/           # Optional hook bundles (centered-layout.php)
    │   ├── intro.php
    │   ├── footer.php
    │   └── …
    ├── split-screen/
    │   ├── config.php
    │   ├── template.php
    │   └── thumb.svg
    └── modern-center/
        ├── config.php
        ├── template.php
        └── thumb.svg
```

## Partials

Load shared markup from any `template.php`:

```php
use Bdthemes\SmartAdminAssistant\Modules\LoginCustomization\Template;
use Bdthemes\SmartAdminAssistant\Modules\LoginCustomization\TemplateLoader;

// Echo in an action callback:
Template::partial('footer');

// Prepend HTML in a filter:
$html = Template::capture('intro');
return $html . $message;
```

Partials receive **`$c`** (same data as `TemplateLoader::vars()`, plus any extra `$args`).

Override a partial path: filter `bdtsaa_login_template_partial_path`.

## Adding a new template

1. Create `templates/<slug>/` with three files:

   **`config.php`**

   ```php
   <?php
   if (! defined('ABSPATH')) {
       exit;
   }

   return [
       'label'        => __('My Layout', 'smart-admin-assistant'),
       'description'  => __('Short description shown on the picker card', 'smart-admin-assistant'),
       'preview'      => 'center',         // 'center' | 'split-left' | 'split-right'
       'capabilities' => [
           'supports_panel_content'  => false,
           'supports_split_position' => false,
           'supports_footer_links'   => true,
       ],
       'defaults'     => [
           // Optional preset values applied via JS when this template is picked.
           'login_bg_color'     => '#f8fafc',
           'form_bg_color'      => '#ffffff',
           'form_border_color'  => '#e2e8f0',
           'form_border_radius' => '10px',
           'form_backdrop_blur' => '0',
           'button_color'       => '#3b82f6',
       ],
       'fields'       => [
           // Which builder fields this template exposes. Keys are looked up in
           // FieldRenderers::schema(). Fields you omit are still in the DOM but
           // hidden when this template is selected (their saved values are kept).
           'login_heading', 'login_subheading',
           'login_footer_text', 'login_footer_privacy_url', 'login_footer_help_url',
           'custom_logo_url', 'logo_width', 'logo_top_spacing',
           'login_bg_color', 'login_bg_image',
           'form_bg_color', 'form_border_color', 'form_border_radius', 'form_backdrop_blur',
           'button_color',
       ],
   ];
   ```

   **`template.php`**

   ```php
   <?php
   if (! defined('ABSPATH')) {
       exit;
   }

   // Reuse centered hooks (head, intro, footer, secondary screens):
   require dirname(__DIR__) . '/_partials/hooks/centered-layout.php';

   // Or compose your own hooks — see split-screen/template.php for an example.
   ```

   **`thumb.svg`** — a small (≈200×100) SVG mock of the layout. PNG/JPG/WEBP also work
   (`thumb.png`, `thumb.jpg`, `thumb.webp`). The picker auto-renders the first file it
   finds — **no SCSS edits needed**. If you skip the thumb file, the picker falls back
   to the legacy `.bdtsaa-login-template-card__thumb--<slug>` CSS class.

2. **(Optional)** add the slug to `templates/manifest.php` to set its display order or
   temporarily hide it. Auto-discovery already includes every folder with a `config.php`.

3. **(Optional)** add SCSS for `body.login.bdtsaa-login-template-my-layout` in
   `src/scss/login.scss` if your layout needs unique frontend styling.

## Adding a new builder field

Rare — most templates reuse existing fields. To add a brand-new key:

1. Add it to `Admin/FieldRenderers::schema()` with its `type`, `section`, `label`, and
   any type-specific options (placeholder, min/max, defaults, etc.).
2. Reference the new key from any template's `fields` array.

Supported field types in `FieldRenderers`: `text`, `url`, `textarea`, `number`, `media`,
`color_row`. Add a new type by extending the `switch` in `FieldRenderers::render()`.

## Split Screen layout options

When **Split Screen** is selected, the **Split Screen layout** controls appear under the
picker (form column position + logo alignment). They're driven by the
`supports_split_position` capability, not the `fields` array — any template that sets
`'supports_split_position' => true` gets them automatically.

## Frontend CSS variables

`Support\CssGenerator` emits `--bdtsaa-login-*` custom properties scoped to
`body.login.bdtsaa-login-template-<slug>`. Layout rules live in
`src/scss/login.scss`; the inline block only provides values.

## Catalog

Edit `templates/manifest.php` to reorder or set `'enabled' => false`. Deleted entries
fall back to auto-discovery.

## Extension filters

`bdtsaa_login_template_manifest`, `bdtsaa_login_templates`,
`bdtsaa_login_template_context`, `bdtsaa_login_generated_css`,
`bdtsaa_login_templates_dir`, `bdtsaa_login_template_partial_path`

Pro builder: `LoginCustomizationAdmin` (Pro plugin only) — renders the picker + fields
using `TemplatePicker`, `SplitLayoutControls`, `BuilderSections`, and `FieldRenderers`
(all owned by the free plugin).
