import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { D as getV1PagesUserList, E as postV1PagesShare, F as getV1FormBuilderFieldsId, G as getV1FormBuilderId, H as patchV1FormBuilderId } from "./api-BQ_tS-9F.esm.js";
import { at as getToken } from "./common-B0qL-cCR.esm.js";
const getAllUserAndDepartmentDropdown = createAsyncThunk(
  "share/getUser",
  async () => {
    const response = await getV1PagesUserList({ ...getToken() });
    return response;
  }
);
const sharePage = createAsyncThunk(
  "share/sharePage",
  async (data2) => {
    const response = await postV1PagesShare({ ...getToken(), data: data2 });
    return response;
  }
);
const originalGrid = {
  layout_cards: {
    lg: [
      {
        i: "card_1",
        x: 0,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Users",
        section_key: "layout_cards"
      },
      {
        i: "card_2",
        x: 1,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Active Users",
        section_key: "layout_cards"
      },
      {
        i: "card_3",
        x: 2,
        y: 0,
        w: 1,
        h: 1.3,
        content: "  ",
        section_key: "layout_cards"
      }
    ],
    md: [
      {
        i: "card_1",
        x: 0,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Users",
        section_key: "layout_cards"
      },
      {
        i: "card_2",
        x: 1,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Active Users",
        section_key: "layout_cards"
      },
      {
        i: "card_3",
        x: 2,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Roles",
        section_key: "layout_cards"
      }
    ],
    sm: [
      {
        i: "card_1",
        x: 0,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Users",
        section_key: "layout_cards"
      },
      {
        i: "card_2",
        x: 0,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Active Users",
        section_key: "layout_cards"
      },
      {
        i: "card_3",
        x: 0,
        y: 0,
        w: 1,
        h: 1.3,
        content: "Total Roles",
        section_key: "layout_cards"
      }
    ]
  },
  layout_charts: {
    lg: [
      {
        i: "dongnut_1",
        x: 0,
        y: 0,
        w: 1,
        h: 2.5,
        content: "User Status Distribution",
        section_key: "layout_charts"
      },
      {
        i: "dongnut_2",
        x: 1,
        y: 0,
        w: 2,
        h: 2.5,
        content: "Role Distribution",
        section_key: "layout_charts"
      }
    ],
    md: [
      {
        i: "dongnut_1",
        x: 0,
        y: 0,
        w: 1,
        h: 2.5,
        content: "User Status Distribution",
        section_key: "layout_charts"
      },
      {
        i: "dongnut_2",
        x: 1,
        y: 0,
        w: 2,
        h: 2.5,
        content: "Role Distribution",
        section_key: "layout_charts"
      }
    ],
    sm: [
      {
        i: "dongnut_1",
        x: 0,
        y: 0,
        w: 1,
        h: 2.5,
        content: "User Status Distribution",
        section_key: "layout_charts"
      },
      {
        i: "dongnut_2",
        x: 0,
        y: 1,
        w: 1,
        h: 2.5,
        content: "Role Distribution",
        section_key: "layout_charts"
      }
    ]
  },
  layout_col1: {
    lg: [
      {
        i: "cards_row",
        x: 0,
        y: 0,
        w: 3,
        h: 1.5,
        content: "cards_row",
        section_key: "layout_col1"
      },
      {
        i: "cards_row_dongnut",
        x: 0,
        y: 1,
        w: 3,
        h: 3.5,
        content: "cards_row_dongnut",
        section_key: "layout_col1"
      }
    ],
    md: [
      {
        i: "cards_row",
        x: 0,
        y: 0,
        w: 3,
        h: 1.5,
        content: "cards_row",
        section_key: "layout_col1"
      },
      {
        i: "cards_row_dongnut",
        x: 0,
        y: 1,
        w: 3,
        h: 3.5,
        content: "cards_row_dongnut",
        section_key: "layout_col1"
      }
    ],
    sm: [
      {
        i: "cards_row",
        x: 0,
        y: 0,
        w: 1,
        h: 4,
        content: "cards_row",
        section_key: "layout_col1"
      },
      {
        i: "cards_row_dongnut",
        x: 0,
        y: 1,
        w: 1,
        h: 5.1,
        content: "cards_row_dongnut",
        section_key: "layout_col1"
      }
    ]
  },
  layout_col2: {
    lg: [
      {
        i: "activity",
        x: 0,
        y: 0,
        w: 3,
        h: 3,
        content: "Activities",
        section_key: "layout_col2"
      },
      {
        i: "pinned_items",
        x: 0,
        y: 0,
        w: 3,
        h: 2,
        content: "Pined Items",
        section_key: "layout_col2"
      }
    ],
    md: [
      {
        i: "activity",
        x: 0,
        y: 0,
        w: 3,
        h: 3,
        content: "Activities",
        section_key: "layout_col2"
      },
      {
        i: "pinned_items",
        x: 0,
        y: 0,
        w: 3,
        h: 2,
        content: "Pined Items",
        section_key: "layout_col2"
      }
    ],
    sm: [
      {
        i: "activity",
        x: 0,
        y: 0,
        w: 1,
        h: 3,
        content: "Activities",
        section_key: "layout_col2"
      },
      {
        i: "pinned_items",
        x: 0,
        y: 0,
        w: 1,
        h: 2,
        content: "Pined Items",
        section_key: "layout_col2"
      }
    ]
  },
  layout_cols: {
    lg: [
      {
        i: "column_1",
        x: 1,
        y: 0,
        w: 2.1,
        h: 5.2,
        content: "column1",
        section_key: "layout_cols"
      },
      {
        i: "column_2",
        x: 12,
        y: 0,
        w: 0.9,
        h: 5.2,
        content: "column2",
        section_key: "layout_cols"
      }
    ],
    md: [
      {
        i: "column_1",
        x: 1,
        y: 0,
        w: 8.5,
        h: 10,
        content: "column1",
        section_key: "layout_cols"
      },
      {
        i: "column_2",
        x: 12,
        y: 0,
        w: 3.5,
        h: 5,
        content: "column2",
        section_key: "layout_cols"
      }
    ],
    sm: [
      {
        i: "column_1",
        x: 0,
        y: 0,
        w: 1,
        h: 9.2,
        content: "column1",
        section_key: "layout_cols"
      },
      {
        i: "column_2",
        x: 0,
        y: 0.2,
        w: 1,
        h: 5,
        content: "column2",
        section_key: "layout_cols"
      }
    ]
  },
  layout: {
    lg: [
      { content: "Total Files", i: "card: Total Files", x: 0, y: 0, w: 1, h: 1 },
      { content: "Total File Size", i: "card1: Total File Size", x: 1, y: 0, w: 1, h: 1 },
      { content: "File With Location", i: "card2: File With Location", x: 2, y: 0, w: 1, h: 1 },
      { content: "File Storage", i: "donut: File Storage", x: 3, y: 0, w: 3, h: 1.5 },
      { content: "Recent Files", i: "table: Recent Files", x: 4, y: 0, w: 3, h: 1.6 }
    ]
  }
};
const sharedPagesData = [
  {
    id: 1,
    name: "Page 1",
    viewStyle: 1,
    owner: "Siddhant",
    isPinToDashboard: false
  },
  {
    id: 2,
    name: "Page 2",
    viewStyle: 1,
    owner: "prasun",
    isPinToDashboard: false
  },
  {
    id: 3,
    name: "Page 3",
    viewStyle: 1,
    owner: "Amrit",
    isPinToDashboard: false
  },
  {
    id: 4,
    name: "Page 4",
    viewStyle: 1,
    owner: "Siddhant",
    isPinToDashboard: false
  },
  {
    id: 5,
    name: "Page 5",
    viewStyle: 1,
    owner: "Amrit",
    isPinToDashboard: false
  },
  {
    id: 6,
    name: "Page 21",
    viewStyle: 1,
    owner: "prasun",
    isPinToDashboard: false
  }
];
const data = [
  {
    _id: 1,
    name: "Default",
    grid_json: originalGrid,
    module: "user",
    user_id: "1"
  }
];
const state$1 = {
  currentPage: 1,
  user_name: "",
  number: "",
  users: [],
  rows: [],
  loading: true,
  error: "",
  pages: data,
  grid: originalGrid,
  paginationModel: {
    pageNo: 1,
    limit: 10
  },
  sharedPages: JSON.parse(
    localStorage.getItem("sharedPages") || JSON.stringify(sharedPagesData)
  ),
  pinToDashboardList: JSON.parse(
    localStorage.getItem("pinToDashboardList") || "[]"
  ),
  driveDashboard: data
};
const BASE_URL = "process.env.baseUrl";
const Server = {
  get: async function(url, isAuth, customOptions, customHeader) {
    let requestOptions = {
      method: "GET",
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        ...customHeader
      }
    };
    if (customOptions) requestOptions = { ...requestOptions, ...customOptions };
    if (isAuth) {
      const token = localStorage.getItem("_tid");
      requestOptions.headers["Authorization"] = `Bearer ${token}`;
      requestOptions.headers["x-auth-token"] = `Bearer ${token}`;
    }
    const response = await fetch(BASE_URL + url, requestOptions);
    return await response.json();
  },
  getWithToken: async function(url, token, customOptions, customHeader) {
    let requestOptions = {
      method: "GET",
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        ...customHeader
      }
    };
    if (customOptions) requestOptions = { ...requestOptions, ...customOptions };
    const response = await fetch(
      BASE_URL + url + `?token=${token}`,
      requestOptions
    );
    return await response.json();
  },
  post: async function(url, payload, isAuth, customOptions, customHeader) {
    let requestOptions = {
      method: "POST",
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        ...customHeader
      },
      body: JSON.stringify(payload)
    };
    if (customOptions) requestOptions = { ...requestOptions, ...customOptions };
    if (isAuth) {
      const token = localStorage.getItem("_tid");
      requestOptions.headers["Authorization"] = `Bearer ${atob(token)}`;
      requestOptions.headers["x-auth-token"] = `Bearer ${atob(token)}`;
    }
    const response = await fetch(BASE_URL + url, requestOptions);
    let jsonResponse = {};
    try {
      jsonResponse = await response.json();
    } catch (e) {
      console.log("unable to parse as json", e);
    }
    return jsonResponse;
  },
  put: async function(url, id, payload, isAuth, customOptions, customHeader) {
    let requestOptions = {
      method: "PUT",
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        ...customHeader
      },
      body: JSON.stringify(payload)
    };
    if (customOptions) requestOptions = { ...requestOptions, ...customOptions };
    if (isAuth) {
      const token = localStorage.getItem("_tid");
      requestOptions.headers["Authorization"] = `Bearer ${atob(token)}`;
      requestOptions.headers["x-auth-token"] = `Bearer ${atob(token)}`;
    }
    const response = await fetch(BASE_URL + url + "/" + id, requestOptions);
    let jsonResponse = {};
    try {
      jsonResponse = await response.json();
    } catch (e) {
      console.log("unable to parse as json", e);
    }
    return jsonResponse;
  },
  redirectPost: (url, data2) => {
    const form = document.createElement("form");
    document.body.appendChild(form);
    form.method = "post";
    form.action = url;
    for (const name in data2) {
      const input = document.createElement("input");
      input.type = "hidden";
      input.name = name;
      input.value = data2[name];
      form.appendChild(input);
    }
    form.submit();
  }
};
const setUserNameAction = (state2, action) => {
  state2.user_name = action.payload;
};
const pinToDashboardAction = (state2, action) => {
  state2.pinToDashboardList = action.payload;
  localStorage.setItem("pinToDashboardList", JSON.stringify(action.payload));
};
const setPagesAction = (state2, action) => {
  state2.pages = action.payload;
};
const setSharedPageAction = (state2, action) => {
  state2.sharedPages = action.payload;
  localStorage.setItem("sharedPages", JSON.stringify(action.payload));
};
const setdashboardDriveData = (state2, action) => {
  state2.DashboardDrive = action.payload;
};
const UsersFetchAction = createAsyncThunk("dashboard/Users", () => {
  Server.get("/users").then((response) => response);
});
const dashboardSlice = createSlice({
  name: "dashboard",
  initialState: state$1,
  reducers: {
    setUserName: setUserNameAction,
    changeCurrentPage(state2, action) {
      state2.currentPage = action.payload;
    },
    // setPages(state, action) {
    //   state.pages = action.payload;
    // },
    setPaginationModel(state2, action) {
      state2.paginationModel = action.payload;
    },
    setGrid(state2, action) {
      state2.grid = action.payload;
    },
    setdashboardDriveData(state2, action) {
      state2.driveDashboard = action.payload;
    },
    setPages: setPagesAction,
    setSharedPage: setSharedPageAction,
    pinToDashboardList: pinToDashboardAction,
    dashBoardDrive: setdashboardDriveData
  },
  extraReducers: (builder) => {
    builder.addCase(UsersFetchAction.pending, (state2) => {
      state2.loading = true;
    });
    builder.addCase(UsersFetchAction.fulfilled, (state2) => {
      state2.loading = false;
      state2.error = "";
    });
    builder.addCase(UsersFetchAction.rejected, (state2) => {
      state2.loading = false;
      state2.users = [];
    });
  }
});
const {
  setUserName,
  changeCurrentPage,
  setPages,
  setSharedPage,
  setPaginationModel: setPaginationModel$1,
  setGrid,
  pinToDashboardList,
  dashBoardDrive
  // setdashboardDriveData,
} = dashboardSlice.actions;
const reducer$1 = dashboardSlice.reducer;
const patchFormDataById = createAsyncThunk(
  "formBuilder/put",
  async ({ id, data: data2 }) => {
    const response = await patchV1FormBuilderId({
      ...getToken(),
      id,
      ...data2
    });
    return response;
  }
);
const getFormDataById = createAsyncThunk(
  "formBuilder/getById",
  async (id) => {
    const response = await getV1FormBuilderId({
      ...getToken(),
      id
    });
    return response;
  }
);
const getFieldsByFormId = createAsyncThunk(
  "formBuilder/fields/get",
  async ({ id }) => {
    const response = await getV1FormBuilderFieldsId({
      ...getToken(),
      id
    });
    return response == null ? void 0 : response.data.fields;
  }
);
const state = {
  rows: [],
  workflowTemplate: [],
  workflow: [],
  isLoading: false,
  isError: false,
  count: 0,
  error: "",
  formData: [],
  fields: null,
  isSuccess: false,
  workflowAutomationId: {},
  paginationModel: {
    pageNo: 1,
    limit: 10,
    totalCount: 0
  }
};
const isJsonParse = (json) => {
  try {
    return JSON.parse(json);
  } catch (error) {
    return false;
  }
};
const formBuilderListSlice = createSlice({
  name: "formBuilder/getAllFormData",
  initialState: state,
  reducers: {
    setFormData: (state2, action) => {
      state2.formData = action.payload;
    },
    setPaginationModel(state2, action) {
      state2.paginationModel = { ...state2.paginationModel, ...action.payload };
    }
  },
  extraReducers: (builder) => {
    builder.addCase(getFormDataById.pending, (state2) => {
      state2.isLoading = true;
      state2.isError = false;
      state2.error = "";
      state2.formData = [];
    });
    builder.addCase(getFormDataById.fulfilled, (state2, action) => {
      var _a, _b, _c;
      state2.isLoading = false;
      state2.isError = false;
      state2.formData = (_c = (_b = (_a = action == null ? void 0 : action.payload) == null ? void 0 : _a.data) == null ? void 0 : _b.form) == null ? void 0 : _c.fields;
      state2.error = "";
    });
    builder.addCase(getFormDataById.rejected, (state2, action) => {
      state2.isLoading = false;
      state2.isError = true;
      state2.error = action.error.message || "";
    });
    builder.addCase(patchFormDataById.pending, (state2) => {
    });
    builder.addCase(patchFormDataById.fulfilled, (state2) => {
      state2.isLoading = false;
      state2.isError = false;
      state2.error = "";
      state2.isSuccess = true;
    });
    builder.addCase(patchFormDataById.rejected, (state2, action) => {
      var _a, _b;
      const error = ((_b = isJsonParse((_a = action.error) == null ? void 0 : _a.message)) == null ? void 0 : _b.message) || action.error.message || "Something went wrong";
      state2.isLoading = false;
      state2.isError = true;
      state2.error = error;
      state2.isSuccess = false;
    });
    builder.addCase(getFieldsByFormId.pending, (state2) => {
      state2.isLoading = true;
    });
    builder.addCase(getFieldsByFormId.fulfilled, (state2, action) => {
      const incomingFields = action.payload;
      if (incomingFields.length) {
        let fields = {};
        incomingFields.forEach((field) => {
          for (const key in field) {
            fields = {
              ...fields,
              [key]: field[key]
            };
          }
        });
        state2.fields = fields;
        state2.isLoading = false;
      }
    });
    builder.addCase(getFieldsByFormId.rejected, (state2, action) => {
      var _a;
      const message = `Fields API: ${((_a = isJsonParse(action.error.message)) == null ? void 0 : _a.message) || action.error.message}`;
      state2.isLoading = false;
      state2.isError = true;
      state2.error = message;
    });
  }
});
const { setFormData, setPaginationModel } = formBuilderListSlice.actions;
const reducer = formBuilderListSlice.reducer;
export {
  UsersFetchAction as U,
  setPaginationModel$1 as a,
  setSharedPage as b,
  changeCurrentPage as c,
  dashBoardDrive as d,
  setGrid as e,
  reducer as f,
  getFieldsByFormId as g,
  getFormDataById as h,
  patchFormDataById as i,
  pinToDashboardAction as j,
  setFormData as k,
  setPagesAction as l,
  setSharedPageAction as m,
  setUserName as n,
  setUserNameAction as o,
  pinToDashboardList as p,
  setdashboardDriveData as q,
  reducer$1 as r,
  setPages as s,
  sharedPagesData as t,
  state as u,
  getAllUserAndDepartmentDropdown as v,
  formBuilderListSlice as w,
  dashboardSlice as x,
  sharePage as y
};
//# sourceMappingURL=reducer-C2CFWu_w.esm.js.map
