---
import ContactUs from 'components/widgets/Contact.astro';
import CallToAction from 'components/widgets/CallToAction.astro';

const pb = Astro.locals.pb
const oauths = (await pb.collection('users').listAuthMethods()).authProviders;
const discordProvider = oauths.find(item => item.name === 'discord');
const googleProvider = oauths.find(item => item.name === 'google');

---

<>
<CallToAction
actions={[
  {
    variant: 'primary',
    text: 'Discord',
    href: discordProvider!.authUrl + Astro.url.protocol + "//" + Astro.url.host + '/account/oauth',
    icon: 'tabler:brand-discord',
    class: "oauth-btn",
    "data-cookie": encodeURIComponent(JSON.stringify(discordProvider))
  },
  {
    variant: 'primary',
    text: 'Google',
    href: googleProvider!.authUrl + Astro.url.protocol + "//" + Astro.url.host + '/account/oauth',
    icon: 'tabler:brand-google',
    class: "oauth-btn",
    "data-cookie": encodeURIComponent(JSON.stringify(googleProvider))
  }
]}
>
<Fragment slot="title">
  Oauth
</Fragment>

<Fragment slot="subtitle">
  Connecter Vous aussi avec
</Fragment>
</CallToAction>
</>

<script>
// import { date } from "astro/zod";

  document.cookie = "provider" + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  // console.log(date.toString)

  const btn = document.querySelectorAll('.oauth-btn')
  btn.forEach((item: Element) =>(item.addEventListener('click', (ev) =>{
    document.cookie = "provider" + "=" + item.getAttribute('data-cookie') + "; path=/;"// expires=" + ;
  })))
</script>
