
if (GetLocale() == "zhCN") then
	MYINVENTORY_ENABLE = "整合玩家背包";
	MYINVENTORY_CONFIG = "设置参数";
	MYBANK_ENABLE = "整合银行背包";
	MYBANK_CONFIG = "设置参数";
	MYBANK_OPEN_TEXT = "打开银行背包";
	PUI_ENABLE_TEXT = "背包整理";
	PUI_ENABLE_TOOLTIP = "将你背包里的物品按种类整理好！";
	PUB_ENABLE_TEXT = "银行整理";
	PUB_ENABLE_TOOLTIP = "将你银行里的物品按种类整理好！";
end

if (IsConfigurableAddOn("MyInventory") or IsConfigurableAddOn("MyBank") or IsConfigurableAddOn("PackupInventory")) then
	ModManagement_RegisterMod(
		"BagIntegration",
		"Interface\\Icons\\INV_Misc_Bag_13",
		MOD_BAG_INTEGRATION_TITLE,
		"",
		nil
	);
end

if (IsConfigurableAddOn("MyInventory")) then
	ModManagement_RegisterCheckBox(
		"BagIntegration",
		MYINVENTORY_ENABLE,
		nil,
		"EnableMyInventory",
		1,
		function (arg)
			if ( arg == 1 ) then
				if (not IsAddOnLoaded("MyInventory")) then
					LoadAddOn("MyInventory");
				end

				if (IsAddOnLoaded("MyInventory")) then
					if ( not MyInventory_Enabled ) then
						MyInventoryFrame:RegisterEvent("BAG_UPDATE");
						MyInventoryFrame:RegisterEvent("BAG_UPDATE_COOLDOWN");
						MyInventoryFrame:RegisterEvent("ITEM_LOCK_CHANGED");
						MyInventoryFrame:RegisterEvent("UPDATE_INVENTORY_ALERTS");
						MyInventory_Register();

						MyInventory_Setup_Hooks(1);
						MyInventory_Loaded = true;
						MyInventory_InitializeProfile();

						MyInventory_Enabled = 1;

						MIStealBackpackButton:Show();
						MIStealItBag0Slot:Show();
						MIStealItBag1Slot:Show();
						MIStealItBag2Slot:Show();
						MIStealItBag3Slot:Show();

						MIStealBackpackButton:GetParent():EnableMouse(0);
						MIStealItBag0Slot:GetParent():EnableMouse(0);
						MIStealItBag1Slot:GetParent():EnableMouse(0);
						MIStealItBag2Slot:GetParent():EnableMouse(0);
						MIStealItBag3Slot:GetParent():EnableMouse(0);
					end
				end
			else
				if (IsAddOnLoaded("MyInventory")) then
					if ( MyInventory_Enabled ) then
						MyInventory_Setup_Hooks(nil);
						MyInventory_Loaded = false;

						MyInventoryFrame:UnregisterEvent("BAG_UPDATE");
						MyInventoryFrame:UnregisterEvent("BAG_UPDATE_COOLDOWN");
						MyInventoryFrame:UnregisterEvent("ITEM_LOCK_CHANGED");
						MyInventoryFrame:UnregisterEvent("UPDATE_INVENTORY_ALERTS");

						MIStealBackpackButton:Hide();
						MIStealItBag0Slot:Hide();
						MIStealItBag1Slot:Hide();
						MIStealItBag2Slot:Hide();
						MIStealItBag3Slot:Hide();


						MIStealBackpackButton:GetParent():EnableMouse(1);
						MIStealItBag0Slot:GetParent():EnableMouse(1);
						MIStealItBag1Slot:GetParent():EnableMouse(1);
						MIStealItBag2Slot:GetParent():EnableMouse(1);
						MIStealItBag3Slot:GetParent():EnableMouse(1);

						MyInventory_Enabled = nil;
					end
				end
			end
		end
	);

	ModManagement_RegisterButton(
		"BagIntegration",
		MYINVENTORY_CONFIG,
		function ()
			if (IsAddOnLoaded("MyInventory")) then
				ShowUIPanel(MyInventoryOptionsFrame);
			end
		end
	);
end

if (IsConfigurableAddOn("MyBank")) then
	ModManagement_RegisterCheckBox(
		"BagIntegration",
		MYBANK_ENABLE,
		nil,
		"EnableMyBank",
		1,
		function (arg)
			if (arg == 1) then
				if (not IsAddOnLoaded("MyBank")) then
					LoadAddOn("MyBank");
				end

				if (IsAddOnLoaded("MyBank")) then
					MyBank_Toggle(true);
				end
			else
				if (IsAddOnLoaded("MyBank")) then
					MyBank_Toggle(false);
				end
			end
		end
	);

    ModManagement_RegisterButton(
		"BagIntegration",
		MYBANK_CONFIG,
		function ()
			if (IsAddOnLoaded("MyBank")) then
				ShowUIPanel(MyBankConfigFrame);
			end
		end
	);

	 ModManagement_RegisterButton(
		"MyBank",
		 MYBANK_OPEN_TEXT,
		 function ()		
			if (IsAddOnLoaded("MyBank")) then
				ToggleMyBankFrame()	;
				HideUIPanel(ModManagementFrame);
			end
		end	
	);
end

if (IsConfigurableAddOn("PackupInventory")) then
	ModManagement_RegisterCheckBox(
		"BagIntegration",
		PUI_ENABLE_TEXT,
		PUI_ENABLE_TOOLTIP,
		"Enable_PUI",
		1,
		function (arg)	          
			if (arg == 1) then	
				if (not IsAddOnLoaded("PackupInventory")) then
					LoadAddOn("PackupInventory");
				end
				if (IsAddOnLoaded("PackupInventory")) then
					PUI_Toggle(true);
				end							
			else
				if (IsAddOnLoaded("PackupInventory")) then
					PUI_Toggle(false);
				end
			end
		end
	);	
	ModManagement_RegisterCheckBox(
		"BagIntegration",
		PUB_ENABLE_TEXT,
		PUB_ENABLE_TOOLTIP,
		"Enable_PUB",
		1,
		function (arg)	          
			if (arg == 1) then
				if (not IsAddOnLoaded("PackupInventory")) then
					LoadAddOn("PackupInventory");
				end
				if (IsAddOnLoaded("PackupInventory")) then
					PUB_Toggle(true);
				end
			else
				if (IsAddOnLoaded("PackupInventory")) then
					PUB_Toggle(false);
				end
			end
		end
	);
end