import { useEffect, useState } from "react";
import { Button, Col, Icon, Row, Steps } from "tiny-ui";
const { Step } = Steps;
const Automation = ({
automation,
presets,
clients,
names,
onPreset,
...props
}) => {
const [current, setCurrent] = useState(-1);
const [total, setTotal] = useState();
useEffect(() => {
setTotal((automation && Object.keys(automation)) || 0);
}, [automation]);
useEffect(() => {
if (current > -1) {
let indx = current + 1;
let payload = {
clients: automation?.[indx] || [],
value: indx
};
onPreset(payload);
}
}, [current]);
const getTitle = (indx) => presets?.[indx]?.name || indx;
const getName = (v) => {
let indx = clients?.findIndex((o) => o === v);
return indx > -1 ? names?.[indx] : v;
};
const getDescription = (indx) => {
return automation?.[indx]?.map((o) => getName(o))?.join(", ");
};
let steps = Object.keys(automation).map((o, i) => {
return ;
});
return (
setCurrent(v)}
>
{steps}
}
onClick={() => {
let next = current - 1;
if (next < 0) next = 0;
setCurrent(next);
}}
/>
}
onClick={() => {
let next = current + 1;
if (next > total) next = 0;
setCurrent(next);
}}
/>
);
};
export default Automation;