getData(); if (!$this->isEnabled($data)) { return ''; } if (!PageVisibilityHelper::shouldShow(self::COMPONENT_NAME)) { return ''; } $visibilityClass = $this->getVisibilityClass($data); if ($visibilityClass === null) { return ''; } $css = $this->generateCSS($data); $html = $this->buildHTML($data, $visibilityClass); return sprintf("\n%s", $css, $html); } public function supports(string $componentType): bool { return $componentType === self::COMPONENT_NAME; } private function isEnabled(array $data): bool { $value = $data['visibility']['is_enabled'] ?? false; return $value === true || $value === '1' || $value === 1; } private function getVisibilityClass(array $data): ?string { $showDesktop = $data['visibility']['show_on_desktop'] ?? true; $showDesktop = $showDesktop === true || $showDesktop === '1' || $showDesktop === 1; $showMobile = $data['visibility']['show_on_mobile'] ?? true; $showMobile = $showMobile === true || $showMobile === '1' || $showMobile === 1; if (!$showDesktop && !$showMobile) { return null; } if (!$showDesktop && $showMobile) { return 'd-lg-none'; } if ($showDesktop && !$showMobile) { return 'd-none d-lg-block'; } return ''; } private function generateCSS(array $data): string { $colors = $data['colors'] ?? []; $spacing = $data['spacing'] ?? []; $typography = $data['typography'] ?? []; $behavior = $data['behavior'] ?? []; $cssRules = []; // Container $marginTop = $spacing['margin_top'] ?? '2rem'; $marginBottom = $spacing['margin_bottom'] ?? '2rem'; $padding = $spacing['padding'] ?? '1.5rem'; $cssRules[] = $this->cssGenerator->generate('.archive-header', [ 'margin-top' => $marginTop, 'margin-bottom' => $marginBottom, 'padding' => $padding, ]); // Sticky behavior $isSticky = $behavior['is_sticky'] ?? false; $isSticky = $isSticky === true || $isSticky === '1' || $isSticky === 1; if ($isSticky) { $stickyOffset = $behavior['sticky_offset'] ?? '0'; $cssRules[] = $this->cssGenerator->generate('.archive-header', [ 'position' => 'sticky', 'top' => $stickyOffset, 'z-index' => '100', 'background' => '#ffffff', ]); } // Title $titleColor = $colors['title_color'] ?? '#0E2337'; $titleSize = $typography['title_size'] ?? '2rem'; $titleWeight = $typography['title_weight'] ?? '700'; $titleMarginBottom = $spacing['title_margin_bottom'] ?? '0.5rem'; $cssRules[] = $this->cssGenerator->generate('.archive-header__title', [ 'color' => $titleColor, 'font-size' => $titleSize, 'font-weight' => $titleWeight, 'margin-bottom' => $titleMarginBottom, 'line-height' => '1.2', ]); // Prefix $prefixColor = $colors['prefix_color'] ?? '#6b7280'; $cssRules[] = $this->cssGenerator->generate('.archive-header__prefix', [ 'color' => $prefixColor, 'font-weight' => '400', ]); // Description $descColor = $colors['description_color'] ?? '#6b7280'; $descSize = $typography['description_size'] ?? '1rem'; $cssRules[] = $this->cssGenerator->generate('.archive-header__description', [ 'color' => $descColor, 'font-size' => $descSize, 'margin-top' => '0.5rem', 'line-height' => '1.6', ]); // Post count badge $countBgColor = $colors['count_bg_color'] ?? '#FF8600'; $countTextColor = $colors['count_text_color'] ?? '#ffffff'; $countSize = $typography['count_size'] ?? '0.875rem'; $countPadding = $spacing['count_padding'] ?? '0.25rem 0.75rem'; $cssRules[] = $this->cssGenerator->generate('.archive-header__count', [ 'background-color' => $countBgColor, 'color' => $countTextColor, 'font-size' => $countSize, 'padding' => $countPadding, 'border-radius' => '9999px', 'font-weight' => '500', 'display' => 'inline-block', 'margin-left' => '0.75rem', ]); return implode("\n", $cssRules); } private function buildHTML(array $data, string $visibilityClass): string { $content = $data['content'] ?? []; $typography = $data['typography'] ?? []; $headingLevel = $typography['heading_level'] ?? 'h1'; $showPostCount = $content['show_post_count'] ?? true; $showPostCount = $showPostCount === true || $showPostCount === '1' || $showPostCount === 1; $showDescription = $content['show_description'] ?? true; $showDescription = $showDescription === true || $showDescription === '1' || $showDescription === 1; // Get context-specific title and description $titleData = $this->getContextualTitle($content); $title = $titleData['title']; $prefix = $titleData['prefix']; $description = $showDescription ? $titleData['description'] : ''; // Get post count $postCount = $this->getPostCount(); $countSingular = $content['posts_count_singular'] ?? 'publicacion'; $countPlural = $content['posts_count_plural'] ?? 'publicaciones'; $countText = $postCount === 1 ? $countSingular : $countPlural; $containerClass = 'archive-header'; if (!empty($visibilityClass)) { $containerClass .= ' ' . $visibilityClass; } $html = sprintf('
%s
', esc_html($description) ); } $html .= '