import React from 'react';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
import BootstrapInput from '../Misc/BootstrapInput'
import Checkbox from '../Misc/Checkbox';
import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';
const { sprintf, __ } = wp.i18n;
const Postmark = props => {
let savedState = {
api_key: props.settings.postmark_server_api,
}
const [formValues, setFormValues] = React.useState(savedState);
const form = [
{
id: 'api_key', label: __('API server key', 'kaliforms'), name: 'kaliforms_postmark_server_api', type: 'text',
help: sprintf(
__('The API key used for the connection to this service. You can retrieve this from your %sPostmark account%s', 'kaliforms'),
'',
''),
},
];
const showItem = (el) => {
let item = form.find(e => e.id === el);
if (!item.hasOwnProperty('conditioned')) {
return true;
}
return formValues[item.conditioned.conditioner] === item.conditioned.value
}
const inputChanged = (evt, id, type) => {
let value = evt.target.value;
if (type === 'checkbox') {
value = evt.target.checked;
}
formValues[id] = value;
setFormValues({ ...formValues });
}
const maybeProps = (item) => {
let obj = {};
if (item.type === 'checkbox') {
obj.checked = formValues[item.id]
}
return obj;
}
return (
{__('Postmark settings', 'kaliforms')}
{form.map((e, idx) => {
return (showItem(e.id) &&
inputChanged(evt, e.id, e.type)} />
inputChanged(evt, e.id, e.type)}
autoComplete={'off'}
/>
)
})}
);
}
export default Postmark;