const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_urlValidator = require("../utils/urlValidator.js");
const require_urlHelper = require("../utils/urlHelper.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/pisellUrl/components/EditView.tsx
/**
* PisellUrl 编辑态视图组件
* 
* 职责：
* - 渲染编辑态 URL 输入框
* - 失焦时自动补全协议
* - 实时格式校验
* - 错误提示展示
* 
* @param props 组件 Props
*/
const EditView = (props) => {
	const { placeholder = "请输入 URL 地址", maxLength = 2048, allowClear = false, autoFocus = false, disabled = false, className, style, autoCompleteProtocol = true, defaultProtocol = "https://", strictValidation = true, allowedProtocols, requireProtocol = false, errorMessage, onProtocolComplete } = props;
	const { value, isValid, errors, handleChange, handleBlur, handleFocus } = (0, _pisell_utils.useTextInputState)(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { validator: (val) => {
		if (!val) return true;
		const normalizedUrl = autoCompleteProtocol ? require_urlHelper.normalizeUrl(val, defaultProtocol) : val;
		if (strictValidation && !require_urlValidator.validateUrl(normalizedUrl)) return errorMessage || "URL 地址格式不正确";
		if (requireProtocol && !val.match(/^[a-z]+:\/\//i)) return "URL 必须包含协议（如 http:// 或 https://）";
		if (allowedProtocols && allowedProtocols.length > 0) {
			const protocolValidation = require_urlValidator.validateUrlProtocol(normalizedUrl, allowedProtocols);
			if (!protocolValidation.isValid) return protocolValidation.errors[0];
		}
		return true;
	} }));
	const handleBlurWithProtocol = () => {
		if (autoCompleteProtocol && value && !value.match(/^[a-z]+:\/\//i)) {
			const normalized = require_urlHelper.normalizeUrl(value, defaultProtocol);
			if (normalized !== value) {
				handleChange(normalized);
				onProtocolComplete === null || onProtocolComplete === void 0 || onProtocolComplete(normalized);
			}
		}
		handleBlur();
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-url-edit" }, /* @__PURE__ */ react.default.createElement(antd.Input, {
		type: "url",
		value,
		onChange: (e) => handleChange(e.target.value),
		onBlur: handleBlurWithProtocol,
		onFocus: handleFocus,
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.LinkOutlined, null),
		placeholder,
		maxLength,
		allowClear,
		autoFocus,
		disabled,
		status: isValid ? void 0 : "error",
		className,
		style,
		"aria-label": props["aria-label"],
		"aria-describedby": props["aria-describedby"]
	}), !isValid && errors.length > 0 && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-url-edit-error" }, errors[0]));
};
//#endregion
exports.default = EditView;
