// 本文件由FirstUI授权予新疆天衡创新研究院有限公司（手机号：  186140   7  2   549，身份证尾号：5A07X5）专用，请尊重知识产权，勿私下传播，违者追究法律责任。
function scroll(event, ownerInstance) {
	var detail = event.detail
	var scrollWidth = detail.scrollWidth
	var scrollLeft = detail.scrollLeft
	var dataset = event.currentTarget.dataset
	var width = dataset.width || 0
	var scrollBarWidth = dataset.bgwidth || 0
	var blockWidth = dataset.blockwidth || 0
	var x = scrollLeft / (scrollWidth - width) * (scrollBarWidth - blockWidth)
	setBarStyle(ownerInstance, x)
}

function scrolltolower(event, ownerInstance) {
	ownerInstance.callMethod('scrollEvent', 'right')
	var dataset = event.currentTarget.dataset
	var scrollBarWidth = dataset.bgwidth || 0
	var blockWidth = dataset.blockwidth || 0
	setBarStyle(ownerInstance, scrollBarWidth - blockWidth)
}

function scrolltoupper(event, ownerInstance) {
	ownerInstance.callMethod('scrollEvent', 'left')
	setBarStyle(ownerInstance, 0)
}

function setBarStyle(ownerInstance, x) {
	var block = ownerInstance.selectComponent('.fui-hor__scroll-indicator')
	block && block.setStyle({
		transform: 'translate3d(' + x + 'px,0,0)'
	})

}

module.exports = {
	scroll: scroll,
	scrolltolower: scrolltolower,
	scrolltoupper: scrolltoupper
}