// Copyright 2026 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { JSX } from 'react';

import { openLinkInWebBrowser } from '../util/openLinkInWebBrowser.dom.ts';
import { KEY_TRANSPARENCY_URL } from '../types/support.std.ts';
import type { LocalizerType } from '../types/I18N.std.ts';
import { AxoDialog } from '../axo/AxoDialog.dom.tsx';
import { tw } from '../axo/tw.dom.tsx';

export type KeyTransparencyOnboardingDialogProps = Readonly<{
  i18n: LocalizerType;
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onContinue: () => void;
}>;

function openKeyTransparencyUrl() {
  openLinkInWebBrowser(KEY_TRANSPARENCY_URL);
}

export function KeyTransparencyOnboardingDialog(
  props: KeyTransparencyOnboardingDialogProps
): JSX.Element {
  const { i18n, open, onOpenChange, onContinue } = props;

  return (
    <AxoDialog.Root open={open} onOpenChange={onOpenChange}>
      <AxoDialog.Content escape="cancel-is-noop" size="sm">
        <AxoDialog.Header>
          <AxoDialog.Close />
        </AxoDialog.Header>
        <AxoDialog.Body>
          <div className={tw('mt-1.5 mb-3 flex items-center justify-center')}>
            <img
              className={tw('dark:hidden')}
              src="images/key-transparency-light.svg"
              height="110"
              width="110"
              alt=""
            />
            <img
              src="images/key-transparency-dark.svg"
              className={tw('hidden dark:inline')}
              height="110"
              width="110"
              alt=""
            />
          </div>
          <h3 className={tw('mt-6 mb-3 type-title-medium font-semibold')}>
            {i18n('icu:KeyTransparencyOnboardingDialog__Title')}
          </h3>
          <AxoDialog.Description>
            <div className={tw('mb-5 type-body-large text-secondary')}>
              {i18n('icu:KeyTransparencyOnboardingDialog__Description')}
            </div>
          </AxoDialog.Description>
        </AxoDialog.Body>
        <AxoDialog.Footer>
          <AxoDialog.Actions>
            <AxoDialog.Action
              variant="strong-secondary"
              onClick={openKeyTransparencyUrl}
            >
              {i18n('icu:KeyTransparencyOnboardingDialog__LearnMore')}
            </AxoDialog.Action>
            <AxoDialog.Action variant="strong-primary" onClick={onContinue}>
              {i18n('icu:KeyTransparencyOnboardingDialog__Continue')}
            </AxoDialog.Action>
          </AxoDialog.Actions>
        </AxoDialog.Footer>
      </AxoDialog.Content>
    </AxoDialog.Root>
  );
}
