<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Form\Type;

use MauticPlugin\DealFlowBundle\Entity\PipelineRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;

class DashboardDealFlowWidgetType extends AbstractType
{
    public function __construct(
        private readonly PipelineRepository $pipelineRepository,
    ) {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $pipelines = $this->pipelineRepository->findBy([], ['id' => 'ASC']);
        $choices = [];
        foreach ($pipelines as $pipeline) {
            $choices[$pipeline->getName()] = $pipeline->getId();
        }

        $builder->add(
            'pipeline_id',
            ChoiceType::class,
            [
                'label' => 'Pipeline',
                'choices' => $choices,
                'label_attr' => ['class' => 'control-label'],
                'attr' => ['class' => 'form-control'],
                'placeholder' => 'Default pipeline',
                'required' => false,
                'empty_data' => '',
            ]
        );
    }

    public function getBlockPrefix(): string
    {
        return 'dealflow_dashboard_widget';
    }
}
