<commit_before>import BungieImage from 'app/dim-ui/BungieImage';
import ElementIcon from 'app/dim-ui/ElementIcon';
import Sheet from 'app/dim-ui/Sheet';
import { DimItem, DimSocket, PluggableInventoryItemDefinition } from 'app/inventory/item-types';
import { DefItemIcon } from 'app/inventory/ItemIcon';
import { allItemsSelector, profileResponseSelector } from 'app/inventory/selectors';
import { isPluggableItem } from 'app/inventory/store/sockets';
import { d2ManifestSelector, useD2Definitions } from 'app/manifest/selectors';
import { itemsForCharacterOrProfilePlugSet } from 'app/records/plugset-helpers';
import { RootState } from 'app/store/types';
import { chainComparator, compareBy, reverseComparator } from 'app/utils/comparators';
import { emptySet } from 'app/utils/empty';
import {
  DestinyEnergyType,
  DestinyItemPlug,
  DestinyItemPlugBase,
  SocketPlugSources,
} from 'bungie-api-ts/destiny2';
import clsx from 'clsx';
import React, { useEffect, useRef, useState } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import '../inventory/StoreBucket.scss';
import styles from './SocketDetails.m.scss';
import SocketDetailsSelectedPlug from './SocketDetailsSelectedPlug';

interface ProvidedProps {
  item: DimItem;
  socket: DimSocket;
  onClose(): void;
  onPlugSelected?(value: { item: DimItem; socket: DimSocket; plugHash: number }): void;
}

interface StoreProps {
  inventoryPlugs: Set<number>;
  unlockedPlugs: Set<number>;
}

function mapStateToProps() {
  /** Build the hashes of all plug set item hashes that are unlocked by any character/profile. */
  const unlockedPlugsSelector = createSelector(
    profileResponseSelector,
    (_state: RootState, { item }: ProvidedProps) => item.owner,
    (_state: RootState, { socket }: ProvidedProps) =>
      socket.socketDefinition.reusablePlugSetHash || socket.socketDefinition.randomizedPlugSetHash,
    (profileResponse, owner, plugSetHash) => {
      if (!plugSetHash || !profileResponse) {
        return emptySet<number>();
      }
      const unlockedPlugs = new Set<number>();
      const plugSetItems = itemsForCharacterOrProfilePlugSet(profileResponse, plugSetHash, owner);
      for (const plugSetItem of plugSetItems) {
        if (plugSetItem.enabled) {
          unlockedPlugs.add(plugSetItem.plugItemHash);
        }
      }
      return unlockedPlugs;
    }
  );

  const inventoryPlugs = createSelector(
    allItemsSelector,
    (_state: RootState, props: ProvidedProps) => props.socket,
    d2ManifestSelector,
    (allItems, socket, defs) => {
      const socketType = defs!.SocketType.get(socket.socketDefinition.socketTypeHash);
      if (
        !(
          socket.socketDefinition.plugSources & SocketPlugSources.InventorySourced &&
          socketType.plugWhitelist
        )
      ) {
        return emptySet<number>();
      }

      const modHashes = new Set<number>();

      const plugAllowList = new Set(socketType.plugWhitelist.map((e) => e.categoryHash));
      for (const item of allItems) {
        const itemDef = defs!.InventoryItem.get(item.hash);
        if (itemDef.plug && plugAllowList.has(itemDef.plug.plugCategoryHash)) {
          modHashes.add(item.hash);
        }<commit_msg>Fix transmog ornament chooser to grey out locked options<commit_after>import BungieImage from 'app/dim-ui/BungieImage';
import ElementIcon from 'app/dim-ui/ElementIcon';
import Sheet from 'app/dim-ui/Sheet';
import { DimItem, DimSocket, PluggableInventoryItemDefinition } from 'app/inventory/item-types';
import { DefItemIcon } from 'app/inventory/ItemIcon';
import { allItemsSelector, profileResponseSelector } from 'app/inventory/selectors';
import { isPluggableItem } from 'app/inventory/store/sockets';
import { d2ManifestSelector, useD2Definitions } from 'app/manifest/selectors';
import { itemsForCharacterOrProfilePlugSet } from 'app/records/plugset-helpers';
import { RootState } from 'app/store/types';
import { chainComparator, compareBy, reverseComparator } from 'app/utils/comparators';
import { emptySet } from 'app/utils/empty';
import {
  DestinyEnergyType,
  DestinyItemPlug,
  DestinyItemPlugBase,
  SocketPlugSources,
} from 'bungie-api-ts/destiny2';
import clsx from 'clsx';
import React, { useEffect, useRef, useState } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import '../inventory/StoreBucket.scss';
import styles from './SocketDetails.m.scss';
import SocketDetailsSelectedPlug from './SocketDetailsSelectedPlug';

interface ProvidedProps {
  item: DimItem;
  socket: DimSocket;
  onClose(): void;
  onPlugSelected?(value: { item: DimItem; socket: DimSocket; plugHash: number }): void;
}

interface StoreProps {
  inventoryPlugs: Set<number>;
  unlockedPlugs: Set<number>;
}

function mapStateToProps() {
  /** Build the hashes of all plug set item hashes that are unlocked by any character/profile. */
  const unlockedPlugsSelector = createSelector(
    profileResponseSelector,
    (_state: RootState, { item }: ProvidedProps) => item.owner,
    (_state: RootState, { socket }: ProvidedProps) =>
      socket.socketDefinition.reusablePlugSetHash || socket.socketDefinition.randomizedPlugSetHash,
    (profileResponse, owner, plugSetHash) => {
      if (!plugSetHash || !profileResponse) {
        return emptySet<number>();
      }
      const unlockedPlugs = new Set<number>();
      const plugSetItems = itemsForCharacterOrProfilePlugSet(profileResponse, plugSetHash, owner);
      for (const plugSetItem of plugSetItems) {
        if (plugSetItem.canInsert) {
          unlockedPlugs.add(plugSetItem.plugItemHash);
        }
      }
      return unlockedPlugs;
    }
  );

  const inventoryPlugs = createSelector(
    allItemsSelector,
    (_state: RootState, props: ProvidedProps) => props.socket,
    d2ManifestSelector,
    (allItems, socket, defs) => {
      const socketType = defs!.SocketType.get(socket.socketDefinition.socketTypeHash);
      if (
        !(
          socket.socketDefinition.plugSources & SocketPlugSources.InventorySourced &&
          socketType.plugWhitelist
        )
      ) {
        return emptySet<number>();
      }

      const modHashes = new Set<number>();

      const plugAllowList = new Set(socketType.plugWhitelist.map((e) => e.categoryHash));
      for (const item of allItems) {
        const itemDef = defs!.InventoryItem.get(item.hash);
        if (itemDef.plug && plugAllowList.has(itemDef.plug.plugCategoryHash)) {
          modHashes.add(item.hash);
        }
{'fraction_non_alphanumeric': 0.11177461338233043, 'fraction_numerical': 0.0012249272699433472, 'mean_word_length': 4.067494181536074, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '507885', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1912, 'n_words': 436}