import { put as o, select as e, takeLatest as a, delay as t } from "redux-saga/effects"
import { getCoreBackend as s } from "../../backend"
import { apiCall as i } from "../../api/core"
import { getAppCurrentRoomId as r } from "../app"
import { createRoomInitialConfig as m, switchRoomSubmit as d } from "../room"
import { userWarnNotification as n } from "../notification"
import { autoCreateRooms as c, autoAddMessages as l } from "./ui-automation.reducer"
import { AUTO_ADD_MESSAGE_TYPE as f, LONG_TEXT as p } from "./ui-automation.constants"
export function* autoCreateRoomsSaga({
payload: { numRooms: e = 1, index: a = 1, openLast: r = !1 },
}) {
const n = s()
let c
for (let o = a; o < a + e; o += 1) {
const e = m(`Room ${o}`)
;((c = yield i(n.createRoom, { config: e })), yield t(250))
}
r && (yield o(d({ roomId: c })))
}
export function* autoAddMessagesSaga({ payload: { numMessages: a = 1, type: m = f.INDEX } }) {
const d = s(),
c = () => Math.round(Math.random() * p.length - 1),
l = yield e(r)
if (l)
for (let o = 0; o < a; o += 1) {
let e
switch (m) {
case f.INDEX:
e = `Message ${o + 1}`
break
case f.SHORT: {
const o = c(),
a = o + 50
e = p.slice(o, a)
break
}
case f.LONG:
e = p.slice(c())
}
;(yield i(d.addChatMessage, l, e), yield t(250))
}
else yield o(n({ title: "Add Messages", message: "No room selected" }))
}
export function* uiAutomationSaga() {
;(yield a(c, autoCreateRoomsSaga), yield a(l, autoAddMessagesSaga))
}