import BaseFormControl from '../../baseFormControl'
import { tpl } from './tpl'
import './style.scss'
import DynamicImage from '../dynamicImage/DynamicImage'
import JDLink from '../link'
import { AppType } from '../../../../util/channelUtil';
class DynamicImageModule 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 || {}
        this.dynamicImg = new DynamicImage({
            domData: {
                name: 'dynamicImage',
                title: '',
                node: this.element.find('.J_dynamicImg'),
            },
            moduleData: moduleData,
            format: '1125, 210-1440',
        })
        if (page_data.clientType == 'M' && !window.page_data.isSDKM && window.page_data.appType != AppType.M) {
            this.linkToolTabs = this.linkToolTabs.concat('financeCouponLink')
        }
        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 DynamicImageModule