using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Rhino;
using Rhino.DocObjects;
using Rhino.Geometry;
using Grasshopper.Kernel;
using EmreIstikam001.component.TehranOffice.FormGH._3D_DEN_2D_YE;
using EmreIstikam001.component.TehranOffice.ToosForAll;
using EmreIstikam001.Properties;
using EmreIstikam001.component.TehranOffice.ZAbsolute.Tools;
using Eto.Forms;
using Eto.Drawing;
using Rhino.Display;
using Bitmap = System.Drawing.Bitmap;

namespace EmreIstikam001.component.TehranOffice.Components._3D_DEN_2D_YE
{
    /// <summary>
    /// Creates a detail from a 3D block.
    /// </summary>
    public class PaftalamDetayAlma22GH : BaseGhComponent
    {
        private PaftalamaDetayAlmaFrm frm = new PaftalamaDetayAlmaFrm();
        private List<Curve> Rectangle = new List<Curve>();
        private readonly List<Curve> PreviewCurvesList = new List<Curve>();
        private bool ShowGeometry = true;
        private bool bake = false;
        private bool IsCloseForm = false;
        private string BlockName;
        private Guid GUID;
        private Make2dResult HiddenAndVisibleCurves;
        private List<GeometryBase> CuttedBlockGeo = new List<GeometryBase>();

        private List<Curve> RectangleSegments0 = new List<Curve>();
        private List<Point3d> MiddlePointsRectangle = new List<Point3d>();
        List<Curve> visibleProjectedCurves = new List<Curve>();
        List<Curve> hiddenProjectedCurves = new List<Curve>();
        List<Curve> joinedCurves = new List<Curve>();
        public PaftalamDetayAlma22GH()
            : base("DETAY ALMA6969696969", "P",
                "DETAY ALMA",
                "PARDUS", "3D'DEN 2D'YE")
        {
            frm.btnBlock.Click += AddBlock;
            frm.btnRec.Click += SelectRectangle;
            frm.txtName.TextChanged += ControlValueChanged;
            frm.cmbScaleText.TextChanged += ControlValueChanged;
            frm.cmbScaleDraw.TextChanged += ControlValueChanged;
            frm.cmbLayer.TextChanged += ControlValueChanged;
            frm.chbHidden.CheckedChanged += ControlValueChanged;
            frm.radTurkey.CheckedChanged += ControlValueChanged;
            frm.radEnglish.CheckedChanged += ControlValueChanged;
            frm.radRussian.CheckedChanged += ControlValueChanged;
            frm.btnBake.Click += Bake;
            frm.Closed += Frm_Closed;
        }
        protected override string CodeName => "DETAY_ALMA";
        protected override GH_Exposure? ValidExposure => GH_Exposure.primary;
        protected override Bitmap Icon => Resources.DETAY_ALMA;

        private void ControlValueChanged(object sender, EventArgs e)
        {
            ExpireSolution(true);
        }
        private void SelectRectangle(object sender, EventArgs e)
        {
            Rectangle.Clear();
            Rectangle = EIGetRihnoTl.GetPolylineCurve("Select region. ", false, false, false, false, out GUID);
            if (Rectangle[0] != null) RectangleSegments0.AddRange(Rectangle[0].DuplicateSegments());
            ExpireSolution(true);
        }
        private void Frm_Closed(object sender, EventArgs e)
        {
            if (IsCloseForm) bake = true;
            ShowGeometry = false;
            ExpireSolution(true);
        }
        private void Bake(object sender, EventArgs e)
        {
            IsCloseForm = true;
            frm.Close();
        }
        public void AddBlock(object sender, EventArgs e)
        {
            BlockName = EIGetRihnoTl.GetNameBlock("Block Seç", false, true)[0];
            ExpireSolution(true);
        }


        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
        }
        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
        }

        protected override void AuthenticatedSolveInstance(IGH_DataAccess DA)
        {
            frm.Show();
            PreviewCurvesList.Clear();
            List<GeometryBase> rectangleGeometries = new List<GeometryBase>();
}
 private List<GeometryWithAttributes> GetBlockGeometries(RhinoDoc doc, string blockName, out BoundingBox boundingBoxGeo, out double objectHeights, out bool is2D)
 {
     var blockGeometriesWithAttributes = new List<GeometryWithAttributes>();
     List<GeometryBase> BlockObjs = new List<GeometryBase>();
     var definition = doc.InstanceDefinitions.Find(blockName, true);
     if (definition != null)
     {
         // Retrieve objects from the block definition
         var geometryObjects = definition.GetObjects();
         if (geometryObjects != null)
         {
             foreach (var obj in geometryObjects)
             {
                 BlockObjs.Add(obj.Geometry);
                 blockGeometriesWithAttributes.Add(new GeometryWithAttributes
                 {
                     Geometry = obj.Geometry,
                     Attributes = obj.Attributes
                 });
             }
         }
     }

     // Compute the bounding box of these geometries
     boundingBoxGeo = BoundigboxGeometry(BlockObjs);


     var bbox = BoundingBox.Empty;
     foreach (var obj in BlockObjs)
     {
         if (obj is Curve ddd)
         {
             var fff = (Curve)ddd;
             Curve.ProjectToPlane(fff, Plane.WorldXY);
             var objBbox = fff.GetBoundingBox(true);
             bbox.Union(objBbox);
         }
     }
     var box = new Box(bbox);

I'm creating this component which gets a bock and a Curve from user in Rhino.
it should get all the curves of the block which are inside or overlap with the given Curve . and should create 2 geometry list and in one of them add the inside curves and in the other one add the overlap s CUrve.and if a curve is both inside and out side of the Reagan it shouuld be shattered at the intersect point with the Reagan Curve and the inside pat of it adds to the inside Curves