"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.ColorPresetMemo = void 0;

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

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

var classnames_1 = __importDefault(require("classnames"));

var find_1 = __importDefault(require("lodash/find"));

var get_1 = __importDefault(require("lodash/get"));

var useToggle_1 = __importDefault(require("react-use/lib/useToggle"));

var dropdown_1 = require("../../dropdown");

var Circle_1 = __importDefault(require("./Circle"));

var constant_1 = require("./constant");

require("../style/color-preset.css");

var Icon_1 = __importDefault(require("../../icon/Icon"));

var useCallback = React.useCallback,
    useState = React.useState,
    useRef = React.useRef;

var ColorPreset = function ColorPreset(_a) {
  var actived = _a.actived,
      color = _a.color,
      onChange = _a.onChange,
      className = _a.className,
      getPopupContainer = _a.getPopupContainer,
      _b = _a.colorPresetOptions,
      colorPresetOptions = _b === void 0 ? constant_1.PRESET_COLORS_OPT : _b,
      _c = _a.value,
      value = _c === void 0 ? constant_1.PRESET_COLORS_OPT[0].key : _c;
  var ref = useRef(null);

  var _d = useToggle_1["default"](true),
      on = _d[0],
      toggle = _d[1];

  var _e = useState(value),
      val = _e[0],
      setValues = _e[1];

  var fd = find_1["default"](constant_1.PRESET_COLORS_OPT, function (t) {
    return t.key === val;
  }) || constant_1.PRESET_COLORS_OPT[0];
  var renderDropNode = useCallback(function (actived) {
    return jsx_runtime_1.jsxs("span", __assign({
      className: classnames_1["default"](constant_1.prefixCls + "-preset-trigger", {
        actived: actived
      })
    }, {
      children: [get_1["default"](fd, 'title'), jsx_runtime_1.jsx(Icon_1["default"], {
        size: 14,
        icon: "unfold-more"
      }, void 0)]
    }), void 0);
  }, [fd]);
  var handleChange = useCallback(function (item) {
    setValues(item.key);
  }, []);
  var colorChange = useCallback(function (c) {
    if (onChange) {
      onChange(c, constant_1.CircleType.preset);
    }
  }, [onChange]);
  var expandCls = classnames_1["default"](constant_1.prefixCls + "-preset-expand", {
    expand: on
  });
  return jsx_runtime_1.jsxs("div", __assign({
    ref: ref,
    className: classnames_1["default"](constant_1.prefixCls + "-preset", className)
  }, {
    children: [jsx_runtime_1.jsxs("div", __assign({
      className: constant_1.prefixCls + "-preset-top"
    }, {
      children: [jsx_runtime_1.jsx(dropdown_1.Dropmenu, __assign({
        values: [val],
        onClickMenuItem: handleChange,
        menus: colorPresetOptions,
        openClassName: constant_1.prefixCls + "-preset-drop",
        getPopupContainer: getPopupContainer,
        renderDropNode: renderDropNode
      }, {
        children: val
      }), void 0), jsx_runtime_1.jsx(Icon_1["default"], {
        icon: "chevron-down",
        className: expandCls,
        onClick: toggle
      }, void 0)]
    }), void 0), on && jsx_runtime_1.jsx(Circle_1["default"], {
      actived: actived,
      color: color,
      colors: fd.colors,
      circleSize: 17,
      circleSpacing: 11,
      onChange: colorChange
    }, void 0)]
  }), void 0);
};

ColorPreset.displayName = 'ColorPreset';
exports["default"] = ColorPreset;
var ColorPresetMemo = React.memo(ColorPreset);
exports.ColorPresetMemo = ColorPresetMemo;
ColorPresetMemo.displayName = 'ColorPresetMemo';

