import React, {useContext} from 'react';
import {
Divider,
Input,
Label,
SegmentGroup,
StatisticLabel,
StatisticValue,
TableCell,
TableRow
} from "semantic-ui-react";
import {Link, Route, Routes} from "react-router";
import {decryptOTP, encryptOTP} from "../api";
import {
APIButton,
ErrorMessage,
humanFileSize,
humanNumber,
mimetypeColor,
PageContainer,
toLocaleString,
useTitle
} from "./Common";
import {ThemeContext} from "../contexts/contexts";
import {Button, Header, Loader, Segment, Statistic, Table, TextArea} from "./Theme";
import {useStatistics, useVINDecoder} from "../hooks/customHooks";
import {CalculatorsPage} from "./Calculators";
class Encrypt extends React.Component {
constructor(props) {
super(props);
this.state = {
otp: '', plaintext: '', ciphertext: '',
}
}
handleSubmit = async () => {
let {otp, plaintext, ciphertext} = await encryptOTP(this.state.otp, this.state.plaintext);
this.setState({otp, plaintext, ciphertext});
}
handleInputChange = async (event, {name, value}) => {
this.setState({[name]: value});
}
render() {
const disabled = !(this.state.otp && this.state.plaintext);
return <>
Key
Plaintext
Ciphertext
{this.state.ciphertext || 'Enter your message above'}
Encrypt
>
}
}
class Decrypt extends React.Component {
constructor(props) {
super(props);
this.state = {
otp: '', plaintext: '', ciphertext: ''
}
}
handleSubmit = async () => {
let {otp, plaintext, ciphertext} = await decryptOTP(this.state.otp, this.state.ciphertext);
this.setState({otp, plaintext, ciphertext});
}
handleInputChange = async (event, {name, value}) => {
this.setState({[name]: value});
}
render() {
const disabled = !(this.state.otp && this.state.ciphertext);
return <>
Key
Ciphertext
Plaintext
{this.state.plaintext || 'Enter the encrypted message above'}
Decrypt
>
}
}
function OTP() {
useTitle('One Time Pad');
const {t} = useContext(ThemeContext);
let newPadURL = `https://${window.location.host}/api/otp/html`;
let cheatSheetURL = `${process.env.PUBLIC_URL}/one-time-pad-cheat-sheet.pdf`;
return <>
One-Time Pads can be used to encrypt your communications. This can be done by hand
(yes, really) or in this app.
These messages are never stored and cannot be retrieved.
Generate New Pad
Cheat Sheet PDF
>
}
function VINDecoder() {
useTitle('VIN Number Decoder');
const {t} = useContext(ThemeContext);
const basicKeys = ['Country', 'Manufacturer', 'Region', 'Years'];
const detailsKeys = ['Body', 'Engine', 'Model', 'Plant', 'Transmission', 'Serial'];
const {value, setValue, vin} = useVINDecoder();
console.debug(vin);
let body = Enter a VIN number above
;
if (value && !vin) {
body = VIN number is invalid
;
}
if (vin && vin['country']) {
let details = No details
;
if (vin['body']) {
details =
{detailsKeys.map(i =>
{i}
{vin[i.toLowerCase()] || '(Unknown)'}
)}
;
}
body = <>
{basicKeys.map(i =>
{i}
{vin[i.toLowerCase()]}
)}
{details}
>;
}
return <>
setValue(e.target.value)}
/>
{body}
>
}
function StatisticsPage() {
useTitle('Statistics');
const {s} = useContext(ThemeContext);
const {statistics} = useStatistics();
if (statistics === undefined) {
return <>
Failed to fetch statistics
>
}
if (statistics['global_statistics']) {
let {global_statistics, file_statistics} = statistics;
const {
archive_count,
audio_count,
ebook_count,
image_count,
pdf_count,
total_count,
video_count,
zip_count,
total_size,
tagged_files,
tagged_zims,
tags_count,
} = file_statistics;
const {db_size} = global_statistics;
return <>
{toLocaleString(total_count)}
All Files
{humanFileSize(total_size)}
Total Size
{toLocaleString(video_count)}
Videos
{toLocaleString(pdf_count)}
PDFs
{toLocaleString(ebook_count)}
eBooks
{toLocaleString(archive_count)}
Archives
{toLocaleString(image_count)}
Images
{toLocaleString(zip_count)}
ZIP
{toLocaleString(audio_count)}
Audio
{humanNumber(tags_count)}
Tags
{humanNumber(tagged_files)}
Tagged Files
{humanNumber(tagged_zims)}
Tagged Zims
{humanFileSize(db_size)}
Size
>;
}
return <>
>;
}
export function MoreRoute(props) {
return
}/>
}/>
}/>
}/>
}
export function ColoredInput({name, value, label, color, ...props}) {
label = label ? {label} : null;
return
}