import pluginConfig from 'config:@sanity/default-login'
import {versionedClient} from '../versionedClient'

export default function getProviders() {
  const config = pluginConfig || {}
  return versionedClient
    .request({
      uri: '/auth/providers',
      withCredentials: true,
    })
    .then((res) => {
      const {providers, thirdPartyLogin} = res
      const customProviders = (config.providers && config.providers.entries) || []
      if (customProviders.length === 0) {
        return providers
      }

      const custom = customProviders.map((provider) => {
        // A user may want to remove certain login options (eg GitHub) and thus provide "official"
        // login options through the config. These shouldn't be treated as custom login providers
        // which require the third-party login feature, but as the official provider
        const isOfficial = providers.some((official) => official.url === provider.url)
        return {...provider, custom: !isOfficial, supported: isOfficial || thirdPartyLogin}
      })

      if (config.providers.mode === 'replace') {
        return custom
      }

      // Append to the list of official providers, but replace any provider that has
      // the same URL with the custom one (allows customizing the title, name)
      return providers
        .filter((official) => custom.some((provider) => provider.url !== official.url))
        .concat(custom)
    })
}

@@ -344,16 +344,21 @@
 rtyLogin
+, sso
 %7D = res%0A
@@ -942,16 +942,129 @@
 er.url)%0A
+        const isSupported =%0A          isOfficial %7C%7C thirdPartyLogin %7C%7C (sso && Object.values(sso).some(Boolean))%0A
         
@@ -1122,35 +1122,17 @@
 : is
-Official %7C%7C thirdPartyLogin
+Supported
 %7D%0A  

add support for sso login providers