import React from "react";
import ContentTitle from "../../component/ContentTitle.jsx";
import SubTitle from "../../component/SubTitle.jsx";
import Button from "../../component/Button.jsx";

export default function AuthorityManagement() {
  const [checkArr, setCheckArr] = React.useState([]); //check 배열
  const [menuCheckArr, setMenuCheckArr] = React.useState([]); //menu check 배열

  const authorityList = ["보호자", "보호사", "병원", "지자체", "관리자"];
  const menuList = [
    {
      menu: {
        시니어관리: ["시니어관리"],
        건강관리: ["복약관리", "댁내온도관리", "복약통계"],
        방문관리: ["방문관리"],
        장비관리: ["장비관리"],
        설정: ["내정보 관리", "사용자 관리", "권한 관리"],
      },
    },
  ];

  const onCheckedElement = (checked, title) => {
    if (checked) {
      setMenuCheckArr([...menuCheckArr]);
      setCheckArr([...checkArr, title]);
    } else if (!checked) {
      setCheckArr(checkArr.filter((el) => el !== title));
    }
  };
  return (
    <main>
      <div className="content-wrap">
        <ContentTitle contentTitle={"관리자 권한관리"} />
        <div className="board-wrap">
          <SubTitle className="margin-bottom" explanation={"메뉴 권한을 설정할 수 있습니다."} />
          <div className="board-wrap">
            {/* <table className="authority-table-pc">
              <thead>
                <tr>
                  <th colSpan={2} style={{ width: "30%" }}>
                    메뉴 목록
                  </th>
                  <th style={{ width: "70%" }}>운영자 목록</th>
                </tr>
                <tr>
                  <th>대메뉴</th>
                  <th>소메뉴</th>
                  <th style={{ backgroundColor: "transparent" }}>
                    <div className="flex">
                      {authorityList.map((i) => (
                        <div className="flex-start">
                          <input
                            className="flex10"
                            type="checkbox"
                            value={i}
                            onChange={(e) => {
                              onCheckedElement(
                                e.target.checked,
                                e.target.value
                              );
                            }}
                          />
                          <label className="flex90">{i}</label>
                        </div>
                      ))}
                    </div>
                  </th>
                </tr>
              </thead>
              <tbody>
                {menuList.map((i, idx) =>
                  Object.entries(i.menu).map(([key, value]) =>
                    value.map((item, index) => (
                      <tr key={idx}>
                        {index === 0 && (
                          <td rowSpan={value.length}>
                            <div className="flex-center">
                              <input
                                type="checkbox"
                                id="largeMenu"
                                className="flex10"
                              />
                              <label htmlFor="largeMenu" className="flex60">
                                {key}
                              </label>
                            </div>
                          </td>
                        )}
                        <td>
                          <div className="flex-center">
                            <input
                              type="checkbox"
                              id="smallMenu"
                              className="flex10"
                            />
                            <label htmlFor="smallMenu" className="flex60">
                              {item}
                            </label>
                          </div>
                        </td>
                        <td>
                          {checkArr.map((managerList, managerIdx) => (
                            <button style={{marginRight:"1rem"}} key={managerIdx}>{managerList}</button>
                          ))}
                        </td>
                      </tr>
                    ))
                  )
                )}
              </tbody>
            </table> */}
            <table>
            <thead>
              <tr>
                <th rowSpan="2">구분</th>
                <th rowSpan="2">사용자 관리</th>
                <th colSpan="3">건강관리</th>
                <th rowSpan="2">방문관리</th>
                <th rowSpan="2">장비관리</th>
                <th rowSpan="2">고객지원센터</th>
                <th rowSpan="2">Q&amp;A</th>
              </tr>
              <tr>
                <th>복약관리</th>
                <th>댁내온도관리</th>
                <th>복약통계</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>시행기관(병원, 복지관 등)</td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
              </tr>
              <tr>
                <td>보호사(간호사, 복지사 등)</td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
              </tr>
              <tr>
                <td>보호자(대상자 가족)</td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" checked="checked"/></td>
              </tr>
              <tr>
                <td>대상자</td>
                <td><input type="checkbox" checked="checked"/></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" /></td>
                <td><input type="checkbox" checked="checked"/></td>
              </tr>             
              
            </tbody>
            </table>
            <div className="btn-wrap flex-end">
              <Button className={"btn-small green-btn"} btnName={"저장"} />
            </div>
          </div>
        </div>
      </div>
    </main>
  );
}
