<%+cbi/valueheader%>
<div class="cbi-value-field" id="switch_dashboard_<%=self.option%>">
	<%:Collecting data...%>
</div>

<script type="text/javascript">//<![CDATA[
	var btn_type_<%=self.option%> = "<%=self.option%>";
	var switch_dashboard_<%=self.option%> = document.getElementById('switch_dashboard_<%=self.option%>');
	XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "dashboard_type")%>', null, function(x, status) {
      	if ( x && x.status == 200 ) {
			if ( btn_type_<%=self.option%> == "Dashboard" ) {
				if ( status.dashboard_type == "Meta" ) {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Official Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
				}
				else {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Meta Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Meta\')"/>';
				}
			}
			if ( btn_type_<%=self.option%> == "Yacd" ) {
				if ( status.yacd_type == "Meta" ) {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Official Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Official\')"/>';
				}
				else {
					switch_dashboard_<%=self.option%>.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch To Meta Version%>" onclick="return switch_dashboard(this, btn_type_<%=self.option%>, \'Meta\')"/>';
				}
			}
        }
	});
    
	function switch_dashboard(btn, name, type)
	{
		btn.disabled = true;
		btn.value = '<%:Downloading File...%>';
		XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "switch_dashboard")%>', {name: name, type : type}, function(x, status) {
			if ( x && x.status == 200 ) {
				if ( status.download_state == "1" ) {
					if ( type == "Meta" ) {
						if ( name == "Dashboard" ) {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Official Version%>" onclick="return switch_dashboard(this, \'Dashboard\', \'Official\')"/>';
						}
						else
						{
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Official Version%>" onclick="return switch_dashboard(this, \'Yacd\', \'Official\')"/>';
						}
					}
					else {
						if ( name == "Dashboard" ) {
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Meta Version%>" onclick="return switch_dashboard(this, \'Dashboard\', \'Meta\')"/>';
						}
						else
						{
							document.getElementById("switch_dashboard_"+name).innerHTML = '<input type="button" class="btn cbi-button cbi-button-reset" value="<%:Switch Successful%> - <%:Switch To Meta Version%>" onclick="return switch_dashboard(this, \'Yacd\', \'Meta\')"/>';
						}
					}
				}
				else if ( status.download_state == "2" ) {
					btn.value = '<%:Unzip Error%>';
				}
				else {
					btn.value = '<%:Switch Failed%>';
				}
			}
		});
		btn.disabled = false;
		return false; 
	}

//]]></script>
      
<%+cbi/valuefooter%>