<?php require_once(ROOT_URL . '/includes/asset/asset_functions.php');

switch ($_REQUEST['view']) {
    default:
        break;
    case "edit_attached":
        require(ROOT_URL . '/includes/asset/asset_edit.php');
        break;
    case "new_attached":
        require(ROOT_URL . '/includes/asset/asset_new.php');
        break;
}
?>

<script>
    const set = '<?= $set ?>';
    const clientnumber = '<?= $d[0] ?>';
    const tenant = '<?= $systemUser ?>';
    const additionalContent = document.getElementById('additionalContent');
    const pspCheck = document.getElementById('pspCheck');
    const levCheck = document.getElementById('levCheck');
    document.addEventListener('DOMContentLoaded', function() {

        // autofill Function
        function autofill(f, s, t) {

            var dest = ROOT_URL + '/includes/asset/asset_options.php?form=' + f + '&source=' + s + '&type=' + t;
            loadModalContent(dest, "popupBox", "modal-xl", 1060, "true", "Auto Fill");
        }



        // Window Resize Handler (Responsive Behavior)
        function adjustArrowIcons() {
            const isSmallScreen = window.innerWidth < 750;
            const arrowElements = document.querySelectorAll('.dirarrow i');

            arrowElements.forEach(arrow => {
                arrow.classList.toggle('fa-arrow-circle-o-right', !isSmallScreen);
                arrow.classList.toggle('fa-arrow-circle-o-down', isSmallScreen);
            });
        }

        adjustArrowIcons(); // Initial adjustment
        window.addEventListener('resize', adjustArrowIcons);

        // resetDD Function
        function resetDD() {
            document.getElementById('clientOpt').value = '';
            document.getElementById('siteOpt').value = '';
            document.getElementById('plantOpt').value = '';
            document.getElementById('confirmbox').style.display = 'none';
        }

        document.addEventListener('change', function(event) {
            const wsSelect = event.target && event.target.id === 'wsSelect' ? event.target : null;
            if (!wsSelect || !wsSelect.value) return;

            const descSelect = document.getElementById('desc');
            const desc = descSelect && descSelect.selectedIndex >= 0
                ? descSelect.options[descSelect.selectedIndex].text
                : 'this item';
            const ws = wsSelect.options[wsSelect.selectedIndex].text;
            const dest = `<p>Do you wish to attach <strong>${desc}</strong> to written Scheme <strong>${ws}</strong></p>`;

            loadModalContent(dest, "confirmBox", "modal-md", 1060, "true", "Attach to scheme",
                "cancelConfirm", () => killModal('confirmBox'));
        });
    });
</script>
