def complex_vlass(df, NN_dist=72, SNR_min=None):
    """Algorithm to select complex VLASS components.

    Args:
        df ([pandas.DataFrame]): Table of VLASS components.
        NN_dist ([float]], optional): Maximum distance (in arcsec) to the nearest component to be considered complex. Defaults to 72.
        SNR_min ([float]], optional): Minimum signal-to-noise of the component. Defaults to None.

    Returns:
        pandas.DataFrame: Subset of the input DataFrame containing only the complex components.
    """
    mask = (df["S_Code"] == "S") & (df["NN_dist"] < NN_dist)
    mask |= df["S_Code"] == "M"
    mask |= df["S_Code"] == "C"
    df = df[mask]

    if SNR_min is not None:
        df = df[df["SNR"] >= SNR_min]

    return df