function add_trigger_defined(){

    let container = document.createElement('div');
	container.style.fontSize = '30px';
	container.style.paddingLeft = '25px';
	

 // Title container for stacking
var titleContainer = document.createElement('div');
titleContainer.style.textAlign = 'left';

// Main Title
var sectionTitle = document.createElement('h2');
sectionTitle.textContent = 'Add Defined Trigger';
titleContainer.appendChild(sectionTitle);

// Subtitle
var subtitle = document.createElement('h2');
subtitle.textContent = 'Choose any bets to track like reds, odds, highs, straights, corners,streets etc etc on wins or loses in a row, then press add trigger button';
subtitle.style.fontWeight = 'normal';  // lighter than main title
subtitle.style.fontSize = '1.2em';     // smaller size
subtitle.style.marginTop = '0';
titleContainer.appendChild(subtitle);

container.appendChild(titleContainer);

let section_outside_bets = outside_bet_section();
container.appendChild(section_outside_bets);

return container;

}



function outside_bet_section() {
    let container = document.createElement('div');
    container.style.width = '90%';
    container.style.fontSize = '36px'; // larger base font
    container.style.display = 'flex';
    container.style.flexDirection = 'column';
    container.style.alignItems = 'center';
    container.style.justifyContent = 'center';
    container.style.gap = '35px';
    container.style.padding = '30px';

    // Input Box
    var evensSpins = document.createElement('input');
    evensSpins.type = 'number';
    evensSpins.id = "triggerEvensLosses";
    evensSpins.name = "triggerEvensLosses";
    evensSpins.style.width = '140px';
    evensSpins.style.height = '70px';
    evensSpins.style.fontSize = '36px';
    evensSpins.style.textAlign = 'center';
    evensSpins.style.borderRadius = '12px';
    evensSpins.style.border = '2px solid #ccc';
    container.appendChild(evensSpins);

    // Wins/Losses Dropdown
    var dropdown = document.createElement('select');
    dropdown.id = 'triggerEvensLossesDropDown';
    dropdown.style.width = '220px';
    dropdown.style.height = '70px';
    dropdown.style.fontSize = '36px';
    dropdown.style.borderRadius = '12px';

    var lossesOption = document.createElement('option');
    lossesOption.value = 'L';
    lossesOption.text = 'Losses';
    dropdown.appendChild(lossesOption);

    var winsOption = document.createElement('option');
    winsOption.value = 'W';
    winsOption.text = 'Wins';
    dropdown.appendChild(winsOption);

    container.appendChild(dropdown);

    // "in a row" Label
    var evenLabel = document.createElement('label');
    evenLabel.htmlFor = 'triggerEvensLosses';
    evenLabel.innerText = 'in a row';
    evenLabel.style.fontSize = '36px';
    container.appendChild(evenLabel);

  

    // Main Option Dropdown
    var selectElement = document.createElement('select');
    selectElement.id = 'triggerOptionDropdown';
    selectElement.style.width = '340px';
    selectElement.style.height = '70px';
    selectElement.style.fontSize = '36px';
    selectElement.style.borderRadius = '12px';

    const defaultValue = 'All';
    triggerDropDown.forEach(function (option) {
        var optionElement = document.createElement('option');
        optionElement.value = option.value;
        optionElement.textContent = option.text;
        if (option.value === defaultValue) {
            optionElement.selected = true;
        }
        selectElement.appendChild(optionElement);
    });
    container.appendChild(selectElement);

    // Add Trigger Button
    const defined_trigger_button = document.createElement('button');
    defined_trigger_button.innerText = "➕ Add Trigger";
    defined_trigger_button.id = "triggerOptionsButtons";
    defined_trigger_button.classList.add('triggerOptionsButtons');
    defined_trigger_button.style.fontSize = '36px';
    defined_trigger_button.style.height = '80px';
    defined_trigger_button.style.padding = '0 50px';
    defined_trigger_button.style.borderRadius = '14px';
    defined_trigger_button.style.backgroundColor = '#4285f4';
    defined_trigger_button.style.color = '#fff';
    defined_trigger_button.style.border = 'none';
    defined_trigger_button.style.cursor = 'pointer';
    defined_trigger_button.style.marginTop = '25px';

    defined_trigger_button.addEventListener('click', function () {
        outsideBetSelectionAddTrigger();
        displayTriggerPanel();
    });

    container.appendChild(defined_trigger_button);

    return container;
}



