import { View } from "@tarojs/components";
import BottomBar from "@/components/BottomBar";
import PageCustom from "@/components/page-custom/index";
import NavBarNormal from "@/components/NavBarNormal/index";
import WemetaTextarea from "@/components/wemeta-textarea/index";
import { useAgentStore } from "@/store/agentStore";
import useEditContactCard from "@/hooks/useEditContactCard";
import Taro from "@tarojs/taro";
export default function Index() {
  const agentContactCard = useAgentStore((state) => state.agentContactCard);
  

  const { value, onChange, handleSubmit, setValue } = useEditContactCard(
    "address",
    agentContactCard?.address
  );

  // todo: 定位当前位置
  const handleEditAddress = ()=> {
    const option = {
      address:  '',
      latitude: 39.916527,
      longitude: 116.397128,
      success(result:Taro.chooseLocation.SuccessCallbackResult) {
          console.log(result)
          setValue(result.address)
      }
    }
    console.log(option)
    Taro.chooseLocation(option)
  }

  return (
    <PageCustom>
      <NavBarNormal backText="联系地址"></NavBarNormal>
      <View className="flex flex-col items-center w-full">
        <View className="w-full p-16">
          <WemetaTextarea
            value={value}
            onBlur={(value: string) => onChange(value)}
            onInput={(value: string) => onChange(value)}
            placeholder="填写联系地址"
            autoFocus
            maxlength={100}
          />
          <View className="text-primary" onClick={handleEditAddress}>
            选择地址
          </View>
        </View>
        <BottomBar>
          <View
            className="button-rounded button-primary flex-1"
            onClick={handleSubmit}
          >
            保存
          </View>
        </BottomBar>
      </View>
    </PageCustom>
  );
}
