import { i18n, Translate } from "@gnu-taler/taler-util";
import { Fragment, h, VNode } from "preact";
import { CheckboxOutlined } from "../components/CheckboxOutlined";
import { ExchangeXmlTos } from "../components/ExchangeToS";
import {
  ButtonSuccess,
  ButtonWarning,
  LinkSuccess,
  TermsOfService,
  WarningBox,
  WarningText,
} from "../components/styled";
import { TermsState } from "../utils/index";
interface Props {
  reviewing: boolean;
  reviewed: boolean;
  terms: TermsState;
  onReview?: (b: boolean) => void;
  onAccept: (b: boolean) => void;
}
export function TermsOfServiceSection({
  reviewed,
  reviewing,
  terms,
  onAccept,
  onReview,
}: Props): VNode {
  if (!reviewing) {
    if (!reviewed) {
      if (!onReview) {
        return (
          
            {terms.status === "notfound" && (
              
                
                  
                    Exchange doesn't have terms of service
                  
                
              
            )}
          
        );
      }
      return (
        
          {terms.status === "notfound" && (
            
              
                
                  Exchange doesn't have terms of service
                
              
            
          )}
          {terms.status === "new" && (
            
               onReview(true)}>
                
                  Review exchange terms of service
                
              
            
          )}
          {terms.status === "changed" && (
            
               onReview(true)}>
                
                  Review new version of terms of service
                
              
            
          )}
        
      );
    }
    return (
      
        {onReview && (
          
             onReview(true)}>
              Show terms of service
            
          
        )}
        
          
                I accept the exchange terms of service
              
            }
            onToggle={() => {
              onAccept(!reviewed);
              if (onReview) onReview(false);
            }}
          />
        
      
    );
  }
  return (
    
      {terms.status !== "notfound" && !terms.content && (
        
          
            
              The exchange reply with a empty terms of service
            
          
        
      )}
      {terms.status !== "accepted" && terms.content && (
        
          {terms.content.type === "xml" && (
            
              
            
          )}
          {terms.content.type === "plain" && (
            
          )}
          {terms.content.type === "html" && (
            
          )}
          {terms.content.type === "pdf" && (
            
              Download Terms of Service
            
          )}
        
      )}
      {reviewed && onReview && (
        
           onReview(false)}>
            Hide terms of service
          
        
      )}
      {terms.status !== "notfound" && (
        
          
                I accept the exchange terms of service
              
            }
            onToggle={() => {
              onAccept(!reviewed);
              if (onReview) onReview(false);
            }}
          />
        
      )}
    
  );
}