private function orderFields(array $fields, array $fieldProperties, array $showFields = null): array
    {
        $originalFields = $fields['fields'];
        $desiredFieldsOrder = $fields['section']['fields'];
        $desiredFieldsOrderFiltered = [];

        if (!is_null($showFields)) {
            foreach ($desiredFieldsOrder as $fieldHandle) {
                $propertyName = $this->handleToPropertyName($fieldHandle, $fieldProperties);
                if (in_array($propertyName, $showFields)) {
                    $desiredFieldsOrderFiltered[] = $propertyName;
                }
            }
        } else {
            $desiredFieldsOrderFiltered = $desiredFieldsOrder;
        }

        $originalFieldsOrder = [];
        $result = [];

        foreach ($originalFields as $field) {
            $handle = array_keys($field)[0];
            if (is_null($showFields) || in_array($handle, $showFields)) {
                $originalFieldsOrder[] = $handle;
            }
        }

        foreach ($desiredFieldsOrderFiltered as $handle) {
            if (is_null($showFields) || in_array($handle, $showFields)) {
                $fieldIndex = array_search($handle, $originalFieldsOrder);
                if ($fieldIndex !== false) {
                    $result[] = $originalFields[$fieldIndex];
                }
            }
        }

        return $result;
    }