import {useEffect, useState} from "react";
import {Input, Button} from '@nutui/nutui-react-taro'
import {copyText} from "@/utils/common";
import Taro from '@tarojs/taro'

const SiteUrl = (props: any) => {
  const [siteUrl, setSiteUrl] = useState<string>('')
  const reload = () => {
    if(props.tenantId){
      setSiteUrl(`https://${props.tenantId}.shoplnk.cn`)
    }else {
      setSiteUrl(`https://${Taro.getStorageSync('TenantId')}.shoplnk.cn`)
    }
  }

  useEffect(() => {
    reload()
  }, [props])

  return (
    <div className={'px-3 mt-1 mb-4'}>
      <div className={'flex justify-between items-center bg-gray-300 rounded-lg pr-2'}>
        <Input type="text" value={siteUrl} disabled style={{backgroundColor: '#d1d5db', borderRadius: '8px'}}/>
        <Button type={'info'} onClick={() => copyText(siteUrl)}>复制</Button>
      </div>
    </div>
  )
}
export default SiteUrl
