// // SearchAplikasiVC.swift // Sirani // // Created by Hendi on 21/06/23. // Copyright © 2023 PT. Mitra Sinerji Teknoindo. All rights reserved. // import UIKit protocol SearchAplikasiDelegate { func onSearch(search: String, status: String, jenisLabel: String) } class SearchAplikasiVC: UIViewController { // Outlets / Views @IBOutlet weak var inputSearch: RoundTextField! @IBOutlet weak var optionsLayoutTV: UITableView! @IBOutlet weak var optionsLayout: UIView! @IBOutlet weak var optionsBg: UIView! @IBOutlet weak var btnStatusOptions: UIButton! // Initialize var delegate: SearchAplikasiDelegate? // constants vallue data private let jenisSertifikatOptionItems = [ OptionItem(label: "Semua", value: "apl_all"), OptionItem(label: "Draft Customer", value: "apl_draft_cust"), OptionItem(label: "Pemeriksaan Dokumen", value: "apl_pemeriksaan_dok"), OptionItem(label: "Tunggu Disposisi", value: "apl_tunggu_disposisi"), OptionItem(label: "Evaluasi Dokumen", value: "apl_eval_dok"), OptionItem(label: "Rekomendasi Aplikasi", value: "apl_rekomendasi_apl"), OptionItem(label: "Persetujuan Aplikasi", value: "apl_persetujuan_apl"), // OptionItem(label: "Persetujuan Penerbitan", value: ""), OptionItem(label: "Proses Sertifikasi", value: "apl_proses_sertifikasi"), OptionItem(label: "Pembayaran SP2", value: "apl_pembayaran_sp2"), OptionItem(label: "Sertifikat Dicetak", value: "apl_sertifikat_dicetak"), OptionItem(label: "Permohonan Tidak Lengkap", value: "apl_permohonan_tidak_lengkap"), OptionItem(label: "Draft Ditolak", value: "apl_draft_ditolak"), OptionItem(label: "SP2 Kadaluarsa", value: "apl_sp2_kadaluarsa"), OptionItem(label: "Batal", value: "apl_batal") ] private let OPTION_JENIS_SERTIFIKAT_ID = 1 // Others private var selectedOptions = 0 private var selectedOptionItems = [OptionItem]() private var optionsShown = false // Result Values private var search = "" private var status = "" private var jenisLabel = "Semua" // View Lifecycles override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override func viewWillAppear(_ animated: Bool) { btnStatusOptions.layer.masksToBounds = false btnStatusOptions.layer.shadowColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1) btnStatusOptions.layer.shadowOpacity = 0.5 btnStatusOptions.layer.shadowOffset = CGSize(width: 1, height: 1) btnStatusOptions.layer.shadowRadius = 1 status = jenisSertifikatOptionItems[0].value as! String jenisLabel = jenisSertifikatOptionItems[0].label btnStatusOptions.setTitle(jenisLabel, for: .normal) hideOptions() optionsLayoutTV.bringSubviewToFront(optionsBg) let onOptionsBgTapped = UITapGestureRecognizer(target: self, action: #selector(hideOptions)) optionsBg.addGestureRecognizer(onOptionsBgTapped) } override func viewDidLoad() { super.viewDidLoad() optionsLayoutTV.delegate = self optionsLayoutTV.dataSource = self optionsLayoutTV.tableFooterView = UIView() } @IBAction func onInputSearchKeyTap(_ sender: Any) { view.endEditing(true) } @IBAction func unwindToAplikasi(_ sender: Any) { if optionsShown { hideOptions() } else { performSegue(withIdentifier: "unwindSearchToAplikasiSegueId", sender: self) } } @IBAction func onJenisSertifikatOptionsTapped(_ sender: Any) { selectedOptions = OPTION_JENIS_SERTIFIKAT_ID selectedOptionItems.removeAll() selectedOptionItems += jenisSertifikatOptionItems optionsLayoutTV.reloadData() showOptions() } @IBAction func onResetTapped(_ sender: Any) { search = "" status = "" jenisLabel = "Semua" inputSearch.text = "" btnStatusOptions.setTitle(jenisLabel, for: .normal) } @IBAction func onSearchTapped(_ sender: Any) { if let searchText = inputSearch.getText() { search = searchText } self.delegate?.onSearch(search: search, status: status, jenisLabel: jenisLabel) performSegue(withIdentifier: "unwindSearchToAplikasiSegueId", sender: self) } private func showOptions() { optionsLayout.show() optionsShown = true } @objc private func hideOptions() { optionsLayout.hide() optionsShown = false } } extension SearchAplikasiVC: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return selectedOptionItems.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if let cell = tableView.dequeueReusableCell(withIdentifier: "searchAplikasiCell", for: indexPath) as? OptionsCell { let optionItem = selectedOptionItems[indexPath.row] cell.updateViews(item: optionItem) return cell } else { return OptionsCell() } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if selectedOptions == OPTION_JENIS_SERTIFIKAT_ID { status = selectedOptionItems[indexPath.row].value as! String jenisLabel = selectedOptionItems[indexPath.row].label btnStatusOptions.setTitle(jenisLabel, for: .normal) } hideOptions() } }