<?php
declare(strict_types=1);

namespace ROITheme\Admin\RelatedPost\Infrastructure\FieldMapping;

use ROITheme\Admin\Shared\Domain\Contracts\FieldMapperInterface;

/**
 * Field Mapper para Related Post
 *
 * RESPONSABILIDAD:
 * - Mapear field IDs del formulario a atributos de BD
 * - Solo conoce sus propios campos (modularidad)
 *
 * NOTA: Este componente NO tenia mapeos en AdminAjaxHandler
 * (era el unico componente roto - 35 campos no se guardaban)
 */
final class RelatedPostFieldMapper implements FieldMapperInterface
{
    public function getComponentName(): string
    {
        return 'related-post';
    }

    public function getFieldMapping(): array
    {
        return [
            // Visibility
            'relatedPostEnabled' => ['group' => 'visibility', 'attribute' => 'is_enabled'],
            'relatedPostShowOnDesktop' => ['group' => 'visibility', 'attribute' => 'show_on_desktop'],
            'relatedPostShowOnMobile' => ['group' => 'visibility', 'attribute' => 'show_on_mobile'],

            // Page Visibility (grupo especial _page_visibility)
            'relatedPostVisibilityHome' => ['group' => '_page_visibility', 'attribute' => 'show_on_home'],
            'relatedPostVisibilityPosts' => ['group' => '_page_visibility', 'attribute' => 'show_on_posts'],
            'relatedPostVisibilityPages' => ['group' => '_page_visibility', 'attribute' => 'show_on_pages'],
            'relatedPostVisibilityArchives' => ['group' => '_page_visibility', 'attribute' => 'show_on_archives'],
            'relatedPostVisibilitySearch' => ['group' => '_page_visibility', 'attribute' => 'show_on_search'],

            // Exclusions (grupo especial _exclusions - Plan 99.11)
            'relatedPostExclusionsEnabled' => ['group' => '_exclusions', 'attribute' => 'exclusions_enabled'],
            'relatedPostExcludeCategories' => ['group' => '_exclusions', 'attribute' => 'exclude_categories', 'type' => 'json_array'],
            'relatedPostExcludePostIds' => ['group' => '_exclusions', 'attribute' => 'exclude_post_ids', 'type' => 'json_array_int'],
            'relatedPostExcludeUrlPatterns' => ['group' => '_exclusions', 'attribute' => 'exclude_url_patterns', 'type' => 'json_array_lines'],

            // Content
            'relatedPostSectionTitle' => ['group' => 'content', 'attribute' => 'section_title'],
            'relatedPostPerPage' => ['group' => 'content', 'attribute' => 'posts_per_page'],
            'relatedPostOrderby' => ['group' => 'content', 'attribute' => 'orderby'],
            'relatedPostOrder' => ['group' => 'content', 'attribute' => 'order'],
            'relatedPostShowPagination' => ['group' => 'content', 'attribute' => 'show_pagination'],

            // Layout
            'relatedPostColsDesktop' => ['group' => 'layout', 'attribute' => 'columns_desktop'],
            'relatedPostColsTablet' => ['group' => 'layout', 'attribute' => 'columns_tablet'],
            'relatedPostColsMobile' => ['group' => 'layout', 'attribute' => 'columns_mobile'],

            // Typography
            'relatedPostSectionTitleSize' => ['group' => 'typography', 'attribute' => 'section_title_size'],
            'relatedPostSectionTitleWeight' => ['group' => 'typography', 'attribute' => 'section_title_weight'],
            'relatedPostCardTitleSize' => ['group' => 'typography', 'attribute' => 'card_title_size'],
            'relatedPostCardTitleWeight' => ['group' => 'typography', 'attribute' => 'card_title_weight'],

            // Colors
            'relatedPostSectionTitleColor' => ['group' => 'colors', 'attribute' => 'section_title_color'],
            'relatedPostCardBgColor' => ['group' => 'colors', 'attribute' => 'card_bg_color'],
            'relatedPostCardTitleColor' => ['group' => 'colors', 'attribute' => 'card_title_color'],
            'relatedPostCardHoverBgColor' => ['group' => 'colors', 'attribute' => 'card_hover_bg_color'],
            'relatedPostPaginationBgColor' => ['group' => 'colors', 'attribute' => 'pagination_bg_color'],
            'relatedPostPaginationTextColor' => ['group' => 'colors', 'attribute' => 'pagination_text_color'],
            'relatedPostPaginationActiveBg' => ['group' => 'colors', 'attribute' => 'pagination_active_bg'],
            'relatedPostPaginationActiveText' => ['group' => 'colors', 'attribute' => 'pagination_active_text'],

            // Spacing
            'relatedPostSectionMarginTop' => ['group' => 'spacing', 'attribute' => 'section_margin_top'],
            'relatedPostSectionMarginBottom' => ['group' => 'spacing', 'attribute' => 'section_margin_bottom'],
            'relatedPostTitleMarginBottom' => ['group' => 'spacing', 'attribute' => 'title_margin_bottom'],
            'relatedPostGridGap' => ['group' => 'spacing', 'attribute' => 'grid_gap'],
            'relatedPostCardPadding' => ['group' => 'spacing', 'attribute' => 'card_padding'],
            'relatedPostPaginationMarginTop' => ['group' => 'spacing', 'attribute' => 'pagination_margin_top'],

            // Visual Effects
            'relatedPostCardBorderRadius' => ['group' => 'visual_effects', 'attribute' => 'card_border_radius'],
            'relatedPostCardShadow' => ['group' => 'visual_effects', 'attribute' => 'card_shadow'],
            'relatedPostCardHoverShadow' => ['group' => 'visual_effects', 'attribute' => 'card_hover_shadow'],
            'relatedPostCardTransition' => ['group' => 'visual_effects', 'attribute' => 'card_transition'],
        ];
    }
}
