import {
  App,
  defineComponent,
  getCurrentInstance,
  onMounted,
  provide,
  ref
} from 'vue';
// @ts-ignore
import style from './style/index.module.less';

const Tl = defineComponent({
  name: 'Tl',
  props: {
    fixed: { type: Boolean, default: true }
  },
  setup(props, { attrs, slots }) {
    const more = ref(false);
    const open = ref(false);
    const updateOpen = () => {
      open.value = !open.value;
    };
    provide('tl-more', more);
    provide('tl-open', open);
    provide('tl-updateOpen', updateOpen);

    const hasTlFilterSecond = () => {
      const instance = getCurrentInstance();
      // @ts-ignore
      const children = instance?.subTree?.children?.[0].children;
      more.value = !!children?.find(
        (_: any) => _.type?.name === 'TlFilterSecond'
      );
    };

    onMounted(() => {
      hasTlFilterSecond();
    });

    return () => (
      <div
        class={`${style['table-layout']} ${
          props.fixed ? style['fixed'] : ''
        } flex flex-col h-full`}
      >
        {slots.default?.()}
      </div>
    );
  }
});
export default Tl as typeof Tl & {
  install: (app: App, ...options: any[]) => any;
};
