public function parsePalettes(
        array $palettes,
        array $subPaletteProperties = [],
        array $selectorFieldNames = [],
        PaletteCollectionInterface $collection = null
    ) {
        if (!$collection) {
            $collection = new PaletteCollection();
        }

        if (isset($palettes['__selector__'])) {
            $selectorFieldNames = \array_merge($selectorFieldNames, $palettes['__selector__']);
            $selectorFieldNames = \array_unique($selectorFieldNames);
            unset($palettes['__selector__']);
        }

        foreach ($palettes as $selector => $fields) {
            // Fields list must be a string.
            if (!\is_string($fields)) {
                continue;
            }

            if ($collection->hasPaletteByName($selector)) {
                $palette = $collection->getPaletteByName($selector);
                $this->parsePalette(
                    $selector,
                    $fields,
                    $subPaletteProperties,
                    $selectorFieldNames,
                    $palette
                );

                continue;
            }

            $palette = $this->parsePalette(
                $selector,
                $fields,
                $subPaletteProperties,
                $selectorFieldNames
            );
            $collection->addPalette($palette);
        }

        return $collection;
    }