import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
import { navTo } from "@/components/utils/PageAction";

export function useTaskEntryForm() {
  const { querys } = useLoadQuerys({ 
    villageId: 0,  
    villageVolunteerId: 0,
  });
  
  function goForm(subType: string, subId: number, subKey = 'type', type = 'list', subTitle = '', catalogId : number|undefined = undefined) {
    navTo('/pages/dig/forms/' + type, {
      id: type === 'common' ? 1 : undefined,
      villageId: querys.value.villageId,  
      villageVolunteerId: querys.value.villageVolunteerId,  
      catalogId,
      subType,
      subId,
      subKey,
      subTitle,
    })
  }
  function goPreviewForm(subType: string, subId: number, subKey = 'type', type = 'list', subTitle = '', catalogId : number|undefined = undefined) {
    navTo('/pages/dig/forms/' + type, {
      id: type === 'common' ? 1 : undefined,
      villageId: querys.value.villageId,  
      villageVolunteerId: querys.value.villageVolunteerId,  
      catalogId,
      subType,
      subId,
      subKey,
      subTitle,
      isView: true,
    })
  }

  return {
    goForm,
    goPreviewForm,
  }
}

export function goFormStatic(villageId: number, villageVolunteerId: number, subType: string, subId: number, subKey = 'type', type = 'list', subTitle = '', catalogId : number|undefined = undefined) {
  navTo('/pages/dig/forms/' + type, {
    id: type === 'common' ? 1 : undefined,
    villageId,  
    villageVolunteerId,  
    catalogId,
    subType,
    subId,
    subKey,
    subTitle,
  })
}