define(['jquery', 'mage/translate'], function ($, $t) { 'use strict'; return function (config, element) { var $root = $(element), rawConfig = $root.find('[data-role="parameter-config"]').text(), data = rawConfig ? JSON.parse(rawConfig) : {}, products = data.products || [], applicationOptions = data.applicationOptions || [], messages = data.messages || {}, maximum = 6, selected = [], mode = 'key', keyParameters = [ 'Density(g/cm3) (unit to be confirmed)', 'Heat Distortion Temperature(°C)', 'Tensile Strength (XY) (MPa)', 'Elongation at Break (XY) (%)', 'Flexural Strength (XY) (MPa)', 'Flexural Modulus (XY) (MPa)', 'IZOD Impact Strength (XY) (kJ/m²)', 'Extruder Temperature(°C)', 'Bed Temperature(°C)', 'Fan Speed(%)', 'Printing Speed(mm/s) (high-speed printing parameter)', 'Printing Recommendation', 'Drying' ], $seriesList = $root.find('[data-role="series-list"]'), $selectedMaterials = $root.find('[data-role="selected-materials"]'), $notice = $root.find('[data-role="material-notice"]'), $selectionCount = $root.find('[data-role="selection-count"]'), $comparisonCount = $root.find('[data-role="comparison-count"]'), $resultCount = $root.find('[data-role="result-count"]'), $placeholder = $root.find('[data-role="comparison-placeholder"]'), $tableWrap = $root.find('[data-role="comparison-table-wrap"]'), $head = $root.find('[data-role="comparison-head"]'), $body = $root.find('[data-role="comparison-body"]'); function selectedBase() { return $root.find('[data-role="base-filter"]:checked').val() || ''; } function productsForBase() { var base = selectedBase(); return $.grep(products, function (product) { return product.base === base; }); } function primaryApplication(product) { return product.applications && product.applications.length ? product.applications[0] : 'other'; } function applicationLabel(value) { var option = applicationOptions.find(function (item) { return item.value === value; }); return option ? option.label : $t('Other Series'); } function isSelected(id) { return $.inArray(id, selected) !== -1; } function findProduct(id) { return products.find(function (product) { return product.id === id; }); } function renderSeries() { var baseProducts = productsForBase(), groups = {}; $.each(baseProducts, function (_, product) { var application = primaryApplication(product); groups[application] = groups[application] || []; groups[application].push(product); }); $seriesList.empty(); $.each(applicationOptions, function (_, option) { var groupProducts = groups[option.value] || []; if (!groupProducts.length) { return; } renderSeriesRow(option.label, groupProducts); delete groups[option.value]; }); $.each(groups, function (application, groupProducts) { renderSeriesRow(applicationLabel(application), groupProducts); }); $resultCount.text(baseProducts.length); updateSelection(); } function renderSeriesRow(label, groupProducts) { var $row = $('
', {'class': 'esun-parameter-comparison__series-row'}), $label = $('
', {'class': 'esun-parameter-comparison__series-name'}), $products = $('
', {'class': 'esun-parameter-comparison__series-products'}); $label.append($('', {text: label}), $('', {text: groupProducts.length})); $.each(groupProducts, function (_, product) { $('