<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Support;

defined('ABSPATH') || exit;

/**
 * Small contract used to render saved designs.
 *
 * Rendering a saved design needs only this CSS map, the default presentation
 * values, and the responsive breakpoints — so they live here, in one small
 * contract, rather than in the editing schema that produced the design.
 */
final class DesignRuntimeConfig
{
    /**
     * The widget settings whose value is the id of another design.
     *
     * Rendering has to follow these to know which designs a layout pulls in, so
     * the list belongs with the rendering contract rather than with any one
     * feature that happens to walk it.
     *
     * @var string[]
     */
    public const DESIGN_REFERENCE_KEYS = [
        'listItemDesignId',
        'infoboxDesignId',
        'detailDesignId',
        'searchFormId',
        'filterSearchFormId',
        'overlaySearchFormId',
        'markerDesignId',
        'categoryTileDesignId',
    ];

    /**
     * @return array<string, array{property:string, selector:string, unit:bool}>
     */
    public static function cssMap(): array
    {
        return [
            'display' => ['property' => 'display', 'selector' => '', 'unit' => false],
            'flexDirection' => ['property' => 'flex-direction', 'selector' => '', 'unit' => false],
            'justifyContent' => ['property' => 'justify-content', 'selector' => '', 'unit' => false],
            'alignItems' => ['property' => 'align-items', 'selector' => '', 'unit' => false],
            'gap' => ['property' => 'gap', 'selector' => '', 'unit' => true],
            'fontSize' => ['property' => 'font-size', 'selector' => '', 'unit' => true],
            'fontWeight' => ['property' => 'font-weight', 'selector' => '', 'unit' => false],
            'textAlign' => ['property' => 'text-align', 'selector' => '', 'unit' => false],
            'iconColor' => ['property' => 'color', 'selector' => ' svg', 'unit' => false],
            'background' => ['property' => 'background', 'selector' => '', 'unit' => false],
            'color' => ['property' => 'color', 'selector' => '', 'unit' => false],
            'padding' => ['property' => 'padding', 'selector' => '', 'unit' => true],
            'margin' => ['property' => 'margin', 'selector' => '', 'unit' => true],
            'borderRadius' => ['property' => 'border-radius', 'selector' => '', 'unit' => true],
            'width' => ['property' => 'width', 'selector' => '', 'unit' => true],
            'height' => ['property' => 'height', 'selector' => '', 'unit' => true],
            'objectFit' => ['property' => 'object-fit', 'selector' => '', 'unit' => false],
        ];
    }

    /** @return array<string, array<string, string>> */
    public static function itemDefaults(): array
    {
        return [
            'heading' => [
                'fontSize' => '16px',
                'fontWeight' => '700',
                'color' => 'var(--cliq-sl-heading, #0f172a)',
            ],
            'button' => [
                'background' => 'var(--cliq-sl-primary, #3858e9)',
                'color' => 'var(--cliq-sl-on-primary, #fff)',
                'borderRadius' => 'var(--cliq-sl-radius-sm, 0)',
                'padding' => '7px 14px',
                'fontWeight' => '600',
            ],
            'logo' => [
                'width' => '100%',
                'height' => 'auto',
                'borderRadius' => 'var(--cliq-sl-radius, 0)',
            ],
            'input' => [
                'background' => 'var(--cliq-sl-surface, #fff)',
                'borderWidth' => '1px',
                'borderColor' => 'var(--cliq-sl-border, #d5d8dc)',
                'borderRadius' => 'var(--cliq-sl-radius, 0)',
                'padding' => '11px 12px',
                'fontSize' => 'var(--cliq-sl-font-size, 14px)',
            ],
        ];
    }

    public static function tabletBreakpoint(): int
    {
        $breakpoint = (int) SettingsService::get('device_width_tablet', 768);

        return $breakpoint > 0 ? $breakpoint : 768;
    }

    public static function mobileBreakpoint(): int
    {
        $breakpoint = (int) SettingsService::get('device_width_mobile', 390);

        return $breakpoint > 0 ? $breakpoint : 390;
    }
}
