// CF Workers version of contexts/session.ts
// Uses real DID Connect session with proper cookie settings for HTTPS
import createSessionContext from '@arcblock/did-connect-react/lib/Session';
import { useContext } from 'react';

const { SessionProvider, SessionContext, SessionConsumer, withSession } = createSessionContext(
  'login_token',
  'cookie',
  { path: '/', secure: true, sameSite: 'Lax', returnDomain: false },
  { appendAuthServicePrefix: false }
);

function useSessionContext() {
  const ctx = useContext<any>(SessionContext);
  if (!ctx) return ctx;
  return {
    session: ctx.session,
    connectApi: ctx.connectApi,
    events: ctx.events,
    ...ctx.session,
  };
}

export { SessionProvider, SessionContext, SessionConsumer, useSessionContext, withSession };
