<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class Blocks extends JsonResource
{
    /**
     * Accesses constructor.
     * @param $resource
     */
    public function __construct($resource)
    {
        $this->resource = $resource;
    }

    public function toArray($request)
    {
        $out = [
            'id' => (int)$this->id,
            'type' => $this->type,
            'slug' => $this->lang_slug
        ];

        // Specific block data per type
        $out = array_merge($out, $this->_getBlockData());

        return $out;
    }

    private function _getBlockData()
    {
        $out = [];
        switch ($this->type) {
            case 'blockWysiwyg':
                $out = $this->_getBlockWysiwyg();
                break;
            case 'blockTwoColumnsWysiwyg':
                $out = $this->_getBlockTwoColumnsWysiwyg();
                break;
            case 'blockCardItems':
            case 'blockFeaturedCards':
            case 'blockContactCards':
                $out = $this->_getBlockCardItems();
                break;
            case 'blockHomeHero':
                $out = $this->_getBlockHomeHero();
                break;
            case 'blockMixedMedia':
                $out = $this->_getBlockMixedMedia();
                break;
            case 'blockTimeline':
                $out = $this->_getBlockTimeline();
                break;
            case 'blockTextCards':
                $out = $this->_getBlockTextCards();
                break;
            case 'blockPageTitle':
                $out = $this->_getBlockPageTitle();
                break;
            case 'blockMixedMediaSimple':
                $out = $this->_getBlockMixedMediaSimple();
                break;
            case 'blockBanner':
                $out = $this->_getBlockBanner();
                break;
            case 'blockTwoColumnText':
                $out = $this->_getBlockTwoColumnText();
                break;
            case 'blockTeamMembers':
                $out = $this->_getBlockTeamMembers();
                break;
            case 'blockSimpleImageHero':
                $out = $this->_getBlockSimpleImageHero();
                break;
            case 'blockHighlightDocuments':
                $out = $this->_getBlockHighlightDocuments();
                break;
            case 'blockDocumentList':
                $out = $this->_getBlockDocumentList();
                break;
            case 'blockClausesSearch':
                $out = $this->_getBlockClausesSearch();
                break;
            case 'blockSlider':
                $out = $this->_getBlockSlider();
                break;
            case 'blockImageFull':
                $out = $this->_getBlockImageFull();
                break;
            case 'blockEventList':
                $out = $this->_getBlockEventList();
                break;
            case 'blockMembers':
            case 'blockPressReleaseList':
            case 'blockStaticDataTableList':
            case 'blockUpcomingEvents':
                $out = $this->_getBlockPlaceholder();
                break;
            case 'blockAccordion':
                $out = $this->_getBlockAccordion();
                break;
            case 'blockFeatures':
                $out = $this->_getBlockFeatures();
                break;
            case 'blockFormEIC':
                $out = $this->_getBlockFormEIC();
                break;
            case 'blockFormEventRegistration':
                $out = $this->_getBlockFormEventRegistration();
                break;
            case 'blockMasterclass26Registration':
                $out = $this->_getBlockFormEventRegistration();
                break;
            case 'blockPageLinks':
                $out = $this->_getBlockPageLinks();
                break;
            case 'blockHomeSliderHero':
                $out = $this->_getBlockHomeSliderHero();
                break;
            case 'blockHomeSliderNews':
                $out = $this->_getBlockHomeSliderNews();
                break;
            case 'blockHomePathEnergy':
                $out = $this->_getBlockHomePathEnergy();
                break;
            case 'blockHomeFullBanner':
                $out = $this->_getBlockHomeFullBanner();
                break;
            case 'blockHomeJoin':
                $out = $this->_getBlockHomeJoin();
                break;
            case 'blockHomeJoinV2':
                $out = $this->_getBlockHomeJoinV2();
                break;
            case 'blockInjectCode':
                $out = $this->_getBlockInjectCode();
                break;
            case 'blockVideo':
                $out = $this->_getBlockVideo();
                break;
            case 'blockForm':
                $out = $this->_getBlockForm();
                break;
            case 'blockImageGallery':
                $out = $this->_getBlockImageGallery();
                break;
            case 'blockImageGrid':
                $out = $this->_getBlockImageGrid();
                break;
            case 'blockVideoList':
                $out = $this->_getBlockPlaceholder();
                break;
            case 'blockProgressTracker':
                $out = $this->_getBlockProgressTracker();
                break;
            case 'blockNewsTickerSlider':
                $out = $this->_getBlockNewsTickerSlider();
                break;
        }
        return $out;
    }

    /**************
     * Helpers
     **************/

    private function _getCardItems($cardItems = NULL)
    {
        if ($cardItems) {
            $out = [];
            foreach ($cardItems as $cardItem) {
                $item = [
                    'title' => $cardItem->title,
                    'description' => $cardItem->description,
                    'subtitle' => $cardItem->subtitle,
                    'cta' => resolve_link($cardItem->cta),
                    'image' => getImage($cardItem->image, ['56x56', '112x112']),
                    'image2' => getImage($cardItem->image2, ['56x56', '112x112']),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getForm($form = NULL)
    {
        if ($form) {
            return [
                'id' => $form->id,
                'title' => $form->title,
                'slug' => $form->slug,
                'description' => $form->description,
                'contactEmail' => $form->resolveContactEmail(),
                'sections' => $this->_getFormSections($form->formSections),
            ];
        }

        return null;
    }

    private function _getFormSections($sections = NULL)
    {
        if ($sections) {
            $out = [];
            foreach ($sections as $section) {
                $item = [
                    'id' => $section->id,
                    'title' => $section->title,
                    'description' => $section->description,
                    'fields' => $this->_getFormFields($section->formFields),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getFormFields($fields = NULL)
    {
        if ($fields) {
            $out = [];
            foreach ($fields as $field) {
                $item = [
                    'id' => $field->id,
                    'title' => $field->title,
                    'label' => $field->label,
                    'fieldType' => $field->field_type,
                    'isMandatory' => $field->is_mandatory,
                    'layout' => $field->layout,
                    'conditionalFieldDependentId' => $field->conditional_field_dependent_id,
                    'options' => $this->_getFormFieldsOptions($field->fieldOptions),
                    'memberOptions' => $field->field_type === 'members' ? $this->_getMemberOptions($field->getMembers()) : [],
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getMemberOptions($members = NULL)
    {
        if ($members) {
            $out = [];
            foreach ($members as $member) {
                $item = [
                    'id'          => $member->id,
                    'companyName' => $member->title,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return [];
        }
    }

    private function _getFormFieldsOptions($options = NULL)
    {
        if ($options) {
            $out = [];
            foreach ($options as $option) {
                $item = [
                    'id' => $option->id,
                    'title' => $option->title,
                    'label' => $option->label,
                    'value' => $option->value,
                    'conditionalFieldParentId' => $option->conditional_field_parent_id,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getTimelineCards($timelineCards = NULL)
    {
        if ($timelineCards) {
            $out = [];
            foreach ($timelineCards as $timelineCard) {
                $item = [
                    'year' => $timelineCard->title,
                    'description' => $timelineCard->description,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getTextCards($textCards = NULL)
    {
        if ($textCards) {
            $out = [];
            foreach ($textCards as $textCard) {
                $item = [
                    'title' => $textCard->title,
                    'subtitle' => $textCard->subtitle,
                    'description' => $textCard->description,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getFileCards($fileCards = NULL)
    {
        if ($fileCards) {
            $out = [];
            foreach ($fileCards as $fileCard) {
                $item = [
                    'title' => $fileCard->title,
                    'subtitle' => $fileCard->subtitle,
                    'description' => $fileCard->description,
                    'document'  => !empty($fileCard->document) ? getMediaUrl($fileCard->document->filename) : '',
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getAccordionItems($accordionItems = NULL)
    {
        if ($accordionItems) {
            $out = [];
            foreach ($accordionItems as $accordionItem) {
                $item = [
                    'title' => $accordionItem->title,
                    'items' => $this->_getFileCards($accordionItem->fileCards),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getTeamMembers($teamMembers = NULL)
    {
        if ($teamMembers) {
            $out = [];
            foreach ($teamMembers as $teamMember) {
                $item = [
                    'id' => $teamMember->id,
                    'title' => $teamMember->title,
                    'firstName' => $teamMember->first_name,
                    'lastName' => $teamMember->last_name,
                    'phoneNumber' => $teamMember->phone_number,
                    'email' => $teamMember->email,
                    'role' => $teamMember->role,
                    'nationality' => $teamMember->nationality,
                    'location' => $teamMember->location,
                    'areaResponsibility' => $teamMember->area_responsibility,
                    'linkedin' => $teamMember->linkedin,
                    'twitter' => $teamMember->twitter,
                    'company' => $teamMember->company,
                    'image' => getImage($teamMember->image, ['232x260', '464x519']),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getDocumentType($documentType = NULL)
    {
        if (!empty($documentType)) {
            return (object)[
                'id' => $documentType->id,
                'title' => $documentType->title,
            ];
        }

        return (object)[];
    }

    private function _getTopic($topic = NULL)
    {
        if (!empty($topic)) {
            return (object)[
                'id' => $topic->id,
                'title' => $topic->title,
            ];
        }

        return (object)[];
    }

    private function _getTopics($topics = NULL)
    {
        if ($topics) {
            $out = [];
            foreach ($topics as $topic) {
                $item = [
                    'id' => $topic->id,
                    'title' => $topic->title,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return [];
        }
    }

    private function _getLinks($links = NULL)
    {
        if ($links) {
            $out = [];
            foreach ($links as $link) {
                $item = [
                    'id' => $link->id,
                    'title' => $link->title,
                    'cta' => resolve_link($link->cta),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getTags($tags = NULL)
    {
        if ($tags) {
            $out = [];
            foreach ($tags as $tag) {
                $item = [
                    'id' => $tag->id,
                    'title' => $tag->title,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getCountry($country = NULL)
    {
        if (!empty($country)) {
            return (object)[
                'id' => $country->id,
                'title' => $country->title,
                'code' => $country->code,
                'image' => getImage($country->flag, ['160x88', '80x44']),
            ];
        }

        return (object)[];
    }

    private function _getDocuments($documents = NULL)
    {
        if ($documents) {
            $out = [];
            foreach ($documents as $document) {
                $item = [
                    'title' => $document->title,
                    'description' => $document->description,
                    'publishDate' => !empty($document->publish_date) ? Carbon::parse($document->publish_date)->format('d-m-Y') : '',
                    'expirationDate' => !empty($document->expiration_date) ? Carbon::parse($document->expiration_date)->format('d-m-Y') : '',
                    'image' => getImage($document->image, ['w400', 'w800']),
                    'document'  => !empty($document->documentFile) ? getMediaUrl($document->documentFile->filename) : '',
                    'documentType' => $this->_getDocumentType($document->documentType),
                    'topics' => $this->_getTopics($document->topics),
                    'tags' => $this->_getTags($document->tags),
                    'country' => $this->_getCountry($document->country),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getSliderItems($slides = NULL, $sizes = [])
    {
        if ($slides) {
            $out = [];
            foreach ($slides as $slide) {
                $item = [
                    'title' => $slide->title,
                    'type' => $slide->type,
                    'image' => getImage($slide->image, $sizes),
                    'video' => $slide->video,
                    'description' => $slide->description,
                    'cta' => resolve_link($slide->cta),
                    'position' => $slide->position,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getVideoItems($videos = NULL)
    {
        if ($videos) {
            $out = [];
            foreach ($videos as $video) {
                $item = [
                    'title' => $video->title,
                    'type' => $video->type,
                    'localVideo' => $video->video,
                    'externalVideo' => $video->external_video,
                    'date' => !empty($video->date) ? Carbon::parse($video->date)->format('d-m-Y') : '',
                    'image' => getImage($video->image, ['w1920', 'w840']),
                    'topic' => $this->_getTopic($video->topic),
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getImageItems($images = NULL, $sizes = [])
    {
        if ($images) {
            $out = [];
            foreach ($images as $image) {
                $item = [
                    'title' => $image->title,
                    'image' => getImage($image->image, $sizes),
                    'caption' => $image->caption,
                    'isDownloadable' => $image->is_downloadable,
                ];

                $out[] = $item;
            }

            return $out;
        } else {
            return (object)[];
        }
    }

    /**************
     * Blocks
     **************/

    private function _getBlockWysiwyg(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->block_title,
            'text' => $this->wysiwyg,
            'pictureVariable' => $this->picture_variable,
        ];
    }

    private function _getBlockTwoColumnsWysiwyg(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->block_title,
            'text' => $this->wysiwyg,
            'textTwo' => $this->wysiwyg_2,
        ];
    }

    private function _getBlockCardItems(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'items' => $this->_getCardItems($this->cardItems),
        ];
    }

    private function _getBlockHomeHero(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'content' => $this->wysiwyg,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'imageMobile' => getImage($this->imageMobile, ['w840']),
        ];
    }

    private function _getBlockMixedMedia(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'date' => !empty($this->date) ? Carbon::parse($this->date)->format('d-m-Y') : '',
            'content' => $this->wysiwyg,
            'cta' => resolve_link($this->cta),
            'image' => getImage($this->image, ['w1000', 'w500']),
            'imageMobile' => getImage($this->imageMobile, ['w500']),
            'align' =>  $this->align,
            'document'  => !empty($this->document) ? getMediaUrl($this->document->filename) : '',
        ];
    }

    private function _getBlockMixedMediaSimple(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'content' => $this->wysiwyg,
            'cta' => resolve_link($this->cta),
            'image' => getImage($this->image, ['w1366', 'w683']),
            'imageMobile' => getImage($this->imageMobile, ['w683']),
        ];
    }

    private function _getBlockTimeline(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'items' => $this->_getTimelineCards($this->timelineCards),
        ];
    }

    private function _getBlockTextCards(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'items' => $this->_getTextCards($this->textCards),
        ];
    }

    private function _getBlockAccordion(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'items' => $this->_getAccordionItems($this->accordionItems),
        ];
    }

    private function _getBlockFeatures(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'topic' => $this->_getTopic($this->topic),
            'cta' => resolve_link($this->cta),
        ];
    }

    private function _getBlockPageLinks(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'items' => $this->_getLinks($this->links),
        ];
    }

    private function _getBlockFormEIC(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
        ];
    }

    private function _getBlockImageGallery(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'items' => $this->_getImageItems($this->imageGallery, ['w1920', 'w840']),
        ];
    }

    private function _getBlockVideoList(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'items' => $this->_getVideoItems($this->videoList),
        ];
    }

    private function _getBlockImageGrid(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'items' => $this->_getImageItems($this->imageGallery, ['w840']),
        ];
    }

    private function _getBlockFormEventRegistration(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
        ];
    }

    private function _getBlockPageTitle(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
        ];
    }

    private function _getBlockBanner(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'cta' => resolve_link($this->cta),
            'size' => $this->size,
            'date' => !empty($this->date) ? Carbon::parse($this->date)->format('d-m-Y') : '',
            'document'  => !empty($this->document) ? getMediaUrl($this->document->filename) : '',
        ];
    }

    private function _getBlockTwoColumnText(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'content' => $this->wysiwyg,
        ];
    }

    private function _getBlockTeamMembers(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'bgColor' => $this->bg_color,
            'position' => $this->position,
            'items' => $this->_getTeamMembers($this->teamMembers),
        ];
    }

    private function _getBlockSimpleImageHero(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'imageMobile' => getImage($this->imageMobile, ['w840']),
        ];
    }

    private function _getBlockHighlightDocuments(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'items' => $this->_getDocuments($this->documents),
        ];
    }

    public function _getBlockDocumentList(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'topic' => $this->_getTopic($this->topic),
            'documentType' => $this->_getDocumentType($this->documentType),
        ];
    }

    public function _getBlockClausesSearch(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'content' => $this->wysiwyg,
        ];
    }

    public function _getBlockSlider(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'items' => $this->_getSliderItems($this->slider, ['w1920', 'w840']),
        ];
    }

    public function _getBlockImageFull(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'imageMobile' => getImage($this->imageMobile, ['w840']),
        ];
    }

    public function _getBlockEventList(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'filterTime' => $this->filter_time,
        ];
    }

    public function _getBlockPlaceholder(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
        ];
    }

    public function _getBlockHomeSliderHero(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'items' => $this->_getSliderItems($this->slider, ['w1920', 'w840']),
        ];
    }

    public function _getBlockHomeSliderNews(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'items' => $this->_getSliderItems($this->slider, ['768x640', '384x320']),
        ];
    }

    public function _getBlockHomePathEnergy(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'content' => $this->wysiwyg,
            'items' => $this->_getCardItems($this->cardItems),
        ];
    }

    public function _getBlockHomeFullBanner(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'subtitle' => $this->subtitle,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'imageMobile' => getImage($this->imageMobile, ['w840']),
            'cta' => resolve_link($this->cta),
        ];
    }

    public function _getBlockHomeJoin(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'subtitle' => $this->subtitle,
            'image' => getImage($this->image, ['580x730', '290x367']),
            'image2' => getImage($this->image2, ['580x730', '290x367']),
            'cta' => resolve_link($this->cta),
            'cta2' => resolve_link($this->cta_2),
        ];
    }

    public function _getBlockHomeJoinV2(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'cta' => resolve_link($this->cta),
            'cta2' => resolve_link($this->cta_2),
        ];
    }

    public function _getBlockInjectCode(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'textCode' => $this->text_code,
        ];
    }

    public function _getBlockVideo(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'videoUrl' => $this->videoUrl,
            'videoMedia'  => !empty($this->video) ? getMediaUrl($this->video->filename) : '',
        ];
    }

    public function _getBlockForm(): array
    {
        return [
            'blockTitle' => $this->block_title,
            'title' => $this->title,
            'formId' => $this->form_id,
            'form' => $this->_getForm($this->form),
        ];
    }

    private function _getBlockProgressTracker(): array
    {
        return [
            'title' => $this->title,
            'titleWysiwyg' => $this->wysiwyg,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'trackerCategories' => $this->_getTrackerCategories($this->trackerCategories),
        ];
    }

    private function _getTrackerCategories($trackerCategories = NULL)
    {
        if ($trackerCategories) {
            $out = [];
            foreach ($trackerCategories as $category) {
                $item = [
                    'id' => $category->id,
                    'title' => $category->title,
                    'color' => $category->color,
                    'percentage' => $category->percentage,
                    'trackerActions' => $this->_getTrackerActions($category->trackerActions),
                ];
                $out[] = $item;
            }
            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getTrackerActions($trackerActions = NULL)
    {
        if ($trackerActions) {
            $out = [];
            foreach ($trackerActions as $action) {
                $item = [
                    'id' => $action->id,
                    'title' => $action->title,
                    'year' => $action->year,
                    'anchor' => $action->anchor,
                    'percentage' => $action->percentage,
                    'action_status' => $action->action_status ?? 'not_started',
                    'progress_status' => $action->progress_status ?? 'on_target',
                    'types' => array_values(array_filter([
                        $action->getAttributes()['type_gas'] ? 'gas' : null,
                        $action->getAttributes()['type_power'] ? 'power' : null,
                        $action->getAttributes()['type_carbon'] ? 'carbon' : null,
                        $action->getAttributes()['type_simplification'] ? 'simplification' : null,
                    ])),
                ];
                $out[] = $item;
            }
            return $out;
        } else {
            return (object)[];
        }
    }

    private function _getblockNewsTickerSlider(): array
    {
        return [
            'title' => $this->title,
            'titleWysiwyg' => $this->wysiwyg,
            'image' => getImage($this->image, ['w1920', 'w840']),
            'cta' => resolve_link($this->cta),
            'autoplay' => $this->autoplay ?? false,
            'layout' => $this->layout ?? 'default',
            'newsTickerSliderItems' => $this->_getNewsTickerSliderItems($this->newsTickerSliderItems),
        ];
    }

    private function _getNewsTickerSliderItems($newsTickerSliderItems = NULL)
    {
        if ($newsTickerSliderItems) {
            $out = [];
            foreach ($newsTickerSliderItems as $item) {
                $out[] = [
                    'id' => $item->id,
                    'title' => $item->title,
                    'description' => $item->description,
                    'image' => getImage($item->image, ['w400', 'w840']),
                    'status_badge' => $item->status_badge ?? null,
                    'color' => $item->color ?? null,
                    'types' => array_values(array_filter([
                        $item->getAttributes()['type_gas'] ? 'gas' : null,
                        $item->getAttributes()['type_power'] ? 'power' : null,
                        $item->getAttributes()['type_carbon'] ? 'carbon' : null,
                        $item->getAttributes()['type_simplification'] ? 'simplification' : null,
                    ])),
                    'date' => !empty($item->date) ? Carbon::parse($item->date)->format('d-m-Y') : '',
                    'cta' => resolve_link($item->cta),
                    'show_button_option' => $item->show_button_option ?? false,
                ];
            }
            return $out;
        } else {
            return (object)[];
        }
    }
}
