import { StringCaser } from "@/components/WebExportReact/src/utils/helpers";
import { layoutImports } from "../utils/layoutImports";
import TranslatorMainActivityAndroid from "./TranslatorMainActivityAndroid";

const buildActivity = (activity, configuration) => {
  return xml(activity, configuration);
};

export default (configuration, activities) => {
  const copyList = [];
  copyList.push({
    fileName: `app/src/main/res/layout/activity_main.xml`,
    content: buildActivity({ name: "main" }, configuration),
  });
  //using only one activity for now
  // for (let activity of activities) {
  //   const activityName = StringCaser(activity?.name, {
  //     casetype: "capitalize",
  //   });
  //   copyList.push({
  //     fileName: `app/src/main/res/layout/activity_${activity?.name.toLowerCase()}.xml`,
  //     content: buildActivity(activity, configuration),
  //   });
  // }

  return copyList;
};

const xml = (activity, configuration) => {

  configuration.navigationType = configuration?.nav;
  return `<?xml version="1.0" encoding="utf-8"?>
<${configuration?.navigationType !== "bottomBar"
      ? "androidx.drawerlayout.widget.DrawerLayout"
      : layoutImports[activity?.layout] ??
      "androidx.drawerlayout.widget.DrawerLayout"
    } xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:animateLayoutChanges="true"
        android:id="@+id/activity_main">
        
        ${activity?.name.toLowerCase() === "main"
      ? `
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

  
            <androidx.appcompat.widget.Toolbar
              android:id="@+id/my_toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              android:elevation="4dp"
              app:labelVisibilityMode="labeled"
              android:visibility="visible"
              android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
              app:theme="@style/ActionBarThemeOverlay"
              app:popupTheme="@style/ActionBarThemeOverlay"
              app:titleTextColor="@android:color/white"
              >
            </androidx.appcompat.widget.Toolbar>
            

              <fragment
              android:id="@+id/nav_host_fragment_activity_main"
              android:name="androidx.navigation.fragment.NavHostFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_below="@id/my_toolbar"
              app:defaultNavHost="true"
              android:layout_above="@+id/navView"
              app:navGraph="@navigation/mobile_navigation" />

              
              ${(configuration?.navigationType === "bottomBar")
        ? ` <com.google.android.material.bottomnavigation.BottomNavigationView
                  android:id="@+id/nav_view"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/_50sdp"
                  android:layout_alignParentBottom="true"
                  android:background="?android:attr/windowBackground"
                  android:visibility="visible"
                  app:itemIconSize="25dp"
                  app:itemPaddingBottom="@dimen/_8sdp"
                  app:itemRippleColor="@null"
                  app:itemTextColor="@color/black"
                  app:labelVisibilityMode="labeled"
                  app:menu="@menu/bottom_nav_menu" />`
        : ""
      }

             
              
              `
      : ""

      
    }

        </RelativeLayout>
        
        ${configuration?.navigationType === "sideBar"
        ? `
              <com.google.android.material.navigation.NavigationView
              android:id="@+id/navView"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              app:menu="@menu/navigation_menu" 
              android:layout_gravity="left" />`
        : ""
      }

</${configuration?.navigationType !== "bottomBar"
      ? "androidx.drawerlayout.widget.DrawerLayout"
      : layoutImports[activity?.layout] ??
      "androidx.drawerlayout.widget.DrawerLayout"
    }>
`;
};


// ${
//   configuration.appBar?.length > 0
//     ? ` <com.google.android.material.bottomnavigation.BottomNavigationView
//     android:id="@+id/nav_view"
//     android:layout_width="match_parent"
//     android:layout_height="@dimen/_50sdp"
//     android:layout_alignParentTop="true"
//     android:background="?android:attr/windowBackground"
//     android:visibility="visible"
//     app:itemIconSize="25dp"
//     app:itemPaddingBottom="@dimen/_8sdp"
//     app:itemRippleColor="@null"
//     app:itemTextColor="@color/black"
//     app:labelVisibilityMode="labeled"
//     app:menu="@menu/bottom_nav_menu" />`
//     : ""
// }