const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_emailValidator = require("../utils/emailValidator.js");
const require_emailDomains = require("../constants/emailDomains.js");
const require_domainSuggestions = require("../utils/domainSuggestions.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
let _ant_design_icons = require("@ant-design/icons");
//#region src/components/pisellEmail/components/EditView.tsx
/**
* PisellEmail 编辑态视图组件
* 
* 职责：
* - 渲染编辑态邮箱输入框
* - 提供域名智能补全（基于 AutoComplete）
* - 实时格式校验（标准/严格）
* - 错误提示展示
* 
* @param props 组件 Props
*/
const EditView = (props) => {
	const { placeholder = "请输入邮箱地址", maxLength = 254, allowClear = false, autoFocus = false, disabled = false, className, style, enableAutoComplete = true, autoCompleteDomains, strictValidation = false, allowedDomains, blockedDomains, errorMessage, onSelect } = props;
	const [suggestions, setSuggestions] = (0, react.useState)([]);
	const domains = (0, react.useMemo)(() => {
		return autoCompleteDomains || require_emailDomains.COMMON_EMAIL_DOMAINS;
	}, [autoCompleteDomains]);
	const { value, isValid, errors, handleChange, handleBlur, handleFocus } = (0, _pisell_utils.useTextInputState)(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { validator: (val) => {
		if (!val) return true;
		if (!(strictValidation ? require_emailValidator.validateEmailStrict(val) : require_emailValidator.validateEmail(val))) return errorMessage || "邮箱地址格式不正确";
		const domainValidation = require_emailValidator.validateEmailDomain(val, allowedDomains, blockedDomains);
		if (!domainValidation.isValid) return domainValidation.errors[0];
		return true;
	} }));
	const handleSearch = (searchText) => {
		if (enableAutoComplete) setSuggestions(require_domainSuggestions.getEmailSuggestions(searchText, domains));
	};
	const handleInputChange = (val) => {
		handleChange(val);
		handleSearch(val);
	};
	const handleSelectSuggestion = (val) => {
		handleChange(val);
		onSelect === null || onSelect === void 0 || onSelect(val);
	};
	const options = suggestions.map((email) => ({ value: email }));
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-email-edit" }, /* @__PURE__ */ react.default.createElement(antd.AutoComplete, {
		value,
		onChange: handleInputChange,
		onSelect: handleSelectSuggestion,
		onBlur: handleBlur,
		onFocus: handleFocus,
		options,
		style: { width: "100%" },
		disabled,
		status: isValid ? void 0 : "error",
		popupClassName: "pisell-email-autocomplete-dropdown"
	}, /* @__PURE__ */ react.default.createElement(antd.Input, {
		type: "email",
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.MailOutlined, null),
		placeholder,
		maxLength,
		allowClear,
		autoFocus,
		className,
		style,
		"aria-label": props["aria-label"],
		"aria-describedby": props["aria-describedby"]
	})), !isValid && errors.length > 0 && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-email-edit-error" }, errors[0]));
};
//#endregion
exports.default = EditView;
