BUG: groupby().agg() loses column names for an empty dataframe with 'idxmax' as an aggregation function
- [x] I have checked that this issue has not already been reported.

- [x] I have confirmed this bug exists on the latest version of pandas.

- [ ] (optional) I have confirmed this bug exists on the master branch of pandas.

---

**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) detailing how to provide the necessary information for us to reproduce your bug.

#### Code Sample, a copy-pastable example

```python
import pandas as pd

df = pd.DataFrame(columns=["id1", "id2", "time", "values"], dtype="int")


df_ok = df.groupby(["id1", "id2"]).sum()

print("Dataframe using .count() with groupby column names retained")
print(df_ok.index.names)


df_ok_2 = df.groupby(["id1", "id2"]).agg(**{
    "start": pd.NamedAgg(column="time", aggfunc="min"),
})

print()
print("Dataframe using aggfunc='min' with groupby columns retained")
print(df_ok_2.index.names)


df_bad = df.groupby(["id1", "id2"]).agg(**{
    "start": pd.NamedAgg(column="time", aggfunc="min"),
    "peak_time": pd.NamedAgg(column="values", aggfunc="idxmax")
})

print()
print("Dataframe using aggfunc='min' and aggfunc='idxmax' with groupby column names lost")
print(df_bad.index.names)


df_bad = df.groupby(["id1", "id2"]).agg(**{
    "peak_time": pd.NamedAgg(column="values", aggfunc="idxmax")
})

print()
print("Dataframe using only aggfunc='idxmax' with groupby columns lost entirely")
print(df_bad.index.names)
```

Output:
```
Dataframe using .count() with groupby column names retained
['id1', 'id2']

Dataframe using aggfunc='min' with groupby columns retained
['id1', 'id2']

Dataframe using aggfunc='min' and aggfunc='idxmax' with groupby column names lost
[None, None]

Dataframe using only aggfunc='idxmax' with groupby columns lost entirely
[None]
```

#### Problem description

The index returned by `DataFrame.groupby().agg()` is inconsistent depending on the aggregation applied to the groupby for an empty dataframe. This makes it difficult to use the output of these functions without adding subsequent if/else blocks to re-build the index names.

In the above examples, the provided DataFrame is empty. The behaviour of the returned DataFrames differs by how I handle the groupby:
1. If I use a function like .count(), the 'groupby' columns are both retained, and their names are kept, as I expect
2. If I use .agg() with 'min' as the function, the same good behaviour occurs
3. If I use .agg() with two functions, one being 'min' and the other 'idxmin', two index columns are returned but their names are lost, becoming 'level_0' and 'level_1'
4. If I use .agg() with only 'idxmin' as the function, only a single index column is returned, even though I grouped by two columns.

In Pandas 1.1.5, the third case behaved well, remembering the column names; the behaviour changed in 1.2.0.

#### Expected Output

The groupby columns and their names are remembered in all cases.

#### Output of ``pd.show_versions()``

<details>


INSTALLED VERSIONS
------------------
commit           : 7c48ff4409c622c582c56a5702373f726de08e96
python           : 3.8.6.final.0
python-bits      : 64
OS               : Linux
OS-release       : 3.10.0-1160.31.1.el7.x86_64
Version          : #1 SMP Tue Jun 15 10:20:52 CDT 2021
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_GB.UTF-8
LOCALE           : en_GB.UTF-8

pandas           : 1.2.5
numpy            : 1.19.4
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 21.1.3
setuptools       : 41.6.0
Cython           : None
pytest           : 6.2.4
hypothesis       : None
sphinx           : 3.5.4
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : 2.9.1 (dt dec pq3 ext lo64)
jinja2           : 3.0.1
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : 2021.06.0
fastparquet      : None
gcsfs            : None
matplotlib       : 3.4.2
numexpr          : None
odfpy            : None
openpyxl         : 3.0.7
pandas_gbq       : None
pyarrow          : 3.0.0
pyxlsb           : None
s3fs             : None
scipy            : 1.7.0
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : 0.53.1

</details>
