"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.cascaderPanelProps = cascaderPanelProps;
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _vue = require("vue");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _lodash = require("lodash");
require("./interface");
var _Panel = _interopRequireWildcard(require("../vc-cascader/Panel"));
var _type = require("../_util/type");
var _useConfigInject = _interopRequireDefault(require("../config-provider/hooks/useConfigInject"));
var _style = _interopRequireDefault(require("./style"));
var _iconsVue = require("@ant-design/icons-vue/lib/icons");
var _form = require("../form");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function cascaderPanelProps() {
  return (0, _extends2.default)((0, _extends2.default)({}, (0, _lodash.omit)((0, _Panel.panelProps)(), 'checkable')), {
    multiple: (0, _type.booleanType)(),
    onChange: Function
  });
}
var _default = exports.default = (0, _vue.defineComponent)({
  name: 'ACascaderPanel',
  inheritAttrs: false,
  props: cascaderPanelProps(),
  setup(props, {
    attrs,
    slots,
    emit
  }) {
    const {
      prefixCls: cascaderPrefixCls,
      direction,
      renderEmpty,
      disabled
    } = (0, _useConfigInject.default)('cascader', props);
    const mergedDisabled = (0, _vue.computed)(() => {
      var _a;
      return (_a = props.disabled) !== null && _a !== void 0 ? _a : disabled.value;
    });
    const [wrapCascaderSSR, hashId] = (0, _style.default)(cascaderPrefixCls);
    const isRtl = (0, _vue.computed)(() => direction.value === 'rtl');
    const formItemContext = (0, _form.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 ? (0, _vue.createVNode)(_iconsVue.LeftOutlined, null, null) : (0, _vue.createVNode)(_iconsVue.RightOutlined, null, null);
      }
      const loadingIcon = (0, _vue.createVNode)("span", {
        "class": `${cascaderPrefixCls.value}-menu-item-loading-icon`
      }, [(0, _vue.createVNode)(_iconsVue.LoadingOutlined, {
        "spin": true
      }, null)]);
      return wrapCascaderSSR((0, _vue.createVNode)(_Panel.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, 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": (0, _extends2.default)((0, _extends2.default)({}, slots), {
          checkable: () => (0, _vue.createVNode)("span", {
            "class": `${cascaderPrefixCls.value}-checkbox-inner`
          }, null)
        })
      }), null));
    };
  }
});