add pagination for this code per pagination 30 


import React, { useState, useEffect } from "react";
import { FwTabs, FwTab, FwTabPanel, FwSpinner } from "@freshworks/crayons/react";
import AutomationCard from "./AutomationCard"; // Import your AutomationCard component
import { getTicketCreationRules, getTicketUpdationRules, getHourlyRules } from '../common'; // Import your rule fetching functions

const getRuleSignature = (rule) => {
  return JSON.stringify({
    conditions: rule.summary.conditions,
    actions: rule.summary.actions,
  });
};

const groupDuplicates = (rules) => {
  const grouped = {};
  rules.forEach((rule) => {
    const signature = getRuleSignature(rule);
    if (!grouped[signature]) {
      grouped[signature] = [];
    }
    grouped[signature].push(rule);
  });
  return Object.values(grouped);
};

const AutomationTabs = ({ client }) => {
  const [searchTerm, setSearchTerm] = useState("");
  const [searchTriggered, setSearchTriggered] = useState(false);
  const [activeTab, setActiveTab] = useState("ticketcreate");

  const [ticketCreationRules, setTicketCreationRules] = useState([]);
  const [ticketUpdateRules, setTicketUpdateRules] = useState([]);
  const [hourlyTriggerRules, setHourlyTriggerRules] = useState([]);

  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const fetchRules = async () => {
      setLoading(true);
     
      await Promise.all([
        console.log("Initializing database..."),
        getTicketCreationRules(client, setTicketCreationRules),
        getTicketUpdationRules(client, setTicketUpdateRules),
        getHourlyRules(client, setHourlyTriggerRules),

        // (async () => {
        //     console.log("Initializing database...");
        //     const entity = await client.db.entity({ version: "v1" });
        //     console.log("Entity Initialized:", entity);
    
        //     // Assign global variable
        //     newRulePloadDB3 = entity.get("newRulePloadDB3");
        //     console.log("📌 Entity Reference:", newRulePloadDB3);
    
        //     // Fetch schema
        //     const data1 = await newRulePloadDB3.schema();
        //     console.log("📄 Schema Data:", data1);
        // })(),


    ]);

    
      setLoading(false);
    };

    fetchRules();
  }, [client]);

  const getFilteredGroups = (rules) => {
    const groupedRules = groupDuplicates(rules);
    if (!searchTriggered || !searchTerm.trim()) return groupedRules;

    return groupedRules.filter((rule) =>
      rule.name?.toLowerCase().includes(searchTerm.toLowerCase()) ||
      rule.description?.toLowerCase().includes(searchTerm.toLowerCase())
    );
  };

  const renderGroupedRules = (groups) => {
    if (loading) {
      return (
        <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '200px' }}>
          <FwSpinner size="medium" color="green" />
        </div>
      );
    }

    return groups.length > 0 ? (
      groups.map((group, index) => (
        <div key={index} className="fw-card-1 fw-py-16" style={{ border: "1px solid #ddd", borderRadius: "8px", marginBottom: "20px", marginTop: "20px", padding: "10px 16px", boxShadow: "0 4px 8px rgba(0, 0, 0, 0.1)", width: "80%", marginLeft: "auto", marginRight: "auto" }}>
          {group.map((rule, idx) => (
            <AutomationCard key={idx} rule={rule} index={idx + 1} isFirstInGroup={idx === 0} />
          ))}
        </div>
      ))
    ) : (
      <p style={{ textAlign: "center", marginTop: "20px" }}>No Rules Found Matched Your Search: {searchTerm}</p>
    );
  };

  const getRulesByTab = () => {
    switch (activeTab) {
      case "ticketcreate":
        return ticketCreationRules;
      case "ticketupdate":
        return ticketUpdateRules;
      case "hourly":
        return hourlyTriggerRules;
      default:
        return [];
    }
  };

  return (
    <>
      <h2>Automations - Rules</h2>
      <input
        type="text"
        placeholder="Search by name or description"
        value={searchTerm}
        onChange={(e) => setSearchTerm(e.target.value)}
      />
      <button onClick={() => { setSearchTriggered(true); }}>Search</button>

      <FwTabs onFwChange={(e) => { setActiveTab(e.target.panel); }}>
        <FwTab slot="tab" panel="ticketcreate">Ticket Create</FwTab>
        <FwTab slot="tab" panel="ticketupdate">Ticket Update</FwTab>
        <FwTab slot="tab" panel="hourly">Hourly Triggers</FwTab>

        <FwTabPanel name="ticketcreate">
          {renderGroupedRules(getFilteredGroups(ticketCreationRules))}
        </FwTabPanel>

        <FwTabPanel name="ticketupdate">
          {renderGroupedRules(getFilteredGroups(ticketUpdateRules))}
        </FwTabPanel>

        <FwTabPanel name="hourly">
          {renderGroupedRules(getFilteredGroups(hourlyTriggerRules))}
        </FwTabPanel>
      </FwTabs>
    </>
  );
};

export default AutomationTabs;