protected function getSelectedChoices(array $values, $value = null)
    {
        $structuredValues = $this->loadChoiceList($value)->getStructuredValues();
        $values = $this->forceStringValues($values);
        $allChoices = [];
        $choices = [];
        $isGrouped = false;

        foreach ($structuredValues as $group => $choice) {
            // group
            if (\is_array($choice)) {
                $isGrouped = true;
                foreach ($choice as $choiceKey => $choiceValue) {
                    if ($this->allChoices || \in_array($choiceValue, $values)) {
                        $choices[$group][$choiceKey] = $choiceValue;
                        $allChoices[$choiceKey] = $choiceValue;
                    }
                }
            } elseif ($this->allChoices || \in_array($choice, $values)) {
                $choices[$group] = $choice;
                $allChoices[$group] = $choice;
            }
        }

        if ($this->isAllowAdd()) {
            $choices = $this->addNewTagsInChoices($choices, $allChoices, $values, $isGrouped);
        }

        return (array) $choices;
    }