const InsuranceDetail = function () {
    function toggleSpecificBalance(buttonId, contentId, toggleStateId) {
        const $content = $(`#${contentId}`);
        const $button = $(`#${buttonId}`);
        const $state = $(`#${toggleStateId}`);

        //check if content needs to be shown/hidden
        if ($content.is(":visible")) {
            $content.hide(300, function () {
                resizeWindow(true);
            });
            $state.val(0);
            $button.attr('title', 'Show Details');
            $button.find('.fa').removeClass('fa-chevron-up').addClass('fa-chevron-down');
        } else {
            $content.show(300, function () {
                resizeWindow(true);
            });
            $state.val(1);
            $button.attr('title', 'Hide Details');
            $button.find('.fa').removeClass('fa-chevron-down').addClass('fa-chevron-up');
        }
    }

    function resizeWindow(animate) {
        const $childHeight = jQuery('#PolicyInformation').outerHeight();
        if (animate)
            jQuery('#insuranceIframeId', window.parent.document).animate({'height': $childHeight}, 300);
        else
            jQuery('#insuranceIframeId', window.parent.document).css({'height': $childHeight});
    }

    const init = function () {
        
        setPageTitle("Insurance Policy Details", true);
        
        resizeWindow(false);

        const $divsToToggle = jQuery('[data-toggle]');
        
        $divsToToggle.each(function () {
            $(this).on('click', function () {
                const toggleValues = $(this).attr('data-toggle').split(',').map(item => item.trim());
                toggleSpecificBalance(toggleValues[0], toggleValues[1], toggleValues[2]);
            });
        });
    };

    return {
        init
    };
}

jQuery(document).ready(function () {
    parent.closeModalSpinner();
    
    const insuranceDetail = new InsuranceDetail();

    insuranceDetail.init();
});         