"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"), _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _amosAntd = require("amos-antd"), _processor = require("../../../utils/processor"), _urlFormat = _interopRequireDefault(require("amos-processor/lib/utils/urlFormat")), _DateUtil = require("../../../utils/DateUtil"), _urlConsts = _interopRequireDefault(require("../../../consts/urlConsts")), _amosFramework = require("amos-framework"), _amosTool = require("amos-tool");

require("./protocol-detail.scss");

var _validate = require("./../../common/utils/validate");

function _createSuper(e) {
    var t = _isNativeReflectConstruct();
    return function() {
        var a, l = (0, _getPrototypeOf2.default)(e);
        if (t) {
            var r = (0, _getPrototypeOf2.default)(this).constructor;
            a = Reflect.construct(l, arguments, r);
        } else a = l.apply(this, arguments);
        return (0, _possibleConstructorReturn2.default)(this, a);
    };
}

function _isNativeReflectConstruct() {
    if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
    if (Reflect.construct.sham) return !1;
    if ("function" == typeof Proxy) return !0;
    try {
        return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), 
        !0;
    } catch (e) {
        return !1;
    }
}

var maxDescLength = 250, RadioGroup = _amosAntd.Radio.Group, FormItem = _amosAntd.Form.Item, createForm = _amosAntd.Form.create(), TextArea = _amosAntd.Input.TextArea, textAreaStyle = {
    minRows: 12,
    maxRows: 16
}, PrivateProtocolDetail = function(e) {
    (0, _inherits2.default)(a, e);
    var t = _createSuper(a);
    function a(e) {
        var l;
        return (0, _classCallCheck2.default)(this, a), l = t.call(this, e), (0, _defineProperty2.default)((0, 
        _assertThisInitialized2.default)(l), "requestProtocolDetail", (function(e) {
            _processor.AmosFetch.get((0, _urlFormat.default)(_urlConsts.default.protocolDetail, {
                id: e
            })).then((function(e) {
                if (e.ok) return e.json();
                throw new Error("从服务端获取数据失败！");
            })).then((function(e) {
                "SUCCESS" === e.result && null !== e.dataList && l.setState({
                    detailData: e.dataList
                });
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "handleEditParam", (function(e) {
            var t = l.props.form.getFieldValue("protocolName"), a = l.props.form.getFieldValue("protocolVersion"), r = l.props.form.getFieldValue("descr");
            l.props.form.getFieldValue("time");
            l.setState({
                textEdit: !l.state.textEdit
            }), l.state.textEdit && l.props.form.validateFields((function(e, o) {
                if (e) l.setState({
                    textEdit: !0
                }); else {
                    var i = l.state.detailData, n = (0, _extends2.default)(i, {
                        name: t,
                        version: a,
                        descr: r,
                        dicIdScriptLang: null,
                        scriptLang: null
                    });
                    l.submitBasicData(n);
                }
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "submitBasicData", (function(e) {
            _processor.AmosFetch.post(_urlConsts.default.protocolSave, {
                data: e
            }).then((function(e) {
                if (e.ok) return e.json();
                throw new Error("从服务端获取数据失败！");
            })).then((function(e) {
                "SUCCESS" === e.result ? _amosFramework.message.success("编辑成功！") : (l.setState({
                    textEdit: !0
                }), _amosFramework.message.danger("编辑失败！"));
            }));
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "handleEditCode", (function(e) {
            var t = l.props.form.getFieldValue("realization"), a = (0, _amosTool.trim)(l.props.form.getFieldValue("code"));
            a && "" !== a ? (l.setState({
                scriptEdit: !l.state.scriptEdit
            }), l.state.scriptEdit && l.props.form.validateFields((function(e, r) {
                if (e) l.setState({
                    textEdit: !0
                }); else {
                    var o = l.state.detailData, i = {
                        id: o.id,
                        dicIdScriptLang: t,
                        scriptCode: a
                    };
                    l.submitBasicData(i), l.setState({
                        detailData: (0, _extends2.default)(o, i)
                    });
                }
            }))) : _amosAntd.Modal.info({
                title: "提示",
                content: "代码不能为空！",
                okText: "确定"
            });
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "handleAddProperty", (function(e) {})), 
        (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "handleDebug", (function(e) {
            _amosFramework.message.success("测试成功！");
        })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(l), "delProperty", (function(e) {})), 
        l.state = {
            textEdit: !1,
            scriptEdit: !1,
            detailData: {}
        }, l;
    }
    return (0, _createClass2.default)(a, [ {
        key: "componentWillMount",
        value: function() {}
    }, {
        key: "componentDidMount",
        value: function() {
            var e = this.props.selected;
            e && e.id && this.requestProtocolDetail(e.id);
        }
    }, {
        key: "render",
        value: function() {
            var e = this.props.form.getFieldProps, t = this.state, a = t.textEdit, l = t.scriptEdit, r = t.detailData, o = !1 === a ? "protocol-detail-title-button" : "protocol-detail-title-button-hidden", i = !1 === a ? "protocol-detail-title-button-hidden" : "protocol-detail-title-button", n = !1 === a ? "protocol-detail-title-content" : "protocol-detail-title-content-hidden", s = !1 === a ? "protocol-detail-title-content-hidden" : "protocol-detail-title-content", c = !1 === l ? "protocol-detail-property-button" : "protocol-detail-property-button-hidden", d = !1 === l ? "protocol-detail-property-button-hidden" : "protocol-detail-property-button", u = !1 === l ? "protocol-detail-property-content" : "protocol-detail-property-content-hidden", p = !1 === l ? "protocol-detail-property-content-hidden" : "protocol-detail-property-content", m = r.visibility, f = this.props.scriptLangOptions.map((function(e) {
                return e.value === r.dicIdScriptLang ? "Groovy" === e.label ? _react.default.createElement(_amosAntd.Radio, {
                    checked: !0,
                    key: e.value,
                    value: "".concat(e.value)
                }, e.label) : _react.default.createElement(_amosAntd.Radio, {
                    checked: !0,
                    key: e.value,
                    value: "".concat(e.value),
                    disabled: !0
                }, e.label) : "Groovy" === e.label ? _react.default.createElement(_amosAntd.Radio, {
                    key: e.value,
                    value: "".concat(e.value)
                }, e.label) : _react.default.createElement(_amosAntd.Radio, {
                    key: e.value,
                    value: "".concat(e.value),
                    disabled: !0
                }, e.label);
            })), _ = e("protocolName", {
                initialValue: r.name || "",
                rules: [ {
                    required: !0,
                    message: "名称不能为空！"
                }, {
                    validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
                } ]
            }), h = e("protocolVersion", {
                initialValue: r.version || "",
                rules: [ {
                    required: !0,
                    message: "版本不能为空！"
                }, {
                    validator: (0, _validate.noSpaceLengthValidate)(20, !0, "版本不能为空！")
                } ]
            }), E = e("realization", {
                initialValue: "".concat(r.dicIdScriptLang) || "1",
                rules: [ {
                    required: !1,
                    message: "实现方式不能为空！"
                } ]
            }), b = e("code", {
                initialValue: r.scriptCode || "",
                rules: [ {
                    required: !1,
                    message: "代码不能为空！"
                } ]
            }), v = e("descr", {
                initialValue: r.descr || "",
                rules: [ {
                    validator: (0, _validate.noSpaceLengthValidate)(maxDescLength, !1, null)
                } ]
            });
            return console.log(r), _react.default.createElement("div", {
                className: "protocol-detail"
            }, _react.default.createElement("div", {
                className: "protocol-detail-title"
            }, _react.default.createElement("label", null, "基本信息"), 1 === m ? _react.default.createElement("span", null, _react.default.createElement("div", {
                onClick: this.handleEditParam,
                className: o
            }, _react.default.createElement("img", {
                src: require("./../../../assets/iot/img/list_edit.png"),
                alt: ""
            }), _react.default.createElement("label", null, "编辑")), _react.default.createElement("div", {
                onClick: this.handleEditParam,
                className: i
            }, _react.default.createElement("img", {
                src: require("./../../../assets/iot/img/list_edit.png"),
                alt: ""
            }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
                className: n
            }, _react.default.createElement("span", null, _react.default.createElement("label", {
                className: "protocol-title-name"
            }, "协议名称： ", r.name || "")), _react.default.createElement("span", null, _react.default.createElement("label", {
                className: "protocol-title-name"
            }, "版  本： ", r.version || "")), _react.default.createElement("span", null, _react.default.createElement("label", {
                className: "protocol-title-name"
            }, "时  间： ", r.createTime ? (0, _DateUtil.dateToStr)(r.createTime) : "")), _react.default.createElement("span", {
                style: {
                    height: "70px",
                    "overflow-y": "auto",
                    padding: "5px"
                }
            }, _react.default.createElement("label", {
                className: "protocol-title-name"
            }, "说  明： ", r.descr || ""))), _react.default.createElement("div", {
                className: s
            }, _react.default.createElement(_amosAntd.Form, {
                horizontal: !0,
                onSubmit: this.handleSubmit
            }, _react.default.createElement(FormItem, {
                label: "名称: ",
                labelCol: {
                    span: 2
                },
                wrapperCol: {
                    span: 22
                }
            }, _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
                disabled: !a
            }, _, {
                style: {
                    width: 250
                }
            }))), _react.default.createElement(FormItem, {
                label: "版本: ",
                labelCol: {
                    span: 2
                },
                wrapperCol: {
                    span: 22
                }
            }, _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
                disabled: !a
            }, h, {
                style: {
                    width: 250
                }
            }))), _react.default.createElement(FormItem, {
                label: "说明: ",
                labelCol: {
                    span: 2
                },
                wrapperCol: {
                    span: 22
                }
            }, _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
                disabled: !a
            }, v, {
                style: {
                    width: 250
                }
            }))))), _react.default.createElement("div", {
                className: "protocol-detail-property"
            }, _react.default.createElement("label", null, "脚本信息"), 1 === m ? _react.default.createElement("span", null, _react.default.createElement("div", {
                onClick: this.handleEditCode,
                className: c
            }, _react.default.createElement("img", {
                src: require("./../../../assets/iot/img/list_edit.png"),
                alt: ""
            }), _react.default.createElement("label", null, "编辑")), _react.default.createElement("div", {
                onClick: this.handleEditCode,
                className: d
            }, _react.default.createElement("img", {
                src: require("./../../../assets/iot/img/list_edit.png"),
                alt: ""
            }), _react.default.createElement("label", null, "确认"))) : null), _react.default.createElement("div", {
                className: u
            }, _react.default.createElement("span", null, _react.default.createElement("label", {
                className: "protocol-content-name"
            }, "实现方式： "), _react.default.createElement("div", {
                className: "protocol-content-value"
            }, _react.default.createElement(RadioGroup, null, f))), _react.default.createElement("span", {
                style: {
                    height: "calc(100% - 50px)"
                }
            }, _react.default.createElement("label", {
                className: "protocol-content-name"
            }, "代  码： "), _react.default.createElement("div", {
                className: "protocol-content-code"
            }, _react.default.createElement(TextArea, {
                value: r.scriptCode || ""
            })))), _react.default.createElement("div", {
                className: p
            }, _react.default.createElement(_amosAntd.Form, {
                horizontal: !0,
                onSubmit: this.handleSubmit
            }, _react.default.createElement(FormItem, {
                label: "实现方式: ",
                labelCol: {
                    span: 2
                },
                wrapperCol: {
                    span: 22,
                    offset: 0
                }
            }, _react.default.createElement(RadioGroup, E, f)), _react.default.createElement(FormItem, {
                label: "代码: ",
                labelCol: {
                    span: 2
                },
                wrapperCol: {
                    span: 12
                }
            }, _react.default.createElement(TextArea, b)))));
        }
    } ]), a;
}(_react.Component);

PrivateProtocolDetail.displayName = "PrivateProtocolDetail", PrivateProtocolDetail.propTypes = {
    form: _propTypes.default.any,
    callBack: _propTypes.default.func
};

var _default = createForm(PrivateProtocolDetail);

exports.default = _default;