import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { computed, makeObservable, observable, action } from 'mobx';
import { observer, } from 'mobx-react';
import * as React from 'react';
import { Utils, emptyFunction, returnFalse, returnZero } from '../../../Utils';
import { Doc, DocListCast } from '../../../fields/Doc';
import { Id } from '../../../fields/FieldSymbols';
import { DocCast, NumCast, ScriptCast, StrCast } from '../../../fields/Types';
import { DocumentType } from '../../documents/DocumentTypes';
import { DragManager } from '../../util/DragManager';
import { SelectionManager } from '../../util/SelectionManager';
import { StyleProp } from '../StyleProvider';
import { DocumentView } from '../nodes/DocumentView';
import { FocusViewOptions } from '../nodes/FieldView';
import './CollectionCardDeckView.scss';
import { CollectionSubView } from './CollectionSubView';
import { ScriptField } from '../../../fields/ScriptField';
import { lengthToDegrees } from '@turf/turf';
@observer
export class CollectionCardView extends CollectionSubView() {
@observable selectedNodeIndex = -1;
@observable hoveredNodeIndex = -1;
@action
setHoveredNodeIndex = (index : number) => {
this.hoveredNodeIndex = index;
}
translateHover = (index : number) => {
if (this.hoveredNodeIndex == index){
return -50;
}
return 0;
}
@action
setSelectedNodeIndex = (index: number) => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
console.log("goodnight")
if (SelectionManager.IsSelected(docs[index])){
console.log("good mornings")
this.setSelectedNodeIndex(index);
}
};
isSelected = (index : number) => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
return SelectionManager.IsSelected(docs[index])
}
// @computed
// rotationDegree = (index : number) => {
// const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
// if (SelectionManager.IsSelected(docs[index])){
// return 30;
// }
// return 0;
// }
constructor(props: any) {
super(props);
makeObservable(this);
// this.rotationDegree(7);
}
private _dropDisposer?: DragManager.DragDropDisposer;
componentWillUnmount() {
this._dropDisposer?.();
}
protected createDashEventsTarget = (ele: HTMLDivElement | null) => {
this._dropDisposer?.();
if (ele) {
this._dropDisposer = DragManager.MakeDropTarget(ele, this.onInternalDrop.bind(this), this.layoutDoc);
}
};
panelWidth = () => (this._props.PanelWidth()) / this.childLayoutPairs.length;
panelHeight = () => this.panelWidth() * 1.5;
onChildDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick);
// onChildClick = () => ScriptCast(this.rotate(3, 3));
isContentActive = () => this._props.isSelected() || this._props.isContentActive() || this._props.isAnyChildContentActive();
isChildContentActive = () => (this.isContentActive() ? true : false);
//thid needs to be fixed
childScreenToLocal = () =>
this._props // document's left is the panel shifted by the doc's index * panelWidth/#docs. But it scales by centerScale around its center, so it's left moves left by the distance of the left from the center (panelwidth/2) * the scale delta (centerScale-1)
.ScreenToLocalTransform() // the top behaves the same way ecept it's shifted by the 'top' amount specified for the panel in css and then by the scale factor.
// .translate(-this.panelWidth() + ((this.centerScale - 1) * this.panelWidth()) / 2,-((Number(CAROUSEL3D_TOP) / 100) * this._props.PanelHeight()) + ((this.centerScale - 1) * this.panelHeight()) / 2)
.rotate(this.rotate(this.childLayoutPairs.length, Number(this.layoutDoc._carousel_index)))
// .scale(1 / this.centerScale);
//literally doesnot do anythin
// focus = (anchor: Doc, options: FocusViewOptions) => {
// const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
// if (anchor.type !== DocumentType.CONFIG && !docs.includes(anchor)) return;
// options.didMove = true;
// const target = DocCast(anchor.annotationOn) ?? anchor;
// const index = docs.indexOf(target);
// index !== -1 && (this.layoutDoc._carousel_index = index); //if index is not -1, then assign index to this.layoutDoc._carousel_index
// return undefined;
// };
rotate = (amCards: number, index: number) => {
const possRotate = -30 + (index * (30/((amCards - (amCards%2))/2)));
if (amCards%2 == 0 && possRotate==0){
console.log('whaddup')
return possRotate + Math.abs(-30 + ((index-1) * (30/((amCards - 1)/2))))
}
return possRotate;
}
// translateY = (amCards: number, index: number) => {
// // Assuming you want a default value when index > amCards/2
// // Adjust the logic as necessary for your use case
// if (index <= amCards / 2) {
// return -((50 / ((amCards - (amCards % 2)) / 2)) * index);
// } else {
// // Return a default or calculated value for indices greater than amCards/2
// // This is just an example; adjust the logic as needed
// return -((50 / ((amCards - (amCards % 2)) / 2)) * (amCards - index - 1));
// }
// };
@computed get content() {
// const currentIndex = NumCast(this.layoutDoc._carousel_index);
const amCards = this.childLayoutPairs.length;
const displayDoc = (childPair: { layout: Doc; data: Doc }) => {
return (