'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.js');
require('../config/index.js');
require('./json-xml-table-row.vue.js');
require('./click-input.vue.js');
var createNamespace = require('../../../../utils/create-namespace.js');
var jsonXml = require('../config/json-xml.js');
var clickInput_vue_vue_type_script_setup_true_lang = require('./click-input.vue2.js');

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

exports.default = _sfc_main;
//# sourceMappingURL=json-xml-table-row.vue2.js.map
