public static function setGroups(HTMLFactoryInterface $factory, HTMLElement $select, $groups = [], $checkedValue = null)
    {
        foreach ($groups as $data) {
            $label = $data['label'];
            $options = $data['options'];

            // Build group
            $group = $factory->buildHtmlElement('optgroup', '', '', '', [
                'label' => $label,
            ]);

            // Add options to group
            self::setOptions($factory, $group, $options, $checkedValue);

            // Append group to container
            $factory->getHTMLHandler()->append($select, $group);
        }
    }