const URL = "/one-api/mockup/masterdata/";

export async function search(token, name, snik, status) {
    try {
        var resp = await axios.post(URL + 'staffv2/search', {
            token:token, 
            nama: name,
            snik: snik,
            status: status
        });
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function getsexreg(token) {
    try {
        var resp = await axios.post(URL + 'staffv2/getsexreg',{token:token});
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function save(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/save',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function newstaff(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/newstaff',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function xdelete(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/deletestaff',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}
export async function saveposition(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/addnewposition', prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}
export async function updateposition(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/editposition', prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}
export async function deleteposition(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/deleteposition', prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}
export async function getaddress(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/getaddress',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function searchcity(token,prm) {
    try {
       var resp = await axios.post(URL + 'staffv2/searchcity',{token:token,search:prm});
       if (resp.status != 200) {
          return {
             status: "ERR",
             message: resp.statusText
          };
       }
       let data = resp.data;
       return data;
    } catch(e) {
       return {
          status: "ERR",
          message: e.message
       };
    }
 }

 export async function getsubarea(token,prm) {
    try {
       var resp = await axios.post(URL + 'staffv2/getsubarea',{id:prm.M_CityID,token:token});
       if (resp.status != 200) {
          return {
             status: "ERR",
             message: resp.statusText
          };
       }
       let data = resp.data;
       return data;
    } catch(e) {
       return {
          status: "ERR",
          message: e.message
       };
    }
 }

 
export async function savenewaddress(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/savenewaddress',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function saveeditaddress(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/saveeditaddress',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function deleteaddress(prm) {
    try {
        var resp = await axios.post(URL + 'staffv2/deleteaddress',prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}