function outsideBetSelectionAddTrigger_old() {
	

	var triggerLoss = parseInt(document.getElementById('triggerEvensLosses').value);
	if (isNaN(triggerLoss) || triggerLoss < 1) {
		triggerLoss = 1;
		document.getElementById('triggerEvensLosses').value = 1;
	}

	var selectElement = document.getElementById('triggerOptionDropdown');
	var triggerOption = selectElement.value;
	var triggerText = selectElement.options[selectElement.selectedIndex].text;


	const indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss && triggerListItem[index] === triggerOption);

	const itemFound = indexFound !== -1;

	
	if (triggerOption === "AllOut") {

		var seletedItems = ["Even","Odd","Red","Black","High","Low","Dozen1","Dozen2","Dozen3","Row1","Row2","Row3"];
		triggerDropDown.forEach(group => {

			var indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss && triggerListItem[index] === group.value);

			var itemFound = indexFound !== -1;

			if (!itemFound && seletedItems.includes(group.value)) {
				addTriggerToTriggersList(triggerLoss, group.text, group.value);
			}

		});
	}

	if (triggerOption === "All") {

		var seletedItems = ["Even","Odd","Red","Black","High","Low","Dozen1","Dozen2","Dozen3","Row1","Row2","Row3","Quads","Splits","Streets","DoubleStreet"];
		triggerDropDown.forEach(group => {

			var indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss && triggerListItem[index] === group.value);

			var itemFound = indexFound !== -1;

			if (!itemFound && group.value !== "All" && group.value !=="StraightNumbers" && group.value !=="AllOut") {
				addTriggerToTriggersList(triggerLoss, group.text, group.value);
			}

		});
	}
	
	if (triggerOption !== "All" && triggerOption !== "AllOut") {

		if (!itemFound) {
			addTriggerToTriggersList(triggerLoss, triggerText, triggerOption);

		} 
		
	}

}

function outsideBetSelectionAddTrigger() {
	

	var triggerLoss = parseInt(document.getElementById('triggerEvensLosses').value);
	if (isNaN(triggerLoss) || triggerLoss < 1) {
		triggerLoss = 1;
		document.getElementById('triggerEvensLosses').value = 1;
	}

	var winLossIndicator = document.getElementById('triggerEvensLossesDropDown').value;

	var selectElement = document.getElementById('triggerOptionDropdown');
	var triggerOption = selectElement.value;
	var triggerText = selectElement.options[selectElement.selectedIndex].text;


	const indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss 
		&& triggerListItem[index] === triggerOption
		&& triggerListWinLoss[index] === winLossIndicator);

	const itemFound = indexFound !== -1;

	
	if (triggerOption === "AllOut") {

		var seletedItems = ["Even","Odd","Red","Black","High","Low","Dozen1","Dozen2","Dozen3","Row1","Row2","Row3"];
		triggerDropDown.forEach(group => {

			var indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss && triggerListItem[index] === group.value
			&& triggerListWinLoss[index] === winLossIndicator);

			var itemFound = indexFound !== -1;

			if (!itemFound && seletedItems.includes(group.value)) {
				addTriggerToTriggersList(triggerLoss, group.text, group.value, winLossIndicator);
			}

		});
	}

	if (triggerOption === "All") {

		var seletedItems = ["Even","Odd","Red","Black","High","Low","Dozen1","Dozen2","Dozen3","Row1","Row2","Row3","Quads","Splits","Streets","DoubleStreet"];
		triggerDropDown.forEach(group => {

			var indexFound = triggerListLoss.findIndex((value, index) => value === triggerLoss && triggerListItem[index] === group.value
			&& triggerListWinLoss[index] === winLossIndicator);

			var itemFound = indexFound !== -1;

			if (!itemFound && group.value !== "All" && group.value !=="StraightNumbers" && group.value !=="AllOut") {
				addTriggerToTriggersList(triggerLoss, group.text, group.value, winLossIndicator);
			}

		});
	}
	
	if (triggerOption !== "All" && triggerOption !== "AllOut") {

		if (!itemFound) {
			addTriggerToTriggersList(triggerLoss, triggerText, triggerOption, winLossIndicator);

		} else {
			showMessageAtCursor("Item already added.");

		}
		
	}

}

