"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import React from "react";

export default function Mobilemenu() {
  const pathname = usePathname();
  const isActive = (link) => link.split("/")[1] == pathname.split("/")[1];

  // Service items matching Header4 component
  const serviceItems = [
    { id: 11, title: "Data Entry Services", href: "/service-details/11" },
    { id: 12, title: "Data Conversion", href: "/service-details/12" },
    { id: 13, title: "Data Processing", href: "/service-details/13" },
    { id: 14, title: "Receipt Data Entry Services", href: "/service-details/14" },
    { id: 15, title: "Logistics Data Entry Services", href: "/service-details/15" },
    { id: 16, title: "Construction", href: "/#" }
  ];

  const isServiceActive = () => {
    return serviceItems.some(service => pathname.includes(service.href));
  };

  return (
    <div className="offcanvas offcanvas-start canvas-mb" id="menu-mobile">
      <div className="offcanvas-header top-nav-mobile justify-content-between">
        <Link href={`/`} className="logo">
          {/* Updated logo to match Header4 SVG logo */}
          <svg
            width="140"
            height={35}
            viewBox="0 0 150 40"
            fill="none"
            xmlns="http://www.w3.org/2000/svg"
            style={{ display: 'block' }}
          >
            <path
              d="M18.2183 15.7033L29.395 34.7289C29.4936 34.8967 29.6741 34.9994 29.8687 34.9985L41.1397 34.9463C41.3308 34.9455 41.5075 34.8448 41.6058 34.6809L47.5 24.8527L35.944 24.8365C35.7518 24.8362 35.5738 24.7349 35.4754 24.5698L23.9713 5.2667C23.8727 5.10131 23.6944 5 23.5019 5L12.3005 5C12.1083 5 11.9302 5.10099 11.8315 5.26594L5.91087 15.1639L0.167756 24.7208C0.0644005 24.8928 0.0636223 25.1076 0.165723 25.2804L5.75222 34.7316C5.85055 34.8979 6.02941 35 6.22264 35L16.7708 35C17.1948 35 17.4573 34.538 17.2402 34.1738L5.91087 15.1639L17.276 15.1639C17.6635 15.1639 18.022 15.3691 18.2183 15.7033Z"
              fill="#28285B"
            />
            <text
              x="55"
              y="20"
              fontFamily="Arial, sans-serif"
              fontSize="20"
              fontWeight="600"
              fill="#121416"
              dominantBaseline="central"
            >
              Keystone
            </text>
          </svg>
        </Link>
        <div className="close-menu" data-bs-dismiss="offcanvas">
          <i className="icon-times-solid" />
        </div>
      </div>
      <div className="mb-canvas-content">
        <div className="mb-body">
          <div className="mb-content-top">
            <ul className="nav-ul-mb" id="wrapper-menu-navigation">
              {/* Services Menu Item with Dropdown */}
              <li className={`nav-mb-item ${isServiceActive() ? "active" : ""}`}>
                <a
                  href="#dropdown-menu-services"
                  className="collapsed mb-menu-link"
                  data-bs-toggle="collapse"
                  aria-expanded="true"
                  aria-controls="dropdown-menu-services"
                >
                  <span>Services</span>
                  <span className="btn-open-sub" />
                </a>
                <div
                  id="dropdown-menu-services"
                  className="collapse"
                  data-bs-parent="#menu-mobile"
                >
                  <ul className="sub-nav-menu">
                    {serviceItems.map((service) => {
                      // Disable Construction service (id: 16) same as in Header4
                      
                      
                      return (
                        <li key={service.id}>
                          <Link
                            href={service.href}
                            className={`sub-nav-link ${
                              isActive(service.href) ? "active" : ""
                            }`}
                          >
                            {service.title}
                          </Link>
                        </li>
                      );
                    })}
                  </ul>
                </div>
              </li>

              {/* About Menu Item */}
              <li className={`nav-mb-item ${isActive("/about") ? "active" : ""}`}>
                <Link href={`/about`} className="mb-menu-link">
                  About
                </Link>
              </li>

              {/* Career Menu Item */}
              <li className={`nav-mb-item ${isActive("/career") ? "active" : ""}`}>
                <Link href={`/career`} className="mb-menu-link">
                  Career
                </Link>
              </li>

              {/* Contact Menu Item */}
              <li className={`nav-mb-item ${isActive("/contact-us") ? "active" : ""}`}>
                <Link href={`/contact-us`} className="mb-menu-link">
                  Contact
                </Link>
              </li>
            </ul>
          </div>

          {/* Updated contact information and buttons */}
          <div className="mb-other-content">
            <ul className="mb-info mb_20">
              <li>
                <p className="text_mono-gray">
                  Address:
                  <a
                    target="_blank"
                    href="https://www.google.com/maps?q=No.3A,1stFloor,BalajiNagar,Dharapadavedu,Vellore-632007,TamilNadu,India"
                  >
                    <span className="fw-5 text_mono-gray-5">
                      No. 3A, 1st Floor, Balaji Nagar, Dharapadavedu, Vellore - 632007, Tamil Nadu, India
                    </span>
                  </a>
                </p>
              </li>
              <li>
                <p className="text_mono-gray">
                  Email:
                  <a href="mailto:koushik@keystonesolution.in">
                    <span className="fw-5 text_mono-gray-5">
                      koushik@keystonesolution.in
                    </span>
                  </a>
                </p>
              </li>
              <li>
                <p className="text_mono-gray">
                  Phone:
                  <a href="tel:+919095450005">
                    <span className="fw-5 text_mono-gray-5">
                      +91 90954 50005
                    </span>
                  </a>
                </p>
              </li>
            </ul>
            <div className="mb-wrap-btn d-flex gap_12">
              <Link href={`/about`} className="tf-btn">
                <span>Get Started</span>
                <span className="bg-effect" />
              </Link>
              <Link href={`/contact-us`} className="tf-btn">
                <span>Contact Us</span>
                <span className="bg-effect" />
              </Link>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}