// packages/block-library/src/form-input/deprecated.js
import clsx from "clsx";
import removeAccents from "remove-accents";
import {
  RichText,
  useBlockProps,
  __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
  __experimentalGetColorClassesAndStyles as getColorClassesAndStyles
} from "@wordpress/block-editor";
import { __unstableStripHTML as stripHTML } from "@wordpress/dom";
import { jsx, jsxs } from "react/jsx-runtime";
var getNameFromLabelV1 = (content) => {
  return removeAccents(stripHTML(content)).replace(/[^\p{L}\p{N}]+/gu, "-").toLowerCase().replace(/(^-+)|(-+$)/g, "");
};
var v2 = {
  attributes: {
    type: {
      type: "string",
      default: "text"
    },
    name: {
      type: "string"
    },
    label: {
      type: "string",
      default: "Label",
      selector: ".wp-block-form-input__label-content",
      source: "html",
      role: "content"
    },
    inlineLabel: {
      type: "boolean",
      default: false
    },
    required: {
      type: "boolean",
      default: false,
      selector: ".wp-block-form-input__input",
      source: "attribute",
      attribute: "required"
    },
    placeholder: {
      type: "string",
      selector: ".wp-block-form-input__input",
      source: "attribute",
      attribute: "placeholder",
      role: "content"
    },
    value: {
      type: "string",
      default: "",
      selector: "input",
      source: "attribute",
      attribute: "value"
    },
    visibilityPermissions: {
      type: "string",
      default: "all"
    }
  },
  supports: {
    anchor: true,
    reusable: false,
    spacing: {
      margin: ["top", "bottom"]
    },
    __experimentalBorder: {
      radius: true,
      __experimentalSkipSerialization: true,
      __experimentalDefaultControls: {
        radius: true
      }
    }
  },
  save({ attributes }) {
    const { type, name, label, inlineLabel, required, placeholder, value } = attributes;
    const borderProps = getBorderClassesAndStyles(attributes);
    const colorProps = getColorClassesAndStyles(attributes);
    const inputStyle = {
      ...borderProps.style,
      ...colorProps.style
    };
    const inputClasses = clsx(
      "wp-block-form-input__input",
      colorProps.className,
      borderProps.className
    );
    const TagName = type === "textarea" ? "textarea" : "input";
    const blockProps = useBlockProps.save();
    if ("hidden" === type) {
      return /* @__PURE__ */ jsx("input", { type, name, value });
    }
    return /* @__PURE__ */ jsx("div", { ...blockProps, children: /* @__PURE__ */ jsxs(
      "label",
      {
        className: clsx("wp-block-form-input__label", {
          "is-label-inline": inlineLabel
        }),
        children: [
          /* @__PURE__ */ jsx("span", { className: "wp-block-form-input__label-content", children: /* @__PURE__ */ jsx(RichText.Content, { value: label }) }),
          /* @__PURE__ */ jsx(
            TagName,
            {
              className: inputClasses,
              type: "textarea" === type ? void 0 : type,
              name: name || getNameFromLabelV1(label),
              required,
              "aria-required": required,
              placeholder: placeholder || void 0,
              style: inputStyle
            }
          )
        ]
      }
    ) });
  }
};
var v1 = {
  attributes: {
    type: {
      type: "string",
      default: "text"
    },
    name: {
      type: "string"
    },
    label: {
      type: "string",
      default: "Label",
      selector: ".wp-block-form-input__label-content",
      source: "html",
      role: "content"
    },
    inlineLabel: {
      type: "boolean",
      default: false
    },
    required: {
      type: "boolean",
      default: false,
      selector: ".wp-block-form-input__input",
      source: "attribute",
      attribute: "required"
    },
    placeholder: {
      type: "string",
      selector: ".wp-block-form-input__input",
      source: "attribute",
      attribute: "placeholder",
      role: "content"
    },
    value: {
      type: "string",
      default: "",
      selector: "input",
      source: "attribute",
      attribute: "value"
    },
    visibilityPermissions: {
      type: "string",
      default: "all"
    }
  },
  supports: {
    className: false,
    anchor: true,
    reusable: false,
    spacing: {
      margin: ["top", "bottom"]
    },
    __experimentalBorder: {
      radius: true,
      __experimentalSkipSerialization: true,
      __experimentalDefaultControls: {
        radius: true
      }
    }
  },
  save({ attributes }) {
    const { type, name, label, inlineLabel, required, placeholder, value } = attributes;
    const borderProps = getBorderClassesAndStyles(attributes);
    const colorProps = getColorClassesAndStyles(attributes);
    const inputStyle = {
      ...borderProps.style,
      ...colorProps.style
    };
    const inputClasses = clsx(
      "wp-block-form-input__input",
      colorProps.className,
      borderProps.className
    );
    const TagName = type === "textarea" ? "textarea" : "input";
    if ("hidden" === type) {
      return /* @__PURE__ */ jsx("input", { type, name, value });
    }
    return /* @__PURE__ */ jsxs(
      "label",
      {
        className: clsx("wp-block-form-input__label", {
          "is-label-inline": inlineLabel
        }),
        children: [
          /* @__PURE__ */ jsx("span", { className: "wp-block-form-input__label-content", children: /* @__PURE__ */ jsx(RichText.Content, { value: label }) }),
          /* @__PURE__ */ jsx(
            TagName,
            {
              className: inputClasses,
              type: "textarea" === type ? void 0 : type,
              name: name || getNameFromLabelV1(label),
              required,
              "aria-required": required,
              placeholder: placeholder || void 0,
              style: inputStyle
            }
          )
        ]
      }
    );
  }
};
var deprecated = [v2, v1];
var deprecated_default = deprecated;
export {
  deprecated_default as default
};
//# sourceMappingURL=deprecated.js.map
