import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { createVNode as _createVNode } from "vue";
import _extends from "@babel/runtime/helpers/esm/extends";
import { omit } from 'lodash';
import './interface';
import Panel, { panelProps } from '../vc-cascader/Panel';
import { booleanType } from '../_util/type';
import { computed, defineComponent } from 'vue';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useStyle from './style';
import { LeftOutlined, LoadingOutlined, RightOutlined } from '@ant-design/icons-vue';
import { useInjectFormItemContext } from '../form';
export function cascaderPanelProps() {
  return _extends(_extends({}, omit(panelProps(), 'checkable')), {
    multiple: booleanType(),
    onChange: Function
  });
}
export default defineComponent({
  name: 'ACascaderPanel',
  inheritAttrs: false,
  props: cascaderPanelProps(),
  setup(props, {
    attrs,
    slots,
    emit
  }) {
    const {
      prefixCls: cascaderPrefixCls,
      direction,
      renderEmpty,
      disabled
    } = useConfigInject('cascader', props);
    const mergedDisabled = computed(() => {
      var _a;
      return (_a = props.disabled) !== null && _a !== void 0 ? _a : disabled.value;
    });
    const [wrapCascaderSSR, hashId] = useStyle(cascaderPrefixCls);
    const isRtl = computed(() => direction.value === 'rtl');
    const formItemContext = useInjectFormItemContext();
    const handleChange = (...args) => {
      emit('update:value', args[0]);
      emit('change', ...args);
      formItemContext.onFieldChange();
    };
    return () => {
      const {
        notFoundContent,
        expandIcon
      } = props;
      const mergedNotFoundContent = notFoundContent || renderEmpty('Cascader');
      // ===================== Icon ======================
      let mergedExpandIcon = expandIcon;
      if (!expandIcon) {
        mergedExpandIcon = isRtl.value ? _createVNode(LeftOutlined, null, null) : _createVNode(RightOutlined, null, null);
      }
      const loadingIcon = _createVNode("span", {
        "class": `${cascaderPrefixCls.value}-menu-item-loading-icon`
      }, [_createVNode(LoadingOutlined, {
        "spin": true
      }, null)]);
      return wrapCascaderSSR(_createVNode(Panel, _objectSpread(_objectSpread({}, props), {}, {
        "checkable": !!props.multiple,
        "prefixCls": cascaderPrefixCls.value,
        "class": [attrs.class, hashId.value],
        "notFoundContent": mergedNotFoundContent,
        "direction": direction.value,
        "expandIcon": mergedExpandIcon,
        "loadingIcon": loadingIcon,
        "disabled": mergedDisabled.value,
        "onChange": handleChange,
        "customSlots": _extends(_extends({}, slots), {
          checkable: () => _createVNode("span", {
            "class": `${cascaderPrefixCls.value}-checkbox-inner`
          }, null)
        })
      }), null));
    };
  }
});