'use client'

import type { WebhookEndpointListItem } from '@admin/actions/webhooks'
import { Switch } from '@admin/components/ui/switch'
import { useToggleWebhookEnabled } from '@admin/hooks/use-webhooks'

export function WebhookEnabledSwitch({ webhook }: { webhook: WebhookEndpointListItem }) {
  const toggleEnabled = useToggleWebhookEnabled()

  return (
    <Switch
      checked={webhook.enabled}
      disabled={toggleEnabled.isPending}
      onCheckedChange={(checked) => toggleEnabled.mutate({ id: webhook.id, enabled: checked })}
      aria-label={`Toggle ${webhook.name}`}
    />
  )
}
