var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/clinetSearch/Add/PhoneField/index.tsx
var PhoneField_exports = {};
__export(PhoneField_exports, {
  default: () => PhoneField_default
});
module.exports = __toCommonJS(PhoneField_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_keyboards = require("../../../../pro/keyboards");
var import_serve = require("./serve");
var import_responsive = require("../../../../responsive");
var defaultValue = {
  code: "+61",
  phone: ""
};
var Compact = import_antd.Space.Compact;
var PhoneField = ({ value, onChange, variant }) => {
  const [keyboardOpen, setKeyboardOpen] = (0, import_react.useState)(false);
  const codes = (0, import_ahooks.useRequest)(import_serve.getCountries, {
    manual: true
  });
  const currentValue = { ...defaultValue, ...value };
  const isPhoneVariant = variant === "phone";
  (0, import_react.useEffect)(() => {
    codes.run();
  }, []);
  const _onChange = (key, val) => {
    onChange({ ...defaultValue, ...value, [key]: val });
  };
  const phoneInput = /* @__PURE__ */ import_react.default.createElement(
    import_antd.Input,
    {
      readOnly: true,
      size: "large",
      value: currentValue.phone || "",
      onClick: () => setKeyboardOpen(true),
      style: { width: "100%", borderRadius: "0 8px 8px 0" }
    }
  );
  const keyboardProps = {
    value: currentValue.phone || "",
    countryCallingCode: currentValue.code,
    onChange: (phone) => {
      _onChange("phone", phone);
    },
    onEnter: (phone) => {
      _onChange("phone", phone);
      setKeyboardOpen(false);
    },
    formatSeparator: "dash"
  };
  return /* @__PURE__ */ import_react.default.createElement(Compact, { style: { width: "100%" } }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      options: codes.data || [],
      onChange: (val) => {
        _onChange("code", val);
      },
      size: "large",
      style: variant === "phone" ? { flex: "0 0 50px" } : { flex: "0 0 100px" },
      loading: codes.loading,
      optionLabelProp: "value",
      value: currentValue.code,
      dropdownMatchSelectWidth: false
    }
  ), isPhoneVariant ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, phoneInput, /* @__PURE__ */ import_react.default.createElement(
    import_keyboards.PhoneKeyboard,
    {
      ...keyboardProps,
      renderType: "modal",
      containerProps: {
        open: keyboardOpen,
        onCancel: () => setKeyboardOpen(false)
      }
    }
  )) : /* @__PURE__ */ import_react.default.createElement(
    import_keyboards.PhoneKeyboard,
    {
      ...keyboardProps,
      renderType: "popover",
      containerProps: {
        open: keyboardOpen,
        onOpenChange: setKeyboardOpen
      }
    },
    phoneInput
  ));
};
PhoneField.displayName = "PhoneField";
var PhoneField_default = (0, import_responsive.withResponsive)(PhoneField);
