import { Component, PropsWithChildren, useEffect, useState } from "react";
import Taro from "@tarojs/taro";
import { Block, View, RichText } from "@tarojs/components";

import Navbar from "../../components/navbar/navbar";

import "./privacyPolicy.less";

import { getPrivacyAgreement } from "../../utils/Interface";

export default class PrivacyPolicy extends Component<any, any> {
  constructor(props) {
    super(props);
    this.state = {
      name: "隐私政策",
      nodes: "",
    };
  }

  async onLoad() {
    this.initData();
  }
  componentDidMount() {}

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  initData = async () => {
    let res = await getPrivacyAgreement();
    if (res.data.code === 200) {
      let nodes = decodeURIComponent(res.data.data.value || "");
      nodes = nodes.replace(/\<img/gi, '<img style="width:100%;height:auto" ');
      nodes = nodes.replace(
        /\<table/gi,
        '<table style="border-spacing: 0;border-collapse: collapse;border: 1px solid #000" '
      );
      nodes = nodes.replace(
        /\<td/gi,
        '<td style="border: 1px solid #000;text-align:center" '
      );
      this.setState({ nodes: nodes });
    }
  };

  render() {
    let { nodes } = this.state;
    return (
      <Block>
        <Navbar titleSlot="隐私政策" isBack={true} />

        <View className="nodes">
          <RichText
            nodes={
              nodes
              // "<pre style=' white-space: pre-wrap;word-wrap: break-word;'>" +
              // nodes +
              // "</pre>"
            }
          />
        </View>
      </Block>
    );
  }
}
