"use strict";

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  Object.defineProperty(o, k2, {
    enumerable: true,
    get: function get() {
      return m[k];
    }
  });
} : function (o, m, k, k2) {
  if (k2 === undefined) k2 = k;
  o[k2] = m[k];
});

var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  Object.defineProperty(o, "default", {
    enumerable: true,
    value: v
  });
} : function (o, v) {
  o["default"] = v;
});

var __importStar = void 0 && (void 0).__importStar || function (mod) {
  if (mod && mod.__esModule) return mod;
  var result = {};
  if (mod != null) for (var k in mod) {
    if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  }

  __setModuleDefault(result, mod);

  return result;
};

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.prefixCls = void 0;

var jsx_runtime_1 = require("react/jsx-runtime");

var React = __importStar(require("react"));

var icon_1 = __importDefault(require("../../../icon"));

var lodash_1 = require("lodash");

var useMeasure_1 = __importDefault(require("react-use/lib/useMeasure"));

var StandardFieldItem_1 = __importDefault(require("./StandardFieldItem"));

var AnalysisBtn_1 = __importDefault(require("../AnalysisBtn"));

var PackageDropDown_1 = __importDefault(require("./PackageDropDown"));

var index_1 = require("../index");

exports.prefixCls = "dmc-global-filter-sf";
var STANDARD_FILTER_HEIGHT = 38;
var DEFAULT_CONTAINER_STYLE = {
  height: STANDARD_FILTER_HEIGHT,
  overflow: 'hidden'
};
var EXPAN_CONTAINER_STYLE = {
  height: 'auto',
  overflow: 'auto'
};

var StandardFilter = function StandardFilter(_a) {
  var packages = _a.packages,
      currentPackage = _a.currentPackage,
      changeCurrentPackage = _a.changeCurrentPackage,
      startAnalysis = _a.startAnalysis,
      startAnalysisProps = _a.startAnalysisProps,
      list = _a.list,
      changeItem = _a.changeItem,
      suppFilter = _a.suppFilter,
      onVisibleChange = _a.onVisibleChange,
      fieldValueObj = _a.fieldValueObj,
      _b = _a.showPackage,
      showPackage = _b === void 0 ? true : _b,
      clearFilter = _a.clearFilter,
      textLabels = _a.textLabels;

  var _c = useMeasure_1["default"](),
      filterWrapperRef = _c[0],
      filterHeight = _c[1].height;

  var _d = React.useState(false),
      expand = _d[0],
      setExpand = _d[1];

  var hasMore = filterHeight > STANDARD_FILTER_HEIGHT;
  var changeExpand = React.useCallback(function () {
    return setExpand(function (expand) {
      return !expand;
    });
  }, []);
  var style = React.useMemo(function () {
    return expand ? EXPAN_CONTAINER_STYLE : DEFAULT_CONTAINER_STYLE;
  }, [expand]);
  var mornIcon = React.useMemo(function () {
    return hasMore && jsx_runtime_1.jsxs("div", __assign({
      className: exports.prefixCls + "-item",
      onClick: changeExpand
    }, {
      children: [jsx_runtime_1.jsx("div", __assign({
        className: exports.prefixCls + "-item"
      }, {
        children: textLabels === null || textLabels === void 0 ? void 0 : textLabels.more
      }), void 0), jsx_runtime_1.jsx(icon_1["default"], {
        icon: "chevron-" + (expand ? 'up' : 'down'),
        size: 12
      }, void 0)]
    }), void 0);
  }, [changeExpand, expand, hasMore, textLabels === null || textLabels === void 0 ? void 0 : textLabels.more]);
  var clearFilterNode = React.useMemo(function () {
    return showPackage && !lodash_1.isEmpty(currentPackage) && jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, {
      children: [jsx_runtime_1.jsx("div", {
        className: exports.prefixCls + "-item-split-line"
      }, void 0), jsx_runtime_1.jsx("div", __assign({
        className: exports.prefixCls + "-more-icon",
        onClick: clearFilter
      }, {
        children: jsx_runtime_1.jsx(icon_1["default"], {
          icon: "delete-2",
          size: 18
        }, void 0)
      }), void 0)]
    }, void 0);
  }, [clearFilter, currentPackage, showPackage]);
  return jsx_runtime_1.jsxs("div", __assign({
    className: exports.prefixCls + "-container"
  }, {
    children: [jsx_runtime_1.jsx("div", __assign({
      className: exports.prefixCls + "-all-wrapper"
    }, {
      children: jsx_runtime_1.jsx("div", __assign({
        className: exports.prefixCls + "-sub-wrapper"
      }, {
        children: jsx_runtime_1.jsxs("div", __assign({
          className: exports.prefixCls,
          style: style
        }, {
          children: [jsx_runtime_1.jsx("div", __assign({
            className: exports.prefixCls + "-content"
          }, {
            children: jsx_runtime_1.jsxs("div", __assign({
              className: exports.prefixCls + "-content-filter",
              ref: filterWrapperRef
            }, {
              children: [jsx_runtime_1.jsx(PackageDropDown_1["default"], {
                currentPackage: currentPackage,
                packages: packages,
                changeCurrentPackage: changeCurrentPackage
              }, void 0), lodash_1.map(list, function (field) {
                var filter = index_1.getFieldFilter(field.detail, suppFilter);
                return jsx_runtime_1.jsx(StandardFieldItem_1["default"], {
                  field: field,
                  fieldFilter: filter,
                  changeItem: changeItem,
                  onVisibleChange: onVisibleChange,
                  options: fieldValueObj[field.detail.uuid],
                  textLabels: textLabels
                }, field.detail.uuid);
              })]
            }), void 0)
          }), exports.prefixCls + "-content"), jsx_runtime_1.jsxs("div", __assign({
            className: exports.prefixCls + "-action-icons"
          }, {
            children: [mornIcon, clearFilterNode]
          }), exports.prefixCls + "-action-icons")]
        }), void 0)
      }), void 0)
    }), void 0), jsx_runtime_1.jsx(AnalysisBtn_1["default"], {
      className: exports.prefixCls + "-analysis-button",
      startAnalysis: startAnalysis,
      startAnalysisProps: startAnalysisProps
    }, void 0)]
  }), void 0);
};

exports["default"] = StandardFilter;

