<?php declare(strict_types=1);

namespace App\Engine\Settings\Sections\Content;

/**
 * @extends \App\Engine\Settings\Sections\SettingsSection<\App\Engine\Settings\Sections\Content\HomeStaticBanners>
 */
readonly class HomeStaticBannersSettingsSection extends \App\Engine\Settings\Sections\SettingsSection
{

    public function getGroup(): \App\Engine\Settings\Groups
    {
        return \App\Engine\Settings\Groups::Content;
    }

    public function getPriority(): int
    {
        return 40;
    }

    public function getTitle(): string
    {
        return $this->translator->trans("admin.settings.sections.home-static-banners.section-title");
    }

    public function getId(): string
    {
        return "home-static-banners";
    }

    protected function getObjectClassName(): string
    {
        return \App\Engine\Settings\Sections\Content\HomeStaticBanners::class;
    }

    protected function processFormData(\Symfony\Component\Form\FormInterface $form, mixed $data): \Symfony\Component\Form\FormInterface
    {
        $this->storageUploader->processFile(
            $form,
            fieldName: "firstBannerImage",
            recordTitle: $data->firstBannerTitle,
            setFile: fn(string $imagePath) => $data->firstBannerImage = $imagePath,
            storageLocation: self::SETTINGS_STORAGE_LOCATION_PREFIX,
        );
        $this->storageUploader->processFile(
            $form,
            fieldName: "secondBannerImage",
            recordTitle: $data->secondBannerTitle,
            setFile: fn(string $imagePath) => $data->secondBannerImage = $imagePath,
            storageLocation: self::SETTINGS_STORAGE_LOCATION_PREFIX,
        );

        $data->firstBannerLink = \App\Engine\Utills\StringHelpers::sanitizeUrlAsAbsoulutePath($data->firstBannerLink); // Sanitizace URL.
        $data->secondBannerLink = \App\Engine\Utills\StringHelpers::sanitizeUrlAsAbsoulutePath($data->secondBannerLink); // Sanitizace URL.

        return \App\Engine\Settings\Sections\SettingsSection::processFormData($this->formFactory->create($this->getFormClassName(), $data), $data);
    }

    protected function getFormClassName(): string
    {
        return \App\Engine\Settings\Sections\Content\HomeStaticBannersForm::class;
    }

}