{block name='selectionwizard-index'}
    {et_isShopVersionAtLeast value="5.6.0-rc.2" assign='shopIsAtLeast56'}
    {if isset($AWA)}
        {opcMountPoint id='opc_before_selection_wizard' inContainer=false}
        {block name='selectionwizard-index-script'}
            {inline_script}<script>
                {if $shopIsAtLeast56}
                    var nSelection_arr = [{$AWA->getSelections()|join:','}];
                {else}
                    var nSelection_arr = [{implode(',', $AWA->getSelections())}];
                {/if}

                function setSelectionWizardAnswerJS(kMerkmalWert)
                {
                    kMerkmalWert = parseInt(kMerkmalWert);
                    nSelection_arr.push(kMerkmalWert);

                    $.evo.io().call(
                        'setSelectionWizardAnswers',
                        [
                            '{$AWA->getLocationKeyName()}',
                            {$AWA->getLocationKeyId()},
                            {JTL\Shop::getLanguageID()},
                            nSelection_arr
                        ],
                        { },
                        function (error, data) {
                            resetSelectionWizardListeners();
                        }
                    );

                    return false;
                }

                function resetSelectionWizardAnswerJS(nFrage)
                {
                    nFrage = parseInt(nFrage);
                    nSelection_arr.splice(nFrage);

                    $.evo.io().call(
                        'setSelectionWizardAnswers',
                        [
                            '{$AWA->getLocationKeyName()}',
                            {$AWA->getLocationKeyId()},
                            {JTL\Shop::getLanguageID()},
                            nSelection_arr
                        ],
                        { },
                        function (error, data) {
                            resetSelectionWizardListeners();
                        }
                    );

                    return false;
                }

                function resetSelectionWizardListeners()
                {
                    $("[id^=kMerkmalWert]").on('change', function() {
                        return setSelectionWizardAnswerJS($(this).val());
                    } );
                    $(".question-edit").on('click', function() {
                        return resetSelectionWizardAnswerJS($(this).data('value'));
                    } );
                    $(".selection-wizard-answer").on('click', function() {
                        return setSelectionWizardAnswerJS($(this).data('value'));
                    } );
                }

                $(window).on("load", function() {
                    resetSelectionWizardListeners();
                } );
            </script>{/inline_script}
        {/block}
        {block name='selectionwizard-index-include-form'}
            {if isset($AWA) && !empty($AWA->getQuestions())}
                <div id="selectionwizard" class="selection-wizard-wrapper {if $container|default:true}container {/if}">
                    {include file='selectionwizard/form.tpl' AWA=$AWA}
                </div>
            {/if}
        {/block}
    {/if}
{/block}
