function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["virtualKeyInputProps", "style", "className", "keyboardProps", "onChange", "value", "rightPanel", "selectType"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useEffect, useMemo } from "react";
import Keyboard from "./Keyboard";
import VirtualKeyInput from "./VirtualKeyInput";
import "./index.less";
import classNames from "classnames";
import { setTheme } from '@pisell/utils';
import usePisellConfig from "../pisell-config-provider/hooks/usePisellConfig";
var items = [{
  value: 1,
  label: "1",
  disabled: false,
  type: "text"
}, {
  value: 2,
  label: "2",
  disabled: false,
  type: "text"
}, {
  value: 3,
  label: "3",
  disabled: false,
  type: "text"
}, {
  value: 4,
  label: "4",
  disabled: false,
  type: "text"
}, {
  value: 5,
  label: "5",
  disabled: false,
  type: "text"
}, {
  value: 6,
  label: "6",
  disabled: false,
  type: "text"
}, {
  value: 7,
  label: "7",
  disabled: false,
  type: "text"
}, {
  value: 8,
  label: "8",
  disabled: false,
  type: "text"
}, {
  value: 9,
  label: "9",
  disabled: false,
  type: "text"
}, {
  value: "0",
  label: "0",
  disabled: false,
  type: "text"
}, {
  value: "ok",
  label: "OK",
  disabled: false,
  type: "primary"
}];
// 默认主题配置
var virtualKeyboardThemeConfig = {
  dark: {
    backgroundColor: 'rgba(0, 0, 0, 0.70)',
    containerBackgroundColor: 'rgba(0, 0, 0, 0.40)',
    buttonBackgroundColor: '#ffffff',
    textColor: '#000000',
    keyboardBackgroundColor: 'rgba(0, 0, 0, 0.40)',
    keyboardButtonBackgroundColor: '#ffffff',
    keyboardButtonTextColor: '#000000',
    keyboardButtonHoverColor: '#f5f5f5',
    primaryButtonBackgroundColor: '#4ca30d',
    primaryButtonTextColor: '#ffffff'
  },
  light: {
    backgroundColor: '#ffffff',
    containerBackgroundColor: '#d0d5dd',
    buttonBackgroundColor: '#ffffff',
    textColor: '#000000',
    keyboardBackgroundColor: '#f9f9f9',
    keyboardButtonBackgroundColor: '#ffffff',
    keyboardButtonTextColor: '#000000',
    keyboardButtonHoverColor: '#f5f5f5',
    primaryButtonBackgroundColor: '#4ca30d',
    primaryButtonTextColor: '#ffffff'
  }
};
var VirtualKeyboard = function VirtualKeyboard(props) {
  var virtualKeyInputProps = props.virtualKeyInputProps,
    style = props.style,
    className = props.className,
    keyboardProps = props.keyboardProps,
    onChange = props.onChange,
    value = props.value,
    rightPanel = props.rightPanel,
    _props$selectType = props.selectType,
    selectType = _props$selectType === void 0 ? 'light' : _props$selectType,
    others = _objectWithoutProperties(props, _excluded);
  var config = usePisellConfig();
  useEffect(function () {
    document.body.id = "body";
  }, []);

  /**
   * 配置颜色
   * 根据 props 和 selectType 生成最终的配置颜色
   */
  var configColor = useMemo(function () {
    var currentConfig = virtualKeyboardThemeConfig[selectType];

    // 过滤出有效的 props 并合并到默认配置中
    var validProps = Object.entries(props).reduce(function (acc, _ref) {
      var _ref2 = _slicedToArray(_ref, 2),
        key = _ref2[0],
        value = _ref2[1];
      if (value !== undefined && key in currentConfig) {
        acc[key] = value;
      }
      return acc;
    }, {});
    return _objectSpread(_objectSpread({}, currentConfig), validProps);
  }, [selectType, props]);
  useEffect(function () {
    setTheme({
      '--virtual-keyboard-background-color': configColor.backgroundColor,
      '--virtual-keyboard-container-background-color': configColor.containerBackgroundColor,
      '--virtual-keyboard-button-background-color': configColor.buttonBackgroundColor,
      '--virtual-keyboard-text-color': configColor.textColor,
      '--virtual-keyboard-keyboard-background-color': configColor.keyboardBackgroundColor,
      '--virtual-keyboard-keyboard-button-background-color': configColor.keyboardButtonBackgroundColor,
      '--virtual-keyboard-keyboard-button-text-color': configColor.keyboardButtonTextColor,
      '--virtual-keyboard-keyboard-button-hover-color': configColor.keyboardButtonHoverColor,
      '--virtual-keyboard-primary-button-background-color': configColor.primaryButtonBackgroundColor,
      '--virtual-keyboard-primary-button-text-color': configColor.primaryButtonTextColor
    });
  }, [configColor]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("virtual-keyboard-component", className, {
      'virtual-keyboard-component-dark': selectType === 'dark',
      'virtual-keyboard-component-light': selectType === 'light'
    }),
    style: style
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames("virtual-keyboard-component-left")
  }, /*#__PURE__*/React.createElement(VirtualKeyInput, virtualKeyInputProps), /*#__PURE__*/React.createElement(Keyboard, _extends({
    items: items
  }, keyboardProps))), rightPanel ? /*#__PURE__*/React.createElement("div", {
    className: "virtual-keyboard-component-right"
  }, rightPanel) : null);
};
export default VirtualKeyboard;