import { StickerItem } from '@ohos/common/src/main/ets/viewmodel/LocalBean';

@Component
export struct ZoomView {
  @ObjectLink item: StickerItem;

  build() {
    Image(this.item.pixelMap)
      .width('100%')
      .height('100%')
      .objectFit(ImageFit.Contain)
      .translate({ x: this.item.posX, y: this.item.posY })
      .scale({ x: this.item.scaleValue, y: this.item.scaleValue })
      .zIndex(this.item.zIndex)
      .hitTestBehavior(HitTestMode.Transparent)
      .visibility(this.item.isHidden ? Visibility.None : Visibility.Visible)
      .gesture(
        GestureGroup(GestureMode.Parallel,
          PanGesture()
            .onActionStart(() => {
              this.promoteZIndex();
            })
            .onActionUpdate((event: GestureEvent) => {
              this.item.posX = this.item.lastX + event.offsetX;
              this.item.posY = this.item.lastY + event.offsetY;
            })
            .onActionEnd(() => {
              this.item.lastX = this.item.posX;
              this.item.lastY = this.item.posY;
            }),

          PinchGesture()
            .onActionUpdate((event: GestureEvent) => {
              this.item.scaleValue = this.item.lastScale * event.scale;
            })
            .onActionEnd(() => {
              this.item.lastScale = this.item.scaleValue;
            })

        )
      )
  }

  private promoteZIndex() {
    const baseZ = (this.item.type + 1) * 10;
    this.item.zIndex = baseZ + 9;
  }
}



