<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Integrations;

defined('ABSPATH') || exit;

use CliqThemes\StoreLocator\Layouts\LocatorLayouts;

use CliqThemes\StoreLocator\Layouts\BundledLocatorPreset;

/**
 * Lists saved locator templates (Builder designs with the 'locator' purpose) as
 * id => label, for the page-builder widgets' template pickers.
 */
final class LocatorTemplates
{
    /**
     * @return array<string, string> id => "Name (#id)" (a placeholder is prepended when requested)
     */
    public static function options(bool $placeholder = true): array
    {
        $layouts = LocatorLayouts::source()->all();

        // One layout is not a choice, so the picker shows it without asking the
        // author to select from a list of one.
        $out = ($placeholder && count($layouts) > 1)
            ? ['' => __('— Select a template —', 'cliq-store-locator')]
            : [];

        foreach ($layouts as $layout) {
            $id = (string) $layout['id'];
            $name = (string) ($layout['name'] ?? '');
            $out[$id] = $name !== '' ? $name : __('Untitled', 'cliq-store-locator');
        }

        return $out;
    }
}
