import { defineComponent, inject, ref, watch, resolveComponent, createElementBlock, openBlock, Fragment, createVNode, createCommentVNode, normalizeClass, unref, withCtx, createElementVNode, normalizeStyle, createBlock, renderList } from 'vue';
import '../../../../utils/index.mjs';
import '../config/index.mjs';
import './json-xml-table-row.vue.mjs';
import './click-input.vue.mjs';
import { createNamespace } from '../../../../utils/create-namespace.mjs';
import { jsonXmlTypeOptions, jsonXmlTableRowEmits, jsonXmlTableRowProps } from '../config/json-xml.mjs';
import _sfc_main$1 from './click-input.vue2.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlJsonXmlTableRow" },
  __name: "json-xml-table-row",
  props: jsonXmlTableRowProps,
  emits: jsonXmlTableRowEmits,
  setup(__props, { emit: __emit }) {
    const bem = createNamespace("json-xml");
    const props = __props;
    const emits = __emit;
    const disabled = inject("disabled");
    const innerData = ref(props.data);
    const parentData = ref(props.parentData);
    const expanded = ref(true);
    const addValue = ref("");
    const customOverlay = (parentData2, innerData2) => [
      {
        label: "\u6DFB\u52A0\u5B50\u8282\u70B9",
        type: "child",
        parentData: parentData2,
        innerData: innerData2
      },
      {
        label: "\u6DFB\u52A0\u76F8\u90BB\u8282\u70B9",
        type: "next",
        parentData: parentData2,
        innerData: innerData2
      }
    ];
    const getTip = (parentData2, innerData2) => {
      if (!parentData2 || parentData2.type === "array" && innerData2.type === "object") {
        return "child";
      }
      if (parentData2.type === "object" && innerData2.type !== "object") {
        return "next";
      }
    };
    const handleChange = () => {
      if (innerData.value.type === "object" || innerData.value.type === "array") {
        innerData.value.children = [];
        if (innerData.value.type === "array") {
          innerData.value.children[0] = {
            key: props.treeKey + "-1",
            name: "ITEMS",
            type: "string",
            value: "",
            chineseName: "",
            description: "",
            mock: ""
          };
        }
      } else {
        delete innerData.value.children;
      }
    };
    const handleConfirm = (parentData2, innerData2) => {
      const findIndex = parentData2.children.findIndex(
        (item) => item.key === innerData2.key
      );
      parentData2.children.splice(findIndex, 1);
    };
    const handleInput = () => {
      innerData.value.children = [];
      innerData.value.children[0] = {
        key: props.treeKey + "-1",
        name: addValue.value,
        type: "string",
        value: "",
        chineseName: "",
        description: "",
        mock: ""
      };
      addValue.value = "";
    };
    const handleAdd = (type, parentData2, innerData2) => {
      if (type === "next") {
        parentData2.children.push({
          key: `${parentData2.children.length + 1}`,
          name: "",
          type: "string",
          value: "",
          chineseName: "",
          description: "",
          mock: ""
        });
      } else {
        innerData2.children.push({
          key: props.treeKey + `${innerData2.children.length + 1}`,
          name: "",
          type: "string",
          value: "",
          chineseName: "",
          description: "",
          mock: ""
        });
      }
    };
    const handleClaimSelected = (item) => {
      const { type, parentData: parentData2, innerData: innerData2 } = item;
      handleAdd(type, parentData2, innerData2);
    };
    const handleRowChange = (child) => {
      if (innerData.value.children) {
        const index = innerData.value.children.findIndex(
          (item) => item.key === child.key
        );
        innerData.value.children[index] = child;
      }
    };
    watch(
      innerData,
      () => {
        emits("change", innerData.value);
      },
      {
        deep: true
      }
    );
    return (_ctx, _cache) => {
      const _component_ll_icon = resolveComponent("ll-icon");
      const _component_ll_button = resolveComponent("ll-button");
      const _component_ll_input = resolveComponent("ll-input");
      const _component_a_col = resolveComponent("a-col");
      const _component_ll_select = resolveComponent("ll-select");
      const _component_ll_tooltip = resolveComponent("ll-tooltip");
      const _component_ll_dropdown = resolveComponent("ll-dropdown");
      const _component_a_popconfirm = resolveComponent("a-popconfirm");
      const _component_a_row = resolveComponent("a-row");
      return openBlock(), createElementBlock(
        Fragment,
        null,
        [
          createVNode(_component_a_row, {
            gutter: 20,
            class: normalizeClass(unref(bem).e("table-row"))
          }, {
            default: withCtx(() => [
              createVNode(_component_a_col, {
                style: { "display": "flex" },
                span: 7,
                class: normalizeClass(unref(bem).e("table-col"))
              }, {
                default: withCtx(() => [
                  createElementVNode(
                    "p",
                    {
                      style: normalizeStyle({ width: 10 * props.layer + "px" })
                    },
                    null,
                    4
                    /* STYLE */
                  ),
                  createElementVNode(
                    "div",
                    {
                      style: { "margin-right": "30px" },
                      class: normalizeClass(unref(bem).m("table-row-icon"))
                    },
                    [
                      innerData.value.type === "object" || innerData.value.type === "array" ? (openBlock(), createBlock(_component_ll_button, {
                        key: 0,
                        type: "link",
                        style: { "width": "10px" },
                        disabled: unref(disabled),
                        onClick: _cache[0] || (_cache[0] = ($event) => expanded.value = !expanded.value)
                      }, {
                        default: withCtx(() => [
                          !expanded.value ? (openBlock(), createBlock(_component_ll_icon, {
                            key: 0,
                            style: { "font-size": "14px" },
                            "icon-name": "icon-list-expand"
                          })) : (openBlock(), createBlock(_component_ll_icon, {
                            key: 1,
                            style: { "font-size": "14px" },
                            "icon-name": "icon-list-retract"
                          }))
                        ]),
                        _: 1
                        /* STABLE */
                      }, 8, ["disabled"])) : createCommentVNode("v-if", true)
                    ],
                    2
                    /* CLASS */
                  ),
                  !props.parentData ? (openBlock(), createElementBlock(
                    "div",
                    {
                      key: 0,
                      class: normalizeClass(unref(bem).m("table-row-tag"))
                    },
                    "\u6839\u8282\u70B9",
                    2
                    /* CLASS */
                  )) : (openBlock(), createElementBlock(
                    Fragment,
                    { key: 1 },
                    [
                      props.parentData.type === "array" ? (openBlock(), createElementBlock(
                        "div",
                        {
                          key: 0,
                          class: normalizeClass(unref(bem).m("table-row-tag"))
                        },
                        " ITEMS ",
                        2
                        /* CLASS */
                      )) : createCommentVNode("v-if", true),
                      props.parentData.type === "object" ? (openBlock(), createBlock(_component_ll_input, {
                        key: 1,
                        value: innerData.value.name,
                        "onUpdate:value": _cache[1] || (_cache[1] = ($event) => innerData.value.name = $event),
                        disabled: unref(disabled),
                        placeholder: "\u6DFB\u52A0\u5B57\u6BB5\u540D",
                        style: { "width": "100%" },
                        bordered: false
                      }, null, 8, ["value", "disabled"])) : createCommentVNode("v-if", true)
                    ],
                    64
                    /* STABLE_FRAGMENT */
                  ))
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"]),
              createVNode(_component_a_col, {
                span: 3,
                class: normalizeClass(unref(bem).e("table-col"))
              }, {
                default: withCtx(() => [
                  createVNode(_component_ll_select, {
                    value: innerData.value.type,
                    "onUpdate:value": _cache[2] || (_cache[2] = ($event) => innerData.value.type = $event),
                    options: unref(jsonXmlTypeOptions),
                    disabled: unref(disabled),
                    style: { "width": "100%" },
                    onChange: handleChange
                  }, null, 8, ["value", "options", "disabled"])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"]),
              createVNode(_component_a_col, {
                span: 4,
                class: normalizeClass(unref(bem).e("table-col"))
              }, {
                default: withCtx(() => [
                  createVNode(_sfc_main$1, {
                    value: innerData.value.mock,
                    "onUpdate:value": _cache[3] || (_cache[3] = ($event) => innerData.value.mock = $event),
                    placeholder: "Mock",
                    disabled: innerData.value.type === "object" || unref(disabled),
                    style: { "width": "100%" }
                  }, null, 8, ["value", "disabled"])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"]),
              createVNode(_component_a_col, {
                span: 4,
                class: normalizeClass(unref(bem).e("table-col"))
              }, {
                default: withCtx(() => [
                  createVNode(_component_ll_input, {
                    value: innerData.value.chineseName,
                    "onUpdate:value": _cache[4] || (_cache[4] = ($event) => innerData.value.chineseName = $event),
                    disabled: unref(disabled),
                    placeholder: "\u4E2D\u6587\u540D",
                    style: { "width": "100%" }
                  }, null, 8, ["value", "disabled"])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"]),
              createVNode(_component_a_col, {
                span: 4,
                class: normalizeClass(unref(bem).e("table-col"))
              }, {
                default: withCtx(() => [
                  createVNode(_sfc_main$1, {
                    value: innerData.value.description,
                    "onUpdate:value": _cache[5] || (_cache[5] = ($event) => innerData.value.description = $event),
                    disabled: unref(disabled),
                    placeholder: "\u8BF4\u660E",
                    style: { "width": "100%" }
                  }, null, 8, ["value", "disabled"])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"]),
              createVNode(_component_a_col, { span: 2 }, {
                default: withCtx(() => [
                  createElementVNode(
                    "div",
                    {
                      class: normalizeClass(unref(bem).e("table-operation"))
                    },
                    [
                      props.parentData && props.parentData.type === "object" && innerData.value.type !== "object" || !props.parentData && innerData.value.type === "object" ? (openBlock(), createBlock(_component_ll_tooltip, {
                        key: 0,
                        tip: getTip(parentData.value, innerData.value) === "child" ? "\u6DFB\u52A0\u5B50\u8282\u70B9" : "\u6DFB\u52A0\u76F8\u90BB\u8282\u70B9"
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_ll_button, {
                            type: "link",
                            disabled: unref(disabled),
                            class: normalizeClass(unref(bem).m("table-icon")),
                            onClick: _cache[6] || (_cache[6] = ($event) => handleAdd(
                              getTip(parentData.value, innerData.value),
                              props.parentData,
                              innerData.value
                            ))
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_ll_icon, { "icon-name": "icon-list-add" })
                            ]),
                            _: 1
                            /* STABLE */
                          }, 8, ["disabled", "class"])
                        ]),
                        _: 1
                        /* STABLE */
                      }, 8, ["tip"])) : createCommentVNode("v-if", true),
                      createVNode(_component_ll_dropdown, {
                        "dropdown-items": customOverlay(props.parentData, innerData.value),
                        placement: "bottomRight",
                        onClaimSelected: handleClaimSelected
                      }, {
                        default: withCtx(() => [
                          props.parentData && props.parentData.type === "object" && innerData.value.type === "object" ? (openBlock(), createBlock(_component_ll_button, {
                            key: 0,
                            class: normalizeClass(unref(bem).m("table-icon")),
                            disabled: unref(disabled),
                            type: "link"
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_ll_icon, { "icon-name": "icon-list-add" })
                            ]),
                            _: 1
                            /* STABLE */
                          }, 8, ["class", "disabled"])) : createCommentVNode("v-if", true)
                        ]),
                        _: 1
                        /* STABLE */
                      }, 8, ["dropdown-items"]),
                      props.parentData && props.parentData.type !== "array" ? (openBlock(), createBlock(_component_a_popconfirm, {
                        key: 1,
                        title: "\u786E\u5B9A\u8981\u79FB\u9664\u5417\uFF1F",
                        "ok-text": "\u786E\u8BA4",
                        "cancel-text": "\u53D6\u6D88",
                        placement: "topRight",
                        "overlay-class-name": unref(bem).e("popconfirm"),
                        disabled: unref(disabled),
                        onConfirm: _cache[7] || (_cache[7] = ($event) => handleConfirm(props.parentData, innerData.value))
                      }, {
                        default: withCtx(() => [
                          createVNode(_component_ll_button, {
                            type: "link",
                            disabled: unref(disabled),
                            class: normalizeClass(unref(bem).m("table-icon"))
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_ll_icon, { "icon-name": "icon-remove" })
                            ]),
                            _: 1
                            /* STABLE */
                          }, 8, ["disabled", "class"])
                        ]),
                        _: 1
                        /* STABLE */
                      }, 8, ["overlay-class-name", "disabled"])) : createCommentVNode("v-if", true)
                    ],
                    2
                    /* CLASS */
                  )
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          }, 8, ["class"]),
          expanded.value ? (openBlock(), createElementBlock(
            Fragment,
            { key: 0 },
            [
              innerData.value.type === "object" && innerData.value.children && innerData.value.children.length === 0 ? (openBlock(), createBlock(_component_a_row, {
                key: 0,
                gutter: 20,
                class: normalizeClass(unref(bem).e("table-row"))
              }, {
                default: withCtx(() => [
                  createVNode(_component_a_col, {
                    style: { "display": "flex" },
                    span: 7,
                    class: normalizeClass(unref(bem).e("table-col"))
                  }, {
                    default: withCtx(() => [
                      createElementVNode(
                        "p",
                        {
                          style: normalizeStyle({ width: 10 * props.layer + "px" })
                        },
                        null,
                        4
                        /* STYLE */
                      ),
                      createElementVNode(
                        "div",
                        {
                          style: { "margin-right": "30px" },
                          class: normalizeClass(unref(bem).m("table-row-icon"))
                        },
                        null,
                        2
                        /* CLASS */
                      ),
                      createVNode(_component_ll_input, {
                        value: addValue.value,
                        "onUpdate:value": _cache[8] || (_cache[8] = ($event) => addValue.value = $event),
                        placeholder: "\u6DFB\u52A0\u5B57\u6BB5\u540D",
                        bordered: false,
                        disabled: unref(disabled),
                        onInput: handleInput
                      }, null, 8, ["value", "disabled"])
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["class"])
                ]),
                _: 1
                /* STABLE */
              }, 8, ["class"])) : createCommentVNode("v-if", true),
              innerData.value.children && innerData.value.children.length > 0 ? (openBlock(true), createElementBlock(
                Fragment,
                { key: 1 },
                renderList(innerData.value.children, (child, index) => {
                  return openBlock(), createBlock(_sfc_main, {
                    key: index,
                    "parent-data": innerData.value,
                    list: innerData.value.children,
                    data: child,
                    layer: props.layer + 1,
                    "tree-key": props.treeKey + "-" + (index + 1),
                    onChange: handleRowChange
                  }, null, 8, ["parent-data", "list", "data", "layer", "tree-key"]);
                }),
                128
                /* KEYED_FRAGMENT */
              )) : createCommentVNode("v-if", true)
            ],
            64
            /* STABLE_FRAGMENT */
          )) : createCommentVNode("v-if", true)
        ],
        64
        /* STABLE_FRAGMENT */
      );
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=json-xml-table-row.vue2.mjs.map
