﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Windows.Media.Imaging;

using Revit_Tools;

namespace Revit_Tools
{
    public class Availability : IExternalCommandAvailability
    {
        public bool IsCommandAvailable(
          UIApplication a,
          CategorySet b)
        {
            return true;
        }
    }

    public class ShowPanel : IExternalApplication
    {

        // define a method that will create our tab and button
        static void AddRibbonPanel(UIControlledApplication application)
        {
            // Create a custom ribbon tab
            String tabName = "Microdesk";
            application.CreateRibbonTab(tabName);

            // Add a new ribbon panel
            RibbonPanel ribbonPanel1 = application.CreateRibbonPanel(tabName, "Revit2Excel");
            RibbonPanel ribbonPanel2 = application.CreateRibbonPanel(tabName, "Excel2Revit");
            RibbonPanel ribbonPanel3 = application.CreateRibbonPanel(tabName, "Library2Project");
            RibbonPanel ribbonPanel4 = application.CreateRibbonPanel(tabName, "Purge");
            RibbonPanel ribbonPanel5 = application.CreateRibbonPanel(tabName, "AssignParameters");


            // Get dll assembly path
            string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;

            // create push button for CurveTotalLength
            PushButtonData b1Data = new PushButtonData(
                "Revit2Excel",
                "Revit2Excel",
                thisAssemblyPath,
                "Revit_Tools.Revit2Excel");

            PushButtonData b2Data = new PushButtonData(
               "Excel2Revit",
               "Excel2Revit",
               thisAssemblyPath,
               "Revit_Tools.Excel2Revit");

            PushButtonData b3Data = new PushButtonData(
               "Library2Project",
               "Library2Project",
               thisAssemblyPath,
               "Revit_Tools.Library2Project");

            PushButtonData b4Data = new PushButtonData(
               "Purge",
               "Purge",
               thisAssemblyPath,
               "Revit_Tools.Purge");

            PushButtonData b5Data = new PushButtonData(
                "AssignParameters",
                "AssignParameters",
                thisAssemblyPath,
                "Revit_Tools.AssignParameters");

            PushButton pb1 = ribbonPanel1.AddItem(b1Data) as PushButton;
            pb1.ToolTip = "Hit Run!";
            BitmapImage pb1Image = new BitmapImage(new Uri(@"pack://application:,,,/Revit_Tools;component/Resources/rvt.png"));
            pb1.LargeImage = pb1Image;
            pb1.AvailabilityClassName = "Revit_Tools.Availability";

            PushButton pb2 = ribbonPanel2.AddItem(b2Data) as PushButton;
            pb2.ToolTip = "Hit Run!";
            BitmapImage pb2Image = new BitmapImage(new Uri(@"pack://application:,,,/Revit_Tools;component/Resources/excel.png"));
            pb2.LargeImage = pb2Image;
            pb2.AvailabilityClassName = "Revit_Tools.Availability";

            PushButton pb3 = ribbonPanel3.AddItem(b3Data) as PushButton;
            pb3.ToolTip = "Hit Run!";
            BitmapImage pb3Image = new BitmapImage(new Uri(@"pack://application:,,,/Revit_Tools;component/Resources/library.png"));
            pb3.LargeImage = pb3Image;
            pb3.AvailabilityClassName = "Revit_Tools.Availability";

            PushButton pb4 = ribbonPanel4.AddItem(b4Data) as PushButton;
            pb4.ToolTip = "Hit Run!";
            BitmapImage pb4Image = new BitmapImage(new Uri(@"pack://application:,,,/Revit_Tools;component/Resources/purge.png"));
            pb4.LargeImage = pb4Image;
            pb4.AvailabilityClassName = "Revit_Tools.Availability";

            PushButton pb5 = ribbonPanel5.AddItem(b5Data) as PushButton;
            pb5.ToolTip = "Hit Run!";
            BitmapImage pb5Image = new BitmapImage(new Uri(@"pack://application:,,,/Revit_Tools;component/Resources/purge.png"));
            pb5.LargeImage = pb5Image;
            pb5.AvailabilityClassName = "Revit_Tools.Availability";

        }

        public Result OnShutdown(UIControlledApplication application)
        {
            // do nothing
            return Result.Succeeded;
        }

        public Result OnStartup(UIControlledApplication application)
        {
            // call our method that will load up our toolbar
            AddRibbonPanel(application);
            return Result.Succeeded;
        }
    }
}