import { PosInfoStore } from '@/domains/pos/store';
import { SharedGoodFormComponent } from '@/shared/components/good';
import { InnerPagesHeaderComponent } from '@/shared/components/innerPagesHeader/inner-pages-header.component';
import { Component, computed, inject } from '@angular/core';
import { Router } from '@angular/router';
import config from 'src/config';
import { PosOwnedGoodsService } from '../services/main.service';

@Component({
  selector: 'pos-good-create',
  templateUrl: './create.component.html',
  imports: [SharedGoodFormComponent, InnerPagesHeaderComponent],
})
export class PosGoodsCreateComponent {
  private readonly router = inject(Router);
  private readonly store = inject(PosInfoStore);
  private readonly service = inject(PosOwnedGoodsService);

  readonly guildId = computed(() => this.store.entity()?.guild.id || '');

  readonly backRoute = config.isPosApplication ? '/' : '/pos';

  preparedPageTitle = computed(
    () => `ایجاد کالا برای ${this.store.entity()?.businessActivity.name}`
  );

  onSubmit() {
    this.onPrev();
  }

  onPrev() {
    this.router.navigateByUrl(this.backRoute);
  }

  createFn = (payload: FormData) => this.service.create(payload);
}
