negotiation-summary-section.js 1.07 KB
const {
	buildUpgradeIconUrl,
	FORM_NAV_ICON_LEFT,
	FORM_NAV_ICON_RIGHT
} = require('../../utils/upgrade-icon-url.js')

Component({
	properties: {
		label: {
			type: String,
			value: ''
		},
		recordRows: {
			type: Array,
			value: []
		},
		activeIndex: {
			type: Number,
			value: 0
		}
	},

	data: {
		visibleFields: [],
		navIconLeft: '',
		navIconRight: ''
	},

	lifetimes: {
		attached() {
			this.setData({
				navIconLeft: buildUpgradeIconUrl(FORM_NAV_ICON_LEFT),
				navIconRight: buildUpgradeIconUrl(FORM_NAV_ICON_RIGHT)
			})
		}
	},

	observers: {
		'recordRows, activeIndex'(recordRows, activeIndex) {
			const rows = Array.isArray(recordRows) ? recordRows : []
			const index = Number(activeIndex)
			const safeIndex = Number.isFinite(index) && index >= 0 ? index : 0
			const row = rows[safeIndex] || { fields: [] }
			this.setData({
				visibleFields: Array.isArray(row.fields) ? row.fields : []
			})
		}
	},

	methods: {
		onNav(e) {
			const direction = Number(e.currentTarget.dataset.direction)
			if (!direction) return
			this.triggerEvent('nav', { direction })
		}
	}
})