import React from "react";
import { connect, DispatchProp } from "react-redux";
import { AnyAction } from "redux";

import {
  CharacterTheme,
  rulesEngineSelectors,
} from "@dndbeyond/character-rules-engine/es";

import a11yStyles from "~/styles/accessibility.module.css";

import SubsectionTablet from "../../../components/SubsectionTablet";
import TabletBox from "../../../components/TabletBox";
import { SheetAppState } from "../../../typings";
import Features from "../../Features";

// TODO: We are typing with AnyAction here to work around issues with UnknownAction, the type that was introduced in Redux 5.
// If we decide to modernize to Redux 5, we will need to refactor much of the Rules Engine redux usage.
interface Props extends DispatchProp<AnyAction> {
  theme: CharacterTheme;
}
class FeaturesTablet extends React.PureComponent<Props> {
  render() {
    const { theme } = this.props;

    return (
      <SubsectionTablet className="ct-features-tablet">
        <TabletBox
          header="Features & Traits"
          className="ct-actions-tablet"
          theme={theme}
        >
          <section>
            <h2 className={a11yStyles.screenreaderOnly}>Features and Traits</h2>
            <Features />
          </section>
        </TabletBox>
      </SubsectionTablet>
    );
  }
}

function mapStateToProps(state: SheetAppState) {
  return {
    theme: rulesEngineSelectors.getCharacterTheme(state),
  };
}

export default connect(mapStateToProps)(FeaturesTablet);
