// const generateRoomNum = (lastRoomNum: string, floor: string) => {
//   let roomNum: string | number | null = null;

//   if (!lastRoomNum) {
//     if (floor === "G") floor = "0";
//     roomNum = floor + "01";
//   }

//   //
//   else if (lastRoomNum && Number(lastRoomNum)) {
//     if (lastRoomNum.startsWith("0") || lastRoomNum.length < 3) {
//       if (Number(lastRoomNum) < 9) roomNum = "00" + (Number(lastRoomNum) + 1);
//       else roomNum = "0" + (Number(lastRoomNum) + 1);
//     } else roomNum = Number(lastRoomNum) + 1;
//   }

//   //
//   else {
//     const lastChar = lastRoomNum[lastRoomNum.length - 1];
//     if (Number(lastChar)) {
//       const inc = Number(lastChar) + 1;
//       if (inc > 9) roomNum = lastRoomNum.slice(0, lastRoomNum.length - 2) + inc;
//       else roomNum = lastRoomNum.slice(0, lastRoomNum.length - 1) + inc;
//     } else {
//       roomNum = lastRoomNum + "_01";
//     }
//   }
//   return roomNum.toString();
// };

// export default generateRoomNum;


const generateRoomNum = (lastRoomNum: string, floor: string) => {
  let roomNum: string;

  if (floor === "G") floor = "0";

  if (!lastRoomNum) {
    roomNum = floor + "01";
  } else {
    const lastNum = lastRoomNum.slice(floor.length);
    let nextNum = parseInt(lastNum, 10) + 1;

    const paddedNextNum = nextNum.toString().padStart(2, "0");

    roomNum = floor + paddedNextNum;
  }

  return roomNum;
};

export const generateRoomNumX = (lastRoomNum: string, floor: string, roomCount: number) => {
  let roomNum: string;

  const lastNum = lastRoomNum.slice(floor.length);

  if (floor === "G") floor = "0";

  if (!lastRoomNum || Number.isNaN(parseInt(lastNum, 10))) {
    if (roomCount === 0) {
      roomNum = floor + "01";
    } else if (roomCount > 9) {
      roomNum = floor + `${roomCount}`;
    } else {
      roomNum = floor + `0${roomCount}`;
    }
  } else {
    let nextNum = parseInt(lastNum, 10) + 1;

    const paddedNextNum = nextNum.toString().padStart(2, "0");

    roomNum = floor + paddedNextNum;
  }

  return roomNum;
};

export default generateRoomNum;
