/* eslint-disable @typescript-eslint/no-explicit-any */
import { Diff } from "deep-diff"

export enum ExecutionErrorType {
  EVALUATED = "EVALUATED",
  LINT = "LINT",
  VALIDATION = "VALIDATION",
}

export interface ErrorShape {
  errorType: ExecutionErrorType
  errorMessage: string
  errorLine?: number
  errorColumn?: number
  errorName?: string
}
export type DependenciesState = Record<string, string[]>

export interface ExecutionState {
  dependencies: DependenciesState
  result: Record<string, any>
  error: Record<string, ErrorShape[]>
  debuggerData: Record<string, ErrorShape[]>
  independencies: DependenciesState
}
// {
//   dependencies: {},
//   result: {},
//   error: {},
//   debuggerData: {},
//   independencies: {},
// }
// const Execution = JSON.parse(localStorage.getItem("App"))
export const executionInitialState: ExecutionState = 
// JSON.parse(localStorage.getItem("rootState")).currentApp.execution||
// Execution?.execution ||
{
  "dependencies": {
      "currentPageInfo.pagePath": [
          "root.pageSortedKey",
          "root.currentPageIndex"
      ],
      "currentPageInfo.subPagePath": [
          "root.currentSubPagePath"
      ]
  },
  "result": {
      "root": {
          "currentPageIndex": 0,
          "pageSortedKey": [
              "page1"
          ],
          "displayName": "root",
          "$parentNode": "",
          "$type": "WIDGET",
          "$widgetType": "DOT_PANEL",
          "$childrenNode": [
              "page1"
          ]
      },
      "page1": {
          "bodyColumns": 32,
          "bottomHeight": 0,
          "canvasSize": "auto",
          "canvasWidth": 100,
          "footerColumns": 32,
          "hasFooter": false,
          "hasHeader": false,
          "hasLeft": false,
          "hasRight": false,
          "headerColumns": 32,
          "isFooterFixed": false,
          "isHeaderFixed": false,
          "isLeftFixed": true,
          "isRightFixed": true,
          "layout": "Custom",
          "leftColumns": 8,
          "leftPosition": "NONE",
          "leftWidth": 0,
          "rightColumns": 8,
          "rightPosition": "NONE",
          "rightWidth": 0,
          "showLeftFoldIcon": false,
          "showRightFoldIcon": false,
          "topHeight": 0,
          "displayName": "page1",
          "$parentNode": "root",
          "$type": "WIDGET",
          "$widgetType": "PAGE_NODE",
          "$childrenNode": [
              "bodySection1",
              "modalSection1"
          ],
          "$parentPageName": "page1"
      },
      "bodySection1": {
          "currentViewIndex": 0,
          "defaultViewKey": "sub-page1",
          "sectionViewConfigs": [
              {
                  "id": "eef9e48d-4f62-4069-909f-86a8c8474893",
                  "key": "sub-page1",
                  "path": "sub-page1",
                  "viewDisplayName": "bodySection1-bodySectionContainer1"
              }
          ],
          "style": {
              "padding": {
                  "mode": "all",
                  "size": "24"
              }
          },
          "viewSortedKey": [
              "bodySection1-bodySectionContainer1"
          ],
          "displayName": "bodySection1",
          "$parentNode": "page1",
          "$type": "WIDGET",
          "$widgetType": "SECTION_NODE",
          "$childrenNode": [
              "bodySection1-bodySectionContainer1"
          ],
          "$parentPageName": "page1"
      },
      "modalSection1": {
          "displayName": "modalSection1",
          "$parentNode": "page1",
          "$type": "WIDGET",
          "$widgetType": "MODAL_SECTION_NODE",
          "$childrenNode": [],
          "$parentPageName": "page1"
      },
      "builderInfo": {
          "version": "4.4.13",
          "language": "English"
      },
      "currentUserInfo": {
          "userID": "ILAfx4p1C7dZ",
          "nickname": "root",
          "email": "root",
          "language": "en-US",
          "createdAt": "2024-02-12T06:57:23.589408Z",
          "updatedAt": "2024-02-12T07:11:03.216272Z"
      },
      "globalData": {
          "$dynamicAttrPaths": []
      },
      "urlParams": {
          "query": {},
          "url": "http://localhost:3000/0/app/ILAfx4p1C7dV",
          "appURL": "http://localhost:3000/0/app/ILAfx4p1C7dV"
      },
      "localStorage": {},
      "currentPageInfo": {
          "pagePath": "page1",
          "$dynamicAttrPaths": [
              "pagePath",
              "subPagePath"
          ]
      },
      "pageInfos": [
          {
              "pagePath": "/page1",
              "subPagePath": "/page1/sub-page1",
              "pageName": "page1",
              "subPageName": "sub-page1",
              "isHomePage": true,
              "subPageGroup": ""
          }
      ]
  },
  "error": {},
  "debuggerData": {},
  "independencies": {
      "root.currentSubPagePath": [
          "currentPageInfo.subPagePath"
      ],
      "root.pageSortedKey": [
          "currentPageInfo.pagePath"
      ],
      "root.currentPageIndex": [
          "currentPageInfo.pagePath"
      ]
  }
};
export interface setExecutionResultPayload {
  updates: Diff<Record<string, any>, Record<string, any>>[]
}

export interface UpdateExecutionByDisplayNamePayload {
  displayName: string
  value: Record<string, any>
}

export interface UpdateCurrentPagePathPayload {
  pageDisplayName: string
  subPagePath?: string
}
