import { defineStore } from 'pinia'

import paper from 'paper';

export const CommonStore = defineStore({
  id: 'common',
  state: () => ({
    hover_elmt: null,
    map_item_ray: Math.min(window.innerWidth, window.innerHeight) * 0.08,
    original_cartouch_width: 450,
    cartouch_width: 450,
    cartouch_is_opened: false,
    paper_symbol_definitions: {}
  }),
  getters: {
    
  },
  actions: {
    setHoverElmt(elmt) {
      // console.log(`setHoverElmt`, elmt);
      // mode can be : terraindevie, proximite, superposition, puissancedagir, action, doleancer
      this.hover_elmt = elmt;
    },
    setOriginalCartoucheWidth (w) {
      console.log('CommonStore setOriginalCartoucheWidth', w);
      this.original_cartouch_width = w;
    },
    setCartoucheWidth (delta) {
      console.log('CommonStore setCartoucheWidth', delta);
      this.cartouch_width = this.original_cartouch_width * delta + 8 * (delta+1);
    },
    setCartoucheOpened (v) {
      console.log('setCartoucheOpened', v);
      this.cartouch_is_opened = v;
    },
    addPaperSymbolDefinition(name, path) {
      // console.log(`addPaperSymbolDefinition ${name}`, path);
      // mode can be : terraindevie, proximite, superposition, puissancedagir, action, doleancer
      this.paper_symbol_definitions[name] = new paper.SymbolDefinition(path);
    },
    updateMapItemRay(){
      console.log('Common Store updateMapItemRay');
      this.map_item_ray = Math.min(window.innerWidth, window.innerHeight) * 0.08;
    }
  }
})