import BaseFormControl from '../../baseFormControl';
import {tpl} from './tpl';
import './style.scss';
import DynamicImage from '../dynamicImage/DynamicImage';
import JDLink from "../link";
class DynamicImageModuleOptionPic extends BaseFormControl {
    constructor(config) {
        super(config);
        this.linkToolTabs = ['custom', 'frequent', 'product', 'shopCategory'];
        this.render();
    }
    
    _getConfig(config) {
        return $.extend(true, {}, {
            domData: {},
            moduleData: {},
        }, config);
    }
    
    render() {
        this.appendFormControl(tpl);
        let moduleData = this.config.moduleData || {};
        const validate = this.config.domData.validate || {};
        let _w = validate.width || '10-1125',
            _h = validate.height || '10-3000';
        this.dynamicImg = new DynamicImage({
            domData:{
                name: 'dynamicImage',
                title: '',
                node: this.element.find('.J_dynamicImg')
            },
            moduleData: moduleData,
            format: `${_w}, ${_h}`
        });
        let JDLinkConfig = {
            domData: {
                name: 'linkInfo',
                title: '链接',
                node: this.element.find('.J_linkInfo')
            },
            linkName: false,
            addLink: false,
            operation: false,
            tab: this.linkToolTabs,
            moduleData:moduleData.linkInfo || {}
        };
        this.link = new JDLink(JDLinkConfig);
    }
    setData() {
    }
    
    validateData() {
        return true;
    }
    
    getData() {
        let key = this.config.domData.name;
        let imageData = this.dynamicImg.getValue();
        let data = $.extend(true, {}, imageData, this.link.getData());
        let result = {};
        result[key] = data;
        return result;
    }
}
export default DynamicImageModuleOptionPic;