import {designComponent} from "@peryl/react-compose"; import {PlcScopeSlotsOptions} from "../../plc/utils/plc.scope-slots"; import {usePlc} from "../../plc/use/usePlc"; import {injectPlainTable} from "../../table/Table"; import {PlcCheckEmitsOptions, PlcCheckPropsOptions} from "./PlcCheck.utils"; import {useWatchAutoClear} from "../../../../utils/watchEffectAutoClear"; import {createPlcCheckHooks} from "./PlcCheck.hooks"; import {usePlcCheckMultiple} from "./PlcCheck.multiple"; import {usePlcCheckSingle} from "./PlcCheck.single"; import {doNothing} from "@peryl/utils/doNothing"; export const PlcCheck = designComponent({ name: 'plc-check', props: PlcCheckPropsOptions, emits: PlcCheckEmitsOptions, scopeSlots: PlcScopeSlotsOptions, setup({ props, scopeSlots, slots, event }) { const methods = { checkAll: () => hooks.onTriggerCheckAll.exec(undefined), uncheckAll: () => hooks.onTriggerUncheckAll.exec(undefined), getSelected: () => hooks.onGetSelected.exec([]), }; const table = injectPlainTable(); const hooks = createPlcCheckHooks(); const params = { props, event, hooks, table, }; const { refer, render } = usePlc({ props, scopeSlots, slots, event, defaultScopeSlots: { head: () => hooks.onRenderHead.exec(null), normal: (rowRenderScope) => hooks.onRenderNormal.exec({ scope: rowRenderScope, content: null }).content, summary: () => '', }, externalRefer: { ...methods, }, }); useWatchAutoClear(() => props.multiple, multiple => { return refer.isExclude() ? doNothing : (multiple ? usePlcCheckMultiple(params) : usePlcCheckSingle(params)); }); useWatchAutoClear(() => props.toggleOnClickRow && !refer.isExclude(), toggleOnClickRow => { return !!toggleOnClickRow ? table.hooks.onClickRow.use(({ node }) => {hooks.onClickRow.exec({ rowRenderScope: { node, row: node.data } });}) : doNothing; }); return { refer, render, }; }, });