import {html} from "lit" import {view} from "@e280/sly" import styleCss from "./style.css.js" import themeCss from "../../theme.css.js" import {Loader} from "./loader.js" import {SpinnerView} from "../spinner/view.js" import {LoadingOperation} from "./parts/operation.js" export const LoaderView = view(use => (loader: Loader) => { use.name("loader") use.css(themeCss, styleCss) const stage = loader.stage.value const curtain = loader.curtain.value const operation = loader.operation.value function renderLoadScreen({tasks}: LoadingOperation, visible: boolean) { const count = 3 const remaining = tasks.size - count const focustasks = [...tasks].slice(0, count) return html`
    ${focustasks.map(task => html`
  1. ${SpinnerView()} ${task.label}...
    ${task.progress ?html`
    `: null}
  2. `)} ${tasks.size > count ? html`
  3. ${SpinnerView()} ...and ${remaining} more ${remaining === 1 ?"task" :"tasks"}...
  4. ` : null}
` } const loadScreenEnabled = curtain >= 1 const loadScreenVisible = curtain >= 2 const shouldRenderContent = curtain <= 2 return html` ${loadScreenEnabled && operation ? renderLoadScreen(operation, loadScreenVisible) : null} ${shouldRenderContent ? loader.render() : null} ` })