<div id="custom-translation-table">
    [{$translationList}]
</div>

<script>
    (function () {
        const $table = $('custom-translation-table');
        const $exportButton = $('navbar_item_[{idoit\Module\Pro\SettingPage\CustomTranslation\CustomTranslation::NAVMODE_EXPORT}]');
        const $importButton = $('navbar_item_[{idoit\Module\Pro\SettingPage\CustomTranslation\CustomTranslation::NAVMODE_IMPORT}]');

        if ($exportButton) {
            $exportButton.writeAttribute('onclick', null);

            $exportButton.on('click', function () {
                if ($table.select('[name="id[]"]:checked').length === 0) {
                    idoit.Notify.info(' ### you need to select one!');
                    return;
                }

                if ($table.select('[name="id[]"]:checked').length !== 1) {
                    idoit.Notify.info(' ### only one!');
                    return;
                }

                const targetUrl = document.location.href.parseQuery();

                targetUrl['[{$smarty.const.C__GET__NAVMODE}]'] = '[{idoit\Module\Pro\SettingPage\CustomTranslation\CustomTranslation::NAVMODE_EXPORT}]';
                targetUrl.id = $table.down('[name="id[]"]:checked').getValue();

                document.location.href = '?' + Object.toQueryString(targetUrl);
            });
        }

        if ($importButton) {
            $importButton.writeAttribute('onclick', null);

            $importButton.on('click', function () {
                get_popup('custom_translation_import', '', 700, 300, { redirectUrl: document.location.href });
            });
        }
    })();
</script>
