"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const React = require('react');
const typings = require('./margin-padding.type');
const mobx_react_1 = require('mobx-react');
const nt_web_margin_padding_editor_1 = require('nt-web-margin-padding-editor');
const _ = require('lodash');
let EditComponentText = class EditComponentText extends React.Component {
    constructor(...args) {
        super(...args);
        this.state = new typings.State();
        this.marginPaddingValues = {};
        this.marginPaddingOldValue = {};
    }
    componentWillMount() {
        this.componentInfo = this.props.viewport.components.get(this.props.viewport.currentEditComponentMapUniqueKey);
        this.marginPaddingValues['marginLeft'] = this.componentInfo.props['marginLeft'];
        this.marginPaddingValues['marginTop'] = this.componentInfo.props['marginTop'];
        this.marginPaddingValues['marginRight'] = this.componentInfo.props['marginRight'];
        this.marginPaddingValues['marginBottom'] = this.componentInfo.props['marginBottom'];
        this.marginPaddingValues['paddingLeft'] = this.componentInfo.props['paddingLeft'];
        this.marginPaddingValues['paddingTop'] = this.componentInfo.props['paddingTop'];
        this.marginPaddingValues['paddingRight'] = this.componentInfo.props['paddingRight'];
        this.marginPaddingValues['paddingBottom'] = this.componentInfo.props['paddingBottom'];
        this.marginPaddingOldValue = _.cloneDeep(this.marginPaddingValues);
    }
    handleChange(name, value) {
        // 直接改值
        this.marginPaddingValues[name] = value;
        this.props.viewport.updateComponentOptionsValueByOptions(this.props.viewport.currentEditComponentMapUniqueKey, this.props.editOption, this.marginPaddingValues);
    }
    handleFinalChange(name, value) {
        // 先把值改回去
        this.props.viewport.updateComponentOptionsValueByOptions(this.props.viewport.currentEditComponentMapUniqueKey, this.props.editOption, this.marginPaddingOldValue);
        // 直接记录历史
        this.marginPaddingValues[name] = value;
        this.marginPaddingOldValue = _.cloneDeep(this.marginPaddingValues);
        this.props.viewport.updateComponentOptionsValue(this.props.editOption, this.marginPaddingValues);
    }
    render() {
        return (<nt_web_margin_padding_editor_1.default size={160} marginLeft={this.componentInfo.props['marginLeft']} marginTop={this.componentInfo.props['marginTop']} marginRight={this.componentInfo.props['marginRight']} marginBottom={this.componentInfo.props['marginBottom']} paddingLeft={this.componentInfo.props['paddingLeft']} paddingTop={this.componentInfo.props['paddingTop']} paddingRight={this.componentInfo.props['paddingRight']} paddingBottom={this.componentInfo.props['paddingBottom']} onChange={this.handleChange.bind(this)} onFinalChange={this.handleFinalChange.bind(this)}/>);
    }
};
EditComponentText.defaultProps = new typings.Props();
EditComponentText = __decorate([
    mobx_react_1.inject('viewport'),
    mobx_react_1.observer
], EditComponentText);
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = EditComponentText;
